src/HOL/List.ML
author nipkow
Sun Feb 22 14:12:23 1998 +0100 (1998-02-22)
changeset 4643 1b40fcac5a09
parent 4628 0c7e97836e3c
child 4647 42af8ae6e2c1
permissions -rw-r--r--
New induction schemas for lists (length and snoc).
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@3011
   183
goal thy "xs ~= [] --> hd xs # tl xs = xs";
paulson@3457
   184
by (induct_tac "xs" 1);
paulson@3457
   185
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   186
qed_spec_mp "hd_Cons_tl";
nipkow@2608
   187
Addsimps [hd_Cons_tl];
clasohm@923
   188
nipkow@3011
   189
goal thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
nipkow@3040
   190
by (induct_tac "xs" 1);
nipkow@1327
   191
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   192
qed "hd_append";
clasohm@923
   193
nipkow@3571
   194
goal thy "!!xs. xs ~= [] ==> hd(xs @ ys) = hd xs";
wenzelm@4089
   195
by (asm_simp_tac (simpset() addsimps [hd_append]
nipkow@4069
   196
                           addsplits [split_list_case]) 1);
nipkow@3571
   197
qed "hd_append2";
nipkow@3571
   198
Addsimps [hd_append2];
nipkow@3571
   199
nipkow@3011
   200
goal thy "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)";
wenzelm@4089
   201
by (simp_tac (simpset() addsplits [split_list_case]) 1);
nipkow@2608
   202
qed "tl_append";
nipkow@2608
   203
nipkow@3571
   204
goal thy "!!xs. xs ~= [] ==> tl(xs @ ys) = (tl xs) @ ys";
wenzelm@4089
   205
by (asm_simp_tac (simpset() addsimps [tl_append]
nipkow@4069
   206
                           addsplits [split_list_case]) 1);
nipkow@3571
   207
qed "tl_append2";
nipkow@3571
   208
Addsimps [tl_append2];
nipkow@3571
   209
nipkow@2608
   210
(** map **)
nipkow@2608
   211
nipkow@3467
   212
section "map";
nipkow@3467
   213
nipkow@3011
   214
goal thy
nipkow@3465
   215
  "(!x. x : set xs --> f x = g x) --> map f xs = map g xs";
paulson@3457
   216
by (induct_tac "xs" 1);
paulson@3457
   217
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   218
bind_thm("map_ext", impI RS (allI RS (result() RS mp)));
nipkow@2608
   219
wenzelm@3842
   220
goal thy "map (%x. x) = (%xs. xs)";
nipkow@2608
   221
by (rtac ext 1);
nipkow@3040
   222
by (induct_tac "xs" 1);
nipkow@2608
   223
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   224
qed "map_ident";
nipkow@2608
   225
Addsimps[map_ident];
nipkow@2608
   226
nipkow@3011
   227
goal thy "map f (xs@ys) = map f xs @ map f ys";
nipkow@3040
   228
by (induct_tac "xs" 1);
nipkow@2608
   229
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   230
qed "map_append";
nipkow@2608
   231
Addsimps[map_append];
nipkow@2608
   232
nipkow@3011
   233
goalw thy [o_def] "map (f o g) xs = map f (map g xs)";
nipkow@3040
   234
by (induct_tac "xs" 1);
nipkow@2608
   235
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   236
qed "map_compose";
nipkow@2608
   237
Addsimps[map_compose];
nipkow@2608
   238
nipkow@3011
   239
goal thy "rev(map f xs) = map f (rev xs)";
nipkow@3040
   240
by (induct_tac "xs" 1);
nipkow@2608
   241
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   242
qed "rev_map";
nipkow@2608
   243
nipkow@3589
   244
(* a congruence rule for map: *)
nipkow@3589
   245
goal thy
nipkow@3589
   246
 "(xs=ys) --> (!x. x : set ys --> f x = g x) --> map f xs = map g ys";
wenzelm@4423
   247
by (rtac impI 1);
wenzelm@4423
   248
by (hyp_subst_tac 1);
wenzelm@4423
   249
by (induct_tac "ys" 1);
wenzelm@4423
   250
by (ALLGOALS Asm_simp_tac);
nipkow@3589
   251
val lemma = result();
nipkow@3589
   252
bind_thm("map_cong",impI RSN (2,allI RSN (2,lemma RS mp RS mp)));
nipkow@3589
   253
nipkow@3860
   254
goal List.thy "(map f xs = []) = (xs = [])";
wenzelm@4423
   255
by (induct_tac "xs" 1);
wenzelm@4423
   256
by (ALLGOALS Asm_simp_tac);
nipkow@3860
   257
