Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Section 2: System T and the Arithmetical Systems Z^X, Z, Z_0^X, and Z_0

Definition
BBS2002_Arithmetic

by kmehltretter82 · Oct 30, 2026 · Mathlib 0df444a (Lean v4.33.1)

classical-logicprogram-extractionproof-theoryrealizabilitytype-theory

Formalizes Section 2 of Berger, Buchholz, and Schwichtenberg (2002): finite types over ι and o, System T constants (true, false, 0, S, R_{o,ρ}, R_{ι,ρ}), capture-avoiding substitution, βR-equality, formulas of L[X] and L, and natural deduction derivations for the four arithmetical systems Z^X, Z, Z_0^X, Z_0.

Definition code
import Std

/-!
# Arithmetic for Functionals: System T and the Systems Z^X, Z, Z_0^X, Z_0 (Berger–Buchholz–Schwichtenberg 2002, Section 2)

Source: Ulrich Berger, Wilfried Buchholz, and Helmut Schwichtenberg,
"Refined program extraction from classical proofs",
*Annals of Pure and Applied Logic* 114, 2002, pp. 3–25 (Section 2, pp. 5–7 / preprint pp. 3–5).

This module formalizes:
- Simple types (`Ty`) over ground types `ι` (natural numbers, `Ty.iota`) and `o` (booleans, `Ty.bool`).
- System `T` constants (`Const`): `true^o`, `false^o`, `0^ι`, `S^{ι→ι}`, boolean recursion
  `R_{o,ρ} : ρ → ρ → o → ρ`, and primitive recursion `R_{ι,ρ} : ρ → (ι → ρ → ρ) → ι → ρ`.
- Typed terms (`Term`, `HasType`), capture-avoiding substitution (`substTerm`), conversions
  `↦_βR` (`ConvStep`, `Step`), and the meta-level equality `=_{βR}` (`BetaREq`, p. 4).
- Formulas of `L[X]` and `L` (`Formula`): `⊥`, `X`, `atom(t^o)`, `A → B`, and `∀x^ρ A`,
  together with `¬A := A → ⊥`, `C^X := C[⊥ := X]` (`substBotWithX`), and `A^F := A[⊥ := atom(false)]`
  (`substBotWithFalse`).
- Natural deduction proof terms (`ProofTerm`) and the derivability relation `Derivable sys M A`
  parameterized by `SysConfig` covering the four systems `Z^X`, `Z`, `Z_0^X`, and `Z_0` (p. 4).
-/

namespace BBS2002

/-- Finite types built from ground types `ι` (natural numbers) and `o` (booleans) by `ρ → σ`
(Section 2, p. 3). -/
inductive Ty where
  | iota : Ty
  | bool : Ty
  | arr : Ty → Ty → Ty
  deriving DecidableEq, Repr

namespace Ty

/-- Multi-argument arrow type `ρ₁ → ⋯ → ρₖ → σ`. -/
def arrMany : List Ty → Ty → Ty
  | [], σ => σ
  | ρ :: ρs, σ => .arr ρ (arrMany ρs σ)

end Ty

/-- Constants of System `T` over `ι` and `o` (Section 2, pp. 3–4):
- `true^o`, `false^o`
- `0^ι`, `S^{ι→ι}`
- `R_{o,ρ} : ρ → ρ → o → ρ` (boolean cases / recursion)
- `R_{ι,ρ} : ρ → (ι → ρ → ρ) → ι → ρ` (primitive recursion). -/
inductive Const where
  | trueConst : Const
  | falseConst : Const
  | zero : Const
  | succ : Const
  | recBool : Ty → Const
  | recNat : Ty → Const
  deriving DecidableEq, Repr

namespace Const

/-- Type of a constant symbol (Section 2, pp. 3–4). -/
def ty : Const → Ty
  | .trueConst => .bool
  | .falseConst => .bool
  | .zero => .iota
  | .succ => .arr .iota .iota
  | .recBool ρ => .arr ρ (.arr ρ (.arr .bool ρ))
  | .recNat ρ => .arr ρ (.arr (.arr .iota (.arr ρ ρ)) (.arr .iota ρ))

end Const

/-- Typed object variable `x^ρ` (Section 2, p. 4). -/
structure Var where
  id : Nat
  ty : Ty
  deriving DecidableEq, Repr

/-- Terms of System `T` (Section 2, p. 4): `x^ρ`, `c^ρ`, `λx^ρ r`, `r s`. -/
inductive Term where
  | var : Var → Term
  | const : Const → Term
  | lam : Var → Term → Term
  | app : Term → Term → Term
  deriving DecidableEq, Repr

namespace Term

/-- Left-associated application `r s₁ ... sₖ`. -/
def appMany : Term → List Term → Term
  | r, [] => r
  | r, s :: ss => appMany (.app r s) ss

/-- Multi-variable abstraction `λx₁ ... xₖ. r`. -/
def lamMany : List Var → Term → Term
  | [], r => r
  | x :: xs, r => .lam x (lamMany xs r)

/-- Abbreviation `t + 1 := S^{ι→ι} t` (Section 2, p. 4). -/
def succTerm (t : Term) : Term :=
  .app (.const .succ) t

end Term

/-- Typing relation `HasType r ρ` for System `T` terms (Section 2, p. 4). -/
inductive HasType : Term → Ty → Prop where
  | var (x : Var) :
      HasType (.var x) x.ty
  | const (c : Const) :
      HasType (.const c) c.ty
  | lam (x : Var) {r : Term} {σ : Ty} :
      HasType r σ →
      HasType (.lam x r) (.arr x.ty σ)
  | app {r s : Term} {ρ σ : Ty} :
      HasType r (.arr ρ σ) →
      HasType s ρ →
      HasType (.app r s) σ

/-- Free variable occurrences in a term `r`. -/
def freeVarOccurrences : Term → List Var
  | .var x => [x]
  | .const _ => []
  | .lam x r => (freeVarOccurrences r).filter (· != x)
  | .app r s => freeVarOccurrences r ++ freeVarOccurrences s

/-- Duplicate-free list of free variables `FV(r)` in `r`. -/
def freeVars (r : Term) : List Var :=
  (freeVarOccurrences r).eraseDups

/-- All variables (free or bound) occurring in `r`. -/
def allVarsTerm : Term → List Var
  | .var x => [x]
  | .const _ => []
  | .lam x r => x :: allVarsTerm r
  | .app r s => allVarsTerm r ++ allVarsTerm s

