IsarMathLib

A library of formalized mathematics for Isabelle/ZF theorem proving environment

theory FiniteSeq_ZF imports Nat_ZF_IML func1
begin

This theory treats finite sequences (i.e. maps \(n\rightarrow X\), where \(n=\{0,1,..,n-1\}\) is a natural number) as lists. It defines and proves the properties of basic operations on lists: concatenation, appending and element etc.

Lists as finite sequences

A natural way of representing (finite) lists in set theory is through (finite) sequences. In such view a list of elements of a set \(X\) is a function that maps the set \(\{0,1,..n-1\}\) into \(X\). Since natural numbers in set theory are defined so that \(n =\{0,1,..n-1\}\), a list of length \(n\) can be understood as an element of the function space \(n\rightarrow X\).

We define the set of lists with values in set \(X\) as \( \text{Lists}(X) \).

Definition

\( \text{Lists}(X) \equiv \bigcup n\in nat.\ (n\rightarrow X) \)

The set of nonempty \(X\)-value listst will be called \( \text{NELists}(X) \).

Definition

\( \text{NELists}(X) \equiv \bigcup n\in nat.\ (succ(n)\rightarrow X) \)

We first define the shift that moves the second sequence to the domain \(\{n,..,n+k-1\}\), where \(n,k\) are the lengths of the first and the second sequence, resp. To understand the notation in the definitions below recall that in Isabelle/ZF \( pred(n) \) is the previous natural number and denotes the difference between natural numbers \(n\) and \(k\).

Definition

\( \text{ShiftedSeq}(b,n) \equiv \{\langle j, b(j \ \sharp - n)\rangle .\ j \in Nat \text{Interval}(n,domain(b))\} \)

We define concatenation of two sequences as the union of the first sequence with the shifted second sequence. The result of concatenating lists \(a\) and \(b\) is called \( \text{Concat}(a,b) \).

Definition

\( \text{Concat}(a,b) \equiv a \cup \text{ShiftedSeq}(b,domain(a)) \)

For a finite sequence we define the sequence of all elements except the first one. This corresponds to the "tail" function in Haskell. We call it Tail here as well.

Definition

\( \text{Tail}(a) \equiv \{\langle k, a(succ(k))\rangle .\ k \in pred(domain(a))\} \)

A dual notion to Tail is the list of all elements of a list except the last one. Borrowing the terminology from Haskell again, we will call this Init.

Definition

\( \text{Init}(a) \equiv \text{restrict}(a,pred(domain(a))) \)

Another obvious operation we can talk about is appending an element at the end of a sequence. This is called Append.

Definition

\( \text{Append}(a,x) \equiv a \cup \{\langle domain(a),x\rangle \} \)

If lists are modeled as finite sequences (i.e. functions on natural intervals \(\{0,1,..,n-1\} = n\)) it is easy to get the first element of a list as the value of the sequence at \(0\). The last element is the value at \(n-1\). To hide this behind a familiar name we define the Last element of a list.

Definition

\( \text{Last}(a) \equiv a(pred(domain(a))) \)

Shifted sequence is a function on a the interval of natural numbers.

lemma shifted_seq_props:

assumes A1: \( n \in nat \), \( k \in nat \) and A2: \( b:k\rightarrow X \)

shows \( \text{ShiftedSeq}(b,n): Nat \text{Interval}(n,k) \rightarrow X \), \( \forall i \in Nat \text{Interval}(n,k).\ \text{ShiftedSeq}(b,n)(i) = b(i \ \sharp - n) \), \( \forall j\in k.\ \text{ShiftedSeq}(b,n)(n \ \sharp + j) = b(j) \)proof
let \( I = Nat \text{Interval}(n,domain(b)) \)
from A2 have Fact: \( I = Nat \text{Interval}(n,k) \) using func1_1_L1
with A1, A2 have \( \forall j\in I.\ b(j \ \sharp - n) \in X \) using inter_diff_in_len , apply_funtype
then have \( \{\langle j, b(j \ \sharp - n)\rangle .\ j \in I\} : I \rightarrow X \) by (rule ZF_fun_from_total )
with Fact show thesis_1: \( \text{ShiftedSeq}(b,n): Nat \text{Interval}(n,k) \rightarrow X \) using ShiftedSeq_def
{
fix \( i \)
from Fact, thesis_1 have \( \text{ShiftedSeq}(b,n): I \rightarrow X \)
moreover
assume \( i \in Nat \text{Interval}(n,k) \)
with Fact have \( i \in I \)
moreover
from Fact have \( \text{ShiftedSeq}(b,n) = \{\langle i, b(i \ \sharp - n)\rangle .\ i \in I\} \) using ShiftedSeq_def
ultimately have \( \text{ShiftedSeq}(b,n)(i) = b(i \ \sharp - n) \) by (rule ZF_fun_from_tot_val )
}
then show thesis1: \( \forall i \in Nat \text{Interval}(n,k).\ \text{ShiftedSeq}(b,n)(i) = b(i \ \sharp - n) \)
{
fix \( j \)
let \( i = n \ \sharp + j \)
assume A3: \( j\in k \)
with A1 have \( j \in nat \) using elem_nat_is_nat
then have \( i \ \sharp - n = j \) using diff_add_inverse
with A3, thesis1 have \( \text{ShiftedSeq}(b,n)(i) = b(j) \) using NatInterval_def
}
then show \( \forall j\in k.\ \text{ShiftedSeq}(b,n)(n \ \sharp + j) = b(j) \)
qed

Basis properties of the contatenation of two finite sequences.

theorem concat_props:

assumes A1: \( n \in nat \), \( k \in nat \) and A2: \( a:n\rightarrow X \), \( b:k\rightarrow X \)

shows \( \text{Concat}(a,b): n \ \sharp + k \rightarrow X \), \( \forall i\in n.\ \text{Concat}(a,b)(i) = a(i) \), \( \forall i \in Nat \text{Interval}(n,k).\ \text{Concat}(a,b)(i) = b(i \ \sharp - n) \), \( \forall j \in k.\ \text{Concat}(a,b)(n \ \sharp + j) = b(j) \)proof
from A1, A2 have \( a:n\rightarrow X \) and I: \( \text{ShiftedSeq}(b,n): Nat \text{Interval}(n,k) \rightarrow X \) and \( n \cap Nat \text{Interval}(n,k) = 0 \) using shifted_seq_props , length_start_decomp
then have \( a \cup \text{ShiftedSeq}(b,n): n \cup Nat \text{Interval}(n,k) \rightarrow X \cup X \) by (rule fun_disjoint_Un )
with A1, A2 show \( \text{Concat}(a,b): n \ \sharp + k \rightarrow X \) using func1_1_L1 , Concat_def , length_start_decomp
{
fix \( i \)
assume \( i \in n \)
with A1, I have \( i \notin domain( \text{ShiftedSeq}(b,n)) \) using length_start_decomp , func1_1_L1
with A2 have \( \text{Concat}(a,b)(i) = a(i) \) using func1_1_L1 , fun_disjoint_apply1 , Concat_def
}
thus \( \forall i\in n.\ \text{Concat}(a,b)(i) = a(i) \)
{
fix \( i \)
assume A3: \( i \in Nat \text{Interval}(n,k) \)
with A1, A2 have \( i \notin domain(a) \) using length_start_decomp , func1_1_L1
with A1, A2, A3 have \( \text{Concat}(a,b)(i) = b(i \ \sharp - n) \) using func1_1_L1 , fun_disjoint_apply2 , Concat_def , shifted_seq_props
}
thus II: \( \forall i \in Nat \text{Interval}(n,k).\ \text{Concat}(a,b)(i) = b(i \ \sharp - n) \)
{
fix \( j \)
let \( i = n \ \sharp + j \)
assume A3: \( j\in k \)
with A1 have \( j \in nat \) using elem_nat_is_nat
then have \( i \ \sharp - n = j \) using diff_add_inverse
with A3, II have \( \text{Concat}(a,b)(i) = b(j) \) using NatInterval_def
}
thus \( \forall j \in k.\ \text{Concat}(a,b)(n \ \sharp + j) = b(j) \)
qed

