chars int64 40 24k | content_type stringclasses 9
values | id stringlengths 13 64 | source stringclasses 5
values | subset stringclasses 31
values | text stringlengths 40 24k |
|---|---|---|---|---|---|
642 | leanexplore_declaration | leanexplore:388172 | leanexplore_sqlite | leanexplore_declarations | /-- Invert the typing of an abstraction. -/
lemma abs_inv (der : Typing Γ (.abs γ' t) τ) (sub : Sub Γ τ (arrow γ δ)) :
Sub Γ γ γ'
∧ ∃ δ' L, ∀ x ∉ (L : Finset Var),
Typing (⟨x, Binding.ty γ'⟩ :: Γ) (t ^ᵗᵗ .fvar x) δ' ∧ Sub Γ δ' δ := by
generalize eq : Term.abs γ' t = e at der
induction der generalizing t ... |
847 | leanexplore_declaration | leanexplore:388173 | leanexplore_sqlite | leanexplore_declarations | /-- Invert the typing of a type abstraction. -/
lemma tabs_inv (der : Typing Γ (.tabs γ' t) τ) (sub : Sub Γ τ (all γ δ)) :
Sub Γ γ γ'
∧ ∃ δ' L, ∀ X ∉ (L : Finset Var),
Typing (⟨X, Binding.sub γ⟩ :: Γ) (t ^ᵗᵞ fvar X) (δ' ^ᵞ fvar X)
∧ Sub (⟨X, Binding.sub γ⟩ :: Γ) (δ' ^ᵞ fvar X) (δ ^ᵞ fvar X) := by
gen... |
242 | leanexplore_declaration | leanexplore:388174 | leanexplore_sqlite | leanexplore_declarations | /-- Invert the typing of a left case. -/
lemma inl_inv (der : Typing Γ (.inl t) τ) (sub : Sub Γ τ (sum γ δ)) :
∃ γ', Typing Γ t γ' ∧ Sub Γ γ' γ := by
generalize eq : t.inl =t at der
induction der generalizing γ δ <;> grind [cases Sub] |
243 | leanexplore_declaration | leanexplore:388175 | leanexplore_sqlite | leanexplore_declarations | /-- Invert the typing of a right case. -/
lemma inr_inv (der : Typing Γ (.inr t) T) (sub : Sub Γ T (sum γ δ)) :
∃ δ', Typing Γ t δ' ∧ Sub Γ δ' δ := by
generalize eq : t.inr =t at der
induction der generalizing γ δ <;> grind [cases Sub] |
306 | leanexplore_declaration | leanexplore:388176 | leanexplore_sqlite | leanexplore_declarations | /-- A value that types as a function is an abstraction. -/
lemma canonical_form_abs (val : Value t) (der : Typing [] t (arrow σ τ)) :
∃ δ t', t = .abs δ t' := by
generalize eq : σ.arrow τ = γ at der
generalize eq' : [] = Γ at der
induction der generalizing σ τ <;> grind [cases Sub, cases Value] |
310 | leanexplore_declaration | leanexplore:388177 | leanexplore_sqlite | leanexplore_declarations | /-- A value that types as a quantifier is a type abstraction. -/
lemma canonical_form_tabs (val : Value t) (der : Typing [] t (all σ τ)) :
∃ δ t', t = .tabs δ t' := by
generalize eq : σ.all τ = γ at der
generalize eq' : [] = Γ at der
induction der generalizing σ τ <;> grind [cases Sub, cases Value] |
313 | leanexplore_declaration | leanexplore:388178 | leanexplore_sqlite | leanexplore_declarations | /-- A value that types as a sum is a left or right case. -/
lemma canonical_form_sum (val : Value t) (der : Typing [] t (sum σ τ)) :
∃ t', t = .inl t' ∨ t = .inr t' := by
generalize eq : σ.sum τ = γ at der
generalize eq' : [] = Γ at der
induction der generalizing σ τ <;> grind [cases Sub, cases Value] |
460 | leanexplore_declaration | leanexplore:388179 | leanexplore_sqlite | leanexplore_declarations | /-- A type is well-formed when it is locally closed and all free variables appear in a context. -/
inductive Ty.Wf : Env Var → Ty Var → Prop
| top : Ty.Wf Γ top
| var : Binding.sub σ ∈ Γ.dlookup X → Ty.Wf Γ (fvar X)
| arrow : Ty.Wf Γ σ → Ty.Wf Γ τ → Ty.Wf Γ (arrow σ τ)
| all (L : Finset Var) :
Ty.Wf Γ σ →... |
54 | leanexplore_declaration | leanexplore:388181 | leanexplore_sqlite | leanexplore_declarations | | var : Binding.sub σ ∈ Γ.dlookup X → Ty.Wf Γ (fvar X) |
53 | leanexplore_declaration | leanexplore:388182 | leanexplore_sqlite | leanexplore_declarations | | arrow : Ty.Wf Γ σ → Ty.Wf Γ τ → Ty.Wf Γ (arrow σ τ) |
130 | leanexplore_declaration | leanexplore:388183 | leanexplore_sqlite | leanexplore_declarations | | all (L : Finset Var) :
Ty.Wf Γ σ →
(∀ X ∉ L, Ty.Wf (⟨X,Binding.sub σ⟩ :: Γ) (τ ^ᵞ fvar X)) →
Ty.Wf Γ (all σ τ) |
49 | leanexplore_declaration | leanexplore:388184 | leanexplore_sqlite | leanexplore_declarations | | sum : Ty.Wf Γ σ → Ty.Wf Γ τ → Ty.Wf Γ (sum σ τ) |
282 | leanexplore_declaration | leanexplore:388185 | leanexplore_sqlite | leanexplore_declarations | /-- An environment is well-formed if it binds each variable exactly once to a well-formed type. -/
inductive Env.Wf : Env Var → Prop
| empty : Wf []
| sub : Wf Γ → τ.Wf Γ → X ∉ Γ.dom → Wf (⟨X, Binding.sub τ⟩ :: Γ)
| ty : Wf Γ → τ.Wf Γ → x ∉ Γ.dom → Wf (⟨x, Binding.ty τ⟩ :: Γ) |
64 | leanexplore_declaration | leanexplore:388187 | leanexplore_sqlite | leanexplore_declarations | | sub : Wf Γ → τ.Wf Γ → X ∉ Γ.dom → Wf (⟨X, Binding.sub τ⟩ :: Γ) |
62 | leanexplore_declaration | leanexplore:388188 | leanexplore_sqlite | leanexplore_declarations | | ty : Wf Γ → τ.Wf Γ → x ∉ Γ.dom → Wf (⟨x, Binding.ty τ⟩ :: Γ) |
215 | leanexplore_declaration | leanexplore:388189 | leanexplore_sqlite | leanexplore_declarations | /-- A well-formed context contains no duplicate keys. -/
@[scoped grind →]
lemma Env.Wf.to_ok {Γ : Env Var} (wf : Γ.Wf) : Γ✓ := by
induction wf <;> constructor <;> first | assumption | grind [List.mem_keys_of_mem] |
171 | leanexplore_declaration | leanexplore:388190 | leanexplore_sqlite | leanexplore_declarations | /-- A well-formed type is locally closed. -/
@[grind →]
theorem lc (wf : σ.Wf Γ) : σ.LC := by
induction wf with
| all => grind [LC.all (free_union Var)]
| _ => grind |
284 | leanexplore_declaration | leanexplore:388191 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under context permutation. -/
theorem perm_env (wf : σ.Wf Γ) (perm : Γ ~ Δ) (ok_Γ : Γ✓) (ok_Δ : Δ✓) : σ.Wf Δ := by
induction wf generalizing Δ with
| all => grind [all <| free_union [dom] Var, Perm.cons, nodupKeys_cons]
| _ => grind [perm_dlookup] |
382 | leanexplore_declaration | leanexplore:388192 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under context weakening (in the middle). -/
theorem weaken (wf_ΓΘ : σ.Wf (Γ ++ Θ)) (ok_ΓΔΘ : (Γ ++ Δ ++ Θ)✓) : σ.Wf (Γ ++ Δ ++ Θ) := by
generalize eq : Γ ++ Θ = ΓΔ at wf_ΓΘ
induction wf_ΓΘ generalizing Γ
case all => apply all ((Γ ++ Δ ++ Θ).dom ∪ free_union Var) <;> grind [-keys_app... |
204 | leanexplore_declaration | leanexplore:388193 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under context weakening (at the front). -/
theorem weaken_head (wf : σ.Wf Δ) (ok : (Γ ++ Δ)✓) : σ.Wf (Γ ++ Δ) := by
have : Γ ++ Δ = [] ++ Γ ++ Δ := by rfl
grind [weaken] |
103 | leanexplore_declaration | leanexplore:388194 | leanexplore_sqlite | leanexplore_declarations | theorem weaken_cons (wf : σ.Wf Δ) (ok : (⟨X, b⟩ :: Δ)✓) : σ.Wf (⟨X, b⟩:: Δ) := by
grind [weaken_head] |
654 | leanexplore_declaration | leanexplore:388195 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under context narrowing. -/
lemma narrow (wf : σ.Wf (Γ ++ ⟨X, Binding.sub τ⟩ :: Δ)) (ok : (Γ ++ ⟨X, Binding.sub τ'⟩ :: Δ)✓) :
σ.Wf (Γ ++ ⟨X, Binding.sub τ'⟩ :: Δ) := by
generalize eq : (Γ ++ ⟨X, Binding.sub τ⟩ :: Δ) = Θ at wf
induction wf generalizing Γ with
| all => apply all (... |
187 | leanexplore_declaration | leanexplore:388196 | leanexplore_sqlite | leanexplore_declarations | lemma narrow_cons (wf : σ.Wf (⟨X, Binding.sub τ⟩ :: Δ)) (ok : (⟨X, Binding.sub τ'⟩ :: Δ)✓) :
σ.Wf (⟨X, Binding.sub τ'⟩ :: Δ) := by
grind [List.nil_append (⟨X, sub τ'⟩ :: Δ), narrow] |
304 | leanexplore_declaration | leanexplore:388197 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under context strengthening. -/
lemma strengthen (wf : σ.Wf (Γ ++ ⟨X, Binding.ty τ⟩ :: Δ)) : σ.Wf (Γ ++ Δ) := by
generalize eq : Γ ++ ⟨X, Binding.ty τ⟩ :: Δ = Θ at wf
induction wf generalizing Γ with
| all => grind [all <| free_union [Context.dom] Var]
| _ => grind |
493 | leanexplore_declaration | leanexplore:388198 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under context substitution (of a well-formed type). -/
lemma map_subst (wf_σ : σ.Wf (Γ ++ ⟨X, Binding.sub τ⟩ :: Δ)) (wf_τ' : τ'.Wf Δ)
(ok : (Γ.map_val (·[X:=τ']) ++ Δ)✓) : σ[X:=τ'].Wf <| Γ.map_val (·[X:=τ']) ++ Δ := by
have := @map_val_mem Var (Binding Var)
generalize eq : Γ ++ ⟨X... |
362 | leanexplore_declaration | leanexplore:388199 | leanexplore_sqlite | leanexplore_declarations | /-- A type remains well-formed under opening (to a well-formed type). -/
lemma open_lc (ok_Γ : Γ✓) (wf_all : (Ty.all σ τ).Wf Γ) (wf_δ : δ.Wf Γ) : (τ ^ᵞ δ).Wf Γ := by
cases wf_all with | all =>
let ⟨X, _⟩ := fresh_exists <| free_union [fv, Context.dom] Var
have : Γ = Context.map_val (·[X:=δ]) [] ++ Γ := by gri... |
167 | leanexplore_declaration | leanexplore:388200 | leanexplore_sqlite | leanexplore_declarations | /-- A type bound in a context is well formed. -/
lemma of_bind_ty (wf : Γ.Wf) (bind : Binding.ty σ ∈ Γ.dlookup X) : σ.Wf Γ := by
induction wf <;> grind [weaken_head] |
160 | leanexplore_declaration | leanexplore:388201 | leanexplore_sqlite | leanexplore_declarations | /-- A type at the head of a well-formed context is well-formed. -/
lemma of_env_ty (wf : Env.Wf (⟨X, Binding.ty σ⟩ :: Γ)) : σ.Wf Γ := by
cases wf
assumption |
165 | leanexplore_declaration | leanexplore:388202 | leanexplore_sqlite | leanexplore_declarations | /-- A subtype at the head of a well-formed context is well-formed. -/
lemma of_env_sub (wf : Env.Wf (⟨X, Binding.sub σ⟩ :: Γ)) : σ.Wf Γ := by
cases wf
assumption |
297 | leanexplore_declaration | leanexplore:388203 | leanexplore_sqlite | leanexplore_declarations | /-- A variable not appearing in a context does not appear in its well-formed types. -/
lemma nmem_fv {σ : Ty Var} (wf : σ.Wf Γ) (nmem : X ∉ Γ.dom) : X ∉ σ.fv := by
induction wf with
| all => grind [fresh_exists <| free_union [dom] Var, nmem_fv_open, openRec_lc]
| _ => grind [dlookup_isSome] |
308 | leanexplore_declaration | leanexplore:388204 | leanexplore_sqlite | leanexplore_declarations | /-- A context remains well-formed under narrowing (of a well-formed subtype). -/
lemma narrow (wf_env : Env.Wf (Γ ++ ⟨X, Binding.sub τ⟩ :: Δ)) (wf_τ' : τ'.Wf Δ) :
Env.Wf (Γ ++ ⟨X, Binding.sub τ'⟩ :: Δ) := by
induction Γ <;> cases wf_env <;>
grind [Ty.Wf.narrow, eq_nil_of_append_eq_nil, cases Env.Wf] |
200 | leanexplore_declaration | leanexplore:388205 | leanexplore_sqlite | leanexplore_declarations | /-- A context remains well-formed under strengthening. -/
lemma strengthen (wf : Env.Wf <| Γ ++ ⟨X, Binding.ty τ⟩ :: Δ) : Env.Wf <| Γ ++ Δ := by
induction Γ <;> cases wf <;> grind [Ty.Wf.strengthen] |
355 | leanexplore_declaration | leanexplore:388206 | leanexplore_sqlite | leanexplore_declarations | /-- A context remains well-formed under substitution (of a well-formed type). -/
lemma map_subst (wf_env : Env.Wf (Γ ++ ⟨X, Binding.sub τ⟩ :: Δ)) (wf_τ' : τ'.Wf Δ) :
Env.Wf <| Γ.map_val (·[X:=τ']) ++ Δ := by
induction Γ generalizing wf_τ' Δ τ' <;> cases wf_env
case nil => grind
case cons.sub | cons.ty => cons... |
259 | leanexplore_declaration | leanexplore:388207 | leanexplore_sqlite | leanexplore_declarations | /-- A well-formed context is unchaged by substituting for a free key. -/
lemma map_subst_nmem (Γ : Env Var) (X : Var) (σ : Ty Var) (wf : Γ.Wf) (nmem : X ∉ Γ.dom) :
Γ = Γ.map_val (·[X:=σ]) := by
induction wf <;> grind [Ty.Wf.nmem_fv, Binding.subst_fresh] |
215 | leanexplore_declaration | leanexplore:388208 | leanexplore_sqlite | leanexplore_declarations | /-- Types of the simply typed lambda calculus. -/
inductive Ty (Base : Type v)
/-- A base type, from a typing context. -/
| base : Base → Ty Base
/-- A function type. -/
| arrow : Ty Base → Ty Base → Ty Base |
68 | leanexplore_declaration | leanexplore:388209 | leanexplore_sqlite | leanexplore_declarations | /-- A base type, from a typing context. -/
| base : Base → Ty Base |
63 | leanexplore_declaration | leanexplore:388210 | leanexplore_sqlite | leanexplore_declarations | /-- A function type. -/
| arrow : Ty Base → Ty Base → Ty Base |
855 | leanexplore_declaration | leanexplore:388211 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped infixr:70 " ⤳ " => Ty.arrow
open Ty Context
/-- An extrinsic typing derivation for locally nameless terms. -/
inductive Typing : Context Var (Ty Base) → Term Var → Ty Base → Prop
/-- Free variables, from a context judgement. -/
| var : Γ✓ → ⟨x,σ⟩ ∈ Γ → Typing Γ (fvar x) σ
/-- Lambda abstra... |
459 | leanexplore_declaration | leanexplore:388212 | leanexplore_sqlite | leanexplore_declarations | /-- An extrinsic typing derivation for locally nameless terms. -/
inductive Typing : Context Var (Ty Base) → Term Var → Ty Base → Prop
/-- Free variables, from a context judgement. -/
| var : Γ✓ → ⟨x,σ⟩ ∈ Γ → Typing Γ (fvar x) σ
/-- Lambda abstraction. -/
| abs (L : Finset Var) : (∀ x ∉ L, Typing (⟨x,σ⟩ :: Γ) (... |
95 | leanexplore_declaration | leanexplore:388213 | leanexplore_sqlite | leanexplore_declarations | /-- Free variables, from a context judgement. -/
| var : Γ✓ → ⟨x,σ⟩ ∈ Γ → Typing Γ (fvar x) σ |
124 | leanexplore_declaration | leanexplore:388214 | leanexplore_sqlite | leanexplore_declarations | /-- Lambda abstraction. -/
| abs (L : Finset Var) : (∀ x ∉ L, Typing (⟨x,σ⟩ :: Γ) (t ^ fvar x) τ) → Typing Γ t.abs (σ ⤳ τ) |
97 | leanexplore_declaration | leanexplore:388215 | leanexplore_sqlite | leanexplore_declarations | /-- Function application. -/
| app : Typing Γ t (σ ⤳ τ) → Typing Γ t' σ → Typing Γ (app t t') τ |
276 | leanexplore_declaration | leanexplore:388216 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped notation:50 Γ " ⊢ " t " ∶ " τ:arg => Typing Γ t τ
namespace Typing
variable {Γ Δ Θ : Context Var (Ty Base)}
omit [DecidableEq Var] in
/-- Typing is preserved on permuting a context. -/
theorem perm (ht : Γ ⊢ t ∶ τ) (hperm : Γ.Perm Δ) : Δ ⊢ t ∶ τ := by |
248 | leanexplore_declaration | leanexplore:388217 | leanexplore_sqlite | leanexplore_declarations | /-- Typing is preserved on permuting a context. -/
theorem perm (ht : Γ ⊢ t ∶ τ) (hperm : Γ.Perm Δ) : Δ ⊢ t ∶ τ := by
induction ht generalizing Δ
case abs ih =>
constructor
intros x mem
exact ih x mem (by simp_all)
all_goals grind |
324 | leanexplore_declaration | leanexplore:388218 | leanexplore_sqlite | leanexplore_declarations | /-- Weakening of a typing derivation with an appended context. -/
lemma weaken_aux (der : Γ ++ Δ ⊢ t ∶ τ) : (Γ ++ Θ ++ Δ)✓ → (Γ ++ Θ ++ Δ) ⊢ t ∶ τ := by
generalize eq : Γ ++ Δ = Γ_Δ at der
induction der generalizing Γ Δ Θ with
| abs xs => grind [Typing.abs (xs ∪ (Γ ++ Θ ++ Δ).dom), List.nodupKeys_cons]
| _ => g... |
183 | leanexplore_declaration | leanexplore:388219 | leanexplore_sqlite | leanexplore_declarations | /-- Weakening of a typing derivation by an additional context. -/
lemma weaken (der : Γ ⊢ t ∶ τ) (ok : (Γ ++ Δ)✓) : Γ ++ Δ ⊢ t ∶ τ := by
grind [List.append_nil (Γ ++ Δ), weaken_aux] |
196 | leanexplore_declaration | leanexplore:388220 | leanexplore_sqlite | leanexplore_declarations | /-- Typing derivations exist only for locally closed terms. -/
@[scoped grind →]
lemma lc (der : Γ ⊢ t ∶ τ) : t.LC := by
induction der <;> constructor
case abs ih => exact ih
all_goals grind |
638 | leanexplore_declaration | leanexplore:388221 | leanexplore_sqlite | leanexplore_declarations | /-- Substitution for a context weakened by a single type between appended contexts. -/
lemma subst_aux (h : Δ ++ ⟨x, σ⟩ :: Γ ⊢ t ∶ τ) (der : Γ ⊢ s ∶ σ) :
Δ ++ Γ ⊢ t[x := s] ∶ τ := by
generalize eq : Δ ++ ⟨x, σ⟩ :: Γ = Θ at h
induction h generalizing Γ Δ der
case app => grind
case var x' _ ok _ =>
subst ... |
184 | leanexplore_declaration | leanexplore:388222 | leanexplore_sqlite | leanexplore_declarations | /-- Substitution for a context weakened by a single type. -/
lemma typing_subst_head (weak : ⟨x, σ⟩ :: Γ ⊢ t ∶ τ) (der : Γ ⊢ s ∶ σ) :
Γ ⊢ (t [x := s]) ∶ τ := by
grind [subst_aux] |
303 | leanexplore_declaration | leanexplore:388223 | leanexplore_sqlite | leanexplore_declarations | /-- Typing preservation for opening. -/
theorem preservation_open {xs : Finset Var}
(cofin : ∀ x ∉ xs, ⟨x, σ⟩ :: Γ ⊢ m ^ fvar x ∶ τ) (der : Γ ⊢ n ∶ σ) :
Γ ⊢ m ^ n ∶ τ := by
have ⟨fresh, _⟩ := fresh_exists <| free_union [Term.fv] Var
grind [subst_intro fresh _ _ ?_ der.lc, typing_subst_head] |
216 | leanexplore_declaration | leanexplore:388224 | leanexplore_sqlite | leanexplore_declarations | /-- A relation on terms preserves typing if all related terms have the same type. -/
def PreservesTyping (R : Term Var → Term Var → Prop) (Base : Type v) :=
∀ {Γ t t'} {τ : Ty Base}, Γ ⊢ t ∶ τ → R t t' → Γ ⊢ t' ∶ τ |
276 | leanexplore_declaration | leanexplore:388225 | leanexplore_sqlite | leanexplore_declarations | /-- If a reduction preserves types, so does its reflexive transitive closure. -/
@[scoped grind →]
theorem redex_preservesTyping :
PreservesTyping R Base → PreservesTyping (Relation.ReflTransGen R) Base := by
intros _ _ _ _ _ _ redex
induction redex <;> [grind; aesop] |
386 | leanexplore_declaration | leanexplore:388226 | leanexplore_sqlite | leanexplore_declarations | /-- Confluence preserves type preservation. -/
theorem confluence_preservesTyping {τ : Ty Base}
(con : Confluent R) (p : PreservesTyping R Base) (der : Γ ⊢ a ∶ τ)
(ab : ReflTransGen R a b) (ac : ReflTransGen R a c) :
∃ d, ReflTransGen R b d ∧ ReflTransGen R c d ∧ Γ ⊢ d ∶ τ := by
have ⟨d, bd, cd⟩ := con ab... |
403 | leanexplore_declaration | leanexplore:388227 | leanexplore_sqlite | leanexplore_declarations | /-- Typing preservation for full beta reduction. -/
@[scoped grind →]
theorem preservation (der : Γ ⊢ t ∶ τ) (step : t ⭢βᶠ t') : Γ ⊢ t' ∶ τ := by
induction der generalizing t' <;> cases step
case abs.abs xs _ _ _ xs' _ => apply Typing.abs (free_union Var); grind
case app.base h der _ _ der_l =>
cases der_l
... |
725 | leanexplore_declaration | leanexplore:388228 | leanexplore_sqlite | leanexplore_declarations | /-- A typed term either full beta reduces or is a value. -/
theorem progress {t : Term Var} {τ : Ty Base} (ht : [] ⊢ t ∶ τ) : t.Value ∨ ∃ t', t ⭢βᶠ t' := by
generalize eq : [] = Γ at ht
induction ht
case var => simp_all
case abs xs mem ih =>
left
constructor
apply Term.LC.abs xs
intros _ mem'
... |
530 | leanexplore_declaration | leanexplore:388229 | leanexplore_sqlite | leanexplore_declarations | /-- A set of terms is called saturated if it
1. only contains locally closed terms,
2. only contains strongly normalizing terms,
3. contains all neutral locally closed terms, and
4. is closed under top-level β-reduction of the form (λ M) N P₁ … Pₙ → M ^ N P₁ … Pₙ.
-/
@[scoped grind]
structure Saturated... |
515 | leanexplore_declaration | leanexplore:388230 | leanexplore_sqlite | leanexplore_declarations | /-- The semantic map maps each type to a corresponding saturated set of terms.
For the strong normalization proof to work, we must ensure that
Γ ⊢ t ∶ τ implies that t is in the set of terms corresponding to τ.
Strong normalization later follows from the fact that terms in saturated
sets are strongly n... |
504 | leanexplore_declaration | leanexplore:388231 | leanexplore_sqlite | leanexplore_declarations | /-- The sets constructed by semanticMap are saturated -/
lemma semanticMap_saturated (τ : Ty Base) : @Saturated Var (semanticMap τ) := by
induction τ with
| base => grind [sn_abs_app_multiApp, sn_neutral, open_abs_lc]
| arrow τ₁ τ₂ ih₁ ih₂ =>
constructor
· grind [ih₁.neutal_lc (fvar <| fresh {}) (.fvar <|... |
276 | leanexplore_declaration | leanexplore:388232 | leanexplore_sqlite | leanexplore_declarations | /-- The `entails_context` predicate ensures that each variable in the context
is mapped to a term in the corresponding semantic map. -/
abbrev entails_context (E : Term.Env Var) (Γ : Context Var (Ty Base)) :=
∀ {x τ}, ⟨x, τ⟩ ∈ Γ → (multiSubst E (fvar x)) ∈ semanticMap τ |
209 | leanexplore_declaration | leanexplore:388233 | leanexplore_sqlite | leanexplore_declarations | /-- The empty context is entailed by any environment. -/
lemma entails_context_empty {Γ : Context Var (Ty Base)} : entails_context [] Γ := by
have := semanticMap_saturated (Var := Var) (Base := Base)
grind |
555 | leanexplore_declaration | leanexplore:388234 | leanexplore_sqlite | leanexplore_declarations | /-- The `entails_context` predicate is preserved when extending the context
with a new variable, provided the new variable is fresh and its
substitution is in the corresponding semantic map. -/
lemma entails_context_cons (E : Term.Env Var) (Γ : Context Var (Ty Base))
(x : Var) (τ : Ty Base) (sub : Term Var)... |
276 | leanexplore_declaration | leanexplore:388235 | leanexplore_sqlite | leanexplore_declarations | /-- The `entails` predicate states that a term `t` is
semantically valid with respect to a context `Γ` and a type `τ` -/
abbrev entails (Γ : Context Var (Ty Base)) (t : Term Var) (τ : Ty Base) :=
∀ E, env_LC E → (entails_context E Γ) → (multiSubst E t) ∈ semanticMap τ |
779 | leanexplore_declaration | leanexplore:388236 | leanexplore_sqlite | leanexplore_declarations | /-- The `soundness` lemma states that if a term `t` has type `τ` in context `Γ`,
then `t` is semantically valid with respect to `Γ` and `τ` -/
lemma soundness {Γ : Context Var (Ty Base)} (derivation_t : Γ ⊢ t ∶ τ) : entails Γ t τ := by
induction derivation_t with
| var Γ xσ_mem_Γ => grind
| @abs σ Γ t τ L HL ... |
339 | leanexplore_declaration | leanexplore:388237 | leanexplore_sqlite | leanexplore_declarations | /-- Using soundness and the fact that the empty context
is entailed by any environment, we can conclude that
a well-typed term is strongly normalizing. -/
theorem strong_norm {t : Term Var} {τ : Ty Base} (der : Γ ⊢ t ∶ τ) : SN t := by
apply (semanticMap_saturated τ).sn
apply (soundness der [] (by grind) ent... |
425 | leanexplore_declaration | leanexplore:388238 | leanexplore_sqlite | leanexplore_declarations | /-- Syntax of locally nameless lambda terms, with free variables over `Var`. -/
inductive Term (Var : Type u)
/-- Bound variables that appear under a lambda abstraction, using a de-Bruijn index. -/
| bvar : ℕ → Term Var
/-- Free variables. -/
| fvar : Var → Term Var
/-- Lambda abstraction, introducing a new bound varia... |
109 | leanexplore_declaration | leanexplore:388239 | leanexplore_sqlite | leanexplore_declarations | /-- Bound variables that appear under a lambda abstraction, using a de-Bruijn index. -/
| bvar : ℕ → Term Var |
46 | leanexplore_declaration | leanexplore:388240 | leanexplore_sqlite | leanexplore_declarations | /-- Free variables. -/
| fvar : Var → Term Var |
89 | leanexplore_declaration | leanexplore:388241 | leanexplore_sqlite | leanexplore_declarations | /-- Lambda abstraction, introducing a new bound variable. -/
| abs : Term Var → Term Var |
68 | leanexplore_declaration | leanexplore:388242 | leanexplore_sqlite | leanexplore_declarations | /-- Function application. -/
| app : Term Var → Term Var → Term Var |
285 | leanexplore_declaration | leanexplore:388243 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening of the ith bound variable. -/
@[scoped grind =]
def openRec (i : ℕ) (sub : Term Var) : Term Var → Term Var
| bvar i' => if i = i' then sub else bvar i'
| fvar x => fvar x
| app l r => app (openRec i sub l) (openRec i sub r)
| abs M => abs <| openRec (i+1) sub M |
159 | leanexplore_declaration | leanexplore:388244 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped notation:68 e "⟦" i " ↝ " sub "⟧"=> Term.openRec i sub e
lemma openRec_bvar : (bvar i')⟦i ↝ s⟧ = if i = i' then s else bvar i' := by rfl |
79 | leanexplore_declaration | leanexplore:388245 | leanexplore_sqlite | leanexplore_declarations | lemma openRec_bvar : (bvar i')⟦i ↝ s⟧ = if i = i' then s else bvar i' := by rfl |
55 | leanexplore_declaration | leanexplore:388246 | leanexplore_sqlite | leanexplore_declarations | lemma openRec_fvar : (fvar x)⟦i ↝ s⟧ = fvar x := by rfl |
74 | leanexplore_declaration | leanexplore:388247 | leanexplore_sqlite | leanexplore_declarations | lemma openRec_app : (app l r)⟦i ↝ s⟧ = app (l⟦i ↝ s⟧) (r⟦i ↝ s⟧) := by rfl |
61 | leanexplore_declaration | leanexplore:388248 | leanexplore_sqlite | leanexplore_declarations | lemma openRec_abs : M.abs⟦i ↝ s⟧ = M⟦i + 1 ↝ s⟧.abs := by rfl |
109 | leanexplore_declaration | leanexplore:388249 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening of the closest binding. -/
@[scoped grind =]
def open' {X} (e u):= @Term.openRec X 0 u e |
579 | leanexplore_declaration | leanexplore:388250 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped infixr:80 " ^ " => Term.open'
/-- Variable closing, replacing a free `fvar x` with `bvar k` -/
@[scoped grind =]
def closeRec (k : ℕ) (x : Var) : Term Var → Term Var
| fvar x' => if x = x' then bvar k else fvar x'
| bvar i => bvar i
| app l r => app (closeRec k x l) (closeRec k x r)
| abs t =>... |
293 | leanexplore_declaration | leanexplore:388251 | leanexplore_sqlite | leanexplore_declarations | /-- Variable closing, replacing a free `fvar x` with `bvar k` -/
@[scoped grind =]
def closeRec (k : ℕ) (x : Var) : Term Var → Term Var
| fvar x' => if x = x' then bvar k else fvar x'
| bvar i => bvar i
| app l r => app (closeRec k x l) (closeRec k x r)
| abs t => abs <| closeRec (k+1) x t |
231 | leanexplore_declaration | leanexplore:388252 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped notation:68 e "⟦" k " ↜ " x "⟧"=> Term.closeRec k x e
variable {x : Var}
/-- Variable closing of the closest binding. -/
@[scoped grind =]
def close {Var} [DecidableEq Var] (e u):= @Term.closeRec Var _ 0 u e |
134 | leanexplore_declaration | leanexplore:388253 | leanexplore_sqlite | leanexplore_declarations | /-- Variable closing of the closest binding. -/
@[scoped grind =]
def close {Var} [DecidableEq Var] (e u):= @Term.closeRec Var _ 0 u e |
187 | leanexplore_declaration | leanexplore:388254 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped infixr:80 " ^* " => Term.close
/-- Substitution of a free variable to a term. -/
@[scoped grind =]
def subst (m : Term Var) (x : Var) (sub : Term Var) : Term Var := |
304 | leanexplore_declaration | leanexplore:388255 | leanexplore_sqlite | leanexplore_declarations | /-- Substitution of a free variable to a term. -/
@[scoped grind =]
def subst (m : Term Var) (x : Var) (sub : Term Var) : Term Var :=
match m with
| bvar i => bvar i
| fvar x' => if x = x' then sub else fvar x'
| app l r => app (l.subst x sub) (r.subst x sub)
| abs M => abs <| M.subst x sub |
197 | leanexplore_declaration | leanexplore:388256 | leanexplore_sqlite | leanexplore_declarations | /-- `Term.subst` is a substitution for λ-terms. Gives access to the notation `m[x := n]`. -/
instance instHasSubstitutionTerm : HasSubstitution (Term Var) Var (Term Var) where
subst := Term.subst |
161 | leanexplore_declaration | leanexplore:388257 | leanexplore_sqlite | leanexplore_declarations | /-- Free variables of a term. -/
@[simp, scoped grind =]
def fv : Term Var → Finset Var
| bvar _ => {}
| fvar x => {x}
| abs e1 => e1.fv
| app l r => l.fv ∪ r.fv |
212 | leanexplore_declaration | leanexplore:388258 | leanexplore_sqlite | leanexplore_declarations | /-- Locally closed terms. -/
inductive LC : Term Var → Prop
| fvar (x : Var) : LC (fvar x)
| abs (L : Finset Var) (e : Term Var) : (∀ x ∉ L, LC (e ^ fvar x)) → LC (abs e)
| app {l r} : l.LC → r.LC → LC (app l r) |
79 | leanexplore_declaration | leanexplore:388260 | leanexplore_sqlite | leanexplore_declarations | | abs (L : Finset Var) (e : Term Var) : (∀ x ∉ L, LC (e ^ fvar x)) → LC (abs e) |
40 | leanexplore_declaration | leanexplore:388261 | leanexplore_sqlite | leanexplore_declarations | | app {l r} : l.LC → r.LC → LC (app l r) |
116 | leanexplore_declaration | leanexplore:388262 | leanexplore_sqlite | leanexplore_declarations | /-- Values are irreducible terms. -/
inductive Value : Term Var → Prop
| abs (e : Term Var) : e.abs.LC → e.abs.Value |
45 | leanexplore_declaration | leanexplore:388263 | leanexplore_sqlite | leanexplore_declarations | | abs (e : Term Var) : e.abs.LC → e.abs.Value |
56 | leanexplore_declaration | leanexplore:388264 | leanexplore_sqlite | leanexplore_declarations | lemma closeRec_bvar : (bvar i)⟦k ↜ x⟧ = bvar i := by rfl |
85 | leanexplore_declaration | leanexplore:388265 | leanexplore_sqlite | leanexplore_declarations | lemma closeRec_fvar : (fvar x')⟦k ↜ x⟧ = if x = x' then bvar k else fvar x' := by rfl |
75 | leanexplore_declaration | leanexplore:388266 | leanexplore_sqlite | leanexplore_declarations | lemma closeRec_app : (app l r)⟦k ↜ x⟧ = app (l⟦k ↜ x⟧) (r⟦k ↜ x⟧) := by rfl |
62 | leanexplore_declaration | leanexplore:388267 | leanexplore_sqlite | leanexplore_declarations | lemma closeRec_abs : t.abs⟦k ↜ x⟧ = t⟦k + 1 ↜ x⟧.abs := by rfl |
65 | leanexplore_declaration | leanexplore:388268 | leanexplore_sqlite | leanexplore_declarations | lemma subst_bvar : (bvar i : Term Var)[x := n] = bvar i := by rfl |
78 | leanexplore_declaration | leanexplore:388269 | leanexplore_sqlite | leanexplore_declarations | lemma subst_fvar : (fvar x')[x := n] = if x = x' then n else fvar x' := by rfl |
92 | leanexplore_declaration | leanexplore:388270 | leanexplore_sqlite | leanexplore_declarations | lemma subst_app {l r : Term Var} : (app l r)[x := n] = app (l[x := n]) (r[x := n]) := by rfl |
72 | leanexplore_declaration | leanexplore:388271 | leanexplore_sqlite | leanexplore_declarations | lemma subst_abs {M : Term Var} : M.abs[x := n] = M[x := n].abs := by rfl |
91 | leanexplore_declaration | leanexplore:388272 | leanexplore_sqlite | leanexplore_declarations | lemma subst_def (m : Term Var) (x : Var) (n : Term Var) : m.subst x n = m[x := n] := by rfl |
494 | leanexplore_declaration | leanexplore:388273 | leanexplore_sqlite | leanexplore_declarations | /-- Congruence closure of a relation. -/
inductive Xi (R : Term Var → Term Var → Prop) : Term Var → Term Var → Prop
/-- The base relation. -/
| base : R M N → Xi R M N
/-- Left congruence rule for application. -/
| appL: LC Z → Xi R M N → Xi R (app Z M) (app Z N)
/-- Right congruence rule for application. -/
| appR : L... |
51 | leanexplore_declaration | leanexplore:388274 | leanexplore_sqlite | leanexplore_declarations | /-- The base relation. -/
| base : R M N → Xi R M N |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.