/-- Whether a term `r` is closed (`FV(r) = ∅`). -/
def IsClosedTerm (r : Term) : Prop :=
  freeVars r = []

/-- Maximum variable `id` occurring in a term `r`. -/
def maxVarIdTerm : Term → Nat
  | .var x => x.id
  | .const _ => 0
  | .lam x r => Nat.max x.id (maxVarIdTerm r)
  | .app r s => Nat.max (maxVarIdTerm r) (maxVarIdTerm s)

/-- Structural size of a term `r`. -/
def rawSize : Term → Nat
  | .var _ => 1
  | .const _ => 1
  | .lam _ r => rawSize r + 1
  | .app r s => rawSize r + rawSize s + 1

/-- Replace free occurrences of `x` with `y` in `r`. -/
def renameFreeVar (r : Term) (x y : Var) : Term :=
  match r with
  | .var v => if v == x then .var y else .var v
  | .const c => .const c
  | .lam v body =>
      if v == x then .lam v body else .lam v (renameFreeVar body x y)
  | .app t s => .app (renameFreeVar t x y) (renameFreeVar s x y)

theorem renameFreeVar_rawSize (r : Term) (x y : Var) :
    rawSize (renameFreeVar r x y) = rawSize r := by
  induction r with
  | var v => simp only [renameFreeVar]; split <;> rfl
  | const c => rfl
  | lam v body ih =>
      simp only [renameFreeVar]
      split
      · rfl
      · simp [rawSize, ih]
  | app t s iht ihs => simp [renameFreeVar, rawSize, iht, ihs]

