Untyped λ-calculus #
Note that we are not using simp
or aesop
in this file, even though our code is written in a
style that is compatible with these tactics. This is because we want to keep the proofs as explicit
as possible, for educational purposes.
Equations
- Untyped.instReprΛ = { reprPrec := Untyped.reprΛ✝ }
Equations
- Untyped.instOrdΛ = { compare := Untyped.ordΛ✝ }
Equations
Equations
Instances For
Equations
- Untyped.Λ.instToString = { toString := Untyped.Λ.toString }
Equations
- Untyped.Λ.instCoeName = { coe := Untyped.Λ.var }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Untyped.Λ.«term_∙_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_∙_ 100 100 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ∙ ") (Lean.ParserDescr.cat `term 101))
Instances For
Equations
- (Untyped.Λ.var a).size = 1
- (a ∙ a_1).size = 1 + a.size + a_1.size
- (Untyped.Λ.abs a a_1).size = 1 + a_1.size
Instances For
Equations
- Untyped.Λ.instSizeOf = { sizeOf := Untyped.Λ.size }
Equations
- (Untyped.Λ.var a).Sub = {Untyped.Λ.var a}
- (a ∙ a_1).Sub = a ∙ a_1 ::ₘ (a.Sub + a_1.Sub)
- (Untyped.Λ.abs a a_1).Sub = Untyped.Λ.abs a a_1 ::ₘ a_1.Sub
Instances For
Equations
- Untyped.Λ.instHasSubset = { Subset := Untyped.Λ.Subterm }
Equations
Equations
Equations
Equations
Equations
Equations
Equations
- Untyped.Λ.instDecidableSubterm = inferInstanceAs (Decidable (M ∈ N.Sub))
Equations
- Untyped.Λ.instDecidableSubset = inferInstanceAs (Decidable (M ∈ N.Sub))
Equations
- Untyped.Λ.instHasSSubset = { SSubset := Untyped.Λ.ProperSubterm }
Equations
- (Untyped.Λ.var a).FV = {a}
- (a ∙ a_1).FV = a.FV ∪ a_1.FV
- (Untyped.Λ.abs a a_1).FV = a_1.FV \ {a}
Instances For
Equations
- Untyped.Λ.instDecidableClosed = inferInstanceAs (Decidable (M.FV = ∅))
Equations
- (Untyped.Λ.var a).hasBindingVar x = False
- (a ∙ a_1).hasBindingVar x = (a.hasBindingVar x ∨ a_1.hasBindingVar x)
- (Untyped.Λ.abs a a_1).hasBindingVar x = (x = a ∨ a_1.hasBindingVar x)
Instances For
Equations
- (Untyped.Λ.var a).hasDecHasBindingVar x = isFalse ⋯
- (a ∙ a_1).hasDecHasBindingVar x = match a.hasDecHasBindingVar x, a_1.hasDecHasBindingVar x with | isTrue hP, x_1 => isTrue ⋯ | x_1, isTrue hQ => isTrue ⋯ | isFalse hP, isFalse hQ => isFalse ⋯
- (Untyped.Λ.abs a a_1).hasDecHasBindingVar x = if h : x = a then isTrue ⋯ else match a_1.hasDecHasBindingVar x with | isTrue hQ => isTrue ⋯ | isFalse hQ => isFalse ⋯
Instances For
Equations
- (Untyped.Λ.var a).rename x y = if a = x then Untyped.Λ.var y else Untyped.Λ.var a
- (a ∙ a_1).rename x y = a.rename x y ∙ a_1.rename x y
- (Untyped.Λ.abs a a_1).rename x y = if a_1.hasBindingVar y ∨ y ∈ a_1.FV then Untyped.Λ.abs a a_1 else if a = x then Untyped.Λ.abs y (a_1.rename x y) else Untyped.Λ.abs a (a_1.rename x y)
Instances For
- rename: ∀ (x y : Name) (M : Untyped.Λ), y ∉ M.FV → ¬M.hasBindingVar y → (Untyped.Λ.abs x M).Renaming (Untyped.Λ.abs y (M.rename x y))
Instances For
@[simp]
theorem
Untyped.Λ.renaming_rename
{x : Name}
{y : Name}
{M : Untyped.Λ}
{hfv : y ∉ M.FV}
{hnb : ¬M.hasBindingVar y}
:
(Untyped.Λ.abs x M).Renaming (Untyped.Λ.abs y (M.rename x y))
- rename: ∀ {M N : Untyped.Λ}, M.Renaming N → M =α N
- compatAppLeft: ∀ {L M N : Untyped.Λ}, M =α N → M ∙ L =α N ∙ L
- compatAppRight: ∀ {L M N : Untyped.Λ}, M =α N → L ∙ M =α L ∙ N
- compatAbs: ∀ {z : Name} {M N : Untyped.Λ}, M =α N → Untyped.Λ.abs z M =α Untyped.Λ.abs z N
- refl: ∀ (M : Untyped.Λ), M =α M
- symm: ∀ {M N : Untyped.Λ}, M =α N → N =α M
- trans: ∀ {L M N : Untyped.Λ}, L =α M → M =α N → L =α N
Instances For
Equations
- Untyped.Λ.«term_=α_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_=α_ 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " =α ") (Lean.ParserDescr.cat `term 51))
Instances For
@[simp]
@[simp]
theorem
Untyped.Λ.alpha_eq_compat_abs
{M : Untyped.Λ}
{N : Untyped.Λ}
{z : Name}
(h : M =α N)
:
Untyped.Λ.abs z M =α Untyped.Λ.abs z N
Equations
Equations
Equations
@[reducible, inline]
Equations
Instances For
Equations
- Untyped.Λ.gensym = getModify Nat.succ <&> toString
Instances For
@[irreducible]
Equations
- One or more equations did not get rendered due to their size.
- (Untyped.Λ.var a).substGensym x N = pure (if x = a then N else Untyped.Λ.var a)
- (a ∙ a_1).substGensym x N = Seq.seq (Untyped.Λ.app <$> a.substGensym x N) fun (x_1 : Unit) => a_1.substGensym x N
Instances For
Equations
- t.substGensym' x N = StateT.run' (t.substGensym x N) 0
Instances For
Equations
- (Untyped.Λ.var a).subst x N = if x = a then N else Untyped.Λ.var a
- (a ∙ a_1).subst x N = a.subst x N ∙ a_1.subst x N
- (Untyped.Λ.abs a a_1).subst x N = if x = a ∨ a ∈ N.FV then Untyped.Λ.abs a a_1 else Untyped.Λ.abs a (a_1.subst x N)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
theorem
Untyped.Λ.modulo_alpha_eq_abs
{M : Untyped.Λ}
{N : Untyped.Λ}
{x : Name}
(h : M =α N)
:
Untyped.Λ.abs x M =α Untyped.Λ.abs x N
Equations
- (Untyped.Λ.abs x M ∙ N).reduceβ = M.subst x N
- (M ∙ N).reduceβ = M.reduceβ ∙ N.reduceβ
- (Untyped.Λ.abs y N).reduceβ = Untyped.Λ.abs y N.reduceβ
- (Untyped.Λ.var name).reduceβ = Untyped.Λ.var name
Instances For
- redex: ∀ {x : Name} (M N : Untyped.Λ), Untyped.Λ.abs x M ∙ N →β M.subst x N
- compatAppLeft: ∀ {L M N : Untyped.Λ}, M →β N → M ∙ L →β N ∙ L
- compatAppRight: ∀ {L M N : Untyped.Λ}, M →β N → L ∙ M →β L ∙ N
- compatAbs: ∀ {x : Name} {M N : Untyped.Λ}, M →β N → Untyped.Λ.abs x M →β Untyped.Λ.abs x N
Instances For
Equations
- Untyped.Λ.«term_→β_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_→β_ 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " →β ") (Lean.ParserDescr.cat `term 51))
Instances For
Equations
- Untyped.Λ.«term_←β_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_←β_ 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ←β ") (Lean.ParserDescr.cat `term 51))
Instances For
@[simp]
theorem
Untyped.Λ.beta_redex
{x : Name}
{M : Untyped.Λ}
{N : Untyped.Λ}
:
Untyped.Λ.abs x M ∙ N →β M.subst x N
@[simp]
theorem
Untyped.Λ.beta_compat_abs
{x : Name}
{M : Untyped.Λ}
{N : Untyped.Λ}
(h : M →β N)
:
Untyped.Λ.abs x M →β Untyped.Λ.abs x N
@[reducible, inline]
Instances For
Equations
- Untyped.Λ.«term_↠β_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_↠β_ 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ↠β ") (Lean.ParserDescr.cat `term 51))
Instances For
Equations
- Untyped.Λ.«term_↞β_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_↞β_ 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ↞β ") (Lean.ParserDescr.cat `term 51))
Instances For
Equations
- Untyped.Λ.«term_=β_» = Lean.ParserDescr.trailingNode `Untyped.Λ.term_=β_ 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " =β ") (Lean.ParserDescr.cat `term 51))
Instances For
Equations
Equations
Equations
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
- (Untyped.Λ.var a).hasDecIsNormalForm = isTrue ⋯
- (Untyped.Λ.abs a a_1).hasDecIsNormalForm = a_1.hasDecIsNormalForm
Instances For
Equations
- Untyped.Λ.instDecidableInNormalForm = M.hasDecIsNormalForm
Equations
- t.reduceβAll = Untyped.Λ.reduceβAll.loop t t.size
Instances For
Equations
- Untyped.Λ.reduceβAll.loop x 0 = x
- Untyped.Λ.reduceβAll.loop x n.succ = if x.reduceβ.inNormalForm then x.reduceβ else Untyped.Λ.reduceβAll.loop x.reduceβ n
Instances For
@[reducible, inline]
Instances For
Equations
- M.isStronglyNormalizing = Acc Untyped.Λ.Beta M
Instances For
Equations
- (Untyped.Λ.abs param (Untyped.Λ.abs param_1 t)).toNat? = Untyped.Λ.toNat?.loop t
- x.toNat? = none
Instances For
Equations
- Untyped.Λ.toNat?.loop (Untyped.Λ.var name) = some 0
- Untyped.Λ.toNat?.loop (Untyped.Λ.var name ∙ e') = match Untyped.Λ.toNat?.loop e' with | some n => some (n + 1) | none => none
- Untyped.Λ.toNat?.loop e = none
Instances For
Equations
- (Untyped.Λ.abs x_1 (Untyped.Λ.abs y (Untyped.Λ.var z))).toBool? = if x_1 = z then some true else if y = z then some false else none
- x.toBool? = none
Instances For
Equations
- M.toBool! = M.toBool?.getD default
Instances For
Equations
- Untyped.Λ.Combinators.Ω = Untyped.Λ.abs "x" (Untyped.Λ.var "x" ∙ Untyped.Λ.var "x") ∙ Untyped.Λ.abs "x" (Untyped.Λ.var "x" ∙ Untyped.Λ.var "x")
Instances For
Equations
- Untyped.Λ.Combinators.Δ = Untyped.Λ.abs "x" (Untyped.Λ.var "x" ∙ Untyped.Λ.var "x" ∙ Untyped.Λ.var "x")
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Untyped.Λ.Combinators.S = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.abs "z" (Untyped.Λ.var "x" ∙ Untyped.Λ.var "z" ∙ (Untyped.Λ.var "y" ∙ Untyped.Λ.var "z"))))
Instances For
Equations
- Untyped.Λ.Combinators.K = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.var "x"))
Instances For
Equations
- Untyped.Λ.Combinators.I = Untyped.Λ.abs "x" (Untyped.Λ.var "x")
Instances For
Equations
- Untyped.Λ.Combinators.B = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.abs "z" (Untyped.Λ.var "x" ∙ (Untyped.Λ.var "y" ∙ Untyped.Λ.var "z"))))
Instances For
Equations
- Untyped.Λ.Combinators.C = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.abs "z" (Untyped.Λ.var "x" ∙ Untyped.Λ.var "z" ∙ Untyped.Λ.var "y")))
Instances For
Equations
- Untyped.Λ.Combinators.W = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.var "x" ∙ Untyped.Λ.var "y" ∙ Untyped.Λ.var "y"))
Instances For
Equations
- Untyped.Λ.Combinators.zero = Untyped.Λ.abs "f" (Untyped.Λ.abs "x" (Untyped.Λ.var "x"))
Instances For
Equations
- Untyped.Λ.Combinators.one = Untyped.Λ.abs "f" (Untyped.Λ.abs "x" (Untyped.Λ.var "f" ∙ Untyped.Λ.var "x"))
Instances For
Equations
- Untyped.Λ.Combinators.two = Untyped.Λ.abs "f" (Untyped.Λ.abs "x" (Untyped.Λ.var "f" ∙ (Untyped.Λ.var "f" ∙ Untyped.Λ.var "x")))
Instances For
Equations
- Untyped.Λ.Combinators.three = Untyped.Λ.abs "f" (Untyped.Λ.abs "x" (Untyped.Λ.var "f" ∙ (Untyped.Λ.var "f" ∙ (Untyped.Λ.var "f" ∙ Untyped.Λ.var "x"))))
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Untyped.Λ.Combinators.suc = Untyped.Λ.abs "m" (Untyped.Λ.abs "f" (Untyped.Λ.abs "x" (Untyped.Λ.var "f" ∙ (Untyped.Λ.var "m" ∙ Untyped.Λ.var "f" ∙ Untyped.Λ.var "x"))))
Instances For
Equations
- Untyped.Λ.Combinators.true = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.var "x"))
Instances For
Equations
- Untyped.Λ.Combinators.false = Untyped.Λ.abs "x" (Untyped.Λ.abs "y" (Untyped.Λ.var "y"))