1 (* Title: ZF/List_ZF.thy |
1 (* Title: ZF/List_ZF.thy |
2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 Copyright 1994 University of Cambridge |
3 Copyright 1994 University of Cambridge |
4 *) |
4 *) |
5 |
5 |
6 section{*Lists in Zermelo-Fraenkel Set Theory*} |
6 section\<open>Lists in Zermelo-Fraenkel Set Theory\<close> |
7 |
7 |
8 theory List_ZF imports Datatype_ZF ArithSimp begin |
8 theory List_ZF imports Datatype_ZF ArithSimp begin |
9 |
9 |
10 consts |
10 consts |
11 list :: "i=>i" |
11 list :: "i=>i" |
96 "take(n, as) == list_rec(\<lambda>n\<in>nat. [], |
96 "take(n, as) == list_rec(\<lambda>n\<in>nat. [], |
97 %a l r. \<lambda>n\<in>nat. nat_case([], %m. Cons(a, r`m), n), as)`n" |
97 %a l r. \<lambda>n\<in>nat. nat_case([], %m. Cons(a, r`m), n), as)`n" |
98 |
98 |
99 definition |
99 definition |
100 nth :: "[i, i]=>i" where |
100 nth :: "[i, i]=>i" where |
101 --{*returns the (n+1)th element of a list, or 0 if the |
101 --\<open>returns the (n+1)th element of a list, or 0 if the |
102 list is too short.*} |
102 list is too short.\<close> |
103 "nth(n, as) == list_rec(\<lambda>n\<in>nat. 0, |
103 "nth(n, as) == list_rec(\<lambda>n\<in>nat. 0, |
104 %a l r. \<lambda>n\<in>nat. nat_case(a, %m. r`m, n), as) ` n" |
104 %a l r. \<lambda>n\<in>nat. nat_case(a, %m. r`m, n), as) ` n" |
105 |
105 |
106 definition |
106 definition |
107 list_update :: "[i, i, i]=>i" where |
107 list_update :: "[i, i, i]=>i" where |
608 "xs:list(A) ==> \<forall>ys \<in> list(A). xs@[x] = ys@[y] \<longleftrightarrow> (xs = ys & x=y)" |
608 "xs:list(A) ==> \<forall>ys \<in> list(A). xs@[x] = ys@[y] \<longleftrightarrow> (xs = ys & x=y)" |
609 apply (erule list.induct) |
609 apply (erule list.induct) |
610 apply clarify |
610 apply clarify |
611 apply (erule list.cases) |
611 apply (erule list.cases) |
612 apply simp_all |
612 apply simp_all |
613 txt{*Inductive step*} |
613 txt\<open>Inductive step\<close> |
614 apply clarify |
614 apply clarify |
615 apply (erule_tac a=ys in list.cases, simp_all) |
615 apply (erule_tac a=ys in list.cases, simp_all) |
616 done |
616 done |
617 |
617 |
618 |
618 |
836 "l\<in>list(A) ==> \<forall>n\<in>nat. length(take(n,l)) = min(n, length(l))" |
836 "l\<in>list(A) ==> \<forall>n\<in>nat. length(take(n,l)) = min(n, length(l))" |
837 apply (induct_tac "l", safe, simp_all) |
837 apply (induct_tac "l", safe, simp_all) |
838 apply (erule natE, simp_all) |
838 apply (erule natE, simp_all) |
839 done |
839 done |
840 |
840 |
841 subsection{*The function zip*} |
841 subsection\<open>The function zip\<close> |
842 |
842 |
843 text{*Crafty definition to eliminate a type argument*} |
843 text\<open>Crafty definition to eliminate a type argument\<close> |
844 |
844 |
845 consts |
845 consts |
846 zip_aux :: "[i,i]=>i" |
846 zip_aux :: "[i,i]=>i" |
847 |
847 |
848 primrec (*explicit lambda is required because both arguments of "un" vary*) |
848 primrec (*explicit lambda is required because both arguments of "un" vary*) |
1225 "xs \<in> list(B) ==> sublist(xs, A \<inter> nat) = sublist(xs, A)" |
1225 "xs \<in> list(B) ==> sublist(xs, A \<inter> nat) = sublist(xs, A)" |
1226 apply (erule list.induct) |
1226 apply (erule list.induct) |
1227 apply (simp_all add: sublist_Cons) |
1227 apply (simp_all add: sublist_Cons) |
1228 done |
1228 done |
1229 |
1229 |
1230 text{*Repetition of a List Element*} |
1230 text\<open>Repetition of a List Element\<close> |
1231 |
1231 |
1232 consts repeat :: "[i,i]=>i" |
1232 consts repeat :: "[i,i]=>i" |
1233 primrec |
1233 primrec |
1234 "repeat(a,0) = []" |
1234 "repeat(a,0) = []" |
1235 |
1235 |