/-- Capture-avoiding substitution `r[x := s]` in a System `T` term. -/
def substTerm (r : Term) (x : Var) (s : Term) : Term :=
  match r with
  | .var v => if v == x then s else .var v
  | .const c => .const c
  | .lam v body =>
      if v == x then
        .lam v body
      else if v ∈ freeVarOccurrences s then
        let freshId := Nat.max (maxVarIdTerm body) (Nat.max (maxVarIdTerm 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)
  | .app t u => .app (substTerm t x s) (substTerm u x s)
termination_by rawSize r
decreasing_by
  all_goals
    simp_wf
    simp [rawSize, renameFreeVar_rawSize]
    try omega

/-- Canonical closed default term of each type `ρ` (built from `0^ι` and `false^o`). -/
def defaultTerm : Ty → Term
  | .iota => .const .zero
  | .bool => .const .falseConst
  | .arr ρ σ => .lam ⟨0, ρ⟩ (defaultTerm σ)

/-- α-equivalence on System `T` terms. -/
inductive AlphaEqTerm : Term → Term → Prop where
  | refl (r : Term) : AlphaEqTerm r r
  | symm {r s : Term} : AlphaEqTerm r s → AlphaEqTerm s r
  | trans {r s t : Term} : AlphaEqTerm r s → AlphaEqTerm s t → AlphaEqTerm r t
  | app {r r' s s' : Term} :
      AlphaEqTerm r r' → AlphaEqTerm s s' → AlphaEqTerm (.app r s) (.app r' s')
  | lam_rename (x y : Var) (r : Term) :
      x.ty = y.ty →
      (y = x ∨ y ∉ allVarsTerm r) →
      AlphaEqTerm (.lam x r) (.lam y (renameFreeVar r x y))
  | lam_congr (x : Var) {r s : Term} :
      AlphaEqTerm r s → AlphaEqTerm (.lam x r) (.lam x s)

/-- Conversion rules `↦_βR` for System `T` (Section 2, p. 4):
- `(λx. r) s ↦_β r[x := s]`
- `R_{o,ρ} r s true ↦_R r`
- `R_{o,ρ} r s false ↦_R s`
- `R_{ι,ρ} r s 0 ↦_R r`
- `R_{ι,ρ} r s (t + 1) ↦_R s t (R_{ι,ρ} r s t)`. -/
inductive ConvStep : Term → Term → Prop where
  | beta (x : Var) (r s : Term) :
      ConvStep (.app (.lam x r) s) (substTerm r x s)
  | recBoolTrue (ρ : Ty) (r s : Term) :
      ConvStep
        (.app (.app (.app (.const (.recBool ρ)) r) s) (.const .trueConst))
        r
  | recBoolFalse (ρ : Ty) (r s : Term) :
      ConvStep
        (.app (.app (.app (.const (.recBool ρ)) r) s) (.const .falseConst))
        s
  | recNatZero (ρ : Ty) (r s : Term) :
      ConvStep
        (.app (.app (.app (.const (.recNat ρ)) r) s) (.const .zero))
        r
  | recNatSucc (ρ : Ty) (r s t : Term) :
      ConvStep
        (.app (.app (.app (.const (.recNat ρ)) r) s) (Term.succTerm t))
        (.app (.app s t) (.app (.app (.app (.const (.recNat ρ)) r) s) t))

/-- Meta-level `βR`-equality `r =_{βR} s` (Section 2, p. 4). -/
inductive BetaREq : Term → Term → Prop where
  | of_alpha {r s : Term} : AlphaEqTerm r s → BetaREq r s
  | of_conv {r s : Term} : ConvStep r s → BetaREq r s
  | refl (r : Term) : BetaREq r r
  | symm {r s : Term} : BetaREq r s → BetaREq s r
  | trans {r s t : Term} : BetaREq r s → BetaREq s t → BetaREq r t
  | lam (x : Var) {r s : Term} : BetaREq r s → BetaREq (.lam x r) (.lam x s)
  | app {r r' s s' : Term} : BetaREq r r' → BetaREq s s' → BetaREq (.app r s) (.app r' s')

/-- Formulas of `L[X]` (Section 2, p. 4):
`⊥`, `X`, `atom(t^o)`, `A → B`, `∀x^ρ A`. -/
inductive Formula where
  | bot : Formula
  | varX : Formula
  | atom : Term → Formula
  | imp : Formula → Formula → Formula
  | all : Var → Formula → Formula
  deriving DecidableEq, Repr

namespace Formula

/-- Abbreviation `¬A := A → ⊥` (Section 2, p. 4). -/
def neg (A : Formula) : Formula :=
  .imp A .bot

/-- Double negation `¬¬A := (A → ⊥) → ⊥` (Lemma 2.2, p. 5). -/
def dneg (A : Formula) : Formula :=
  neg (neg A)

/-- Formula `F := atom(false)` (Lemma 2.1, p. 5). -/
def falseAtom : Formula :=
  .atom (.const .falseConst)

/-- Iterated implication `A₁ → ⋯ → Aₙ → B`. -/
def impMany : List Formula → Formula → Formula
  | [], B => B
  | A :: As, B => .imp A (impMany As B)

/-- Iterated universal quantification `∀y₁ ... ∀yₖ. A`. -/
def allMany : List Var → Formula → Formula
  | [], A => A
  | y :: ys, A => .all y (allMany ys A)

end Formula

/-- Whether every `atom(t)` in `A` has `HasType t .bool`. -/
inductive FormulaWellTyped : Formula → Prop where
  | bot : FormulaWellTyped .bot
  | varX : FormulaWellTyped .varX
  | atom {t : Term} : HasType t .bool → FormulaWellTyped (.atom t)
  | imp {A B : Formula} : FormulaWellTyped A → FormulaWellTyped B → FormulaWellTyped (.imp A B)
  | all (x : Var) {A : Formula} : FormulaWellTyped A → FormulaWellTyped (.all x A)

/-- Whether a formula belongs to `L` (contains no occurrences of `X`, Section 2, pp. 4–5). -/
def isLFormula : Formula → Bool
  | .bot => true
  | .varX => false
  | .atom _ => true
  | .imp A B => isLFormula A && isLFormula B
  | .all _ A => isLFormula A

/-- Whether a formula is an atomic `L`-formula (`⊥` or `atom(t)`, Section 2, p. 5 & Section 3, p. 6). -/
def isAtomicL : Formula → Bool
  | .bot => true
  | .atom _ => true
  | _ => false

/-- Whether a formula is quantifier-free (contains no `∀`, Section 2, p. 5 & Section 3, p. 6). -/
def isQuantifierFree : Formula → Bool
  | .bot | .varX | .atom _ => true
  | .imp A B => isQuantifierFree A && isQuantifierFree B
  | .all _ _ => false

/-- Replace `⊥` with `B` throughout a formula `C` (`C[⊥ := B]`, Section 2, pp. 4–5). -/
def substBotFormula (C B : Formula) : Formula :=
  match C with
  | .bot => B
  | .varX => .varX
  | .atom t => .atom t
  | .imp A₁ A₂ => .imp (substBotFormula A₁ B) (substBotFormula A₂ B)
  | .all x A => .all x (substBotFormula A B)

/-- `C^X := C[⊥ := X]` (Section 2, p. 4). -/
def substBotWithX (C : Formula) : Formula :=
  substBotFormula C .varX

/-- `A^F := A[⊥ := atom(false)]` (Lemma 2.1, p. 5). -/
def substBotWithFalse (A : Formula) : Formula :=
  substBotFormula A Formula.falseAtom

/-- Free object variables `FV(A)` of a formula `A`. -/
def freeVarsFormula : Formula → List Var
  | .bot | .varX => []
  | .atom t => freeVars t
  | .imp A B => (freeVarsFormula A ++ freeVarsFormula B).eraseDups
  | .all x A => (freeVarsFormula A).filter (· != x)

/-- Maximum variable `id` occurring in a formula `A`. -/
def maxVarIdFormula : Formula → Nat
  | .bot | .varX => 0
  | .atom t => maxVarIdTerm t
  | .imp A B => Nat.max (maxVarIdFormula A) (maxVarIdFormula B)
  | .all x A => Nat.max x.id (maxVarIdFormula A)

/-- Structural size of a formula `A`. -/
def formulaSize : Formula → Nat
  | .bot | .varX => 1
  | .atom _ => 1
  | .imp A B => formulaSize A + formulaSize B + 1
  | .all _ A => formulaSize A + 1

/-- Replace free occurrences of object variable `x` with `y` in a formula `A`. -/
def renameFreeVarFormula (A : Formula) (x y : Var) : Formula :=
  match A with
  | .bot => .bot
  | .varX => .varX
  | .atom t => .atom (renameFreeVar t x y)
  | .imp B C => .imp (renameFreeVarFormula B x y) (renameFreeVarFormula C x y)
  | .all v B =>
      if v == x then .all v B else .all v (renameFreeVarFormula B x y)

theorem renameFreeVarFormula_size (A : Formula) (x y : Var) :
    formulaSize (renameFreeVarFormula A x y) = formulaSize A := by
  induction A with
  | bot | varX | atom _ => rfl
  | imp B C ihB ihC => simp [renameFreeVarFormula, formulaSize, ihB, ihC]
  | all v B ih =>
      simp only [renameFreeVarFormula]
      split
      · rfl
      · simp [formulaSize, ih]

/-- Capture-avoiding substitution `A[x^ρ := t^ρ]` of a term `t` into a formula `A` (Section 2, p. 4). -/
def substFormula (A : Formula) (x : Var) (t : Term) : Formula :=
  match A with
  | .bot => .bot
  | .varX => .varX
  | .atom s => .atom (substTerm s x t)
  | .imp B C => .imp (substFormula B x t) (substFormula C x t)
  | .all v B =>
      if v == x then
        .all v B
      else if v ∈ freeVarOccurrences t then
        let freshId := Nat.max (maxVarIdFormula B) (Nat.max (maxVarIdTerm t) x.id) + 1
        let v' : Var := ⟨freshId, v.ty⟩
        .all v' (substFormula (renameFreeVarFormula B v v') x t)
      else
        .all v (substFormula B x t)
termination_by formulaSize A
decreasing_by
  all_goals
    simp_wf
    simp [formulaSize, renameFreeVarFormula_size]
    try omega

/-- Simultaneous substitution `A[y₁ := t₁, ..., yₖ := tₖ]` into a formula `A`. -/
def substFormulaMany : Formula → List (Var × Term) → Formula
  | A, [] => A
  | A, (y, t) :: rest => substFormulaMany (substFormula A y t) rest

/-- All object variables (free or bound) occurring in a formula `A`. -/
def allVarsFormula : Formula → List Var
  | .bot | .varX => []
  | .atom t => allVarsTerm t
  | .imp A B => allVarsFormula A ++ allVarsFormula B
  | .all x A => x :: allVarsFormula A