Properties of concatenating three lists.

lemma concat_concat_list:

assumes A1: \( n \in nat \), \( k \in nat \), \( m \in nat \) and A2: \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( c:m\rightarrow X \) and A3: \( d = \text{Concat}( \text{Concat}(a,b),c) \)

shows \( d : n \ \sharp +k \ \sharp + m \rightarrow X \), \( \forall j \in n.\ d(j) = a(j) \), \( \forall j \in k.\ d(n \ \sharp + j) = b(j) \), \( \forall j \in m.\ d(n \ \sharp + k \ \sharp + j) = c(j) \)proof
from A1, A2 have I: \( n \ \sharp + k \in nat \), \( m \in nat \), \( \text{Concat}(a,b): n \ \sharp + k \rightarrow X \), \( c:m\rightarrow X \) using concat_props
with A3 show \( d: n \ \sharp +k \ \sharp + m \rightarrow X \) using concat_props
from I have II: \( \forall i \in n \ \sharp + k.\ \) \( \text{Concat}( \text{Concat}(a,b),c)(i) = \text{Concat}(a,b)(i) \) by (rule concat_props )
{
fix \( j \)
assume A4: \( j \in n \)
moreover
from A1 have \( n \subseteq n \ \sharp + k \) using add_nat_le
ultimately have \( j \in n \ \sharp + k \)
with A3, II have \( d(j) = \text{Concat}(a,b)(j) \)
with A1, A2, A4 have \( d(j) = a(j) \) using concat_props
}
thus \( \forall j \in n.\ d(j) = a(j) \)
{
fix \( j \)
assume A5: \( j \in k \)
with A1, A3, II have \( d(n \ \sharp + j) = \text{Concat}(a,b)(n \ \sharp + j) \) using add_lt_mono
also
from A1, A2, A5 have \( \ldots = b(j) \) using concat_props
finally have \( d(n \ \sharp + j) = b(j) \)
}
thus \( \forall j \in k.\ d(n \ \sharp + j) = b(j) \)
from I have \( \forall j \in m.\ \text{Concat}( \text{Concat}(a,b),c)(n \ \sharp + k \ \sharp + j) = c(j) \) by (rule concat_props )
with A3 show \( \forall j \in m.\ d(n \ \sharp + k \ \sharp + j) = c(j) \)
qed

Properties of concatenating a list with a concatenation of two other lists.

lemma concat_list_concat:

assumes A1: \( n \in nat \), \( k \in nat \), \( m \in nat \) and A2: \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( c:m\rightarrow X \) and A3: \( e = \text{Concat}(a, \text{Concat}(b,c)) \)

shows \( e : n \ \sharp +k \ \sharp + m \rightarrow X \), \( \forall j \in n.\ e(j) = a(j) \), \( \forall j \in k.\ e(n \ \sharp + j) = b(j) \), \( \forall j \in m.\ e(n \ \sharp + k \ \sharp + j) = c(j) \)proof
from A1, A2 have I: \( n \in nat \), \( k \ \sharp + m \in nat \), \( a:n\rightarrow X \), \( \text{Concat}(b,c): k \ \sharp + m \rightarrow X \) using concat_props
with A3 show \( e : n \ \sharp +k \ \sharp + m \rightarrow X \) using concat_props , add_assoc
from I have \( \forall j \in n.\ \text{Concat}(a, \text{Concat}(b,c))(j) = a(j) \) by (rule concat_props )
with A3 show \( \forall j \in n.\ e(j) = a(j) \)
from I have II: \( \forall j \in k \ \sharp + m.\ \text{Concat}(a, \text{Concat}(b,c))(n \ \sharp + j) = \text{Concat}(b,c)(j) \) by (rule concat_props )
{
fix \( j \)
assume A4: \( j \in k \)
moreover
from A1 have \( k \subseteq k \ \sharp + m \) using add_nat_le
ultimately have \( j \in k \ \sharp + m \)
with A3, II have \( e(n \ \sharp + j) = \text{Concat}(b,c)(j) \)
also
from A1, A2, A4 have \( \ldots = b(j) \) using concat_props
finally have \( e(n \ \sharp + j) = b(j) \)
}
thus \( \forall j \in k.\ e(n \ \sharp + j) = b(j) \)
{
fix \( j \)
assume A5: \( j \in m \)
with A1, II, A3 have \( e(n \ \sharp + k \ \sharp + j) = \text{Concat}(b,c)(k \ \sharp + j) \) using add_lt_mono , add_assoc
also
from A1, A2, A5 have \( \ldots = c(j) \) using concat_props
finally have \( e(n \ \sharp + k \ \sharp + j) = c(j) \)
}
then show \( \forall j \in m.\ e(n \ \sharp + k \ \sharp + j) = c(j) \)
qed

Concatenation is associative.

theorem concat_assoc:

assumes A1: \( n \in nat \), \( k \in nat \), \( m \in nat \) and A2: \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( c:m\rightarrow X \)