qed "map_is_Nil_conv";
nipkow@3860
   258
AddIffs [map_is_Nil_conv];
nipkow@3860
   259
nipkow@3860
   260
goal List.thy "([] = map f xs) = (xs = [])";
wenzelm@4423
   261
by (induct_tac "xs" 1);
wenzelm@4423
   262
by (ALLGOALS Asm_simp_tac);
nipkow@3860
   263
qed "Nil_is_map_conv";
nipkow@3860
   264
AddIffs [Nil_is_map_conv];
nipkow@3860
   265
nipkow@3860
   266
lcp@1169
   267
(** rev **)
lcp@1169
   268
nipkow@3467
   269
section "rev";
nipkow@3467
   270
nipkow@3011
   271
goal thy "rev(xs@ys) = rev(ys) @ rev(xs)";
nipkow@3040
   272
by (induct_tac "xs" 1);
nipkow@2512
   273
by (ALLGOALS Asm_simp_tac);
lcp@1169
   274
qed "rev_append";
nipkow@2512
   275
Addsimps[rev_append];
lcp@1169
   276
nipkow@3011
   277
goal thy "rev(rev l) = l";
nipkow@3040
   278
by (induct_tac "l" 1);
nipkow@2512
   279
by (ALLGOALS Asm_simp_tac);
lcp@1169
   280
qed "rev_rev_ident";
nipkow@2512
   281
Addsimps[rev_rev_ident];
lcp@1169
   282
nipkow@3860
   283
goal thy "(rev xs = []) = (xs = [])";
wenzelm@4423
   284
by (induct_tac "xs" 1);
wenzelm@4423
   285
by (ALLGOALS Asm_simp_tac);
nipkow@3860
   286
qed "rev_is_Nil_conv";
nipkow@3860
   287
AddIffs [rev_is_Nil_conv];
nipkow@3860
   288
nipkow@3860
   289
goal thy "([] = rev xs) = (xs = [])";
wenzelm@4423
   290
by (induct_tac "xs" 1);
wenzelm@4423
   291
by (ALLGOALS Asm_simp_tac);
nipkow@3860
   292
qed "Nil_is_rev_conv";
nipkow@3860
   293
AddIffs [Nil_is_rev_conv];
nipkow@3860
   294
nipkow@2608
   295
clasohm@923
   296
(** mem **)
clasohm@923
   297
nipkow@3467
   298
section "mem";
nipkow@3467
   299
nipkow@3011
   300
goal thy "x mem (xs@ys) = (x mem xs | x mem ys)";
nipkow@3040
   301
by (induct_tac "xs" 1);
wenzelm@4089
   302
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
clasohm@923
   303
qed "mem_append";
nipkow@2512
   304
Addsimps[mem_append];
clasohm@923
   305
wenzelm@3842
   306
goal thy "x mem [x:xs. P(x)] = (x mem xs & P(x))";
nipkow@3040
   307
by (induct_tac "xs" 1);
wenzelm@4089
   308
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
clasohm@923
   309
qed "mem_filter";
nipkow@2512
   310
Addsimps[mem_filter];
clasohm@923
   311
nipkow@3465
   312
(** set **)
paulson@1812
   313
nipkow@3467
   314
section "set";
nipkow@3467
   315
nipkow@3465
   316
goal thy "set (xs@ys) = (set xs Un set ys)";
nipkow@3040
   317
by (induct_tac "xs" 1);
paulson@1812
   318
by (ALLGOALS Asm_simp_tac);
paulson@3647
   319
qed "set_append";
paulson@3647
   320
Addsimps[set_append];
paulson@1812
   321
nipkow@3465
   322
goal thy "(x mem xs) = (x: set xs)";
nipkow@3040
   323
by (induct_tac "xs" 1);
wenzelm@4089
   324
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
paulson@2891
   325
by (Blast_tac 1);
paulson@3647
   326
qed "set_mem_eq";
paulson@1812
   327
nipkow@3465
   328
goal thy "set l <= set (x#l)";
paulson@1936
   329
by (Simp_tac 1);
paulson@2891
   330
by (Blast_tac 1);
paulson@3647
   331
qed "set_subset_Cons";
paulson@1936
   332
nipkow@3465
   333
goal thy "(set xs = {}) = (xs = [])";
paulson@3457
   334
by (induct_tac "xs" 1);
paulson@3457
   335
by (ALLGOALS Asm_simp_tac);
paulson@3647
   336
qed "set_empty";
paulson@3647
   337
Addsimps [set_empty];
nipkow@2608
   338
nipkow@3465
   339
