Example of Proof by Double Induction
Ackermann's Function is total on ℕ×ℕ

A very well known function is Ackermann's, A: ℕ×ℕ ⟶ ℕ, which can be defined like this:

A(0,n)=n+1
A(m,0)=A(m−1, 1) (m>0)
A(m,n)=A(m−1, A(m,n−1)) (m,n>0)

Here we prove that A(m,n) is well-defined for all pairs of natural numbers (m,n). For notational convenience, we use ↓ as a unary postfix operator denoting "is well-defined". That is, A(m,n)↓ means "A(m,n) is well-defined" or "A is well-defined at (m,n)".

It turns out that to prove this claim it is useful to use mathematical induction on both arguments of the function. Sometimes this is called "double induction". Our claim is

(∀m,n | m≥0 ∧ n≥0 : A(m,n)↓ )
which by Gries's (8.20) (nesting) is equivalent to

(∀m | m≥0 : (∀n | n≥0 : A(m,n)↓ ))

Let P be the body of this universal quantification; that is:

P: (∀n | n≥0 : A(m,n)↓)

Following Gries's instructions, to prove our claim by induction on m we must prove:

  1. P[m := 0] (the basis step) and
  2. P ⇒ P[m := m+1] (the inductive step).

Here we go:

Basis step:
   P[m := 0]

=    < defn of P >

   (∀n | n≥0 : A(m,n)↓)[m:=0]

=    < textual substitution >

   (∀n | n≥0 : A(0,n)↓)

=    < defn of A >

   (∀n | n≥0 : (n+1)↓)

=    < obvious >

   true

Inductive step: Let m≥0 and assume P as the induction hypothesis (IH). What is to be proved is P[m := m+1]
   P[m := m+1]

=    < defn of P >

   (∀n | n≥0 : A(m,n)↓)[m:=m+1]

=    < textual substitution >

   (∀n | n≥0 : A(m+1,n)↓)
At this point, it would seem that a proof by induction (on n) is called for. Letting Q be the body of this quantification (which is itself P[m:=m+1]), what we do is to prove
  1. Q[n:=0] (the basis step) and
  2. Q ⇒ Q[n:=n+1] (the inductive step).
Basis step (wrt n):
   Q[n:=0]

=    < defn of Q >

   (A(m+1,n)↓)[n:=0]

=    < text. sub. >

   A(m+1,0)↓

=    < defn of A >

   A(m,1)↓

⇐  (9.13'): (∀x | R : P) ∧ R[x:=E] ⇒ P[x:=E] >

   (∀n | n≥0 : A(m,n)↓) ∧ 1≥0

=    < defn of P; arithmetic; (3.39)

   P

=    < assumption (IH) >

   true
If we were being a little less formal, we would have combined the last two steps, which rely on applying (9.13') and IH P. (It's rather obvious that P implies A(m,1)↓.)

Induction step (wrt n): The IH (wrt n) is Q: A(m+1,n)↓. To be proved is Q[n:=n+1]. Note that we are still within the scope of the assumption of "outer" IH (wrt m), which is P: (∀n | n≥0 : A(m,n)↓)
   Q[n:=n+1]

=    < defn of Q >

   (A(m+1,n)↓)[n:=n+1]

=    < text. sub. >

   A(m+1,n+1)↓

=    < defn of A >

   A(m, A(m+1,n))↓

=    < by IH Q, A(m+1,n)↓; let r = A(m+1,n) >

   A(m,r)↓

⇐  < (9.13') and IH P >

   true
Note that this time we combined the steps relying upon the applications of (9.13') and IH P.