src/HOL/List.ML
author nipkow
Mon Jul 06 14:03:25 1998 +0200 (1998-07-06)
changeset 5129 99ffd3dfb180
parent 5122 229190f9f303
child 5132 24f992a25adc
permissions -rw-r--r--
Converted to Auto_tac
     1 (*  Title:      HOL/List
     2     ID:         $Id$
     3     Author:     Tobias Nipkow
     4     Copyright   1994 TU Muenchen
     5 
     6 List lemmas
     7 *)
     8 
     9 Goal "!x. xs ~= x#xs";
    10 by (induct_tac "xs" 1);
    11 by (Auto_tac);
    12 qed_spec_mp "not_Cons_self";
    13 bind_thm("not_Cons_self2",not_Cons_self RS not_sym);
    14 Addsimps [not_Cons_self,not_Cons_self2];
    15 
    16 Goal "(xs ~= []) = (? y ys. xs = y#ys)";
    17 by (induct_tac "xs" 1);
    18 by (Auto_tac);
    19 qed "neq_Nil_conv";
    20 
    21 (* Induction over the length of a list: *)
    22 val [prem] = Goal
    23   "(!!xs. (!ys. length ys < length xs --> P ys) ==> P xs) ==> P(xs)";
    24 by(rtac measure_induct 1 THEN etac prem 1);
    25 qed "length_induct";
    26 
    27 
    28 (** "lists": the list-forming operator over sets **)
    29 
    30 Goalw lists.defs "A<=B ==> lists A <= lists B";
    31 by (rtac lfp_mono 1);
    32 by (REPEAT (ares_tac basic_monos 1));
    33 qed "lists_mono";
    34 
    35 val listsE = lists.mk_cases list.simps  "x#l : lists A";
    36 AddSEs [listsE];
    37 AddSIs lists.intrs;
    38 
    39 Goal "l: lists A ==> l: lists B --> l: lists (A Int B)";
    40 by (etac lists.induct 1);
    41 by (ALLGOALS Blast_tac);
    42 qed_spec_mp "lists_IntI";
    43 
    44 Goal "lists (A Int B) = lists A Int lists B";
    45 by (rtac (mono_Int RS equalityI) 1);
    46 by (simp_tac (simpset() addsimps [mono_def, lists_mono]) 1);
    47 by (blast_tac (claset() addSIs [lists_IntI]) 1);
    48 qed "lists_Int_eq";
    49 Addsimps [lists_Int_eq];
    50 
    51 
    52 (**  Case analysis **)
    53 section "Case analysis";
    54 
    55 val prems = Goal "[| P([]); !!x xs. P(x#xs) |] ==> P(xs)";
    56 by (induct_tac "xs" 1);
    57 by (REPEAT(resolve_tac prems 1));
    58 qed "list_cases";
    59 
    60 Goal "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
    61 by (induct_tac "xs" 1);
    62 by (Blast_tac 1);
    63 by (Blast_tac 1);
    64 bind_thm("list_eq_cases",
    65   impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
    66 
    67 (** length **)
    68 (* needs to come before "@" because of thm append_eq_append_conv *)
    69 
    70 section "length";
    71 
    72 Goal "length(xs@ys) = length(xs)+length(ys)";
    73 by (induct_tac "xs" 1);
    74 by (Auto_tac);
    75 qed"length_append";
    76 Addsimps [length_append];
    77 
    78 Goal "length (map f xs) = length xs";
    79 by (induct_tac "xs" 1);
    80 by (Auto_tac);
    81 qed "length_map";
    82 Addsimps [length_map];
    83 
    84 Goal "length(rev xs) = length(xs)";
    85 by (induct_tac "xs" 1);
    86 by (Auto_tac);
    87 qed "length_rev";
    88 Addsimps [length_rev];
    89 
    90 Goal "xs ~= [] ==> length(tl xs) = (length xs) - 1";
    91 by (exhaust_tac "xs" 1);
    92 by (Auto_tac);
    93 qed "length_tl";
    94 Addsimps [length_tl];
    95 
    96 Goal "(length xs = 0) = (xs = [])";
    97 by (induct_tac "xs" 1);
    98 by (Auto_tac);
    99 qed "length_0_conv";
   100 AddIffs [length_0_conv];
   101 
   102 Goal "(0 = length xs) = (xs = [])";
   103 by (induct_tac "xs" 1);
   104 by (Auto_tac);
   105 qed "zero_length_conv";
   106 AddIffs [zero_length_conv];
   107 
   108 Goal "(0 < length xs) = (xs ~= [])";
   109 by (induct_tac "xs" 1);
   110 by (Auto_tac);
   111 qed "length_greater_0_conv";
   112 AddIffs [length_greater_0_conv];
   113 
   114 (** @ - append **)
   115 
   116 section "@ - append";
   117 
   118 Goal "(xs@ys)@zs = xs@(ys@zs)";
   119 by (induct_tac "xs" 1);
   120 by (Auto_tac);
   121 qed "append_assoc";
   122 Addsimps [append_assoc];
   123 
   124 Goal "xs @ [] = xs";
   125 by (induct_tac "xs" 1);
   126 by (Auto_tac);
   127 qed "append_Nil2";
   128 Addsimps [append_Nil2];
   129 
   130 Goal "(xs@ys = []) = (xs=[] & ys=[])";
   131 by (induct_tac "xs" 1);
   132 by (Auto_tac);
   133 qed "append_is_Nil_conv";
   134 AddIffs [append_is_Nil_conv];
   135 
   136 Goal "([] = xs@ys) = (xs=[] & ys=[])";
   137 by (induct_tac "xs" 1);
   138 by (Auto_tac);
   139 qed "Nil_is_append_conv";
   140 AddIffs [Nil_is_append_conv];
   141 
   142 Goal "(xs @ ys = xs) = (ys=[])";
   143 by (induct_tac "xs" 1);
   144 by (Auto_tac);
   145 qed "append_self_conv";
   146 
   147 Goal "(xs = xs @ ys) = (ys=[])";
   148 by (induct_tac "xs" 1);
   149 by (Auto_tac);
   150 qed "self_append_conv";
   151 AddIffs [append_self_conv,self_append_conv];
   152 
   153 Goal "!ys. length xs = length ys | length us = length vs \
   154 \              --> (xs@us = ys@vs) = (xs=ys & us=vs)";
   155 by (induct_tac "xs" 1);
   156  by (rtac allI 1);
   157  by (exhaust_tac "ys" 1);
   158   by (Asm_simp_tac 1);
   159  by (fast_tac (claset() addIs [less_add_Suc2] addss simpset()
   160                       addEs [less_not_refl2 RSN (2,rev_notE)]) 1);
   161 by (rtac allI 1);
   162 by (exhaust_tac "ys" 1);
   163  by (fast_tac (claset() addIs [less_add_Suc2] addss simpset()
   164                       addEs [(less_not_refl2 RS not_sym) RSN (2,rev_notE)]) 1);
   165 by (Asm_simp_tac 1);
   166 qed_spec_mp "append_eq_append_conv";
   167 Addsimps [append_eq_append_conv];
   168 
   169 Goal "(xs @ ys = xs @ zs) = (ys=zs)";
   170 by (Simp_tac 1);
   171 qed "same_append_eq";
   172 
   173 Goal "(xs @ [x] = ys @ [y]) = (xs = ys & x = y)"; 
   174 by (Simp_tac 1);
   175 qed "append1_eq_conv";
   176 
   177 Goal "(ys @ xs = zs @ xs) = (ys=zs)";
   178 by (Simp_tac 1);
   179 qed "append_same_eq";
   180 
   181 AddSIs
   182  [same_append_eq RS iffD2, append1_eq_conv RS iffD2, append_same_eq RS iffD2];
   183 AddSDs
   184  [same_append_eq RS iffD1, append1_eq_conv RS iffD1, append_same_eq RS iffD1];
   185 
   186 Goal "(xs @ ys = ys) = (xs=[])";
   187 by(cut_inst_tac [("zs","[]")] append_same_eq 1);
   188 by (Auto_tac);
   189 qed "append_self_conv2";
   190 
   191 Goal "(ys = xs @ ys) = (xs=[])";
   192 by(simp_tac (simpset() addsimps
   193      [simplify (simpset()) (read_instantiate[("ys","[]")]append_same_eq)]) 1);
   194 by(Blast_tac 1);
   195 qed "self_append_conv2";
   196 AddIffs [append_self_conv2,self_append_conv2];
   197 
   198 Goal "xs ~= [] --> hd xs # tl xs = xs";
   199 by (induct_tac "xs" 1);
   200 by (Auto_tac);
   201 qed_spec_mp "hd_Cons_tl";
   202 Addsimps [hd_Cons_tl];
   203 
   204 Goal "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
   205 by (induct_tac "xs" 1);
   206 by (Auto_tac);
   207 qed "hd_append";
   208 
   209 Goal "xs ~= [] ==> hd(xs @ ys) = hd xs";
   210 by (asm_simp_tac (simpset() addsimps [hd_append]
   211                            addsplits [split_list_case]) 1);
   212 qed "hd_append2";
   213 Addsimps [hd_append2];
   214 
   215 Goal "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)";
   216 by (simp_tac (simpset() addsplits [split_list_case]) 1);
   217 qed "tl_append";
   218 
   219 Goal "xs ~= [] ==> tl(xs @ ys) = (tl xs) @ ys";
   220 by (asm_simp_tac (simpset() addsimps [tl_append]
   221                            addsplits [split_list_case]) 1);
   222 qed "tl_append2";
   223 Addsimps [tl_append2];
   224 
   225 
   226 (** map **)
   227 
   228 section "map";
   229 
   230 Goal
   231   "(!x. x : set xs --> f x = g x) --> map f xs = map g xs";
   232 by (induct_tac "xs" 1);
   233 by (Auto_tac);
   234 bind_thm("map_ext", impI RS (allI RS (result() RS mp)));
   235 
   236 Goal "map (%x. x) = (%xs. xs)";
   237 by (rtac ext 1);
   238 by (induct_tac "xs" 1);
   239 by (Auto_tac);
   240 qed "map_ident";
   241 Addsimps[map_ident];
   242 
   243 Goal "map f (xs@ys) = map f xs @ map f ys";
   244 by (induct_tac "xs" 1);
   245 by (Auto_tac);
   246 qed "map_append";
   247 Addsimps[map_append];
   248 
   249 Goalw [o_def] "map (f o g) xs = map f (map g xs)";
   250 by (induct_tac "xs" 1);
   251 by (Auto_tac);
   252 qed "map_compose";
   253 Addsimps[map_compose];
   254 
   255 Goal "rev(map f xs) = map f (rev xs)";
   256 by (induct_tac "xs" 1);
   257 by (Auto_tac);
   258 qed "rev_map";
   259 
   260 (* a congruence rule for map: *)
   261 Goal
   262  "(xs=ys) --> (!x. x : set ys --> f x = g x) --> map f xs = map g ys";
   263 by (rtac impI 1);
   264 by (hyp_subst_tac 1);
   265 by (induct_tac "ys" 1);
   266 by (Auto_tac);
   267 val lemma = result();
   268 bind_thm("map_cong",impI RSN (2,allI RSN (2,lemma RS mp RS mp)));
   269 
   270 Goal "(map f xs = []) = (xs = [])";
   271 by (induct_tac "xs" 1);
   272 by (Auto_tac);
   273 qed "map_is_Nil_conv";
   274 AddIffs [map_is_Nil_conv];
   275 
   276 Goal "([] = map f xs) = (xs = [])";
   277 by (induct_tac "xs" 1);
   278 by (Auto_tac);
   279 qed "Nil_is_map_conv";
   280 AddIffs [Nil_is_map_conv];
   281 
   282 
   283 (** rev **)
   284 
   285 section "rev";
   286 
   287 Goal "rev(xs@ys) = rev(ys) @ rev(xs)";
   288 by (induct_tac "xs" 1);
   289 by (Auto_tac);
   290 qed "rev_append";
   291 Addsimps[rev_append];
   292 
   293 Goal "rev(rev l) = l";
   294 by (induct_tac "l" 1);
   295 by (Auto_tac);
   296 qed "rev_rev_ident";
   297 Addsimps[rev_rev_ident];
   298 
   299 Goal "(rev xs = []) = (xs = [])";
   300 by (induct_tac "xs" 1);
   301 by (Auto_tac);
   302 qed "rev_is_Nil_conv";
   303 AddIffs [rev_is_Nil_conv];
   304 
   305 Goal "([] = rev xs) = (xs = [])";
   306 by (induct_tac "xs" 1);
   307 by (Auto_tac);
   308 qed "Nil_is_rev_conv";
   309 AddIffs [Nil_is_rev_conv];
   310 
   311 val prems = Goal "[| P []; !!x xs. P xs ==> P(xs@[x]) |] ==> P xs";
   312 by(stac (rev_rev_ident RS sym) 1);
   313 br(read_instantiate [("P","%xs. ?P(rev xs)")]list.induct)1;
   314 by(ALLGOALS Simp_tac);
   315 brs prems 1;
   316 bes prems 1;
   317 qed "rev_induct";
   318 
   319 Goal  "(xs = [] --> P) -->  (!ys y. xs = ys@[y] --> P) --> P";
   320 by(res_inst_tac [("xs","xs")] rev_induct 1);
   321 by(Auto_tac);
   322 bind_thm ("rev_exhaust",
   323   impI RSN (2,allI RSN (2,allI RSN (2,impI RS (result() RS mp RS mp)))));
   324 
   325 
   326 (** mem **)
   327 
   328 section "mem";
   329 
   330 Goal "x mem (xs@ys) = (x mem xs | x mem ys)";
   331 by (induct_tac "xs" 1);
   332 by (Auto_tac);
   333 qed "mem_append";
   334 Addsimps[mem_append];
   335 
   336 Goal "x mem [x:xs. P(x)] = (x mem xs & P(x))";
   337 by (induct_tac "xs" 1);
   338 by (Auto_tac);
   339 qed "mem_filter";
   340 Addsimps[mem_filter];
   341 
   342 (** set **)
   343 
   344 section "set";
   345 
   346 Goal "set (xs@ys) = (set xs Un set ys)";
   347 by (induct_tac "xs" 1);
   348 by (Auto_tac);
   349 qed "set_append";
   350 Addsimps[set_append];
   351 
   352 Goal "(x mem xs) = (x: set xs)";
   353 by (induct_tac "xs" 1);
   354 by (Auto_tac);
   355 qed "set_mem_eq";
   356 
   357 Goal "set l <= set (x#l)";
   358 by (Auto_tac);
   359 qed "set_subset_Cons";
   360 
   361 Goal "(set xs = {}) = (xs = [])";
   362 by (induct_tac "xs" 1);
   363 by (Auto_tac);
   364 qed "set_empty";
   365 Addsimps [set_empty];
   366 
   367 Goal "set(rev xs) = set(xs)";
   368 by (induct_tac "xs" 1);
   369 by (Auto_tac);
   370 qed "set_rev";
   371 Addsimps [set_rev];
   372 
   373 Goal "set(map f xs) = f``(set xs)";
   374 by (induct_tac "xs" 1);
   375 by (Auto_tac);
   376 qed "set_map";
   377 Addsimps [set_map];
   378 
   379 Goal "(x : set(filter P xs)) = (x : set xs & P x)";
   380 by (induct_tac "xs" 1);
   381 by (Auto_tac);
   382 qed "in_set_filter";
   383 Addsimps [in_set_filter];
   384 
   385 
   386 (** list_all **)
   387 
   388 section "list_all";
   389 
   390 Goal "list_all (%x. True) xs = True";
   391 by (induct_tac "xs" 1);
   392 by (Auto_tac);
   393 qed "list_all_True";
   394 Addsimps [list_all_True];
   395 
   396 Goal "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
   397 by (induct_tac "xs" 1);
   398 by (Auto_tac);
   399 qed "list_all_append";
   400 Addsimps [list_all_append];
   401 
   402 Goal "list_all P xs = (!x. x mem xs --> P(x))";
   403 by (induct_tac "xs" 1);
   404 by (Auto_tac);
   405 qed "list_all_mem_conv";
   406 
   407 
   408 (** filter **)
   409 
   410 section "filter";
   411 
   412 Goal "filter P (xs@ys) = filter P xs @ filter P ys";
   413 by (induct_tac "xs" 1);
   414 by (Auto_tac);
   415 qed "filter_append";
   416 Addsimps [filter_append];
   417 
   418 Goal "filter (%x. True) xs = xs";
   419 by (induct_tac "xs" 1);
   420 by (Auto_tac);
   421 qed "filter_True";
   422 Addsimps [filter_True];
   423 
   424 Goal "filter (%x. False) xs = []";
   425 by (induct_tac "xs" 1);
   426 by (Auto_tac);
   427 qed "filter_False";
   428 Addsimps [filter_False];
   429 
   430 Goal "length (filter P xs) <= length xs";
   431 by (induct_tac "xs" 1);
   432 by (Auto_tac);
   433 qed "length_filter";
   434 
   435 
   436 (** concat **)
   437 
   438 section "concat";
   439 
   440 Goal  "concat(xs@ys) = concat(xs)@concat(ys)";
   441 by (induct_tac "xs" 1);
   442 by (Auto_tac);
   443 qed"concat_append";
   444 Addsimps [concat_append];
   445 
   446 Goal "(concat xss = []) = (!xs:set xss. xs=[])";
   447 by (induct_tac "xss" 1);
   448 by (Auto_tac);
   449 qed "concat_eq_Nil_conv";
   450 AddIffs [concat_eq_Nil_conv];
   451 
   452 Goal "([] = concat xss) = (!xs:set xss. xs=[])";
   453 by (induct_tac "xss" 1);
   454 by (Auto_tac);
   455 qed "Nil_eq_concat_conv";
   456 AddIffs [Nil_eq_concat_conv];
   457 
   458 Goal  "set(concat xs) = Union(set `` set xs)";
   459 by (induct_tac "xs" 1);
   460 by (Auto_tac);
   461 qed"set_concat";
   462 Addsimps [set_concat];
   463 
   464 Goal "map f (concat xs) = concat (map (map f) xs)"; 
   465 by (induct_tac "xs" 1);
   466 by (Auto_tac);
   467 qed "map_concat";
   468 
   469 Goal "filter p (concat xs) = concat (map (filter p) xs)"; 
   470 by (induct_tac "xs" 1);
   471 by (Auto_tac);
   472 qed"filter_concat"; 
   473 
   474 Goal "rev(concat xs) = concat (map rev (rev xs))";
   475 by (induct_tac "xs" 1);
   476 by (Auto_tac);
   477 qed "rev_concat";
   478 
   479 (** nth **)
   480 
   481 section "nth";
   482 
   483 Goal
   484   "!xs. (xs@ys)!n = (if n < length xs then xs!n else ys!(n - length xs))";
   485 by (nat_ind_tac "n" 1);
   486  by (Asm_simp_tac 1);
   487  by (rtac allI 1);
   488  by (exhaust_tac "xs" 1);
   489   by (Auto_tac);
   490 qed_spec_mp "nth_append";
   491 
   492 Goal "!n. n < length xs --> (map f xs)!n = f(xs!n)";
   493 by (induct_tac "xs" 1);
   494 (* case [] *)
   495 by (Asm_full_simp_tac 1);
   496 (* case x#xl *)
   497 by (rtac allI 1);
   498 by (nat_ind_tac "n" 1);
   499 by (Auto_tac);
   500 qed_spec_mp "nth_map";
   501 Addsimps [nth_map];
   502 
   503 Goal "!n. n < length xs --> list_all P xs --> P(xs!n)";
   504 by (induct_tac "xs" 1);
   505 (* case [] *)
   506 by (Simp_tac 1);
   507 (* case x#xl *)
   508 by (rtac allI 1);
   509 by (nat_ind_tac "n" 1);
   510 by (Auto_tac);
   511 qed_spec_mp "list_all_nth";
   512 
   513 Goal "!n. n < length xs --> xs!n mem xs";
   514 by (induct_tac "xs" 1);
   515 (* case [] *)
   516 by (Simp_tac 1);
   517 (* case x#xl *)
   518 by (rtac allI 1);
   519 by (nat_ind_tac "n" 1);
   520 (* case 0 *)
   521 by (Asm_full_simp_tac 1);
   522 (* case Suc x *)
   523 by (Asm_full_simp_tac 1);
   524 qed_spec_mp "nth_mem";
   525 Addsimps [nth_mem];
   526 
   527 (** list update **)
   528 
   529 section "list update";
   530 
   531 Goal "!i. length(xs[i:=x]) = length xs";
   532 by (induct_tac "xs" 1);
   533 by (Simp_tac 1);
   534 by (asm_full_simp_tac (simpset() addsplits [split_nat_case]) 1);
   535 qed_spec_mp "length_list_update";
   536 Addsimps [length_list_update];
   537 
   538 
   539 (** last & butlast **)
   540 
   541 Goal "last(xs@[x]) = x";
   542 by (induct_tac "xs" 1);
   543 by (Auto_tac);
   544 qed "last_snoc";
   545 Addsimps [last_snoc];
   546 
   547 Goal "butlast(xs@[x]) = xs";
   548 by (induct_tac "xs" 1);
   549 by (Auto_tac);
   550 qed "butlast_snoc";
   551 Addsimps [butlast_snoc];
   552 
   553 Goal "length(butlast xs) = length xs - 1";
   554 by (res_inst_tac [("xs","xs")] rev_induct 1);
   555 by (Auto_tac);
   556 qed "length_butlast";
   557 Addsimps [length_butlast];
   558 
   559 Goal
   560   "!ys. butlast (xs@ys) = (if ys=[] then butlast xs else xs@butlast ys)";
   561 by (induct_tac "xs" 1);
   562 by (Auto_tac);
   563 qed_spec_mp "butlast_append";
   564 
   565 Goal "x:set(butlast xs) --> x:set xs";
   566 by (induct_tac "xs" 1);
   567 by (Auto_tac);
   568 qed_spec_mp "in_set_butlastD";
   569 
   570 Goal "x:set(butlast xs) ==> x:set(butlast(xs@ys))";
   571 by (asm_simp_tac (simpset() addsimps [butlast_append]) 1);
   572 by (blast_tac (claset() addDs [in_set_butlastD]) 1);
   573 qed "in_set_butlast_appendI1";
   574 
   575 Goal "x:set(butlast ys) ==> x:set(butlast(xs@ys))";
   576 by (asm_simp_tac (simpset() addsimps [butlast_append]) 1);
   577 by (Clarify_tac 1);
   578 by (Full_simp_tac 1);
   579 qed "in_set_butlast_appendI2";
   580 
   581 (** take  & drop **)
   582 section "take & drop";
   583 
   584 Goal "take 0 xs = []";
   585 by (induct_tac "xs" 1);
   586 by (Auto_tac);
   587 qed "take_0";
   588 
   589 Goal "drop 0 xs = xs";
   590 by (induct_tac "xs" 1);
   591 by (Auto_tac);
   592 qed "drop_0";
   593 
   594 Goal "take (Suc n) (x#xs) = x # take n xs";
   595 by (Simp_tac 1);
   596 qed "take_Suc_Cons";
   597 
   598 Goal "drop (Suc n) (x#xs) = drop n xs";
   599 by (Simp_tac 1);
   600 qed "drop_Suc_Cons";
   601 
   602 Delsimps [take_Cons,drop_Cons];
   603 Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons];
   604 
   605 Goal "!xs. length(take n xs) = min (length xs) n";
   606 by (nat_ind_tac "n" 1);
   607  by (Auto_tac);
   608 by (exhaust_tac "xs" 1);
   609  by (Auto_tac);
   610 qed_spec_mp "length_take";
   611 Addsimps [length_take];
   612 
   613 Goal "!xs. length(drop n xs) = (length xs - n)";
   614 by (nat_ind_tac "n" 1);
   615  by (Auto_tac);
   616 by (exhaust_tac "xs" 1);
   617  by (Auto_tac);
   618 qed_spec_mp "length_drop";
   619 Addsimps [length_drop];
   620 
   621 Goal "!xs. length xs <= n --> take n xs = xs";
   622 by (nat_ind_tac "n" 1);
   623  by (Auto_tac);
   624 by (exhaust_tac "xs" 1);
   625  by (Auto_tac);
   626 qed_spec_mp "take_all";
   627 
   628 Goal "!xs. length xs <= n --> drop n xs = []";
   629 by (nat_ind_tac "n" 1);
   630  by (Auto_tac);
   631 by (exhaust_tac "xs" 1);
   632  by (Auto_tac);
   633 qed_spec_mp "drop_all";
   634 
   635 Goal 
   636   "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)";
   637 by (nat_ind_tac "n" 1);
   638  by (Auto_tac);
   639 by (exhaust_tac "xs" 1);
   640  by (Auto_tac);
   641 qed_spec_mp "take_append";
   642 Addsimps [take_append];
   643 
   644 Goal "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; 
   645 by (nat_ind_tac "n" 1);
   646  by (Auto_tac);
   647 by (exhaust_tac "xs" 1);
   648  by (Auto_tac);
   649 qed_spec_mp "drop_append";
   650 Addsimps [drop_append];
   651 
   652 Goal "!xs n. take n (take m xs) = take (min n m) xs"; 
   653 by (nat_ind_tac "m" 1);
   654  by (Auto_tac);
   655 by (exhaust_tac "xs" 1);
   656  by (Auto_tac);
   657 by (exhaust_tac "n" 1);
   658  by (Auto_tac);
   659 qed_spec_mp "take_take";
   660 
   661 Goal "!xs. drop n (drop m xs) = drop (n + m) xs"; 
   662 by (nat_ind_tac "m" 1);
   663  by (Auto_tac);
   664 by (exhaust_tac "xs" 1);
   665  by (Auto_tac);
   666 qed_spec_mp "drop_drop";
   667 
   668 Goal "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; 
   669 by (nat_ind_tac "m" 1);
   670  by (Auto_tac);
   671 by (exhaust_tac "xs" 1);
   672  by (Auto_tac);
   673 qed_spec_mp "take_drop";
   674 
   675 Goal "!xs. take n (map f xs) = map f (take n xs)"; 
   676 by (nat_ind_tac "n" 1);
   677  by (Auto_tac);
   678 by (exhaust_tac "xs" 1);
   679  by (Auto_tac);
   680 qed_spec_mp "take_map"; 
   681 
   682 Goal "!xs. drop n (map f xs) = map f (drop n xs)"; 
   683 by (nat_ind_tac "n" 1);
   684  by (Auto_tac);
   685 by (exhaust_tac "xs" 1);
   686  by (Auto_tac);
   687 qed_spec_mp "drop_map";
   688 
   689 Goal "!n i. i < n --> (take n xs)!i = xs!i";
   690 by (induct_tac "xs" 1);
   691  by (Auto_tac);
   692 by (exhaust_tac "n" 1);
   693  by (Blast_tac 1);
   694 by (exhaust_tac "i" 1);
   695  by (Auto_tac);
   696 qed_spec_mp "nth_take";
   697 Addsimps [nth_take];
   698 
   699 Goal  "!xs i. n + i <= length xs --> (drop n xs)!i = xs!(n+i)";
   700 by (nat_ind_tac "n" 1);
   701  by (Auto_tac);
   702 by (exhaust_tac "xs" 1);
   703  by (Auto_tac);
   704 qed_spec_mp "nth_drop";
   705 Addsimps [nth_drop];
   706 
   707 (** takeWhile & dropWhile **)
   708 
   709 section "takeWhile & dropWhile";
   710 
   711 Goal "takeWhile P xs @ dropWhile P xs = xs";
   712 by (induct_tac "xs" 1);
   713 by (Auto_tac);
   714 qed "takeWhile_dropWhile_id";
   715 Addsimps [takeWhile_dropWhile_id];
   716 
   717 Goal  "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs";
   718 by (induct_tac "xs" 1);
   719 by (Auto_tac);
   720 bind_thm("takeWhile_append1", conjI RS (result() RS mp));
   721 Addsimps [takeWhile_append1];
   722 
   723 Goal "(!x:set xs. P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys";
   724 by (induct_tac "xs" 1);
   725 by (Auto_tac);
   726 bind_thm("takeWhile_append2", ballI RS (result() RS mp));
   727 Addsimps [takeWhile_append2];
   728 
   729 Goal "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys";
   730 by (induct_tac "xs" 1);
   731 by (Auto_tac);
   732 bind_thm("dropWhile_append1", conjI RS (result() RS mp));
   733 Addsimps [dropWhile_append1];
   734 
   735 Goal "(!x:set xs. P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys";
   736 by (induct_tac "xs" 1);
   737 by (Auto_tac);
   738 bind_thm("dropWhile_append2", ballI RS (result() RS mp));
   739 Addsimps [dropWhile_append2];
   740 
   741 Goal "x:set(takeWhile P xs) --> x:set xs & P x";
   742 by (induct_tac "xs" 1);
   743 by (Auto_tac);
   744 qed_spec_mp"set_take_whileD";
   745 
   746 qed_goal "zip_Nil_Nil"   thy "zip []     []     = []" (K [Simp_tac 1]);
   747 qed_goal "zip_Cons_Cons" thy "zip (x#xs) (y#ys) = (x,y)#zip xs ys" 
   748 						      (K [Simp_tac 1]);
   749 
   750 (** nodups & remdups **)
   751 section "nodups & remdups";
   752 
   753 Goal "set(remdups xs) = set xs";
   754 by (induct_tac "xs" 1);
   755  by (Simp_tac 1);
   756 by (asm_full_simp_tac (simpset() addsimps [insert_absorb]) 1);
   757 qed "set_remdups";
   758 Addsimps [set_remdups];
   759 
   760 Goal "nodups(remdups xs)";
   761 by (induct_tac "xs" 1);
   762 by (Auto_tac);
   763 qed "nodups_remdups";
   764 
   765 Goal "nodups xs --> nodups (filter P xs)";
   766 by (induct_tac "xs" 1);
   767 by (Auto_tac);
   768 qed_spec_mp "nodups_filter";
   769 
   770 (** replicate **)
   771 section "replicate";
   772 
   773 Goal "set(replicate (Suc n) x) = {x}";
   774 by (induct_tac "n" 1);
   775 by (Auto_tac);
   776 val lemma = result();
   777 
   778 Goal "n ~= 0 ==> set(replicate n x) = {x}";
   779 by (fast_tac (claset() addSDs [not0_implies_Suc] addSIs [lemma]) 1);
   780 qed "set_replicate";
   781 Addsimps [set_replicate];