src/HOL/List.ML
author nipkow
Thu Jul 24 11:12:18 1997 +0200 (1997-07-24)
changeset 3571 f1c8fa0f0bf9
parent 3468 1f972dc8eafb
child 3574 5995ab73d790
permissions -rw-r--r--
List.ML: added lemmas by Stefan Merz.
simpodata.ML: removed rules about ? now subsumed by simplification proc.
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@2512
    13
Addsimps [not_Cons_self];
clasohm@923
    14
nipkow@3011
    15
goal thy "(xs ~= []) = (? y ys. xs = y#ys)";
nipkow@3040
    16
by (induct_tac "xs" 1);
clasohm@1264
    17
by (Simp_tac 1);
clasohm@1264
    18
by (Asm_simp_tac 1);
clasohm@923
    19
qed "neq_Nil_conv";
clasohm@923
    20
clasohm@923
    21
paulson@3468
    22
(** "lists": the list-forming operator over sets **)
paulson@3342
    23
paulson@3342
    24
goalw thy lists.defs "!!A B. A<=B ==> lists A <= lists B";
paulson@3342
    25
by (rtac lfp_mono 1);
paulson@3342
    26
by (REPEAT (ares_tac basic_monos 1));
paulson@3342
    27
qed "lists_mono";
paulson@3196
    28
paulson@3468
    29
val listsE = lists.mk_cases list.simps  "x#l : lists A";
paulson@3468
    30
AddSEs [listsE];
paulson@3468
    31
AddSIs lists.intrs;
paulson@3468
    32
paulson@3468
    33
goal thy "!!l. l: lists A ==> l: lists B --> l: lists (A Int B)";
paulson@3468
    34
by (etac lists.induct 1);
paulson@3468
    35
by (ALLGOALS Blast_tac);
paulson@3468
    36
qed_spec_mp "lists_IntI";
paulson@3468
    37
paulson@3468
    38
goal thy "lists (A Int B) = lists A Int lists B";
paulson@3468
    39
br (mono_Int RS equalityI) 1;
paulson@3468
    40
by (simp_tac (!simpset addsimps [mono_def, lists_mono]) 1);
paulson@3468
    41
by (blast_tac (!claset addSIs [lists_IntI]) 1);
paulson@3468
    42
qed "lists_Int_eq";
paulson@3468
    43
Addsimps [lists_Int_eq];
paulson@3468
    44
paulson@3196
    45
nipkow@2608
    46
(** list_case **)
nipkow@2608
    47
nipkow@3011
    48
goal thy
nipkow@2608
    49
 "P(list_case a f xs) = ((xs=[] --> P(a)) & \
paulson@2891
    50