shows \( \text{Concat}( \text{Concat}(a,b),c) = \text{Concat}(a, \text{Concat}(b,c)) \)proof
let \( d = \text{Concat}( \text{Concat}(a,b),c) \)
let \( e = \text{Concat}(a, \text{Concat}(b,c)) \)
from A1, A2 have \( d : n \ \sharp +k \ \sharp + m \rightarrow X \) and \( e : n \ \sharp +k \ \sharp + m \rightarrow X \) using concat_concat_list , concat_list_concat
moreover
have \( \forall i \in n \ \sharp +k \ \sharp + m.\ d(i) = e(i) \)proof
{
fix \( i \)
assume \( i \in n \ \sharp +k \ \sharp + m \)
moreover
from A1 have \( n \ \sharp +k \ \sharp + m = n \cup Nat \text{Interval}(n,k) \cup Nat \text{Interval}(n \ \sharp + k,m) \) using adjacent_intervals3
ultimately have \( i \in n \vee i \in Nat \text{Interval}(n,k) \vee i \in Nat \text{Interval}(n \ \sharp + k,m) \)
moreover {
assume \( i \in n \)
with A1, A2 have \( d(i) = e(i) \) using concat_concat_list , concat_list_concat
} moreover {
assume \( i \in Nat \text{Interval}(n,k) \)
then obtain \( j \) where \( j\in k \) and \( i = n \ \sharp + j \) using NatInterval_def
with A1, A2 have \( d(i) = e(i) \) using concat_concat_list , concat_list_concat
} moreover {
assume \( i \in Nat \text{Interval}(n \ \sharp + k,m) \)
then obtain \( j \) where \( j \in m \) and \( i = n \ \sharp + k \ \sharp + j \) using NatInterval_def
with A1, A2 have \( d(i) = e(i) \) using concat_concat_list , concat_list_concat
} ultimately have \( d(i) = e(i) \)
}
thus \( thesis \)
qed
ultimately show \( d = e \) by (rule func_eq )
qed

Properties of Tail.

theorem tail_props:

assumes A1: \( n \in nat \) and A2: \( a: succ(n) \rightarrow X \)

shows \( \text{Tail}(a) : n \rightarrow X \), \( \forall k \in n.\ \text{Tail}(a)(k) = a(succ(k)) \)proof
from A1, A2 have \( \forall k \in n.\ a(succ(k)) \in X \) using succ_ineq , apply_funtype
then have \( \{\langle k, a(succ(k))\rangle .\ k \in n\} : n \rightarrow X \) by (rule ZF_fun_from_total )
with A2 show I: \( \text{Tail}(a) : n \rightarrow X \) using func1_1_L1 , pred_succ_eq , Tail_def
moreover
from A2 have \( \text{Tail}(a) = \{\langle k, a(succ(k))\rangle .\ k \in n\} \) using func1_1_L1 , pred_succ_eq , Tail_def
ultimately show \( \forall k \in n.\ \text{Tail}(a)(k) = a(succ(k)) \) by (rule ZF_fun_from_tot_val0 )
qed

Properties of Append. It is a bit surprising that the we don't need to assume that \(n\) is a natural number.

theorem append_props:

assumes A1: \( a: n \rightarrow X \) and A2: \( x\in X \) and A3: \( b = \text{Append}(a,x) \)

shows \( b : succ(n) \rightarrow X \), \( \forall k\in n.\ b(k) = a(k) \), \( b(n) = x \)proof
note A1
moreover
have I: \( n \notin n \) using mem_not_refl
moreover
from A1, A3 have II: \( b = a \cup \{\langle n,x\rangle \} \) using func1_1_L1 , Append_def
ultimately have \( b : n \cup \{n\} \rightarrow X \cup \{x\} \) by (rule func1_1_L11D )
with A2 show \( b : succ(n) \rightarrow X \) using succ_explained , set_elem_add
from A1, I, II show \( \forall k\in n.\ b(k) = a(k) \) and \( b(n) = x \) using func1_1_L11D
qed

A special case of append_props: appending to a nonempty list does not change the head (first element) of the list.

corollary head_of_append:

assumes \( n\in nat \) and \( a: succ(n) \rightarrow X \) and \( x\in X \)

shows \( \text{Append}(a,x)(0) = a(0) \) using assms , append_props , empty_in_every_succ

Tail commutes with Append.

theorem tail_append_commute:

assumes A1: \( n \in nat \) and A2: \( a: succ(n) \rightarrow X \) and A3: \( x\in X \)

shows \( \text{Append}( \text{Tail}(a),x) = \text{Tail}( \text{Append}(a,x)) \)proof
let \( b = \text{Append}( \text{Tail}(a),x) \)
let \( c = \text{Tail}( \text{Append}(a,x)) \)
from A1, A2 have I: \( \text{Tail}(a) : n \rightarrow X \) using tail_props
from A1, A2, A3 have \( succ(n) \in nat \) and \( \text{Append}(a,x) : succ(succ(n)) \rightarrow X \) using append_props
then have II: \( \forall k \in succ(n).\ c(k) = \text{Append}(a,x)(succ(k)) \) by (rule tail_props )
from assms have \( b : succ(n) \rightarrow X \) and \( c : succ(n) \rightarrow X \) using tail_props , append_props
moreover
have \( \forall k \in succ(n).\ b(k) = c(k) \)proof
{
fix \( k \)
assume \( k \in succ(n) \)
hence \( k \in n \vee k = n \)
moreover {
assume A4: \( k \in n \)
with assms, II have \( c(k) = a(succ(k)) \) using succ_ineq , append_props
moreover
from A3, I have \( \forall k\in n.\ b(k) = \text{Tail}(a)(k) \) using append_props
with A1, A2, A4 have \( b(k) = a(succ(k)) \) using tail_props
ultimately have \( b(k) = c(k) \)
} moreover {
assume A5: \( k = n \)
with A2, A3, I, II have \( b(k) = c(k) \) using append_props
} ultimately have \( b(k) = c(k) \)
}
thus \( thesis \)
qed
ultimately show \( b = c \) by (rule func_eq )
qed

Properties of Init.

theorem init_props:

assumes A1: \( n \in nat \) and A2: \( a: succ(n) \rightarrow X \)

shows \( \text{Init}(a) : n \rightarrow X \), \( \forall k\in n.\ \text{Init}(a)(k) = a(k) \), \( a = \text{Append}( \text{Init}(a), a(n)) \)proof
have \( n \subseteq succ(n) \)
with A2 have \( \text{restrict}(a,n): n \rightarrow X \) using restrict_type2
moreover
from A1, A2 have I: \( \text{restrict}(a,n) = \text{Init}(a) \) using func1_1_L1 , pred_succ_eq , Init_def
ultimately show thesis1: \( \text{Init}(a) : n \rightarrow X \)
{
fix \( k \)
assume \( k\in n \)
then have \( \text{restrict}(a,n)(k) = a(k) \) using restrict
with I have \( \text{Init}(a)(k) = a(k) \)
}
then show thesis2: \( \forall k\in n.\ \text{Init}(a)(k) = a(k) \)
let \( b = \text{Append}( \text{Init}(a), a(n)) \)
from A2, thesis1 have II: \( \text{Init}(a) : n \rightarrow X \), \( a(n) \in X \), \( b = \text{Append}( \text{Init}(a), a(n)) \) using apply_funtype
note A2
moreover
from II have \( b : succ(n) \rightarrow X \) by (rule append_props )
moreover
have \( \forall k \in succ(n).\ a(k) = b(k) \)proof
{
fix \( k \)
assume A3: \( k \in n \)
from II have \( \forall j\in n.\ b(j) = \text{Init}(a)(j) \) by (rule append_props )
with thesis2, A3 have \( a(k) = b(k) \)
}
moreover
from II have \( b(n) = a(n) \) by (rule append_props )
hence \( a(n) = b(n) \)
ultimately show \( \forall k \in succ(n).\ a(k) = b(k) \)
qed
ultimately show \( a = b \) by (rule func_eq )
qed

