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