The ZF set theory constructs natural numbers from the empty set and the notion of a one-element set. Namely, zero of natural numbers is defined as the empty set. For each natural number \(n\) the next natural number is defined as \(n\cup \{n\}\). With this definition for every non-zero natural number we get the identity \(n = \{0,1,2,..,n-1\}\). It is good to remember that when we see an expression like \(f: n \rightarrow X\). Also, with this definition the relation "less or equal than" becomes "\(\subseteq\)" and the relation "less than" becomes "\(\in\)".
The induction lemmas in the standard Isabelle's Nat.thy file like for example nat_induct require the induction step to be a higher order statement (the one that uses the \(\Longrightarrow\) sign). I found it difficult to apply from Isar, which is perhaps more of an indication of my Isar skills than anything else. Anyway, here we provide a first order version that is easier to reference in Isar declarative style proofs.
The next theorem is a version of induction on natural numbers that I was thought in school.
theorem ind_on_nat:
assumes A1: \( n\in nat \) and A2: \( P(0) \) and A3: \( \forall k\in nat.\ P(k)\longrightarrow P(succ(k)) \)
shows \( P(n) \)proofA nonzero natural number has a predecessor.
lemma Nat_ZF_1_L3:
assumes A1: \( n \in nat \) and A2: \( n\neq 0 \)
shows \( \exists k\in nat.\ n = succ(k) \)proofWhat is succ, anyway? It's a union with the singleton of the set.
lemma succ_explained:
shows \( succ(n) = n \cup \{n\} \) using succ_iffThe singleton containing the empty set is a natural number.
lemma one_is_nat:
shows \( \{0\} \in nat \), \( \{0\} = succ(0) \), \( \{0\} = 1 \)proofIf \(k\) is a member of \(succ(n)\) but is not \(n\), then it must be the member of \(n\).
lemma mem_succ_not_eq:
assumes \( k\in succ(n) \), \( k\neq n \)
shows \( k\in n \) using assms, succ_explainedEmpty set is an element of every natural number which is not zero.
lemma empty_in_every_succ:
assumes A1: \( n \in nat \)
shows \( 0 \in succ(n) \)proofVarious forms of saying that for natural numbers taking the successor is the same as adding one.
lemma succ_add_one:
assumes \( n\in nat \)
shows \( n + 1 = succ(n) \), \( n + 1 \in nat \), \( \{0\} + n = succ(n) \), \( n + \{0\} = succ(n) \), \( succ(n) \in nat \), \( 0 \in n + 1 \), \( n \subseteq n + 1 \)proofA more direct way of stating that empty set is an element of every non-zero natural number:
lemma empty_in_non_empty:
assumes \( n\in nat \), \( n\neq 0 \)
shows \( 0\in n \) using assms, Nat_ZF_1_L3, empty_in_every_succIf one natural number is less than another then their successors are in the same relation.
lemma succ_ineq:
assumes A1: \( n \in nat \)
shows \( \forall i \in n.\ succ(i) \in succ(n) \)proofFor natural numbers if \(k\subseteq n\) the similar holds for their successors.
lemma succ_subset:
assumes A1: \( k \in nat \), \( n \in nat \) and A2: \( k\subseteq n \)
shows \( succ(k) \subseteq succ(n) \)proofFor any two natural numbers one of them is contained in the other.
lemma nat_incl_total:
assumes A1: \( i \in nat \), \( j \in nat \)
shows \( i \subseteq j \vee j \subseteq i \)proofThe set of natural numbers is the union of all successors of natural numbers.
lemma nat_union_succ:
shows \( nat = (\bigcup n \in nat.\ succ(n)) \)proofSuccessors of natural numbers are subsets of the set of natural numbers.
lemma succnat_subset_nat:
assumes A1: \( n \in nat \)
shows \( succ(n) \subseteq nat \)proofElement \(k\) of a natural number \(n\) is a natural number that is smaller than \(n\).
lemma elem_nat_is_nat:
assumes A1: \( n \in nat \) and A2: \( k\in n \)
shows \( k \lt n \), \( k \in nat \), \( k \leq n \), \( \langle k,n\rangle \in Le \)proofA version of succ_ineq without a quantifier, with additional assertion using the \( n + 1 \) notation.
lemma succ_ineq1:
assumes \( n \in nat \), \( i\in n \)
shows \( succ(i) \in succ(n) \), \( i + 1 \in n + 1 \), \( i \in n + 1 \) using assms, succ_ineq, succ_add_one(1,7), elem_nat_is_nat(2)For natural numbers membership and inequality are the same and \(k \leq n\) is the same as \(k \in \textrm{succ}(n)\). The proof relies on lemmas in the standard Isabelle's Nat and Ordinal theories.
lemma nat_mem_lt:
assumes \( n\in nat \)
shows \( k \lt n \longleftrightarrow k\in n \) and \( k\leq n \longleftrightarrow k \in succ(n) \) using assms, nat_into_Ord, Ord_mem_iff_ltThe term \(k \leq n\) is the same as \(k < \textrm{succ}(n)\).
lemma leq_mem_succ:
shows \( k\leq n \longleftrightarrow k \lt succ(n) \)If the successor of a natural number \(k\) is an element of the successor of \(n\) then a similar relations holds for the numbers themselves.
lemma succ_mem:
assumes \( n \in nat \), \( succ(k) \in succ(n) \)
shows \( k\in n \) using assms, elem_nat_is_nat(1), succ_leE, nat_into_Ord unfolding lt_defThe set of natural numbers is the union of its elements.
lemma nat_union_nat:
shows \( nat = \bigcup nat \) using elem_nat_is_natA natural number is a subset of the set of natural numbers.
lemma nat_subset_nat:
assumes A1: \( n \in nat \)
shows \( n \subseteq nat \)proofAdding natural numbers does not decrease what we add to.
lemma add_nat_le:
assumes A1: \( n \in nat \) and A2: \( k \in nat \)
shows \( n \leq n + k \), \( n \subseteq n + k \), \( n \subseteq k + n \)proofResult of adding an element of \(k\) is smaller than of adding \(k\).
lemma add_lt_mono:
assumes \( k \in nat \) and \( j\in k \)
shows \( (n + j) \lt (n + k) \), \( (n + j) \in (n + k) \)proofA technical lemma about a decomposition of a sum of two natural numbers: if a number \(i\) is from \(m + n\) then it is either from \(m\) or can be written as a sum of \(m\) and a number from \(n\). The proof by induction w.r.t. to \(m\) seems to be a bit heavy-handed, but I could not figure out how to do this directly from results from standard Isabelle/ZF.
lemma nat_sum_decomp:
assumes A1: \( n \in nat \) and A2: \( m \in nat \)
shows \( \forall i \in m + n.\ i \in m \vee (\exists j \in n.\ i = m + j) \)proofA variant of induction useful for finite sequences.
lemma fin_nat_ind:
assumes A1: \( n \in nat \) and A2: \( k \in succ(n) \) and A3: \( P(0) \) and A4: \( \forall j\in n.\ P(j) \longrightarrow P(succ(j)) \)
shows \( P(k) \)proofSome properties of positive natural numbers.
lemma succ_plus:
assumes \( n \in nat \), \( k \in nat \)
shows \( succ(n + j) \in nat \), \( succ(n) + succ(j) = succ(succ(n + j)) \) using assmsIf \(k\) is in the successor of \(n\), then the predecessor of \(k\) is in \(n\).
lemma pred_succ_mem:
assumes \( n\in nat \), \( n\neq 0 \), \( k\in succ(n) \)
shows \( pred(k)\in n \)proofFor non-zero natural numbers \(\textrm{pred}(n) = n-1\).
lemma pred_minus_one:
assumes \( n\in nat \), \( n\neq 0 \)
shows \( n - 1 = pred(n) \)proofFor natural numbers if \(j\in n\) then \(j+1 \subseteq n\).
lemma mem_add_one_subset:
assumes \( n \in nat \), \( k\in n \)
shows \( k + 1 \subseteq n \)proofFor a natural \(n\) if \(k\in n+1\) then \(k+1\leq n+1\).
lemma succ_ineq2:
assumes \( n \in nat \), \( k \in n + 1 \)
shows \( k + 1 \leq n + 1 \) and \( k\leq n \)proofA nonzero natural number is of the form \(n=m+1\) for some natural number \(m\). This is very similar to Nat_ZF_1_L3 except that we use \(n+1\) instead of \( succ(n) \).
lemma nat_not0_succ:
assumes \( n\in nat \), \( n\neq 0 \)
shows \( \exists m\in nat.\ n = m #+1 \) using assms, Nat_ZF_1_L3, succ_add_one(1)Adding and subtracting a natural number cancel each other.
lemma add_subctract:
assumes \( m\in nat \)
shows \( (m + n) - n = m \) using assms, diff_add_inverse2A version of induction on natural numbers that uses the \(n+1\) notation instead of \(\( succ(n) \)\).
lemma ind_on_nat1:
assumes \( n\in nat \) and \( P(0) \) and \( \forall k\in nat.\ P(k)\longrightarrow P(k + 1) \)
shows \( P(n) \) using assms, succ_add_one(1), ind_on_natA version of induction for finite sequences using the \(n+1\) notation instead of \( succ(n) \):
lemma fin_nat_ind1:
assumes \( n\in nat \) and \( P(0) \) and \( \forall j\in n.\ P(j)\longrightarrow P(j + 1) \)
shows \( \forall k\in n + 1.\ P(k) \) and \( P(n) \)proofA simplification rule for natural numbers: if \(k
lemma nat_subtr_simpl0:
assumes \( n\in nat \), \( k\in n \)
shows \( n - (k + 1) + 1 = n - k \)proofIn this section we consider intervals of natural numbers i.e. sets of the form \(\{n+j : j \in 0..k-1\}\).
The interval is determined by two parameters: starting point and length.
definition
\( Nat \text{Interval}(n,k) \equiv \{n + j.\ j\in k\} \)
Subtracting the beginning af the interval results in a number from the length of the interval. It may sound weird, but note that the length of such interval is a natural number, hence a set.
lemma inter_diff_in_len:
assumes A1: \( k \in nat \) and A2: \( i \in Nat \text{Interval}(n,k) \)
shows \( i - n \in k \)proofIntervals don't overlap with their starting point and the union of an interval with its starting point is the sum of the starting point and the length of the interval.
lemma length_start_decomp:
assumes A1: \( n \in nat \), \( k \in nat \)
shows \( n \cap Nat \text{Interval}(n,k) = 0 \), \( n \cup Nat \text{Interval}(n,k) = n + k \)proofSome properties of three adjacent intervals.
lemma adjacent_intervals3:
assumes \( n \in nat \), \( k \in nat \), \( m \in nat \)
shows \( n + k + m = (n + k) \cup Nat \text{Interval}(n + k,m) \), \( n + k + m = n \cup Nat \text{Interval}(n,k + m) \), \( n + k + m = n \cup Nat \text{Interval}(n,k) \cup Nat \text{Interval}(n + k,m) \) using assms, add_assoc, length_start_decompassumes \( n\in nat \) and \( P(0) \) and \( \forall k\in nat.\ P(k)\longrightarrow P(succ(k)) \)
shows \( P(n) \)assumes \( n \in nat \)
shows \( 0 \in succ(n) \)assumes \( n \in nat \) and \( n\neq 0 \)
shows \( \exists k\in nat.\ n = succ(k) \)assumes \( n \in nat \)
shows \( \forall i \in n.\ succ(i) \in succ(n) \)assumes \( n\in nat \)
shows \( n + 1 = succ(n) \), \( n + 1 \in nat \), \( \{0\} + n = succ(n) \), \( n + \{0\} = succ(n) \), \( succ(n) \in nat \), \( 0 \in n + 1 \), \( n \subseteq n + 1 \)assumes \( n \in nat \) and \( k\in n \)
shows \( k \lt n \), \( k \in nat \), \( k \leq n \), \( \langle k,n\rangle \in Le \)assumes \( n \in nat \) and \( k\in n \)
shows \( k \lt n \), \( k \in nat \), \( k \leq n \), \( \langle k,n\rangle \in Le \)assumes \( n \in nat \) and \( k\in n \)
shows \( k \lt n \), \( k \in nat \), \( k \leq n \), \( \langle k,n\rangle \in Le \)assumes \( n \in nat \)
shows \( succ(n) \subseteq nat \)assumes \( n \in nat \), \( succ(k) \in succ(n) \)
shows \( k\in n \)assumes \( n\in nat \), \( n\neq 0 \)
shows \( 0\in n \)assumes \( n \in nat \), \( i\in n \)
shows \( succ(i) \in succ(n) \), \( i + 1 \in n + 1 \), \( i \in n + 1 \)assumes \( n\in nat \)
shows \( n + 1 = succ(n) \), \( n + 1 \in nat \), \( \{0\} + n = succ(n) \), \( n + \{0\} = succ(n) \), \( succ(n) \in nat \), \( 0 \in n + 1 \), \( n \subseteq n + 1 \)assumes \( n\in nat \)
shows \( k \lt n \longleftrightarrow k\in n \) and \( k\leq n \longleftrightarrow k \in succ(n) \)assumes \( n \in nat \) and \( k \in succ(n) \) and \( P(0) \) and \( \forall j\in n.\ P(j) \longrightarrow P(succ(j)) \)
shows \( P(k) \)assumes \( n\in nat \), \( n\neq 0 \)
shows \( \exists m\in nat.\ n = m #+1 \)assumes \( n\in nat \)
shows \( n + 1 = succ(n) \), \( n + 1 \in nat \), \( \{0\} + n = succ(n) \), \( n + \{0\} = succ(n) \), \( succ(n) \in nat \), \( 0 \in n + 1 \), \( n \subseteq n + 1 \)assumes \( n \in nat \), \( k \in n + 1 \)
shows \( k + 1 \leq n + 1 \) and \( k\leq n \)assumes \( n \in nat \) and \( k \in nat \)
shows \( n \leq n + k \), \( n \subseteq n + k \), \( n \subseteq k + n \)assumes \( n \in nat \) and \( m \in nat \)
shows \( \forall i \in m + n.\ i \in m \vee (\exists j \in n.\ i = m + j) \)assumes \( n \in nat \), \( k \in nat \)
shows \( n \cap Nat \text{Interval}(n,k) = 0 \), \( n \cup Nat \text{Interval}(n,k) = n + k \)