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