/-- Formula equality modulo α-renaming of bound variables and meta-level `=_{βR}` on embedded terms
(Section 2, p. 4). -/
inductive FormulaBetaREq : Formula → Formula → Prop where
  | refl (A : Formula) : FormulaBetaREq A A
  | symm {A B : Formula} : FormulaBetaREq A B → FormulaBetaREq B A
  | trans {A B C : Formula} : FormulaBetaREq A B → FormulaBetaREq B C → FormulaBetaREq A C
  | bot : FormulaBetaREq .bot .bot
  | varX : FormulaBetaREq .varX .varX
  | atom {t s : Term} : BetaREq t s → FormulaBetaREq (.atom t) (.atom s)
  | imp {A A' B B' : Formula} :
      FormulaBetaREq A A' → FormulaBetaREq B B' → FormulaBetaREq (.imp A B) (.imp A' B')
  | all (x : Var) {A A' : Formula} :
      FormulaBetaREq A A' → FormulaBetaREq (.all x A) (.all x A')
  | all_rename (x y : Var) (A : Formula) :
      x.ty = y.ty →
      (y = x ∨ y ∉ allVarsFormula A) →
      FormulaBetaREq (.all x A) (.all y (renameFreeVarFormula A x y))

/-- Assumption variable `u^B` in natural deduction derivations (Section 2, p. 4). -/
structure AssumpVar where
  id : Nat
  formula : Formula
  deriving DecidableEq, Repr

/-- Natural deduction proof terms in Curry–Howard style (Section 2, p. 4):
- `u^B` (assumptions)
- axioms `Ind_{n,A}`, `Ind_{p,A}`, `ax_true`, `ax_{false,A}`, `efq_A`
- `(λu^A M^B)^{A→B}`, `(M^{A→B} N^A)^B`
- `(λx^ρ M^A)^{∀x^ρ A}`, `(M^{∀x^ρ A} t^ρ)^{A[x^ρ := t^ρ]}`. -/
inductive ProofTerm where
  | assump : AssumpVar → ProofTerm
  | indNat : Var → Formula → ProofTerm
  | indBool : Var → Formula → ProofTerm
  | axTrue : ProofTerm
  | axFalse : Formula → ProofTerm
  | efq : Formula → ProofTerm
  | lamAssump : AssumpVar → ProofTerm → ProofTerm
  | appAssump : ProofTerm → ProofTerm → ProofTerm
  | lamTerm : Var → ProofTerm → ProofTerm
  | appTerm : ProofTerm → Term → ProofTerm
  deriving DecidableEq, Repr

/-- Free assumption variables `FA(M)` of a derivation `M` (Section 2, p. 4). -/
def freeAssumpVars : ProofTerm → List AssumpVar
  | .assump u => [u]
  | .indNat _ _ | .indBool _ _ | .axTrue | .axFalse _ | .efq _ => []
  | .lamAssump u M => (freeAssumpVars M).filter (· != u)
  | .appAssump M N => (freeAssumpVars M ++ freeAssumpVars N).eraseDups
  | .lamTerm _ M => freeAssumpVars M
  | .appTerm M _ => freeAssumpVars M

/-- Substitute `X` for `⊥` throughout a `Z_0`-derivation `M` to obtain `M^X` (Section 2, p. 4). -/
def substBotProof : ProofTerm → ProofTerm
  | .assump u => .assump ⟨u.id, substBotWithX u.formula⟩
  | .indNat n A => .indNat n (substBotWithX A)
  | .indBool p A => .indBool p (substBotWithX A)
  | .axTrue => .axTrue
  | .axFalse A => .axFalse (substBotWithX A)
  | .efq A => .efq (substBotWithX A)
  | .lamAssump u M => .lamAssump ⟨u.id, substBotWithX u.formula⟩ (substBotProof M)
  | .appAssump M N => .appAssump (substBotProof M) (substBotProof N)
  | .lamTerm x M => .lamTerm x (substBotProof M)
  | .appTerm M t => .appTerm (substBotProof M) t

/-- Configuration flags selecting one of the four systems `Z^X, Z, Z_0^X, Z_0` (Section 2, p. 4):
- `allowX`: whether the propositional symbol `X` is permitted in formulas (`L[X]` vs. `L`)
- `allowEfq`: whether the `efq_A : ⊥ → A` axiom scheme is permitted. -/
structure SysConfig where
  allowX : Bool
  allowEfq : Bool
  deriving DecidableEq, Repr

namespace SysConfig

/-- System `Z^X`: intuitionistic arithmetic over `L[X]` with `efq_A` (p. 4). -/
def ZX : SysConfig := ⟨true, true⟩

/-- System `Z`: intuitionistic arithmetic over `L` (`X`-free) with `efq_A` (p. 4). -/
def Z : SysConfig := ⟨false, true⟩

/-- System `Z_0^X`: minimal arithmetic over `L[X]` without `efq_A` (p. 4). -/
def ZX0 : SysConfig := ⟨true, false⟩

/-- System `Z_0`: minimal arithmetic over `L` (`X`-free) without `efq_A` (p. 4). -/
def Z0 : SysConfig := ⟨false, false⟩

/-- Whether a formula `A` is allowed in system `sys`. -/
def allowsFormula (sys : SysConfig) (A : Formula) : Prop :=
  FormulaWellTyped A ∧ (sys.allowX = true ∨ isLFormula A = true)

end SysConfig

/-- Induction axiom formula `Ind_{n,A} : A[n := 0] → ∀n(A → A[n := n + 1]) → ∀n A` (p. 2 & p. 4). -/
def indNatFormula (n : Var) (A : Formula) : Formula :=
  .imp
    (substFormula A n (.const .zero))
    (.imp
      (.all n (.imp A (substFormula A n (Term.succTerm (.var n)))))
      (.all n A))

/-- Boolean induction axiom formula `Ind_{p,A} : A[p := true] → A[p := false] → ∀p A` (p. 2 & p. 4). -/
def indBoolFormula (p : Var) (A : Formula) : Formula :=
  .imp
    (substFormula A p (.const .trueConst))
    (.imp
      (substFormula A p (.const .falseConst))
      (.all p A))