If we take init of the result of append, we get back the same list.

lemma init_append:

assumes A1: \( n \in nat \) and A2: \( a:n\rightarrow X \) and A3: \( x \in X \)

shows \( \text{Init}( \text{Append}(a,x)) = a \)proof
from A2, A3 have \( \text{Append}(a,x): succ(n)\rightarrow X \) using append_props
with A1 have \( \text{Init}( \text{Append}(a,x)):n\rightarrow X \) and \( \forall k\in n.\ \text{Init}( \text{Append}(a,x))(k) = \text{Append}(a,x)(k) \) using init_props
with A2, A3 have \( \forall k\in n.\ \text{Init}( \text{Append}(a,x))(k) = a(k) \) using append_props
with \( \text{Init}( \text{Append}(a,x)):n\rightarrow X \), A2 show \( thesis \) by (rule func_eq )
qed

A reformulation of definition of Init.

lemma init_def:

assumes \( n \in nat \) and \( x:succ(n)\rightarrow X \)

shows \( \text{Init}(x) = \text{restrict}(x,n) \) using assms , func1_1_L1 , Init_def

A lemma about extending a finite sequence by one more value. This is just a more explicit version of append_props.

lemma finseq_extend:

assumes \( a:n\rightarrow X \), \( y\in X \), \( b = a \cup \{\langle n,y\rangle \} \)

shows \( b: succ(n) \rightarrow X \), \( \forall k\in n.\ b(k) = a(k) \), \( b(n) = y \) using assms , Append_def , func1_1_L1 , append_props

The next lemma is a bit displaced as it is mainly about finite sets. It is proven here because it uses the notion of Append. Suppose we have a list of element of \(A\) is a bijection. Then for every element that does not belong to \(A\) we can we can construct a bijection for the set \(A \cup \{ x\}\) by appending \(x\). This is just a specialised version of lemma bij_extend_point from func1.thy.

lemma bij_append_point:

assumes A1: \( n \in nat \) and A2: \( b \in \text{bij}(n,X) \) and A3: \( x \notin X \)

shows \( \text{Append}(b,x) \in \text{bij}(succ(n), X \cup \{x\}) \)proof
from A2, A3 have \( b \cup \{\langle n,x\rangle \} \in \text{bij}(n \cup \{n\},X \cup \{x\}) \) using mem_not_refl , bij_extend_point
moreover
have \( \text{Append}(b,x) = b \cup \{\langle n,x\rangle \} \)proof
from A2 have \( b:n\rightarrow X \) using bij_def , surj_def
then have \( b : n \rightarrow X \cup \{x\} \) using func1_1_L1B
then show \( \text{Append}(b,x) = b \cup \{\langle n,x\rangle \} \) using Append_def , func1_1_L1
qed
ultimately show \( thesis \) using succ_explained
qed

The next lemma rephrases the definition of Last. Recall that in ZF we have \(\{0,1,2,..,n\} = n+1=\)succ\((n)\).

lemma last_seq_elem:

assumes \( a: succ(n) \rightarrow X \)

shows \( \text{Last}(a) = a(n) \) using assms , func1_1_L1 , pred_succ_eq , Last_def

If two finite sequences are the same when restricted to domain one shorter than the original and have the same value on the last element, then they are equal.

lemma finseq_restr_eq:

assumes A1: \( n \in nat \) and A2: \( a: succ(n) \rightarrow X \), \( b: succ(n) \rightarrow X \) and A3: \( \text{restrict}(a,n) = \text{restrict}(b,n) \) and A4: \( a(n) = b(n) \)

shows \( a = b \)proof
{
fix \( k \)
assume \( k \in succ(n) \)
then have \( k \in n \vee k = n \)
moreover {
assume \( k \in n \)
then have \( \text{restrict}(a,n)(k) = a(k) \) and \( \text{restrict}(b,n)(k) = b(k) \) using restrict
with A3 have \( a(k) = b(k) \)
} moreover {
assume \( k = n \)
with A4 have \( a(k) = b(k) \)
} ultimately have \( a(k) = b(k) \)
}
then have \( \forall k \in succ(n).\ a(k) = b(k) \)
with A2 show \( a = b \) by (rule func_eq )
qed

Concatenating a list of length \(1\) is the same as appending its first (and only) element. Recall that in ZF set theory \(1 = \{ 0 \} \).

lemma append_1elem:

assumes A1: \( n \in nat \) and A2: \( a: n \rightarrow X \) and A3: \( b : 1 \rightarrow X \)

shows \( \text{Concat}(a,b) = \text{Append}(a,b(0)) \)proof
let \( C = \text{Concat}(a,b) \)
let \( A = \text{Append}(a,b(0)) \)
from A1, A2, A3 have I: \( n \in nat \), \( 1 \in nat \), \( a:n\rightarrow X \), \( b:1\rightarrow X \)
have \( C : succ(n) \rightarrow X \)proof
from I have \( C : n \ \sharp + 1 \rightarrow X \) by (rule concat_props )
with A1 show \( C : succ(n) \rightarrow X \)
qed
moreover
from A2, A3 have \( A : succ(n) \rightarrow X \) using apply_funtype , append_props
moreover
have \( \forall k \in succ(n).\ C(k) = A(k) \)proof
fix \( k \)
assume \( k \in succ(n) \)
moreover {
assume \( k \in n \)
moreover
from I have \( \forall i \in n.\ C(i) = a(i) \) by (rule concat_props )
moreover
from A2, A3 have \( \forall i\in n.\ A(i) = a(i) \) using apply_funtype , append_props
ultimately have \( C(k) = A(k) \)
} moreover
have \( C(n) = A(n) \)proof
from I have \( \forall j \in 1.\ C(n \ \sharp + j) = b(j) \) by (rule concat_props )
with A1, A2, A3 show \( C(n) = A(n) \) using apply_funtype , append_props
qed
ultimately show \( C(k) = A(k) \)
qed
ultimately show \( C = A \) by (rule func_eq )
qed

A simple lemma about lists of length \(1\).

lemma list_len1_singleton:

assumes A1: \( x\in X \)

shows \( \{\langle 0,x\rangle \} : 1 \rightarrow X \)proof
from A1 have \( \{\langle 0,x\rangle \} : \{0\} \rightarrow X \) using pair_func_singleton
moreover
have \( \{0\} = 1 \)
ultimately show \( thesis \)
qed

A singleton list is in fact a singleton set with a pair as the only element.

lemma list_singleton_pair:

assumes A1: \( x:1\rightarrow X \)

shows \( x = \{\langle 0,x(0)\rangle \} \)proof
from A1 have \( x = \{\langle t,x(t)\rangle .\ t\in 1\} \) by (rule fun_is_set_of_pairs )
hence \( x = \{\langle t,x(t)\rangle .\ t\in \{0\} \} \)
thus \( thesis \)
qed

