Second Principle of Mathematical Induction/Algorithm

Algorithm
The Second Principle of Mathematical Induction can be implemented as an algorithm as follows.

Let $P \left({n}\right)$ be a propositional function depending on $n \in \N$.

Let it be established that:
 * $\text{(a)}: \quad P \left({1}\right)$ is true
 * $\text{(b)}: \quad$ If all of $P \left({1}\right), P \left({2}\right), \ldots, P \left({k}\right)$ are true, then $P \left({k + 1}\right)$ is true.

Then the following algorithm provides a proof of $P \left({k}\right)$ for all $n \in \N$:


 * $\mathbf 1:$ Prove $P \left({1}\right)$.
 * Set $k \gets 1$ and prove $P \left({1}\right)$ according to $\text{(a)}$.


 * $\mathbf 2:$ Is $k = n$?.
 * If $k = n$ then terminate. The required proof has been output.


 * $\mathbf 3:$ Prove $P \left({k + 1}\right)$.
 * According to $\text{(b)}$, output a proof that if all of $P \left({1}\right), P \left({2}\right), \ldots, P \left({k}\right)$ are true, then $P \left({k + 1}\right)$ is true.


 * $\mathbf 4:$ Increase $k$.
 * $k \gets k + 1$ and to to step $\mathbf 2$.