goal thy "set(rev xs) = set(xs)";
paulson@3457
   340
by (induct_tac "xs" 1);
paulson@3457
   341
by (ALLGOALS Asm_simp_tac);
paulson@3647
   342
qed "set_rev";
paulson@3647
   343
Addsimps [set_rev];
nipkow@2608
   344
nipkow@3465
   345
goal thy "set(map f xs) = f``(set xs)";
paulson@3457
   346
by (induct_tac "xs" 1);
paulson@3457
   347
by (ALLGOALS Asm_simp_tac);
paulson@3647
   348
qed "set_map";
paulson@3647
   349
Addsimps [set_map];
nipkow@2608
   350
nipkow@4605
   351
goal thy "set(map f xs) = f``(set xs)";
nipkow@4605
   352
by (induct_tac "xs" 1);
nipkow@4605
   353
by (ALLGOALS Asm_simp_tac);
nipkow@4605
   354
qed "set_map";
nipkow@4605
   355
Addsimps [set_map];
nipkow@4605
   356
nipkow@4605
   357
goal thy "(x : set(filter P xs)) = (x : set xs & P x)";
nipkow@4605
   358
by (induct_tac "xs" 1);
nipkow@4605
   359
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@4605
   360
by(Blast_tac 1);
nipkow@4605
   361
qed "in_set_filter";
nipkow@4605
   362
Addsimps [in_set_filter];
nipkow@4605
   363
paulson@1812
   364
clasohm@923
   365
(** list_all **)
clasohm@923
   366
nipkow@3467
   367
section "list_all";
nipkow@3467
   368
wenzelm@3842
   369
goal thy "list_all (%x. True) xs = True";
nipkow@3040
   370
by (induct_tac "xs" 1);
clasohm@1264
   371
by (ALLGOALS Asm_simp_tac);
clasohm@923
   372
qed "list_all_True";
nipkow@2512
   373
Addsimps [list_all_True];
clasohm@923
   374
nipkow@3011
   375
goal thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
nipkow@3040
   376
by (induct_tac "xs" 1);
clasohm@1264
   377
by (ALLGOALS Asm_simp_tac);
nipkow@2512
   378
qed "list_all_append";
nipkow@2512
   379
Addsimps [list_all_append];
clasohm@923
   380
nipkow@3011
   381
goal thy "list_all P xs = (!x. x mem xs --> P(x))";
nipkow@3040
   382
by (induct_tac "xs" 1);
wenzelm@4089
   383
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
paulson@2891
   384
by (Blast_tac 1);
clasohm@923
   385
qed "list_all_mem_conv";
clasohm@923
   386
clasohm@923
   387
nipkow@2608
   388
(** filter **)
clasohm@923
   389
nipkow@3467
   390
section "filter";
nipkow@3467
   391
paulson@3383
   392
goal thy "filter P (xs@ys) = filter P xs @ filter P ys";
paulson@3457
   393
by (induct_tac "xs" 1);
wenzelm@4089
   394
 by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@2608
   395
qed "filter_append";
nipkow@2608
   396
Addsimps [filter_append];
nipkow@2608
   397
nipkow@4605
   398
goal thy "filter (%x. True) xs = xs";
nipkow@4605
   399
by (induct_tac "xs" 1);
nipkow@4605
   400
by (ALLGOALS Asm_simp_tac);
nipkow@4605
   401
qed "filter_True";
nipkow@4605
   402
Addsimps [filter_True];
nipkow@4605
   403
nipkow@4605
   404
goal thy "filter (%x. False) xs = []";
nipkow@4605
   405
by (induct_tac "xs" 1);
nipkow@4605
   406
by (ALLGOALS Asm_simp_tac);
nipkow@4605
   407
qed "filter_False";
nipkow@4605
   408
Addsimps [filter_False];
nipkow@4605
   409
nipkow@4605
   410
goal thy "length (filter P xs) <= length xs";
paulson@3457
   411
by (induct_tac "xs" 1);
wenzelm@4089
   412
 by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@4605
   413
qed "length_filter";
paulson@3383
   414
nipkow@2608
   415
nipkow@2608
   416
(** concat **)
nipkow@2608
   417
nipkow@3467
   418
section "concat";
nipkow@3467
   419
nipkow@3011
   420
goal thy  "concat(xs@ys) = concat(xs)@concat(ys)";
nipkow@3040
   421
by (induct_tac "xs" 1);
clasohm@1264
   422
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   423
qed"concat_append";
nipkow@2608
   424
Addsimps [concat_append];
nipkow@2512
   425
nipkow@3896
   426
goal thy "(concat xss = []) = (!xs:set xss. xs=[])";
wenzelm@4423
   427
