Elm Exactly

Theoremtypes_leaf

StandardElmMech/Stat/RefuseTypes.lean:973, Type declarations · tactic proof

Statement

theorem types_leaf {C : Ctx} (hI : Inv B f A C) {TE : TyEnv} {VE : ValEnv} {db' : Option BDatBind}
    {seg post : List BTypBind}
    (hnd : ((db'.getD []).map (·.1) ++ (seg ++ post).map (·.c)).Nodup)
    (hcu : customsOK A db' = true) (hord : aliasOrderB (seg ++ post) = true)
    (hH : aliasesRefuted A (seg ++ post) = true ∨ aliasesAllOK A (seg ++ post) = true)
    (h : checkTypes C TE VE db' seg = true) :
    (aliasesRefuted A (seg ++ post) = true → aliasesRefuted A post = true) ∧
    (aliasesAllOK A (seg ++ post) = true → aliasesAllOK A post = true) ∧
    (∀ lc, LookSim f (C.oplusTE TE) A lc) ∧ consOK A db' = true

Proof

by
  have hnd' := (List.nodup_append.mp hnd)
  have hseg : (seg.map (·.c)).Nodup := by
    have := hnd'.2.1
    rw [List.map_append] at this
    exact (List.nodup_append.mp this).1
  replace h := checkTypes_fix h
  unfold checkTypesFix at h
  cases db' with
  | none =>
    simp only at h
    split at h
    · rename_i VEs TEs hb
      simp only [decide_eq_true_eq] at h
      obtain ⟨_, rfl, _⟩ := h
      have := leaf_core hcol hAU hI (TE' := []) hb (fun c => by simp [FMap.find?]) (fun c θ VEc h => by cases h)
        hseg hord hH
      exact ⟨this.1, this.2.1, this.2.2, rfl⟩
    · cases h
  | some d =>
    simp only at h
    split at h
    · rename_i VE' TE' VEs TEs hd hb
      simp only [Bool.and_eq_true, decide_eq_true_eq] at h
      obtain ⟨hnew, _, hTE, _⟩ := h
      have hdn : (d.map (·.1)).Nodup := hnd'.1
      have hfacts := datBind_facts _ _ d VE' TE' hd hdn
      have hTE' : ∀ c θ VEc, FMap.find? TE' c = some (θ, VEc) →
          ∃ VE'', A.lookupTy ⟨none, c⟩ = some (mapFcn f θ, VE'') := by
        intro c θ VEc hc
        have hcm : c ∈ d.map (·.1) := by
          by_cases hn : c ∈ d.map (·.1)
          · exact hn
          · rw [hfacts.1 c hn] at hc; cases hc
        obtain ⟨x, hx, rfl⟩ := List.mem_map.mp hcm
        obtain ⟨t, VEt, ht1, ht2, _⟩ := hfacts.2 x hx
        rw [ht1] at hc
        simp only [Option.some.injEq, Prod.mk.injEq] at hc
        obtain ⟨rfl, rfl⟩ := hc
        have htT : t ∉ C.T := namesNewB_spec C.T TE' hnew _ (find?_mem_vals _ _ TE' ht1) t (name?_toFcn t)
        have hft : f t = ⟨Did, t.arity⟩ := hcol.out t (fun hb => htT (hI.T t hb))
        have hcx := List.all_eq_true.mp hcu x hx
        simp only [decide_eq_true_eq] at hcx
        cases hA : A.lookupTy ⟨none, x.1⟩ with
        | none => rw [hA] at hcx; cases hcx
        | some s =>
          rw [hA] at hcx
          simp only [Option.map_some, Option.some.injEq] at hcx
          refine ⟨s.2, ?_⟩
          rw [toFcn_map f t (by rw [hft]), hft, ht2, ← hcx]
      have hfind : ∀ c, FMap.find? TE c = (FMap.find? (FMap.plusAll TEs) c).or (FMap.find? TE' c) := by
        intro c; rw [← hTE, FMap.find?_modify]
      have hc := leaf_core hcol hAU hI hb hfind hTE' hseg hord hH
      refine ⟨hc.1, hc.2.1, hc.2.2, ?_⟩
      simp only [consOK, Option.getD_some, List.all_eq_true]
      intro x hx y hy
      obtain ⟨t, VEt, _, _, hcons⟩ := hfacts.2 x hx
      have hs := hcons y hy
      cases he : elabTyList ((C.oplusTE TE).plusU (seqVars x.2.1 (conBindExtNames x.2.2))) y.2 with
      | none => rw [he] at hs; cases hs
      | some τs =>
        have hUeq : UEq ((C.oplusTE TE).plusU (seqVars x.2.1 (conBindExtNames x.2.2))).U
            (A.plusU (seqVars x.2.1 (conBindExtNames x.2.2))).U := by
          simp only [Ctx.plusU, Ctx.oplusTE, hI.U, hAU]; exact uEq_refl _
        rw [elabTyList_sim f hcol.builtins _ _ hUeq y.2 τs (fun lc _ => lookSim_plusU _ _ (hc.2.2 lc)) he]
        rfl
    · cases h

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

Theorems it uses

Used by

In StandardElmMech/Stat/RefuseTypes.lean: Refusals by type expressions (aliases, constructor arguments, annotations, ports) and by the type of main (typesFailB, mainFailB), for every choice of generated names and variable sorts.

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.