Theoremlegal_of_infer1
Statement
theorem legal_of_infer1 {B : SBasis} {imps : List BImport} {C : Ctx} {sp : SProgram}
(hctx : importCtx B imps = some C) (h : legal1B B imps C sp = true) :
InferPrincipalFor B (Src.deriveProgram (Src.canonOrder sp)) → LegalProgram B spProof
by
intro H
unfold legal1B at h
simp only [Bool.and_eq_true] at h
obtain ⟨hsyn, h⟩ := h
generalize hp : Src.deriveProgram (Src.canonOrder sp) = p at h H
have hpm := congrArg BProgram.modules hp
split at h
· rename_i m hms
simp only [Bool.and_eq_true, decide_eq_true_eq] at h
obtain ⟨himps, h⟩ := h
split at h
· rename_i a hinf
split at h
· rename_i B' E hres
simp only [Bool.and_eq_true] at h
obtain ⟨⟨hfur, hports⟩, hmain⟩ := h
obtain ⟨τ, hτ⟩ := Option.isSome_iff_exists.mp hmain
have hctxm : importCtx B m.imports = some C := himps ▸ hctx
have hctxa : importCtx B a.imports = some C := (inferModuleIn_imports hinf) ▸ hctxm
have hresult : a.result B = some (B', E) := by rw [AModule.result_of_ctx hctxa]; exact hres
have hinfp : inferProgram B p = .ok [a] := by
unfold inferProgram
rw [hms]
simp only [inferProgramFrom, bind, Except.bind, pure, Except.pure]
rw [inferModule_of_ctx hctxm, hinf]
simp only [hresult]
have hcheck : checkProgram B [a] = true := by
simp [checkProgram, AProgram.bases, hresult]
obtain ⟨⟨_, herase⟩, Bs, hBs, hpr⟩ := H [a] hinfp hcheck
simp only [AProgram.bases, hresult, Option.map_some] at hBs
cases hBs
have hprin : IsPrincipalMod B a := hpr 0 (by simp) (by simp)
have hea : a.erase = m := by rw [hms] at herase; simpa using herase
have hfm : FurtherMod B a := by
unfold FurtherMod; rw [hresult]; exact furtherModInB_sound hfur
refine ⟨Src.synOKSet_of_synOK (by simpa [Src.decSynOK] using hsyn), τ, (B.plus B').PE, ?_⟩
rw [hp, hms]
exact elProgram_main ⟨a, hea, hprin, hresult, hfm⟩ (portsDisjointB_sound hports) hτ
· cases h
· cases h
· cases hProved with tactics, which Lean expands into a proof term that its kernel checks.
Theorems it uses
In StandardElmMech/Stat/Legal.lean: The master theorems: a program whose inferred derivation checks, meets the further restrictions and gives main a Chapter 9 type is legal, under D11 (legal_of_infer1, legal_of_infer).
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.