by (induct_tac "xss" 1);
wenzelm@4423
   428
by (ALLGOALS Asm_simp_tac);
nipkow@3896
   429
qed "concat_eq_Nil_conv";
nipkow@3896
   430
AddIffs [concat_eq_Nil_conv];
nipkow@3896
   431
nipkow@3896
   432
goal thy "([] = concat xss) = (!xs:set xss. xs=[])";
wenzelm@4423
   433
by (induct_tac "xss" 1);
wenzelm@4423
   434
by (ALLGOALS Asm_simp_tac);
nipkow@3896
   435
qed "Nil_eq_concat_conv";
nipkow@3896
   436
AddIffs [Nil_eq_concat_conv];
nipkow@3896
   437
nipkow@3467
   438
goal thy  "set(concat xs) = Union(set `` set xs)";
nipkow@3467
   439
by (induct_tac "xs" 1);
nipkow@3467
   440
by (ALLGOALS Asm_simp_tac);
paulson@3647
   441
qed"set_concat";
paulson@3647
   442
Addsimps [set_concat];
nipkow@3467
   443
nipkow@3467
   444
goal thy "map f (concat xs) = concat (map (map f) xs)"; 
nipkow@3467
   445
by (induct_tac "xs" 1);
nipkow@3467
   446
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   447
qed "map_concat";
nipkow@3467
   448
nipkow@3467
   449
goal thy "filter p (concat xs) = concat (map (filter p) xs)"; 
nipkow@3467
   450
by (induct_tac "xs" 1);
nipkow@3467
   451
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   452
qed"filter_concat"; 
nipkow@3467
   453
nipkow@3467
   454
goal thy "rev(concat xs) = concat (map rev (rev xs))";
nipkow@3467
   455
by (induct_tac "xs" 1);
nipkow@2512
   456
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   457
qed "rev_concat";
clasohm@923
   458
clasohm@923
   459
(** nth **)
clasohm@923
   460
nipkow@3467
   461
section "nth";
nipkow@3467
   462
nipkow@3011
   463
goal thy
nipkow@4502
   464
  "!xs. (xs@ys)!n = (if n < length xs then xs!n else ys!(n - length xs))";
paulson@3457
   465
by (nat_ind_tac "n" 1);
paulson@3457
   466
 by (Asm_simp_tac 1);
paulson@3457
   467
 by (rtac allI 1);
paulson@3457
   468
 by (exhaust_tac "xs" 1);
paulson@3457
   469
  by (ALLGOALS Asm_simp_tac);
paulson@3457
   470
by (rtac allI 1);
paulson@3457
   471
by (exhaust_tac "xs" 1);
paulson@3457
   472
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   473
qed_spec_mp "nth_append";
nipkow@2608
   474
nipkow@4502
   475
goal thy "!n. n < length xs --> (map f xs)!n = f(xs!n)";
nipkow@3040
   476
by (induct_tac "xs" 1);
nipkow@1301
   477
(* case [] *)
nipkow@1301
   478
by (Asm_full_simp_tac 1);
nipkow@1301
   479
