| author | wenzelm | 
| Thu, 28 Sep 2006 23:42:32 +0200 | |
| changeset 20767 | 9bc632ae588f | 
| parent 19736 | d8d0f8f51d69 | 
| child 20770 | 2c583720436e | 
| permissions | -rw-r--r-- | 
| 12169 | 1 | (* *********************************************************************** *) | 
| 2 | (* *) | |
| 3 | (* Title: SList.thy (Extended List Theory) *) | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 4 | (* Based on: $Id$ *) | 
| 12169 | 5 | (* Author: Lawrence C Paulson, Cambridge University Computer Laboratory*) | 
| 6 | (* Author: B. Wolff, University of Bremen *) | |
| 7 | (* Purpose: Enriched theory of lists *) | |
| 8 | (* mutual indirect recursive data-types *) | |
| 9 | (* *) | |
| 10 | (* *********************************************************************** *) | |
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 11 | |
| 12169 | 12 | (* Definition of type 'a list (strict lists) by a least fixed point | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 13 | |
| 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 14 | We use          list(A) == lfp(%Z. {NUMB(0)} <+> A <*> Z)
 | 
| 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 15 | and not         list    == lfp(%Z. {NUMB(0)} <+> range(Leaf) <*> Z)
 | 
| 12169 | 16 | |
| 17 | so that list can serve as a "functor" for defining other recursive types. | |
| 18 | ||
| 19 | This enables the conservative construction of mutual recursive data-types | |
| 20 | such as | |
| 21 | ||
| 22 | datatype 'a m = Node 'a * ('a m) list
 | |
| 23 | ||
| 24 | Tidied by lcp. Still needs removal of nat_rec. | |
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 25 | *) | 
| 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 26 | |
| 16417 | 27 | theory SList imports NatArith Sexp Hilbert_Choice begin | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 28 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 29 | (*Hilbert_Choice is needed for the function "inv"*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 30 | |
| 12169 | 31 | (* *********************************************************************** *) | 
| 32 | (* *) | |
| 33 | (* Building up data type *) | |
| 34 | (* *) | |
| 35 | (* *********************************************************************** *) | |
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 36 | |
| 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 37 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 38 | (* Defining the Concrete Constructors *) | 
| 19736 | 39 | definition | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 40 | NIL :: "'a item" | 
| 19736 | 41 | "NIL = In0(Numb(0))" | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 42 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 43 | CONS :: "['a item, 'a item] => 'a item" | 
| 19736 | 44 | "CONS M N = In1(Scons M N)" | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 45 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 46 | consts | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 47 | list :: "'a item set => 'a item set" | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 48 | inductive "list(A)" | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 49 | intros | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 50 | NIL_I: "NIL: list A" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 51 | CONS_I: "[| a: A; M: list A |] ==> CONS a M : list A" | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 52 | |
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 53 | |
| 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 54 | typedef (List) | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 55 | 'a list = "list(range Leaf) :: 'a item set" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 56 | by (blast intro: list.NIL_I) | 
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 57 | |
| 19736 | 58 | definition | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 59 | List_case :: "['b, ['a item, 'a item]=>'b, 'a item] => 'b" | 
| 19736 | 60 | "List_case c d = Case(%x. c)(Split(d))" | 
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 61 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 62 | List_rec :: "['a item, 'b, ['a item, 'a item, 'b]=>'b] => 'b" | 
| 19736 | 63 | "List_rec M c d = wfrec (trancl pred_sexp) | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 64 | (%g. List_case c (%x y. d x y (g y))) M" | 
| 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 65 | |
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 66 | |
| 12169 | 67 | (* *********************************************************************** *) | 
| 68 | (* *) | |
| 69 | (* Abstracting data type *) | |
| 70 | (* *) | |
| 71 | (* *********************************************************************** *) | |
| 72 | ||
| 73 | (*Declaring the abstract list constructors*) | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 74 | |
| 19736 | 75 | definition | 
| 12169 | 76 | Nil :: "'a list" | 
| 19736 | 77 | "Nil = Abs_List(NIL)" | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 78 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 79 | "Cons" :: "['a, 'a list] => 'a list" (infixr "#" 65) | 
| 19736 | 80 | "x#xs = Abs_List(CONS (Leaf x)(Rep_List xs))" | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 81 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 82 | (* list Recursion -- the trancl is Essential; see list.ML *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 83 | list_rec :: "['a list, 'b, ['a, 'a list, 'b]=>'b] => 'b" | 
| 19736 | 84 | "list_rec l c d = | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 85 | List_rec(Rep_List l) c (%x y r. d(inv Leaf x)(Abs_List y) r)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 86 | |
| 14653 | 87 | list_case :: "['b, ['a, 'a list]=>'b, 'a list] => 'b" | 
| 19736 | 88 | "list_case a f xs = list_rec xs a (%x xs r. f x xs)" | 
| 14653 | 89 | |
| 12169 | 90 | (* list Enumeration *) | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 91 | consts | 
| 12169 | 92 |   "[]"      :: "'a list"                            ("[]")
 | 
| 14765 | 93 | syntax | 
| 12169 | 94 |   "@list"   :: "args => 'a list"                    ("[(_)]")
 | 
| 95 | ||
| 96 | translations | |
| 97 | "[x, xs]" == "x#[xs]" | |
| 98 | "[x]" == "x#[]" | |
| 99 | "[]" == "Nil" | |
| 100 | ||
| 101 | "case xs of Nil => a | y#ys => b" == "list_case(a, %y ys. b, xs)" | |
| 102 | ||
| 103 | ||
| 104 | (* *********************************************************************** *) | |
| 105 | (* *) | |
| 106 | (* Generalized Map Functionals *) | |
| 107 | (* *) | |
| 108 | (* *********************************************************************** *) | |
| 109 | ||
| 110 | ||
| 111 | (* Generalized Map Functionals *) | |
| 112 | ||
| 19736 | 113 | definition | 
| 12169 | 114 |   Rep_map   :: "('b => 'a item) => ('b list => 'a item)"
 | 
| 19736 | 115 | "Rep_map f xs = list_rec xs NIL(%x l r. CONS(f x) r)" | 
| 12169 | 116 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 117 |   Abs_map   :: "('a item => 'b) => 'a item => 'b list"
 | 
| 19736 | 118 | "Abs_map g M = List_rec M Nil (%N L r. g(N)#r)" | 
| 12169 | 119 | |
| 120 | ||
| 121 | (**** Function definitions ****) | |
| 122 | ||
| 19736 | 123 | definition | 
| 12169 | 124 | |
| 125 | null :: "'a list => bool" | |
| 19736 | 126 | "null xs = list_rec xs True (%x xs r. False)" | 
| 12169 | 127 | |
| 128 | hd :: "'a list => 'a" | |
| 19736 | 129 | "hd xs = list_rec xs (@x. True) (%x xs r. x)" | 
| 12169 | 130 | |
| 131 | tl :: "'a list => 'a list" | |
| 19736 | 132 | "tl xs = list_rec xs (@xs. True) (%x xs r. xs)" | 
| 12169 | 133 | |
| 134 | (* a total version of tl: *) | |
| 135 | ttl :: "'a list => 'a list" | |
| 19736 | 136 | "ttl xs = list_rec xs [] (%x xs r. xs)" | 
| 12169 | 137 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 138 | member :: "['a, 'a list] => bool" (infixl "mem" 55) | 
| 19736 | 139 | "x mem xs = list_rec xs False (%y ys r. if y=x then True else r)" | 
| 12169 | 140 | |
| 141 |   list_all  :: "('a => bool) => ('a list => bool)"
 | |
| 19736 | 142 | "list_all P xs = list_rec xs True(%x l r. P(x) & r)" | 
| 12169 | 143 | |
| 144 |   map       :: "('a=>'b) => ('a list => 'b list)"
 | |
| 19736 | 145 | "map f xs = list_rec xs [] (%x l r. f(x)#r)" | 
| 12169 | 146 | |
| 147 | ||
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 148 | append :: "['a list, 'a list] => 'a list" (infixr "@" 65) | 
| 19736 | 149 | "xs@ys = list_rec xs ys (%x l r. x#r)" | 
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 150 | |
| 12169 | 151 | filter :: "['a => bool, 'a list] => 'a list" | 
| 19736 | 152 | "filter P xs = list_rec xs [] (%x xs r. if P(x)then x#r else r)" | 
| 12169 | 153 | |
| 154 | foldl :: "[['b,'a] => 'b, 'b, 'a list] => 'b" | |
| 19736 | 155 | "foldl f a xs = list_rec xs (%a. a)(%x xs r.%a. r(f a x))(a)" | 
| 12169 | 156 | |
| 157 | foldr :: "[['a,'b] => 'b, 'b, 'a list] => 'b" | |
| 19736 | 158 | "foldr f a xs = list_rec xs a (%x xs r. (f x r))" | 
| 12169 | 159 | |
| 160 | length :: "'a list => nat" | |
| 19736 | 161 | "length xs = list_rec xs 0 (%x xs r. Suc r)" | 
| 12169 | 162 | |
| 163 | drop :: "['a list,nat] => 'a list" | |
| 19736 | 164 | "drop t n = (nat_rec(%x. x)(%m r xs. r(ttl xs)))(n)(t)" | 
| 12169 | 165 | |
| 166 | copy :: "['a, nat] => 'a list" (* make list of n copies of x *) | |
| 19736 | 167 | "copy t = nat_rec [] (%m xs. t # xs)" | 
| 12169 | 168 | |
| 169 | flat :: "'a list list => 'a list" | |
| 19736 | 170 | "flat = foldr (op @) []" | 
| 12169 | 171 | |
| 172 | nth :: "[nat, 'a list] => 'a" | |
| 19736 | 173 | "nth = nat_rec hd (%m r xs. r(tl xs))" | 
| 12169 | 174 | |
| 175 | rev :: "'a list => 'a list" | |
| 19736 | 176 | "rev xs = list_rec xs [] (%x xs xsa. xsa @ [x])" | 
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 177 | |
| 12169 | 178 | (* miscellaneous definitions *) | 
| 179 | zipWith :: "['a * 'b => 'c, 'a list * 'b list] => 'c list" | |
| 19736 | 180 | "zipWith f S = (list_rec (fst S) (%T.[]) | 
| 12169 | 181 | (%x xs r. %T. if null T then [] | 
| 182 | else f(x,hd T) # r(tl T)))(snd(S))" | |
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 183 | |
| 14653 | 184 |   zip       :: "'a list * 'b list => ('a*'b) list"
 | 
| 19736 | 185 | "zip = zipWith (%s. s)" | 
| 14653 | 186 | |
| 12169 | 187 |   unzip     :: "('a*'b) list => ('a list * 'b list)"
 | 
| 19736 | 188 | "unzip = foldr(% (a,b)(c,d).(a#c,b#d))([],[])" | 
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 189 | |
| 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 190 | |
| 12169 | 191 | consts take :: "['a list,nat] => 'a list" | 
| 192 | primrec | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 193 | take_0: "take xs 0 = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 194 | take_Suc: "take xs (Suc n) = list_case [] (%x l. x # take l n) xs" | 
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 195 | |
| 12169 | 196 | consts enum :: "[nat,nat] => nat list" | 
| 197 | primrec | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 198 | enum_0: "enum i 0 = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 199 | enum_Suc: "enum i (Suc j) = (if i <= j then enum i j @ [j] else [])" | 
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 200 | |
| 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 201 | |
| 12169 | 202 | syntax | 
| 203 | (* Special syntax for list_all and filter *) | |
| 204 |   "@Alls"       :: "[idt, 'a list, bool] => bool"        ("(2Alls _:_./ _)" 10)
 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 205 |   "@filter"     :: "[idt, 'a list, bool] => 'a list"     ("(1[_:_ ./ _])")
 | 
| 12169 | 206 | |
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 207 | translations | 
| 12169 | 208 | "[x:xs. P]" == "filter(%x. P) xs" | 
| 209 | "Alls x:xs. P"== "list_all(%x. P)xs" | |
| 5977 
9f0c8869cf71
tidied up list definitions, using type 'a option instead of
 paulson parents: 
5191diff
changeset | 210 | |
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 211 | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 212 | lemma ListI: "x : list (range Leaf) ==> x : List" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 213 | by (simp add: List_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 214 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 215 | lemma ListD: "x : List ==> x : list (range Leaf)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 216 | by (simp add: List_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 217 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 218 | lemma list_unfold: "list(A) = usum {Numb(0)} (uprod A (list(A)))"
 | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 219 | by (fast intro!: list.intros [unfolded NIL_def CONS_def] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 220 | elim: list.cases [unfolded NIL_def CONS_def]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 221 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 222 | (*This justifies using list in other recursive type definitions*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 223 | lemma list_mono: "A<=B ==> list(A) <= list(B)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 224 | apply (unfold list.defs ) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 225 | apply (rule lfp_mono) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 226 | apply (assumption | rule basic_monos)+ | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 227 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 228 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 229 | (*Type checking -- list creates well-founded sets*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 230 | lemma list_sexp: "list(sexp) <= sexp" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 231 | apply (unfold NIL_def CONS_def list.defs) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 232 | apply (rule lfp_lowerbound) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 233 | apply (fast intro: sexp.intros sexp_In0I sexp_In1I) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 234 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 235 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 236 | (* A <= sexp ==> list(A) <= sexp *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 237 | lemmas list_subset_sexp = subset_trans [OF list_mono list_sexp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 238 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 239 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 240 | (*Induction for the type 'a list *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 241 | lemma list_induct: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 242 | "[| P(Nil); | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 243 | !!x xs. P(xs) ==> P(x # xs) |] ==> P(l)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 244 | apply (unfold Nil_def Cons_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 245 | apply (rule Rep_List_inverse [THEN subst]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 246 | (*types force good instantiation*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 247 | apply (rule Rep_List [unfolded List_def, THEN list.induct], simp) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 248 | apply (erule Abs_List_inverse [unfolded List_def, THEN subst], blast) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 249 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 250 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 251 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 252 | (*** Isomorphisms ***) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 253 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 254 | lemma inj_on_Abs_list: "inj_on Abs_List (list(range Leaf))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 255 | apply (rule inj_on_inverseI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 256 | apply (erule Abs_List_inverse [unfolded List_def]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 257 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 258 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 259 | (** Distinctness of constructors **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 260 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 261 | lemma CONS_not_NIL [iff]: "CONS M N ~= NIL" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 262 | by (simp add: NIL_def CONS_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 263 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 264 | lemmas NIL_not_CONS [iff] = CONS_not_NIL [THEN not_sym] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 265 | lemmas CONS_neq_NIL = CONS_not_NIL [THEN notE, standard] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 266 | lemmas NIL_neq_CONS = sym [THEN CONS_neq_NIL] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 267 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 268 | lemma Cons_not_Nil [iff]: "x # xs ~= Nil" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 269 | apply (unfold Nil_def Cons_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 270 | apply (rule CONS_not_NIL [THEN inj_on_Abs_list [THEN inj_on_contraD]]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 271 | apply (simp_all add: list.intros rangeI Rep_List [unfolded List_def]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 272 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 273 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 274 | lemmas Nil_not_Cons [iff] = Cons_not_Nil [THEN not_sym, standard] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 275 | lemmas Cons_neq_Nil = Cons_not_Nil [THEN notE, standard] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 276 | lemmas Nil_neq_Cons = sym [THEN Cons_neq_Nil] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 277 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 278 | (** Injectiveness of CONS and Cons **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 279 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 280 | lemma CONS_CONS_eq [iff]: "(CONS K M)=(CONS L N) = (K=L & M=N)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 281 | by (simp add: CONS_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 282 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 283 | (*For reasoning about abstract list constructors*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 284 | declare Rep_List [THEN ListD, intro] ListI [intro] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 285 | declare list.intros [intro,simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 286 | declare Leaf_inject [dest!] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 287 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 288 | lemma Cons_Cons_eq [iff]: "(x#xs=y#ys) = (x=y & xs=ys)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 289 | apply (simp add: Cons_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 290 | apply (subst Abs_List_inject) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 291 | apply (auto simp add: Rep_List_inject) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 292 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 293 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 294 | lemmas Cons_inject2 = Cons_Cons_eq [THEN iffD1, THEN conjE, standard] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 295 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 296 | lemma CONS_D: "CONS M N: list(A) ==> M: A & N: list(A)" | 
| 18413 | 297 | by (induct L == "CONS M N" set: list) auto | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 298 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 299 | lemma sexp_CONS_D: "CONS M N: sexp ==> M: sexp & N: sexp" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 300 | apply (simp add: CONS_def In1_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 301 | apply (fast dest!: Scons_D) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 302 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 303 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 304 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 305 | (*Reasoning about constructors and their freeness*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 306 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 307 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 308 | lemma not_CONS_self: "N: list(A) ==> !M. N ~= CONS M N" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 309 | by (erule list.induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 310 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 311 | lemma not_Cons_self2: "\<forall>x. l ~= x#l" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 312 | by (induct_tac "l" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 313 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 314 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 315 | lemma neq_Nil_conv2: "(xs ~= []) = (\<exists>y ys. xs = y#ys)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 316 | by (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 317 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 318 | (** Conversion rules for List_case: case analysis operator **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 319 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 320 | lemma List_case_NIL [simp]: "List_case c h NIL = c" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 321 | by (simp add: List_case_def NIL_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 322 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 323 | lemma List_case_CONS [simp]: "List_case c h (CONS M N) = h M N" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 324 | by (simp add: List_case_def CONS_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 325 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 326 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 327 | (*** List_rec -- by wf recursion on pred_sexp ***) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 328 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 329 | (* The trancl(pred_sexp) is essential because pred_sexp_CONS_I1,2 would not | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 330 | hold if pred_sexp^+ were changed to pred_sexp. *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 331 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 332 | lemma List_rec_unfold_lemma: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 333 | "(%M. List_rec M c d) == | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 334 | wfrec (trancl pred_sexp) (%g. List_case c (%x y. d x y (g y)))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 335 | by (simp add: List_rec_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 336 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 337 | lemmas List_rec_unfold = | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 338 | def_wfrec [OF List_rec_unfold_lemma wf_pred_sexp [THEN wf_trancl], | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 339 | standard] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 340 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 341 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 342 | (** pred_sexp lemmas **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 343 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 344 | lemma pred_sexp_CONS_I1: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 345 | "[| M: sexp; N: sexp |] ==> (M, CONS M N) : pred_sexp^+" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 346 | by (simp add: CONS_def In1_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 347 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 348 | lemma pred_sexp_CONS_I2: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 349 | "[| M: sexp; N: sexp |] ==> (N, CONS M N) : pred_sexp^+" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 350 | by (simp add: CONS_def In1_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 351 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 352 | lemma pred_sexp_CONS_D: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 353 | "(CONS M1 M2, N) : pred_sexp^+ ==> | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 354 | (M1,N) : pred_sexp^+ & (M2,N) : pred_sexp^+" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 355 | apply (frule pred_sexp_subset_Sigma [THEN trancl_subset_Sigma, THEN subsetD]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 356 | apply (blast dest!: sexp_CONS_D intro: pred_sexp_CONS_I1 pred_sexp_CONS_I2 | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 357 | trans_trancl [THEN transD]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 358 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 359 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 360 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 361 | (** Conversion rules for List_rec **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 362 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 363 | lemma List_rec_NIL [simp]: "List_rec NIL c h = c" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 364 | apply (rule List_rec_unfold [THEN trans]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 365 | apply (simp add: List_case_NIL) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 366 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 367 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 368 | lemma List_rec_CONS [simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 369 | "[| M: sexp; N: sexp |] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 370 | ==> List_rec (CONS M N) c h = h M N (List_rec N c h)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 371 | apply (rule List_rec_unfold [THEN trans]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 372 | apply (simp add: pred_sexp_CONS_I2) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 373 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 374 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 375 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 376 | (*** list_rec -- by List_rec ***) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 377 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 378 | lemmas Rep_List_in_sexp = | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 379 | subsetD [OF range_Leaf_subset_sexp [THEN list_subset_sexp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 380 | Rep_List [THEN ListD]] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 381 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 382 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 383 | lemma list_rec_Nil [simp]: "list_rec Nil c h = c" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 384 | by (simp add: list_rec_def ListI [THEN Abs_List_inverse] Nil_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 385 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 386 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 387 | lemma list_rec_Cons [simp]: "list_rec (a#l) c h = h a l (list_rec l c h)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 388 | by (simp add: list_rec_def ListI [THEN Abs_List_inverse] Cons_def | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 389 | Rep_List_inverse Rep_List [THEN ListD] inj_Leaf Rep_List_in_sexp) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 390 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 391 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 392 | (*Type checking. Useful?*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 393 | lemma List_rec_type: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 394 | "[| M: list(A); | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 395 | A<=sexp; | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 396 | c: C(NIL); | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 397 | !!x y r. [| x: A; y: list(A); r: C(y) |] ==> h x y r: C(CONS x y) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 398 | |] ==> List_rec M c h : C(M :: 'a item)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 399 | apply (erule list.induct, simp) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 400 | apply (insert list_subset_sexp) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 401 | apply (subst List_rec_CONS, blast+) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 402 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 403 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 404 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 405 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 406 | (** Generalized map functionals **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 407 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 408 | lemma Rep_map_Nil [simp]: "Rep_map f Nil = NIL" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 409 | by (simp add: Rep_map_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 410 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 411 | lemma Rep_map_Cons [simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 412 | "Rep_map f(x#xs) = CONS(f x)(Rep_map f xs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 413 | by (simp add: Rep_map_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 414 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 415 | lemma Rep_map_type: "(!!x. f(x): A) ==> Rep_map f xs: list(A)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 416 | apply (simp add: Rep_map_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 417 | apply (rule list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 418 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 419 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 420 | lemma Abs_map_NIL [simp]: "Abs_map g NIL = Nil" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 421 | by (simp add: Abs_map_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 422 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 423 | lemma Abs_map_CONS [simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 424 | "[| M: sexp; N: sexp |] ==> Abs_map g (CONS M N) = g(M) # Abs_map g N" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 425 | by (simp add: Abs_map_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 426 | |
| 19736 | 427 | (*Eases the use of primitive recursion.*) | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 428 | lemma def_list_rec_NilCons: | 
| 19736 | 429 | "[| !!xs. f(xs) = list_rec xs c h |] | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 430 | ==> f [] = c & f(x#xs) = h x xs (f xs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 431 | by simp | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 432 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 433 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 434 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 435 | lemma Abs_map_inverse: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 436 | "[| M: list(A); A<=sexp; !!z. z: A ==> f(g(z)) = z |] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 437 | ==> Rep_map f (Abs_map g M) = M" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 438 | apply (erule list.induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 439 | apply (insert list_subset_sexp) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 440 | apply (subst Abs_map_CONS, blast) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 441 | apply blast | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 442 | apply simp | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 443 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 444 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 445 | (*Rep_map_inverse is obtained via Abs_Rep_map and map_ident*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 446 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 447 | (** list_case **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 448 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 449 | (* setting up rewrite sets *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 450 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 451 | text{*Better to have a single theorem with a conjunctive conclusion.*}
 | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 452 | declare def_list_rec_NilCons [OF list_case_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 453 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 454 | (** list_case **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 455 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 456 | lemma expand_list_case: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 457 | "P(list_case a f xs) = ((xs=[] --> P a ) & (!y ys. xs=y#ys --> P(f y ys)))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 458 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 459 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 460 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 461 | (**** Function definitions ****) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 462 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 463 | declare def_list_rec_NilCons [OF null_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 464 | declare def_list_rec_NilCons [OF hd_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 465 | declare def_list_rec_NilCons [OF tl_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 466 | declare def_list_rec_NilCons [OF ttl_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 467 | declare def_list_rec_NilCons [OF append_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 468 | declare def_list_rec_NilCons [OF member_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 469 | declare def_list_rec_NilCons [OF map_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 470 | declare def_list_rec_NilCons [OF filter_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 471 | declare def_list_rec_NilCons [OF list_all_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 472 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 473 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 474 | (** nth **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 475 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 476 | lemma def_nat_rec_0_eta: | 
| 19736 | 477 | "[| !!n. f = nat_rec c h |] ==> f(0) = c" | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 478 | by simp | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 479 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 480 | lemma def_nat_rec_Suc_eta: | 
| 19736 | 481 | "[| !!n. f = nat_rec c h |] ==> f(Suc(n)) = h n (f n)" | 
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 482 | by simp | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 483 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 484 | declare def_nat_rec_0_eta [OF nth_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 485 | declare def_nat_rec_Suc_eta [OF nth_def, simp] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 486 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 487 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 488 | (** length **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 489 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 490 | lemma length_Nil [simp]: "length([]) = 0" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 491 | by (simp add: length_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 492 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 493 | lemma length_Cons [simp]: "length(a#xs) = Suc(length(xs))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 494 | by (simp add: length_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 495 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 496 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 497 | (** @ - append **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 498 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 499 | lemma append_assoc [simp]: "(xs@ys)@zs = xs@(ys@zs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 500 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 501 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 502 | lemma append_Nil2 [simp]: "xs @ [] = xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 503 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 504 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 505 | (** mem **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 506 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 507 | lemma mem_append [simp]: "x mem (xs@ys) = (x mem xs | x mem ys)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 508 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 509 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 510 | lemma mem_filter [simp]: "x mem [x:xs. P x ] = (x mem xs & P(x))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 511 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 512 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 513 | (** list_all **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 514 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 515 | lemma list_all_True [simp]: "(Alls x:xs. True) = True" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 516 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 517 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 518 | lemma list_all_conj [simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 519 | "list_all p (xs@ys) = ((list_all p xs) & (list_all p ys))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 520 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 521 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 522 | lemma list_all_mem_conv: "(Alls x:xs. P(x)) = (!x. x mem xs --> P(x))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 523 | apply (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 524 | apply blast | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 525 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 526 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 527 | lemma nat_case_dist : "(! n. P n) = (P 0 & (! n. P (Suc n)))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 528 | apply auto | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 529 | apply (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 530 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 531 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 532 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 533 | lemma alls_P_eq_P_nth: "(Alls u:A. P u) = (!n. n < length A --> P(nth n A))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 534 | apply (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 535 | apply (rule trans) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 536 | apply (rule_tac [2] nat_case_dist [symmetric], simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 537 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 538 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 539 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 540 | lemma list_all_imp: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 541 | "[| !x. P x --> Q x; (Alls x:xs. P(x)) |] ==> (Alls x:xs. Q(x))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 542 | by (simp add: list_all_mem_conv) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 543 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 544 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 545 | (** The functional "map" and the generalized functionals **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 546 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 547 | lemma Abs_Rep_map: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 548 | "(!!x. f(x): sexp) ==> | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 549 | Abs_map g (Rep_map f xs) = map (%t. g(f(t))) xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 550 | apply (induct_tac "xs" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 551 | apply (simp_all add: Rep_map_type list_sexp [THEN subsetD]) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 552 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 553 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 554 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 555 | (** Additional mapping lemmas **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 556 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 557 | lemma map_ident [simp]: "map(%x. x)(xs) = xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 558 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 559 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 560 | lemma map_append [simp]: "map f (xs@ys) = map f xs @ map f ys" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 561 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 562 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 563 | lemma map_compose: "map(f o g)(xs) = map f (map g xs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 564 | apply (simp add: o_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 565 | apply (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 566 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 567 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 568 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 569 | lemma mem_map_aux1 [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 570 | "x mem (map f q) --> (\<exists>y. y mem q & x = f y)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 571 | by (induct_tac "q" rule: list_induct, simp_all, blast) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 572 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 573 | lemma mem_map_aux2 [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 574 | "(\<exists>y. y mem q & x = f y) --> x mem (map f q)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 575 | by (induct_tac "q" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 576 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 577 | lemma mem_map: "x mem (map f q) = (\<exists>y. y mem q & x = f y)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 578 | apply (rule iffI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 579 | apply (erule mem_map_aux1) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 580 | apply (erule mem_map_aux2) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 581 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 582 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 583 | lemma hd_append [rule_format]: "A ~= [] --> hd(A @ B) = hd(A)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 584 | by (induct_tac "A" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 585 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 586 | lemma tl_append [rule_format]: "A ~= [] --> tl(A @ B) = tl(A) @ B" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 587 | by (induct_tac "A" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 588 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 589 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 590 | (** take **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 591 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 592 | lemma take_Suc1 [simp]: "take [] (Suc x) = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 593 | by simp | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 594 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 595 | lemma take_Suc2 [simp]: "take(a#xs)(Suc x) = a#take xs x" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 596 | by simp | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 597 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 598 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 599 | (** drop **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 600 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 601 | lemma drop_0 [simp]: "drop xs 0 = xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 602 | by (simp add: drop_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 603 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 604 | lemma drop_Suc1 [simp]: "drop [] (Suc x) = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 605 | apply (simp add: drop_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 606 | apply (induct_tac "x", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 607 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 608 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 609 | lemma drop_Suc2 [simp]: "drop(a#xs)(Suc x) = drop xs x" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 610 | by (simp add: drop_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 611 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 612 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 613 | (** copy **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 614 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 615 | lemma copy_0 [simp]: "copy x 0 = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 616 | by (simp add: copy_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 617 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 618 | lemma copy_Suc [simp]: "copy x (Suc y) = x # copy x y" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 619 | by (simp add: copy_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 620 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 621 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 622 | (** fold **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 623 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 624 | lemma foldl_Nil [simp]: "foldl f a [] = a" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 625 | by (simp add: foldl_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 626 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 627 | lemma foldl_Cons [simp]: "foldl f a(x#xs) = foldl f (f a x) xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 628 | by (simp add: foldl_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 629 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 630 | lemma foldr_Nil [simp]: "foldr f a [] = a" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 631 | by (simp add: foldr_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 632 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 633 | lemma foldr_Cons [simp]: "foldr f z(x#xs) = f x (foldr f z xs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 634 | by (simp add: foldr_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 635 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 636 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 637 | (** flat **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 638 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 639 | lemma flat_Nil [simp]: "flat [] = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 640 | by (simp add: flat_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 641 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 642 | lemma flat_Cons [simp]: "flat (x # xs) = x @ flat xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 643 | by (simp add: flat_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 644 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 645 | (** rev **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 646 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 647 | lemma rev_Nil [simp]: "rev [] = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 648 | by (simp add: rev_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 649 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 650 | lemma rev_Cons [simp]: "rev (x # xs) = rev xs @ [x]" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 651 | by (simp add: rev_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 652 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 653 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 654 | (** zip **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 655 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 656 | lemma zipWith_Cons_Cons [simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 657 | "zipWith f (a#as,b#bs) = f(a,b) # zipWith f (as,bs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 658 | by (simp add: zipWith_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 659 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 660 | lemma zipWith_Nil_Nil [simp]: "zipWith f ([],[]) = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 661 | by (simp add: zipWith_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 662 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 663 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 664 | lemma zipWith_Cons_Nil [simp]: "zipWith f (x,[]) = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 665 | apply (simp add: zipWith_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 666 | apply (induct_tac "x" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 667 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 668 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 669 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 670 | lemma zipWith_Nil_Cons [simp]: "zipWith f ([],x) = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 671 | by (simp add: zipWith_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 672 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 673 | lemma unzip_Nil [simp]: "unzip [] = ([],[])" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 674 | by (simp add: unzip_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 675 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 676 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 677 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 678 | (** SOME LIST THEOREMS **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 679 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 680 | (* SQUIGGOL LEMMAS *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 681 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 682 | lemma map_compose_ext: "map(f o g) = ((map f) o (map g))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 683 | apply (simp add: o_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 684 | apply (rule ext) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 685 | apply (simp add: map_compose [symmetric] o_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 686 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 687 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 688 | lemma map_flat: "map f (flat S) = flat(map (map f) S)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 689 | by (induct_tac "S" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 690 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 691 | lemma list_all_map_eq: "(Alls u:xs. f(u) = g(u)) --> map f xs = map g xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 692 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 693 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 694 | lemma filter_map_d: "filter p (map f xs) = map f (filter(p o f)(xs))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 695 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 696 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 697 | lemma filter_compose: "filter p (filter q xs) = filter(%x. p x & q x) xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 698 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 699 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 700 | (* "filter(p, filter(q,xs)) = filter(q, filter(p,xs))", | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 701 | "filter(p, filter(p,xs)) = filter(p,xs)" BIRD's thms.*) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 702 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 703 | lemma filter_append [rule_format, simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 704 | "\<forall>B. filter p (A @ B) = (filter p A @ filter p B)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 705 | by (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 706 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 707 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 708 | (* inits(xs) == map(fst,splits(xs)), | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 709 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 710 | splits([]) = [] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 711 | splits(a # xs) = <[],xs> @ map(%x. <a # fst(x),snd(x)>, splits(xs)) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 712 | (x @ y = z) = <x,y> mem splits(z) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 713 | x mem xs & y mem ys = <x,y> mem diag(xs,ys) *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 714 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 715 | lemma length_append: "length(xs@ys) = length(xs)+length(ys)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 716 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 717 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 718 | lemma length_map: "length(map f xs) = length(xs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 719 | by (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 720 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 721 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 722 | lemma take_Nil [simp]: "take [] n = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 723 | by (induct_tac "n", simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 724 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 725 | lemma take_take_eq [simp]: "\<forall>n. take (take xs n) n = take xs n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 726 | apply (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 727 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 728 | apply (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 729 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 730 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 731 | lemma take_take_Suc_eq1 [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 732 | "\<forall>n. take (take xs(Suc(n+m))) n = take xs n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 733 | apply (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 734 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 735 | apply (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 736 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 737 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 738 | declare take_Suc [simp del] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 739 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 740 | lemma take_take_1: "take (take xs (n+m)) n = take xs n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 741 | apply (induct_tac "m") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 742 | apply (simp_all add: take_take_Suc_eq1) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 743 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 744 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 745 | lemma take_take_Suc_eq2 [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 746 | "\<forall>n. take (take xs n)(Suc(n+m)) = take xs n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 747 | apply (induct_tac "xs" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 748 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 749 | apply (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 750 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 751 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 752 | lemma take_take_2: "take(take xs n)(n+m) = take xs n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 753 | apply (induct_tac "m") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 754 | apply (simp_all add: take_take_Suc_eq2) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 755 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 756 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 757 | (* length(take(xs,n)) = min(n, length(xs)) *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 758 | (* length(drop(xs,n)) = length(xs) - n *) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 759 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 760 | lemma drop_Nil [simp]: "drop [] n = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 761 | by (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 762 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 763 | lemma drop_drop [rule_format]: "\<forall>xs. drop (drop xs m) n = drop xs(m+n)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 764 | apply (induct_tac "m", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 765 | apply (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 766 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 767 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 768 | lemma take_drop [rule_format]: "\<forall>xs. (take xs n) @ (drop xs n) = xs" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 769 | apply (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 770 | apply (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 771 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 772 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 773 | lemma copy_copy: "copy x n @ copy x m = copy x (n+m)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 774 | by (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 775 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 776 | lemma length_copy: "length(copy x n) = n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 777 | by (induct_tac "n", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 778 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 779 | lemma length_take [rule_format, simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 780 | "\<forall>xs. length(take xs n) = min (length xs) n" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 781 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 782 | apply auto | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 783 | apply (induct_tac "xs" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 784 | apply auto | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 785 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 786 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 787 | lemma length_take_drop: "length(take A k) + length(drop A k) = length(A)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 788 | by (simp only: length_append [symmetric] take_drop) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 789 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 790 | lemma take_append [rule_format]: "\<forall>A. length(A) = n --> take(A@B) n = A" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 791 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 792 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 793 | apply (rule_tac [2] allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 794 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 795 | apply (induct_tac [3] "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 796 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 797 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 798 | lemma take_append2 [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 799 | "\<forall>A. length(A) = n --> take(A@B) (n+k) = A @ take B k" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 800 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 801 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 802 | apply (rule_tac [2] allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 803 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 804 | apply (induct_tac [3] "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 805 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 806 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 807 | lemma take_map [rule_format]: "\<forall>n. take (map f A) n = map f (take A n)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 808 | apply (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 809 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 810 | apply (induct_tac "n", simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 811 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 812 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 813 | lemma drop_append [rule_format]: "\<forall>A. length(A) = n --> drop(A@B)n = B" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 814 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 815 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 816 | apply (rule_tac [2] allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 817 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 818 | apply (induct_tac [3] "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 819 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 820 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 821 | lemma drop_append2 [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 822 | "\<forall>A. length(A) = n --> drop(A@B)(n+k) = drop B k" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 823 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 824 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 825 | apply (rule_tac [2] allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 826 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 827 | apply (induct_tac [3] "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 828 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 829 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 830 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 831 | lemma drop_all [rule_format]: "\<forall>A. length(A) = n --> drop A n = []" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 832 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 833 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 834 | apply (rule_tac [2] allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 835 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 836 | apply (induct_tac [3] "A" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 837 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 838 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 839 | lemma drop_map [rule_format]: "\<forall>n. drop (map f A) n = map f (drop A n)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 840 | apply (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 841 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 842 | apply (induct_tac "n", simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 843 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 844 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 845 | lemma take_all [rule_format]: "\<forall>A. length(A) = n --> take A n = A" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 846 | apply (induct_tac "n") | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 847 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 848 | apply (rule_tac [2] allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 849 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 850 | apply (induct_tac [3] "A" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 851 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 852 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 853 | lemma foldl_single: "foldl f a [b] = f a b" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 854 | by simp_all | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 855 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 856 | lemma foldl_append [rule_format, simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 857 | "\<forall>a. foldl f a (A @ B) = foldl f (foldl f a A) B" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 858 | by (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 859 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 860 | lemma foldl_map [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 861 | "\<forall>e. foldl f e (map g S) = foldl (%x y. f x (g y)) e S" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 862 | by (induct_tac "S" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 863 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 864 | lemma foldl_neutr_distr [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 865 | assumes r_neutr: "\<forall>a. f a e = a" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 866 | and r_neutl: "\<forall>a. f e a = a" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 867 | and assoc: "\<forall>a b c. f a (f b c) = f(f a b) c" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 868 | shows "\<forall>y. f y (foldl f e A) = foldl f y A" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 869 | apply (induct_tac "A" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 870 | apply (simp_all add: r_neutr r_neutl, clarify) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 871 | apply (erule all_dupE) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 872 | apply (rule trans) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 873 | prefer 2 apply assumption | 
| 13612 | 874 | apply (simp (no_asm_use) add: assoc [THEN spec, THEN spec, THEN spec, THEN sym]) | 
| 875 | apply simp | |
| 13079 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 876 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 877 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 878 | lemma foldl_append_sym: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 879 | "[| !a. f a e = a; !a. f e a = a; | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 880 | !a b c. f a (f b c) = f(f a b) c |] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 881 | ==> foldl f e (A @ B) = f(foldl f e A)(foldl f e B)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 882 | apply (rule trans) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 883 | apply (rule foldl_append) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 884 | apply (rule sym) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 885 | apply (rule foldl_neutr_distr, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 886 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 887 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 888 | lemma foldr_append [rule_format, simp]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 889 | "\<forall>a. foldr f a (A @ B) = foldr f (foldr f a B) A" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 890 | apply (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 891 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 892 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 893 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 894 | lemma foldr_map [rule_format]: "\<forall>e. foldr f e (map g S) = foldr (f o g) e S" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 895 | apply (simp add: o_def) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 896 | apply (induct_tac "S" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 897 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 898 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 899 | lemma foldr_Un_eq_UN: "foldr op Un {} S = (UN X: {t. t mem S}.X)"
 | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 900 | by (induct_tac "S" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 901 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 902 | lemma foldr_neutr_distr: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 903 | "[| !a. f e a = a; !a b c. f a (f b c) = f(f a b) c |] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 904 | ==> foldr f y S = f (foldr f e S) y" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 905 | by (induct_tac "S" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 906 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 907 | lemma foldr_append2: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 908 | "[| !a. f e a = a; !a b c. f a (f b c) = f(f a b) c |] | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 909 | ==> foldr f e (A @ B) = f (foldr f e A) (foldr f e B)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 910 | apply auto | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 911 | apply (rule foldr_neutr_distr, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 912 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 913 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 914 | lemma foldr_flat: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 915 | "[| !a. f e a = a; !a b c. f a (f b c) = f(f a b) c |] ==> | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 916 | foldr f e (flat S) = (foldr f e)(map (foldr f e) S)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 917 | apply (induct_tac "S" rule: list_induct) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 918 | apply (simp_all del: foldr_append add: foldr_append2) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 919 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 920 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 921 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 922 | lemma list_all_map: "(Alls x:map f xs .P(x)) = (Alls x:xs.(P o f)(x))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 923 | by (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 924 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 925 | lemma list_all_and: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 926 | "(Alls x:xs. P(x)&Q(x)) = ((Alls x:xs. P(x))&(Alls x:xs. Q(x)))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 927 | by (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 928 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 929 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 930 | lemma nth_map [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 931 | "\<forall>i. i < length(A) --> nth i (map f A) = f(nth i A)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 932 | apply (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 933 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 934 | apply (induct_tac "i", auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 935 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 936 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 937 | lemma nth_app_cancel_right [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 938 | "\<forall>i. i < length(A) --> nth i(A@B) = nth i A" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 939 | apply (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 940 | apply (rule allI) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 941 | apply (induct_tac "i", simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 942 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 943 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 944 | lemma nth_app_cancel_left [rule_format]: | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 945 | "\<forall>n. n = length(A) --> nth(n+i)(A@B) = nth i B" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 946 | by (induct_tac "A" rule: list_induct, simp_all) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 947 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 948 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 949 | (** flat **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 950 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 951 | lemma flat_append [simp]: "flat(xs@ys) = flat(xs) @ flat(ys)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 952 | by (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 953 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 954 | lemma filter_flat: "filter p (flat S) = flat(map (filter p) S)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 955 | by (induct_tac "S" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 956 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 957 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 958 | (** rev **) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 959 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 960 | lemma rev_append [simp]: "rev(xs@ys) = rev(ys) @ rev(xs)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 961 | by (induct_tac "xs" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 962 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 963 | lemma rev_rev_ident [simp]: "rev(rev l) = l" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 964 | by (induct_tac "l" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 965 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 966 | lemma rev_flat: "rev(flat ls) = flat (map rev (rev ls))" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 967 | by (induct_tac "ls" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 968 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 969 | lemma rev_map_distrib: "rev(map f l) = map f (rev l)" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 970 | by (induct_tac "l" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 971 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 972 | lemma foldl_rev: "foldl f b (rev l) = foldr (%x y. f y x) b l" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 973 | by (induct_tac "l" rule: list_induct, auto) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 974 | |
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 975 | lemma foldr_rev: "foldr f b (rev l) = foldl (%x y. f y x) b l" | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 976 | apply (rule sym) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 977 | apply (rule trans) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 978 | apply (rule_tac [2] foldl_rev, simp) | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 979 | done | 
| 
e7738aa7267f
conversion of Induct/{Slist,Sexp} to Isar scripts
 paulson parents: 
12169diff
changeset | 980 | |
| 3120 
c58423c20740
New directory to contain examples of (co)inductive definitions
 paulson parents: diff
changeset | 981 | end |