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