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