(* case x#xl *)
nipkow@1301
   480
by (rtac allI 1);
nipkow@1301
   481
by (nat_ind_tac "n" 1);
nipkow@1301
   482
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   483
qed_spec_mp "nth_map";
nipkow@1301
   484
Addsimps [nth_map];
nipkow@1301
   485
nipkow@4502
   486
goal thy "!n. n < length xs --> list_all P xs --> P(xs!n)";
nipkow@3040
   487
by (induct_tac "xs" 1);
nipkow@1301
   488
(* case [] *)
nipkow@1301
   489
by (Simp_tac 1);
nipkow@1301
   490
(* case x#xl *)
nipkow@1301
   491
by (rtac allI 1);
nipkow@1301
   492
by (nat_ind_tac "n" 1);
nipkow@1301
   493
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   494
qed_spec_mp "list_all_nth";
nipkow@1301
   495
nipkow@4502
   496
goal thy "!n. n < length xs --> xs!n mem xs";
nipkow@3040
   497
by (induct_tac "xs" 1);
nipkow@1301
   498
(* case [] *)
nipkow@1301
   499
by (Simp_tac 1);
nipkow@1301
   500
(* case x#xl *)
nipkow@1301
   501
by (rtac allI 1);
nipkow@1301
   502
by (nat_ind_tac "n" 1);
nipkow@1301
   503
(* case 0 *)
nipkow@1301
   504
by (Asm_full_simp_tac 1);
nipkow@1301
   505
(* case Suc x *)
wenzelm@4089
   506
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
nipkow@1485
   507
qed_spec_mp "nth_mem";
nipkow@1301
   508
Addsimps [nth_mem];
nipkow@1301
   509
nipkow@4643
   510
(**  More case analysis and induction **)
nipkow@4643
   511
section "More case analysis and induction";
nipkow@4643
   512
nipkow@4643
   513
val [prem] = goal thy
nipkow@4643
   514
  "(!!xs. (!ys. length ys < length xs --> P ys) ==> P xs) ==> P(xs)";
nipkow@4643
   515
by(rtac measure_induct 1 THEN etac prem 1);
nipkow@4643
   516
qed "length_induct";
nipkow@4643
   517
nipkow@4643
   518
goal thy "xs ~= [] --> (? ys y. xs = ys@[y])";
nipkow@4643
   519
by(res_inst_tac [("xs","xs")] length_induct 1);
nipkow@4643
   520
by(Clarify_tac 1);
nipkow@4643
   521
bd (neq_Nil_conv RS iffD1) 1;
nipkow@4643
   522
by(Clarify_tac 1);
nipkow@4643
   523
by(rename_tac "ys" 1);
nipkow@4643
   524
by(case_tac "ys = []" 1);
nipkow@4643
   525
 by(res_inst_tac [("x","[]")] exI 1);
nipkow@4643
   526
 by(Asm_full_simp_tac 1);
nipkow@4643
   527
by(eres_inst_tac [("x","ys")] allE 1);
nipkow@4643
   528
by(Asm_full_simp_tac 1);
nipkow@4643
   529
by(REPEAT(etac exE 1));
nipkow@4643
   530
by(rename_tac "zs z" 1);
nipkow@4643
   531
by(hyp_subst_tac 1);
nipkow@4643
   532
by(res_inst_tac [("x","y#zs")] exI 1);
nipkow@4643
   533
by(Simp_tac 1);
nipkow@4643
   534
qed_spec_mp "neq_Nil_snocD";
nipkow@4643
   535
nipkow@4643
   536
val prems = goal thy
nipkow@4643
   537
  "[| xs=[] ==> P []; !!ys y. xs=ys@[y] ==> P(ys@[y]) |] ==> P xs";
nipkow@4643
   538
by(case_tac "xs = []" 1);
nipkow@4643
   539
 by(Asm_simp_tac 1);
nipkow@4643
   540
 bes prems 1;
nipkow@4643
   541
bd neq_Nil_snocD 1;
nipkow@4643
   542
by(REPEAT(etac exE 1));
nipkow@4643
   543
by(Asm_simp_tac 1);
nipkow@4643
   544
bes prems 1;
nipkow@4643
   545
qed "snoc_eq_cases";
nipkow@4643
   546
nipkow@4643
   547
val prems = goal thy
nipkow@4643
   548
  "[| P []; !!x xs. P xs ==> P(xs@[x]) |] ==> P(xs)";
nipkow@4643
   549
by(res_inst_tac [("xs","xs")] length_induct 1);
nipkow@4643
   550
by(res_inst_tac [("xs","xs")] snoc_eq_cases 1);
nipkow@4643
   551
 brs prems 1;
nipkow@4643
   552
by(fast_tac (claset() addIs prems addss simpset()) 1);
nipkow@4643
   553
qed "snoc_induct";
nipkow@4643
   554
nipkow@3896
   555
(** last & butlast **)
nipkow@1327
   556
nipkow@3896
   557
goal thy "last(xs@[x]) = x";
wenzelm@4423
   558
by (induct_tac "xs" 1);
wenzelm@4423
   559
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@3896
   560
qed "last_snoc";
nipkow@3896
   561
Addsimps [last_snoc];
nipkow@3896
   562
nipkow@3896
   563
goal thy "butlast(xs@[x]) = xs";
wenzelm@4423
   564
by (induct_tac "xs" 1);
wenzelm@4423
   565
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@3896
   566
qed "butlast_snoc";
nipkow@3896
   567
Addsimps [butlast_snoc];
nipkow@3896
   568
nipkow@4643
   569
goal thy "length(butlast xs) = length xs - 1";
nipkow@4643
   570
by(res_inst_tac [("xs","xs")] snoc_induct 1);
nipkow@4643
   571
by(ALLGOALS Asm_simp_tac);
nipkow@4643
   572
qed "length_butlast";
nipkow@4643
   573
Addsimps [length_butlast];
nipkow@4643
   574
nipkow@3896
   575
goal thy
nipkow@3896
   576
  "!ys. butlast (xs@ys) = (if ys=[] then butlast xs else xs@butlast ys)";
wenzelm@4423
   577
by (induct_tac "xs" 1);
wenzelm@4423
   578
by (ALLGOALS(asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@3896
   579
qed_spec_mp "butlast_append";
nipkow@3896
   580
nipkow@3896
   581
goal thy "x:set(butlast xs) --> x:set xs";
wenzelm@4423
   582
by (induct_tac "xs" 1);
wenzelm@4423
   583
by (ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if])));
nipkow@3896
   584
qed_spec_mp "in_set_butlastD";
nipkow@3896
   585
nipkow@3896
   586
goal thy "!!xs. x:set(butlast xs) ==> x:set(butlast(xs@ys))";
wenzelm@4423
   587
by (asm_simp_tac (simpset() addsimps [butlast_append]
nipkow@3919
   588
                          addsplits [expand_if]) 1);
wenzelm@4423
   589
by (blast_tac (claset() addDs [in_set_butlastD]) 1);
nipkow@3896
   590
qed "in_set_butlast_appendI1";
nipkow@3896
   591
nipkow@3896
   592
goal thy "!!xs. x:set(butlast ys) ==> x:set(butlast(xs@ys))";
wenzelm@4423
   593
by (asm_simp_tac (simpset() addsimps [butlast_append]
nipkow@3919
   594
                          addsplits [expand_if]) 1);
wenzelm@4423
   595
by (Clarify_tac 1);
wenzelm@4423
   596
by (Full_simp_tac 1);
nipkow@3896
   597
qed "in_set_butlast_appendI2";
nipkow@3902
   598
nipkow@2608
   599
(** take  & drop **)
nipkow@2608
   600
section "take & drop";
nipkow@1327
   601
nipkow@1419
   602
goal thy "take 0 xs = []";
nipkow@3040
   603
by (induct_tac "xs" 1);
nipkow@1419
   604
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   605
qed "take_0";
nipkow@1327
   606
nipkow@2608
   607
goal thy "drop 0 xs = xs";
nipkow@3040
   608
by (induct_tac "xs" 1);
nipkow@2608
   609
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   610
qed "drop_0";
nipkow@2608
   611
nipkow@1419
   612
goal thy "take (Suc n) (x#xs) = x # take n xs";
paulson@1552
   613
by (Simp_tac 1);
nipkow@1419
   614
qed "take_Suc_Cons";
nipkow@1327
   615
nipkow@2608
   616
goal thy "drop (Suc n) (x#xs) = drop n xs";
nipkow@2608
   617
by (Simp_tac 1);
nipkow@2608
   618
qed "drop_Suc_Cons";
nipkow@2608
   619
nipkow@2608
   620
Delsimps [take_Cons,drop_Cons];
nipkow@2608
   621
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons];
nipkow@2608
   622
nipkow@3011
   623
goal thy "!xs. length(take n xs) = min (length xs) n";
paulson@3457
   624
by (nat_ind_tac "n" 1);
paulson@3457
   625
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   626
by (rtac allI 1);
paulson@3457
   627
by (exhaust_tac "xs" 1);
paulson@3457
   628
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   629
qed_spec_mp "length_take";
nipkow@2608
   630
Addsimps [length_take];
clasohm@923
   631
nipkow@3011
   632
goal thy "!xs. length(drop n xs) = (length xs - n)";
paulson@3457
   633
by (nat_ind_tac "n" 1);
paulson@3457
   634
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   635
by (rtac allI 1);
paulson@3457
   636
by (exhaust_tac "xs" 1);
paulson@3457
   637
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   638
qed_spec_mp "length_drop";
nipkow@2608
   639
Addsimps [length_drop];
nipkow@2608
   640
nipkow@3011
   641
goal thy "!xs. length xs <= n --> take n xs = xs";
paulson@3457
   642
by (nat_ind_tac "n" 1);
paulson@3457
   643
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   644
by (rtac allI 1);
paulson@3457
   645
by (exhaust_tac "xs" 1);
paulson@3457
   646
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   647
qed_spec_mp "take_all";
clasohm@923
   648
nipkow@3011
   649
goal thy "!xs. length xs <= n --> drop n xs = []";
paulson@3457
   650
by (nat_ind_tac "n" 1);
paulson@3457
   651
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   652
by (rtac allI 1);
paulson@3457
   653
by (exhaust_tac "xs" 1);
paulson@3457
   654
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   655
qed_spec_mp "drop_all";
nipkow@2608
   656
nipkow@3011
   657
goal thy 
nipkow@2608
   658
  "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)";
paulson@3457
   659
by (nat_ind_tac "n" 1);
paulson@3457
   660
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   661
by (rtac allI 1);
paulson@3457
   662
by (exhaust_tac "xs" 1);
paulson@3457
   663
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   664
qed_spec_mp "take_append";
nipkow@2608
   665
Addsimps [take_append];
nipkow@2608
   666
nipkow@3011
   667
goal thy "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; 
paulson@3457
   668
by (nat_ind_tac "n" 1);
paulson@3457
   669
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   670
by (rtac allI 1);
paulson@3457
   671
by (exhaust_tac "xs" 1);
paulson@3457
   672
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   673
qed_spec_mp "drop_append";
nipkow@2608
   674
Addsimps [drop_append];
nipkow@2608
   675
nipkow@3011
   676
goal thy "!xs n. take n (take m xs) = take (min n m) xs"; 
paulson@3457
   677
by (nat_ind_tac "m" 1);
paulson@3457
   678
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   679
by (rtac allI 1);
paulson@3457
   680
by (exhaust_tac "xs" 1);
paulson@3457
   681
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   682
by (rtac allI 1);
paulson@3457
   683
by (exhaust_tac "n" 1);
paulson@3457
   684
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   685
qed_spec_mp "take_take";
nipkow@2608
   686
nipkow@3011
   687
goal thy "!xs. drop n (drop m xs) = drop (n + m) xs"; 
paulson@3457
   688
by (nat_ind_tac "m" 1);
paulson@3457
   689
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   690
by (rtac allI 1);
paulson@3457
   691
by (exhaust_tac "xs" 1);
paulson@3457
   692
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   693
qed_spec_mp "drop_drop";
clasohm@923
   694
nipkow@3011
   695
goal thy "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; 
paulson@3457
   696
by (nat_ind_tac "m" 1);
paulson@3457
   697
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   698
by (rtac allI 1);
paulson@3457
   699
by (exhaust_tac "xs" 1);
paulson@3457
   700
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   701
qed_spec_mp "take_drop";
nipkow@2608
   702
nipkow@3011
   703
goal thy "!xs. take n (map f xs) = map f (take n xs)"; 
paulson@3457
   704
by (nat_ind_tac "n" 1);
paulson@3457
   705
by (ALLGOALS Asm_simp_tac);
paulson@3457
   706
by (rtac allI 1);
paulson@3457
   707
by (exhaust_tac "xs" 1);
paulson@3457
   708
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   709
qed_spec_mp "take_map"; 
nipkow@2608
   710
nipkow@3011
   711
goal thy "!xs. drop n (map f xs) = map f (drop n xs)"; 
paulson@3457
   712
by (nat_ind_tac "n" 1);
paulson@3457
   713
by (ALLGOALS Asm_simp_tac);
paulson@3457
   714
by (rtac allI 1);
paulson@3457
   715
by (exhaust_tac "xs" 1);
paulson@3457
   716
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   717
qed_spec_mp "drop_map";
nipkow@2608
   718
nipkow@4502
   719
goal thy "!n i. i < n --> (take n xs)!i = xs!i";
paulson@3457
   720
by (induct_tac "xs" 1);
paulson@3457
   721
 by (ALLGOALS Asm_simp_tac);
paulson@3708
   722
by (Clarify_tac 1);
paulson@3457
   723
by (exhaust_tac "n" 1);
paulson@3457
   724
 by (Blast_tac 1);
paulson@3457
   725
by (exhaust_tac "i" 1);
paulson@3457
   726
by (ALLGOALS Asm_full_simp_tac);
nipkow@2608
   727
qed_spec_mp "nth_take";
nipkow@2608
   728
Addsimps [nth_take];
clasohm@923
   729
nipkow@4502
   730
goal thy  "!xs i. n + i <= length xs --> (drop n xs)!i = xs!(n+i)";
paulson@3457
   731
by (nat_ind_tac "n" 1);
paulson@3457
   732
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   733
by (rtac allI 1);
paulson@3457
   734
by (exhaust_tac "xs" 1);
paulson@3457
   735
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   736
qed_spec_mp "nth_drop";
nipkow@2608
   737
Addsimps [nth_drop];
nipkow@2608
   738
nipkow@2608
   739
(** takeWhile & dropWhile **)
nipkow@2608
   740
nipkow@3467
   741
section "takeWhile & dropWhile";
nipkow@3467
   742
nipkow@3586
   743
goal thy "takeWhile P xs @ dropWhile P xs = xs";
nipkow@3586
   744
by (induct_tac "xs" 1);
nipkow@3586
   745
 by (Simp_tac 1);
wenzelm@4089
   746
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
nipkow@3586
   747
qed "takeWhile_dropWhile_id";
nipkow@3586
   748
Addsimps [takeWhile_dropWhile_id];
nipkow@3586
   749
nipkow@3586
   750
goal thy  "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs";
paulson@3457
   751
by (induct_tac "xs" 1);
paulson@3457
   752
 by (Simp_tac 1);
wenzelm@4089
   753
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
paulson@3457
   754
by (Blast_tac 1);
nipkow@2608
   755
bind_thm("takeWhile_append1", conjI RS (result() RS mp));
nipkow@2608
   756
Addsimps [takeWhile_append1];
clasohm@923
   757
nipkow@3011
   758
goal thy
wenzelm@3842
   759
  "(!x:set xs. P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys";
paulson@3457
   760
by (induct_tac "xs" 1);
paulson@3457
   761
 by (Simp_tac 1);
wenzelm@4089
   762
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
nipkow@2608
   763
bind_thm("takeWhile_append2", ballI RS (result() RS mp));
nipkow@2608
   764
Addsimps [takeWhile_append2];
lcp@1169
   765
nipkow@3011
   766
goal thy
nipkow@3465
   767
  "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys";
paulson@3457
   768
by (induct_tac "xs" 1);
paulson@3457
   769
 by (Simp_tac 1);
wenzelm@4089
   770
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
paulson@3457
   771
by (Blast_tac 1);
nipkow@2608
   772
bind_thm("dropWhile_append1", conjI RS (result() RS mp));
nipkow@2608
   773
Addsimps [dropWhile_append1];
nipkow@2608
   774
nipkow@3011
   775
goal thy
wenzelm@3842
   776
  "(!x:set xs. P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys";
paulson@3457
   777
by (induct_tac "xs" 1);
paulson@3457
   778
 by (Simp_tac 1);
wenzelm@4089
   779
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
nipkow@2608
   780
bind_thm("dropWhile_append2", ballI RS (result() RS mp));
nipkow@2608
   781
Addsimps [dropWhile_append2];
nipkow@2608
   782
nipkow@3465
   783
goal thy "x:set(takeWhile P xs) --> x:set xs & P x";
paulson@3457
   784
by (induct_tac "xs" 1);
paulson@3457
   785
 by (Simp_tac 1);
wenzelm@4089
   786
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
paulson@3647
   787
qed_spec_mp"set_take_whileD";
nipkow@2608
   788
oheimb@4132
   789
qed_goal "zip_Nil_Nil"   thy "zip []     []     = []" (K [Simp_tac 1]);
oheimb@4132
   790
qed_goal "zip_Cons_Cons" thy "zip (x#xs) (y#ys) = (x,y)#zip xs ys" 
oheimb@4132
   791
						      (K [Simp_tac 1]);
nipkow@4605
   792
nipkow@4605
   793
(** nodups & remdups **)
nipkow@4605
   794
section "nodups & remdups";
nipkow@4605
   795
nipkow@4605
   796
goal thy "set(remdups xs) = set xs";
nipkow@4605
   797
by (induct_tac "xs" 1);
nipkow@4605
   798
 by (Simp_tac 1);
nipkow@4605
   799
by (asm_full_simp_tac (simpset() addsimps [insert_absorb]
nipkow@4605
   800
                                 addsplits [expand_if]) 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@4605
   806
 by (Simp_tac 1);
nipkow@4605
   807
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
nipkow@4605
   808
qed "nodups_remdups";
nipkow@4605
   809
nipkow@4605
   810
goal thy "nodups xs --> nodups (filter P xs)";
nipkow@4605
   811
by (induct_tac "xs" 1);
nipkow@4605
   812
 by (Simp_tac 1);
nipkow@4605
   813
by (asm_full_simp_tac (simpset() addsplits [expand_if]) 1);
nipkow@4605
   814
qed_spec_mp "nodups_filter";
nipkow@4605
   815
nipkow@3589
   816
(** replicate **)
nipkow@3589
   817
section "replicate";
nipkow@3589
   818
nipkow@3589
   819
goal thy "set(replicate (Suc n) x) = {x}";
wenzelm@4423
   820
by (induct_tac "n" 1);
wenzelm@4423
   821
by (ALLGOALS Asm_full_simp_tac);
nipkow@3589
   822
val lemma = result();
nipkow@3589
   823
nipkow@3589
   824
goal thy "!!n. n ~= 0 ==> set(replicate n x) = {x}";
wenzelm@4423
   825
by (fast_tac (claset() addSDs [not0_implies_Suc] addSIs [lemma]) 1);
nipkow@3589
   826
qed "set_replicate";
nipkow@3589
   827
Addsimps [set_replicate];