Inductive definitions [00KK]
- January 23, 2024
- Jon Sterling, with contributions from Marcelo Fiore
We have already seen some inductive definitions:
- Definition [00JE] defines n-fold iterations of endo-relations by induction on n.
- Algorithm [00JV] computes the adjacency matrix of the path relation of a finite directed graph by induction on the number of vertices in the graph.
In this section, we will study this concept in more detail.
Example Informal examples of inductively defined functions [00KL]
- January 23, 2024
- Jon Sterling, with contributions from Marcelo Fiore
An inductive definition on the naturals defines a structure for each number n:\mathbb {N} by first defining it for n=0 and then specifying how to augment a structure for n=m to a structure for n=m+1. From the point of view of computer programming, inductive definitions proceed by structural recursion. For example, addition of natural numbers can be defined by induction on the second argument (or the first, if you prefer!):
\begin {aligned} \mathsf {add} &\colon \mathbb {N}^2\to \mathbb {N} \\ \mathsf {add}{\mathopen {}\left (m,0\right )\mathclose {}} &= m \\ \mathsf {add}{\mathopen {}\left (m,n+1\right )\mathclose {}} &= \mathsf {add}{\mathopen {}\left (m,n\right )\mathclose {}}+1 \end {aligned}Likewise, the function \Sigma \colon \mathbb {N}\to \mathbb {N} that takes n:\mathbb {N} to the sum \sum _{0\leq i < n}i can be defined inductively:
\begin {aligned} \Sigma &\colon \mathbb {N}\to \mathbb {N}\\ \Sigma {\mathopen {}\left (0\right )\mathclose {}} &= 0\\ \Sigma {\mathopen {}\left (n+1\right )\mathclose {}} &= \mathsf {add}{\mathopen {}\left (n,\Sigma {\mathopen {}\left (n\right )\mathclose {}}\right )\mathclose {}} \end {aligned}In order to make precise the description of Definition [00JE], Algorithm [00JV], and Example [00KL] as “inductive definitions”, we must give an actual formal definition of what an inductive definition is.
Definition Inductively defined function [00KM]
- January 23, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Let A be a set, and fix a:A and f\colon \mathbb {N}\times A\to A. The function inductively defined from a and f is defined to be the unique function \mathbf {\rho }_{a,f}\colon \mathbb {N}\to A satisfying the following equations:
\begin {aligned} \mathbf {\rho }_{a,f}{\mathopen {}\left (0\right )\mathclose {}} &= a\\ \mathbf {\rho }_{a,f}{\mathopen {}\left (n+1\right )\mathclose {}} &= f{\mathopen {}\left (n,\mathbf {\rho }_{a,f}{\mathopen {}\left (n\right )\mathclose {}}\right )\mathclose {}} \end {aligned}Note that our specification of inductively defined functions in Definition [00KM] asserts, without proof, that there does in fact exist a unique function \mathbf {\rho }_{a,f}\colon \mathbb {N}\to A satisfying the described equations. It is not blindingly obvious that this claim is true — and, after seeing a few examples to motivate Definition [00KM], we will explicitly justify Definition [00KM] by means of an existence theorem.
Example Formal examples of inductively defined functions [00KN]
- January 23, 2024
- Jon Sterling, with contributions from Marcelo Fiore
We have seen two informal examples of inductive definitions in Example [00KL]; we will now update these examples in light of Definition [00KM]:
- For every m: \mathbb {N}, function \mathsf {add}{\mathopen {}\left (m,-\right )\mathclose {}}\colon \mathbb {N}\to \mathbb {N} is the function \mathbf {\rho }_{m,{\mathopen {}\left (i,n\right )\mathclose {}}\mapsto n+1} inductively defined by m:\mathbb {N} and f{\mathopen {}\left (i,n\right )\mathclose {}} = n+1.
- The function \Sigma \colon \mathbb {N}\to \mathbb {N} taking n:\mathbb {N} to \sum _{0\leq i<n}i is the function \mathbf {\rho }_{0,\mathsf {add}} inductively defined by 0:\mathbb {N} and \mathsf {add}\colon \mathbb {N}\times \mathbb {N}\to \mathbb {N}.
Definition {\mathopen {}\left (a,f\right )\mathclose {}}-closed relation [00KO]
- January 23, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Given an element a:A and a function f\colon \mathbb {N}\times A \to A, we call a relation R\colon \mathbb {N}\mathbin {\nrightarrow } A {\mathopen {}\left (a,f\right )\mathclose {}}-closed whenever we have both 0\mathrel {R}a and n\mathrel {R}x\implies {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {R}f{\mathopen {}\left (n,x\right )\mathclose {}} for all n:\mathbb {N} and x:A.
In light of Definition [00KO], we see that Definition [00KM] is defining \mathbf {\rho }_{a,f} to be the unique {\mathopen {}\left (a,f\right )\mathclose {}}-closed function. We still have to show that this exists.
Theorem Existence of inductively defined functions [00KP]
- January 23, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Given an element a:A and a function f\colon \mathbb {N}\times A\to A, now let \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\nrightarrow } A be the intersection of all the {\mathopen {}\left (a,f\right )\mathclose {}}-closed relations R\colon \mathbb {N}\mathbin {\nrightarrow } A.
- The relation \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\nrightarrow } A is functional and total, and therefore a function.
- The function \mathbf {\rho }_{a,f}\colon \mathbb {N}\to A is the unique {\mathopen {}\left (a,f\right )\mathclose {}}-closed function, i.e. it is the unique function satisfying both \mathbf {\rho }_{a,f}{\mathopen {}\left (0\right )\mathclose {}}=a and \forall n:\mathbb {N}\mathpunct {.} \mathbf {\rho }_{a,f}{\mathopen {}\left (n+1\right )\mathclose {}}=f{\mathopen {}\left (n,\mathbf {\rho }_{a,f}{n}\right )\mathclose {}}.
Proof.
- January 23, 2024
- Jon Sterling
We first notice that \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\nrightarrow } A is itself {\mathopen {}\left (a,f\right )\mathclose {}}-closed, which can be seen by observing that the intersection of a set of {\mathopen {}\left (a,f\right )\mathclose {}}-closed relations is {\mathopen {}\left (a,f\right )\mathclose {}}-closed. With this in hand, we proceed.
We must show that \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\nrightarrow } A is a function.
-
To show that \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\nrightarrow } A is functional, we must show that for all n:\mathbb {N} and x,y:A, if n\mathrel {\mathbf {\rho }_{a,f}} x and n\mathrel {\mathbf {\rho }_{a,f}}y, then x=y. We proceed to prove P{\mathopen {}\left (n\right )\mathclose {}} = \forall x,y:A\mathpunct {.} n\mathrel {\mathbf {\rho }_{a,f}} x \land n\mathrel {\mathbf {\rho }_{a,f}}y\implies x=y by induction on n:\mathbb {N}.
For the base case, we fix x,y:A such that 0\mathrel {\mathbf {\rho }_{a,f}}x and 0\mathrel {\mathbf {\rho }_{a,f}} y to check that x=y. By definition, we know that for any {\mathopen {}\left (a,f\right )\mathclose {}}-closed relation R\colon \mathbb {N}\mathbin {\nrightarrow } A we both 0\mathrel {R}x and 0\mathrel {R}y.
We choose R be the union of {\mathopen {}\left \{{\mathopen {}\left (0,a\right )\mathclose {}}\right \}\mathclose {}} and {\mathopen {}\left \{{\mathopen {}\left (n,x\right )\mathclose {}}\,\middle \vert \,n > 0 \land x:A\right \}\mathclose {}}, which is {\mathopen {}\left (a,f\right )\mathclose {}}-closed; we have used the fact that \mathbf {\rho }_{a,f} is {\mathopen {}\left (a,f\right )\mathclose {}}-closed. As this union is disjoint, we can see that 0\mathrel {R}z if and only if z=a, so we have x=a=y.
In the inductive step, we assume P{\mathopen {}\left (n\right )\mathclose {}} to prove P{\mathopen {}\left (n+1\right )\mathclose {}}. Fixing x,y:A such that {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {\mathbf {\rho }_{a,f}}x and {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {\mathbf {\rho }_{a,f}}y, we must show that x=y.
We know that for any {\mathopen {}\left (a,f\right )\mathclose {}}-closed relation R\colon \mathbb {N}\mathbin {\nrightarrow } A we have both {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {R}x and {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {R}y.
We choose R to be the union of {\mathopen {}\left \{{\mathopen {}\left (m+1,f{\mathopen {}\left (m,z\right )\mathclose {}}\right )\mathclose {}}\,\middle \vert \,m=n\land m\mathrel {\mathbf {\rho }_{a,f}}{z}\right \}\mathclose {}} with {\mathopen {}\left \{{\mathopen {}\left (m,z\right )\mathclose {}}\,\middle \vert \,m\mathrel {\mathbf {\rho }_{a,f}}z\land m\not =n+1\right \}\mathclose {}}, noting that R is {\mathopen {}\left (a,f\right )\mathclose {}}-closed because \mathbf {\rho }_{a,f} is {\mathopen {}\left (a,f\right )\mathclose {}}-closed. As the union defining R is disjoint, for any z:A we know that {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {R}z if and only if z=f{\mathopen {}\left (n,z'\right )\mathclose {}} for some z' with n\mathrel {\mathbf {\rho }_{a,f}} z'.
Therefore, we have some x',y':A such that x=f{\mathopen {}\left (n,x'\right )\mathclose {}} and y=f{\mathopen {}\left (n,y'\right )\mathclose {}} and n\mathrel {\mathbf {\rho }_{a,f}} x' and n\mathrel {\mathbf {\rho }_{a,f}}y'. By our inductive hypothesis, we know that x'=y', and hence x=y.
To show that \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\rightharpoonup } A is total, we must show that for every n:\mathbb {N}, we have \mathbf {\rho }_{a,f}{\mathopen {}\left (n\right )\mathclose {}}{\downarrow }. This is proved by induction on n:\mathbb {N}:
- In the base case, we deduce \mathbf {\rho }_{a,f}{\mathopen {}\left (0\right )\mathclose {}}{\downarrow } from our asumption that 0\mathrel {\mathbf {\rho }_{a,f}}a.
- In the inductive step, we assume that \mathbf {\rho }_{a,f}{\mathopen {}\left (n\right )\mathclose {}}{\downarrow } and must show that \mathbf {\rho }_{a,f}{\mathopen {}\left (n+1\right )\mathclose {}}{\downarrow }. By our assumption, we have n\mathrel {\mathbf {\rho }_{a,f}}\mathbf {\rho }_{a,f}{{\mathopen {}\left (n\right )\mathclose {}}}; because \mathbf {\rho }_{a,f} is {\mathopen {}\left (a,f\right )\mathclose {}}-closed relation, we may conclude {\mathopen {}\left (n+1\right )\mathclose {}}\mathrel {\mathbf {\rho }_{a,f}}f{\mathopen {}\left (n,\mathbf {\rho }_{a,f}\right )\mathclose {}}.
-
To show that \mathbf {\rho }_{a,f}\colon \mathbb {N}\mathbin {\nrightarrow } A is functional, we must show that for all n:\mathbb {N} and x,y:A, if n\mathrel {\mathbf {\rho }_{a,f}} x and n\mathrel {\mathbf {\rho }_{a,f}}y, then x=y. We proceed to prove P{\mathopen {}\left (n\right )\mathclose {}} = \forall x,y:A\mathpunct {.} n\mathrel {\mathbf {\rho }_{a,f}} x \land n\mathrel {\mathbf {\rho }_{a,f}}y\implies x=y by induction on n:\mathbb {N}.
- It remains to show that the function \mathbf {\rho }_{a,f}\colon \mathbb {N}\to A is the unique {\mathopen {}\left (a,f\right )\mathclose {}}-closed function. This too can be proved by induction, as functionality and {\mathopen {}\left (a,f\right )\mathclose {}}-closure fully specify the values of \mathbf {\rho }_{a,f} on all inputs.