src/HOL/List.ML
author paulson
Tue Jul 01 10:34:30 1997 +0200 (1997-07-01)
changeset 3468 1f972dc8eafb
parent 3467 a0797ba03dfe
child 3571 f1c8fa0f0bf9
permissions -rw-r--r--
New laws for the "lists" operator
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@3011
   115
goal thy "xs ~= [] --> hd xs # tl xs = xs";
paulson@3457
   116
by (induct_tac "xs" 1);
paulson@3457
   117
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   118
qed_spec_mp "hd_Cons_tl";
nipkow@2608
   119
Addsimps [hd_Cons_tl];
clasohm@923
   120
nipkow@3011
   121
goal thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
nipkow@3040
   122
by (induct_tac "xs" 1);
nipkow@1327
   123
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   124
qed "hd_append";
clasohm@923
   125
nipkow@3011
   126
goal thy "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)";
paulson@3457
   127
by (simp_tac (!simpset setloop(split_tac[expand_list_case])) 1);
nipkow@2608
   128
qed "tl_append";
nipkow@2608
   129
nipkow@2608
   130
(** map **)
nipkow@2608
   131
nipkow@3467
   132
section "map";
nipkow@3467
   133
nipkow@3011
   134
goal thy
nipkow@3465
   135
  "(!x. x : set xs --> f x = g x) --> map f xs = map g xs";
paulson@3457
   136
by (induct_tac "xs" 1);
paulson@3457
   137
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   138
bind_thm("map_ext", impI RS (allI RS (result() RS mp)));
nipkow@2608
   139
nipkow@3011
   140
goal thy "map (%x.x) = (%xs.xs)";
nipkow@2608
   141
by (rtac ext 1);
nipkow@3040
   142
by (induct_tac "xs" 1);
nipkow@2608
   143
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   144
qed "map_ident";
nipkow@2608
   145
Addsimps[map_ident];
nipkow@2608
   146
nipkow@3011
   147
goal thy "map f (xs@ys) = map f xs @ map f ys";
nipkow@3040
   148
by (induct_tac "xs" 1);
nipkow@2608
   149
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   150
qed "map_append";
nipkow@2608
   151
Addsimps[map_append];
nipkow@2608
   152
nipkow@3011
   153
goalw thy [o_def] "map (f o g) xs = map f (map g xs)";
nipkow@3040
   154
by (induct_tac "xs" 1);
nipkow@2608
   155
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   156
qed "map_compose";
nipkow@2608
   157
Addsimps[map_compose];
nipkow@2608
   158
nipkow@3011
   159
goal thy "rev(map f xs) = map f (rev xs)";
nipkow@3040
   160
by (induct_tac "xs" 1);
nipkow@2608
   161
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   162
qed "rev_map";
nipkow@2608
   163
lcp@1169
   164
(** rev **)
lcp@1169
   165
nipkow@3467
   166
section "rev";
nipkow@3467
   167
nipkow@3011
   168
goal thy "rev(xs@ys) = rev(ys) @ rev(xs)";
nipkow@3040
   169
by (induct_tac "xs" 1);
nipkow@2512
   170
by (ALLGOALS Asm_simp_tac);
lcp@1169
   171
qed "rev_append";
nipkow@2512
   172
Addsimps[rev_append];
lcp@1169
   173
nipkow@3011
   174
goal thy "rev(rev l) = l";
nipkow@3040
   175
by (induct_tac "l" 1);
nipkow@2512
   176
by (ALLGOALS Asm_simp_tac);
lcp@1169
   177
qed "rev_rev_ident";
nipkow@2512
   178
Addsimps[rev_rev_ident];
lcp@1169
   179
nipkow@2608
   180
clasohm@923
   181
(** mem **)
clasohm@923
   182
nipkow@3467
   183
section "mem";
nipkow@3467
   184
nipkow@3011
   185
goal thy "x mem (xs@ys) = (x mem xs | x mem ys)";
nipkow@3040
   186
