Simply Typed λ-Calculus, Church Numerals, Combinators, and Extended Polynomials
DefinitionSchwichtenberg1976_LambdaFormalizes Schwichtenberg (1975/1976, pp. 113-114): simple types built from 0 (Ty.zero) with ν = (0 → 0) → (0 → 0) (Ty.nu), typed λ-terms, capture-avoiding substitution, α-equivalence, β-reduction (ReducesTo), β-normal forms, Church numerals n̄ = λα. α^n, explicit combinators for addition (addComb), multiplication (mulComb), constants (constComb), and zero-test conditional (condComb), multivariate polynomials (IsPolynomial), extended polynomials (IsExtendedPolyInd, IsPiecewisePolynomial), and the inductive grammar IsType00Subterm of normal subterms of type 0 → 0.
import Std
/-!
# Simply Typed λ-Calculus, Church Numerals, and Extended Polynomials (Schwichtenberg 1976)
Source: Helmut Schwichtenberg,
"Definierbare Funktionen im λ-Kalkül mit Typen",
*Archiv für mathematische Logik und Grundlagenforschung* 17, 1975/1976, pp. 113–114.
This module formalizes:
- Simple types (`Ty`) built from ground type `0` (`Ty.zero`) by `(σ → τ)` (`Ty.arr`),
and the Church numeral type `ν := (0 → 0) → (0 → 0)` (`Ty.nu`, p. 113).
- Typed λ-terms (`Term`, `HasType`), capture-avoiding substitution (`substTerm`),
α-equivalence (`AlphaEq`), β-reduction `t =| t'` (`ReducesTo`, clauses (i)–(v) on p. 113),
β-normal forms (`IsBetaNormal`), and normal-form equality (`TermEq`, p. 113).
- Iterated function application `α^n := λx. α(...(α x)...)` (`iterApp`, `iterTerm`),
Church numerals `n̄ := λα. α^n` (`churchNumeral`), and λ-definability of numerical
functions `f : (Fin k → Nat) → Nat` (`DefinesFunction`, `IsLambdaDefinable`, p. 113).
- Explicit combinators for composition `t ∘ s`, addition `addComb`, multiplication `mulComb`,
constant `constComb`, and zero-test conditional `condComb` (`d(n, m, i)`, p. 113).
- Polynomials (`IsPolynomial`), piecewise polynomials by vanishing/non-vanishing of arguments
(`IsPiecewisePolynomial`, p. 114), and the inductive class of extended polynomials
(`IsExtendedPolyInd`, pp. 113–114).
- Inductive grammar of normal subterms of type `0 → 0` (`IsType00Subterm`, clauses (1)–(3), p. 114).
-/
namespace Schwichtenberg1976
/-- Simple types over ground type `0` (p. 113):
`σ, τ ::= 0 | (σ → τ)`. -/
inductive Ty where
| zero : Ty
| arr : Ty → Ty → Ty
deriving DecidableEq, Repr
namespace Ty
/-- Endomorphism type `0 → 0` (p. 113). -/
def endo : Ty := .arr .zero .zero
/-- Church numeral type `ν := (0 → 0) → (0 → 0)` (p. 113). -/
def nu : Ty := .arr endo endo
/-- Type `ν → (ν → ... (ν → ν)...)` with `k` arguments of type `ν` (p. 113). -/
def nuArity : Nat → Ty
| 0 => nu
| k + 1 => .arr nu (nuArity k)
end Ty
/-- Typed variable `x^τ` (p. 113). -/
structure Var where
id : Nat
ty : Ty
deriving DecidableEq, Repr
/-- Typed λ-terms built from typed variables by application and λ-abstraction (p. 113). -/
inductive Term where
| var : Var → Term
| app : Term → Term → Term
| lam : Var → Term → Term
deriving DecidableEq, Repr
namespace Term
/-- Left-associated multi-argument application `t s₁ ... sₖ`. -/
def appMany : Term → List Term → Term
| t, [] => t
| t, s :: ss => appMany (.app t s) ss
/-- Multi-variable λ-abstraction `λx₁ ... xₖ. t`. -/
def lamMany : List Var → Term → Term
| [], t => t
| x :: xs, t => .lam x (lamMany xs t)
end Term
/-- Typing relation `HasType t τ` (`t^τ`, p. 113). -/
inductive HasType : Term → Ty → Prop where
| var (x : Var) :
HasType (.var x) x.ty
| app {t s : Term} {σ τ : Ty} :
HasType t (.arr σ τ) →
HasType s σ →
HasType (.app t s) τ
| lam (x : Var) {t : Term} {τ : Ty} :
HasType t τ →
HasType (.lam x t) (.arr x.ty τ)
/-- Free variable occurrences of a term `t`. -/
def freeVarOccurrences : Term → List Var
| .var x => [x]
| .app t s => freeVarOccurrences t ++ freeVarOccurrences s
| .lam x t => (freeVarOccurrences t).filter (· != x)
/-- Underlying set of free variables `FV(t)`. -/
def freeVars (t : Term) : List Var :=
(freeVarOccurrences t).eraseDups
/-- All variables (both free and bound) occurring in `t`. -/
def allVars : Term → List Var
| .var x => [x]
| .app t s => allVars t ++ allVars s
| .lam x t => x :: allVars t
/-- A term `t` is closed ("abgeschlossen", p. 113) if `FV(t) = ∅`. -/
def IsClosed (t : Term) : Prop :=
freeVars t = []
/-- Maximum variable id occurring in `t`. -/
def maxVarId : Term → Nat
| .var x => x.id
| .app t s => Nat.max (maxVarId t) (maxVarId s)
| .lam x t => Nat.max x.id (maxVarId t)
/-- Replace free occurrences of `x` with `y` in `t`. -/
def renameFreeVar (t : Term) (x y : Var) : Term :=
match t with
| .var v => if v == x then .var y else .var v
| .app r s => .app (renameFreeVar r x y) (renameFreeVar s x y)
| .lam v body =>
if v == x then .lam v body else .lam v (renameFreeVar body x y)
/-- Structural size of `t` for termination of capture-avoiding substitution. -/
def rawSize : Term → Nat
| .var _ => 1
| .app t s => rawSize t + rawSize s + 1
| .lam _ t => rawSize t + 1
theorem renameFreeVar_rawSize (t : Term) (x y : Var) :
rawSize (renameFreeVar t x y) = rawSize t := by
induction t with
| var v => simp only [renameFreeVar]; split <;> rfl
| app r s ihr ihs => simp [renameFreeVar, rawSize, ihr, ihs]
| lam v body ih =>
simp only [renameFreeVar]
split
· rfl
· simp [rawSize, ih]
/-- Capture-avoiding substitution `t_x[s]` (p. 113). -/
def substTerm (t : Term) (x : Var) (s : Term) : Term :=
match t with
| .var v => if v == x then s else .var v
| .app r u => .app (substTerm r x s) (substTerm u x s)
| .lam v body =>
if v == x then
.lam v body
else if v ∈ freeVarOccurrences s then
let freshId := Nat.max (maxVarId body) (Nat.max (maxVarId s) x.id) + 1
let v' : Var := ⟨freshId, v.ty⟩
.lam v' (substTerm (renameFreeVar body v v') x s)
else
.lam v (substTerm body x s)
termination_by rawSize t
decreasing_by
all_goals
simp_wf
simp [rawSize, renameFreeVar_rawSize]
try omega
/-- Sequential substitution `t[s₁/x₁, ..., sₖ/xₖ]`. -/
def substMany : Term → List (Var × Term) → Term
| t, [] => t
| t, (x, s) :: rest => substMany (substTerm t x s) rest
/-- α-equivalence `AlphaEq t s` (p. 113: "Terme, die sich nur durch gebundene Umbenennung
unterscheiden, werden identifiziert."). -/
inductive AlphaEq : Term → Term → Prop where
| refl (t : Term) : AlphaEq t t
| symm {t s : Term} : AlphaEq t s → AlphaEq s t
| trans {t s u : Term} : AlphaEq t s → AlphaEq s u → AlphaEq t u
| app {t t' s s' : Term} :
AlphaEq t t' → AlphaEq s s' → AlphaEq (.app t s) (.app t' s')
| lam_rename (x y : Var) (t : Term) :
x.ty = y.ty →
(y = x ∨ y ∉ allVars t) →
AlphaEq (.lam x t) (.lam y (renameFreeVar t x y))
| lam_congr (x : Var) {t s : Term} :
AlphaEq t s → AlphaEq (.lam x t) (.lam x s)
/-- Reduction relation `t =| t'` ("`t` ist reduzierbar auf `t'`", p. 113, clauses (i)–(v)):
- (i) `(λx t)s =| t_x[s]`
- (ii) `t =| t' ∧ s =| s' ⇒ t s =| t' s'`
- (iii) `t =| t' ⇒ λx t =| λx t'`
- (iv) `t =| t` (modulo bound variable renaming `AlphaEq`)
- (v) `t =| t' ∧ t' =| t'' ⇒ t =| t''`. -/
inductive ReducesTo : Term → Term → Prop where
| beta (x : Var) (t s : Term) :
ReducesTo (.app (.lam x t) s) (substTerm t x s)
| app {t t' s s' : Term} :
ReducesTo t t' → ReducesTo s s' → ReducesTo (.app t s) (.app t' s')
| lam (x : Var) {t t' : Term} :
ReducesTo t t' → ReducesTo (.lam x t) (.lam x t')
| refl_alpha {t t' : Term} :
AlphaEq t t' → ReducesTo t t'
| trans {t t' t'' : Term} :
ReducesTo t t' → ReducesTo t' t'' → ReducesTo t t''
/-- Predicate testing whether a term contains a β-redex `(λx t)s` as a subterm (p. 113). -/
def hasBetaRedex : Term → Bool
| .var _ => false
| .app (.lam _ _) _ => true
| .app t s => hasBetaRedex t || hasBetaRedex s
| .lam _ t => hasBetaRedex t
/-- Normal form predicate (p. 113: "Ein Term heißt in Normalform, wenn er keine Teilterme
der Gestalt `(λx t)s` besitzt."). -/
def IsBetaNormal (t : Term) : Prop :=
hasBetaRedex t = false
/-- Subterm relation `IsSubterm s t` ("Teilterm", pp. 113–114). -/
inductive IsSubterm : Term → Term → Prop where
| refl (t : Term) : IsSubterm t t
| appLeft {s t u : Term} : IsSubterm s t → IsSubterm s (.app t u)
| appRight {s t u : Term} : IsSubterm s u → IsSubterm s (.app t u)
| lamBody {s t : Term} (x : Var) : IsSubterm s t → IsSubterm s (.lam x t)
/-- Term equality by common normal form (p. 113: "Zwei Terme heißen gleich, wenn sie dieselbe
Normalform besitzen."). -/
def TermEq (t s : Term) : Prop :=
∃ u v : Term,
IsBetaNormal u ∧ IsBetaNormal v ∧
ReducesTo t u ∧ ReducesTo s v ∧ AlphaEq u v
/-- `n`-fold application `α(α(...(α base)...))` (p. 113). -/
def iterApp (α base : Term) : Nat → Term
| 0 => base
| n + 1 => .app α (iterApp α base n)
/-- Iterated endomorphism `α^n := λx^0. α(...(α x)...)` (p. 113). -/
def iterTerm (α : Term) (xId : Nat := 0) (n : Nat) : Term :=
let x : Var := ⟨xId, .zero⟩
.lam x (iterApp α (.var x) n)
/-- Church numeral `n̄ := λα^{0→0}. α^n` of type `ν = (0 → 0) → (0 → 0)` (p. 113). -/
def churchNumeral (n : Nat) : Term :=
let α : Var := ⟨1, Ty.endo⟩
let x : Var := ⟨0, .zero⟩
.lam α (.lam x (iterApp (.var α) (.var x) n))
/-- Endomorphism composition `t^{τ→τ} ∘ s^{τ→τ} := λx^τ. t(s x)` (p. 113). -/
def compTerm (τ : Ty) (t s : Term) (xId : Nat := 2) : Term :=
let x : Var := ⟨xId, τ⟩
.lam x (.app t (.app s (.var x)))
/-- Schwichtenberg's addition combinator `λF G α. (F α) ∘ (G α)` of type `ν → ν → ν` (p. 113). -/
def addComb : Term :=
let F : Var := ⟨3, Ty.nu⟩
let G : Var := ⟨4, Ty.nu⟩
let α : Var := ⟨1, Ty.endo⟩
.lam F (.lam G (.lam α (compTerm .zero (.app (.var F) (.var α)) (.app (.var G) (.var α)) 0)))
/-- Schwichtenberg's multiplication combinator `λF G. F ∘ G` of type `ν → ν → ν` (p. 113). -/
def mulComb : Term :=
let F : Var := ⟨3, Ty.nu⟩
let G : Var := ⟨4, Ty.nu⟩
.lam F (.lam G (compTerm Ty.endo (.var F) (.var G) 1))
/-- Schwichtenberg's unary constant combinator `λF α. α^k` of type `ν → ν` (p. 113). -/
def constComb (k : Nat) : Term :=
let F : Var := ⟨3, Ty.nu⟩
let α : Var := ⟨1, Ty.endo⟩
.lam F (.lam α (iterTerm (.var α) 0 k))
/-- Schwichtenberg's conditional combinator `λF G H α x. H (λy. G α x) (F α x)` of type
`ν → ν → ν → ν` defining `d(n, m, i) = n` if `i = 0` else `m` (p. 113). -/
def condComb : Term :=
let F : Var := ⟨3, Ty.nu⟩
let G : Var := ⟨4, Ty.nu⟩
let H : Var := ⟨5, Ty.nu⟩
let α : Var := ⟨1, Ty.endo⟩
let x : Var := ⟨0, .zero⟩
let y : Var := ⟨2, .zero⟩
.lam F (.lam G (.lam H (.lam α (.lam x
(.app
(.app (.var H) (.lam y (.app (.app (.var G) (.var α)) (.var x))))
(.app (.app (.var F) (.var α)) (.var x)))))))
/-- Numerical conditional `d(n, m, i) = n` if `i = 0`, and `m` if `i ≠ 0` (p. 113). -/
def condNat (n m i : Nat) : Nat :=
if i == 0 then n else m
/-- Tuple of Church numerals `[n̄₁, ..., n̄ₖ]` for an input vector `v : Fin k → Nat`. -/
def numeralArgs : (k : Nat) → (Fin k → Nat) → List Term
| 0, _ => []
| k + 1, v =>
churchNumeral (v ⟨0, Nat.zero_lt_succ k⟩) ::
numeralArgs k (fun i => v ⟨i.val + 1, Nat.succ_lt_succ i.isLt⟩)
/-- A closed term `t` of type `ν → ... → ν → ν` (`k` arguments) defines `f : (Fin k → Nat) → Nat`
if `t n̄₁ ... n̄ₖ` reduces to `f(n₁, ..., nₖ)̄` up to α-equivalence (p. 113). -/
def DefinesFunction (k : Nat) (t : Term) (f : (Fin k → Nat) → Nat) : Prop :=
HasType t (Ty.nuArity k) ∧
IsClosed t ∧
∀ v : Fin k → Nat,
ReducesTo (Term.appMany t (numeralArgs k v)) (churchNumeral (f v))
/-- A function `f : (Fin k → Nat) → Nat` is λ-definable (`IsLambdaDefinable k f`, p. 113)
if there exists a closed term `t` of type `Ty.nuArity k` that defines `f`. -/
def IsLambdaDefinable (k : Nat) (f : (Fin k → Nat) → Nat) : Prop :=
∃ t : Term, DefinesFunction k t f
/-- Multivariate polynomials `P : (Fin k → Nat) → Nat` with natural number coefficients (p. 114). -/
inductive IsPolynomial : {k : Nat} → ((Fin k → Nat) → Nat) → Prop where
| const {k : Nat} (c : Nat) :
IsPolynomial (k := k) (fun _ => c)
| proj {k : Nat} (i : Fin k) :
IsPolynomial (k := k) (fun v => v i)
| add {k : Nat} {P Q : (Fin k → Nat) → Nat} :
IsPolynomial P → IsPolynomial Q →
IsPolynomial (k := k) (fun v => P v + Q v)
| mul {k : Nat} {P Q : (Fin k → Nat) → Nat} :
IsPolynomial P → IsPolynomial Q →
IsPolynomial (k := k) (fun v => P v * Q v)
/-- Inductive class of extended polynomials (`IsExtendedPolyInd`, pp. 113–114):
functions generated from constants, projections, addition, multiplication, zero-test
conditional `d(n, m, i)`, and composition. -/
inductive IsExtendedPolyInd : {k : Nat} → ((Fin k → Nat) → Nat) → Prop where
| const {k : Nat} (c : Nat) :
IsExtendedPolyInd (k := k) (fun _ => c)
| proj {k : Nat} (i : Fin k) :
IsExtendedPolyInd (k := k) (fun v => v i)
| add {k : Nat} {f g : (Fin k → Nat) → Nat} :
IsExtendedPolyInd f → IsExtendedPolyInd g →
IsExtendedPolyInd (k := k) (fun v => f v + g v)
| mul {k : Nat} {f g : (Fin k → Nat) → Nat} :
IsExtendedPolyInd f → IsExtendedPolyInd g →
IsExtendedPolyInd (k := k) (fun v => f v * g v)
| cond {k : Nat} {f g h : (Fin k → Nat) → Nat} :
IsExtendedPolyInd f → IsExtendedPolyInd g → IsExtendedPolyInd h →
IsExtendedPolyInd (k := k) (fun v => condNat (f v) (g v) (h v))
| comp {k m : Nat} {g : (Fin m → Nat) → Nat} {hs : Fin m → (Fin k → Nat) → Nat} :
IsExtendedPolyInd g →
(∀ j : Fin m, IsExtendedPolyInd (hs j)) →
IsExtendedPolyInd (k := k) (fun v => g (fun j => hs j v))
/-- Pattern-wise polynomial characterization from the top of p. 114:
"alle Funktionen, die aus Polynomen durch Fallunterscheidung nach Verschwinden oder
Nicht-Verschwinden von Argumenten definierbar sind":
for every zero/nonzero pattern `σ : Fin k → Bool` of the arguments, there is a polynomial
`P_σ` such that `f(v) = P_σ(v)` whenever `(v i != 0) = σ i` for all `i`. -/
def IsPiecewisePolynomial (k : Nat) (f : (Fin k → Nat) → Nat) : Prop :=
∀ σ : Fin k → Bool,
∃ P : (Fin k → Nat) → Nat,
IsPolynomial P ∧
∀ v : Fin k → Nat, (∀ i : Fin k, (v i != 0) = σ i) → f v = P v
mutual
/-- Clause (1)–(2) basic subterms of type `0 → 0`: `α` or `Fᵢ s` (p. 114). -/
inductive IsBasicType00 (Fs : List Var) (α : Var) : Term → Prop where
| alpha :
IsBasicType00 Fs α (.var α)
| appF {F : Var} {s : Term} :
F ∈ Fs →
IsType00Subterm Fs α s →
IsBasicType00 Fs α (.app (.var F) s)
/-- Iterated application chain `s₁(...(s_q z)...)` of basic subterms `s₁, ..., s_q`
to a variable `z` of type `0` (clause (3), p. 114). -/
inductive IsBasicType00Chain (Fs : List Var) (α : Var) : Var → Term → Prop where
| base (z : Var) :
z.ty = .zero →
IsBasicType00Chain Fs α z (.var z)
| step {z : Var} {s₁ body : Term} :
IsBasicType00 Fs α s₁ →
IsBasicType00Chain Fs α z body →
IsBasicType00Chain Fs α z (.app s₁ body)
/-- Inductive characterization of the possible subterms of type `0 → 0` in the normal form
of `t F₁ ... Fₖ α` (clauses (1)–(3) on p. 114):
- (1) `α`
- (2) With `s` also `Fᵢ s` (for `Fᵢ ∈ Fs`)
- (3) With `s₁, ..., s_q` formed by (1), (2), also `λy^0. s₁(...(s_q z)...)`, where `z` has
type `0` (and may be identical with `y`). -/
inductive IsType00Subterm (Fs : List Var) (α : Var) : Term → Prop where
| basic {s : Term} :
IsBasicType00 Fs α s →
IsType00Subterm Fs α s
| chainLam (y z : Var) {body : Term} :
y.ty = .zero →
z.ty = .zero →
IsBasicType00Chain Fs α z body →
IsType00Subterm Fs α (.lam y body)
end
end Schwichtenberg1976
Read-back
What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)
Mathematical Read-Back: Def_Schwichtenberg1976_Lambda.lean
All declarations below reside in the namespace Schwichtenberg1976.
1. Simple Types and Variables
Ty (Inductive Type)
The set of simple types is generated inductively by two constructors:
- A ground type (
Ty.zero). - For any types , a function (arrow) type (
Ty.arr σ τ).
Ty.endo (Definition)
The endomorphism type on the ground type , defined as
Ty.nu (Definition)
The Church numeral type , defined as
Ty.nuArity (Definition)
For any natural number , the -ary function type over , denoted (Ty.nuArity k), is defined recursively by:
In particular, for , this is the ground numeral type itself, and for it is the right-associated -argument arrow type .
Var (Structure)
A typed variable is an ordered pair consisting of a natural-number identifier and an intrinsic simple type . Two variables are equal if and only if both and .
2. Raw Terms, Typing, and Free/Bound Variables
Term (Inductive Type)
The set of raw -terms is generated inductively by three constructors:
- Variable term: for any typed variable , a term (
Term.var x). - Application: for any terms , an application (
Term.app t s). - -abstraction: for any typed variable and body term , an abstraction (
Term.lam x t).
Note that Term itself is an intrinsically untyped syntax tree whose variables carry type annotations; well-typedness is enforced externally via the predicate HasType.
Term.appMany (Definition)
For a head term and a finite list of argument terms , the multi-argument application is defined by left-associated recursion:
Term.lamMany (Definition)
For a finite list of typed variables and a body term , the multi-variable abstraction is defined by right-associated recursion:
HasType (Inductive Predicate)
For and , the typing judgment (HasType t τ) is the smallest relation closed under:
- Variable (
HasType.var): For every , the variable term has type . - Application (
HasType.app): For any and , if and , then . - Abstraction (
HasType.lam): For any , , and , if , then .
Because variables carry their own types, there is no separate typing context; if a variable with the same identifier appears with two different types in a term, they are treated as distinct elements of .
freeVarOccurrences (Definition)
For , the ordered list of free variable occurrences (preserving multiplicity and left-to-right order) is defined recursively by:
- for .
- .
- .
freeVars (Definition)
For , the duplicate-free list of free variables (freeVars t) is obtained by removing duplicate entries from (List.eraseDups).
allVars (Definition)
For , the list of all variables (both free and bound, including -binders) occurring anywhere in , denoted , is defined recursively by:
- for .
- .
- .
IsClosed (Definition)
A term is closed (IsClosed t) if and only if (equivalently, ).
3. Variable Renaming, Capture-Avoiding Substitution, and -Equivalence
maxVarId (Definition)
For , is the maximum identifier among all variables :
- .
- .
- .
renameFreeVar (Definition)
For and , replaces every free occurrence of in with , without renaming bound variables of :
- if , and if .
- .
- if , and if .
Whenever (as guaranteed at all call sites in substTerm and AlphaEq.lam_rename), no inner binder in satisfies , so is completely capture-avoiding.
rawSize (Definition) and renameFreeVar_rawSize (Theorem)
For , the syntactic size is defined by , , and . The lemma renameFreeVar_rawSize states that for all and ,
substTerm (Definition)
For , , and , the capture-avoiding substitution (substTerm t x s) is defined by well-founded recursion on :
- For a variable :
- For an application :
- For an abstraction :
where in the middle branch the fresh variable is defined with and identifier
Notice that in the middle branch, is renamed to whenever and , even if .
substMany (Definition)
For a term and a list of variable-term pairs , the sequential substitution is defined by left-to-right recursion:
That is, is substituted for first, then is substituted for in the resulting term (including inside any free occurrences of that might appear in ), and so on.
AlphaEq (Inductive Predicate)
For , the -equivalence relation (AlphaEq t s) is the smallest equivalence and congruence relation generated by the following rules:
- Reflexivity (
AlphaEq.refl): for all . - Symmetry (
AlphaEq.symm): If , then . - Transitivity (
AlphaEq.trans): If and , then . - Application congruence (
AlphaEq.app): If and , then . - Bound variable renaming (
AlphaEq.lam_rename): For any and , if and , then
- Abstraction congruence (
AlphaEq.lam_congr): For any and , if , then .
4. -Reduction, Normal Forms, Subterms, and Term Equality
ReducesTo (Inductive Predicate)
For , the reduction relation (ReducesTo t t', written in the source comments) is the smallest relation closed under five rules:
- -contraction (
ReducesTo.beta): For any and ,
- Application compatibility (
ReducesTo.app): If and , then . - Abstraction compatibility (
ReducesTo.lam): For any , if , then . - -equivalence inclusion (
ReducesTo.refl_alpha): If , then . - Transitivity (
ReducesTo.trans): If and , then .
hasBetaRedex and IsBetaNormal (Definitions)
For , the Boolean function tests whether contains a subterm of the form :
- for .
- .
- when is not an abstraction.
- .
A term is in -normal form (IsBetaNormal t) if and only if .
IsSubterm (Inductive Predicate)
For , the syntactic subterm relation (IsSubterm s t) is the smallest reflexive-transitive relation satisfying:
- Reflexivity (
IsSubterm.refl): for all . - Left application (
IsSubterm.appLeft): If , then . - Right application (
IsSubterm.appRight): If , then . - Abstraction body (
IsSubterm.lamBody): If , then for any .
TermEq (Definition)
Two terms are equal in normal form (TermEq t s) if and only if there exist terms such that and are both in -normal form (IsBetaNormal u and IsBetaNormal v), , , and .
5. Church Numerals, Combinators, and -Definability
iterApp (Definition)
For and , the -fold right-nested application is defined recursively by:
iterTerm (Definition)
For , an optional variable identifier (defaulting to ), and , the iterated endomorphism term (iterTerm α xId n) is
churchNumeral (Definition)
For , the Church numeral (churchNumeral n) is the closed term of type given explicitly by:
compTerm (Definition)
For a type , terms , and an optional variable identifier (defaulting to ), the composition term (compTerm τ t s xId) is:
addComb, mulComb, constComb, condComb, and condNat (Definitions)
Let the fixed variables be , , , , , and .
- Addition combinator (
addComb):
- Multiplication combinator (
mulComb):
- Unary constant combinator (
constComb): For ,
- Conditional combinator (
condComb):
- Numerical conditional (
condNat): For ,
numeralArgs, DefinesFunction, and IsLambdaDefinable (Definitions)
- For and a -tuple of natural numbers , is the list of Church numerals corresponding to the components of in increasing index order.
- A term defines a -ary numerical function (
DefinesFunction k t f) if and only if:- has type (
HasType t (Ty.nuArity k)), - is closed (
IsClosed t), and - for every input tuple ,
- has type (
- A -ary function is -definable (
IsLambdaDefinable k f) if and only if there exists such thatDefinesFunction k t fholds.
6. Polynomials, Extended Polynomials, and Normal Subterms of Type
IsPolynomial (Inductive Predicate)
For , the class of -ary multivariate polynomials over (IsPolynomial (k := k) P) is the smallest class of functions closed under:
- Constant (
IsPolynomial.const): For any , the constant function . - Projection (
IsPolynomial.proj): For any coordinate , the projection . - Pointwise addition (
IsPolynomial.add): If and are polynomials, then is a polynomial. - Pointwise multiplication (
IsPolynomial.mul): If and are polynomials, then is a polynomial.
IsExtendedPolyInd (Inductive Predicate)
For any arity , the inductive class of extended polynomials (IsExtendedPolyInd (k := k) f) is the smallest family of functions (simultaneously across all ) closed under:
- Constant (
IsExtendedPolyInd.const): For any and , . - Projection (
IsExtendedPolyInd.proj): For any and , . - Addition (
IsExtendedPolyInd.add): If are extended polynomials, so is . - Multiplication (
IsExtendedPolyInd.mul): If are extended polynomials, so is . - Zero-test conditional (
IsExtendedPolyInd.cond): If are extended polynomials, so is , which equals when and when . - Composition (
IsExtendedPolyInd.comp): For any , if is an -ary extended polynomial and is a -ary extended polynomial for every , then the composite is a -ary extended polynomial.
IsPiecewisePolynomial (Definition)
For and , is a piecewise polynomial by vanishing/non-vanishing of arguments (IsPiecewisePolynomial k f) if and only if for every Boolean sign pattern , there exists a -ary polynomial satisfying IsPolynomial P such that for every input ,
IsBasicType00, IsBasicType00Chain, and IsType00Subterm (Mutually Inductive Predicates)
Fix a list of variables and a variable . Three predicates on terms are defined by mutual induction:
- Basic subterms of type (
IsBasicType00 Fs α s):- (
IsBasicType00.alpha): The variable term satisfiesIsBasicType00 Fs α α. - (
IsBasicType00.appF): For any variable and term satisfyingIsType00Subterm Fs α s, the application satisfiesIsBasicType00 Fs α (F s).
- (
- Application chains of basic subterms (
IsBasicType00Chain Fs α z b): Parameterized additionally by a target variable :- (
IsBasicType00Chain.base): For any with , the variable term satisfiesIsBasicType00Chain Fs α z z. - (
IsBasicType00Chain.step): For any and terms , if satisfiesIsBasicType00 Fs α s_1and satisfiesIsBasicType00Chain Fs α z b, then satisfiesIsBasicType00Chain Fs α z (s_1 b). Unfolding the recursion,IsBasicType00Chain Fs α z bholds if and only if and for some (where gives ) and basic terms satisfyingIsBasicType00 Fs α.
- (
- Subterms of type (
IsType00Subterm Fs α s):- (
IsType00Subterm.basic): Any term satisfyingIsBasicType00 Fs α salso satisfiesIsType00Subterm Fs α s. - (
IsType00Subterm.chainLam): For any variables with and , and any term satisfyingIsBasicType00Chain Fs α z b, the abstraction satisfiesIsType00Subterm Fs α (λy. b).
- (
7. Audit Notes: Edge Cases, Degenerate Cases, and Potential Issues
- Capture-avoiding -equivalence via
allVarsand transitivity: InAlphaEq.lam_rename, the condition requires that a new binder does not occur anywhere in (neither free nor bound). This guarantees thatrenameFreeVar t x ynever captures free occurrences of under an inner binder in . BecauseAlphaEqalso includesAlphaEq.transandAlphaEq.lam_congr, general -renaming where happens to appear as an inner bound variable of is derivable by first renaming the inner bound variable to a fresh identifier outside and then renaming the outer binder to . - Arity edge case:
For , the input domain is a singleton type (inhabited by the unique empty tuple ). Here , ,
DefinesFunction 0 t frequires closed with , andIsPolynomial,IsExtendedPolyInd, andIsPiecewisePolynomialall reduce to the class of constant functions . - Empty chain () in
IsBasicType00Chain: The base constructorIsBasicType00Chain.baseallows basic terms , so (including the identity when , which equals ) is included inIsType00Subterm Fs α. - Intrinsically typed variables (
Var): Because a variable is a pair , two variables with the same numericalidbut differenttyare distinct infreeVars,allVars,renameFreeVar, andsubstTerm. Furthermore,IsBasicType00,IsBasicType00Chain, andIsType00Subtermdo not themselves assert or in their constructors; those typing constraints are supplied as external hypotheses in the theorems that use them.