When we append an element to the empty list we get a list with length \(1\).

lemma empty_append1:

assumes A1: \( x\in X \)

shows \( \text{Append}(0,x): 1 \rightarrow X \) and \( \text{Append}(0,x)(0) = x \)proof
let \( a = \text{Append}(0,x) \)
have \( a = \{\langle 0,x\rangle \} \) using Append_def
with A1 show \( a : 1 \rightarrow X \) and \( a(0) = x \) using list_len1_singleton , pair_func_singleton
qed

Appending an element is the same as concatenating with certain pair.

lemma append_concat_pair:

assumes \( n \in nat \) and \( a: n \rightarrow X \) and \( x\in X \)

shows \( \text{Append}(a,x) = \text{Concat}(a,\{\langle 0,x\rangle \}) \) using assms , list_len1_singleton , append_1elem , pair_val

An associativity property involving concatenation and appending. For proof we just convert appending to concatenation and use concat_assoc.

lemma concat_append_assoc:

assumes A1: \( n \in nat \), \( k \in nat \) and A2: \( a:n\rightarrow X \), \( b:k\rightarrow X \) and A3: \( x \in X \)

shows \( \text{Append}( \text{Concat}(a,b),x) = \text{Concat}(a, \text{Append}(b,x)) \)proof
from A1, A2, A3 have \( n \ \sharp + k \in nat \), \( \text{Concat}(a,b) : n \ \sharp + k \rightarrow X \), \( x \in X \) using concat_props
then have \( \text{Append}( \text{Concat}(a,b),x) = \text{Concat}( \text{Concat}(a,b),\{\langle 0,x\rangle \}) \) by (rule append_concat_pair )
moreover
from A1, A2, A3 have \( n \in nat \), \( k \in nat \), \( 1 \in nat \), \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( \{\langle 0,x\rangle \} : 1 \rightarrow X \) using list_len1_singleton
then have \( \text{Concat}( \text{Concat}(a,b),\{\langle 0,x\rangle \}) = \text{Concat}(a, \text{Concat}(b,\{\langle 0,x\rangle \})) \) by (rule concat_assoc )
moreover
from A1, A2, A3 have \( \text{Concat}(b,\{\langle 0,x\rangle \}) = \text{Append}(b,x) \) using list_len1_singleton , append_1elem , pair_val
ultimately show \( \text{Append}( \text{Concat}(a,b),x) = \text{Concat}(a, \text{Append}(b,x)) \)
qed

An identity involving concatenating with init and appending the last element.

lemma concat_init_last_elem:

assumes \( n \in nat \), \( k \in nat \) and \( a: n \rightarrow X \) and \( b : succ(k) \rightarrow X \)

shows \( \text{Append}( \text{Concat}(a, \text{Init}(b)),b(k)) = \text{Concat}(a,b) \) using assms , init_props , apply_funtype , concat_append_assoc

A lemma about creating lists by composition and how Append behaves in such case.

lemma list_compose_append:

assumes A1: \( n \in nat \) and A2: \( a : n \rightarrow X \) and A3: \( x \in X \) and A4: \( c : X \rightarrow Y \)

shows \( c\circ \text{Append}(a,x) : succ(n) \rightarrow Y \), \( c\circ \text{Append}(a,x) = \text{Append}(c\circ a, c(x)) \)proof
let \( b = \text{Append}(a,x) \)
let \( d = \text{Append}(c\circ a, c(x)) \)
from A2, A4 have \( c\circ a : n \rightarrow Y \) using comp_fun
from A2, A3 have \( b : succ(n) \rightarrow X \) using append_props
with A4 show \( c\circ b : succ(n) \rightarrow Y \) using comp_fun
moreover
from A3, A4, \( c\circ a : n \rightarrow Y \) have \( d: succ(n) \rightarrow Y \) using apply_funtype , append_props
moreover
have \( \forall k \in succ(n).\ (c\circ b) (k) = d(k) \)proof
{
fix \( k \)
assume \( k \in succ(n) \)
with \( b : succ(n) \rightarrow X \) have \( (c\circ b) (k) = c(b(k)) \) using comp_fun_apply
with A2, A3, A4, \( c\circ a : n \rightarrow Y \), \( c\circ a : n \rightarrow Y \), \( k \in succ(n) \) have \( (c\circ b) (k) = d(k) \) using append_props , comp_fun_apply , apply_funtype
}
thus \( thesis \)
qed
ultimately show \( c\circ b = d \) by (rule func_eq )
qed

A lemma about appending an element to a list defined by set comprehension.

lemma set_list_append:

assumes A1: \( \forall i \in succ(k).\ b(i) \in X \) and A2: \( a = \{\langle i,b(i)\rangle .\ i \in succ(k)\} \)

shows \( a: succ(k) \rightarrow X \), \( \{\langle i,b(i)\rangle .\ i \in k\}: k \rightarrow X \), \( a = \text{Append}(\{\langle i,b(i)\rangle .\ i \in k\},b(k)) \)proof
from A1 have \( \{\langle i,b(i)\rangle .\ i \in succ(k)\} : succ(k) \rightarrow X \) by (rule ZF_fun_from_total )
with A2 show \( a: succ(k) \rightarrow X \)
from A1 have \( \forall i \in k.\ b(i) \in X \)
then show \( \{\langle i,b(i)\rangle .\ i \in k\}: k \rightarrow X \) by (rule ZF_fun_from_total )
with A2 show \( a = \text{Append}(\{\langle i,b(i)\rangle .\ i \in k\},b(k)) \) using func1_1_L1 , Append_def
qed

An induction theorem for lists.

lemma list_induct:

assumes A1: \( \forall b\in 1\rightarrow X.\ P(b) \) and A2: \( \forall b\in \text{NELists}(X).\ P(b) \longrightarrow (\forall x\in X.\ P( \text{Append}(b,x))) \) and A3: \( d \in \text{NELists}(X) \)

shows \( P(d) \)proof
{
fix \( n \)
assume \( n\in nat \)
moreover
from A1 have \( \forall b\in succ(0)\rightarrow X.\ P(b) \)
moreover
have \( \forall k\in nat.\ ((\forall b\in succ(k)\rightarrow X.\ P(b)) \longrightarrow (\forall c\in succ(succ(k))\rightarrow X.\ P(c))) \)proof
{
fix \( k \)
assume \( k \in nat \)
assume \( \forall b\in succ(k)\rightarrow X.\ P(b) \)
have \( \forall c\in succ(succ(k))\rightarrow X.\ P(c) \)proof
fix \( c \)
assume \( c: succ(succ(k))\rightarrow X \)
let \( b = \text{Init}(c) \)
let \( x = c(succ(k)) \)
from \( k \in nat \), \( c: succ(succ(k))\rightarrow X \) have \( b:succ(k)\rightarrow X \) using init_props
with A2, \( k \in nat \), \( \forall b\in succ(k)\rightarrow X.\ P(b) \) have \( \forall x\in X.\ P( \text{Append}(b,x)) \) using NELists_def
with \( c: succ(succ(k))\rightarrow X \) have \( P( \text{Append}(b,x)) \) using apply_funtype
with \( k \in nat \), \( c: succ(succ(k))\rightarrow X \) show \( P(c) \) using init_props
qed
}
thus \( thesis \)
qed
ultimately have \( \forall b\in succ(n)\rightarrow X.\ P(b) \) by (rule ind_on_nat )
}
with A3 show \( thesis \) using NELists_def
qed