by (induct_tac "xs" 1);
clasohm@1264
   187
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
   188
qed "mem_append";
nipkow@2512
   189
Addsimps[mem_append];
clasohm@923
   190
nipkow@3011
   191
goal thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
nipkow@3040
   192
by (induct_tac "xs" 1);
clasohm@1264
   193
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
   194
qed "mem_filter";
nipkow@2512
   195
Addsimps[mem_filter];
clasohm@923
   196
nipkow@3465
   197
(** set **)
paulson@1812
   198
nipkow@3467
   199
section "set";
nipkow@3467
   200
nipkow@3465
   201
goal thy "set (xs@ys) = (set xs Un set ys)";
nipkow@3040
   202
by (induct_tac "xs" 1);
paulson@1812
   203
by (ALLGOALS Asm_simp_tac);
paulson@1908
   204
qed "set_of_list_append";
nipkow@2512
   205
Addsimps[set_of_list_append];
paulson@1812
   206
nipkow@3465
   207
goal thy "(x mem xs) = (x: set xs)";
nipkow@3040
   208
by (induct_tac "xs" 1);
paulson@1812
   209
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@2891
   210
by (Blast_tac 1);
paulson@1908
   211
qed "set_of_list_mem_eq";
paulson@1812
   212
nipkow@3465
   213
goal thy "set l <= set (x#l)";
paulson@1936
   214
by (Simp_tac 1);
paulson@2891
   215
by (Blast_tac 1);
paulson@1936
   216
qed "set_of_list_subset_Cons";
paulson@1936
   217
nipkow@3465
   218
goal thy "(set xs = {}) = (xs = [])";
paulson@3457
   219
by (induct_tac "xs" 1);
paulson@3457
   220
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   221
qed "set_of_list_empty";
nipkow@2608
   222
Addsimps [set_of_list_empty];
nipkow@2608
   223
nipkow@3465
   224
goal thy "set(rev xs) = set(xs)";
paulson@3457
   225
by (induct_tac "xs" 1);
paulson@3457
   226
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   227
qed "set_of_list_rev";
nipkow@2608
   228
Addsimps [set_of_list_rev];
nipkow@2608
   229
nipkow@3465
   230
goal thy "set(map f xs) = f``(set xs)";
paulson@3457
   231
by (induct_tac "xs" 1);
paulson@3457
   232
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   233
qed "set_of_list_map";
nipkow@2608
   234
Addsimps [set_of_list_map];
nipkow@2608
   235
paulson@1812
   236
clasohm@923
   237
(** list_all **)
clasohm@923
   238
nipkow@3467
   239
section "list_all";
nipkow@3467
   240
nipkow@3011
   241
goal thy "list_all (%x.True) xs = True";
nipkow@3040
   242
by (induct_tac "xs" 1);
clasohm@1264
   243
by (ALLGOALS Asm_simp_tac);
clasohm@923
   244
qed "list_all_True";
nipkow@2512
   245
Addsimps [list_all_True];
clasohm@923
   246
nipkow@3011
   247
goal thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
nipkow@3040
   248
by (induct_tac "xs" 1);
clasohm@1264
   249
by (ALLGOALS Asm_simp_tac);
nipkow@2512
   250
qed "list_all_append";
nipkow@2512
   251
Addsimps [list_all_append];
clasohm@923
   252
nipkow@3011
   253
goal thy "list_all P xs = (!x. x mem xs --> P(x))";
nipkow@3040
   254
by (induct_tac "xs" 1);
clasohm@1264
   255
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@2891
   256
by (Blast_tac 1);
clasohm@923
   257
qed "list_all_mem_conv";
clasohm@923
   258
clasohm@923
   259
nipkow@2608
   260
(** filter **)
clasohm@923
   261
nipkow@3467
   262
section "filter";
nipkow@3467
   263
paulson@3383
   264
goal thy "filter P (xs@ys) = filter P xs @ filter P ys";
paulson@3457
   265
by (induct_tac "xs" 1);
paulson@3457
   266
 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
