Denotational semantics of the simply typed lambda calculus
DefinitionDenotation of simple types#✓fully proved
Given an interpretation \(I\) assigning a type \(I(b)\) to each base type \(b\), the denotation \([\![A]\!]_I\) of a simple type \(A\) is defined by recursion on \(A\): a base type \(b\) denotes \(I(b)\), and a function type \(A \Rightarrow B\) denotes the type of all functions from \([\![A]\!]_I\) to \([\![B]\!]_I\).
def denote (I : Base → Type v) : Ty Base → Type v
| .base b => I b
| .arr A B => denote I A → denote I B
inductive Ty (Base : Type u) where
| base : Base → Ty Base
| arr : Ty Base → Ty Base → Ty Base
deriving DecidableEq, Repr
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:36
Uses 1 · Used by 40
AbbreviationSemantic environments for the denotational semantics of STLC#✓fully proved
Given an interpretation \(I\) assigning a type to each base type and a typing context \(\Gamma\) (a list of simple types), an environment for \(\Gamma\) assigns to every variable \(x\) of \(\Gamma\), of any simple type \(A\), an element of the denotation \([\![A]\!]_I\).
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
inductive Ty (Base : Type u) where
| base : Base → Ty Base
| arr : Ty Base → Ty Base → Ty Base
deriving DecidableEq, Repr
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:36
inductive Var {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| zero {A : Ty Base} {Γ : List (Ty Base)} : Var (A :: Γ) A
| succ {A B : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Var (B :: Γ) A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:56
def denote (I : Base → Type v) : Ty Base → Type v
| .base b => I b
| .arr A B => denote I A → denote I B
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:51
Uses 3 · Used by 43
DefinitionExtending a semantic environment in STLC#✓fully proved
Given an interpretation \(I\) of the base types, a value \(a\) in the denotation of a type \(A\) and an environment \(\eta\) for a context \(\Gamma\), the extended environment for the context \(A :: \Gamma\) sends the newest variable to \(a\) and the successor \(\mathrm{succ}\,x\) of each variable \(x\) of \(\Gamma\) to \(\eta(x)\).
def cons (a : Ty.denote I A) (η : Env I Γ) : Env I (A :: Γ)
| _, .zero => a
| _, .succ x => η x
def denote (I : Base → Type v) : Ty Base → Type v
| .base b => I b
| .arr A B => denote I A → denote I B
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:51
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
Uses 4 · Used by 14
DefinitionRenaming an environment#✓fully proved
Given a renaming \(\rho\) from context \(\Gamma\) to context \(\Delta\) (a type-preserving map from the variables of \(\Gamma\) to those of \(\Delta\)) and an environment \(\eta\) for \(\Delta\), the renamed environment for \(\Gamma\) sends each variable \(x\) of \(\Gamma\) to \(\eta(\rho(x))\); that is, it is the composite \(\eta \circ \rho\).
def rename (ρ : Ren Γ Δ) (η : Env I Δ) : Env I Γ := fun x ↦ η (ρ x)
abbrev Ren {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Var Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:71
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
Uses 4 · Used by 8
DefinitionDenotation of an STLC term#✓fully proved
Given an interpretation \(I\) of the base types, the denotation of a well-typed term \(t\) of type \(A\) in context \(\Gamma\) in an environment \(\eta\) for \(\Gamma\) is the element of the denotation of \(A\) defined by recursion on \(t\): a variable \(x\) denotes \(\eta(x)\), an application \(f\,a\) denotes the denotation of \(f\) applied to the denotation of \(a\) (both in \(\eta\)), and an abstraction \(\lambda.\,b\) denotes the function sending each value \(a\) of its argument type to the denotation of the body \(b\) in \(\eta\) extended by \(a\) for the newest variable.
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
inductive Ty (Base : Type u) where
| base : Base → Ty Base
| arr : Ty Base → Ty Base → Ty Base
deriving DecidableEq, Repr
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:36
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : Ty Base → Type v
| .base b => I b
| .arr A B => denote I A → denote I B
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:51
def cons (a : Ty.denote I A) (η : Env I Γ) : Env I (A :: Γ)
| _, .zero => a
| _, .succ x => η x
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:69
Uses 6 · Used by 35
TheoremRenaming lemma for STLC denotation#✓fully proved
For every interpretation \(I\) of the base types, every type-preserving renaming \(\rho\) from context \(\Gamma\) to context \(\Delta\), every term \(t\) in context \(\Gamma\) and every environment \(\eta\) for \(\Delta\), the denotation in \(\eta\) of the term obtained by renaming the variables of \(t\) along \(\rho\) equals the denotation of \(t\) in the environment that sends each variable \(x\) of \(\Gamma\) to \(\eta(\rho(x))\).
theorem denote_rename (I : Base → Type v) (ρ : Ren Γ Δ) (t : Tm Γ A) (η : Env I Δ) :
denote I (rename ρ t) η = denote I t (Env.rename ρ η)
abbrev Ren {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Var Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:71
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
def rename : {Γ Δ : List (Ty Base)} → Ren Γ Δ → {A : Ty Base} → Tm Γ A → Tm Δ A
| _, _, ρ, _, .var x => .var (ρ x)
| _, _, ρ, _, .app f a => .app (rename ρ f) (rename ρ a)
| _, _, ρ, _, .lam body => .lam (rename (Var.lift ρ) body)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:105
def rename (ρ : Ren Γ Δ) (η : Env I Δ) : Env I Γ := fun x ↦ η (ρ x)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:79
Uses 11 · Used by 5
TheoremWeakening preserves STLC denotation#✓fully proved
For every interpretation \(I\) of the base types, every term \(t\) of type \(A\) in context \(\Gamma\), every type \(B\), every value \(a\) in the denotation of \(B\) and every environment \(\eta\) for \(\Gamma\), the weakening of \(t\) to the context \(B :: \Gamma\) has, in the environment that extends \(\eta\) by \(a\) for the newest variable, the same denotation as \(t\) in \(\eta\).
theorem denote_weaken (I : Base → Type v) (t : Tm Γ A) (a : Ty.denote I B) (η : Env I Γ) :
denote I (weaken (B := B) t) (Env.cons a η) = denote I t η
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def denote (I : Base → Type v) : Ty Base → Type v
| .base b => I b
| .arr A B => denote I A → denote I B
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:51
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
def weaken (t : Tm Γ A) : Tm (B :: Γ) A := rename .succ t
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:156
def cons (a : Ty.denote I A) (η : Env I Γ) : Env I (A :: Γ)
| _, .zero => a
| _, .succ x => η x
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:69
Uses 11 · Used by 4
DefinitionDenotation of an STLC substitution#✓fully proved
Given an interpretation \(I\) of the base types, a type-preserving substitution \(\sigma\) mapping each variable of a context \(\Gamma\) to a term in a context \(\Delta\), and an environment \(\eta\) for \(\Delta\), this is the environment for \(\Gamma\) that sends each variable \(x\) to the denotation of \(\sigma(x)\) in \(\eta\).
def denoteSub (I : Base → Type v) (σ : Sub Γ Δ) (η : Env I Δ) : Env I Γ :=
fun x ↦ denote I (σ x) η
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
TheoremSubstitution lemma for STLC denotation#✓fully proved
For every interpretation \(I\) of the base types, every type-preserving substitution \(\sigma\) mapping each variable of a context \(\Gamma\) to a term in a context \(\Delta\), every term \(t\) in context \(\Gamma\) and every environment \(\eta\) for \(\Delta\), the denotation in \(\eta\) of \(t\) with \(\sigma\) applied simultaneously to its variables equals the denotation of \(t\) in the environment that sends each variable \(x\) of \(\Gamma\) to the denotation of \(\sigma(x)\) in \(\eta\).
theorem denote_subst (I : Base → Type v) (σ : Sub Γ Δ) (t : Tm Γ A) (η : Env I Δ) :
denote I (subst σ t) η = denote I t (denoteSub I σ η)
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
def subst : {Γ Δ : List (Ty Base)} → Sub Γ Δ → {A : Ty Base} → Tm Γ A → Tm Δ A
| _, _, σ, _, .var x => σ x
| _, _, σ, _, .app f a => .app (subst σ f) (subst σ a)
| _, _, σ, _, .lam body => .lam (subst (Sub.lift σ) body)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:74
def denoteSub (I : Base → Type v) (σ : Sub Γ Δ) (η : Env I Δ) : Env I Γ :=
fun x ↦ denote I (σ x) η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:124
Uses 12 · Used by 3
TheoremDenotation of an instantiated STLC body#✓fully proved
For every interpretation \(I\) of the base types, every term \(b\) of type \(B\) in context \(A :: \Gamma\), every term \(a\) of type \(A\) in context \(\Gamma\) and every environment \(\eta\) for \(\Gamma\), the denotation in \(\eta\) of \(b\) with its newest variable replaced by \(a\) equals the denotation of \(b\) in the environment that extends \(\eta\) by the denotation of \(a\) in \(\eta\) for the newest variable.
theorem denote_instantiate (I : Base → Type v) (body : Tm (A :: Γ) B) (a : Tm Γ A)
(η : Env I Γ) :
denote I (instantiate body a) η = denote I body (Env.cons (denote I a η) η)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
def instantiate (body : Tm (A :: Γ) B) (a : Tm Γ A) : Tm Γ B :=
subst (Sub.single a) body
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:124
def cons (a : Ty.denote I A) (η : Env I Γ) : Env I (A :: Γ)
| _, .zero => a
| _, .succ x => η x
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:69
Uses 12 · Used by 2
TheoremOne reduction step preserves STLC denotation#✓fully proved
For every interpretation \(I\) of the base types, if a term \(t\) reduces to \(t'\) in one step of call-by-value reduction, then \(t\) and \(t'\) have the same denotation in every environment \(\eta\) for their context.
theorem denote_eq (I : Base → Type v) {t t' : Tm Γ A} (h : Step t t') (η : Env I Γ) :
Tm.denote I t η = Tm.denote I t' η
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
inductive Step {Base : Type u} : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Tm Γ A → Prop where
| appFun {A B : Ty Base} {Γ : List (Ty Base)} {f f' : Tm Γ (A ⇒ B)} {a : Tm Γ A} :
Step f f' → Step (.app f a) (.app f' a)
| appArg {A B : Ty Base} {Γ : List (Ty Base)} {f : Tm Γ (A ⇒ B)} {a a' : Tm Γ A} :
Value f → Step a a' → Step (.app f a) (.app f a')
| beta {A B : Ty Base} {Γ : List (Ty Base)} {body : Tm (A :: Γ) B} {a : Tm Γ A} :
Value a → Step (.app (.lam body) a) (Tm.instantiate body a)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Semantics.lean:43
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
Uses 10 · Used by 2
TheoremMulti-step reduction preserves STLC denotation#✓fully proved
For every interpretation \(I\) of the base types, if a term \(t\) reduces to \(t'\) in zero or more steps of call-by-value reduction, then \(t\) and \(t'\) have the same denotation in every environment \(\eta\) for their context.
theorem denote_eq (I : Base → Type v) {t t' : Tm Γ A} (h : Steps t t') (η : Env I Γ) :
Tm.denote I t η = Tm.denote I t' η
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Steps {Base : Type u} {Γ : List (Ty Base)} {A : Ty Base} :=
Relation.ReflTransGen (@Step Base Γ A)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Semantics.lean:129
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
TheoremBig-step evaluation preserves STLC denotation#✓fully proved
For every interpretation \(I\) of the base types, if a term \(t\) evaluates to \(v\) under call-by-value big-step evaluation, then \(t\) and \(v\) have the same denotation in every environment \(\eta\) for their context.
theorem denote_eq (I : Base → Type v) {t value : Tm Γ A} (h : Eval t value)
(η : Env I Γ) : Tm.denote I t η = Tm.denote I value η
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
inductive Eval : {A : Ty Base} → Tm Γ A → Tm Γ A → Prop where
| lam {A B : Ty Base} (body : Tm (A :: Γ) B) : Eval (.lam body) (.lam body)
| app {A B : Ty Base} {f : Tm Γ (A ⇒ B)} {a : Tm Γ A}
{body : Tm (A :: Γ) B} {va : Tm Γ A} {v : Tm Γ B} :
Eval f (.lam body) →
Eval a va →
Eval (Tm.instantiate body va) v →
Eval (.app f a) v
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/BigStep.lean:43
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
DefinitionSemantic equality of terms in a model#✓fully proved
Fix an interpretation \(I\) of the base types as types. Two terms \(t\) and \(u\) of the same type \(A\) in the same context \(\Gamma\) are semantically equal in \(I\) when, for every semantic environment \(\eta\) for \(\Gamma\), the denotation of \(t\) in \(I\) at \(\eta\) equals the denotation of \(u\) in \(I\) at \(\eta\).
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
Uses 5 · Used by 16
TheoremSemantic equality is reflexive#✓fully proved
For every interpretation \(I\) of the base types, every term \(t\) is semantically equal to itself in \(I\): it has the same denotation as itself in every environment.
theorem refl (I : Base → Type v) (t : Tm Γ A) : SemEq I t t
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 6 · Used by 3
TheoremSymmetry of semantic equality of terms#✓fully proved
For every interpretation \(I\) of the base types and all terms \(t\) and \(u\) of the same type in the same context, if \(t\) and \(u\) are semantically equal in \(I\), then \(u\) and \(t\) are semantically equal in \(I\).
theorem symm {t u : Tm Γ A} (h : SemEq I t u) : SemEq I u t
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 6 · Used by 2
TheoremTransitivity of semantic equality of terms#✓fully proved
For every interpretation \(I\) of the base types and all terms \(t\), \(u\) and \(w\) of the same type in the same context, if \(t\) and \(u\) are semantically equal in \(I\) and \(u\) and \(w\) are semantically equal in \(I\), then \(t\) and \(w\) are semantically equal in \(I\).
theorem trans {t u w : Tm Γ A} (htu : SemEq I t u) (huw : SemEq I u w) :
SemEq I t w
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 6 · Used by 2
TheoremSemantic equality is a congruence for application#✓fully proved
Fix an interpretation \(I\) of the base types. If terms \(f\) and \(g\) of type \(A \Rightarrow B\) in a context \(\Gamma\) are semantically equal in \(I\) (they have the same denotation in every environment), and terms \(a\) and \(b\) of type \(A\) in \(\Gamma\) are semantically equal in \(I\), then the applications \(f\,a\) and \(g\,b\) are semantically equal in \(I\).
theorem app {f g : Tm Γ (A ⇒ B)} {a b : Tm Γ A}
(hfg : SemEq I f g) (hab : SemEq I a b) : SemEq I (.app f a) (.app g b)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 6 · Used by 1
TheoremSemantic equality is a congruence for lambda abstraction#✓fully proved
Fix an interpretation \(I\) of the base types. If two terms of type \(B\) in the context \(\Gamma\) extended by a newest variable of type \(A\) are semantically equal in \(I\) (they have the same denotation in every environment), then their lambda abstractions, terms of type \(A \Rightarrow B\) in \(\Gamma\), are semantically equal in \(I\).
theorem lam {body body' : Tm (A :: Γ) B} (h : SemEq I body body') :
SemEq I (.lam body) (.lam body')
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 7 · Used by 1
TheoremRenaming preserves semantic equality#✓fully proved
Fix an interpretation \(I\) of the base types. If terms \(t\) and \(u\) of type \(A\) in a context \(\Gamma\) are semantically equal in \(I\) (they have the same denotation in every environment), then for every type-preserving renaming \(\rho\) of the variables of \(\Gamma\) into a context \(\Delta\), the renamed terms \(\rho(t)\) and \(\rho(u)\) are semantically equal in \(I\).
theorem rename {t u : Tm Γ A} (h : SemEq I t u) (ρ : Ren Γ Δ) :
SemEq I (Tm.rename ρ t) (Tm.rename ρ u)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
abbrev Ren {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Var Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:71
def rename : {Γ Δ : List (Ty Base)} → Ren Γ Δ → {A : Ty Base} → Tm Γ A → Tm Δ A
| _, _, ρ, _, .var x => .var (ρ x)
| _, _, ρ, _, .app f a => .app (rename ρ f) (rename ρ a)
| _, _, ρ, _, .lam body => .lam (rename (Var.lift ρ) body)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:105
TheoremSubstitution preserves semantic equality#✓fully proved
For every interpretation \(I\) of the base types, if two terms \(t\) and \(u\) of the same type \(A\) in a context \(\Gamma\) are semantically equal in \(I\), then for every simultaneous substitution \(\sigma\) from \(\Gamma\) to a context \(\Delta\), the result of applying \(\sigma\) to \(t\) and the result of applying \(\sigma\) to \(u\) are semantically equal in \(I\).
theorem subst {t u : Tm Γ A} (h : SemEq I t u) (σ : Sub Γ Δ) :
SemEq I (Tm.subst σ t) (Tm.subst σ u)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
def subst : {Γ Δ : List (Ty Base)} → Sub Γ Δ → {A : Ty Base} → Tm Γ A → Tm Δ A
| _, _, σ, _, .var x => σ x
| _, _, σ, _, .app f a => .app (subst σ f) (subst σ a)
| _, _, σ, _, .lam body => .lam (subst (Sub.lift σ) body)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:74
TheoremSingle-step evaluation is a semantic equation#✓fully proved
For every interpretation \(I\) of the base types, if a term \(t\) reduces to a term \(u\) in one call-by-value evaluation step, then \(t\) and \(u\) are semantically equal in \(I\): they have the same denotation in every environment.
theorem of_step {t u : Tm Γ A} (h : Step t u) : SemEq I t u
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
inductive Step {Base : Type u} : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Tm Γ A → Prop where
| appFun {A B : Ty Base} {Γ : List (Ty Base)} {f f' : Tm Γ (A ⇒ B)} {a : Tm Γ A} :
Step f f' → Step (.app f a) (.app f' a)
| appArg {A B : Ty Base} {Γ : List (Ty Base)} {f : Tm Γ (A ⇒ B)} {a a' : Tm Γ A} :
Value f → Step a a' → Step (.app f a) (.app f a')
| beta {A B : Ty Base} {Γ : List (Ty Base)} {body : Tm (A :: Γ) B} {a : Tm Γ A} :
Value a → Step (.app (.lam body) a) (Tm.instantiate body a)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Semantics.lean:43
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 6
TheoremMulti-step evaluation is a semantic equation#✓fully proved
For every interpretation \(I\) of the base types, if a term \(t\) reduces to a term \(u\) in zero or more call-by-value evaluation steps, then \(t\) and \(u\) are semantically equal in \(I\): they have the same denotation in every environment.
theorem of_steps {t u : Tm Γ A} (h : Steps t u) : SemEq I t u
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Steps {Base : Type u} {Γ : List (Ty Base)} {A : Ty Base} :=
Relation.ReflTransGen (@Step Base Γ A)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Semantics.lean:129
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 6
TheoremBeta is sound for the denotational semantics#✓fully proved
For every interpretation \(I\) of the base types, every term \(t\) of type \(B\) in the context \(\Gamma\) extended by a newest variable of type \(A\), and every term \(a\) of type \(A\) in \(\Gamma\), the redex \((\lambda.\,t)\,a\) is semantically equal in \(I\) (has the same denotation in every environment) to the instantiation \(t[a]\), which replaces the newest free variable of \(t\) by \(a\).
The argument \(a\) need not be a value.
theorem beta (I : Base → Type v) (body : Tm (A :: Γ) B) (a : Tm Γ A) :
SemEq I (.app (.lam body) a) (Tm.instantiate body a)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
def instantiate (body : Tm (A :: Γ) B) (a : Tm Γ A) : Tm Γ B :=
subst (Sub.single a) body
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:124
Uses 9 · Used by 1
TheoremEta is sound for the denotational semantics#✓fully proved
For every interpretation \(I\) of the base types and every term \(f\) of type \(A \Rightarrow B\) in a context \(\Gamma\), let \(f'\) be the weakening of \(f\) to the context \(\Gamma\) extended by a newest variable \(x\) of type \(A\). Then the term \(\lambda x.\, f'\,x\), which binds \(x\), is semantically equal to \(f\) in \(I\) (has the same denotation in every environment).
theorem eta (I : Base → Type v) (f : Tm Γ (A ⇒ B)) :
SemEq I (.lam (.app (Tm.weaken f) (.var .zero))) f
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
def weaken (t : Tm Γ A) : Tm (B :: Γ) A := rename .succ t
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:156
Uses 10 · Used by 1
DefinitionPointwise semantic equality of substitutions#✓fully proved
Fix an interpretation \(I\) of the base types as types. Two simultaneous substitutions \(\sigma\) and \(\tau\) from a context \(\Gamma\) to a context \(\Delta\) are pointwise semantically equal in \(I\) when, for every variable \(x\) of \(\Gamma\) (of any type) and every semantic environment \(\eta\) for \(\Delta\), the denotation of the term \(\sigma(x)\) in \(I\) at \(\eta\) equals the denotation of the term \(\tau(x)\) in \(I\) at \(\eta\).
def SubSemEq (I : Base → Type v) (σ τ : Sub Γ Δ) : Prop :=
∀ {A} (x : Var Γ A) (η : Env I Δ), Tm.denote I (σ x) η = Tm.denote I (τ x) η
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
inductive Var {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| zero {A : Ty Base} {Γ : List (Ty Base)} : Var (A :: Γ) A
| succ {A B : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Var (B :: Γ) A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:56
abbrev Env (I : Base → Type v) (Γ : List (Ty Base)) :=
∀ {A}, Var Γ A → Ty.denote I A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:63
def denote (I : Base → Type v) : {Γ : List (Ty Base)} → {A : Ty Base} →
Tm Γ A → Env I Γ → Ty.denote I A
| _, _, .var x, η => η x
| _, _, .app f a, η => denote I f η (denote I a η)
| _, _, .lam body, η => fun a ↦ denote I body (Env.cons a η)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Denotational.lean:86
TheoremPointwise semantic equality of substitutions is reflexive#✓fully proved
For every interpretation \(I\) of the base types and every simultaneous substitution \(\sigma\) that replaces each variable of a context \(\Gamma\) by a term of the same type in a context \(\Delta\), \(\sigma\) is pointwise semantically equal to itself in \(I\): for every variable \(x\) of \(\Gamma\), the term \(\sigma(x)\) has the same denotation as itself in every environment for \(\Delta\).
theorem refl (I : Base → Type v) (σ : Sub Γ Δ) : SubSemEq I σ σ
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
def SubSemEq (I : Base → Type v) (σ τ : Sub Γ Δ) : Prop :=
∀ {A} (x : Var Γ A) (η : Env I Δ), Tm.denote I (σ x) η = Tm.denote I (τ x) η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:112
Uses 7
TheoremSymmetry of pointwise semantic equality of substitutions#✓fully proved
For every interpretation \(I\) of the base types and all simultaneous substitutions \(\sigma\) and \(\tau\) from a context \(\Gamma\) to a context \(\Delta\), if \(\sigma\) and \(\tau\) are pointwise semantically equal in \(I\), then \(\tau\) and \(\sigma\) are pointwise semantically equal in \(I\).
theorem symm {σ τ : Sub Γ Δ} (h : SubSemEq I σ τ) : SubSemEq I τ σ
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
def SubSemEq (I : Base → Type v) (σ τ : Sub Γ Δ) : Prop :=
∀ {A} (x : Var Γ A) (η : Env I Δ), Tm.denote I (σ x) η = Tm.denote I (τ x) η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:112
Uses 7
TheoremTransitivity of pointwise semantic equality of substitutions#✓fully proved
For every interpretation \(I\) of the base types and all simultaneous substitutions \(\sigma\), \(\tau\) and \(\upsilon\) from a context \(\Gamma\) to a context \(\Delta\), if \(\sigma\) and \(\tau\) are pointwise semantically equal in \(I\) and \(\tau\) and \(\upsilon\) are pointwise semantically equal in \(I\), then \(\sigma\) and \(\upsilon\) are pointwise semantically equal in \(I\).
theorem trans {σ τ υ : Sub Γ Δ} (hστ : SubSemEq I σ τ) (hτυ : SubSemEq I τ υ) :
SubSemEq I σ υ
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
def SubSemEq (I : Base → Type v) (σ τ : Sub Γ Δ) : Prop :=
∀ {A} (x : Var Γ A) (η : Env I Δ), Tm.denote I (σ x) η = Tm.denote I (τ x) η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:112
Uses 7
TheoremSemantically equal substitutions give semantically equal results#✓fully proved
For every interpretation \(I\) of the base types, every term \(t\) of type \(A\) in a context \(\Gamma\), and all simultaneous substitutions \(\sigma\) and \(\tau\) from \(\Gamma\) to a context \(\Delta\) that are pointwise semantically equal in \(I\), the result of applying \(\sigma\) to \(t\) and the result of applying \(\tau\) to \(t\) are semantically equal in \(I\).
theorem subst_congr (t : Tm Γ A) {σ τ : Sub Γ Δ} (hστ : SubSemEq I σ τ) :
SemEq I (Tm.subst σ t) (Tm.subst τ t)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
abbrev Sub {Base : Type u} (Γ Δ : List (Ty Base)) := ∀ {A}, Var Γ A → Tm Δ A
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:74
def SubSemEq (I : Base → Type v) (σ τ : Sub Γ Δ) : Prop :=
∀ {A} (x : Var Γ A) (η : Env I Δ), Tm.denote I (σ x) η = Tm.denote I (τ x) η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:112
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
def subst : {Γ Δ : List (Ty Base)} → Sub Γ Δ → {A : Ty Base} → Tm Γ A → Tm Δ A
| _, _, σ, _, .var x => σ x
| _, _, σ, _, .app f a => .app (subst σ f) (subst σ a)
| _, _, σ, _, .lam body => .lam (subst (Sub.lift σ) body)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:74
TheoremSemantic equality is an equivalence relation#✓fully proved
For every interpretation \(I\) of the base types, every context \(\Gamma\) and every type \(A\), semantic equality in \(I\) of terms of type \(A\) in \(\Gamma\) (having the same denotation in every environment) is reflexive, symmetric and transitive.
theorem equivalence (I : Base → Type v) : Equivalence (@SemEq Base A Γ I)
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
InductiveTyped one-hole contexts#✓fully proved
Fix simple types over a type of base types. A one-hole context whose hole has type \(A\) in variable context \(\Gamma\), and which produces a term of type \(B\) in variable context \(\Delta\), is built by four rules. The hole itself is such a context, with \(\Delta = \Gamma\) and \(B = A\). If \(C\) produces type \(S \Rightarrow T\) in \(\Delta\) and \(a\) is a term of type \(S\) in \(\Delta\), then the application \(C\,a\) produces type \(T\) in \(\Delta\). If \(f\) is a term of type \(S \Rightarrow T\) in \(\Delta\) and \(C\) produces type \(S\) in \(\Delta\), then the application \(f\,C\) produces type \(T\) in \(\Delta\). If \(C\) produces type \(T\) in the context \(S :: \Delta\) obtained from \(\Delta\) by adding a new leading variable of type \(S\), then the abstraction \(\lambda C\) produces type \(S \Rightarrow T\) in \(\Delta\). In every rule the hole keeps type \(A\) in context \(\Gamma\).
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
inductive Ty (Base : Type u) where
| base : Base → Ty Base
| arr : Ty Base → Ty Base → Ty Base
deriving DecidableEq, Repr
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:36
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
Uses 2 · Used by 8
DefinitionPlugging a term into an STLC context#✓fully proved
Let \(E\) be a typed one-hole context whose hole has type \(A\) in variable context \(\Gamma\) and which produces a term of type \(B\) in variable context \(\Delta\). For a term \(t\) of type \(A\) in \(\Gamma\), the plugged term \(E[t]\) of type \(B\) in \(\Delta\) is defined by recursion on \(E\): \([\,][t] = t\), \((E\,a)[t] = E[t]\,a\), \((f\,E)[t] = f\,E[t]\) and \((\lambda.\,E)[t] = \lambda.\,E[t]\), where \([\,]\) is the bare hole, \(E\,a\) applies \(E\) to a term \(a\), \(f\,E\) applies a term \(f\) to \(E\), and \(\lambda.\,E\) puts \(E\) under a lambda. No renaming is applied, so a lambda above the hole may bind free variables of \(t\).
def plug {Δ : List (Ty Base)} {B : Ty Base} : TmCtx Γ A Δ B → Tm Γ A → Tm Δ B
| .hole, t => t
| .appFun C a, t => .app (plug C t) a
| .appArg f C, t => .app f (plug C t)
| .lam C, t => .lam (plug C t)
inductive Ty (Base : Type u) where
| base : Base → Ty Base
| arr : Ty Base → Ty Base → Ty Base
deriving DecidableEq, Repr
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:36
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
Uses 3 · Used by 5
DefinitionComposition of STLC contexts#✓fully proved
Let \(E_2\) be a typed one-hole context whose hole has type \(B\) in variable context \(\Delta\) and which produces a term of type \(C\) in context \(\Theta\), and let \(E_1\) be one whose hole has type \(A\) in context \(\Gamma\) and which produces a term of type \(B\) in \(\Delta\). The composite \(E_2 \circ E_1\), with hole of type \(A\) in \(\Gamma\) and result of type \(C\) in \(\Theta\), replaces the hole of \(E_2\) by \(E_1\); by recursion on \(E_2\): \([\,] \circ E_1 = E_1\), \((E_2\,a) \circ E_1 = (E_2 \circ E_1)\,a\), \((f\,E_2) \circ E_1 = f\,(E_2 \circ E_1)\) and \((\lambda.\,E_2) \circ E_1 = \lambda.\,(E_2 \circ E_1)\), where \([\,]\) is the bare hole and \(E\,a\), \(f\,E\), \(\lambda.\,E\) apply a context \(E\) to a term \(a\), apply a term \(f\) to \(E\), and put \(E\) under a lambda.
def comp {Δ Θ : List (Ty Base)} {B C : Ty Base} :
TmCtx Δ B Θ C → TmCtx Γ A Δ B → TmCtx Γ A Θ C
| .hole, inner => inner
| .appFun outer a, inner => .appFun (comp outer inner) a
| .appArg f outer, inner => .appArg f (comp outer inner)
| .lam outer, inner => .lam (comp outer inner)
inductive Ty (Base : Type u) where
| base : Base → Ty Base
| arr : Ty Base → Ty Base → Ty Base
deriving DecidableEq, Repr
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:36
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
Uses 3 · Used by 2
TheoremPlugging into a composite STLC context#✓fully proved
Let \(E_2\) be a typed one-hole context whose hole has type \(B\) in variable context \(\Delta\) and which produces a term of type \(C\) in context \(\Theta\), and let \(E_1\) be one whose hole has type \(A\) in context \(\Gamma\) and which produces a term of type \(B\) in \(\Delta\). Then for every term \(t\) of type \(A\) in \(\Gamma\), \((E_2 \circ E_1)[t] = E_2[E_1[t]]\).
theorem plug_comp (outer : TmCtx Δ B Θ C) (inner : TmCtx Γ A Δ B) (t : Tm Γ A) :
plug (comp outer inner) t = plug outer (plug inner t)
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def plug {Δ : List (Ty Base)} {B : Ty Base} : TmCtx Γ A Δ B → Tm Γ A → Tm Δ B
| .hole, t => t
| .appFun C a, t => .app (plug C t) a
| .appArg f C, t => .app f (plug C t)
| .lam C, t => .lam (plug C t)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:62
def comp {Δ Θ : List (Ty Base)} {B C : Ty Base} :
TmCtx Δ B Θ C → TmCtx Γ A Δ B → TmCtx Γ A Θ C
| .hole, inner => inner
| .appFun outer a, inner => .appFun (comp outer inner) a
| .appArg f outer, inner => .appArg f (comp outer inner)
| .lam outer, inner => .lam (comp outer inner)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:84
TheoremAssociativity of composition of STLC contexts#✓fully proved
Let \(E_1\) be a typed one-hole context whose hole has type \(A\) in variable context \(\Gamma\) and which produces a term of type \(B\) in context \(\Delta\), \(E_2\) one with hole of type \(B\) in \(\Delta\) producing type \(C\) in \(\Theta\), and \(E_3\) one with hole of type \(C\) in \(\Theta\) producing type \(D\) in \(\Xi\). Then \((E_3 \circ E_2) \circ E_1 = E_3 \circ (E_2 \circ E_1)\).
theorem comp_assoc (outer : TmCtx Θ C Ξ D) (middle : TmCtx Δ B Θ C)
(inner : TmCtx Γ A Δ B) :
comp (comp outer middle) inner = comp outer (comp middle inner)
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
def comp {Δ Θ : List (Ty Base)} {B C : Ty Base} :
TmCtx Δ B Θ C → TmCtx Γ A Δ B → TmCtx Γ A Θ C
| .hole, inner => inner
| .appFun outer a, inner => .appFun (comp outer inner) a
| .appArg f outer, inner => .appArg f (comp outer inner)
| .lam outer, inner => .lam (comp outer inner)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:84
Uses 4
TheoremSemantic equality is a congruence for typed contexts#✓fully proved
Fix an interpretation \(I\) of the base types. Let \(t\) and \(u\) be terms of type \(A\) in variable context \(\Gamma\) that denote the same value in \(I\) under every semantic environment. Then for every typed one-hole context \(C\) whose hole has type \(A\) in context \(\Gamma\) and which produces a term of type \(B\) in context \(\Delta\), the terms \(C[t]\) and \(C[u]\) obtained by plugging \(t\) and \(u\) into the hole also denote the same value in \(I\) under every semantic environment.
theorem semEq {I : Base → Type v} (C : TmCtx Γ A Δ B) {t u : Tm Γ A}
(h : SemEq I t u) : SemEq I (plug C t) (plug C u)
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
def plug {Δ : List (Ty Base)} {B : Ty Base} : TmCtx Γ A Δ B → Tm Γ A → Tm Δ B
| .hole, t => t
| .appFun C a, t => .app (plug C t) a
| .appArg f C, t => .app f (plug C t)
| .lam C, t => .lam (plug C t)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:62
Uses 8 · Used by 1
DefinitionModel equality of STLC terms#✓fully proved
Two terms \(t\) and \(u\) of type \(A\) in variable context \(\Gamma\) are model-equal when, for every interpretation \(I\) of the base types by types in the same universe as the type of base types, they are semantically equal in \(I\): with function types interpreted as full function spaces, the denotations of \(t\) and \(u\) agree at every semantic environment for \(\Gamma\).
Unlike semantic equality in a fixed interpretation, this relation does not choose a particular model.
def ModelEq (t u : Tm Γ A) : Prop :=
∀ I : Base → Type u, SemEq I t u
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def SemEq (I : Base → Type v) (t u : Tm Γ A) : Prop :=
∀ η : Env I Γ, Tm.denote I t η = Tm.denote I u η
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Equational.lean:44
Uses 3 · Used by 7
TheoremModel equality is a congruence for STLC contexts#✓fully proved
Let \(E\) be a typed one-hole context whose hole has type \(A\) in variable context \(\Gamma\) and which produces a term of type \(B\) in context \(\Delta\). If two terms \(t\) and \(u\) of type \(A\) in \(\Gamma\) are model-equal, then \(E[t]\) and \(E[u]\) are model-equal.
theorem context (C : TmCtx Γ A Δ B) {t u : Tm Γ A} (h : ModelEq t u) :
ModelEq (C.plug t) (C.plug u)
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def ModelEq (t u : Tm Γ A) : Prop :=
∀ I : Base → Type u, SemEq I t u
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:122
Uses 6 · Used by 2
TheoremModel-independent beta equality#✓fully proved
For every term \(b\) of type \(B\) in the variable context \(\Gamma\) extended by a newest variable of type \(A\), and every term \(a\) of type \(A\) in \(\Gamma\), the application \((\lambda.\,b)\,a\) is model-equal to \(b[a]\), the result of substituting \(a\) for the newest variable of \(b\).
theorem beta (body : Tm (A :: Γ) B) (a : Tm Γ A) :
ModelEq (.app (.lam body) a) (Tm.instantiate body a)
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def ModelEq (t u : Tm Γ A) : Prop :=
∀ I : Base → Type u, SemEq I t u
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:122
def instantiate (body : Tm (A :: Γ) B) (a : Tm Γ A) : Tm Γ B :=
subst (Sub.single a) body
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:124
Uses 5 · Used by 1
TheoremModel-independent eta equality#✓fully proved
For every term \(f\) of type \(A \Rightarrow B\) in variable context \(\Gamma\), the term \(\lambda.\,(f^{\uparrow}\,x_0)\) is model-equal to \(f\), where \(f^{\uparrow}\) is \(f\) weakened by a newest variable of type \(A\) and \(x_0\) is that variable.
theorem eta (f : Tm Γ (A ⇒ B)) :
ModelEq (.lam (.app (Tm.weaken f) (.var .zero))) f
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def ModelEq (t u : Tm Γ A) : Prop :=
∀ I : Base → Type u, SemEq I t u
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:122
def weaken (t : Tm Γ A) : Tm (B :: Γ) A := rename .succ t
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:156
TheoremBeta equality inside an STLC context#✓fully proved
Let \(E\) be a typed one-hole context whose hole has type \(B\) in variable context \(\Gamma\) and which produces a term of type \(C\) in context \(\Delta\). For every term \(b\) of type \(B\) in \(\Gamma\) extended by a newest variable of type \(A\), and every term \(a\) of type \(A\) in \(\Gamma\), the term \(E[(\lambda.\,b)\,a]\) is model-equal to \(E[b[a]]\), where \(b[a]\) is the result of substituting \(a\) for the newest variable of \(b\).
theorem context_beta (C : TmCtx Γ B Δ C) (body : Tm (A :: Γ) B) (a : Tm Γ A) :
ModelEq (C.plug (.app (.lam body) a)) (C.plug (Tm.instantiate body a))
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def ModelEq (t u : Tm Γ A) : Prop :=
∀ I : Base → Type u, SemEq I t u
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:122
def instantiate (body : Tm (A :: Γ) B) (a : Tm Γ A) : Tm Γ B :=
subst (Sub.single a) body
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Substitution.lean:124
TheoremEta equality inside an STLC context#✓fully proved
Let \(E\) be a typed one-hole context whose hole has type \(A \Rightarrow B\) in variable context \(\Gamma\) and which produces a term of type \(C\) in context \(\Delta\). For every term \(f\) of type \(A \Rightarrow B\) in \(\Gamma\), the term \(E[\lambda.\,(f^{\uparrow}\,x_0)]\) is model-equal to \(E[f]\), where \(f^{\uparrow}\) is \(f\) weakened by a newest variable of type \(A\) and \(x_0\) is that variable.
theorem context_eta (C : TmCtx Γ (A ⇒ B) Δ C) (f : Tm Γ (A ⇒ B)) :
ModelEq (C.plug (.lam (.app (Tm.weaken f) (.var .zero))) ) (C.plug f)
inductive TmCtx {Base : Type u} (Γ : List (Ty Base)) (A : Ty Base) :
(Δ : List (Ty Base)) → (B : Ty Base) → Type u where
| hole : TmCtx Γ A Γ A
| appFun {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A Δ (B ⇒ C)) (a : Tm Δ B) : TmCtx Γ A Δ C
| appArg {Δ : List (Ty Base)} {B C : Ty Base}
(f : Tm Δ (B ⇒ C)) (ctx : TmCtx Γ A Δ B) : TmCtx Γ A Δ C
| lam {Δ : List (Ty Base)} {B C : Ty Base}
(ctx : TmCtx Γ A (B :: Δ) C) : TmCtx Γ A Δ (B ⇒ C)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:49
inductive Tm {Base : Type u} : List (Ty Base) → Ty Base → Type u where
| var {A : Ty Base} {Γ : List (Ty Base)} : Var Γ A → Tm Γ A
| app {A B : Ty Base} {Γ : List (Ty Base)} : Tm Γ (A ⇒ B) → Tm Γ A → Tm Γ B
| lam {A B : Ty Base} {Γ : List (Ty Base)} : Tm (A :: Γ) B → Tm Γ (A ⇒ B)
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:61
def ModelEq (t u : Tm Γ A) : Prop :=
∀ I : Base → Type u, SemEq I t u
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Contextual.lean:122
def weaken (t : Tm Γ A) : Tm (B :: Γ) A := rename .succ t
CSLibExt/Languages/LambdaCalculus/DeBruijn/Stlc/Syntax.lean:156
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.