/-- Typing / derivability judgment `Derivable sys M A` for natural deduction proof terms `M`
in system `sys ∈ {Z^X, Z, Z_0^X, Z_0}` (Section 2, p. 4). -/
inductive Derivable (sys : SysConfig) : ProofTerm → Formula → Prop where
  | assump (u : AssumpVar) :
      sys.allowsFormula u.formula →
      Derivable sys (.assump u) u.formula
  | indNat (n : Var) (A : Formula) :
      n.ty = .iota →
      sys.allowsFormula A →
      Derivable sys (.indNat n A) (indNatFormula n A)
  | indBool (p : Var) (A : Formula) :
      p.ty = .bool →
      sys.allowsFormula A →
      Derivable sys (.indBool p A) (indBoolFormula p A)
  | axTrue :
      Derivable sys .axTrue (.atom (.const .trueConst))
  | axFalse (A : Formula) :
      sys.allowsFormula A →
      Derivable sys (.axFalse A) (.imp Formula.falseAtom A)
  | efq (A : Formula) :
      sys.allowEfq = true →
      sys.allowsFormula A →
      Derivable sys (.efq A) (.imp .bot A)
  | lamAssump (u : AssumpVar) {M : ProofTerm} {B : Formula} :
      sys.allowsFormula u.formula →
      Derivable sys M B →
      Derivable sys (.lamAssump u M) (.imp u.formula B)
  | appAssump {M N : ProofTerm} {A B : Formula} :
      Derivable sys M (.imp A B) →
      Derivable sys N A →
      Derivable sys (.appAssump M N) B
  | lamTerm (x : Var) {M : ProofTerm} {A : Formula} :
      (∀ u ∈ freeAssumpVars M, x ∉ freeVarsFormula u.formula) →
      Derivable sys M A →
      Derivable sys (.lamTerm x M) (.all x A)
  | appTerm {M : ProofTerm} {x : Var} {A : Formula} (t : Term) :
      HasType t x.ty →
      Derivable sys M (.all x A) →
      Derivable sys (.appTerm M t) (substFormula A x t)
  | conv {M : ProofTerm} {A B : Formula} :
      Derivable sys M A →
      sys.allowsFormula B →
      FormulaBetaREq A B →
      Derivable sys M B

/-- Closed derivability `sys ⊢ A` (`Provable sys A`, Section 2, pp. 4–5):
there is a derivation `M` of `A` in `sys` with no free assumption variables (`FA(M) = ∅`). -/
def Provable (sys : SysConfig) (A : Formula) : Prop :=
  ∃ M : ProofTerm, Derivable sys M A ∧ freeAssumpVars M = []

end BBS2002
Source
Ulrich Berger, Wilfried Buchholz, and Helmut Schwichtenberg, 'Refined program extraction from classical proofs', Annals of Pure and Applied Logic 114(1-3), 2002, pp. 3-25 (doi:10.1016/S0168-0072(01)00073-2). Section 2, pp. 5-7 (preprint pp. 3-5).
Read-back

What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)

Independent Mathematical Read-Back: Def_BBS2002_Arithmetic.lean

Ty and Ty.arrMany (Simple Types). Ty is an inductive type of simple types generated by two ground types Ty.iota (ι\iotaι, representing natural numbers) and Ty.bool (ooo, representing booleans), and a binary arrow constructor Ty.arr (ρ→σ\rho \to \sigmaρ→σ). For a list of argument types [ρ1,…,ρk][\rho_1, \dots, \rho_k][ρ1​,…,ρk​] and a target type σ\sigmaσ, Ty.arrMany defines the right-associated iterated function type ρ1→(ρ2→⋯→(ρk→σ)⋯ )\rho_1 \to (\rho_2 \to \cdots \to (\rho_k \to \sigma)\cdots)ρ1​→(ρ2​→⋯→(ρk​→σ)⋯), returning σ\sigmaσ when the list is empty.

Const and Const.ty (System T\mathsf{T}T Constants). Const is the inductive type of primitive constants of Gödel's System T\mathsf{T}T over ι\iotaι and ooo, and Const.ty assigns a simple type to each constant as follows:

ty(trueConst)=o,ty(falseConst)=o,ty(zero)=ι,ty(succ)=ι→ι,ty(recBool ρ)=ρ→ρ→o→ρ,ty(recNat ρ)=ρ→(ι→ρ→ρ)→ι→ρ,\begin{aligned} \mathsf{ty}(\mathsf{trueConst}) &= o, & \mathsf{ty}(\mathsf{falseConst}) &= o, \\ \mathsf{ty}(\mathsf{zero}) &= \iota, & \mathsf{ty}(\mathsf{succ}) &= \iota \to \iota, \\ \mathsf{ty}(\mathsf{recBool}\,\rho) &= \rho \to \rho \to o \to \rho, & \mathsf{ty}(\mathsf{recNat}\,\rho) &= \rho \to (\iota \to \rho \to \rho) \to \iota \to \rho, \end{aligned}ty(trueConst)ty(zero)ty(recBoolρ)​=o,=ι,=ρ→ρ→o→ρ,​ty(falseConst)ty(succ)ty(recNatρ)​=o,=ι→ι,=ρ→(ι→ρ→ρ)→ι→ρ,​

where arrows associate to the right, recBool ρ\mathsf{recBool}\,\rhorecBoolρ (Ro,ρR_{o,\rho}Ro,ρ​) is boolean recursion/case-analysis at type ρ\rhoρ, and recNat ρ\mathsf{recNat}\,\rhorecNatρ (Rι,ρR_{\iota,\rho}Rι,ρ​) is primitive recursion on natural numbers at type ρ\rhoρ.

Var, Term, Term.appMany, Term.lamMany, Term.succTerm, and HasType (System T\mathsf{T}T Terms and Typing). Var is a structure representing an intrinsically typed object variable xρx^\rhoxρ, consisting of a natural number identifier id∈N\mathrm{id} \in \mathbb{N}id∈N and a type ty:Ty\mathrm{ty} : \mathrm{Ty}ty:Ty (two variables are equal if and only if both their id\mathrm{id}id and ty\mathrm{ty}ty coincide). Term is the inductive syntax of System T\mathsf{T}T terms built from variables Term.var (xxx), constants Term.const (ccc), single-variable lambda abstractions Term.lam (λx. r\lambda x.\, rλx.r), and binary applications Term.app (r sr\, srs). Term.appMany constructs the left-associated multi-argument application (⋯(r s1)⋯ ) sk(\cdots(r\, s_1)\cdots)\, s_k(⋯(rs1​)⋯)sk​ (returning rrr on the empty list), Term.lamMany constructs the right-nested multi-variable abstraction λx1…λxk. r\lambda x_1 \dots \lambda x_k.\, rλx1​…λxk​.r (returning rrr on the empty list), and Term.succTerm defines t+1:=succ tt + 1 := \mathsf{succ}\, tt+1:=succt. The inductive relation HasType r ρ (r:ρr : \rhor:ρ) is defined without an external typing context (since each variable carries its type) by four rules:

  1. every variable var x\mathrm{var}\,xvarx has type x.tyx.\mathrm{ty}x.ty;
  2. every constant const c\mathrm{const}\,cconstc has type c.tyc.\mathrm{ty}c.ty;
  3. if r:σr : \sigmar:σ, then (λx. r):x.ty→σ(\lambda x.\, r) : x.\mathrm{ty} \to \sigma(λx.r):x.ty→σ (even if rrr contains other free variables with the same numeric id\mathrm{id}id as xxx but a different type);
  4. if r:ρ→σr : \rho \to \sigmar:ρ→σ and s:ρs : \rhos:ρ, then (r s):σ(r\, s) : \sigma(rs):σ.