\                        (!y ys. xs=y#ys --> P(f y ys)))";
nipkow@3040
    51
by (induct_tac "xs" 1);
nipkow@2608
    52
by (ALLGOALS Asm_simp_tac);
paulson@2891
    53
by (Blast_tac 1);
nipkow@2608
    54
qed "expand_list_case";
nipkow@2608
    55
nipkow@3011
    56
val prems = goal thy "[| P([]); !!x xs. P(x#xs) |] ==> P(xs)";
paulson@3457
    57
by (induct_tac "xs" 1);
paulson@3457
    58
by (REPEAT(resolve_tac prems 1));
nipkow@2608
    59
qed "list_cases";
nipkow@2608
    60
nipkow@3011
    61
goal thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
nipkow@3040
    62
by (induct_tac "xs" 1);
paulson@2891
    63
by (Blast_tac 1);
paulson@2891
    64
by (Blast_tac 1);
nipkow@2608
    65
bind_thm("list_eq_cases",
nipkow@2608
    66
  impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
nipkow@2608
    67
nipkow@2608
    68
clasohm@923
    69
(** @ - append **)
clasohm@923
    70
nipkow@3467
    71
section "@ - append";
nipkow@3467
    72
nipkow@3011
    73
goal thy "(xs@ys)@zs = xs@(ys@zs)";
nipkow@3040
    74
by (induct_tac "xs" 1);
clasohm@1264
    75
by (ALLGOALS Asm_simp_tac);
clasohm@923
    76
qed "append_assoc";
nipkow@2512
    77
Addsimps [append_assoc];
clasohm@923
    78
nipkow@3011
    79
goal thy "xs @ [] = xs";
nipkow@3040
    80
by (induct_tac "xs" 1);
clasohm@1264
    81
by (ALLGOALS Asm_simp_tac);
clasohm@923
    82
qed "append_Nil2";
nipkow@2512
    83
Addsimps [append_Nil2];
clasohm@923
    84
nipkow@3011
    85
goal thy "(xs@ys = []) = (xs=[] & ys=[])";
nipkow@3040
    86
by (induct_tac "xs" 1);
clasohm@1264
    87
by (ALLGOALS Asm_simp_tac);
nipkow@2608
    88
qed "append_is_Nil_conv";
nipkow@2608
    89
AddIffs [append_is_Nil_conv];
nipkow@2608
    90
nipkow@3011
    91
goal thy "([] = xs@ys) = (xs=[] & ys=[])";
nipkow@3040
    92
by (induct_tac "xs" 1);
nipkow@2608
    93
by (ALLGOALS Asm_simp_tac);
paulson@3457
    94
by (Blast_tac 1);
nipkow@2608
    95
qed "Nil_is_append_conv";
nipkow@2608
    96
AddIffs [Nil_is_append_conv];
clasohm@923
    97
nipkow@3011
    98
goal thy "(xs @ ys = xs @ zs) = (ys=zs)";
nipkow@3040
    99
by (induct_tac "xs" 1);
clasohm@1264
   100
by (ALLGOALS Asm_simp_tac);
clasohm@923
   101
qed "same_append_eq";
nipkow@2608
   102
AddIffs [same_append_eq];
nipkow@2608
   103
nipkow@3011
   104
goal thy "!ys. (xs @ [x] = ys @ [y]) = (xs = ys & x = y)"; 
paulson@3457
   105
by (induct_tac "xs" 1);
paulson@3457
   106
 by (rtac allI 1);
paulson@3457
   107
 by (induct_tac "ys" 1);
paulson@3457
   108
  by (ALLGOALS Asm_simp_tac);
paulson@3457
   109
by (rtac allI 1);
paulson@3457
   110
by (induct_tac "ys" 1);
paulson@3457
   111
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   112
qed_spec_mp "append1_eq_conv";
nipkow@2608
   113
AddIffs [append1_eq_conv];
nipkow@2608
   114
nipkow@3571
   115
goal thy "!ys zs. (ys @ xs = zs @ xs) = (ys=zs)";
nipkow@3571
   116
by (induct_tac "xs" 1);
nipkow@3571
   117
by (Simp_tac 1);
nipkow@3571
   118
by (strip_tac 1);
nipkow@3571
   119
by (subgoal_tac "((ys @ [a]) @ list = (zs @ [a]) @ list) = (ys=zs)" 1);
nipkow@3571
   120
by (Asm_full_simp_tac 1);
nipkow@3571
   121
by (Blast_tac 1);
nipkow@3571
   122
qed_spec_mp "append_same_eq";
nipkow@3571
   123
AddIffs [append_same_eq];
nipkow@3571
   124
nipkow@3011
   125
goal thy "xs ~= [] --> hd xs # tl xs = xs";
paulson@3457
   126
by (induct_tac "xs" 1);
paulson@3457
   127
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   128
qed_spec_mp "hd_Cons_tl";
nipkow@2608
   129
Addsimps [hd_Cons_tl];
clasohm@923
   130
nipkow@3011
   131
goal thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
nipkow@3040
   132
by (induct_tac "xs" 1);
nipkow@1327
   133
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   134
qed "hd_append";
clasohm@923
   135
nipkow@3571
   136
goal thy "!!xs. xs ~= [] ==> hd(xs @ ys) = hd xs";
nipkow@3571
   137
by (asm_simp_tac (!simpset addsimps [hd_append]
nipkow@3571
   138
                           setloop (split_tac [expand_list_case])) 1);
nipkow@3571
   139
qed "hd_append2";
nipkow@3571
   140
Addsimps [hd_append2];
nipkow@3571
   141
nipkow@3011
   142
goal thy "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)";
paulson@3457
   143
by (simp_tac (!simpset setloop(split_tac[expand_list_case])) 1);
nipkow@2608
   144
qed "tl_append";
nipkow@2608
   145
nipkow@3571
   146
goal thy "!!xs. xs ~= [] ==> tl(xs @ ys) = (tl xs) @ ys";
nipkow@3571
   147
by (asm_simp_tac (!simpset addsimps [tl_append]
nipkow@3571
   148
                           setloop (split_tac [expand_list_case])) 1);
nipkow@3571
   149
qed "tl_append2";
nipkow@3571
   150
Addsimps [tl_append2];
nipkow@3571
   151
nipkow@2608
   152
(** map **)
nipkow@2608
   153
nipkow@3467
   154
section "map";
nipkow@3467
   155
nipkow@3011
   156
goal thy
nipkow@3465
   157
  "(!x. x : set xs --> f x = g x) --> map f xs = map g xs";
paulson@3457
   158
by (induct_tac "xs" 1);
paulson@3457
   159
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   160
bind_thm("map_ext", impI RS (allI RS (result() RS mp)));
nipkow@2608
   161
nipkow@3011
   162
goal thy "map (%x.x) = (%xs.xs)";
nipkow@2608
   163
by (rtac ext 1);
nipkow@3040
   164
by (induct_tac "xs" 1);
nipkow@2608
   165
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   166
qed "map_ident";
nipkow@2608
   167
Addsimps[map_ident];
nipkow@2608
   168
nipkow@3011
   169
goal thy "map f (xs@ys) = map f xs @ map f ys";
nipkow@3040
   170
by (induct_tac "xs" 1);
nipkow@2608
   171
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   172
qed "map_append";
nipkow@2608
   173
Addsimps[map_append];
nipkow@2608
   174
nipkow@3011
   175
goalw thy [o_def] "map (f o g) xs = map f (map g xs)";
nipkow@3040
   176
by (induct_tac "xs" 1);
nipkow@2608
   177
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   178
qed "map_compose";
nipkow@2608
   179
Addsimps[map_compose];
nipkow@2608
   180
nipkow@3011
   181
goal thy "rev(map f xs) = map f (rev xs)";
nipkow@3040
   182
by (induct_tac "xs" 1);
nipkow@2608
   183
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   184
qed "rev_map";
nipkow@2608
   185
lcp@1169
   186
(** rev **)
lcp@1169
   187
nipkow@3467
   188
section "rev";
nipkow@3467
   189
nipkow@3011
   190
goal thy "rev(xs@ys) = rev(ys) @ rev(xs)";
nipkow@3040
   191
by (induct_tac "xs" 1);
nipkow@2512
   192
by (ALLGOALS Asm_simp_tac);
lcp@1169
   193
qed "rev_append";
nipkow@2512
   194
Addsimps[rev_append];
lcp@1169
   195
nipkow@3011
   196
goal thy "rev(rev l) = l";
nipkow@3040
   197
by (induct_tac "l" 1);
nipkow@2512
   198
by (ALLGOALS Asm_simp_tac);
lcp@1169
   199
qed "rev_rev_ident";
nipkow@2512
   200
Addsimps[rev_rev_ident];
lcp@1169
   201
nipkow@2608
   202
clasohm@923
   203
(** mem **)
clasohm@923
   204
nipkow@3467
   205
section "mem";
nipkow@3467
   206
nipkow@3011
   207
goal thy "x mem (xs@ys) = (x mem xs | x mem ys)";
nipkow@3040
   208
by (induct_tac "xs" 1);
clasohm@1264
   209
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
   210
qed "mem_append";
nipkow@2512
   211
Addsimps[mem_append];
clasohm@923
   212
nipkow@3011
   213
goal thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
nipkow@3040
   214
by (induct_tac "xs" 1);
clasohm@1264
   215
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
   216
qed "mem_filter";
nipkow@2512
   217
Addsimps[mem_filter];
clasohm@923
   218
nipkow@3465
   219
(** set **)
paulson@1812
   220
nipkow@3467
   221
section "set";
nipkow@3467
   222
nipkow@3465
   223
goal thy "set (xs@ys) = (set xs Un set ys)";
nipkow@3040
   224
by (induct_tac "xs" 1);
paulson@1812
   225
by (ALLGOALS Asm_simp_tac);
paulson@1908
   226
qed "set_of_list_append";
nipkow@2512
   227
Addsimps[set_of_list_append];
paulson@1812
   228
nipkow@3465
   229
goal thy "(x mem xs) = (x: set xs)";
nipkow@3040
   230
by (induct_tac "xs" 1);
paulson@1812
   231
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@2891
   232
by (Blast_tac 1);
paulson@1908
   233
qed "set_of_list_mem_eq";
paulson@1812
   234
nipkow@3465
   235
goal thy "set l <= set (x#l)";
paulson@1936
   236
by (Simp_tac 1);
paulson@2891
   237
by (Blast_tac 1);
paulson@1936
   238
qed "set_of_list_subset_Cons";
paulson@1936
   239
nipkow@3465
   240
goal thy "(set xs = {}) = (xs = [])";
paulson@3457
   241
by (induct_tac "xs" 1);
paulson@3457
   242
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   243
qed "set_of_list_empty";
nipkow@2608
   244
Addsimps [set_of_list_empty];
nipkow@2608
   245
nipkow@3465
   246
goal thy "set(rev xs) = set(xs)";
paulson@3457
   247
by (induct_tac "xs" 1);
paulson@3457
   248
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   249
qed "set_of_list_rev";
nipkow@2608
   250
Addsimps [set_of_list_rev];
nipkow@2608
   251
nipkow@3465
   252
goal thy "set(map f xs) = f``(set xs)";
paulson@3457
   253
by (induct_tac "xs" 1);
paulson@3457
   254
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   255
qed "set_of_list_map";
nipkow@2608
   256
Addsimps [set_of_list_map];
nipkow@2608
   257
paulson@1812
   258
clasohm@923
   259
(** list_all **)
clasohm@923
   260
nipkow@3467
   261
section "list_all";
nipkow@3467
   262
nipkow@3011
   263
goal thy "list_all (%x.True) xs = True";
nipkow@3040
   264
by (induct_tac "xs" 1);
clasohm@1264
   265
by (ALLGOALS Asm_simp_tac);
clasohm@923
   266
qed "list_all_True";
nipkow@2512
   267
Addsimps [list_all_True];
clasohm@923
   268
nipkow@3011
   269
goal thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
nipkow@3040
   270
by (induct_tac "xs" 1);
clasohm@1264
   271
by (ALLGOALS Asm_simp_tac);
nipkow@2512
   272
qed "list_all_append";
nipkow@2512
   273
Addsimps [list_all_append];
clasohm@923
   274
nipkow@3011
   275
goal thy "list_all P xs = (!x. x mem xs --> P(x))";
nipkow@3040
   276
by (induct_tac "xs" 1);
clasohm@1264
   277
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@2891
   278
by (Blast_tac 1);
clasohm@923
   279
qed "list_all_mem_conv";
clasohm@923
   280
clasohm@923
   281
nipkow@2608
   282
(** filter **)
clasohm@923
   283
nipkow@3467
   284
section "filter";
nipkow@3467
   285
paulson@3383
   286
goal thy "filter P (xs@ys) = filter P xs @ filter P ys";
paulson@3457
   287
by (induct_tac "xs" 1);
paulson@3457
   288
 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
nipkow@2608
   289
qed "filter_append";
nipkow@2608
   290
Addsimps [filter_append];
nipkow@2608
   291
paulson@3383
   292
goal thy "size (filter P xs) <= size xs";
paulson@3457
   293
by (induct_tac "xs" 1);
paulson@3457
   294
 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@3383
   295
qed "filter_size";
paulson@3383
   296
nipkow@2608
   297
nipkow@2608
   298
(** concat **)
nipkow@2608
   299
nipkow@3467
   300
section "concat";
nipkow@3467
   301
nipkow@3011
   302
goal thy  "concat(xs@ys) = concat(xs)@concat(ys)";
nipkow@3040
   303
by (induct_tac "xs" 1);
clasohm@1264
   304
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   305
qed"concat_append";
nipkow@2608
   306
Addsimps [concat_append];
nipkow@2512
   307
nipkow@3467
   308
goal thy  "set(concat xs) = Union(set `` set xs)";
nipkow@3467
   309
by (induct_tac "xs" 1);
nipkow@3467
   310
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   311
qed"set_of_list_concat";
nipkow@3467
   312
Addsimps [set_of_list_concat];
nipkow@3467
   313
nipkow@3467
   314
goal thy "map f (concat xs) = concat (map (map f) xs)"; 
nipkow@3467
   315
by (induct_tac "xs" 1);
nipkow@3467
   316
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   317
qed "map_concat";
nipkow@3467
   318
nipkow@3467
   319
goal thy "filter p (concat xs) = concat (map (filter p) xs)"; 
nipkow@3467
   320
by (induct_tac "xs" 1);
nipkow@3467
   321
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   322
qed"filter_concat"; 
nipkow@3467
   323
nipkow@3467
   324
goal thy "rev(concat xs) = concat (map rev (rev xs))";
nipkow@3467
   325
by (induct_tac "xs" 1);
nipkow@2512
   326
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   327
qed "rev_concat";
clasohm@923
   328
nipkow@962
   329
(** length **)
nipkow@962
   330
nipkow@3467
   331
section "length";
nipkow@3467
   332
nipkow@3011
   333
goal thy "length(xs@ys) = length(xs)+length(ys)";
nipkow@3040
   334
by (induct_tac "xs" 1);
clasohm@1264
   335
by (ALLGOALS Asm_simp_tac);
nipkow@962
   336
qed"length_append";
nipkow@1301
   337
Addsimps [length_append];
nipkow@1301
   338
nipkow@3011
   339
goal thy "length (map f l) = length l";
nipkow@3040
   340
by (induct_tac "l" 1);
nipkow@1301
   341
by (ALLGOALS Simp_tac);
nipkow@1301
   342
qed "length_map";
nipkow@1301
   343
Addsimps [length_map];
nipkow@962
   344
nipkow@3011
   345
goal thy "length(rev xs) = length(xs)";
nipkow@3040
   346
by (induct_tac "xs" 1);
nipkow@1301
   347
by (ALLGOALS Asm_simp_tac);
lcp@1169
   348
qed "length_rev";
nipkow@1301
   349
Addsimps [length_rev];
lcp@1169
   350
nipkow@3011
   351
goal thy "(length xs = 0) = (xs = [])";
paulson@3457
   352
by (induct_tac "xs" 1);
paulson@3457
   353
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   354
qed "length_0_conv";
nipkow@2608
   355
AddIffs [length_0_conv];
nipkow@2608
   356
nipkow@3011
   357
goal thy "(0 < length xs) = (xs ~= [])";
paulson@3457
   358
by (induct_tac "xs" 1);
paulson@3457
   359
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   360
qed "length_greater_0_conv";
nipkow@2608
   361
AddIffs [length_greater_0_conv];
nipkow@2608
   362
nipkow@2608
   363
clasohm@923
   364
(** nth **)
clasohm@923
   365
nipkow@3467
   366
section "nth";
nipkow@3467
   367
nipkow@3011
   368
goal thy
nipkow@2608
   369
  "!xs. nth n (xs@ys) = \
nipkow@2608
   370
\          (if n < length xs then nth n xs else nth (n - length xs) ys)";
paulson@3457
   371
by (nat_ind_tac "n" 1);
paulson@3457
   372
 by (Asm_simp_tac 1);
paulson@3457
   373
 by (rtac allI 1);
paulson@3457
   374
 by (exhaust_tac "xs" 1);
paulson@3457
   375
  by (ALLGOALS Asm_simp_tac);
paulson@3457
   376
by (rtac allI 1);
paulson@3457
   377
by (exhaust_tac "xs" 1);
paulson@3457
   378
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   379
qed_spec_mp "nth_append";
nipkow@2608
   380
nipkow@3011
   381
goal thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)";
nipkow@3040
   382
by (induct_tac "xs" 1);
nipkow@1301
   383
(* case [] *)
nipkow@1301
   384
by (Asm_full_simp_tac 1);
nipkow@1301
   385
(* case x#xl *)
nipkow@1301
   386
by (rtac allI 1);
nipkow@1301
   387
by (nat_ind_tac "n" 1);
nipkow@1301
   388
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   389
qed_spec_mp "nth_map";
nipkow@1301
   390
Addsimps [nth_map];
nipkow@1301
   391
nipkow@3011
   392
goal thy "!n. n < length xs --> list_all P xs --> P(nth n xs)";
nipkow@3040
   393
by (induct_tac "xs" 1);
nipkow@1301
   394
(* case [] *)
nipkow@1301
   395
by (Simp_tac 1);
nipkow@1301
   396
(* case x#xl *)
nipkow@1301
   397
by (rtac allI 1);
nipkow@1301
   398
by (nat_ind_tac "n" 1);
nipkow@1301
   399
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   400
qed_spec_mp "list_all_nth";
nipkow@1301
   401
nipkow@3011
   402
goal thy "!n. n < length xs --> (nth n xs) mem xs";
nipkow@3040
   403
by (induct_tac "xs" 1);
nipkow@1301
   404
(* case [] *)
nipkow@1301
   405
by (Simp_tac 1);
nipkow@1301
   406
(* case x#xl *)
nipkow@1301
   407
by (rtac allI 1);
nipkow@1301
   408
by (nat_ind_tac "n" 1);
nipkow@1301
   409
(* case 0 *)
nipkow@1301
   410
by (Asm_full_simp_tac 1);
nipkow@1301
   411
(* case Suc x *)
nipkow@1301
   412
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
nipkow@1485
   413
qed_spec_mp "nth_mem";
nipkow@1301
   414
Addsimps [nth_mem];
nipkow@1301
   415
nipkow@1327
   416
nipkow@2608
   417
(** take  & drop **)
nipkow@2608
   418
section "take & drop";
nipkow@1327
   419
nipkow@1419
   420
goal thy "take 0 xs = []";
nipkow@3040
   421
by (induct_tac "xs" 1);
nipkow@1419
   422
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   423
qed "take_0";
nipkow@1327
   424
nipkow@2608
   425
goal thy "drop 0 xs = xs";
nipkow@3040
   426
by (induct_tac "xs" 1);
nipkow@2608
   427
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   428
qed "drop_0";
nipkow@2608
   429
nipkow@1419
   430
goal thy "take (Suc n) (x#xs) = x # take n xs";
paulson@1552
   431
by (Simp_tac 1);
nipkow@1419
   432
qed "take_Suc_Cons";
nipkow@1327
   433
nipkow@2608
   434
goal thy "drop (Suc n) (x#xs) = drop n xs";
nipkow@2608
   435
by (Simp_tac 1);
nipkow@2608
   436
qed "drop_Suc_Cons";
nipkow@2608
   437
nipkow@2608
   438
Delsimps [take_Cons,drop_Cons];
nipkow@2608
   439
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons];
nipkow@2608
   440
nipkow@3011
   441
goal thy "!xs. length(take n xs) = min (length xs) n";
paulson@3457
   442
by (nat_ind_tac "n" 1);
paulson@3457
   443
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   444
by (rtac allI 1);
paulson@3457
   445
by (exhaust_tac "xs" 1);
paulson@3457
   446
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   447
qed_spec_mp "length_take";
nipkow@2608
   448
Addsimps [length_take];
clasohm@923
   449
nipkow@3011
   450
goal thy "!xs. length(drop n xs) = (length xs - n)";
paulson@3457
   451
by (nat_ind_tac "n" 1);
paulson@3457
   452
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   453
by (rtac allI 1);
paulson@3457
   454
by (exhaust_tac "xs" 1);
paulson@3457
   455
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   456
qed_spec_mp "length_drop";
nipkow@2608
   457
Addsimps [length_drop];
nipkow@2608
   458
nipkow@3011
   459
goal thy "!xs. length xs <= n --> take n xs = xs";
paulson@3457
   460
by (nat_ind_tac "n" 1);
paulson@3457
   461
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   462
by (rtac allI 1);
paulson@3457
   463
by (exhaust_tac "xs" 1);
paulson@3457
   464
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   465
qed_spec_mp "take_all";
clasohm@923
   466
nipkow@3011
   467
goal thy "!xs. length xs <= n --> drop n xs = []";
paulson@3457
   468
by (nat_ind_tac "n" 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 "drop_all";
nipkow@2608
   474
nipkow@3011
   475
goal thy 
nipkow@2608
   476
  "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)";
paulson@3457
   477
by (nat_ind_tac "n" 1);
paulson@3457
   478
 by (ALLGOALS Asm_simp_tac);
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 "take_append";
nipkow@2608
   483
Addsimps [take_append];
nipkow@2608
   484
nipkow@3011
   485
goal thy "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; 
paulson@3457
   486
by (nat_ind_tac "n" 1);
paulson@3457
   487
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   488
by (rtac allI 1);
paulson@3457
   489
by (exhaust_tac "xs" 1);
paulson@3457
   490
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   491
qed_spec_mp "drop_append";
nipkow@2608
   492
Addsimps [drop_append];
nipkow@2608
   493
nipkow@3011
   494
goal thy "!xs n. take n (take m xs) = take (min n m) xs"; 
paulson@3457
   495
by (nat_ind_tac "m" 1);
paulson@3457
   496
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   497
by (rtac allI 1);
paulson@3457
   498
by (exhaust_tac "xs" 1);
paulson@3457
   499
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   500
by (rtac allI 1);
paulson@3457
   501
by (exhaust_tac "n" 1);
paulson@3457
   502
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   503
qed_spec_mp "take_take";
nipkow@2608
   504
nipkow@3011
   505
goal thy "!xs. drop n (drop m xs) = drop (n + m) xs"; 
paulson@3457
   506
by (nat_ind_tac "m" 1);
paulson@3457
   507
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   508
by (rtac allI 1);
paulson@3457
   509
by (exhaust_tac "xs" 1);
paulson@3457
   510
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   511
qed_spec_mp "drop_drop";
clasohm@923
   512
nipkow@3011
   513
goal thy "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; 
paulson@3457
   514
by (nat_ind_tac "m" 1);
paulson@3457
   515
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   516
by (rtac allI 1);
paulson@3457
   517
by (exhaust_tac "xs" 1);
paulson@3457
   518
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   519
qed_spec_mp "take_drop";
nipkow@2608
   520
nipkow@3011
   521
goal thy "!xs. take n (map f xs) = map f (take n xs)"; 
paulson@3457
   522
by (nat_ind_tac "n" 1);
paulson@3457
   523
by (ALLGOALS Asm_simp_tac);
paulson@3457
   524
by (rtac allI 1);
paulson@3457
   525
by (exhaust_tac "xs" 1);
paulson@3457
   526
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   527
qed_spec_mp "take_map"; 
nipkow@2608
   528
nipkow@3011
   529
goal thy "!xs. drop n (map f xs) = map f (drop n xs)"; 
paulson@3457
   530
by (nat_ind_tac "n" 1);
paulson@3457
   531
by (ALLGOALS Asm_simp_tac);
paulson@3457
   532
by (rtac allI 1);
paulson@3457
   533
by (exhaust_tac "xs" 1);
paulson@3457
   534
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   535
qed_spec_mp "drop_map";
nipkow@2608
   536
nipkow@3283
   537
goal thy "!n i. i < n --> nth i (take n xs) = nth i xs";
paulson@3457
   538
by (induct_tac "xs" 1);
paulson@3457
   539
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   540
by (strip_tac 1);
paulson@3457
   541
by (exhaust_tac "n" 1);
paulson@3457
   542
 by (Blast_tac 1);
paulson@3457
   543
by (exhaust_tac "i" 1);
paulson@3457
   544
by (ALLGOALS Asm_full_simp_tac);
nipkow@2608
   545
qed_spec_mp "nth_take";
nipkow@2608
   546
Addsimps [nth_take];
clasohm@923
   547
nipkow@3283
   548
goal thy  "!xs i. n + i < length xs --> nth i (drop n xs) = nth (n + i) xs";
paulson@3457
   549
by (nat_ind_tac "n" 1);
paulson@3457
   550
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   551
by (rtac allI 1);
paulson@3457
   552
by (exhaust_tac "xs" 1);
paulson@3457
   553
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   554
qed_spec_mp "nth_drop";
nipkow@2608
   555
Addsimps [nth_drop];
nipkow@2608
   556
nipkow@2608
   557
(** takeWhile & dropWhile **)
nipkow@2608
   558
nipkow@3467
   559
section "takeWhile & dropWhile";
nipkow@3467
   560
nipkow@3011
   561
goal thy
nipkow@3465
   562
  "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs";
paulson@3457
   563
by (induct_tac "xs" 1);
paulson@3457
   564
 by (Simp_tac 1);
paulson@3457
   565
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
paulson@3457
   566
by (Blast_tac 1);
nipkow@2608
   567
bind_thm("takeWhile_append1", conjI RS (result() RS mp));
nipkow@2608
   568
Addsimps [takeWhile_append1];
clasohm@923
   569
nipkow@3011
   570
goal thy
nipkow@3465
   571
  "(!x:set xs.P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys";
paulson@3457
   572
by (induct_tac "xs" 1);
paulson@3457
   573
 by (Simp_tac 1);
paulson@3457
   574
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608
   575
bind_thm("takeWhile_append2", ballI RS (result() RS mp));
nipkow@2608
   576
Addsimps [takeWhile_append2];
lcp@1169
   577
nipkow@3011
   578
goal thy
nipkow@3465
   579
  "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys";
paulson@3457
   580
by (induct_tac "xs" 1);
paulson@3457
   581
 by (Simp_tac 1);
paulson@3457
   582
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
paulson@3457
   583
by (Blast_tac 1);
nipkow@2608
   584
bind_thm("dropWhile_append1", conjI RS (result() RS mp));
nipkow@2608
   585
Addsimps [dropWhile_append1];
nipkow@2608
   586
nipkow@3011
   587
goal thy
nipkow@3465
   588
  "(!x:set xs.P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys";
paulson@3457
   589
by (induct_tac "xs" 1);
paulson@3457
   590
 by (Simp_tac 1);
paulson@3457
   591
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608
   592
bind_thm("dropWhile_append2", ballI RS (result() RS mp));
nipkow@2608
   593
Addsimps [dropWhile_append2];
nipkow@2608
   594
nipkow@3465
   595
goal thy "x:set(takeWhile P xs) --> x:set xs & P x";
paulson@3457
   596
by (induct_tac "xs" 1);
paulson@3457
   597
 by (Simp_tac 1);
paulson@3457
   598
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608
   599
qed_spec_mp"set_of_list_take_whileD";
nipkow@2608
   600