Lists and cartesian products

Lists of length \(n\) of elements of some set \(X\) can be thought of as a model of the cartesian product \(X^n\) which is more convenient in many applications.

There is a natural bijection between the space \((n+1)\rightarrow X\) of lists of length \(n+1\) of elements of \(X\) and the cartesian product \((n\rightarrow X)\times X\).

lemma lists_cart_prod:

assumes \( n \in nat \)

shows \( \{\langle x,\langle \text{Init}(x),x(n)\rangle \rangle .\ x \in succ(n)\rightarrow X\} \in \text{bij}(succ(n)\rightarrow X,(n\rightarrow X)\times X) \)proof
let \( f = \{\langle x,\langle \text{Init}(x),x(n)\rangle \rangle .\ x \in succ(n)\rightarrow X\} \)
from assms have \( \forall x \in succ(n)\rightarrow X.\ \langle \text{Init}(x),x(n)\rangle \in (n\rightarrow X)\times X \) using init_props , succ_iff , apply_funtype
then have I: \( f: (succ(n)\rightarrow X)\rightarrow ((n\rightarrow X)\times X) \) by (rule ZF_fun_from_total )
moreover
from assms, I have \( \forall x\in succ(n)\rightarrow X.\ \forall y\in succ(n)\rightarrow X.\ f(x)=f(y) \longrightarrow x=y \) using ZF_fun_from_tot_val , init_def , finseq_restr_eq
moreover
have \( \forall p\in (n\rightarrow X)\times X.\ \exists x\in succ(n)\rightarrow X.\ f(x) = p \)proof
fix \( p \)
assume \( p \in (n\rightarrow X)\times X \)
let \( x = \text{Append}(\text{fst}(p),\text{snd}(p)) \)
from assms, \( p \in (n\rightarrow X)\times X \) have \( x:succ(n)\rightarrow X \) using append_props
with I have \( f(x) = \langle \text{Init}(x),x(n)\rangle \) using succ_iff , ZF_fun_from_tot_val
moreover
from assms, \( p \in (n\rightarrow X)\times X \) have \( \text{Init}(x) = \text{fst}(p) \) and \( x(n) = \text{snd}(p) \) using init_append , append_props
ultimately have \( f(x) = \langle \text{fst}(p),\text{snd}(p)\rangle \)
with \( p \in (n\rightarrow X)\times X \), \( x:succ(n)\rightarrow X \) show \( \exists x\in succ(n)\rightarrow X.\ f(x) = p \)
qed
ultimately show \( thesis \) using inj_def , surj_def , bij_def
qed

We can identify a set \(X\) with lists of length one of elements of \(X\).

lemma singleton_list_bij:

shows \( \{\langle x,x(0)\rangle .\ x\in 1\rightarrow X\} \in \text{bij}(1\rightarrow X,X) \)proof
let \( f = \{\langle x,x(0)\rangle .\ x\in 1\rightarrow X\} \)
have \( \forall x\in 1\rightarrow X.\ x(0) \in X \) using apply_funtype
then have I: \( f:(1\rightarrow X)\rightarrow X \) by (rule ZF_fun_from_total )
moreover
have \( \forall x\in 1\rightarrow X.\ \forall y\in 1\rightarrow X.\ f(x) = f(y) \longrightarrow x=y \)proof
{
fix \( x \) \( y \)
assume \( x:1\rightarrow X \), \( y:1\rightarrow X \) and \( f(x) = f(y) \)
with I have \( x(0) = y(0) \) using ZF_fun_from_tot_val
moreover
from \( x:1\rightarrow X \), \( y:1\rightarrow X \) have \( x = \{\langle 0,x(0)\rangle \} \) and \( y = \{\langle 0,y(0)\rangle \} \) using list_singleton_pair
ultimately have \( x=y \)
}
thus \( thesis \)
qed
moreover
have \( \forall y\in X.\ \exists x\in 1\rightarrow X.\ f(x)=y \)proof
fix \( y \)
assume \( y\in X \)
let \( x = \{\langle 0,y\rangle \} \)
from I, \( y\in X \) have \( x:1\rightarrow X \) and \( f(x) = y \) using list_len1_singleton , ZF_fun_from_tot_val , pair_val
thus \( \exists x\in 1\rightarrow X.\ f(x)=y \)
qed
ultimately show \( thesis \) using inj_def , surj_def , bij_def
qed

We can identify a set of \(X\)-valued lists of length with \(X\).

lemma list_singleton_bij:

shows \( \{\langle x,\{\langle 0,x\rangle \}\rangle .\ x\in X\} \in \text{bij}(X,1\rightarrow X) \) and \( \{\langle y,y(0)\rangle .\ y\in 1\rightarrow X\} = converse(\{\langle x,\{\langle 0,x\rangle \}\rangle .\ x\in X\}) \) and \( \{\langle x,\{\langle 0,x\rangle \}\rangle .\ x\in X\} = converse(\{\langle y,y(0)\rangle .\ y\in 1\rightarrow X\}) \)proof
let \( f = \{\langle y,y(0)\rangle .\ y\in 1\rightarrow X\} \)
let \( g = \{\langle x,\{\langle 0,x\rangle \}\rangle .\ x\in X\} \)
have \( 1 = \{0\} \)
then have \( f \in \text{bij}(1\rightarrow X,X) \) and \( g:X\rightarrow (1\rightarrow X) \) using singleton_list_bij , pair_func_singleton , ZF_fun_from_total
moreover
have \( \forall y\in 1\rightarrow X.\ g(f(y)) = y \)proof
fix \( y \)
assume \( y:1\rightarrow X \)
have \( f:(1\rightarrow X)\rightarrow X \) using singleton_list_bij , bij_def , inj_def
with \( 1 = \{0\} \), \( y:1\rightarrow X \), \( g:X\rightarrow (1\rightarrow X) \) show \( g(f(y)) = y \) using ZF_fun_from_tot_val , apply_funtype , func_singleton_pair
qed
ultimately show \( g \in \text{bij}(X,1\rightarrow X) \) and \( f = converse(g) \) and \( g = converse(f) \) using comp_conv_id
qed

What is the inverse image of a set by the natural bijection between \(X\)-valued singleton lists and \(X\)?

lemma singleton_vimage:

assumes \( U\subseteq X \)