nipkow@2608
   267
qed "filter_append";
nipkow@2608
   268
Addsimps [filter_append];
nipkow@2608
   269
paulson@3383
   270
goal thy "size (filter P xs) <= size xs";
paulson@3457
   271
by (induct_tac "xs" 1);
paulson@3457
   272
 by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@3383
   273
qed "filter_size";
paulson@3383
   274
nipkow@2608
   275
nipkow@2608
   276
(** concat **)
nipkow@2608
   277
nipkow@3467
   278
section "concat";
nipkow@3467
   279
nipkow@3011
   280
goal thy  "concat(xs@ys) = concat(xs)@concat(ys)";
nipkow@3040
   281
by (induct_tac "xs" 1);
clasohm@1264
   282
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   283
qed"concat_append";
nipkow@2608
   284
Addsimps [concat_append];
nipkow@2512
   285
nipkow@3467
   286
goal thy  "set(concat xs) = Union(set `` set xs)";
nipkow@3467
   287
by (induct_tac "xs" 1);
nipkow@3467
   288
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   289
qed"set_of_list_concat";
nipkow@3467
   290
Addsimps [set_of_list_concat];
nipkow@3467
   291
nipkow@3467
   292
goal thy "map f (concat xs) = concat (map (map f) xs)"; 
nipkow@3467
   293
by (induct_tac "xs" 1);
nipkow@3467
   294
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   295
qed "map_concat";
nipkow@3467
   296
nipkow@3467
   297
goal thy "filter p (concat xs) = concat (map (filter p) xs)"; 
nipkow@3467
   298
by (induct_tac "xs" 1);
nipkow@3467
   299
by (ALLGOALS Asm_simp_tac);
nipkow@3467
   300
qed"filter_concat"; 
nipkow@3467
   301
nipkow@3467
   302
goal thy "rev(concat xs) = concat (map rev (rev xs))";
nipkow@3467
   303
by (induct_tac "xs" 1);
nipkow@2512
   304
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   305
qed "rev_concat";
clasohm@923
   306
nipkow@962
   307
(** length **)
nipkow@962
   308
nipkow@3467
   309
section "length";
nipkow@3467
   310
nipkow@3011
   311
goal thy "length(xs@ys) = length(xs)+length(ys)";
nipkow@3040
   312
by (induct_tac "xs" 1);
clasohm@1264
   313
by (ALLGOALS Asm_simp_tac);
nipkow@962
   314
qed"length_append";
nipkow@1301
   315
Addsimps [length_append];
nipkow@1301
   316
nipkow@3011
   317
goal thy "length (map f l) = length l";
nipkow@3040
   318
by (induct_tac "l" 1);
nipkow@1301
   319
by (ALLGOALS Simp_tac);
nipkow@1301
   320
qed "length_map";
nipkow@1301
   321
Addsimps [length_map];
nipkow@962
   322
nipkow@3011
   323
goal thy "length(rev xs) = length(xs)";
nipkow@3040
   324
by (induct_tac "xs" 1);
nipkow@1301
   325
by (ALLGOALS Asm_simp_tac);
lcp@1169
   326
qed "length_rev";
nipkow@1301
   327
Addsimps [length_rev];
lcp@1169
   328
nipkow@3011
   329
goal thy "(length xs = 0) = (xs = [])";
paulson@3457
   330
by (induct_tac "xs" 1);
paulson@3457
   331
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   332
qed "length_0_conv";
nipkow@2608
   333
AddIffs [length_0_conv];
nipkow@2608
   334
nipkow@3011
   335
goal thy "(0 < length xs) = (xs ~= [])";
paulson@3457
   336
by (induct_tac "xs" 1);
paulson@3457
   337
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   338
qed "length_greater_0_conv";
nipkow@2608
   339
AddIffs [length_greater_0_conv];
nipkow@2608
   340
nipkow@2608
   341
clasohm@923
   342
(** nth **)
clasohm@923
   343
