Elm Exactly

Theoremnot_legal_of_wMainVar

StandardElmMech/Stat/Complete/Discharge.lean:464, A96: flags of a type variable (StandardA96NumberFlagsTest) · tactic proof

A96 (correction 3, and the comment after r:p-stat-main-view): when W's principal scheme of main gives the flags a type variable, no derivation of the program has a type of Chapter 9 for main. Every principal derivation of the module is W's up to a bijection of type names fixing the basis (step 10's module step), which takes a type variable to itself; a variable is not a port type (r:p-stat-main-program), and the default of a Program type is not a Node type (r:p-stat-main-view).

Statement

theorem not_legal_of_wMainVar {B : SBasis} {s : SProgram} (hB : BasisInv B) (h : wMainVarB B s = true) :
    ¬ LegalProgram B s

Proof

by
  rintro ⟨-, τ, PE, hel⟩
  unfold wMainVarB at h
  split at h
  · rename_i m hm
    split at h
    · rename_i a hw
      split at h
      · rename_i R E hr
        split at h
        · rename_i σ hσ
          split at h
          · rename_i α τ2 τ3 t hb
            simp only [decide_eq_true_eq] at h
            subst h
            obtain ⟨hae, hpa⟩ := MW.inferModuleW_principal hB hw
            obtain ⟨C, hC⟩ := MW.importCtx_of_ok hw
            have ho : TypesOrdered a.erase := hae ▸ MW.typesOrdered_of_W hw hC
            -- any principal derivation of the module has `main`'s scheme W's, renamed
            have key : ∀ a' B' E', a'.erase = m → IsPrincipalMod B a' → a'.result B = some (B', E') →
                ∃ σ' x y, E'.VE.find? "main" = some (σ', .v) ∧ σ'.body = .con [.var α, x, y] tProgram := by
              intro a' B' E' he' hpa' hr'
              have hI1 : InstanceOfMod B a' a := hpa.2.2 a' hpa'.1 hpa'.2.1 (he'.trans hae.symm)
              have hI2 : InstanceOfMod B a a' := hpa'.2.2 a hpa.1 hpa.2.1 (hae.trans he'.symm)
              obtain ⟨ρ, ρ', R1, E1, hρ, -, hr1, hr2, -⟩ :=
                MStep.moduleStep B a a' hB ho hpa.1 hpa'.1 hpa.2.1 hpa'.2.1 hI1 hI2
              rw [hr] at hr1
              simp only [Option.some.injEq, Prod.mk.injEq] at hr1
              obtain ⟨rfl, rfl⟩ := hr1
              rw [hr'] at hr2
              simp only [Option.some.injEq, Prod.mk.injEq] at hr2
              obtain ⟨-, rfl⟩ := hr2
              refine ⟨(nr ρ).scheme σ, (nr ρ).ty τ2, (nr ρ).ty τ3, ?_, ?_⟩
              · simp only [Renaming.env, Renaming.valEnv]
                rw [find?_map_snd (fun b => ((nr ρ).scheme b.1, b.2)) E.VE "main", hσ]
                rfl
              · simp only [Renaming.scheme, hb, Renaming.ty, Renaming.tys]
                rw [hρ.h.t0 tProgram (by decide)]
                rfl
            have hel' : ElProgram B [m] τ PE := by rw [← hm]; exact hel
            cases hel' with
            | r_p_stat_module _ _ hne _ => exact hne rfl
            | r_p_stat_main_program hd _ hσ' hb' hP =>
              obtain ⟨a', he', hpa', hr', -⟩ := hd
              obtain ⟨σ0, x0, y0, hf, hb0⟩ := key a' _ _ he' hpa' hr'
              rw [hf] at hσ'
              simp only [Option.some.injEq, Prod.mk.injEq] at hσ'
              obtain ⟨rfl, -⟩ := hσ'
              rw [hb0] at hb'
              simp only [Ty.con.injEq, List.cons.injEq] at hb'
              obtain ⟨⟨rfl, -⟩, -⟩ := hb'
              cases hP
            | r_p_stat_main_view hd _ hσ' hdf =>
              obtain ⟨a', he', hpa', hr', -⟩ := hd
              obtain ⟨σ0, x0, y0, hf, hb0⟩ := key a' _ _ he' hpa' hr'
              rw [hf] at hσ'
              simp only [Option.some.injEq, Prod.mk.injEq] at hσ'
              obtain ⟨rfl, -⟩ := hσ'
              obtain ⟨as, hd3, hl⟩ := dflt_con3 hb0
              rw [hd3] at hdf
              simp only [Ty.con.injEq] at hdf
              rw [hdf.1] at hl
              simp at hl
          · cases h
        · cases h
      · cases h
    · cases h
  · cases h

Proved with tactics, which Lean expands into a proof term that its kernel checks.

Rules of the book it uses

Theorems it uses

Used by

About ruling A96 of the book, where the implementations disagreed or were silent and the definition decides.

In StandardElmMech/Stat/Complete/Discharge.lean: Step 11, milestone (g): Stat.wCheck, legal_of_W, ident_of_wCheck, programSem_of_wCheck (D11 discharged test by test), not_legal_of_wMainVar (A96's flags refusal), principalExistsCore_of_covers, principalExistsMod_of_covers, d11For_of_agree; Lean's pipeline with W, endToEndW (step 10's endToEnd with W in place of step 9's inference), with endToEndW_of_wCheck (the per-test spec_ from wcheck_, without a second run of the inference), specOf_of_endToEndW, ident_of_endToEndW, programSem_of_endToEndW (step 10's statements, without D11); wCheckIn, wCheck_of_ctx (the W check of a one-module program with the context of its imports given by a lemma ctx_<name>_eq, so the kernel does not compute it per test: an end-to-end shard of 20 tests takes 32 s instead of 98 s).

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.