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