Theoremaliases_inner
Statement
theorem aliases_inner {Cte : Ctx} (hCU : Cte.U = []) (post : List BTypBind) :
∀ todo : List BTypBind,
(∀ lc : LongId, (lc.qual.isSome = true ∨ lc.id ∉ todo.map (·.c)) → LookSim f Cte A lc) →
(∀ tb ∈ todo, ∃ τ X, elabTy (Cte.plusU (aliasVars tb)) tb.t = some τ ∧
Cte.lookupTy ⟨none, tb.c⟩ = some (TyFcn.canon ⟨aliasVars tb, τ⟩, X)) →
aliasOrderB (todo ++ post) = true →
(aliasesRefuted A (todo ++ post) = true ∨ aliasesAllOK A (todo ++ post) = true) →
(aliasesRefuted A (todo ++ post) = true → aliasesRefuted A post = true) ∧
(aliasesAllOK A (todo ++ post) = true → aliasesAllOK A post = true) ∧ ∀ lc, LookSim f Cte A lc
| [], hS, _, _, _ => ⟨id, id, fun lc => hS lc (.inr (by simp))⟩
| tb :: rest, hS, hT, hord, hH => by
simp only [List.cons_append] at hH hord ⊢
obtain ⟨τ, X, he, hl⟩Proof
hT tb (List.mem_cons_self ..)
simp only [aliasOrderB, Bool.and_eq_true, List.all_eq_true, Bool.or_eq_true,
Bool.not_eq_true', List.any_eq_false, beq_iff_eq] at hord
have hsim : ∀ lc ∈ bTyCons tb.t, LookSim f (Cte.plusU (aliasVars tb)) (A.plusU (aliasVars tb)) lc := by
intro lc hlc
apply lookSim_plusU
rcases hord.1 lc hlc with hq | hn
· exact hS lc (.inl hq)
· refine hS lc (.inr ?_)
intro hm
obtain ⟨tb', htb', he'⟩ := List.mem_map.mp hm
have : tb' ∈ tb :: (rest ++ post) := by
rcases List.mem_cons.mp htb' with rfl | h'
· exact List.mem_cons_self ..
· exact List.mem_cons_of_mem _ (List.mem_append_left _ h')
exact hn tb' this he'
have hUeq : UEq (Cte.plusU (aliasVars tb)).U (A.plusU (aliasVars tb)).U := by
simp only [Ctx.plusU, hCU, hAU]; exact uEq_refl _
have hea := elabTy_sim f hcol.builtins _ _ hUeq tb.t τ hsim he
have hel : aliasElab A tb = some (mapTy f τ) := hea
have hok : aliasOK A tb = true ∧
(aliasesRefuted A (tb :: (rest ++ post)) = true → aliasesRefuted A (rest ++ post) = true) ∧
(aliasesAllOK A (tb :: (rest ++ post)) = true → aliasesAllOK A (rest ++ post) = true) := by
simp only [aliasesRefuted, aliasesAllOK, List.all_cons, hel, Option.isNone_some, Bool.false_or,
Bool.and_eq_true] at hH ⊢
rcases hH with h | h
· exact ⟨h.1, fun h' => h'.2, fun h' => h'.2⟩
· exact ⟨h.1, fun h' => h'.2, fun h' => h'.2⟩
have hlook : LookSim f Cte A ⟨none, tb.c⟩ := by
intro θ VE hθ
rw [hl] at hθ
simp only [Option.some.injEq, Prod.mk.injEq] at hθ
obtain ⟨rfl, rfl⟩ := hθ
have h1 := hok.1
simp only [aliasOK, hel, decide_eq_true_eq] at h1
cases hA : A.lookupTy ⟨none, tb.c⟩ with
| none => rw [hA] at h1; cases h1
| some s =>
rw [hA] at h1
simp only [Option.map_some, Option.some.injEq] at h1
refine ⟨s.2, ?_⟩
rw [canon_map]
have e : mapFcn f ⟨aliasVars tb, τ⟩ = ⟨aliasVars tb, mapTy f τ⟩ := rfl
rw [e, ← h1]
have ih := aliases_inner hCU post rest
(fun lc hlc => by
obtain ⟨q, c⟩ := lc
rcases hlc with hq | hn
· exact hS _ (.inl hq)
· by_cases e : c = tb.c
· cases q with
| none => subst e; exact hlook
| some m => exact hS _ (.inl rfl)
· refine hS _ (.inr ?_)
simp only [List.map_cons, List.mem_cons, not_or]
exact ⟨e, hn⟩)
(fun tb' h' => hT tb' (List.mem_cons_of_mem _ h')) hord.2
(by
rcases hH with h | h
· exact .inl (hok.2.1 h)
· exact .inr (hok.2.2 h))
exact ⟨fun h => ih.1 (hok.2.1 h), fun h => ih.2.1 (hok.2.2 h), ih.2.2⟩Proved by a term, which Lean's kernel checks directly.
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.