Natural numbers and primitive recursion¶
This page constructs the natural numbers, their induction principle, and primitive recursion inside the logic, by definitions alone. Nothing here changes the kernel, the root theory, or a profile's axioms: every new symbol is a conservative definition (Theorem M-5), a type definition (Theorem Y-1), or a specification (Theorem Y-2), and every new theorem is derived by the kernel's rules. The construction is the one HOL Light and Isabelle/HOL use, with recursion obtained from an impredicative graph and choice [Harrison 2009; Gordon and Melham 1993]. The optional theory package specified on the natural numbers implementation page builds it. Results are numbered NR.
Inputs¶
The construction runs in a theory \(T_0\) that contains, as axioms or theorems, the following classical principles. They are recognized by their checked statements, never by their names.
- (I1) Choice. A constant \(\varepsilon[\alpha]: (\alpha \to \mathsf{Prop}) \to \alpha\) with the scheme \(\forall P\, x.\; P\,x \to P(\varepsilon\,P)\).
- (I2) Function extensionality. The scheme \(\forall f\, g{:}\alpha \to \beta.\; (\forall x.\, f\,x = g\,x) \to f = g\).
- (I3) Infinity, in witness form. A type \(\mathsf{ind}\), a nullary type constructor or a nullary type definition, with \(\vdash \exists s\, z.\; (\forall x\, y.\, s\,x = s\,y \to x = y) \land (\forall x.\, \neg\, s\,x = z)\).
These are the classical principles of the
deduction page (Classical principles), with infinity stated
for an existentially quantified function. A profile may instead
declare infinity for a named successor \(c\), as scalar does:
\((\forall x\, y.\, c\,x = c\,y \to x = y) \land (\exists z.\, \forall x.\, \neg\, c\,x = z)\).
(I3) follows from it by ∃E on \(z\), ∃I with \(z\) and then with \(c\), and
reassembling the conjunction. (I1) is used by Definitions NR-3 and NR-4,
and in the proofs of Theorems NR-2(2), (3), NR-5(6), and Corollary NR-5a;
(I2) only for equations between functions (Theorems NR-4(3), NR-5(5),
NR-6(2), Corollary NR-5a).
Excluded middle is not used; it follows from (I1), (I2), and the core's
propositional extensionality anyway [Diaconescu 1975]. A constructive
profile cannot use this construction.
Below, \(\mathsf{Inj}(z, s)\) and \(\mathsf{Fresh}(z, s)\) abbreviate, for \(z{:}\tau\) and \(s{:}\tau \to \tau\),
They are not declarations: every statement that uses them spells them out.
The least closed predicate¶
Definition NR-1 (least closed predicate). The transparent definition
of type \(\tau \to (\tau \to \tau) \to \tau \to \mathsf{Prop}\). \(\mathsf{least}\,z\,s\) is the intersection of all predicates that contain \(z\) and are closed under \(s\). Its body is closed, does not mention \(\mathsf{least}\), and has the type variable \(\tau\) only, which occurs in its type, so it is a conservative definition by Theorem M-5.
Theorem NR-1 (closure and induction). For all \(\tau\), \(z{:}\tau\), \(s{:}\tau \to \tau\):
- \(\vdash \mathsf{least}\,z\,s\,z\);
- \(\vdash \forall y.\; \mathsf{least}\,z\,s\,y \to \mathsf{least}\,z\,s\,(s\,y)\);
- (induction) \(\vdash \forall P.\; P\,z \to (\forall y.\, P\,y \to P(s\,y)) \to \forall x.\; \mathsf{least}\,z\,s\,x \to P\,x\);
- (induction with the hypothesis) \(\vdash \forall P.\; P\,z \to (\forall y.\, \mathsf{least}\,z\,s\,y \to P\,y \to P(s\,y)) \to \forall x.\; \mathsf{least}\,z\,s\,x \to P\,x\).
Proof. Each statement is closed over \(z\) and \(s\) by (∀I), so it suffices to prove it with \(z\) and \(s\) fixed. By δ for \(\mathsf{least}\) and β, \(\mathsf{least}\,z\,s\,x \equiv_{\{\mathsf{least}\}} \forall P.\; P\,z \to (\forall y.\, P\,y \to P(s\,y)) \to P\,x\), so (Conv) moves between the two forms.
(3) Assume \(P\,z\), \(\forall y.\, P\,y \to P(s\,y)\), and \(\mathsf{least}\,z\,s\,x\). Convert the last, instantiate it at \(P\) (∀E), and apply it to the first two (→E). This is \(P\,x\).
(1) Fix \(P\) and assume \(P\,z\) and the step. The goal \(P\,z\) is the first assumption. Discharge, generalize \(P\), and convert back.
(2) Fix \(y\), assume \(\mathsf{least}\,z\,s\,y\), fix \(P\), and assume \(P\,z\) and \(h: \forall y'.\, P\,y' \to P(s\,y')\). By (3), \(P\,y\); by \(h\) at \(y\), \(P(s\,y)\). Discharge, generalize \(P\), and convert back.
(4) Let \(P' := \lambda x.\; \mathsf{least}\,z\,s\,x \land P\,x\). Then \(P'\,z\) by (1) and the assumption \(P\,z\). If \(P'\,y\), then \(\mathsf{least}\,z\,s\,(s\,y)\) by (2), and \(P(s\,y)\) by the step applied to the two conjuncts, so \(P'(s\,y)\). By (3) at \(P'\), \(\mathsf{least}\,z\,s\,x \to P'\,x\), whose right conjunct is \(P\,x\). β-steps are canonical construction, so \(P'\,x\) is \(\mathsf{least}\,z\,s\,x \land P\,x\) as built. \(\square\)
Recursion on a least closed predicate¶
Definition NR-2 (recursion graph). The transparent definition
of type \(\tau \to (\tau \to \tau) \to \alpha \to (\tau \to \alpha \to \alpha) \to \tau \to \alpha \to \mathsf{Prop}\). \(\mathsf{graph}\,z\,s\,a\,f\) is the least relation containing \((z, a)\) and closed under \((y, c) \mapsto (s\,y, f\,y\,c)\). Its type variables, \(\tau\) and \(\alpha\), occur in its type: a conservative definition.
Definition NR-3 (recursor). The opaque definition
of type \(\tau \to (\tau \to \tau) \to \alpha \to (\tau \to \alpha \to \alpha) \to \tau \to \alpha\), where \(\varepsilon\) is the choice constant of (I1). The argument of \(\varepsilon\) is the partial application \(\mathsf{graph}\,z\,s\,a\,f\,x\) of type \(\alpha \to \mathsf{Prop}\), not an η-expansion of it. The definition is opaque, so conversion never unfolds it (C1.5); its equation is used only through (Use). It is conservative by Theorem M-5.
Lemma NR-2a (the graph). For fixed \(z, s, a, f\), write \(G\,x\,b\) for \(\mathsf{graph}\,z\,s\,a\,f\,x\,b\). Then:
- \(\vdash G\,z\,a\);
- \(\vdash \forall x\, c.\; G\,x\,c \to G\,(s\,x)\,(f\,x\,c)\);
- (graph induction) for every \(R{:}\tau \to \alpha \to \mathsf{Prop}\), from \(R\,z\,a\) and \(\forall y\, c.\, R\,y\,c \to R\,(s\,y)\,(f\,y\,c)\) follows \(\forall x\, b.\; G\,x\,b \to R\,x\,b\);
- \(\vdash \forall x\, b.\; G\,x\,b \to \mathsf{least}\,z\,s\,x\);
- (inversion) \(\vdash \forall x\, b.\; G\,x\,b \to (x = z \land b = a) \lor (\exists y\, c.\; x = s\,y \land b = f\,y\,c \land G\,y\,c)\).
Proof. (1), (2), (3) are Theorem NR-1(1), (2), (3) for a binary predicate, with the same proofs: unfold \(G\) by δ and β, instantiate \(Q\), and apply.
(4) Graph induction (3) with \(R\,x\,b := \mathsf{least}\,z\,s\,x\): the base is Theorem NR-1(1), the step Theorem NR-1(2) (the \(c\) is unused).
(5) Graph induction with \(R\,x\,b := G\,x\,b \land D\,x\,b\), where \(D\,x\,b\) is the disjunction to be proved. Base: \(G\,z\,a\) by (1), and \(D\,z\,a\) by its left disjunct, \(z = z \land a = a\) (Refl). Step: from \(R\,y\,c\), take \(G\,y\,c\); then \(G\,(s\,y)\,(f\,y\,c)\) by (2), and \(D\,(s\,y)\,(f\,y\,c)\) by its right disjunct, with witnesses \(y\) and \(c\), the two reflexivities, and \(G\,y\,c\) (∃I twice). So \(R\) holds of every pair in \(G\); its right conjunct is the claim. The conjunct \(G\,x\,b\) is what makes the step go through: \(D\) alone is not closed under the step, because its right disjunct asks for \(G\,y\,c\). \(\square\)
Theorem NR-2 (recursion on a least closed predicate). Let \(z{:}\tau\) and \(s{:}\tau \to \tau\) satisfy \(\mathsf{Inj}(z, s)\) and \(\mathsf{Fresh}(z, s)\), and let \(a{:}\alpha\) and \(f{:}\tau \to \alpha \to \alpha\). Write \(G\) as in Lemma NR-2a and \(R := \mathsf{recursor}\,z\,s\,a\,f\). Then:
- (unique graph) \(\vdash \forall x.\; \mathsf{least}\,z\,s\,x \to (\exists b.\, G\,x\,b) \land (\forall b\, b'.\, G\,x\,b \to G\,x\,b' \to b = b')\);
- \(\vdash R\,z = a\);
- \(\vdash \forall x.\; \mathsf{least}\,z\,s\,x \to R\,(s\,x) = f\,x\,(R\,x)\);
- (uniqueness) for every \(h{:}\tau \to \alpha\), \(\vdash h\,z = a \to (\forall x.\, \mathsf{least}\,z\,s\,x \to h\,(s\,x) = f\,x\,(h\,x)) \to \forall x.\; \mathsf{least}\,z\,s\,x \to h\,x = R\,x\).
The declared theorems are closed over \(z, s\) (with the hypotheses \(\mathsf{Inj}\) and \(\mathsf{Fresh}\) as premises), \(a, f\), and \(h\).
Proof. (1) By Theorem NR-1(4) with \(P\,x := (\exists b.\, G\,x\,b) \land U\,x\), where \(U\,x := \forall b\, b'.\, G\,x\,b \to G\,x\,b' \to b = b'\). It suffices, for each case, to show existence and that every \(b\) with \(G\,x\,b\) equals one fixed value \(b_0\); then \(b = b_0 = b'\).
Base, \(x = z\). Existence: \(G\,z\,a\) by Lemma NR-2a(1). Let \(G\,z\,b\). By inversion (Lemma NR-2a(5)) either \(z = z \land b = a\), so \(b = a\); or \(z = s\,y\), \(b = f\,y\,c\), and \(G\,y\,c\) for some \(y, c\). In the second case \(\mathsf{least}\,z\,s\,y\) by Lemma NR-2a(4), so \(\neg\, s\,y = z\) by \(\mathsf{Fresh}\), contradicting \(z = s\,y\) by (Sym); (⊥E) gives \(b = a\). So every \(b\) with \(G\,z\,b\) is \(a\).
Step. Let \(\mathsf{least}\,z\,s\,y\) and \(P\,y\), and take \(c_0\) with \(G\,y\,c_0\) (∃E). Existence: \(G\,(s\,y)\,(f\,y\,c_0)\) by Lemma NR-2a(2). Let \(G\,(s\,y)\,b\). By inversion, either \(s\,y = z\), which contradicts \(\mathsf{Fresh}\) at \(y\); or \(s\,y = s\,y'\), \(b = f\,y'\,c'\), and \(G\,y'\,c'\) for some \(y', c'\). Then \(\mathsf{least}\,z\,s\,y'\) by Lemma NR-2a(4), so \(y = y'\) by \(\mathsf{Inj}\) at \(y, y'\). Rewriting with it (Subst), \(G\,y\,c'\), so \(c' = c_0\) by \(U\,y\), and \(b = f\,y'\,c' = f\,y\,c_0\) by (Subst) and congruence (App). So every \(b\) with \(G\,(s\,y)\,b\) is \(f\,y\,c_0\).
For (2) and (3), first: if \(\mathsf{least}\,z\,s\,x\), then \(G\,x\,(R\,x)\). By the equation of \(\mathsf{recursor}\) (Use), congruence, and β, \(R\,x = \varepsilon\,(G\,x)\). By (1) there is \(b\) with \(G\,x\,b\); choice (I1) at \(P := G\,x\) and \(b\) gives \(G\,x\,(\varepsilon\,(G\,x))\), and (Subst) with the equation gives \(G\,x\,(R\,x)\).
(2) \(\mathsf{least}\,z\,s\,z\) (Theorem NR-1(1)), so \(G\,z\,(R\,z)\) and \(G\,z\,a\) (Lemma NR-2a(1)). The uniqueness part of (1) at \(z\) gives \(R\,z = a\).
(3) Let \(\mathsf{least}\,z\,s\,x\). Then \(G\,x\,(R\,x)\), so \(G\,(s\,x)\,(f\,x\,(R\,x))\) by Lemma NR-2a(2). Also \(\mathsf{least}\,z\,s\,(s\,x)\) by Theorem NR-1(2), so \(G\,(s\,x)\,(R\,(s\,x))\). Uniqueness at \(s\,x\) gives \(R\,(s\,x) = f\,x\,(R\,x)\).
(4) Theorem NR-1(4) with \(P\,x := h\,x = R\,x\). Base: \(h\,z = a = R\,z\) by the hypothesis and (2). Step: for \(\mathsf{least}\,z\,s\,x\) and \(h\,x = R\,x\), \(h\,(s\,x) = f\,x\,(h\,x) = f\,x\,(R\,x) = R\,(s\,x)\) by the hypothesis, congruence, and (3). \(\square\)
Neither hypothesis can be dropped. Without \(\mathsf{Fresh}\), take \(\tau = \mathsf{Prop}\), \(z = \mathsf{True}\), \(s = \lambda x.\, x\): \(\mathsf{least}\,z\,s\) holds of \(\mathsf{True}\) only, and \(G\,\mathsf{True}\,b\) holds for \(b = a, f\,\mathsf{True}\,a, \dots\), so the graph is not functional for a general \(f\). Without \(\mathsf{Inj}\), take \(s\,z = y\) and \(s\,y = y\) with \(y \neq z\): \(\mathsf{Fresh}\) holds on \(\mathsf{least}\,z\,s = \{z, y\}\), but \(G\) relates \(y\) to both \(f\,z\,a\) and \(f\,y\,(f\,z\,a)\).
The theorem is generic over \(\tau\), so it also gives recursion on a least
predicate inside another carrier, for example scalar's \(\mathbb N_0\):
the bodies of \(\mathbb N_0(x)\) and of
\(\mathsf{least}\,0\,(\lambda y.\, y + 1)\,x\) agree after β, and
\(\mathsf{Inj}\) and \(\mathsf{Fresh}\) on \(\mathbb N_0\) follow from Theorem
O-2(1), (2) of the scalar order page
together with additive cancellation on real numbers from the field laws.
The type of natural numbers¶
Definition NR-4 (the type \(\mathsf{nat}\)). In \(T_0\):
- Representatives. Let \(\Phi(s, z) := (\forall x\, y.\, s\,x = s\,y \to x = y) \land (\forall x.\, \neg\, s\,x = z)\), for \(s{:}\mathsf{ind} \to \mathsf{ind}\) and \(z{:}\mathsf{ind}\), and $$ t_s := \varepsilon\,(\lambda s.\, \exists z.\, \Phi(s, z)), \qquad t_z := \varepsilon\,(\lambda z.\, \Phi(t_s, z)). $$ The specification (Definition Y-2) with witness \(\vdash \forall v_1\, v_2.\; v_1 = t_s \to v_2 = t_z \to \Phi(v_1, v_2)\) declares \(\mathsf{suc\_rep}{:}\mathsf{ind} \to \mathsf{ind}\) and \(\mathsf{zero\_rep}{:}\mathsf{ind}\) with the theorem \(\Phi(\mathsf{suc\_rep}, \mathsf{zero\_rep})\). The \(t_i\) are closed and have no type variables.
- The type. The type definition (Definition Y-1) of \(\mathsf{nat}\), with no parameters, by the predicate \(\mathsf{least}[\mathsf{ind}]\,\mathsf{zero\_rep}\,\mathsf{suc\_rep}\) and the witness \(\vdash \exists x.\; \mathsf{least}\,\mathsf{zero\_rep}\,\mathsf{suc\_rep}\,x\), declares \(\mathsf{abs}{:}\mathsf{ind} \to \mathsf{nat}\), \(\mathsf{rep}{:}\mathsf{nat} \to \mathsf{ind}\) and the theorems (AR) \(\forall a.\; \mathsf{abs}(\mathsf{rep}\,a) = a\) and (RA) \(\forall r.\; \mathsf{least}\,\mathsf{zero\_rep}\,\mathsf{suc\_rep}\,r = (\mathsf{rep}(\mathsf{abs}\,r) = r)\).
- Zero and successor. The opaque definitions \(\mathsf{zero} := \mathsf{abs}\,\mathsf{zero\_rep}\) and \(\mathsf{suc} := \lambda n.\; \mathsf{abs}(\mathsf{suc\_rep}(\mathsf{rep}\,n))\).
The specification follows isabelle_names' specification of
Nat.Suc_Rep and Nat.Zero_Rep (the Store's Isabelle bridge),
with its own names.
Well-formedness. (1) The witness is derivable: from (I3), \(\exists s.\, \exists z.\, \Phi(s, z)\). By ∃E fix \(s_0\) with \(\exists z.\, \Phi(s_0, z)\); choice at \(\lambda s.\, \exists z.\, \Phi(s, z)\) and \(s_0\) gives \(\exists z.\, \Phi(t_s, z)\) (β is canonical). By ∃E fix \(z_0\) with \(\Phi(t_s, z_0)\); choice at \(\lambda z.\, \Phi(t_s, z)\) and \(z_0\) gives \(\Phi(t_s, t_z)\). Neither eliminated variable occurs in the conclusion. Now fix \(v_1, v_2\) and assume \(v_1 = t_s\) and \(v_2 = t_z\); rewriting \(\Phi(t_s, t_z)\) with the symmetric equations (Subst, twice) gives \(\Phi(v_1, v_2)\). Discharge and generalize. The free variables of \(\Phi(v_1, v_2)\) are \(v_1, v_2\), and the \(t_i\) are closed with no type variables, so Definition Y-2's conditions hold. (2) The predicate is closed, of type \(\mathsf{ind} \to \mathsf{Prop}\), with no type variables, matching the empty parameter list; the witness follows from Theorem NR-1(1) by ∃I. Its statement is exactly \(\exists x.\; P\,x\) for the predicate \(P\): the application of the partial spine \(\mathsf{least}\,\mathsf{zero\_rep}\,\mathsf{suc\_rep}\) to \(x\) is the spine \(\mathsf{least}(\mathsf{zero\_rep}, \mathsf{suc\_rep}, x)\), and canonical construction does not unfold the transparent \(\mathsf{least}\). (3) Both bodies are closed, monomorphic, and mention only earlier symbols. By Theorems Y-2, Y-1, and M-5 every model of \(T_0\) expands to a model of the extended theory.
Theorem NR-3 (Peano). With \(L\,r := \mathsf{least}\,\mathsf{zero\_rep}\,\mathsf{suc\_rep}\,r\):
- \(\vdash \forall n.\; L(\mathsf{rep}\,n)\), \(\vdash \mathsf{rep}\,\mathsf{zero} = \mathsf{zero\_rep}\), and \(\vdash \forall n.\; \mathsf{rep}(\mathsf{suc}\,n) = \mathsf{suc\_rep}(\mathsf{rep}\,n)\);
- \(\vdash \forall m\, n.\; \mathsf{suc}\,m = \mathsf{suc}\,n \to m = n\);
- \(\vdash \forall n.\; \neg\, \mathsf{suc}\,n = \mathsf{zero}\);
- \(\vdash \forall n.\; \mathsf{least}[\mathsf{nat}]\,\mathsf{zero}\,\mathsf{suc}\,n\);
- (induction) \(\vdash \forall P.\; P\,\mathsf{zero} \to (\forall n.\, P\,n \to P(\mathsf{suc}\,n)) \to \forall n.\; P\,n\);
- (cases) \(\vdash \forall n.\; n = \mathsf{zero} \lor \exists k.\; n = \mathsf{suc}\,k\).
Proof. A preliminary: if \(L\,r\), then \(\mathsf{rep}(\mathsf{abs}\,r) = r\). (RA) at \(r\) is \(L\,r = (\mathsf{rep}(\mathsf{abs}\,r) = r)\); (Subst) with the motive \(\lambda X.\, X\) turns a proof of \(L\,r\) into one of the right side.
(1) (RA) at \(\mathsf{rep}\,n\): \(L(\mathsf{rep}\,n) = (\mathsf{rep}(\mathsf{abs}(\mathsf{rep}\,n)) = \mathsf{rep}\,n)\). The right side holds: (AR) gives \(\mathsf{abs}(\mathsf{rep}\,n) = n\), and congruence with \(\mathsf{rep}\) gives \(\mathsf{rep}(\mathsf{abs}(\mathsf{rep}\,n)) = \mathsf{rep}\,n\). (Sym) and (Subst) with \(\lambda X.\, X\) give \(L(\mathsf{rep}\,n)\). Next, by the equation of \(\mathsf{zero}\), \(\mathsf{rep}\,\mathsf{zero} = \mathsf{rep}(\mathsf{abs}\,\mathsf{zero\_rep})\), which is \(\mathsf{zero\_rep}\) by the preliminary and Theorem NR-1(1). Finally, by the equation of \(\mathsf{suc}\) and β, \(\mathsf{rep}(\mathsf{suc}\,n) = \mathsf{rep}(\mathsf{abs}(\mathsf{suc\_rep}(\mathsf{rep}\,n)))\); \(L(\mathsf{suc\_rep}(\mathsf{rep}\,n))\) by Theorem NR-1(2) and the first part, so the preliminary gives \(\mathsf{suc\_rep}(\mathsf{rep}\,n)\).
(2) From \(\mathsf{suc}\,m = \mathsf{suc}\,n\), congruence with \(\mathsf{rep}\) and (1) give \(\mathsf{suc\_rep}(\mathsf{rep}\,m) = \mathsf{suc\_rep}(\mathsf{rep}\,n)\); the left conjunct of \(\Phi(\mathsf{suc\_rep}, \mathsf{zero\_rep})\) gives \(\mathsf{rep}\,m = \mathsf{rep}\,n\); congruence with \(\mathsf{abs}\) and (AR) give \(m = n\).
(3) From \(\mathsf{suc}\,n = \mathsf{zero}\), congruence with \(\mathsf{rep}\) and (1) give \(\mathsf{suc\_rep}(\mathsf{rep}\,n) = \mathsf{zero\_rep}\), which the right conjunct of \(\Phi\) refutes at \(\mathsf{rep}\,n\). Discharge: \(\neg\) is \(\lambda P.\, P \to \mathsf{False}\), and (Conv) unfolds it.
(4) Unfolded, the goal is: for every \(P\) with \(P\,\mathsf{zero}\) and \(h: \forall y.\, P\,y \to P(\mathsf{suc}\,y)\), \(P\,n\). Prove \(\forall r.\; L\,r \to P(\mathsf{abs}\,r)\) by Theorem NR-1(4) on \(\mathsf{ind}\). Base: \(P\,\mathsf{zero}\) and the equation \(\mathsf{zero} = \mathsf{abs}\,\mathsf{zero\_rep}\) give \(P(\mathsf{abs}\,\mathsf{zero\_rep})\). Step: let \(L\,r\) and \(P(\mathsf{abs}\,r)\). By \(h\), \(P(\mathsf{suc}(\mathsf{abs}\,r))\). By the equation of \(\mathsf{suc}\) and β, \(\mathsf{suc}(\mathsf{abs}\,r) = \mathsf{abs}(\mathsf{suc\_rep}(\mathsf{rep}(\mathsf{abs}\,r)))\), and \(\mathsf{rep}(\mathsf{abs}\,r) = r\) by the preliminary, so \(\mathsf{suc}(\mathsf{abs}\,r) = \mathsf{abs}(\mathsf{suc\_rep}\,r)\) and (Subst) gives \(P(\mathsf{abs}(\mathsf{suc\_rep}\,r))\). Now apply the result at \(r := \mathsf{rep}\,n\), with \(L(\mathsf{rep}\,n)\) by (1): \(P(\mathsf{abs}(\mathsf{rep}\,n))\), which is \(P\,n\) by (AR) and (Subst). Discharge, generalize \(P\), and convert to \(\mathsf{least}\).
(5) Theorem NR-1(3) at \(\mathsf{nat}\), \(\mathsf{zero}\), \(\mathsf{suc}\), applied to (4).
(6) (5) with \(P\,n := n = \mathsf{zero} \lor \exists k.\, n = \mathsf{suc}\,k\): the base by the left disjunct and (Refl), the step by the right disjunct with witness \(n\) and (Refl). \(\square\)
\(\mathsf{Inj}(\mathsf{zero}, \mathsf{suc})\) and \(\mathsf{Fresh}(\mathsf{zero}, \mathsf{suc})\) follow from (2) and (3), which hold even without the \(\mathsf{least}\) premises.
Definition NR-5 (recursion on \(\mathsf{nat}\)). The opaque definition
of type \(\alpha \to (\mathsf{nat} \to \alpha \to \alpha) \to \mathsf{nat} \to \alpha\). Its body's only type variable is \(\alpha\).
Theorem NR-4 (primitive recursion). For all \(a{:}\alpha\) and \(f{:}\mathsf{nat} \to \alpha \to \alpha\):
- \(\vdash \mathsf{rec}\,a\,f\,\mathsf{zero} = a\);
- \(\vdash \forall n.\; \mathsf{rec}\,a\,f\,(\mathsf{suc}\,n) = f\,n\,(\mathsf{rec}\,a\,f\,n)\);
- (uniqueness) \(\vdash \forall h.\; h\,\mathsf{zero} = a \to (\forall n.\, h(\mathsf{suc}\,n) = f\,n\,(h\,n)) \to h = \mathsf{rec}\,a\,f\).
Proof. By the equation of \(\mathsf{rec}\), congruence, and β, \(\mathsf{rec}\,a\,f\,x = \mathsf{recursor}\,\mathsf{zero}\,\mathsf{suc}\,a\,f\,x\). \(\mathsf{Inj}(\mathsf{zero}, \mathsf{suc})\) and \(\mathsf{Fresh}(\mathsf{zero}, \mathsf{suc})\) hold by Theorem NR-3(2), (3), so Theorem NR-2(2) and (3) apply, and the premise \(\mathsf{least}\,\mathsf{zero}\,\mathsf{suc}\,n\) of (3) is Theorem NR-3(4). Rewriting with the first equation gives (1) and (2). For (3), Theorem NR-2(4) and Theorem NR-3(4) give \(\forall n.\; h\,n = \mathsf{rec}\,a\,f\,n\), and function extensionality (I2) gives \(h = \mathsf{rec}\,a\,f\). \(\square\)
Categoricity¶
Theorem NR-5 (categoricity). Let \(z{:}\tau\) and \(s{:}\tau \to \tau\), and let \(\varphi := \mathsf{rec}[\tau]\,z\,(\lambda n\, y.\, s\,y)\). Then:
- \(\vdash \varphi\,\mathsf{zero} = z\) and \(\vdash \forall n.\; \varphi(\mathsf{suc}\,n) = s(\varphi\,n)\);
- \(\vdash \forall n.\; \mathsf{least}\,z\,s\,(\varphi\,n)\);
- (onto) \(\vdash \forall x.\; \mathsf{least}\,z\,s\,x \to \exists n.\; \varphi\,n = x\);
- (into) if \(\mathsf{Inj}(z, s)\) and \(\mathsf{Fresh}(z, s)\), then \(\vdash \forall m\, n.\; \varphi\,m = \varphi\,n \to m = n\);
- (unique) \(\vdash \forall \psi.\; \psi\,\mathsf{zero} = z \to (\forall n.\, \psi(\mathsf{suc}\,n) = s(\psi\,n)) \to \psi = \varphi\);
- (inverse) under the hypotheses of (4), with \(\iota := \lambda x.\; \varepsilon\,(\lambda n.\, \varphi\,n = x)\): \(\vdash \forall n.\; \iota(\varphi\,n) = n\) and \(\vdash \forall x.\; \mathsf{least}\,z\,s\,x \to \varphi(\iota\,x) = x\).
So \(\varphi\) is a bijection from \(\mathsf{nat}\) onto \(\mathsf{least}\,z\,s\) that commutes with zero and successor, and the only such map.
Proof. (1) Theorem NR-4(1), (2), with β for \((\lambda n\, y.\, s\,y)\,n\,(\varphi\,n)\).
(2) Induction (Theorem NR-3(5)): \(\varphi\,\mathsf{zero} = z\) and \(\mathsf{least}\,z\,s\,z\); if \(\mathsf{least}\,z\,s\,(\varphi\,n)\), then \(\mathsf{least}\,z\,s\,(s(\varphi\,n))\) by Theorem NR-1(2), which is \(\mathsf{least}\,z\,s\,(\varphi(\mathsf{suc}\,n))\) by (1) and (Subst).
(3) Theorem NR-1(3) with \(P\,x := \exists n.\, \varphi\,n = x\): the base with witness \(\mathsf{zero}\); the step, from \(\varphi\,n = x\), with witness \(\mathsf{suc}\,n\), since \(\varphi(\mathsf{suc}\,n) = s(\varphi\,n) = s\,x\).
(4) Induction on \(m\) with \(P\,m := \forall n.\; \varphi\,m = \varphi\,n \to m = n\), and in each case cases (Theorem NR-3(6)) on \(n\). Let \(\varphi\,m = \varphi\,n\).
- \(m = \mathsf{zero}\), \(n = \mathsf{zero}\): (Refl).
- \(m = \mathsf{zero}\), \(n = \mathsf{suc}\,k\): \(z = s(\varphi\,k)\) by (1), and \(\mathsf{least}\,z\,s\,(\varphi\,k)\) by (2), so \(\mathsf{Fresh}\) refutes it; (⊥E).
- \(m = \mathsf{suc}\,m'\), \(n = \mathsf{zero}\): symmetric.
- \(m = \mathsf{suc}\,m'\), \(n = \mathsf{suc}\,k\): \(s(\varphi\,m') = s(\varphi\,k)\) by (1); both arguments satisfy \(\mathsf{least}\,z\,s\) by (2), so \(\varphi\,m' = \varphi\,k\) by \(\mathsf{Inj}\); the induction hypothesis \(P\,m'\) gives \(m' = k\), and congruence gives \(\mathsf{suc}\,m' = \mathsf{suc}\,k\).
The variable \(n\) is generalized inside \(P\), so the hypothesis applies at \(k\).
(5) Theorem NR-4(3) with \(a := z\) and \(f := \lambda n\, y.\, s\,y\), by β.
(6) For \(x\) with \(\mathsf{least}\,z\,s\,x\), (3) gives \(n\) with \(\varphi\,n = x\), so choice gives \(\varphi(\iota\,x) = x\) (β for \(\iota\)). For any \(n\), \(\mathsf{least}\,z\,s\,(\varphi\,n)\) by (2), so \(\varphi(\iota(\varphi\,n)) = \varphi\,n\), and (4) gives \(\iota(\varphi\,n) = n\). \(\square\)
Corollary NR-5a (isomorphic structures). If moreover \(\vdash \forall x.\; \mathsf{least}\,z\,s\,x\), as for a type with its own induction principle, then \(\varphi\) and \(\iota\) are inverse bijections between \(\mathsf{nat}\) and \(\tau\): \(\vdash \iota \circ \varphi = \lambda n.\, n\), \(\vdash \varphi \circ \iota = \lambda x.\, x\), and \(\vdash \iota\,z = \mathsf{zero}\) and \(\vdash \forall x.\; \iota(s\,x) = \mathsf{suc}(\iota\,x)\).
Proof. The two compositions follow from Theorem NR-5(6) by (I2). Then \(\iota\,z = \iota(\varphi\,\mathsf{zero}) = \mathsf{zero}\), and \(\iota(s\,x) = \iota(s(\varphi(\iota\,x))) = \iota(\varphi(\mathsf{suc}(\iota\,x))) = \mathsf{suc}(\iota\,x)\), by Theorem NR-5(1) and (6). \(\square\)
Corollary NR-5a is the bridge to Isabelle's Nat.nat, with \(z\) its zero
and \(s\) its Suc. The facts it needs at $\tau = $ Nat.nat
(injectivity of Suc, Suc n ≠ 0, and induction, from which
\(\forall x.\, \mathsf{least}\,z\,s\,x\) follows) are imported Isabelle
statements, so every result transferred through the bridge depends on
them and carries them in its label until they are replayed. Theorem
NR-5(4) and (6), with \(\mathsf{Inj}\) and \(\mathsf{Fresh}\) from the order
laws, are the bridge to scalar's \(\mathbb N_0\).
Primitive recursive definitions¶
Definition NR-6 (primitive recursive definition). Let \(a{:}\beta\) and \(f{:}\mathsf{nat} \to \beta \to \beta\) be closed terms whose type variables occur in \(\beta\). The primitive recursive definition of a new constant \(c{:}\mathsf{nat} \to \beta\) declares
- the opaque definition \(c := \mathsf{rec}[\beta]\,a\,f\);
- the theorems \(\vdash c\,\mathsf{zero} = a\) and \(\vdash \forall n.\; c\,(\mathsf{suc}\,n) = f\,n\,(c\,n)\), with \(f\,n\,(c\,n)\) in canonical form (β-reduced).
Parameters are passed by λ-abstraction into \(\beta\): a function \(c\,n\,\bar p\) of further arguments \(\bar p{:}\bar\pi\) recursive in its first argument has \(\beta = \bar\pi \to \beta'\), and its equations are equations between functions. Its pointwise equations follow by congruence and β.
Theorem NR-6 (primitive recursive definitions are conservative).
- The declarations of Definition NR-6 preserve models, and the two theorems are derivable in the theory with the definition.
- If \(h{:}\mathsf{nat} \to \beta\) satisfies the two equations, then \(\vdash h = c\).
- The type-variable condition is necessary, and the body cannot mention \(c\).
Proof. (1) The body \(\mathsf{rec}[\beta]\,a\,f\) is closed, of type \(\mathsf{nat} \to \beta\), its type variables are those of \(\beta\), \(a\), and \(f\), which occur in \(\beta\), and it does not mention \(c\), which is declared by this definition. So Theorem M-5 applies. The equation of \(c\) (Use), congruence, and Theorem NR-4(1), (2) give the theorems, rewritten with the equation of \(c\) (Sym, Subst).
(2) Theorem NR-4(3) and (Trans) with the equation of \(c\).
(3) The condition is Definition T-1's. Without it, the counterexample after Theorem M-5 applies verbatim: with \(\beta = \mathsf{Prop}\) and \(a := \exists x\, y{:}\alpha.\, x \neq y\), the constant \(c\) would be a scheme over \(\alpha\) although its type does not mention \(\alpha\), and instantiating \(c\,\mathsf{zero} = a\) at \(\mathsf{Prop}\) and at a one-element type proves \(\mathsf{True} = \mathsf{False}\). A body that mentions \(c\) is impossible: \(c\) is not declared in the theory in which \(a\) and \(f\) are checked, and the kernel refuses a definition that mentions itself (K1.3). \(\square\)
Recursion that is not primitive, such as well-founded recursion, is not defined here; it would also be definitional, built on \(\mathsf{rec}\) and the order of Definition NR-7.
Arithmetic¶
Definition NR-7 (arithmetic). Primitive recursive definitions (Definition NR-6), recursive in the first argument:
| Constant | \(\beta\) | \(a\) | \(f\) | Pointwise equations |
|---|---|---|---|---|
| \(\mathsf{pred}\) | \(\mathsf{nat}\) | \(\mathsf{zero}\) | \(\lambda n\, r.\, n\) | \(\mathsf{pred}\,\mathsf{zero} = \mathsf{zero}\), \(\mathsf{pred}(\mathsf{suc}\,n) = n\) |
| \(\mathsf{add}\) | \(\mathsf{nat} \to \mathsf{nat}\) | \(\lambda m.\, m\) | \(\lambda n\, r\, m.\, \mathsf{suc}(r\,m)\) | \(\mathsf{add}\,\mathsf{zero}\,m = m\), \(\mathsf{add}(\mathsf{suc}\,n)\,m = \mathsf{suc}(\mathsf{add}\,n\,m)\) |
| \(\mathsf{mult}\) | \(\mathsf{nat} \to \mathsf{nat}\) | \(\lambda m.\, \mathsf{zero}\) | \(\lambda n\, r\, m.\, \mathsf{add}\,(r\,m)\,m\) | \(\mathsf{mult}\,\mathsf{zero}\,m = \mathsf{zero}\), \(\mathsf{mult}(\mathsf{suc}\,n)\,m = \mathsf{add}(\mathsf{mult}\,n\,m)\,m\) |
The equations that Definition NR-6 declares are those between functions: \(\mathsf{add}\,\mathsf{zero} = \lambda m.\, m\) and \(\forall n.\; \mathsf{add}(\mathsf{suc}\,n) = \lambda m.\, \mathsf{suc}(\mathsf{add}\,n\,m)\), and likewise for \(\mathsf{mult}\). The pointwise equations in the table follow by congruence (App) and β, and are declared as laws (the implementation page lists them). Further, the definitions
\(\mathsf{sub}\) recurses in its second argument through \(\mathsf{rec}\) directly, so it is an ordinary definition whose equations \(\mathsf{sub}\,m\,\mathsf{zero} = m\) and \(\mathsf{sub}\,m\,(\mathsf{suc}\,n) = \mathsf{pred}(\mathsf{sub}\,m\,n)\) follow from Theorem NR-4 as in Theorem NR-6. All are monomorphic.
Theorem NR-7 (arithmetic laws). For all \(k, m, n{:}\mathsf{nat}\):
- \(\mathsf{add}\,n\,\mathsf{zero} = n\); \(\mathsf{add}\,n\,(\mathsf{suc}\,m) = \mathsf{suc}(\mathsf{add}\,n\,m)\); \(\mathsf{add}\,m\,n = \mathsf{add}\,n\,m\); \(\mathsf{add}(\mathsf{add}\,k\,m)\,n = \mathsf{add}\,k\,(\mathsf{add}\,m\,n)\); \(\mathsf{add}\,k\,m = \mathsf{add}\,k\,n \to m = n\); \(\mathsf{add}\,m\,n = \mathsf{zero} \to m = \mathsf{zero}\).
- \(\mathsf{mult}\,n\,\mathsf{zero} = \mathsf{zero}\); \(\mathsf{mult}\,n\,(\mathsf{suc}\,m) = \mathsf{add}(\mathsf{mult}\,n\,m)\,n\); \(\mathsf{mult}\,m\,n = \mathsf{mult}\,n\,m\); \(\mathsf{mult}\,k\,(\mathsf{add}\,m\,n) = \mathsf{add}(\mathsf{mult}\,k\,m)(\mathsf{mult}\,k\,n)\); \(\mathsf{mult}(\mathsf{mult}\,k\,m)\,n = \mathsf{mult}\,k\,(\mathsf{mult}\,m\,n)\).
- \(\mathsf{sub}\,(\mathsf{add}\,m\,n)\,n = m\); \(\mathsf{sub}\,n\,n = \mathsf{zero}\); \(\mathsf{sub}\,\mathsf{zero}\,n = \mathsf{zero}\).
- \(\mathsf{le}\,n\,n\); \(\mathsf{le}\,k\,m \to \mathsf{le}\,m\,n \to \mathsf{le}\,k\,n\); \(\mathsf{le}\,m\,n \to \mathsf{le}\,n\,m \to m = n\); \(\mathsf{le}\,m\,n \lor \mathsf{le}\,n\,m\); \(\mathsf{le}\,\mathsf{zero}\,n\); \(\neg\,\mathsf{lt}\,n\,\mathsf{zero}\); \(\mathsf{lt}\,n\,(\mathsf{suc}\,n)\); \(\neg\,\mathsf{lt}\,n\,n\); \(\mathsf{lt}\,m\,n \leftrightarrow \mathsf{le}\,m\,n \land \neg\, m = n\).
Proof. Each law is closed over its variables by (∀I) and proved by induction (Theorem NR-3(5)) on the variable named, using the defining equations of Definition NR-7 and earlier laws. The decisive cases:
- (1) Right zero and right successor by induction on \(n\). Commutativity by induction on \(m\), with the right laws in the step. Associativity by induction on \(k\). Cancellation by induction on \(k\), with Theorem NR-3(2) in the step. \(\mathsf{add}\,m\,n = \mathsf{zero}\): cases on \(m\); for \(m = \mathsf{suc}\,m'\) the left side is \(\mathsf{suc}(\mathsf{add}\,m'\,n)\), which Theorem NR-3(3) refutes.
- (2) Right zero and right successor by induction on \(n\), the second with associativity and commutativity of \(\mathsf{add}\). Commutativity by induction on \(m\). Distributivity by induction on \(k\), with the laws of (1). Associativity by induction on \(k\), with distributivity in the form \(\mathsf{mult}(\mathsf{add}\,a\,b)\,n = \mathsf{add}(\mathsf{mult}\,a\,n)(\mathsf{mult}\,b\,n)\), obtained from distributivity by commutativity.
- (3) \(\mathsf{sub}\,(\mathsf{add}\,m\,n)\,n = m\) by induction on \(n\), generalizing \(m\): for \(\mathsf{suc}\,n\), \(\mathsf{sub}(\mathsf{add}\,m\,(\mathsf{suc}\,n))(\mathsf{suc}\,n) = \mathsf{pred}(\mathsf{sub}(\mathsf{suc}(\mathsf{add}\,m\,n))\,n)\), and \(\mathsf{suc}(\mathsf{add}\,m\,n) = \mathsf{add}(\mathsf{suc}\,m)\,n\), so the hypothesis at \(\mathsf{suc}\,m\) gives \(\mathsf{pred}(\mathsf{suc}\,m) = m\). Then \(\mathsf{sub}\,n\,n = \mathsf{zero}\) is the case \(m = \mathsf{zero}\), and \(\mathsf{sub}\,\mathsf{zero}\,n = \mathsf{zero}\) is by induction on \(n\) with \(\mathsf{pred}\,\mathsf{zero} = \mathsf{zero}\).
- (4) Reflexivity with \(k := \mathsf{zero}\) and right zero; transitivity with \(k_1 + k_2\) and associativity; antisymmetry: from \(n = \mathsf{add}\,m\,k_1\) and \(m = \mathsf{add}\,n\,k_2\), \(\mathsf{add}\,m\,\mathsf{zero} = \mathsf{add}\,m\,(\mathsf{add}\,k_1\,k_2)\), so by cancellation and the last law of (1), \(k_1 = \mathsf{zero}\) and \(n = m\). Totality by induction on \(m\), generalizing \(n\), with cases on \(n\) in the step. \(\mathsf{le}\,\mathsf{zero}\,n\) with \(k := n\). \(\neg\,\mathsf{lt}\,n\,\mathsf{zero}\): \(\mathsf{zero} = \mathsf{suc}(\mathsf{add}\,n\,k)\) contradicts Theorem NR-3(3). \(\mathsf{lt}\,n\,(\mathsf{suc}\,n)\) with \(k := \mathsf{zero}\). Irreflexivity: \(n = \mathsf{suc}(\mathsf{add}\,n\,k)\) gives, by cancellation after rewriting \(n = \mathsf{add}\,n\,\mathsf{zero}\) and \(\mathsf{suc}(\mathsf{add}\,n\,k) = \mathsf{add}\,n\,(\mathsf{suc}\,k)\), \(\mathsf{zero} = \mathsf{suc}\,k\). The last law: left to right, \(\mathsf{le}\,m\,n\) from \(\mathsf{le}\,m\,(\mathsf{suc}\,m)\) and transitivity, and \(m \neq n\) by irreflexivity; right to left, from \(n = \mathsf{add}\,m\,k\) and \(m \neq n\), \(k \neq \mathsf{zero}\), so \(k = \mathsf{suc}\,k'\) by cases and \(n = \mathsf{add}\,m\,(\mathsf{suc}\,k') = \mathsf{suc}(\mathsf{add}\,m\,k') = \mathsf{add}\,(\mathsf{suc}\,m)\,k'\) by the right successor law and the left successor equation. \(\square\)
None of these laws needs excluded middle; totality and the last law use induction and cases only.
What this page does not claim¶
- No new kernel rule, axiom, conversion step, or literal kind. Recursion is by equations proved once per definition and used by (Use); nothing reduces by ι in conversion, and numerals \(\mathsf{suc}^k\,\mathsf{zero}\) are computed by rewriting with the equations.
- \(\mathsf{nat}\) is not identified with Isabelle's
Nat.nator withscalar's \(\mathbb N_0\): Theorem NR-5 and Corollary NR-5a relate them by checked bijections. - Declarations are made in the order of the implementation page; that order is part of every stored identity that depends on them.