shows \( \{x\in 1\rightarrow X.\ x(0) \in U\} = \{ \{\langle 0,y\rangle \}.\ y\in U\} \)proof
have \( 1 = \{0\} \)
{
fix \( x \)
assume \( x \in \{x\in 1\rightarrow X.\ x(0) \in U\} \)
with \( 1 = \{0\} \) have \( x = \{\langle 0, x(0)\rangle \} \) using func_singleton_pair
}
thus \( \{x\in 1\rightarrow X.\ x(0) \in U\} \subseteq \{ \{\langle 0,y\rangle \}.\ y\in U\} \)
{
fix \( x \)
assume \( x \in \{ \{\langle 0,y\rangle \}.\ y\in U\} \)
then obtain \( y \) where \( x = \{\langle 0,y\rangle \} \) and \( y\in U \)
with \( 1 = \{0\} \), assms have \( x:1\rightarrow X \) using pair_func_singleton
}
thus \( \{ \{\langle 0,y\rangle \}.\ y\in U\} \subseteq \{x\in 1\rightarrow X.\ x(0) \in U\} \)
qed

A technical lemma about extending a list by values from a set.

lemma list_append_from:

assumes A1: \( n \in nat \) and A2: \( U \subseteq n\rightarrow X \) and A3: \( V \subseteq X \)

shows \( \{x \in succ(n)\rightarrow X.\ \text{Init}(x) \in U \wedge x(n) \in V\} = (\bigcup y\in V.\ \{ \text{Append}(x,y).\ x\in U\}) \)proof
{
fix \( x \)
assume \( x \in \{x \in succ(n)\rightarrow X.\ \text{Init}(x) \in U \wedge x(n) \in V\} \)
then have \( x \in succ(n)\rightarrow X \) and \( \text{Init}(x) \in U \) and I: \( x(n) \in V \)
let \( y = x(n) \)
from A1, and, \( x \in succ(n)\rightarrow X \) have \( x = \text{Append}( \text{Init}(x),y) \) using init_props
with I, and, \( \text{Init}(x) \in U \) have \( x \in (\bigcup y\in V.\ \{ \text{Append}(a,y).\ a\in U\}) \)
}
moreover {
fix \( x \)
assume \( x \in (\bigcup y\in V.\ \{ \text{Append}(a,y).\ a\in U\}) \)
then obtain \( a \) \( y \) where \( y\in V \) and \( a\in U \) and \( x = \text{Append}(a,y) \)
with A2, A3 have \( x: succ(n)\rightarrow X \) using append_props
from A2, A3, \( y\in V \), \( a\in U \) have \( a:n\rightarrow X \) and \( y\in X \)
with A1, \( a\in U \), \( y\in V \), \( x = \text{Append}(a,y) \) have \( \text{Init}(x) \in U \) and \( x(n) \in V \) using append_props , init_append
with \( x: succ(n)\rightarrow X \) have \( x \in \{x \in succ(n)\rightarrow X.\ \text{Init}(x) \in U \wedge x(n) \in V\} \)
} ultimately show \( thesis \)
qed
end
lemma func1_1_L1:

assumes \( f:A\rightarrow C \)

shows \( domain(f) = A \)
lemma inter_diff_in_len:

assumes \( k \in nat \) and \( i \in Nat \text{Interval}(n,k) \)

shows \( i \ \sharp - n \in k \)
lemma ZF_fun_from_total:

assumes \( \forall x\in X.\ b(x) \in Y \)

shows \( \{\langle x,b(x)\rangle .\ x\in X\} : X\rightarrow Y \)
Definition of ShiftedSeq: \( \text{ShiftedSeq}(b,n) \equiv \{\langle j, b(j \ \sharp - n)\rangle .\ j \in Nat \text{Interval}(n,domain(b))\} \)
lemma ZF_fun_from_tot_val:

assumes \( f:X\rightarrow Y \), \( x\in X \) and \( f = \{\langle x,b(x)\rangle .\ x\in X\} \)

shows \( f(x) = b(x) \)
lemma elem_nat_is_nat:

assumes \( n \in nat \) and \( k\in n \)

shows \( k \lt n \), \( k \in nat \), \( k \leq n \), \( \langle k,n\rangle \in Le \)
Definition of NatInterval: \( Nat \text{Interval}(n,k) \equiv \{n \ \sharp + j.\ j\in k\} \)
lemma shifted_seq_props:

assumes \( n \in nat \), \( k \in nat \) and \( b:k\rightarrow X \)

shows \( \text{ShiftedSeq}(b,n): Nat \text{Interval}(n,k) \rightarrow X \), \( \forall i \in Nat \text{Interval}(n,k).\ \text{ShiftedSeq}(b,n)(i) = b(i \ \sharp - n) \), \( \forall j\in k.\ \text{ShiftedSeq}(b,n)(n \ \sharp + j) = b(j) \)
lemma length_start_decomp:

assumes \( n \in nat \), \( k \in nat \)

shows \( n \cap Nat \text{Interval}(n,k) = 0 \), \( n \cup Nat \text{Interval}(n,k) = n \ \sharp + k \)
Definition of Concat: \( \text{Concat}(a,b) \equiv a \cup \text{ShiftedSeq}(b,domain(a)) \)
theorem concat_props:

assumes \( n \in nat \), \( k \in nat \) and \( a:n\rightarrow X \), \( b:k\rightarrow X \)

shows \( \text{Concat}(a,b): n \ \sharp + k \rightarrow X \), \( \forall i\in n.\ \text{Concat}(a,b)(i) = a(i) \), \( \forall i \in Nat \text{Interval}(n,k).\ \text{Concat}(a,b)(i) = b(i \ \sharp - n) \), \( \forall j \in k.\ \text{Concat}(a,b)(n \ \sharp + j) = b(j) \)
lemma add_nat_le:

assumes \( n \in nat \) and \( k \in nat \)

shows \( n \leq n \ \sharp + k \), \( n \subseteq n \ \sharp + k \), \( n \subseteq k \ \sharp + n \)
lemma add_lt_mono:

assumes \( k \in nat \) and \( j\in k \)

shows \( (n \ \sharp + j) \lt (n \ \sharp + k) \), \( (n \ \sharp + j) \in (n \ \sharp + k) \)
lemma concat_concat_list:

assumes \( n \in nat \), \( k \in nat \), \( m \in nat \) and \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( c:m\rightarrow X \) and \( d = \text{Concat}( \text{Concat}(a,b),c) \)

shows \( d : n \ \sharp +k \ \sharp + m \rightarrow X \), \( \forall j \in n.\ d(j) = a(j) \), \( \forall j \in k.\ d(n \ \sharp + j) = b(j) \), \( \forall j \in m.\ d(n \ \sharp + k \ \sharp + j) = c(j) \)
lemma concat_list_concat:

assumes \( n \in nat \), \( k \in nat \), \( m \in nat \) and \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( c:m\rightarrow X \) and \( e = \text{Concat}(a, \text{Concat}(b,c)) \)

shows \( e : n \ \sharp +k \ \sharp + m \rightarrow X \), \( \forall j \in n.\ e(j) = a(j) \), \( \forall j \in k.\ e(n \ \sharp + j) = b(j) \), \( \forall j \in m.\ e(n \ \sharp + k \ \sharp + j) = c(j) \)
lemma adjacent_intervals3:

