author | berghofe |
Mon, 21 Jan 2002 14:43:38 +0100 | |
changeset 12822 | 073116d65bb9 |
parent 12789 | 459b5de466b2 |
child 12825 | f1f7964ed05c |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/List.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
Datatype definition of Lists |
|
7 |
*) |
|
8 |
||
516 | 9 |
(*** Aspects of the datatype definition ***) |
0 | 10 |
|
11 |
(*An elimination rule, for type-checking*) |
|
9907 | 12 |
bind_thm ("ConsE", list.mk_cases "Cons(a,l) : list(A)"); |
0 | 13 |
|
14 |
(*Proving freeness results*) |
|
9907 | 15 |
bind_thm ("Cons_iff", list.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'"); |
16 |
bind_thm ("Nil_Cons_iff", list.mk_free "~ Nil=Cons(a,l)"); |
|
0 | 17 |
|
5067 | 18 |
Goal "list(A) = {0} + (A * list(A))"; |
12789 | 19 |
by (blast_tac (claset() addSIs (map (rewrite_rule list.con_defs) list.intrs) |
20 |
addEs [rewrite_rule list.con_defs list.elim]) 1); |
|
760 | 21 |
qed "list_unfold"; |
435 | 22 |
|
0 | 23 |
(** Lemmas to justify using "list" in other recursive type definitions **) |
24 |
||
5137 | 25 |
Goalw list.defs "A<=B ==> list(A) <= list(B)"; |
0 | 26 |
by (rtac lfp_mono 1); |
516 | 27 |
by (REPEAT (rtac list.bnd_mono 1)); |
0 | 28 |
by (REPEAT (ares_tac (univ_mono::basic_monos) 1)); |
760 | 29 |
qed "list_mono"; |
0 | 30 |
|
31 |
(*There is a similar proof by list induction.*) |
|
5067 | 32 |
Goalw (list.defs@list.con_defs) "list(univ(A)) <= univ(A)"; |
0 | 33 |
by (rtac lfp_lowerbound 1); |
34 |
by (rtac (A_subset_univ RS univ_mono) 2); |
|
4091 | 35 |
by (blast_tac (claset() addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ, |
6112 | 36 |
Pair_in_univ]) 1); |
760 | 37 |
qed "list_univ"; |
0 | 38 |
|
908
1f99a44c10cb
Updated comment about list_subset_univ and list_into_univ.
lcp
parents:
782
diff
changeset
|
39 |
(*These two theorems justify datatypes involving list(nat), list(A), ...*) |
6112 | 40 |
bind_thm ("list_subset_univ", [list_mono, list_univ] MRS subset_trans); |
0 | 41 |
|
5137 | 42 |
Goal "[| l: list(A); A <= univ(B) |] ==> l: univ(B)"; |
435 | 43 |
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1)); |
760 | 44 |
qed "list_into_univ"; |
435 | 45 |
|
5321 | 46 |
val major::prems = Goal |
0 | 47 |
"[| l: list(A); \ |
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
48 |
\ c: C(Nil); \ |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
49 |
\ !!x y. [| x: A; y: list(A) |] ==> h(x,y): C(Cons(x,y)) \ |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
50 |
\ |] ==> list_case(c,h,l) : C(l)"; |
516 | 51 |
by (rtac (major RS list.induct) 1); |
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
5529
diff
changeset
|
52 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems))); |
760 | 53 |
qed "list_case_type"; |
0 | 54 |
|
55 |
||
516 | 56 |
(*** List functions ***) |
57 |
||
5137 | 58 |
Goal "l: list(A) ==> tl(l) : list(A)"; |
6065 | 59 |
by (exhaust_tac "l" 1); |
4091 | 60 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps list.intrs))); |
760 | 61 |
qed "tl_type"; |
516 | 62 |
|
63 |
(** drop **) |
|
64 |
||
6070 | 65 |
Goal "i:nat ==> drop(i, Nil) = Nil"; |
66 |
by (induct_tac "i" 1); |
|
2469 | 67 |
by (ALLGOALS Asm_simp_tac); |
760 | 68 |
qed "drop_Nil"; |
516 | 69 |
|
6070 | 70 |
Goal "i:nat ==> drop(succ(i), Cons(a,l)) = drop(i,l)"; |
2493 | 71 |
by (rtac sym 1); |
6070 | 72 |
by (induct_tac "i" 1); |
2469 | 73 |
by (Simp_tac 1); |
74 |
by (Asm_simp_tac 1); |
|
760 | 75 |
qed "drop_succ_Cons"; |
516 | 76 |
|
6070 | 77 |
Addsimps [drop_Nil, drop_succ_Cons]; |
2469 | 78 |
|
6070 | 79 |
Goal "[| i:nat; l: list(A) |] ==> drop(i,l) : list(A)"; |
80 |
by (induct_tac "i" 1); |
|
4091 | 81 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [tl_type]))); |
760 | 82 |
qed "drop_type"; |
516 | 83 |
|
6070 | 84 |
Delsimps [drop_SUCC]; |
85 |
||
516 | 86 |
|
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
5529
diff
changeset
|
87 |
(** Type checking -- proved by induction, as usual **) |
516 | 88 |
|
5321 | 89 |
val prems = Goal |
516 | 90 |
"[| l: list(A); \ |
91 |
\ c: C(Nil); \ |
|
92 |
\ !!x y r. [| x:A; y: list(A); r: C(y) |] ==> h(x,y,r): C(Cons(x,y)) \ |
|
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
5529
diff
changeset
|
93 |
\ |] ==> list_rec(c,h,l) : C(l)"; |
6065 | 94 |
by (cut_facts_tac prems 1); |
95 |
by (induct_tac "l" 1); |
|
4091 | 96 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems))); |
760 | 97 |
qed "list_rec_type"; |
516 | 98 |
|
99 |
(** map **) |
|
100 |
||
11145 | 101 |
val prems = Goalw [thm "map_list_def"] |
516 | 102 |
"[| l: list(A); !!x. x: A ==> h(x): B |] ==> map(h,l) : list(B)"; |
103 |
by (REPEAT (ares_tac (prems @ list.intrs @ [list_rec_type]) 1)); |
|
760 | 104 |
qed "map_type"; |
516 | 105 |
|
5321 | 106 |
Goal "l: list(A) ==> map(h,l) : list({h(u). u:A})"; |
107 |
by (etac map_type 1); |
|
516 | 108 |
by (etac RepFunI 1); |
760 | 109 |
qed "map_type2"; |
516 | 110 |
|
111 |
(** length **) |
|
112 |
||
11145 | 113 |
Goalw [thm "length_list_def"] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
114 |
"l: list(A) ==> length(l) : nat"; |
516 | 115 |
by (REPEAT (ares_tac [list_rec_type, nat_0I, nat_succI] 1)); |
760 | 116 |
qed "length_type"; |
516 | 117 |
|
118 |
(** app **) |
|
119 |
||
11145 | 120 |
Goalw [thm "op @_list_def"] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
121 |
"[| xs: list(A); ys: list(A) |] ==> xs@ys : list(A)"; |
516 | 122 |
by (REPEAT (ares_tac [list_rec_type, list.Cons_I] 1)); |
760 | 123 |
qed "app_type"; |
516 | 124 |
|
125 |
(** rev **) |
|
126 |
||
11145 | 127 |
Goalw [thm "rev_list_def"] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
128 |
"xs: list(A) ==> rev(xs) : list(A)"; |
516 | 129 |
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1)); |
760 | 130 |
qed "rev_type"; |
516 | 131 |
|
132 |
||
133 |
(** flat **) |
|
134 |
||
11145 | 135 |
Goalw [thm "flat_list_def"] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
136 |
"ls: list(list(A)) ==> flat(ls) : list(A)"; |
516 | 137 |
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1)); |
760 | 138 |
qed "flat_type"; |
516 | 139 |
|
140 |
||
1926 | 141 |
(** set_of_list **) |
142 |
||
11145 | 143 |
Goalw [thm "set_of_list_list_def"] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
144 |
"l: list(A) ==> set_of_list(l) : Pow(A)"; |
2033 | 145 |
by (etac list_rec_type 1); |
3016 | 146 |
by (ALLGOALS (Blast_tac)); |
1926 | 147 |
qed "set_of_list_type"; |
148 |
||
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
149 |
Goal "xs: list(A) ==> \ |
1926 | 150 |
\ set_of_list (xs@ys) = set_of_list(xs) Un set_of_list(ys)"; |
151 |
by (etac list.induct 1); |
|
4091 | 152 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Un_cons]))); |
1926 | 153 |
qed "set_of_list_append"; |
154 |
||
155 |
||
516 | 156 |
(** list_add **) |
157 |
||
11145 | 158 |
Goalw [thm "list_add_list_def"] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
159 |
"xs: list(nat) ==> list_add(xs) : nat"; |
516 | 160 |
by (REPEAT (ares_tac [list_rec_type, nat_0I, add_type] 1)); |
760 | 161 |
qed "list_add_type"; |
516 | 162 |
|
9907 | 163 |
bind_thms ("list_typechecks", |
516 | 164 |
list.intrs @ |
165 |
[list_rec_type, map_type, map_type2, app_type, length_type, |
|
9907 | 166 |
rev_type, flat_type, list_add_type]); |
516 | 167 |
|
6153 | 168 |
AddTCs list_typechecks; |
516 | 169 |
|
170 |
||
171 |
(*** theorems about map ***) |
|
172 |
||
5321 | 173 |
Goal "l: list(A) ==> map(%u. u, l) = l"; |
6065 | 174 |
by (induct_tac "l" 1); |
3016 | 175 |
by (ALLGOALS Asm_simp_tac); |
760 | 176 |
qed "map_ident"; |
6112 | 177 |
Addsimps [map_ident]; |
516 | 178 |
|
5321 | 179 |
Goal "l: list(A) ==> map(h, map(j,l)) = map(%u. h(j(u)), l)"; |
6065 | 180 |
by (induct_tac "l" 1); |
3016 | 181 |
by (ALLGOALS Asm_simp_tac); |
760 | 182 |
qed "map_compose"; |
516 | 183 |
|
5321 | 184 |
Goal "xs: list(A) ==> map(h, xs@ys) = map(h,xs) @ map(h,ys)"; |
6065 | 185 |
by (induct_tac "xs" 1); |
3016 | 186 |
by (ALLGOALS Asm_simp_tac); |
760 | 187 |
qed "map_app_distrib"; |
516 | 188 |
|
5321 | 189 |
Goal "ls: list(list(A)) ==> map(h, flat(ls)) = flat(map(map(h),ls))"; |
6065 | 190 |
by (induct_tac "ls" 1); |
4091 | 191 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [map_app_distrib]))); |
760 | 192 |
qed "map_flat"; |
516 | 193 |
|
5321 | 194 |
Goal "l: list(A) ==> \ |
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
5529
diff
changeset
|
195 |
\ list_rec(c, d, map(h,l)) = \ |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
5529
diff
changeset
|
196 |
\ list_rec(c, %x xs r. d(h(x), map(h,xs), r), l)"; |
6065 | 197 |
by (induct_tac "l" 1); |
3016 | 198 |
by (ALLGOALS Asm_simp_tac); |
760 | 199 |
qed "list_rec_map"; |
516 | 200 |
|
201 |
(** theorems about list(Collect(A,P)) -- used in ex/term.ML **) |
|
202 |
||
203 |
(* c : list(Collect(B,P)) ==> c : list(B) *) |
|
6112 | 204 |
bind_thm ("list_CollectD", Collect_subset RS list_mono RS subsetD); |
516 | 205 |
|
5321 | 206 |
Goal "l: list({x:A. h(x)=j(x)}) ==> map(h,l) = map(j,l)"; |
6065 | 207 |
by (induct_tac "l" 1); |
3016 | 208 |
by (ALLGOALS Asm_simp_tac); |
760 | 209 |
qed "map_list_Collect"; |
516 | 210 |
|
211 |
(*** theorems about length ***) |
|
212 |
||
5321 | 213 |
Goal "xs: list(A) ==> length(map(h,xs)) = length(xs)"; |
6065 | 214 |
by (induct_tac "xs" 1); |
3016 | 215 |
by (ALLGOALS Asm_simp_tac); |
760 | 216 |
qed "length_map"; |
516 | 217 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6153
diff
changeset
|
218 |
Goal "[| xs: list(A); ys: list(A) |] \ |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6153
diff
changeset
|
219 |
\ ==> length(xs@ys) = length(xs) #+ length(ys)"; |
6065 | 220 |
by (induct_tac "xs" 1); |
3016 | 221 |
by (ALLGOALS Asm_simp_tac); |
760 | 222 |
qed "length_app"; |
516 | 223 |
|
5321 | 224 |
Goal "xs: list(A) ==> length(rev(xs)) = length(xs)"; |
6065 | 225 |
by (induct_tac "xs" 1); |
6112 | 226 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [length_app]))); |
760 | 227 |
qed "length_rev"; |
516 | 228 |
|
5321 | 229 |
Goal "ls: list(list(A)) ==> length(flat(ls)) = list_add(map(length,ls))"; |
6065 | 230 |
by (induct_tac "ls" 1); |
4091 | 231 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [length_app]))); |
760 | 232 |
qed "length_flat"; |
516 | 233 |
|
234 |
(** Length and drop **) |
|
235 |
||
236 |
(*Lemma for the inductive step of drop_length*) |
|
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
237 |
Goal "xs: list(A) ==> \ |
516 | 238 |
\ ALL x. EX z zs. drop(length(xs), Cons(x,xs)) = Cons(z,zs)"; |
239 |
by (etac list.induct 1); |
|
2469 | 240 |
by (ALLGOALS Asm_simp_tac); |
3016 | 241 |
by (Blast_tac 1); |
6112 | 242 |
qed_spec_mp "drop_length_Cons"; |
516 | 243 |
|
6112 | 244 |
Goal "l: list(A) ==> ALL i:length(l). (EX z zs. drop(i,l) = Cons(z,zs))"; |
516 | 245 |
by (etac list.induct 1); |
2469 | 246 |
by (ALLGOALS Asm_simp_tac); |
6112 | 247 |
by Safe_tac; |
516 | 248 |
by (etac drop_length_Cons 1); |
249 |
by (rtac natE 1); |
|
250 |
by (etac ([asm_rl, length_type, Ord_nat] MRS Ord_trans) 1); |
|
251 |
by (assume_tac 1); |
|
3016 | 252 |
by (ALLGOALS Asm_simp_tac); |
4091 | 253 |
by (ALLGOALS (blast_tac (claset() addIs [succ_in_naturalD, length_type]))); |
6112 | 254 |
qed_spec_mp "drop_length"; |
516 | 255 |
|
256 |
||
257 |
(*** theorems about app ***) |
|
258 |
||
5321 | 259 |
Goal "xs: list(A) ==> xs@Nil=xs"; |
260 |
by (etac list.induct 1); |
|
3016 | 261 |
by (ALLGOALS Asm_simp_tac); |
760 | 262 |
qed "app_right_Nil"; |
6112 | 263 |
Addsimps [app_right_Nil]; |
516 | 264 |
|
5321 | 265 |
Goal "xs: list(A) ==> (xs@ys)@zs = xs@(ys@zs)"; |
6065 | 266 |
by (induct_tac "xs" 1); |
3016 | 267 |
by (ALLGOALS Asm_simp_tac); |
760 | 268 |
qed "app_assoc"; |
516 | 269 |
|
5321 | 270 |
Goal "ls: list(list(A)) ==> flat(ls@ms) = flat(ls)@flat(ms)"; |
6065 | 271 |
by (induct_tac "ls" 1); |
4091 | 272 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [app_assoc]))); |
760 | 273 |
qed "flat_app_distrib"; |
516 | 274 |
|
275 |
(*** theorems about rev ***) |
|
276 |
||
5321 | 277 |
Goal "l: list(A) ==> rev(map(h,l)) = map(h,rev(l))"; |
6065 | 278 |
by (induct_tac "l" 1); |
4091 | 279 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [map_app_distrib]))); |
760 | 280 |
qed "rev_map_distrib"; |
516 | 281 |
|
282 |
(*Simplifier needs the premises as assumptions because rewriting will not |
|
283 |
instantiate the variable ?A in the rules' typing conditions; note that |
|
284 |
rev_type does not instantiate ?A. Only the premises do. |
|
285 |
*) |
|
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
286 |
Goal "[| xs: list(A); ys: list(A) |] ==> rev(xs@ys) = rev(ys)@rev(xs)"; |
516 | 287 |
by (etac list.induct 1); |
6112 | 288 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [app_assoc]))); |
760 | 289 |
qed "rev_app_distrib"; |
516 | 290 |
|
5321 | 291 |
Goal "l: list(A) ==> rev(rev(l))=l"; |
6065 | 292 |
by (induct_tac "l" 1); |
4091 | 293 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [rev_app_distrib]))); |
760 | 294 |
qed "rev_rev_ident"; |
6112 | 295 |
Addsimps [rev_rev_ident]; |
516 | 296 |
|
5321 | 297 |
Goal "ls: list(list(A)) ==> rev(flat(ls)) = flat(map(rev,rev(ls)))"; |
6065 | 298 |
by (induct_tac "ls" 1); |
6112 | 299 |
by (ALLGOALS |
300 |
(asm_simp_tac (simpset() addsimps |
|
301 |
[map_app_distrib, flat_app_distrib, rev_app_distrib]))); |
|
760 | 302 |
qed "rev_flat"; |
516 | 303 |
|
304 |
||
305 |
(*** theorems about list_add ***) |
|
306 |
||
5321 | 307 |
Goal "[| xs: list(nat); ys: list(nat) |] ==> \ |
516 | 308 |
\ list_add(xs@ys) = list_add(ys) #+ list_add(xs)"; |
6065 | 309 |
by (induct_tac "xs" 1); |
9548 | 310 |
by (ALLGOALS Asm_simp_tac); |
760 | 311 |
qed "list_add_app"; |
516 | 312 |
|
5321 | 313 |
Goal "l: list(nat) ==> list_add(rev(l)) = list_add(l)"; |
6065 | 314 |
by (induct_tac "l" 1); |
9548 | 315 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [list_add_app]))); |
760 | 316 |
qed "list_add_rev"; |
516 | 317 |
|
5321 | 318 |
Goal "ls: list(list(nat)) ==> list_add(flat(ls)) = list_add(map(list_add,ls))"; |
6065 | 319 |
by (induct_tac "ls" 1); |
4091 | 320 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [list_add_app]))); |
516 | 321 |
by (REPEAT (ares_tac [refl, list_add_type, map_type, add_commute] 1)); |
760 | 322 |
qed "list_add_flat"; |
516 | 323 |
|
324 |
(** New induction rule **) |
|
325 |
||
5321 | 326 |
val major::prems = Goal |
516 | 327 |
"[| l: list(A); \ |
328 |
\ P(Nil); \ |
|
329 |
\ !!x y. [| x: A; y: list(A); P(y) |] ==> P(y @ [x]) \ |
|
330 |
\ |] ==> P(l)"; |
|
331 |
by (rtac (major RS rev_rev_ident RS subst) 1); |
|
332 |
by (rtac (major RS rev_type RS list.induct) 1); |
|
4091 | 333 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems))); |
760 | 334 |
qed "list_append_induct"; |
516 | 335 |
|
12789 | 336 |
|
337 |
(*** Thanks to Sidi Ehmety for these results about min, take, etc. ***) |
|
338 |
||
339 |
(** min **) |
|
340 |
(* Min theorems are also true for i, j ordinals *) |
|
341 |
Goalw [min_def] "[| i:nat; j:nat |] ==> min(i,j)=min(j,i)"; |
|
342 |
by (auto_tac (claset() addSDs [not_lt_imp_le] |
|
343 |
addDs [lt_not_sym] |
|
344 |
addIs [le_anti_sym], simpset())); |
|
345 |
qed "min_sym"; |
|
346 |
||
347 |
Goalw [min_def] "[| i:nat; j:nat |] ==> min(i,j):nat"; |
|
348 |
by Auto_tac; |
|
349 |
qed "min_type"; |
|
350 |
AddTCs [min_type]; |
|
351 |
Addsimps [min_type]; |
|
352 |
||
353 |
Goalw [min_def] "i:nat ==> min(0,i) = 0"; |
|
354 |
by (auto_tac (claset() addDs [not_lt_imp_le], simpset())); |
|
355 |
qed "min_0"; |
|
356 |
Addsimps [min_0]; |
|
357 |
||
358 |
Goalw [min_def] "i:nat ==> min(i, 0) = 0"; |
|
359 |
by (auto_tac (claset() addDs [not_lt_imp_le], simpset())); |
|
360 |
qed "min_02"; |
|
361 |
Addsimps [min_02]; |
|
362 |
||
363 |
Goalw [min_def] "[| i:nat; j:nat; k:nat |] ==> i<min(j,k) <-> i<j & i<k"; |
|
364 |
by (auto_tac (claset() addSDs [not_lt_imp_le] |
|
365 |
addIs [lt_trans2, lt_trans], simpset())); |
|
366 |
qed "lt_min_iff"; |
|
367 |
||
368 |
Goalw [min_def] |
|
369 |
"[| i:nat; j:nat |] ==> min(succ(i), succ(j))= succ(min(i, j))"; |
|
370 |
by Auto_tac; |
|
371 |
qed "min_succ_succ"; |
|
372 |
Addsimps [min_succ_succ]; |
|
373 |
||
374 |
(*** more theorems about lists ***) |
|
375 |
||
376 |
Goal "xs:list(A) ==> (xs~=Nil)<->(EX y:A. EX ys:list(A). xs=Cons(y,ys))"; |
|
377 |
by (induct_tac "xs" 1); |
|
378 |
by Auto_tac; |
|
379 |
qed "neq_Nil_iff"; |
|
380 |
||
381 |
(** filter **) |
|
382 |
||
383 |
Goal "xs:list(A) ==> filter(P, xs@ys) = filter(P, xs) @ filter(P, ys)"; |
|
384 |
by (induct_tac "xs" 1); |
|
385 |
by Auto_tac; |
|
386 |
qed "filter_append"; |
|
387 |
Addsimps [filter_append]; |
|
388 |
||
389 |
Goal "xs:list(A) ==> filter(P, xs):list(A)"; |
|
390 |
by (induct_tac "xs" 1); |
|
391 |
by Auto_tac; |
|
392 |
qed "filter_type"; |
|
393 |
||
394 |
Goal "xs:list(A) ==> length(filter(P, xs)) le length(xs)"; |
|
395 |
by (induct_tac "xs" 1); |
|
396 |
by Auto_tac; |
|
397 |
by (res_inst_tac [("j", "length(l)")] le_trans 1); |
|
398 |
by (auto_tac (claset(), simpset() addsimps [le_iff])); |
|
399 |
qed "length_filter"; |
|
400 |
||
401 |
Goal "xs:list(A) ==> set_of_list(filter(P,xs)) <= set_of_list(xs)"; |
|
402 |
by (induct_tac "xs" 1); |
|
403 |
by Auto_tac; |
|
404 |
qed "filter_is_subset"; |
|
405 |
||
406 |
Goal "xs:list(A) ==> filter(%p. False, xs) = Nil"; |
|
407 |
by (induct_tac "xs" 1); |
|
408 |
by Auto_tac; |
|
409 |
qed "filter_False"; |
|
410 |
||
411 |
Goal "xs:list(A) ==> filter(%p. True, xs) = xs"; |
|
412 |
by (induct_tac "xs" 1); |
|
413 |
by Auto_tac; |
|
414 |
qed "filter_True"; |
|
415 |
Addsimps [filter_False, filter_True]; |
|
416 |
||
417 |
(** length **) |
|
418 |
||
419 |
Goal "xs:list(A) ==> length(xs)=0 <-> xs=Nil"; |
|
420 |
by (etac list.induct 1); |
|
421 |
by Auto_tac; |
|
422 |
qed "length_is_0_iff"; |
|
423 |
Addsimps [length_is_0_iff]; |
|
424 |
||
425 |
Goal "xs:list(A) ==> 0 = length(xs) <-> xs=Nil"; |
|
426 |
by (etac list.induct 1); |
|
427 |
by Auto_tac; |
|
428 |
qed "length_is_0_iff2"; |
|
429 |
Addsimps [length_is_0_iff2]; |
|
430 |
||
431 |
Goal "xs:list(A) ==> length(tl(xs)) = length(xs) #- 1"; |
|
432 |
by (etac list.induct 1); |
|
433 |
by Auto_tac; |
|
434 |
qed "length_tl"; |
|
435 |
Addsimps [length_tl]; |
|
436 |
||
437 |
Goal "xs:list(A) ==> 0<length(xs) <-> xs ~= Nil"; |
|
438 |
by (etac list.induct 1); |
|
439 |
by Auto_tac; |
|
440 |
qed "length_greater_0_iff"; |
|
441 |
||
442 |
Goal "xs:list(A) ==> length(xs)=succ(n) <-> (EX y ys. xs=Cons(y, ys) & length(ys)=n)"; |
|
443 |
by (etac list.induct 1); |
|
444 |
by Auto_tac; |
|
445 |
qed "length_succ_iff"; |
|
446 |
||
447 |
(** more theorems about append **) |
|
448 |
||
449 |
Goal "xs:list(A) ==> (xs@ys = Nil) <-> (xs=Nil & ys = Nil)"; |
|
450 |
by (etac list.induct 1); |
|
451 |
by Auto_tac; |
|
452 |
qed "append_is_Nil_iff"; |
|
453 |
Addsimps [append_is_Nil_iff]; |
|
454 |
||
455 |
Goal "xs:list(A) ==> (Nil = xs@ys) <-> (xs=Nil & ys = Nil)"; |
|
456 |
by (etac list.induct 1); |
|
457 |
by Auto_tac; |
|
458 |
qed "append_is_Nil_iff2"; |
|
459 |
Addsimps [append_is_Nil_iff2]; |
|
460 |
||
461 |
Goal "xs:list(A) ==> (xs@ys = xs) <-> (ys = Nil)"; |
|
462 |
by (etac list.induct 1); |
|
463 |
by Auto_tac; |
|
464 |
qed "append_left_is_self_iff"; |
|
465 |
Addsimps [append_left_is_self_iff]; |
|
466 |
||
467 |
Goal "xs:list(A) ==> (xs = xs@ys) <-> (ys = Nil)"; |
|
468 |
by (etac list.induct 1); |
|
469 |
by Auto_tac; |
|
470 |
qed "append_left_is_self_iff2"; |
|
471 |
Addsimps [append_left_is_self_iff2]; |
|
472 |
||
473 |
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> \ |
|
474 |
\ length(ys)=length(zs) --> (xs@ys=zs <-> (xs=Nil & ys=zs))"; |
|
475 |
by (etac list.induct 1); |
|
476 |
by (auto_tac (claset(), simpset() addsimps [length_app])); |
|
477 |
qed_spec_mp "append_left_is_Nil_iff"; |
|
478 |
Addsimps [append_left_is_Nil_iff]; |
|
479 |
||
480 |
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> \ |
|
481 |
\ length(ys)=length(zs) --> (zs=ys@xs <-> (xs=Nil & ys=zs))"; |
|
482 |
by (etac list.induct 1); |
|
483 |
by (auto_tac (claset(), simpset() addsimps [length_app])); |
|
484 |
qed_spec_mp "append_left_is_Nil_iff2"; |
|
485 |
Addsimps [append_left_is_Nil_iff2]; |
|
486 |
||
487 |
Goal "xs:list(A) ==> ALL ys:list(A). \ |
|
488 |
\ length(xs)=length(ys) --> (xs@us = ys@vs) <-> (xs=ys & us=vs)"; |
|
489 |
by (etac list.induct 1); |
|
490 |
by (Asm_simp_tac 1); |
|
491 |
by (Clarify_tac 1); |
|
492 |
by (eres_inst_tac [("a", "ys")] list.elim 1); |
|
493 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
494 |
qed_spec_mp "append_eq_append_iff"; |
|
495 |
||
496 |
||
497 |
Goal "xs:list(A) ==> \ |
|
498 |
\ ALL ys:list(A). ALL us:list(A). ALL vs:list(A). \ |
|
499 |
\ length(us) = length(vs) --> (xs@us = ys@vs) --> (xs=ys & us=vs)"; |
|
500 |
by (induct_tac "xs" 1); |
|
501 |
by (ALLGOALS(Clarify_tac)); |
|
502 |
by (asm_full_simp_tac (simpset() addsimps [length_app]) 1); |
|
503 |
by (eres_inst_tac [("a", "ys")] list.elim 1); |
|
504 |
by (Asm_full_simp_tac 1); |
|
505 |
by (subgoal_tac "Cons(a, l) @ us =vs" 1); |
|
506 |
by (dtac (rotate_prems 4 (append_left_is_Nil_iff RS iffD1)) 1); |
|
507 |
by Auto_tac; |
|
508 |
qed_spec_mp "append_eq_append"; |
|
509 |
||
510 |
Goal "[| xs:list(A); ys:list(A); us:list(A); vs:list(A); length(us)=length(vs) |] \ |
|
511 |
\ ==> xs@us = ys@vs <-> (xs=ys & us=vs)"; |
|
512 |
by (rtac iffI 1); |
|
513 |
by (rtac append_eq_append 1); |
|
514 |
by Auto_tac; |
|
515 |
qed "append_eq_append_iff2"; |
|
516 |
Addsimps [append_eq_append_iff, append_eq_append_iff2]; |
|
517 |
||
518 |
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> xs@ys=xs@zs <-> ys=zs"; |
|
519 |
by (Asm_simp_tac 1); |
|
520 |
qed "append_self_iff"; |
|
521 |
Addsimps [append_self_iff]; |
|
522 |
||
523 |
Goal "[| xs:list(A); ys:list(A); zs:list(A) |] ==> ys@xs=zs@xs <-> ys=zs"; |
|
524 |
by (Asm_simp_tac 1); |
|
525 |
qed "append_self_iff2"; |
|
526 |
Addsimps [append_self_iff2]; |
|
527 |
||
528 |
(* Can also be proved from append_eq_append_iff2, |
|
529 |
but the proof requires two more hypotheses: x:A and y:A *) |
|
530 |
Goal "xs:list(A) ==> ALL ys:list(A). xs@[x] = ys@[y] <-> (xs = ys & x=y)"; |
|
531 |
by (etac list.induct 1); |
|
532 |
by (ALLGOALS(Clarify_tac)); |
|
533 |
by (ALLGOALS(eres_inst_tac [("a", "ys")] list.elim)); |
|
534 |
by Auto_tac; |
|
535 |
qed_spec_mp "append1_eq_iff"; |
|
536 |
Addsimps [append1_eq_iff]; |
|
537 |
||
538 |
Goal "[| xs:list(A); ys:list(A) |] ==> (xs@ys = ys) <-> (xs=Nil)"; |
|
539 |
by (Asm_simp_tac 1); |
|
540 |
qed "append_right_is_self_iff"; |
|
541 |
Addsimps [append_right_is_self_iff]; |
|
542 |
||
543 |
Goal "[| xs:list(A); ys:list(A) |] ==> (ys = xs@ys) <-> (xs=Nil)"; |
|
544 |
by (rtac iffI 1); |
|
545 |
by (dtac sym 1); |
|
546 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
547 |
qed "append_right_is_self_iff2"; |
|
548 |
Addsimps [append_right_is_self_iff2]; |
|
549 |
||
550 |
Goal "xs:list(A) ==> xs ~= Nil --> hd(xs @ ys) = hd(xs)"; |
|
551 |
by (induct_tac "xs" 1); |
|
552 |
by Auto_tac; |
|
553 |
qed_spec_mp "hd_append"; |
|
554 |
Addsimps [hd_append]; |
|
555 |
||
556 |
Goal "xs:list(A) ==> xs~=Nil --> tl(xs @ ys) = tl(xs)@ys"; |
|
557 |
by (induct_tac "xs" 1); |
|
558 |
by Auto_tac; |
|
559 |
qed_spec_mp "tl_append"; |
|
560 |
Addsimps [tl_append]; |
|
561 |
||
562 |
(** rev **) |
|
563 |
Goal "xs:list(A) ==> (rev(xs) = Nil <-> xs = Nil)"; |
|
564 |
by (etac list.induct 1); |
|
565 |
by Auto_tac; |
|
566 |
qed "rev_is_Nil_iff"; |
|
567 |
Addsimps [rev_is_Nil_iff]; |
|
568 |
||
569 |
Goal "xs:list(A) ==> (Nil = rev(xs) <-> xs = Nil)"; |
|
570 |
by (etac list.induct 1); |
|
571 |
by Auto_tac; |
|
572 |
qed "Nil_is_rev_iff"; |
|
573 |
Addsimps [Nil_is_rev_iff]; |
|
574 |
||
575 |
Goal "xs:list(A) ==> ALL ys:list(A). rev(xs)=rev(ys) <-> xs=ys"; |
|
576 |
by (etac list.induct 1); |
|
577 |
by (Force_tac 1); |
|
578 |
by (Clarify_tac 1); |
|
579 |
by (eres_inst_tac [("a", "ys")] list.elim 1); |
|
580 |
by Auto_tac; |
|
581 |
qed_spec_mp "rev_is_rev_iff"; |
|
582 |
Addsimps [rev_is_rev_iff]; |
|
583 |
||
584 |
Goal "xs:list(A) ==> \ |
|
585 |
\ (xs=Nil --> P) --> (ALL ys:list(A). ALL y:A. xs =ys@[y] -->P)-->P"; |
|
586 |
by (etac list_append_induct 1); |
|
587 |
by Auto_tac; |
|
588 |
qed_spec_mp "rev_list_elim_aux"; |
|
589 |
||
590 |
bind_thm("rev_list_elim", impI RS ballI RS ballI RSN(3, rev_list_elim_aux)); |
|
591 |
||
592 |
(** more theorems about drop **) |
|
593 |
||
594 |
Goal "n:nat ==> ALL xs:list(A). length(drop(n, xs)) = length(xs) #- n"; |
|
595 |
by (etac nat_induct 1); |
|
596 |
by (auto_tac (claset() addEs [list.elim], simpset())); |
|
597 |
qed_spec_mp "length_drop"; |
|
598 |
Addsimps [length_drop]; |
|
599 |
||
600 |
Goal "n:nat ==> ALL xs:list(A). length(xs) le n --> drop(n, xs)=Nil"; |
|
601 |
by (etac nat_induct 1); |
|
602 |
by (auto_tac (claset() addEs [list.elim], simpset())); |
|
603 |
qed_spec_mp "drop_all"; |
|
604 |
Addsimps [drop_all]; |
|
605 |
||
606 |
Goal "n:nat ==> ALL xs:list(A). drop(n, xs@ys) = \ |
|
607 |
\ drop(n,xs) @ drop(n #- length(xs), ys)"; |
|
608 |
by (induct_tac "n" 1); |
|
609 |
by (auto_tac (claset() addEs [list.elim], simpset())); |
|
610 |
qed_spec_mp "drop_append"; |
|
611 |
||
612 |
Goal "m:nat ==> \ |
|
613 |
\ ALL xs:list(A). ALL n:nat. drop(n, drop(m, xs))=drop(n #+ m, xs)"; |
|
614 |
by (induct_tac "m" 1); |
|
615 |
by (auto_tac (claset() addEs [list.elim], simpset())); |
|
616 |
qed "drop_drop"; |
|
617 |
||
618 |
(** take **) |
|
619 |
||
620 |
Goalw [take_def] |
|
621 |
"xs:list(A) ==> take(0, xs) = Nil"; |
|
622 |
by (etac list.induct 1); |
|
623 |
by Auto_tac; |
|
624 |
qed "take_0"; |
|
625 |
Addsimps [take_0]; |
|
626 |
||
627 |
Goalw [take_def] |
|
628 |
"n:nat ==> take(succ(n), Cons(a, xs)) = Cons(a, take(n, xs))"; |
|
629 |
by (Asm_simp_tac 1); |
|
630 |
qed "take_succ_Cons"; |
|
631 |
Addsimps [take_succ_Cons]; |
|
632 |
||
633 |
(* Needed for proving take_all *) |
|
634 |
Goalw [take_def] |
|
635 |
"n:nat ==> take(n, Nil) = Nil"; |
|
636 |
by Auto_tac; |
|
637 |
qed "take_Nil"; |
|
638 |
Addsimps [take_Nil]; |
|
639 |
||
640 |
Goal "n:nat ==> ALL xs:list(A). length(xs) le n --> take(n, xs) = xs"; |
|
641 |
by (etac nat_induct 1); |
|
642 |
by (auto_tac (claset() addEs [list.elim], simpset())); |
|
643 |
qed_spec_mp "take_all"; |
|
644 |
Addsimps [take_all]; |
|
645 |
||
646 |
Goal "xs:list(A) ==> ALL n:nat. take(n, xs):list(A)"; |
|
647 |
by (etac list.induct 1); |
|
648 |
by (Clarify_tac 2); |
|
649 |
by (etac natE 2); |
|
650 |
by Auto_tac; |
|
651 |
qed_spec_mp "take_type"; |
|
652 |
||
653 |
Goal "xs:list(A) ==> \ |
|
654 |
\ ALL ys:list(A). ALL n:nat. take(n, xs @ ys) = \ |
|
655 |
\ take(n, xs) @ take(n #- length(xs), ys)"; |
|
656 |
by (etac list.induct 1); |
|
657 |
by (Clarify_tac 2); |
|
658 |
by (etac natE 2); |
|
659 |
by Auto_tac; |
|
660 |
qed_spec_mp "take_append"; |
|
661 |
Addsimps [take_append]; |
|
662 |
||
663 |
Goal |
|
664 |
"m:nat ==> \ |
|
665 |
\ ALL xs:list(A). ALL n:nat. take(n, take(m,xs))= take(min(n, m), xs)"; |
|
666 |
by (induct_tac "m" 1); |
|
667 |
by Auto_tac; |
|
668 |
by (eres_inst_tac [("a", "xs")] list.elim 1); |
|
669 |
by (auto_tac (claset(), simpset() addsimps [take_Nil])); |
|
670 |
by (rotate_tac 1 1); |
|
671 |
by (etac natE 1); |
|
672 |
by (auto_tac (claset() addIs [take_0, take_type], simpset())); |
|
673 |
qed_spec_mp "take_take"; |
|
674 |
||
675 |
(** nth **) |
|
676 |
||
677 |
Goalw [nth_def] "nth(0, Cons(a, l))= a"; |
|
678 |
by Auto_tac; |
|
679 |
qed "nth_0"; |
|
680 |
Addsimps [nth_0]; |
|
681 |
||
682 |
Goalw [nth_def] |
|
683 |
"n:nat ==> nth(succ(n), Cons(a, l)) = nth(n, l)"; |
|
684 |
by (Asm_simp_tac 1); |
|
685 |
qed "nth_Cons"; |
|
686 |
Addsimps [nth_Cons]; |
|
687 |
||
688 |
Goal "xs:list(A) ==> ALL n:nat. n < length(xs) --> nth(n, xs):A"; |
|
689 |
by (etac list.induct 1); |
|
690 |
by (ALLGOALS(Clarify_tac)); |
|
691 |
by (etac natE 2); |
|
692 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
693 |
qed_spec_mp "nth_type"; |
|
694 |
||
695 |
AddTCs [nth_type]; |
|
696 |
Addsimps [nth_type]; |
|
697 |
||
698 |
Goal |
|
699 |
"xs:list(A) ==> ALL n:nat. \ |
|
700 |
\ nth(n, xs @ ys) = (if n < length(xs) then nth(n,xs) \ |
|
701 |
\ else nth(n #- length(xs),ys))"; |
|
702 |
by (induct_tac "xs" 1); |
|
703 |
by (Clarify_tac 2); |
|
704 |
by (etac natE 2); |
|
705 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
706 |
qed_spec_mp "nth_append"; |
|
707 |
||
708 |
Goal "xs:list(A) ==> \ |
|
709 |
\ set_of_list(xs) = {x:A. EX i:nat. i<length(xs) & x=nth(i, xs)}"; |
|
710 |
by (induct_tac "xs" 1); |
|
711 |
by (ALLGOALS(Asm_simp_tac)); |
|
712 |
by (rtac equalityI 1); |
|
713 |
by Auto_tac; |
|
714 |
by (res_inst_tac [("x", "0")] bexI 1); |
|
715 |
by Auto_tac; |
|
716 |
by (res_inst_tac [("x", "succ(i)")] bexI 1); |
|
717 |
by Auto_tac; |
|
718 |
by (etac natE 1); |
|
719 |
by Auto_tac; |
|
720 |
qed "set_of_list_conv_nth"; |
|
721 |
||
722 |
(* Other theorems about lists *) |
|
723 |
||
724 |
Goalw [Ball_def] |
|
725 |
"k:nat ==> \ |
|
726 |
\ ALL xs:list(A). (ALL ys:list(A). k le length(xs) --> k le length(ys) --> \ |
|
727 |
\ (ALL i:nat. i<k --> nth(i,xs)= nth(i,ys))--> take(k, xs) = take(k,ys))"; |
|
728 |
by (induct_tac "k" 1); |
|
729 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps |
|
730 |
[lt_succ_eq_0_disj, all_conj_distrib]))); |
|
731 |
by (Clarify_tac 1); |
|
732 |
(*Both lists must be non-empty*) |
|
733 |
by (case_tac "xa=Nil" 1); |
|
734 |
by (case_tac "xb=Nil" 2); |
|
735 |
by (Clarify_tac 1); |
|
736 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [neq_Nil_iff]))); |
|
737 |
by (Clarify_tac 1); |
|
738 |
(*prenexing's needed, not miniscoping*) |
|
739 |
by (Asm_simp_tac 1); |
|
740 |
by (rtac conjI 1); |
|
741 |
by (Force_tac 1); |
|
742 |
by (ALLGOALS (full_simp_tac (simpset() addsimps (all_simps RL [iff_sym]) |
|
743 |
delsimps (all_simps)))); |
|
744 |
by (dres_inst_tac [("x", "ys"), ("x1", "ysa")] (spec RS spec) 1); |
|
745 |
by (Clarify_tac 1); |
|
746 |
by Auto_tac; |
|
747 |
qed_spec_mp "nth_take_lemma"; |
|
748 |
||
749 |
Goal "[| xs:list(A); ys:list(A); length(xs) = length(ys); \ |
|
750 |
\ ALL i:nat. i < length(xs) --> nth(i,xs) = nth(i,ys) |] \ |
|
751 |
\ ==> xs = ys"; |
|
752 |
by (subgoal_tac "length(xs) le length(ys)" 1); |
|
753 |
by (forw_inst_tac [("ys", "ys")] (rotate_prems 1 nth_take_lemma) 1); |
|
754 |
by (ALLGOALS(Asm_simp_tac)); |
|
755 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [take_all]))); |
|
756 |
qed_spec_mp "nth_equalityI"; |
|
757 |
||
758 |
(*The famous take-lemma*) |
|
759 |
||
760 |
Goal "[| xs:list(A); ys:list(A); (ALL i:nat. take(i, xs) = take(i,ys)) |] ==> xs = ys"; |
|
761 |
by (case_tac "length(xs) le length(ys)" 1); |
|
762 |
by (dres_inst_tac [("x", "length(ys)")] bspec 1); |
|
763 |
by (dtac not_lt_imp_le 3); |
|
764 |
by (subgoal_tac "length(ys) le length(xs)" 5); |
|
765 |
by (res_inst_tac [("j", "succ(length(ys))")] le_trans 6); |
|
766 |
by (rtac leI 6); |
|
767 |
by (dres_inst_tac [("x", "length(xs)")] bspec 5); |
|
768 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [take_all]))); |
|
769 |
qed_spec_mp "take_equalityI"; |
|
770 |
||
771 |
Goal "n:nat ==> ALL i:nat. ALL xs:list(A). n #+ i le length(xs) \ |
|
772 |
\ --> nth(i, drop(n, xs)) = nth(n #+ i, xs)"; |
|
773 |
by (induct_tac "n" 1); |
|
774 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
775 |
by (Clarify_tac 1); |
|
776 |
by (case_tac "xb=Nil" 1); |
|
777 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [neq_Nil_iff]))); |
|
778 |
by (Clarify_tac 1); |
|
779 |
by (auto_tac (claset() addSEs [ConsE], simpset())); |
|
780 |
qed_spec_mp "nth_drop"; |
|
781 |
||
782 |
(** zip **) |
|
783 |
||
784 |
Goal "l:list(A) ==> l:list(set_of_list(l))"; |
|
785 |
by (induct_tac "l" 1); |
|
786 |
by Auto_tac; |
|
787 |
by (res_inst_tac [("A1", "set_of_list(l)")] (list_mono RS subsetD) 1); |
|
788 |
by Auto_tac; |
|
789 |
qed "list_on_set_of_list"; |
|
790 |
||
791 |
Goal "A<=C ==> ziprel(A, B) <= ziprel(C,B)"; |
|
792 |
by (Clarify_tac 1); |
|
793 |
by (forward_tac [ziprel.dom_subset RS subsetD] 1); |
|
794 |
by (Clarify_tac 1); |
|
795 |
by (etac ziprel.induct 1); |
|
796 |
by (auto_tac (claset() addIs [list_mono RS subsetD] |
|
797 |
addSIs ziprel.intrs, simpset())); |
|
798 |
qed "ziprel_mono1"; |
|
799 |
||
800 |
Goal "B<=C ==> ziprel(A, B) <= ziprel(A,C)"; |
|
801 |
by (Clarify_tac 1); |
|
802 |
by (forward_tac [ziprel.dom_subset RS subsetD] 1); |
|
803 |
by (Clarify_tac 1); |
|
804 |
by (etac ziprel.induct 1); |
|
805 |
by (auto_tac (claset() addIs [list_mono RS subsetD] |
|
806 |
addSIs ziprel.intrs, simpset())); |
|
807 |
qed "ziprel_mono2"; |
|
808 |
||
809 |
Goal "[| A<=C; B<=D |] ==> ziprel(A, B) <= ziprel(C,D)"; |
|
810 |
by (rtac subset_trans 1); |
|
811 |
by (rtac ziprel_mono1 2); |
|
812 |
by (rtac ziprel_mono2 1); |
|
813 |
by Auto_tac; |
|
814 |
qed "ziprel_mono"; |
|
815 |
||
816 |
(* ziprel is a function *) |
|
817 |
||
818 |
Goal "<xs, ys, zs>:ziprel(A,B) \ |
|
819 |
\ ==> ALL ks. <xs, ys, ks>:ziprel(A, B) --> ks=zs"; |
|
820 |
by (etac ziprel.induct 1); |
|
821 |
by (ALLGOALS(Clarify_tac)); |
|
822 |
by (rotate_tac 1 3); |
|
823 |
by (ALLGOALS(etac ziprel.elim)); |
|
824 |
by Safe_tac; |
|
825 |
(* These hypotheses make Auto_tac loop! *) |
|
826 |
by (thin_tac "ALL k. ?P(k)" 3); |
|
827 |
by (thin_tac "ALL k. ?P(k)" 4); |
|
828 |
by Auto_tac; |
|
829 |
qed "ziprel_is_fun"; |
|
830 |
||
831 |
Goal "ys:list(B) ==> ALL xs:list(A). EX zs. <xs, ys, zs>:ziprel(A,B)"; |
|
832 |
by (induct_tac "ys" 1); |
|
833 |
by (auto_tac (claset() addIs ziprel.intrs, simpset())); |
|
834 |
by (eres_inst_tac [("a", "xs")] list.elim 1); |
|
835 |
by (auto_tac (claset() addIs ziprel.intrs, simpset())); |
|
836 |
qed_spec_mp "ziprel_exist"; |
|
837 |
||
838 |
Goalw [zip_def] |
|
839 |
"[|xs:list(A); ys:list(B) |] ==> <xs, ys, zip(xs,ys)>:ziprel(A,B)"; |
|
840 |
by (rtac theI2 1); |
|
841 |
by (asm_full_simp_tac (simpset() addsimps [set_of_list_append]) 2); |
|
842 |
by (REPEAT(dtac set_of_list_type 2)); |
|
843 |
by (rtac (ziprel_mono RS subsetD) 2); |
|
844 |
by (Blast_tac 3); |
|
845 |
by (dtac list_on_set_of_list 1); |
|
846 |
by (dtac list_on_set_of_list 1); |
|
847 |
by (subgoal_tac "xs:list(set_of_list(xs@ys)) & \ |
|
848 |
\ ys:list(set_of_list(xs@ys))" 1); |
|
849 |
by (auto_tac (claset() addIs [list_mono RS subsetD], |
|
850 |
simpset() addsimps [set_of_list_append])); |
|
851 |
by (rtac (ziprel_is_fun RS spec RS mp) 2); |
|
852 |
by (rtac ziprel_exist 1); |
|
853 |
by Auto_tac; |
|
854 |
qed "zip_in_ziprel"; |
|
855 |
||
856 |
Goal |
|
857 |
"<xs, ys, zs>:ziprel(A,B) ==> zip(xs, ys)=zs"; |
|
858 |
by (rtac (ziprel_is_fun RS spec RS mp) 1); |
|
859 |
by (Blast_tac 1); |
|
860 |
by (blast_tac (claset() addDs [ziprel.dom_subset RS subsetD] |
|
861 |
addIs [zip_in_ziprel]) 1); |
|
862 |
qed "zip_eq"; |
|
863 |
||
864 |
(* zip equations *) |
|
865 |
||
866 |
Goal "ys:list(A) ==> zip(Nil, ys)=Nil"; |
|
867 |
by (res_inst_tac [("A", "A")] zip_eq 1); |
|
868 |
by (auto_tac (claset() addIs ziprel.intrs, simpset())); |
|
869 |
qed "zip_Nil"; |
|
870 |
Addsimps [zip_Nil]; |
|
871 |
||
872 |
Goal "xs:list(A) ==> zip(xs, Nil)=Nil"; |
|
873 |
by (res_inst_tac [("A", "A")] zip_eq 1); |
|
874 |
by (auto_tac (claset() addIs ziprel.intrs, simpset())); |
|
875 |
qed "zip_Nil2"; |
|
876 |
Addsimps [zip_Nil2]; |
|
877 |
||
878 |
Goal "[| xs:list(A); ys:list(B); x:A; y:B |] ==> \ |
|
879 |
\ zip(Cons(x,xs), Cons(y, ys)) = Cons(<x,y>, zip(xs, ys))"; |
|
880 |
by (res_inst_tac [("A", "A")] zip_eq 1); |
|
881 |
by (forw_inst_tac [("ys", "ys")] zip_in_ziprel 1); |
|
882 |
by (auto_tac (claset() addIs ziprel.intrs, simpset())); |
|
883 |
qed "zip_Cons_Cons"; |
|
884 |
Addsimps [zip_Cons_Cons]; |
|
885 |
||
886 |
Goal "xs:list(A) ==> ALL ys:list(B). zip(xs, ys):list(A*B)"; |
|
887 |
by (induct_tac "xs" 1); |
|
888 |
by (Simp_tac 1); |
|
889 |
by (Clarify_tac 1); |
|
890 |
by (eres_inst_tac [("a", "ys")] list.elim 1); |
|
891 |
by Auto_tac; |
|
892 |
qed_spec_mp "zip_type"; |
|
893 |
||
894 |
AddTCs [zip_type]; |
|
895 |
Addsimps [zip_type]; |
|
896 |
||
897 |
(* zip length *) |
|
898 |
Goalw [min_def] "xs:list(A) ==> ALL ys:list(B). length(zip(xs,ys)) = \ |
|
899 |
\ min(length(xs), length(ys))"; |
|
900 |
by (induct_tac "xs" 1); |
|
901 |
by (Clarify_tac 2); |
|
902 |
by (eres_inst_tac [("a", "ys")] list.elim 2); |
|
903 |
by Auto_tac; |
|
904 |
qed_spec_mp "length_zip"; |
|
905 |
Addsimps [length_zip]; |
|
906 |
||
907 |
AddTCs [take_type]; |
|
908 |
Addsimps [take_type]; |
|
909 |
||
910 |
Goal "[| ys:list(A); zs:list(B) |] ==> ALL xs:list(A). zip(xs @ ys, zs) = \ |
|
911 |
\ zip(xs, take(length(xs), zs)) @ zip(ys, drop(length(xs),zs))"; |
|
912 |
by (induct_tac "zs" 1); |
|
913 |
by (Clarify_tac 2); |
|
914 |
by (eres_inst_tac [("a", "xs")] list.elim 2); |
|
915 |
by Auto_tac; |
|
916 |
qed_spec_mp "zip_append1"; |
|
917 |
||
918 |
Goal |
|
919 |
"[| xs:list(A); zs:list(B) |] ==> ALL ys:list(B). zip(xs, ys@zs) = \ |
|
920 |
\ zip(take(length(ys), xs), ys) @ zip(drop(length(ys), xs), zs)"; |
|
921 |
by (induct_tac "xs" 1); |
|
922 |
by (Clarify_tac 2); |
|
923 |
by (eres_inst_tac [("a", "ys")] list.elim 2); |
|
924 |
by Auto_tac; |
|
925 |
qed_spec_mp "zip_append2"; |
|
926 |
||
927 |
Goal |
|
928 |
"[| length(xs) = length(us); length(ys) = length(vs); \ |
|
929 |
\ xs:list(A); us:list(B); ys:list(A); vs:list(B) |] ==> \ |
|
930 |
\ zip(xs@ys,us@vs) = zip(xs, us) @ zip(ys, vs)"; |
|
931 |
by (asm_simp_tac (simpset() addsimps |
|
932 |
[zip_append1, drop_append, diff_self_eq_0]) 1); |
|
933 |
qed_spec_mp "zip_append"; |
|
934 |
Addsimps [zip_append]; |
|
935 |
||
936 |
Goal "ys:list(B) ==> ALL xs:list(A). \ |
|
937 |
\ length(xs) = length(ys) --> zip(rev(xs), rev(ys)) = rev(zip(xs, ys))"; |
|
938 |
by (induct_tac "ys" 1); |
|
939 |
by (Clarify_tac 2); |
|
940 |
by (eres_inst_tac [("a", "xs")] list.elim 2); |
|
941 |
by (auto_tac (claset(), simpset() addsimps [length_rev])); |
|
942 |
qed_spec_mp "zip_rev"; |
|
943 |
Addsimps [zip_rev]; |
|
944 |
||
945 |
Goal |
|
946 |
"ys:list(B) ==> ALL i:nat. ALL xs:list(A). \ |
|
947 |
\ i < length(xs) --> i < length(ys) --> \ |
|
948 |
\ nth(i,zip(xs, ys)) = <nth(i,xs),nth(i, ys)>"; |
|
949 |
by (induct_tac "ys" 1); |
|
950 |
by (Clarify_tac 2); |
|
951 |
by (eres_inst_tac [("a", "xs")] list.elim 2); |
|
952 |
by (auto_tac (claset() addEs [natE], simpset())); |
|
953 |
qed_spec_mp "nth_zip"; |
|
954 |
Addsimps [nth_zip]; |
|
955 |
||
956 |
Goal "[| xs:list(A); ys:list(B); i:nat |] \ |
|
957 |
\ ==> set_of_list(zip(xs, ys)) = \ |
|
958 |
\ {<x, y>:A*B. EX i:nat. i < min(length(xs), length(ys)) \ |
|
959 |
\ & x=nth(i, xs) & y=nth(i, ys)}"; |
|
960 |
by (force_tac (claset() addSIs [Collect_cong], |
|
961 |
simpset() addsimps [lt_min_iff, set_of_list_conv_nth]) 1); |
|
962 |
qed_spec_mp "set_of_list_zip"; |
|
963 |
||
964 |
(** list_update **) |
|
965 |
||
966 |
Goalw [list_update_def] "i:nat ==>list_update(Nil, i, v) = Nil"; |
|
967 |
by Auto_tac; |
|
968 |
qed "list_update_Nil"; |
|
969 |
Addsimps [list_update_Nil]; |
|
970 |
||
971 |
Goalw [list_update_def] |
|
972 |
"list_update(Cons(x, xs), 0, v)= Cons(v, xs)"; |
|
973 |
by Auto_tac; |
|
974 |
qed "list_update_Cons_0"; |
|
975 |
Addsimps [list_update_Cons_0]; |
|
976 |
||
977 |
Goalw [list_update_def] |
|
978 |
"n:nat ==>\ |
|
979 |
\ list_update(Cons(x, xs), succ(n), v)= Cons(x, list_update(xs, n, v))"; |
|
980 |
by Auto_tac; |
|
981 |
qed "list_update_Cons_succ"; |
|
982 |
Addsimps [list_update_Cons_succ]; |
|
983 |
||
984 |
Goal "[| xs:list(A); v:A |] ==> ALL n:nat. list_update(xs, n, v):list(A)"; |
|
985 |
by (induct_tac "xs" 1); |
|
986 |
by (Simp_tac 1); |
|
987 |
by (Clarify_tac 1); |
|
988 |
by (etac natE 1); |
|
989 |
by Auto_tac; |
|
990 |
qed_spec_mp "list_update_type"; |
|
991 |
Addsimps [list_update_type]; |
|
992 |
AddTCs [list_update_type]; |
|
993 |
||
994 |
Goal "xs:list(A) ==> ALL i:nat. length(list_update(xs, i, v))=length(xs)"; |
|
995 |
by (induct_tac "xs" 1); |
|
996 |
by (Simp_tac 1); |
|
997 |
by (Clarify_tac 1); |
|
998 |
by (etac natE 1); |
|
999 |
by Auto_tac; |
|
1000 |
qed_spec_mp "length_list_update"; |
|
1001 |
Addsimps [length_list_update]; |
|
1002 |
||
1003 |
Goal "[| xs:list(A) |] ==> ALL i:nat. ALL j:nat. i < length(xs) --> \ |
|
1004 |
\ nth(j, list_update(xs, i, x)) = (if i=j then x else nth(j, xs))"; |
|
1005 |
by (induct_tac "xs" 1); |
|
1006 |
by (Simp_tac 1); |
|
1007 |
by (Clarify_tac 1); |
|
1008 |
by (etac natE 1); |
|
1009 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
1010 |
by (ALLGOALS(Clarify_tac)); |
|
1011 |
by (etac natE 1); |
|
1012 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
1013 |
by Safe_tac; |
|
1014 |
by (etac natE 2); |
|
1015 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [nth_Cons]))); |
|
1016 |
qed_spec_mp "nth_list_update"; |
|
1017 |
||
1018 |
Goal "[| i < length(xs); xs:list(A); i:nat |] \ |
|
1019 |
\ ==> nth(i, list_update(xs, i,x)) = x"; |
|
1020 |
by (asm_simp_tac (simpset() addsimps [nth_list_update]) 1); |
|
1021 |
qed "nth_list_update_eq"; |
|
1022 |
Addsimps [nth_list_update_eq]; |
|
1023 |
||
1024 |
Goal "xs:list(A) ==> ALL i:nat. ALL j:nat. i ~= j \ |
|
1025 |
\ --> nth(j, list_update(xs, i,x)) = nth(j, xs)"; |
|
1026 |
by (induct_tac "xs" 1); |
|
1027 |
by (Simp_tac 1); |
|
1028 |
by (Clarify_tac 1); |
|
1029 |
by (etac natE 1); |
|
1030 |
by (etac natE 2); |
|
1031 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
1032 |
by (etac natE 1); |
|
1033 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [nth_Cons]))); |
|
1034 |
qed_spec_mp "nth_list_update_neq"; |
|
1035 |
Addsimps [nth_list_update_neq]; |
|
1036 |
||
1037 |
Goal "xs:list(A) ==> ALL i:nat. i < length(xs)\ |
|
1038 |
\ --> list_update(list_update(xs, i, x), i, y) = list_update(xs, i,y)"; |
|
1039 |
by (induct_tac "xs" 1); |
|
1040 |
by (Simp_tac 1); |
|
1041 |
by (Clarify_tac 1); |
|
1042 |
by (etac natE 1); |
|
1043 |
by Auto_tac; |
|
1044 |
qed_spec_mp "list_update_overwrite"; |
|
1045 |
Addsimps [list_update_overwrite]; |
|
1046 |
||
1047 |
Goal "xs:list(A) ==> ALL i:nat. i < length(xs) --> \ |
|
1048 |
\ (list_update(xs, i, x) = xs) <-> (nth(i, xs) = x)"; |
|
1049 |
by (induct_tac "xs" 1); |
|
1050 |
by (Simp_tac 1); |
|
1051 |
by (Clarify_tac 1); |
|
1052 |
by (etac natE 1); |
|
1053 |
by Auto_tac; |
|
1054 |
qed_spec_mp "list_update_same_conv"; |
|
1055 |
||
1056 |
Goal "ys:list(B) ==> ALL i:nat. ALL xy:A*B. ALL xs:list(A). \ |
|
1057 |
\ length(xs) = length(ys) --> \ |
|
1058 |
\ list_update(zip(xs, ys), i, xy) = zip(list_update(xs, i, fst(xy)), \ |
|
1059 |
\ list_update(ys, i, snd(xy)))"; |
|
1060 |
by (induct_tac "ys" 1); |
|
1061 |
by Auto_tac; |
|
1062 |
by (eres_inst_tac [("a", "xc")] list.elim 1); |
|
1063 |
by (auto_tac (claset() addEs [natE], simpset())); |
|
1064 |
qed_spec_mp "update_zip"; |
|
1065 |
||
1066 |
Goal "xs:list(A) ==> ALL i:nat. set_of_list(list_update(xs, i, x)) \ |
|
1067 |
\ <= cons(x, set_of_list(xs))"; |
|
1068 |
by (induct_tac "xs" 1); |
|
1069 |
by (asm_full_simp_tac (simpset() addsimps []) 1); |
|
1070 |
by (rtac ballI 1); |
|
1071 |
by (etac natE 1); |
|
1072 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
1073 |
by Auto_tac; |
|
1074 |
qed_spec_mp "set_update_subset_cons"; |
|
1075 |
||
1076 |
Goal "[| set_of_list(xs) <= A; xs:list(A); x:A; i:nat|] \ |
|
1077 |
\ ==> set_of_list(list_update(xs, i,x)) <= A"; |
|
1078 |
by (rtac subset_trans 1); |
|
1079 |
by (rtac set_update_subset_cons 1); |
|
1080 |
by Auto_tac; |
|
1081 |
qed "set_of_list_update_subsetI"; |
|
1082 |
||
1083 |
(** upt **) |
|
1084 |
||
1085 |
Goal "[| i:nat; j:nat |] \ |
|
1086 |
\ ==> upt(i,j) = (if i<j then Cons(i, upt(succ(i), j)) else Nil)"; |
|
1087 |
by (induct_tac "j" 1); |
|
1088 |
by Auto_tac; |
|
1089 |
by (dtac not_lt_imp_le 1); |
|
1090 |
by (auto_tac (claset() addIs [le_anti_sym], simpset())); |
|
1091 |
qed "upt_rec"; |
|
1092 |
||
1093 |
Goal "[| j le i; i:nat; j:nat |] ==> upt(i,j) = Nil"; |
|
1094 |
by (stac upt_rec 1); |
|
1095 |
by Auto_tac; |
|
1096 |
by (auto_tac (claset(), simpset() addsimps [le_iff])); |
|
1097 |
by (dtac (lt_asym RS notE) 1); |
|
1098 |
by Auto_tac; |
|
1099 |
qed "upt_conv_Nil"; |
|
1100 |
Addsimps [upt_conv_Nil]; |
|
1101 |
||
1102 |
(*Only needed if upt_Suc is deleted from the simpset*) |
|
1103 |
Goal "[| i le j; i:nat; j:nat |] ==> upt(i,succ(j)) = upt(i, j)@[j]"; |
|
1104 |
by (Asm_simp_tac 1); |
|
1105 |
qed "upt_succ_append"; |
|
1106 |
||
1107 |
Goal "[| i<j; i:nat; j:nat |] ==> upt(i,j) = Cons(i,upt(succ(i),j))"; |
|
1108 |
by (rtac trans 1); |
|
1109 |
by (stac upt_rec 1); |
|
1110 |
by (rtac refl 4); |
|
1111 |
by Auto_tac; |
|
1112 |
qed "upt_conv_Cons"; |
|
1113 |
||
1114 |
Goal "[| i:nat; j:nat |] ==> upt(i,j):list(nat)"; |
|
1115 |
by (induct_tac "j" 1); |
|
1116 |
by Auto_tac; |
|
1117 |
qed "upt_type"; |
|
1118 |
||
1119 |
AddTCs [upt_type]; |
|
1120 |
Addsimps [upt_type]; |
|
1121 |
||
1122 |
(*LOOPS as a simprule, since j<=j*) |
|
1123 |
Goal "[| i le j; i:nat; j:nat; k:nat |] ==> \ |
|
1124 |
\ upt(i, j #+k) = upt(i,j)@upt(j,j#+k)"; |
|
1125 |
by (induct_tac "k" 1); |
|
1126 |
by (auto_tac (claset(), simpset() addsimps [app_assoc, app_type])); |
|
1127 |
by (res_inst_tac [("j", "j")] le_trans 1); |
|
1128 |
by Auto_tac; |
|
1129 |
qed "upt_add_eq_append"; |
|
1130 |
||
1131 |
Goal "[| i:nat; j:nat |] ==>length(upt(i,j)) = j #- i"; |
|
1132 |
by (induct_tac "j" 1); |
|
1133 |
by (rtac sym 2); |
|
1134 |
by (auto_tac (claset() addSDs [not_lt_imp_le], |
|
1135 |
simpset() addsimps [length_app, diff_succ, diff_is_0_iff])); |
|
1136 |
qed "length_upt"; |
|
1137 |
Addsimps [length_upt]; |
|
1138 |
||
1139 |
Goal "[| i:nat; j:nat; k:nat |] ==> \ |
|
1140 |
\ i #+ k < j --> nth(k, upt(i,j)) = i #+ k"; |
|
1141 |
by (induct_tac "j" 1); |
|
1142 |
by (Asm_simp_tac 1); |
|
1143 |
by (asm_full_simp_tac (simpset() addsimps [nth_append,lt_succ_iff] |
|
1144 |
addsplits [nat_diff_split]) 1); |
|
1145 |
by Safe_tac; |
|
1146 |
by (auto_tac (claset() addSDs [not_lt_imp_le], |
|
1147 |
simpset() addsimps [nth_append, diff_self_eq_0, |
|
1148 |
less_diff_conv, add_commute])); |
|
1149 |
by (dres_inst_tac [("j", "x")] lt_trans2 1); |
|
1150 |
by Auto_tac; |
|
1151 |
qed_spec_mp "nth_upt"; |
|
1152 |
Addsimps [nth_upt]; |
|
1153 |
||
1154 |
Goal "[| m:nat; n:nat |] ==> \ |
|
1155 |
\ ALL i:nat. i #+ m le n --> take(m, upt(i,n)) = upt(i,i#+m)"; |
|
1156 |
by (induct_tac "m" 1); |
|
1157 |
by (asm_simp_tac (simpset() addsimps [take_0]) 1); |
|
1158 |
by (Clarify_tac 1); |
|
1159 |
by (stac upt_rec 1); |
|
1160 |
by (rtac sym 3); |
|
1161 |
by (stac upt_rec 3); |
|
1162 |
by (ALLGOALS(asm_full_simp_tac (simpset() delsimps (thms"upt.simps")))); |
|
1163 |
by (res_inst_tac [("j", "succ(i #+ x)")] lt_trans2 1); |
|
1164 |
by Auto_tac; |
|
1165 |
qed_spec_mp "take_upt"; |
|
1166 |
Addsimps [take_upt]; |
|
1167 |
||
1168 |
Goal "[| m:nat; n:nat |] ==> map(succ, upt(m,n))= upt(succ(m), succ(n))"; |
|
1169 |
by (induct_tac "n" 1); |
|
1170 |
by (auto_tac (claset(), simpset() addsimps [map_app_distrib])); |
|
1171 |
qed "map_succ_upt"; |
|
1172 |
||
1173 |
Goal "xs:list(A) ==> \ |
|
1174 |
\ ALL n:nat. n < length(xs) --> nth(n, map(f, xs)) = f(nth(n, xs))"; |
|
1175 |
by (induct_tac "xs" 1); |
|
1176 |
by (Asm_full_simp_tac 1); |
|
1177 |
by (rtac ballI 1); |
|
1178 |
by (induct_tac "n" 1); |
|
1179 |
by Auto_tac; |
|
1180 |
qed_spec_mp "nth_map"; |
|
1181 |
Addsimps [nth_map]; |
|
1182 |
||
1183 |
Goal "[| m:nat; n:nat |] ==> \ |
|
1184 |
\ ALL i:nat. i < n #- m --> nth(i, map(f, upt(m,n))) = f(m #+ i)"; |
|
1185 |
by (res_inst_tac [("n", "m"), ("m", "n")] diff_induct 1); |
|
1186 |
by (stac (map_succ_upt RS sym) 5); |
|
1187 |
by (ALLGOALS(Asm_full_simp_tac)); |
|
1188 |
by (ALLGOALS(Clarify_tac)); |
|
1189 |
by (subgoal_tac "xa < length(upt(0, x))" 1); |
|
1190 |
by (Asm_simp_tac 2); |
|
1191 |
by (subgoal_tac "xa < length(upt(y, x))" 2); |
|
1192 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [map_compose, |
|
1193 |
nth_map, add_commute, less_diff_conv]))); |
|
1194 |
by (res_inst_tac [("j", "succ(xa #+ y)")] lt_trans2 1); |
|
1195 |
by Auto_tac; |
|
1196 |
qed_spec_mp "nth_map_upt"; |
|
1197 |
||
1198 |
(** sublist (a generalization of nth to sets) **) |
|
1199 |
||
1200 |
Goalw [sublist_def] "xs:list(A) ==>sublist(xs, 0) =Nil"; |
|
1201 |
by Auto_tac; |
|
1202 |
qed "sublist_0"; |
|
1203 |
||
1204 |
Goalw [sublist_def] "sublist(Nil, A) = Nil"; |
|
1205 |
by Auto_tac; |
|
1206 |
qed "sublist_Nil"; |
|
1207 |
||
1208 |
AddTCs [filter_type]; |
|
1209 |
Addsimps [filter_type]; |
|
1210 |
||
1211 |
Goal "[| xs:list(B); i:nat |] ==>\ |
|
1212 |
\ map(fst, filter(%p. snd(p):A, zip(xs, upt(i,i #+ length(xs))))) = \ |
|
1213 |
\ map(fst, filter(%p. snd(p):nat & snd(p) #+ i:A, zip(xs,upt(0,length(xs)))))"; |
|
1214 |
by (etac list_append_induct 1); |
|
1215 |
by (Asm_simp_tac 1); |
|
1216 |
by (auto_tac (claset(), simpset() addsimps |
|
1217 |
[add_commute, length_app, filter_append, map_app_distrib])); |
|
1218 |
qed "sublist_shift_lemma"; |
|
1219 |
||
1220 |
Goalw [sublist_def] |
|
1221 |
"xs:list(B) ==> sublist(xs, A):list(B)"; |
|
1222 |
by (induct_tac "xs" 1); |
|
1223 |
by (auto_tac (claset(), simpset() addsimps [filter_append, map_app_distrib])); |
|
1224 |
by (auto_tac (claset() addIs [map_type,filter_type,zip_type], simpset())); |
|
1225 |
qed "sublist_type"; |
|
1226 |
||
1227 |
AddTCs [sublist_type]; |
|
1228 |
Addsimps [sublist_type]; |
|
1229 |
||
1230 |
Goal "[| i:nat; j:nat |] ==> upt(0, i #+ j) = upt(0, i) @ upt(i, i #+ j)"; |
|
1231 |
by (asm_simp_tac (simpset() addsimps |
|
1232 |
[inst "i" "0" upt_add_eq_append, nat_0_le]) 1); |
|
1233 |
qed "upt_add_eq_append2"; |
|
1234 |
||
1235 |
Goalw [sublist_def] |
|
1236 |
"[| xs:list(B); ys:list(B) |] ==> \ |
|
1237 |
\ sublist(xs@ys, A) = sublist(xs, A) @ sublist(ys, {j:nat. j #+ length(xs): A})"; |
|
1238 |
by (eres_inst_tac [("l", "ys")] list_append_induct 1); |
|
1239 |
by (Asm_simp_tac 1); |
|
1240 |
by (asm_simp_tac (simpset() addsimps [upt_add_eq_append2, |
|
1241 |
zip_append, length_app, app_assoc RS sym]) 1); |
|
1242 |
by (auto_tac (claset(), simpset() addsimps [sublist_shift_lemma, |
|
1243 |
length_type, map_app_distrib, app_assoc])); |
|
1244 |
by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [add_commute]))); |
|
1245 |
qed "sublist_append"; |
|
1246 |
||
1247 |
Addsimps [sublist_0, sublist_Nil]; |
|
1248 |
||
1249 |
Goal "[| xs:list(B); x:B |] ==> \ |
|
1250 |
\ sublist(Cons(x, xs), A) = (if 0:A then [x] else []) @ sublist(xs, {j:nat. succ(j) : A})"; |
|
1251 |
by (eres_inst_tac [("l", "xs")] list_append_induct 1); |
|
1252 |
by (asm_simp_tac (simpset() addsimps [sublist_def]) 1); |
|
1253 |
by (asm_simp_tac (simpset() delsimps (thms "op @.simps") |
|
1254 |
addsimps [(hd (tl (thms "op @.simps"))) RS sym, sublist_append]) 1); |
|
1255 |
by Auto_tac; |
|
1256 |
qed "sublist_Cons"; |
|
1257 |
||
1258 |
Goal "sublist([x], A) = (if 0 : A then [x] else [])"; |
|
1259 |
by (simp_tac (simpset() addsimps [sublist_Cons]) 1); |
|
1260 |
qed "sublist_singleton"; |
|
1261 |
Addsimps [sublist_singleton]; |
|
1262 |
||
1263 |
Goalw [less_than_def] |
|
1264 |
"[| xs:list(A); n:nat |] ==> sublist(xs, less_than(n)) = take(n,xs)"; |
|
1265 |
by (eres_inst_tac [("l", "xs")] list_append_induct 1); |
|
1266 |
by (asm_simp_tac (simpset() addsplits [nat_diff_split] |
|
1267 |
addsimps [sublist_append]) 2); |
|
1268 |
by Auto_tac; |
|
1269 |
by (subgoal_tac "n #- length(y) = 0" 1); |
|
1270 |
by (Asm_simp_tac 1); |
|
1271 |
by (auto_tac (claset() addSDs [not_lt_imp_le], |
|
1272 |
simpset() addsimps [diff_is_0_iff])); |
|
1273 |
qed "sublist_upt_eq_take"; |
|
1274 |
Addsimps [sublist_upt_eq_take]; |
|
1275 |