Variable Bookkeeping, renameFreeVar, substTerm, and defaultTerm. For any term rrr:

  • freeVarOccurrences r collects the list of free variable occurrences in rrr in left-to-right order, filtering out xxx (by full Var equality of both id\mathrm{id}id and ty\mathrm{ty}ty) under λx\lambda xλx; freeVars r removes duplicates from freeVarOccurrences r; and IsClosedTerm r is the proposition freeVars(r)=[ ]\mathrm{freeVars}(r) = [\,]freeVars(r)=[].
  • allVarsTerm r collects all variables occurring in rrr (both bound binders and variable references), maxVarIdTerm r computes the maximum id\mathrm{id}id among all variables in allVarsTerm r (returning 000 on constants), and rawSize r is the syntactic node count (111 on variables and constants, rawSize(r)+1\mathrm{rawSize}(r) + 1rawSize(r)+1 on λx. r\lambda x.\, rλx.r, and rawSize(r)+rawSize(s)+1\mathrm{rawSize}(r) + \mathrm{rawSize}(s) + 1rawSize(r)+rawSize(s)+1 on r sr\, srs).
  • renameFreeVar r x y replaces every free occurrence of xxx in rrr with yyy (halting under λv\lambda vλv if v=xv = xv=x, without renaming vvv if v=yv = yv=y), and renameFreeVar_rawSize proves that renameFreeVar preserves rawSize.
  • substTerm r x s defines capture-avoiding substitution r[x:=s]r[x := s]r[x:=s] by structural recursion on rawSize(r)\mathrm{rawSize}(r)rawSize(r): it replaces var v\mathrm{var}\,vvarv with sss if v=xv = xv=x (and leaves it unchanged otherwise), leaves constants unchanged, distributes over applications, and for λv. body\lambda v.\,\mathrm{body}λv.body returns λv. body\lambda v.\,\mathrm{body}λv.body if v=xv = xv=x, else if v∈freeVarOccurrences(s)v \in \mathrm{freeVarOccurrences}(s)v∈freeVarOccurrences(s) renames vvv to the fresh variable v′=⟨max⁡(maxVarIdTerm(body),max⁡(maxVarIdTerm(s),x.id))+1,v.ty⟩v' = \langle \max(\mathrm{maxVarIdTerm}(\mathrm{body}), \max(\mathrm{maxVarIdTerm}(s), x.\mathrm{id})) + 1, v.\mathrm{ty}\ranglev′=⟨max(maxVarIdTerm(body),max(maxVarIdTerm(s),x.id))+1,v.ty⟩ in body\mathrm{body}body before recursively substituting [x:=s][x := s][x:=s], and otherwise substitutes [x:=s][x := s][x:=s] directly under λv\lambda vλv.
  • defaultTerm ρ defines a canonical closed term of each type ρ\rhoρ: 0ι0^\iota0ι for ι\iotaι, falseo\mathsf{false}^ofalseo for ooo, and λ⟨0,ρ⟩. defaultTerm(σ)\lambda\langle 0, \rho\rangle.\,\mathrm{defaultTerm}(\sigma)λ⟨0,ρ⟩.defaultTerm(σ) for ρ→σ\rho \to \sigmaρ→σ.

AlphaEqTerm, ConvStep, and BetaREq (α\alphaα-Equivalence and βR\beta RβR-Equality on Terms). AlphaEqTerm (≡α\equiv_\alpha≡α​) is the equivalence and congruence relation on Term generated by single-binder α\alphaα-renaming: whenever x.ty=y.tyx.\mathrm{ty} = y.\mathrm{ty}x.ty=y.ty and either y=xy = xy=x or y∉allVarsTerm(r)y \notin \mathrm{allVarsTerm}(r)y∈/allVarsTerm(r), λx. r≡αλy. renameFreeVar(r,x,y)\lambda x.\, r \equiv_\alpha \lambda y.\,\mathrm{renameFreeVar}(r, x, y)λx.r≡α​λy.renameFreeVar(r,x,y). ConvStep (r↦βRsr \mapsto_{\beta R} sr↦βR​s) is the five-clause top-level contraction relation on (not necessarily well-typed) terms:

(λx. r) s↦βRr[x:=s],Ro,ρ r s true↦βRr,Ro,ρ r s false↦βRs,Rι,ρ r s 0↦βRr,Rι,ρ r s (t+1)↦βRs t (Rι,ρ r s t).\begin{aligned} (\lambda x.\, r)\, s &\mapsto_{\beta R} r[x := s], \\ R_{o,\rho}\, r\, s\, \mathsf{true} &\mapsto_{\beta R} r, & R_{o,\rho}\, r\, s\, \mathsf{false} &\mapsto_{\beta R} s, \\ R_{\iota,\rho}\, r\, s\, 0 &\mapsto_{\beta R} r, & R_{\iota,\rho}\, r\, s\, (t + 1) &\mapsto_{\beta R} s\, t\, (R_{\iota,\rho}\, r\, s\, t). \end{aligned}(λx.r)sRo,ρ​rstrueRι,ρ​rs0​↦βR​r[x:=s],↦βR​r,↦βR​r,​Ro,ρ​rsfalseRι,ρ​rs(t+1)​↦βR​s,↦βR​st(Rι,ρ​rst).​

BetaREq (r=βRsr =_{\beta R} sr=βR​s) is the reflexive, symmetric, transitive, and congruence closure (under λx\lambda xλx and application) of the union of AlphaEqTerm and ConvStep.

Formula, Logical Abbreviations, and Syntactic Predicates (FormulaWellTyped, isLFormula, isAtomicL, isQuantifierFree). Formula is the inductive syntax of formulas of L[X]\mathcal{L}[X]L[X], with constructors:

  • Formula.bot (⊥\bot⊥, falsity),
  • Formula.varX (XXX, a distinguished propositional parameter),
  • Formula.atom t (atom(t)\mathrm{atom}(t)atom(t), an atomic formula wrapping a term ttt),
  • Formula.imp A B (A→BA \to BA→B, implication),
  • Formula.all x A (∀x. A\forall x.\, A∀x.A, universal quantification over a typed variable x:Varx : \mathrm{Var}x:Var).

