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