assumes \( n \in nat \), \( k \in nat \), \( m \in nat \)

shows \( n \ \sharp + k \ \sharp + m = (n \ \sharp + k) \cup Nat \text{Interval}(n \ \sharp + k,m) \), \( n \ \sharp + k \ \sharp + m = n \cup Nat \text{Interval}(n,k \ \sharp + m) \), \( n \ \sharp + k \ \sharp + m = n \cup Nat \text{Interval}(n,k) \cup Nat \text{Interval}(n \ \sharp + k,m) \)
lemma func_eq:

assumes \( f: X\rightarrow Y \), \( g: X\rightarrow Z \) and \( \forall x\in X.\ f(x) = g(x) \)

shows \( f = g \)
lemma succ_ineq:

assumes \( n \in nat \)

shows \( \forall i \in n.\ succ(i) \in succ(n) \)
Definition of Tail: \( \text{Tail}(a) \equiv \{\langle k, a(succ(k))\rangle .\ k \in pred(domain(a))\} \)
lemma ZF_fun_from_tot_val0:

assumes \( f:X\rightarrow Y \) and \( f = \{\langle x,b(x)\rangle .\ x\in X\} \)

shows \( \forall x\in X.\ f(x) = b(x) \)
Definition of Append: \( \text{Append}(a,x) \equiv a \cup \{\langle domain(a),x\rangle \} \)
lemma func1_1_L11D:

assumes \( f:X\rightarrow Y \) and \( a\notin X \) and \( g = f \cup \{\langle a,b\rangle \} \)

shows \( g : X\cup \{a\} \rightarrow Y\cup \{b\} \), \( \forall x\in X.\ g(x) = f(x) \), \( g(a) = b \)
lemma succ_explained: shows \( succ(n) = n \cup \{n\} \)
lemma set_elem_add:

assumes \( x\in X \)

shows \( X \cup \{x\} = X \)
theorem append_props:

assumes \( a: n \rightarrow X \) and \( x\in X \) and \( b = \text{Append}(a,x) \)

shows \( b : succ(n) \rightarrow X \), \( \forall k\in n.\ b(k) = a(k) \), \( b(n) = x \)
lemma empty_in_every_succ:

assumes \( n \in nat \)

shows \( 0 \in succ(n) \)
theorem tail_props:

assumes \( n \in nat \) and \( a: succ(n) \rightarrow X \)

shows \( \text{Tail}(a) : n \rightarrow X \), \( \forall k \in n.\ \text{Tail}(a)(k) = a(succ(k)) \)
Definition of Init: \( \text{Init}(a) \equiv \text{restrict}(a,pred(domain(a))) \)
theorem init_props:

assumes \( n \in nat \) and \( a: succ(n) \rightarrow X \)

shows \( \text{Init}(a) : n \rightarrow X \), \( \forall k\in n.\ \text{Init}(a)(k) = a(k) \), \( a = \text{Append}( \text{Init}(a), a(n)) \)
lemma bij_extend_point:

assumes \( f \in \text{bij}(X,Y) \), \( a\notin X \), \( b\notin Y \)

shows \( (f \cup \{\langle a,b\rangle \}) \in \text{bij}(X\cup \{a\},Y\cup \{b\}) \)
lemma func1_1_L1B:

assumes \( f:X\rightarrow Y \) and \( Y\subseteq Z \)

shows \( f:X\rightarrow Z \)
Definition of Last: \( \text{Last}(a) \equiv a(pred(domain(a))) \)
lemma pair_func_singleton:

assumes \( y \in Y \)

shows \( \{\langle x,y\rangle \} : \{x\} \rightarrow Y \)
theorem fun_is_set_of_pairs:

assumes \( f:X\rightarrow Y \)

shows \( f = \{\langle x, f(x)\rangle .\ x \in X\} \)
lemma list_len1_singleton:

assumes \( x\in X \)

shows \( \{\langle 0,x\rangle \} : 1 \rightarrow X \)
lemma append_1elem:

assumes \( n \in nat \) and \( a: n \rightarrow X \) and \( b : 1 \rightarrow X \)

shows \( \text{Concat}(a,b) = \text{Append}(a,b(0)) \)
lemma pair_val: shows \( \{\langle x,y\rangle \}(x) = y \)
lemma append_concat_pair:

assumes \( n \in nat \) and \( a: n \rightarrow X \) and \( x\in X \)

shows \( \text{Append}(a,x) = \text{Concat}(a,\{\langle 0,x\rangle \}) \)
theorem concat_assoc:

assumes \( n \in nat \), \( k \in nat \), \( m \in nat \) and \( a:n\rightarrow X \), \( b:k\rightarrow X \), \( c:m\rightarrow X \)

shows \( \text{Concat}( \text{Concat}(a,b),c) = \text{Concat}(a, \text{Concat}(b,c)) \)
lemma concat_append_assoc:

assumes \( n \in nat \), \( k \in nat \) and \( a:n\rightarrow X \), \( b:k\rightarrow X \) and \( x \in X \)

shows \( \text{Append}( \text{Concat}(a,b),x) = \text{Concat}(a, \text{Append}(b,x)) \)
Definition of NELists: \( \text{NELists}(X) \equiv \bigcup n\in nat.\ (succ(n)\rightarrow X) \)
theorem ind_on_nat:

assumes \( n\in nat \) and \( P(0) \) and \( \forall k\in nat.\ P(k)\longrightarrow P(succ(k)) \)

shows \( P(n) \)
lemma init_def:

assumes \( n \in nat \) and \( x:succ(n)\rightarrow X \)

shows \( \text{Init}(x) = \text{restrict}(x,n) \)
lemma finseq_restr_eq:

assumes \( n \in nat \) and \( a: succ(n) \rightarrow X \), \( b: succ(n) \rightarrow X \) and \( \text{restrict}(a,n) = \text{restrict}(b,n) \) and \( a(n) = b(n) \)

shows \( a = b \)
lemma init_append:

assumes \( n \in nat \) and \( a:n\rightarrow X \) and \( x \in X \)

shows \( \text{Init}( \text{Append}(a,x)) = a \)
lemma list_singleton_pair:

assumes \( x:1\rightarrow X \)

shows \( x = \{\langle 0,x(0)\rangle \} \)
lemma singleton_list_bij: shows \( \{\langle x,x(0)\rangle .\ x\in 1\rightarrow X\} \in \text{bij}(1\rightarrow X,X) \)
lemma func_singleton_pair:

assumes \( f : \{a\}\rightarrow X \)

shows \( f = \{\langle a, f(a)\rangle \} \)
lemma comp_conv_id:

assumes \( a \in \text{bij}(A,B) \) and \( b:B\rightarrow A \) and \( \forall x\in A.\ b(a(x)) = x \)

shows \( b \in \text{bij}(B,A) \) and \( a = converse(b) \) and \( b = converse(a) \)
305
166
69
69