The namespace Formula defines ¬A:=A→⊥\neg A := A \to \bot¬A:=A→⊥ (Formula.neg), ¬¬A:=(A→⊥)→⊥\neg\neg A := (A \to \bot) \to \bot¬¬A:=(A→⊥)→⊥ (Formula.dneg), F:=atom(falseo)F := \mathrm{atom}(\mathsf{false}^o)F:=atom(falseo) (Formula.falseAtom), right-associated iterated implication A1→⋯→An→BA_1 \to \cdots \to A_n \to BA1​→⋯→An​→B (Formula.impMany, returning BBB when the antecedent list is empty), and iterated universal quantification ∀y1…∀yk. A\forall y_1 \dots \forall y_k.\, A∀y1​…∀yk​.A (Formula.allMany, returning AAA when the variable list is empty).

  • FormulaWellTyped A is the inductive proposition asserting that for every subformula of the form atom(t)\mathrm{atom}(t)atom(t) in AAA, the term ttt has type ooo (HasType t .bool). Note that FormulaWellTyped imposes no condition on quantifiers ∀x. B\forall x.\, B∀x.B or on whether free variables with the same numeric id\mathrm{id}id have matching types.
  • isLFormula A returns true if and only if AAA contains no occurrences of XXX (Formula.varX).
  • isAtomicL A returns true if and only if AAA is ⊥\bot⊥ or atom(t)\mathrm{atom}(t)atom(t) for some term ttt (in particular, isAtomicL is false on XXX).
  • isQuantifierFree A returns true if and only if AAA contains no universal quantifiers ∀x\forall x∀x.

Formula Substitutions and FormulaBetaREq.

  • substBotFormula C B replaces every occurrence of ⊥\bot⊥ in CCC with the formula BBB (C[⊥:=B]C[\bot := B]C[⊥:=B]). As special cases, substBotWithX C defines CX:=C[⊥:=X]C^X := C[\bot := X]CX:=C[⊥:=X] and substBotWithFalse A defines AF:=A[⊥:=atom(falseo)]A^F := A[\bot := \mathrm{atom}(\mathsf{false}^o)]AF:=A[⊥:=atom(falseo)].
  • freeVarsFormula A, allVarsFormula A, maxVarIdFormula A, formulaSize A, and renameFreeVarFormula A x y lift the corresponding object-variable operations from terms to formulas, with renameFreeVarFormula_size proving that variable renaming preserves formulaSize.
  • substFormula A x t defines capture-avoiding substitution A[x:=t]A[x := t]A[x:=t] of a term ttt for an object variable xxx in AAA, renaming a bound quantifier variable vvv in ∀v. B\forall v.\, B∀v.B (when v≠xv \neq xv=x and v∈freeVarOccurrences(t)v \in \mathrm{freeVarOccurrences}(t)v∈freeVarOccurrences(t)) to v′=⟨max⁡(maxVarIdFormula(B),max⁡(maxVarIdTerm(t),x.id))+1,v.ty⟩v' = \langle \max(\mathrm{maxVarIdFormula}(B), \max(\mathrm{maxVarIdTerm}(t), x.\mathrm{id})) + 1, v.\mathrm{ty}\ranglev′=⟨max(maxVarIdFormula(B),max(maxVarIdTerm(t),x.id))+1,v.ty⟩.
  • substFormulaMany A [(y_1, t_1), ..., (y_k, t_k)] performs sequential (left-to-right iterated) substitution (⋯(A[y1:=t1])⋯ )[yk:=tk](\cdots(A[y_1 := t_1])\cdots)[y_k := t_k](⋯(A[y1​:=t1​])⋯)[yk​:=tk​]; note that despite its docstring ("Simultaneous substitution"), if a term tit_iti​ contains a variable yjy_jyj​ with j>ij > ij>i, the later substitution [yj:=tj][y_j := t_j][yj​:=tj​] will substitute into tit_iti​ as well.
  • FormulaBetaREq A B is the equivalence relation on formulas generated by congruence under →\to→ and ∀\forall∀, lifting BetaREq t s to atom(t)≃βRatom(s)\mathrm{atom}(t) \simeq_{\beta R} \mathrm{atom}(s)atom(t)≃βR​atom(s), and single-binder α\alphaα-renaming of ∀x. A\forall x.\, A∀x.A to ∀y. renameFreeVarFormula(A,x,y)\forall y.\,\mathrm{renameFreeVarFormula}(A, x, y)∀y.renameFreeVarFormula(A,x,y) whenever x.ty=y.tyx.\mathrm{ty} = y.\mathrm{ty}x.ty=y.ty and (y=x∨y∉allVarsFormula(A))(y = x \lor y \notin \mathrm{allVarsFormula}(A))(y=x∨y∈/allVarsFormula(A)).

AssumpVar, ProofTerm, freeAssumpVars, and substBotProof (Natural Deduction Proof Terms). AssumpVar is a structure representing an assumption variable uBu^BuB with a numeric identifier id∈N\mathrm{id} \in \mathbb{N}id∈N and a formula formula:Formula\mathrm{formula} : \mathrm{Formula}formula:Formula. ProofTerm is the inductive syntax of Curry–Howard proof terms:

  • assump u (assumption variable uuu),
  • indNat n A (induction axiom Indn,A\mathsf{Ind}_{n,A}Indn,A​ on natural numbers),
  • indBool p A (case-analysis/induction axiom Indp,A\mathsf{Ind}_{p,A}Indp,A​ on booleans),
  • axTrue (truth axiom axtrue\mathsf{ax}_{\mathsf{true}}axtrue​),
  • axFalse A (boolean-false elimination axiom axfalse,A\mathsf{ax}_{\mathsf{false},A}axfalse,A​),
  • efq A (ex falso quodlibet axiom efqA\mathsf{efq}_AefqA​),
  • lamAssump u M (implication introduction λu. M\lambda u.\, Mλu.M),
  • appAssump M N (implication elimination M NM\, NMN),
  • lamTerm x M (universal introduction λx. M\lambda x.\, Mλx.M),
  • appTerm M t (universal elimination M tM\, tMt).

freeAssumpVars M (FA(M)\mathsf{FA}(M)FA(M)) computes the duplicate-free list of free assumption variables in MMM, where lamAssump u M removes only assumption variables strictly equal to uuu (matching both u.idu.\mathrm{id}u.id and u.formulau.\mathrm{formula}u.formula syntactically). substBotProof M (MXM^XMX) replaces every formula annotation BBB occurring inside MMM (in assump, indNat, indBool, axFalse, efq, and lamAssump) by BX=B[⊥:=X]B^X = B[\bot := X]BX=B[⊥:=X].