nipkow@3467
   344
section "nth";
nipkow@3467
   345
nipkow@3011
   346
goal thy
nipkow@2608
   347
  "!xs. nth n (xs@ys) = \
nipkow@2608
   348
\          (if n < length xs then nth n xs else nth (n - length xs) ys)";
paulson@3457
   349
by (nat_ind_tac "n" 1);
paulson@3457
   350
 by (Asm_simp_tac 1);
paulson@3457
   351
 by (rtac allI 1);
paulson@3457
   352
 by (exhaust_tac "xs" 1);
paulson@3457
   353
  by (ALLGOALS Asm_simp_tac);
paulson@3457
   354
by (rtac allI 1);
paulson@3457
   355
by (exhaust_tac "xs" 1);
paulson@3457
   356
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   357
qed_spec_mp "nth_append";
nipkow@2608
   358
nipkow@3011
   359
goal thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)";
nipkow@3040
   360
by (induct_tac "xs" 1);
nipkow@1301
   361
(* case [] *)
nipkow@1301
   362
by (Asm_full_simp_tac 1);
nipkow@1301
   363
(* case x#xl *)
nipkow@1301
   364
by (rtac allI 1);
nipkow@1301
   365
by (nat_ind_tac "n" 1);
nipkow@1301
   366
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   367
qed_spec_mp "nth_map";
nipkow@1301
   368
Addsimps [nth_map];
nipkow@1301
   369
nipkow@3011
   370
goal thy "!n. n < length xs --> list_all P xs --> P(nth n xs)";
nipkow@3040
   371
by (induct_tac "xs" 1);
nipkow@1301
   372
(* case [] *)
nipkow@1301
   373
by (Simp_tac 1);
nipkow@1301
   374
(* case x#xl *)
nipkow@1301
   375
by (rtac allI 1);
nipkow@1301
   376
by (nat_ind_tac "n" 1);
nipkow@1301
   377
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   378
qed_spec_mp "list_all_nth";
nipkow@1301
   379
nipkow@3011
   380
goal thy "!n. n < length xs --> (nth n xs) mem xs";
nipkow@3040
   381
by (induct_tac "xs" 1);
nipkow@1301
   382
(* case [] *)
nipkow@1301
   383
by (Simp_tac 1);
nipkow@1301
   384
(* case x#xl *)
nipkow@1301
   385
by (rtac allI 1);
nipkow@1301
   386
by (nat_ind_tac "n" 1);
nipkow@1301
   387
(* case 0 *)
nipkow@1301
   388
by (Asm_full_simp_tac 1);
nipkow@1301
   389
(* case Suc x *)
nipkow@1301
   390
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
nipkow@1485
   391
qed_spec_mp "nth_mem";
nipkow@1301
   392
Addsimps [nth_mem];
nipkow@1301
   393
nipkow@1327
   394
nipkow@2608
   395
(** take  & drop **)
nipkow@2608
   396
section "take & drop";
nipkow@1327
   397
nipkow@1419
   398
goal thy "take 0 xs = []";
nipkow@3040
   399
by (induct_tac "xs" 1);
nipkow@1419
   400
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   401
qed "take_0";
nipkow@1327
   402
nipkow@2608
   403
goal thy "drop 0 xs = xs";
nipkow@3040
   404
by (induct_tac "xs" 1);
nipkow@2608
   405
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   406
qed "drop_0";
nipkow@2608
   407
nipkow@1419
   408
goal thy "take (Suc n) (x#xs) = x # take n xs";
paulson@1552
   409
by (Simp_tac 1);
nipkow@1419
   410
qed "take_Suc_Cons";
nipkow@1327
   411
nipkow@2608
   412
goal thy "drop (Suc n) (x#xs) = drop n xs";
nipkow@2608
   413
by (Simp_tac 1);
nipkow@2608
   414
qed "drop_Suc_Cons";
nipkow@2608
   415
nipkow@2608
   416
Delsimps [take_Cons,drop_Cons];
nipkow@2608
   417
Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons];
nipkow@2608
   418
nipkow@3011
   419
goal thy "!xs. length(take n xs) = min (length xs) n";
paulson@3457
   420
by (nat_ind_tac "n" 1);
paulson@3457
   421
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   422
by (rtac allI 1);
paulson@3457
   423
by (exhaust_tac "xs" 1);
paulson@3457
   424
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   425
qed_spec_mp "length_take";
nipkow@2608
   426
Addsimps [length_take];
clasohm@923
   427
nipkow@3011
   428
goal thy "!xs. length(drop n xs) = (length xs - n)";
paulson@3457
   429
by (nat_ind_tac "n" 1);
paulson@3457
   430
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   431
by (rtac allI 1);
paulson@3457
   432
by (exhaust_tac "xs" 1);
paulson@3457
   433
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   434
qed_spec_mp "length_drop";
nipkow@2608
   435
Addsimps [length_drop];
nipkow@2608
   436
nipkow@3011
   437
goal thy "!xs. length xs <= n --> take n xs = xs";
paulson@3457
   438
by (nat_ind_tac "n" 1);
paulson@3457
   439
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   440
by (rtac allI 1);
paulson@3457
   441
by (exhaust_tac "xs" 1);
paulson@3457
   442
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   443
qed_spec_mp "take_all";
clasohm@923
   444
nipkow@3011
   445
goal thy "!xs. length xs <= n --> drop n xs = []";
paulson@3457
   446
by (nat_ind_tac "n" 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 "drop_all";
nipkow@2608
   452
nipkow@3011
   453
goal thy 
nipkow@2608
   454
  "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)";
paulson@3457
   455
by (nat_ind_tac "n" 1);
paulson@3457
   456
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   457
by (rtac allI 1);
paulson@3457
   458
by (exhaust_tac "xs" 1);
paulson@3457
   459
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   460
qed_spec_mp "take_append";
nipkow@2608
   461
Addsimps [take_append];
nipkow@2608
   462
nipkow@3011
   463
goal thy "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys"; 
paulson@3457
   464
by (nat_ind_tac "n" 1);
paulson@3457
   465
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   466
by (rtac allI 1);
paulson@3457
   467
by (exhaust_tac "xs" 1);
paulson@3457
   468
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   469
qed_spec_mp "drop_append";
nipkow@2608
   470
Addsimps [drop_append];
nipkow@2608
   471
nipkow@3011
   472
goal thy "!xs n. take n (take m xs) = take (min n m) xs"; 
paulson@3457
   473
by (nat_ind_tac "m" 1);
paulson@3457
   474
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   475
by (rtac allI 1);
paulson@3457
   476
by (exhaust_tac "xs" 1);
paulson@3457
   477
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   478
by (rtac allI 1);
paulson@3457
   479
by (exhaust_tac "n" 1);
paulson@3457
   480
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   481
qed_spec_mp "take_take";
nipkow@2608
   482
nipkow@3011
   483
goal thy "!xs. drop n (drop m xs) = drop (n + m) xs"; 
paulson@3457
   484
by (nat_ind_tac "m" 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 "drop_drop";
clasohm@923
   490
nipkow@3011
   491
goal thy "!xs n. take n (drop m xs) = drop m (take (n + m) xs)"; 
paulson@3457
   492
by (nat_ind_tac "m" 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 "take_drop";
nipkow@2608
   498
nipkow@3011
   499
goal thy "!xs. take n (map f xs) = map f (take n xs)"; 
paulson@3457
   500
by (nat_ind_tac "n" 1);
paulson@3457
   501
by (ALLGOALS Asm_simp_tac);
paulson@3457
   502
by (rtac allI 1);
paulson@3457
   503
by (exhaust_tac "xs" 1);
paulson@3457
   504
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   505
qed_spec_mp "take_map"; 
nipkow@2608
   506
nipkow@3011
   507
goal thy "!xs. drop n (map f xs) = map f (drop n xs)"; 
paulson@3457
   508
by (nat_ind_tac "n" 1);
paulson@3457
   509
by (ALLGOALS Asm_simp_tac);
paulson@3457
   510
by (rtac allI 1);
paulson@3457
   511
by (exhaust_tac "xs" 1);
paulson@3457
   512
by (ALLGOALS Asm_simp_tac);
nipkow@2608
   513
qed_spec_mp "drop_map";
nipkow@2608
   514
nipkow@3283
   515
goal thy "!n i. i < n --> nth i (take n xs) = nth i xs";
paulson@3457
   516
by (induct_tac "xs" 1);
paulson@3457
   517
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   518
by (strip_tac 1);
paulson@3457
   519
by (exhaust_tac "n" 1);
paulson@3457
   520
 by (Blast_tac 1);
paulson@3457
   521
by (exhaust_tac "i" 1);
paulson@3457
   522
by (ALLGOALS Asm_full_simp_tac);
nipkow@2608
   523
qed_spec_mp "nth_take";
nipkow@2608
   524
Addsimps [nth_take];
clasohm@923
   525
nipkow@3283
   526
goal thy  "!xs i. n + i < length xs --> nth i (drop n xs) = nth (n + i) xs";
paulson@3457
   527
by (nat_ind_tac "n" 1);
paulson@3457
   528
 by (ALLGOALS Asm_simp_tac);
paulson@3457
   529
by (rtac allI 1);
paulson@3457
   530
by (exhaust_tac "xs" 1);
paulson@3457
   531
 by (ALLGOALS Asm_simp_tac);
nipkow@2608
   532
qed_spec_mp "nth_drop";
nipkow@2608
   533
Addsimps [nth_drop];
nipkow@2608
   534
nipkow@2608
   535
(** takeWhile & dropWhile **)
nipkow@2608
   536
nipkow@3467
   537
section "takeWhile & dropWhile";
nipkow@3467
   538
nipkow@3011
   539
goal thy
nipkow@3465
   540
  "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs";
paulson@3457
   541
by (induct_tac "xs" 1);
paulson@3457
   542
 by (Simp_tac 1);
paulson@3457
   543
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
paulson@3457
   544
by (Blast_tac 1);
nipkow@2608
   545
bind_thm("takeWhile_append1", conjI RS (result() RS mp));
nipkow@2608
   546
Addsimps [takeWhile_append1];
clasohm@923
   547
nipkow@3011
   548
goal thy
nipkow@3465
   549
  "(!x:set xs.P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys";
paulson@3457
   550
by (induct_tac "xs" 1);
paulson@3457
   551
 by (Simp_tac 1);
paulson@3457
   552
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608
   553
bind_thm("takeWhile_append2", ballI RS (result() RS mp));
nipkow@2608
   554
Addsimps [takeWhile_append2];
lcp@1169
   555
nipkow@3011
   556
goal thy
nipkow@3465
   557
  "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys";
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);
paulson@3457
   561
by (Blast_tac 1);
nipkow@2608
   562
bind_thm("dropWhile_append1", conjI RS (result() RS mp));
nipkow@2608
   563
Addsimps [dropWhile_append1];
nipkow@2608
   564
nipkow@3011
   565
goal thy
nipkow@3465
   566
  "(!x:set xs.P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys";
paulson@3457
   567
by (induct_tac "xs" 1);
paulson@3457
   568
 by (Simp_tac 1);
paulson@3457
   569
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608
   570
bind_thm("dropWhile_append2", ballI RS (result() RS mp));
nipkow@2608
   571
Addsimps [dropWhile_append2];
nipkow@2608
   572
nipkow@3465
   573
goal thy "x:set(takeWhile P xs) --> x:set xs & P x";
paulson@3457
   574
by (induct_tac "xs" 1);
paulson@3457
   575
 by (Simp_tac 1);
paulson@3457
   576
by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608
   577
qed_spec_mp"set_of_list_take_whileD";
nipkow@2608
   578