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