SysConfig, indNatFormula, indBoolFormula, Derivable, and Provable (Derivability in ZX,Z,Z0X,Z0Z^X, Z, Z_0^X, Z_0ZX,Z,Z0X​,Z0​). SysConfig is a pair of booleans ⟨allowX,allowEfq⟩\langle \mathrm{allowX}, \mathrm{allowEfq}\rangle⟨allowX,allowEfq⟩ configuring four formal systems:

ZX(ZX)=⟨true,true⟩,Z(Z)=⟨false,true⟩,Z0X(ZX0)=⟨true,false⟩,Z0(Z0)=⟨false,false⟩.\begin{aligned} Z^X (\text{\texttt{ZX}}) &= \langle \mathsf{true}, \mathsf{true}\rangle, & Z (\text{\texttt{Z}}) &= \langle \mathsf{false}, \mathsf{true}\rangle, \\ Z_0^X (\text{\texttt{ZX0}}) &= \langle \mathsf{true}, \mathsf{false}\rangle, & Z_0 (\text{\texttt{Z0}}) &= \langle \mathsf{false}, \mathsf{false}\rangle. \end{aligned}ZX(ZX)Z0X​(ZX0)​=⟨true,true⟩,=⟨true,false⟩,​Z(Z)Z0​(Z0)​=⟨false,true⟩,=⟨false,false⟩.​

A formula AAA satisfies sys.allowsFormula A if and only if FormulaWellTyped(A)\mathrm{FormulaWellTyped}(A)FormulaWellTyped(A) holds and either sys.allowX=true\mathrm{sys.allowX} = \mathsf{true}sys.allowX=true or isLFormula(A)=true\mathrm{isLFormula}(A) = \mathsf{true}isLFormula(A)=true. The induction axiom formulas are defined by

indNatFormula(n,A):=A[n:=0]→(∀n. (A→A[n:=n+1]))→∀n. A,indBoolFormula(p,A):=A[p:=true]→A[p:=false]→∀p. A.\begin{aligned} \mathrm{indNatFormula}(n, A) &:= A[n := 0] \to \bigl(\forall n.\, (A \to A[n := n + 1])\bigr) \to \forall n.\, A, \\ \mathrm{indBoolFormula}(p, A) &:= A[p := \mathsf{true}] \to A[p := \mathsf{false}] \to \forall p.\, A. \end{aligned}indNatFormula(n,A)indBoolFormula(p,A)​:=A[n:=0]→(∀n.(A→A[n:=n+1]))→∀n.A,:=A[p:=true]→A[p:=false]→∀p.A.​

Derivable sys M A is the inductive derivability judgment defined by the following clauses:

  1. (assump) if sys.allowsFormula(u.formula)\mathrm{sys.allowsFormula}(u.\mathrm{formula})sys.allowsFormula(u.formula), then uuu derives u.formulau.\mathrm{formula}u.formula;
  2. (indNat) if n.ty=ιn.\mathrm{ty} = \iotan.ty=ι and sys.allowsFormula(A)\mathrm{sys.allowsFormula}(A)sys.allowsFormula(A), then Indn,A\mathsf{Ind}_{n,A}Indn,A​ derives indNatFormula(n,A)\mathrm{indNatFormula}(n, A)indNatFormula(n,A);
  3. (indBool) if p.ty=op.\mathrm{ty} = op.ty=o and sys.allowsFormula(A)\mathrm{sys.allowsFormula}(A)sys.allowsFormula(A), then Indp,A\mathsf{Ind}_{p,A}Indp,A​ derives indBoolFormula(p,A)\mathrm{indBoolFormula}(p, A)indBoolFormula(p,A);
  4. (axTrue) axtrue\mathsf{ax}_{\mathsf{true}}axtrue​ derives atom(trueo)\mathrm{atom}(\mathsf{true}^o)atom(trueo);
  5. (axFalse) if sys.allowsFormula(A)\mathrm{sys.allowsFormula}(A)sys.allowsFormula(A), then axfalse,A\mathsf{ax}_{\mathsf{false},A}axfalse,A​ derives atom(falseo)→A\mathrm{atom}(\mathsf{false}^o) \to Aatom(falseo)→A;
  6. (efq) if sys.allowEfq=true\mathrm{sys.allowEfq} = \mathsf{true}sys.allowEfq=true and sys.allowsFormula(A)\mathrm{sys.allowsFormula}(A)sys.allowsFormula(A), then efqA\mathsf{efq}_AefqA​ derives ⊥→A\bot \to A⊥→A;
  7. (lamAssump) if sys.allowsFormula(u.formula)\mathrm{sys.allowsFormula}(u.\mathrm{formula})sys.allowsFormula(u.formula) and MMM derives BBB, then λu. M\lambda u.\, Mλu.M derives u.formula→Bu.\mathrm{formula} \to Bu.formula→B;
  8. (appAssump) if MMM derives A→BA \to BA→B and NNN derives AAA, then M NM\, NMN derives BBB;
  9. (lamTerm) if for every u∈freeAssumpVars(M)u \in \mathrm{freeAssumpVars}(M)u∈freeAssumpVars(M) we have x∉freeVarsFormula(u.formula)x \notin \mathrm{freeVarsFormula}(u.\mathrm{formula})x∈/freeVarsFormula(u.formula), and MMM derives AAA, then λx. M\lambda x.\, Mλx.M derives ∀x. A\forall x.\, A∀x.A;
  10. (appTerm) if t:x.tyt : x.\mathrm{ty}t:x.ty and MMM derives ∀x. A\forall x.\, A∀x.A, then M tM\, tMt derives A[x:=t]A[x := t]A[x:=t];
  11. (conv) if MMM derives AAA, sys.allowsFormula(B)\mathrm{sys.allowsFormula}(B)sys.allowsFormula(B), and FormulaBetaREq(A,B)\mathrm{FormulaBetaREq}(A, B)FormulaBetaREq(A,B), then MMM also derives BBB.

Finally, Provable sys A (sys⊢A\mathrm{sys} \vdash Asys⊢A) asserts that there exists a proof term MMM such that Derivable sys M A and freeAssumpVars(M)=[ ]\mathrm{freeAssumpVars}(M) = [\,]freeAssumpVars(M)=[].

Human review
  • Endorsed by Shuze Chen · Oct 31, 2026

    Confirmed by the moderator at approval.

  • Endorsed by kmehltretter82 · Oct 31, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me