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 |
|---|---|---|---|---|---|
104 | leanexplore_declaration | leanexplore:387955 | leanexplore_sqlite | leanexplore_declarations | /-- Find the minimal root of `fNat` above a number n -/
def RFindAbove : SKI := RFindAboveAux.fixedPoint |
983 | leanexplore_declaration | leanexplore:387956 | leanexplore_sqlite | leanexplore_declarations | theorem RFindAbove_correct (fNat : Nat → Nat) (f x : SKI)
(hf : ∀ i : Nat, ∀ y : SKI, IsChurch i y → IsChurch (fNat i) (f ⬝ y))
(n m : Nat) (hx : IsChurch m x) (hroot : fNat (m+n) = 0) (hpos : ∀ i < n, fNat (m+i) ≠ 0) :
IsChurch (m+n) (RFindAbove ⬝ x ⬝ f) := by
induction n generalizing m x
all_goals ap... |
90 | leanexplore_declaration | leanexplore:387957 | leanexplore_sqlite | leanexplore_declarations | /-- Ordinary root finding is root finding above zero -/
def RFind := RFindAbove ⬝ SKI.Zero |
365 | leanexplore_declaration | leanexplore:387958 | leanexplore_sqlite | leanexplore_declarations | theorem RFind_correct (fNat : Nat → Nat) (f : SKI)
(hf : ∀ (i : Nat) (y : SKI), IsChurch i y → IsChurch (fNat i) (f ⬝ y))
(n : Nat) (hroot : fNat n = 0) (hpos : ∀ i < n, fNat i ≠ 0) : IsChurch n (RFind ⬝ f) := by
have :_ := RFindAbove_correct (n := n) (fNat := fNat) (hf := hf) (hx := zero_correct)
simp_rw [... |
87 | leanexplore_declaration | leanexplore:387959 | leanexplore_sqlite | leanexplore_declarations | /-- Addition: λ n m. n Succ m -/
def AddPoly : SKI.Polynomial 2 := &0 ⬝' SKI.Succ ⬝' &1 |
95 | leanexplore_declaration | leanexplore:387960 | leanexplore_sqlite | leanexplore_declarations | /-- A term representing addition on church numerals -/
protected def Add : SKI := AddPoly.toSKI |
110 | leanexplore_declaration | leanexplore:387961 | leanexplore_sqlite | leanexplore_declarations | theorem add_def (a b : SKI) : (SKI.Add ⬝ a ⬝ b) ↠ a ⬝ SKI.Succ ⬝ b :=
AddPoly.toSKI_correct [a, b] (by simp) |
481 | leanexplore_declaration | leanexplore:387962 | leanexplore_sqlite | leanexplore_declarations | theorem add_correct (n m : Nat) (a b : SKI) (ha : IsChurch n a) (hb : IsChurch m b) :
IsChurch (n + m) (SKI.Add ⬝ a ⬝ b) := by
refine isChurch_trans (n + m) (a' := Church n SKI.Succ b) ?_ ?_
· calc
_ ↠ a ⬝ SKI.Succ ⬝ b := add_def a b
_ ↠ Church n SKI.Succ b := ha SKI.Succ b
· clear ha
induction n ... |
112 | leanexplore_declaration | leanexplore:387963 | leanexplore_sqlite | leanexplore_declarations | /-- Multiplication: λ n m. n (Add m) Zero -/
def MulPoly : SKI.Polynomial 2 := &0 ⬝' (SKI.Add ⬝' &1) ⬝' SKI.Zero |
101 | leanexplore_declaration | leanexplore:387964 | leanexplore_sqlite | leanexplore_declarations | /-- A term representing multiplication on church numerals -/
protected def Mul : SKI := MulPoly.toSKI |
122 | leanexplore_declaration | leanexplore:387965 | leanexplore_sqlite | leanexplore_declarations | theorem mul_def (a b : SKI) : (SKI.Mul ⬝ a ⬝ b) ↠ a ⬝ (SKI.Add ⬝ b) ⬝ SKI.Zero :=
MulPoly.toSKI_correct [a, b] (by simp) |
537 | leanexplore_declaration | leanexplore:387966 | leanexplore_sqlite | leanexplore_declarations | theorem mul_correct {n m : Nat} {a b : SKI} (ha : IsChurch n a) (hb : IsChurch m b) :
IsChurch (n * m) (SKI.Mul ⬝ a ⬝ b) := by
refine isChurch_trans (n * m) (a' := Church n (SKI.Add ⬝ b) SKI.Zero) ?_ ?_
· exact Trans.trans (mul_def a b) (ha (SKI.Add ⬝ b) SKI.Zero)
· clear ha
induction n with
| zero ... |
86 | leanexplore_declaration | leanexplore:387967 | leanexplore_sqlite | leanexplore_declarations | /-- Subtraction: λ n m. n Pred m -/
def SubPoly : SKI.Polynomial 2 := &1 ⬝' Pred ⬝' &0 |
98 | leanexplore_declaration | leanexplore:387968 | leanexplore_sqlite | leanexplore_declarations | /-- A term representing subtraction on church numerals -/
protected def Sub : SKI := SubPoly.toSKI |
106 | leanexplore_declaration | leanexplore:387969 | leanexplore_sqlite | leanexplore_declarations | theorem sub_def (a b : SKI) : (SKI.Sub ⬝ a ⬝ b) ↠ b ⬝ Pred ⬝ a :=
SubPoly.toSKI_correct [a, b] (by simp) |
459 | leanexplore_declaration | leanexplore:387970 | leanexplore_sqlite | leanexplore_declarations | theorem sub_correct (n m : Nat) (a b : SKI) (ha : IsChurch n a) (hb : IsChurch m b) :
IsChurch (n - m) (SKI.Sub ⬝ a ⬝ b) := by
refine isChurch_trans (n - m) (a' := Church m Pred a) ?_ ?_
· calc
_ ↠ b ⬝ Pred ⬝ a := sub_def a b
_ ↠ Church m Pred a := hb Pred a
· clear hb
induction m with
| zer... |
124 | leanexplore_declaration | leanexplore:387971 | leanexplore_sqlite | leanexplore_declarations | /-- Comparison: (. ≤ .) := λ n m. IsZero ⬝ (Sub ⬝ n ⬝ m) -/
def LEPoly : SKI.Polynomial 2 := IsZero ⬝' (SKI.Sub ⬝' &0 ⬝' &1) |
95 | leanexplore_declaration | leanexplore:387972 | leanexplore_sqlite | leanexplore_declarations | /-- A term representing comparison on church numerals -/
protected def LE : SKI := LEPoly.toSKI |
117 | leanexplore_declaration | leanexplore:387973 | leanexplore_sqlite | leanexplore_declarations | theorem le_def (a b : SKI) : (SKI.LE ⬝ a ⬝ b) ↠ IsZero ⬝ (SKI.Sub ⬝ a ⬝ b) :=
LEPoly.toSKI_correct [a, b] (by simp) |
321 | leanexplore_declaration | leanexplore:387974 | leanexplore_sqlite | leanexplore_declarations | theorem le_correct (n m : Nat) (a b : SKI) (ha : IsChurch n a) (hb : IsChurch m b) :
IsBool (n ≤ m) (SKI.LE ⬝ a ⬝ b) := by
simp only [← decide_eq_decide.mpr <| Nat.sub_eq_zero_iff_le]
apply isBool_trans (a' := IsZero ⬝ (SKI.Sub ⬝ a ⬝ b)) (h := le_def _ _)
apply isZero_correct
apply sub_correct <;> assumptio... |
265 | leanexplore_declaration | leanexplore:387975 | leanexplore_sqlite | leanexplore_declarations | /-- Inner condition for Sqrt: with &0 = n, &1 = k,
computes `if n < (k+1)² then 0 else 1`. -/
def SqrtCondPoly : SKI.Polynomial 2 :=
SKI.Cond ⬝' SKI.Zero ⬝' SKI.One
⬝' (SKI.Neg ⬝' (SKI.LE ⬝' (SKI.Mul ⬝' (SKI.Succ ⬝' &1) ⬝' (SKI.Succ ⬝' &1)) ⬝' &0)) |
88 | leanexplore_declaration | leanexplore:387976 | leanexplore_sqlite | leanexplore_declarations | /-- SKI term for the inner condition of Sqrt -/
def SqrtCond : SKI := SqrtCondPoly.toSKI |
374 | leanexplore_declaration | leanexplore:387977 | leanexplore_sqlite | leanexplore_declarations | /-- `SqrtCond ⬝ n ⬝ k` reduces to: return 0 if `(k+1)² > n`, else 1.
Used by `RFind` to locate the smallest such `k`, which is `√n`. -/
theorem sqrtCond_def (cn ck : SKI) :
(SqrtCond ⬝ cn ⬝ ck) ↠
SKI.Cond ⬝ SKI.Zero ⬝ SKI.One ⬝
(SKI.Neg ⬝ (SKI.LE ⬝ (SKI.Mul ⬝ (SKI.Succ ⬝ ck) ⬝ (SKI.Succ ⬝ ck)) ⬝ c... |
182 | leanexplore_declaration | leanexplore:387978 | leanexplore_sqlite | leanexplore_declarations | /-- Sqrt n = smallest k such that (k+1)² > n, i.e., the integer square root.
Defined as `λ n. RFind (SqrtCond n)`. -/
def SqrtPoly : SKI.Polynomial 1 := RFind ⬝' (SqrtCond ⬝' &0) |
72 | leanexplore_declaration | leanexplore:387979 | leanexplore_sqlite | leanexplore_declarations | /-- SKI term for integer square root -/
def Sqrt : SKI := SqrtPoly.toSKI |
197 | leanexplore_declaration | leanexplore:387980 | leanexplore_sqlite | leanexplore_declarations | /-- `Sqrt ⬝ n` reduces to an `RFind` search for the smallest `k` with `(k+1)² > n`. -/
theorem sqrt_def (cn : SKI) : (Sqrt ⬝ cn) ↠ RFind ⬝ (SqrtCond ⬝ cn) :=
SqrtPoly.toSKI_correct [cn] (by simp) |
721 | leanexplore_declaration | leanexplore:387981 | leanexplore_sqlite | leanexplore_declarations | /-- `Sqrt` correctly computes `Nat.sqrt`. -/
theorem sqrt_correct (n : Nat) (cn : SKI) (hcn : IsChurch n cn) :
IsChurch (Nat.sqrt n) (Sqrt ⬝ cn) := by
apply isChurch_trans _ (sqrt_def cn)
apply RFind_correct (fun k => if n < (k + 1) * (k + 1) then 0 else 1) (SqrtCond ⬝ cn)
· -- SqrtCond ⬝ cn correctly compute... |
337 | leanexplore_declaration | leanexplore:387982 | leanexplore_sqlite | leanexplore_declarations | /-- NatPair a b = if a < b then b*b + a else a*a + a + b.
With &0 = a, &1 = b. The condition `a < b` is `¬(b ≤ a)`. -/
def NatPairPoly : SKI.Polynomial 2 :=
SKI.Cond ⬝' (SKI.Add ⬝' (SKI.Mul ⬝' &1 ⬝' &1) ⬝' &0)
⬝' (SKI.Add ⬝' (SKI.Add ⬝' (SKI.Mul ⬝' &0 ⬝' &0) ⬝' &0) ⬝' &1)
⬝' (SKI.Neg ⬝' (SKI... |
70 | leanexplore_declaration | leanexplore:387983 | leanexplore_sqlite | leanexplore_declarations | /-- SKI term for Nat pairing -/
def NatPair : SKI := NatPairPoly.toSKI |
366 | leanexplore_declaration | leanexplore:387984 | leanexplore_sqlite | leanexplore_declarations | /-- `NatPair ⬝ a ⬝ b` reduces to: if `a < b` then `b² + a`, else `a² + a + b`. -/
theorem natPair_def (ca cb : SKI) :
(NatPair ⬝ ca ⬝ cb) ↠
SKI.Cond ⬝ (SKI.Add ⬝ (SKI.Mul ⬝ cb ⬝ cb) ⬝ ca)
⬝ (SKI.Add ⬝ (SKI.Add ⬝ (SKI.Mul ⬝ ca ⬝ ca) ⬝ ca) ⬝ cb)
⬝ (SKI.Neg ⬝ (SKI.LE ⬝ cb ⬝ ca)) :=
... |
540 | leanexplore_declaration | leanexplore:387985 | leanexplore_sqlite | leanexplore_declarations | /-- `NatPair` correctly computes `Nat.pair`. -/
theorem natPair_correct (a b : Nat) (ca cb : SKI)
(ha : IsChurch a ca) (hb : IsChurch b cb) :
IsChurch (Nat.pair a b) (NatPair ⬝ ca ⬝ cb) := by
simp only [Nat.pair]
apply isChurch_trans _ (natPair_def ca cb)
have hcond := neg_correct _ _ (le_correct b a cb c... |
292 | leanexplore_declaration | leanexplore:387986 | leanexplore_sqlite | leanexplore_declarations | /-- `NatUnpairLeft n = if n - s² < s then n - s² else s` where `s = Nat.sqrt n`. -/
def NatUnpairLeftPoly : SKI.Polynomial 1 :=
let s := Sqrt ⬝' &0
let s2 := SKI.Mul ⬝' s ⬝' s
let diff := SKI.Sub ⬝' &0 ⬝' s2
let cond := SKI.Neg ⬝' (SKI.LE ⬝' s ⬝' diff)
SKI.Cond ⬝' diff ⬝' s ⬝' cond |
100 | leanexplore_declaration | leanexplore:387987 | leanexplore_sqlite | leanexplore_declarations | /-- SKI term for left projection of Nat.unpair -/
def NatUnpairLeft : SKI := NatUnpairLeftPoly.toSKI |
454 | leanexplore_declaration | leanexplore:387988 | leanexplore_sqlite | leanexplore_declarations | /-- `NatUnpairLeft ⬝ n` reduces to: let `s = √n` and `d = n - s²`;
return `d` if `d < s`, else `s`. -/
theorem natUnpairLeft_def (cn : SKI) :
(NatUnpairLeft ⬝ cn) ↠
SKI.Cond ⬝ (SKI.Sub ⬝ cn ⬝ (SKI.Mul ⬝ (Sqrt ⬝ cn) ⬝ (Sqrt ⬝ cn)))
⬝ (Sqrt ⬝ cn)
⬝ (SKI.Neg ⬝ (SKI.LE ⬝ (Sqrt ⬝ ... |
486 | leanexplore_declaration | leanexplore:387989 | leanexplore_sqlite | leanexplore_declarations | /-- `NatUnpairLeft` correctly computes the first component of `Nat.unpair`. -/
theorem natUnpairLeft_correct (n : Nat) (cn : SKI) (hcn : IsChurch n cn) :
IsChurch (Nat.unpair n).1 (NatUnpairLeft ⬝ cn) := by
apply isChurch_trans _ (natUnpairLeft_def cn)
obtain ⟨hs, hdiff⟩ := natUnpair_church n cn hcn
have hcon... |
309 | leanexplore_declaration | leanexplore:387990 | leanexplore_sqlite | leanexplore_declarations | /-- NatUnpairRight n = let s = sqrt n in if n - s² < s then s else n - s² - s. -/
def NatUnpairRightPoly : SKI.Polynomial 1 :=
let s := Sqrt ⬝' &0
let s2 := SKI.Mul ⬝' s ⬝' s
let diff := SKI.Sub ⬝' &0 ⬝' s2
let cond := SKI.Neg ⬝' (SKI.LE ⬝' s ⬝' diff)
SKI.Cond ⬝' s ⬝' (SKI.Sub ⬝' diff ⬝' s) ⬝' cond |
103 | leanexplore_declaration | leanexplore:387991 | leanexplore_sqlite | leanexplore_declarations | /-- SKI term for right projection of Nat.unpair -/
def NatUnpairRight : SKI := NatUnpairRightPoly.toSKI |
516 | leanexplore_declaration | leanexplore:387992 | leanexplore_sqlite | leanexplore_declarations | /-- `NatUnpairRight ⬝ n` reduces to: let `s = √n` and `d = n - s²`;
return `s` if `d < s`, else `d - s`. -/
theorem natUnpairRight_def (cn : SKI) :
(NatUnpairRight ⬝ cn) ↠
SKI.Cond ⬝ (Sqrt ⬝ cn)
⬝ (SKI.Sub ⬝ (SKI.Sub ⬝ cn ⬝ (SKI.Mul ⬝ (Sqrt ⬝ cn) ⬝ (Sqrt ⬝ cn)))
... |
480 | leanexplore_declaration | leanexplore:387993 | leanexplore_sqlite | leanexplore_declarations | /-- `NatUnpairRight` correctly computes the second component of `Nat.unpair`. -/
theorem natUnpairRight_correct (n : Nat) (cn : SKI) (hcn : IsChurch n cn) :
IsChurch (Nat.unpair n).2 (NatUnpairRight ⬝ cn) := by
apply isChurch_trans _ (natUnpairRight_def cn)
obtain ⟨hs, hdiff⟩ := natUnpair_church n cn hcn
have... |
139 | leanexplore_declaration | leanexplore:387994 | leanexplore_sqlite | leanexplore_declarations | /-- A typing context is a list of free variables and corresponding types. -/
abbrev Context (α : Type u) (β : Type v) := List ((_ : α) × β) |
148 | leanexplore_declaration | leanexplore:387995 | leanexplore_sqlite | leanexplore_declarations | /-- The domain of a context is the finite set of free variables it uses. -/
@[simp, grind =]
def dom (Γ : Context α β) : Finset α := Γ.keys.toFinset |
55 | leanexplore_declaration | leanexplore:387996 | leanexplore_sqlite | leanexplore_declarations | instance : HasWellFormed (Context α β) :=
⟨NodupKeys⟩ |
92 | leanexplore_declaration | leanexplore:387997 | leanexplore_sqlite | leanexplore_declarations | @[scoped grind _=_]
theorem haswellformed_def (Γ : Context α β) : Γ✓ = Γ.NodupKeys := by rfl |
162 | leanexplore_declaration | leanexplore:387998 | leanexplore_sqlite | leanexplore_declarations | /-- A mapping of values within a context. -/
@[simp, scoped grind]
def map_val (f : β → β) (Γ : Context α β) : Context α β :=
Γ.map (fun ⟨var,ty⟩ => ⟨var,f ty⟩) |
143 | leanexplore_declaration | leanexplore:387999 | leanexplore_sqlite | leanexplore_declarations | /-- A mapping of values preserves keys. -/
@[scoped grind .]
lemma map_val_keys (f) : Γ.keys = (Γ.map_val f).keys := by
induction Γ <;> grind |
148 | leanexplore_declaration | leanexplore:388000 | leanexplore_sqlite | leanexplore_declarations | /-- A mapping of values maps lookups. -/
lemma map_val_mem (mem : σ ∈ Γ.dlookup x) (f) : f σ ∈ (Γ.map_val f).dlookup x := by
induction Γ <;> grind |
500 | leanexplore_declaration | leanexplore:388001 | leanexplore_sqlite | leanexplore_declarations | /-- Types of the polymorphic lambda calculus. -/
inductive Ty (Var : Type*)
/-- The type ⊤, with a single inhabitant. -/
| top : Ty Var
/-- Bound variables that appear in a type, using a de-Bruijn index. -/
| bvar : ℕ → Ty Var
/-- Free type variables. -/
| fvar : Var → Ty Var
/-- A function type. -/
| a... |
61 | leanexplore_declaration | leanexplore:388002 | leanexplore_sqlite | leanexplore_declarations | /-- The type ⊤, with a single inhabitant. -/
| top : Ty Var |
92 | leanexplore_declaration | leanexplore:388003 | leanexplore_sqlite | leanexplore_declarations | /-- Bound variables that appear in a type, using a de-Bruijn index. -/
| bvar : ℕ → Ty Var |
51 | leanexplore_declaration | leanexplore:388004 | leanexplore_sqlite | leanexplore_declarations | /-- Free type variables. -/
| fvar : Var → Ty Var |
60 | leanexplore_declaration | leanexplore:388005 | leanexplore_sqlite | leanexplore_declarations | /-- A function type. -/
| arrow : Ty Var → Ty Var → Ty Var |
69 | leanexplore_declaration | leanexplore:388006 | leanexplore_sqlite | leanexplore_declarations | /-- A universal quantification. -/
| all : Ty Var → Ty Var → Ty Var |
53 | leanexplore_declaration | leanexplore:388007 | leanexplore_sqlite | leanexplore_declarations | /-- A sum type. -/
| sum : Ty Var → Ty Var → Ty Var |
924 | leanexplore_declaration | leanexplore:388010 | leanexplore_sqlite | leanexplore_declarations | /-- Syntax of locally nameless lambda terms, with free variables over `Var`. -/
inductive Term (Var : Type*)
/-- Bound term variables that appear under a lambda abstraction, using a de-Bruijn index. -/
| bvar : ℕ → Term Var
/-- Free term variables. -/
| fvar : Var → Term Var
/-- Lambda abstraction, introducin... |
116 | leanexplore_declaration | leanexplore:388011 | leanexplore_sqlite | leanexplore_declarations | /-- Bound term variables that appear under a lambda abstraction, using a de-Bruijn index. -/
| bvar : ℕ → Term Var |
53 | leanexplore_declaration | leanexplore:388012 | leanexplore_sqlite | leanexplore_declarations | /-- Free term variables. -/
| fvar : Var → Term Var |
104 | leanexplore_declaration | leanexplore:388013 | leanexplore_sqlite | leanexplore_declarations | /-- Lambda abstraction, introducing a new bound term variable. -/
| abs : Ty Var → Term Var → Term Var |
69 | leanexplore_declaration | leanexplore:388014 | leanexplore_sqlite | leanexplore_declarations | /-- Function application. -/
| app : Term Var → Term Var → Term Var |
103 | leanexplore_declaration | leanexplore:388015 | leanexplore_sqlite | leanexplore_declarations | /-- Type abstraction, introducing a new bound type variable. -/
| tabs : Ty Var → Term Var → Term Var |
64 | leanexplore_declaration | leanexplore:388016 | leanexplore_sqlite | leanexplore_declarations | /-- Type application. -/
| tapp : Term Var → Ty Var → Term Var |
67 | leanexplore_declaration | leanexplore:388017 | leanexplore_sqlite | leanexplore_declarations | /-- Binding of a term. -/
| let' : Term Var → Term Var → Term Var |
63 | leanexplore_declaration | leanexplore:388018 | leanexplore_sqlite | leanexplore_declarations | /-- Left constructor of a sum. -/
| inl : Term Var → Term Var |
64 | leanexplore_declaration | leanexplore:388019 | leanexplore_sqlite | leanexplore_declarations | /-- Right constructor of a sum. -/
| inr : Term Var → Term Var |
83 | leanexplore_declaration | leanexplore:388020 | leanexplore_sqlite | leanexplore_declarations | /-- Case matching on a sum. -/
| case : Term Var → Term Var → Term Var → Term Var |
188 | leanexplore_declaration | leanexplore:388021 | leanexplore_sqlite | leanexplore_declarations | /-- A context binding. -/
inductive Binding (Var : Type*)
/-- Subtype binding. -/
| sub : Ty Var → Binding Var
/-- Type binding. -/
| ty : Ty Var → Binding Var
deriving Inhabited |
54 | leanexplore_declaration | leanexplore:388022 | leanexplore_sqlite | leanexplore_declarations | /-- Subtype binding. -/
| sub : Ty Var → Binding Var |
50 | leanexplore_declaration | leanexplore:388023 | leanexplore_sqlite | leanexplore_declarations | /-- Type binding. -/
| ty : Ty Var → Binding Var |
166 | leanexplore_declaration | leanexplore:388026 | leanexplore_sqlite | leanexplore_declarations | /-- Free variables of a type. -/
@[scoped grind =]
def Ty.fv : Ty Var → Finset Var
| top | bvar _ => {}
| fvar X => {X}
| arrow σ τ | all σ τ | sum σ τ => σ.fv ∪ τ.fv |
118 | leanexplore_declaration | leanexplore:388027 | leanexplore_sqlite | leanexplore_declarations | /-- Free variables of a binding. -/
@[scoped grind =]
def Binding.fv : Binding Var → Finset Var
| sub σ | ty σ => σ.fv |
300 | leanexplore_declaration | leanexplore:388028 | leanexplore_sqlite | leanexplore_declarations | /-- Free type variables of a term. -/
@[scoped grind =]
def Term.fv_ty : Term Var → Finset Var
| bvar _ | fvar _ => {}
| abs σ t₁ | tabs σ t₁ | tapp t₁ σ => σ.fv ∪ t₁.fv_ty
| inl t₁ | inr t₁ => t₁.fv_ty
| app t₁ t₂ | let' t₁ t₂ => t₁.fv_ty ∪ t₂.fv_ty
| case t₁ t₂ t₃ => t₁.fv_ty ∪ t₂.fv_ty ∪ t₃.fv_ty |
288 | leanexplore_declaration | leanexplore:388029 | leanexplore_sqlite | leanexplore_declarations | /-- Free term variables of a term. -/
@[scoped grind =]
def Term.fv_tm : Term Var → Finset Var
| bvar _ => {}
| fvar x => {x}
| abs _ t₁ | tabs _ t₁ | tapp t₁ _ | inl t₁ | inr t₁ => t₁.fv_tm
| app t₁ t₂ | let' t₁ t₂ => t₁.fv_tm ∪ t₂.fv_tm
| case t₁ t₂ t₃ => t₁.fv_tm ∪ t₂.fv_tm ∪ t₃.fv_tm |
83 | leanexplore_declaration | leanexplore:388030 | leanexplore_sqlite | leanexplore_declarations | /-- A context of bindings. -/
abbrev Env (Var : Type*) := Context Var (Binding Var) |
371 | leanexplore_declaration | leanexplore:388031 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening (type opening to type) of the ith bound variable. -/
@[scoped grind =]
def openRec (X : ℕ) (δ : Ty Var) : Ty Var → Ty Var
| top => top
| bvar Y => if X = Y then δ else bvar Y
| fvar X => fvar X
| arrow σ τ => arrow (openRec X δ σ) (openRec X δ τ)
| all σ τ => all (openRec X δ σ) (openRec (X + 1) δ ... |
202 | leanexplore_declaration | leanexplore:388032 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped notation:68 γ "⟦" X " ↝ " δ "⟧ᵞ"=> openRec X δ γ
/-- Variable opening (type opening to type) of the closest binding. -/
@[scoped grind =]
def open' (γ δ : Ty Var) := openRec 0 δ γ |
130 | leanexplore_declaration | leanexplore:388033 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening (type opening to type) of the closest binding. -/
@[scoped grind =]
def open' (γ δ : Ty Var) := openRec 0 δ γ |
753 | leanexplore_declaration | leanexplore:388034 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped infixr:80 " ^ᵞ " => open'
/-- Locally closed types. -/
inductive LC : Ty Var → Prop
| top : LC top
| var : LC (fvar X)
| arrow : LC σ → LC τ → LC (arrow σ τ)
| all (L : Finset Var) : LC σ → (∀ X ∉ L, LC (τ ^ᵞ fvar X)) → LC (all σ τ)
| sum : LC σ → LC τ → LC (sum σ τ)
attribute [scoped ... |
251 | leanexplore_declaration | leanexplore:388035 | leanexplore_sqlite | leanexplore_declarations | /-- Locally closed types. -/
inductive LC : Ty Var → Prop
| top : LC top
| var : LC (fvar X)
| arrow : LC σ → LC τ → LC (arrow σ τ)
| all (L : Finset Var) : LC σ → (∀ X ∉ L, LC (τ ^ᵞ fvar X)) → LC (all σ τ)
| sum : LC σ → LC τ → LC (sum σ τ) |
74 | leanexplore_declaration | leanexplore:388039 | leanexplore_sqlite | leanexplore_declarations | | all (L : Finset Var) : LC σ → (∀ X ∉ L, LC (τ ^ᵞ fvar X)) → LC (all σ τ) |
305 | leanexplore_declaration | leanexplore:388041 | leanexplore_sqlite | leanexplore_declarations | /-- Type substitution. -/
@[scoped grind =]
def subst (X : Var) (δ : Ty Var) : Ty Var → Ty Var
| top => top
| bvar J => bvar J
| fvar Y => if Y = X then δ else fvar Y
| arrow σ τ => arrow (subst X δ σ) (subst X δ τ)
| all σ τ => all (subst X δ σ) (subst X δ τ)
| sum σ τ => sum (subst X δ σ) (subst X δ τ) |
86 | leanexplore_declaration | leanexplore:388042 | leanexplore_sqlite | leanexplore_declarations | instance : HasSubstitution (Ty Var) Var (Ty Var) where
subst γ X δ := Ty.subst X δ γ |
234 | leanexplore_declaration | leanexplore:388043 | leanexplore_sqlite | leanexplore_declarations | /-- An opening appearing in both sides of an equality of types can be removed. -/
lemma openRec_neq_eq {σ τ γ : Ty Var} (neq : X ≠ Y) (h : σ⟦Y ↝ τ⟧ᵞ = σ⟦Y ↝ τ⟧ᵞ⟦X ↝ γ⟧ᵞ) :
σ = σ⟦X ↝ γ⟧ᵞ := by induction σ generalizing Y X <;> grind |
235 | leanexplore_declaration | leanexplore:388044 | leanexplore_sqlite | leanexplore_declarations | /-- A locally closed type is unchanged by opening. -/
lemma openRec_lc {σ τ : Ty Var} (lc : σ.LC) : σ = σ⟦X ↝ τ⟧ᵞ := by
induction lc generalizing X with
| all => grind [fresh_exists <| free_union Var, openRec_neq_eq]
| _ => grind |
104 | leanexplore_declaration | leanexplore:388045 | leanexplore_sqlite | leanexplore_declarations | @[scoped grind _=_]
lemma subst_def : Ty.subst (X : Var) (δ : Ty Var) (γ : Ty Var) = γ[X := δ] := by rfl |
176 | leanexplore_declaration | leanexplore:388046 | leanexplore_sqlite | leanexplore_declarations | /-- Substitution of a free variable not present in a type leaves it unchanged. -/
lemma subst_fresh (nmem : X ∉ γ.fv) (δ : Ty Var) : γ = γ[X := δ] := by
induction γ <;> grind |
247 | leanexplore_declaration | leanexplore:388047 | leanexplore_sqlite | leanexplore_declarations | /-- Substitution of a locally closed type distributes with opening. -/
lemma openRec_subst (Y : ℕ) (σ τ : Ty Var) (lc : δ.LC) (X : Var) :
(σ⟦Y ↝ τ⟧ᵞ)[X := δ] = σ[X := δ]⟦Y ↝ τ[X := δ]⟧ᵞ := by
induction σ generalizing Y <;> grind [openRec_lc] |
186 | leanexplore_declaration | leanexplore:388048 | leanexplore_sqlite | leanexplore_declarations | /-- Specialize `Ty.openRec_subst` to the first opening. -/
lemma open_subst (σ τ : Ty Var) (lc : δ.LC) (X : Var) : (σ ^ᵞ τ)[X := δ] = σ[X := δ] ^ᵞ τ[X := δ]
:= openRec_subst 0 σ τ lc X |
189 | leanexplore_declaration | leanexplore:388049 | leanexplore_sqlite | leanexplore_declarations | /-- Specialize `Ty.subst_open` to free variables. -/
lemma open_subst_var (σ : Ty Var) (neq : Y ≠ X) (lc : δ.LC) :
(σ ^ᵞ fvar Y)[X := δ] = (σ[X := δ]) ^ᵞ fvar Y := by grind [open_subst] |
241 | leanexplore_declaration | leanexplore:388050 | leanexplore_sqlite | leanexplore_declarations | /-- Opening to a type is equivalent to opening to a free variable and substituting. -/
lemma openRec_subst_intro (Y : ℕ) (δ : Ty Var) (nmem : X ∉ γ.fv) :
γ⟦Y ↝ δ⟧ᵞ = (γ⟦Y ↝ fvar X⟧ᵞ)[X := δ] := by
induction γ generalizing δ Y <;> grind |
185 | leanexplore_declaration | leanexplore:388051 | leanexplore_sqlite | leanexplore_declarations | /-- Specialize `Ty.openRec_subst_intro` to the first opening. -/
lemma open_subst_intro (δ : Ty Var) (nmem : X ∉ γ.fv) : γ ^ᵞ δ = (γ ^ᵞ fvar X)[X := δ] :=
openRec_subst_intro _ _ nmem |
184 | leanexplore_declaration | leanexplore:388052 | leanexplore_sqlite | leanexplore_declarations | lemma subst_lc (σ_lc : σ.LC) (τ_lc : τ.LC) (X : Var) : σ[X := τ].LC := by
induction σ_lc with
| all => grind [LC.all (free_union Var), openRec_subst]
| _ => grind [openRec_subst] |
105 | leanexplore_declaration | leanexplore:388053 | leanexplore_sqlite | leanexplore_declarations | lemma nmem_fv_openRec (nmem : X ∉ (σ⟦k ↝ γ⟧ᵞ).fv) : X ∉ σ.fv := by
induction σ generalizing k <;> grind |
92 | leanexplore_declaration | leanexplore:388054 | leanexplore_sqlite | leanexplore_declarations | lemma nmem_fv_open (nmem : X ∉ (σ ^ᵞ γ).fv) : X ∉ σ.fv :=
Ty.nmem_fv_openRec (k := 0) nmem |
623 | leanexplore_declaration | leanexplore:388055 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening (term opening to type) of the ith bound variable. -/
@[scoped grind =]
def openRec_ty (X : ℕ) (δ : Ty Var) : Term Var → Term Var
| bvar x => bvar x
| fvar x => fvar x
| abs σ t₁ => abs (σ⟦X ↝ δ⟧ᵞ) (openRec_ty X δ t₁)
| app t₁ t₂ => app (openRec_ty X δ t₁) (openRec_ty X δ t₂)
| tabs σ t₁ => tabs (σ⟦... |
224 | leanexplore_declaration | leanexplore:388056 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped notation:68 t "⟦" X " ↝ " δ "⟧ᵗᵞ"=> openRec_ty X δ t
/-- Variable opening (term opening to type) of the closest binding. -/
@[scoped grind =]
def open_ty (t : Term Var) (δ : Ty Var) := openRec_ty 0 δ t |
148 | leanexplore_declaration | leanexplore:388057 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening (term opening to type) of the closest binding. -/
@[scoped grind =]
def open_ty (t : Term Var) (δ : Ty Var) := openRec_ty 0 δ t |
907 | leanexplore_declaration | leanexplore:388058 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped infixr:80 " ^ᵗᵞ " => open_ty
/-- Variable opening (term opening to term) of the ith bound variable. -/
@[scoped grind =]
def openRec_tm (x : ℕ) (s : Term Var) : Term Var → Term Var
| bvar y => if x = y then s else (bvar y)
| fvar x => fvar x
| abs σ t₁ => abs σ (openRec_tm (x + 1) s t₁)
| app t₁ ... |
636 | leanexplore_declaration | leanexplore:388059 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening (term opening to term) of the ith bound variable. -/
@[scoped grind =]
def openRec_tm (x : ℕ) (s : Term Var) : Term Var → Term Var
| bvar y => if x = y then s else (bvar y)
| fvar x => fvar x
| abs σ t₁ => abs σ (openRec_tm (x + 1) s t₁)
| app t₁ t₂ => app (openRec_tm x s t₁) (openRec_tm x s t₂)
| ... |
217 | leanexplore_declaration | leanexplore:388060 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped notation:68 t "⟦" x " ↝ " s "⟧ᵗᵗ"=> openRec_tm x s t
/-- Variable opening (term opening to term) of the closest binding. -/
@[scoped grind =]
def open_tm (t₁ t₂ : Term Var) := openRec_tm 0 t₂ t₁ |
141 | leanexplore_declaration | leanexplore:388061 | leanexplore_sqlite | leanexplore_declarations | /-- Variable opening (term opening to term) of the closest binding. -/
@[scoped grind =]
def open_tm (t₁ t₂ : Term Var) := openRec_tm 0 t₂ t₁ |
1,011 | leanexplore_declaration | leanexplore:388062 | leanexplore_sqlite | leanexplore_declarations | @[inherit_doc]
scoped infixr:80 " ^ᵗᵗ " => open_tm
/-- Locally closed terms. -/
inductive LC : Term Var → Prop
| var : LC (fvar x)
| abs (L : Finset Var) : σ.LC → (∀ x ∉ L, LC (t₁ ^ᵗᵗ fvar x)) → LC (abs σ t₁)
| app : LC t₁ → LC t₂ → LC (app t₁ t₂)
| tabs (L : Finset Var) : σ.LC → (∀ X ∉ L, LC (t₁ ^ᵗᵞ .fvar X))... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.