src/HOL/List.ML
author paulson
Tue Jun 18 16:20:30 1996 +0200 (1996-06-18)
changeset 1812 debfc40b7756
parent 1760 6f41a494f3b1
child 1908 55d8e38262a8
permissions -rw-r--r--
Addition of setOfList
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
clasohm@923
    11
val [Nil_not_Cons,Cons_not_Nil] = list.distinct;
clasohm@923
    12
clasohm@923
    13
bind_thm("Cons_neq_Nil", Cons_not_Nil RS notE);
clasohm@923
    14
bind_thm("Nil_neq_Cons", sym RS Cons_neq_Nil);
clasohm@923
    15
clasohm@923
    16
bind_thm("Cons_inject", (hd list.inject) RS iffD1 RS conjE);
clasohm@923
    17
clasohm@923
    18
goal List.thy "!x. xs ~= x#xs";
clasohm@923
    19
by (list.induct_tac "xs" 1);
clasohm@1264
    20
by (ALLGOALS Asm_simp_tac);
clasohm@923
    21
qed "not_Cons_self";
clasohm@923
    22
clasohm@923
    23
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
clasohm@923
    24
by (list.induct_tac "xs" 1);
clasohm@1264
    25
by (Simp_tac 1);
clasohm@1264
    26
by (Asm_simp_tac 1);
lcp@1169
    27
by (REPEAT(resolve_tac [exI,refl,conjI] 1));
clasohm@923
    28
qed "neq_Nil_conv";
clasohm@923
    29
clasohm@923
    30
clasohm@923
    31
(** @ - append **)
clasohm@923
    32
clasohm@923
    33
goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
clasohm@923
    34
by (list.induct_tac "xs" 1);
clasohm@1264
    35
by (ALLGOALS Asm_simp_tac);
clasohm@923
    36
qed "append_assoc";
clasohm@923
    37
clasohm@923
    38
goal List.thy "xs @ [] = xs";
clasohm@923
    39
by (list.induct_tac "xs" 1);
clasohm@1264
    40
by (ALLGOALS Asm_simp_tac);
clasohm@923
    41
qed "append_Nil2";
clasohm@923
    42
clasohm@923
    43
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
clasohm@923
    44
by (list.induct_tac "xs" 1);
clasohm@1264
    45
by (ALLGOALS Asm_simp_tac);
clasohm@923
    46
qed "append_is_Nil";
clasohm@923
    47
clasohm@923
    48
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
clasohm@923
    49
by (list.induct_tac "xs" 1);
clasohm@1264
    50
by (ALLGOALS Asm_simp_tac);
clasohm@923
    51
qed "same_append_eq";
clasohm@923
    52
nipkow@1327
    53
goal List.thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
nipkow@1327
    54
by (list.induct_tac "xs" 1);
nipkow@1327
    55
by (ALLGOALS Asm_simp_tac);
nipkow@1327
    56
qed "hd_append";
clasohm@923
    57
lcp@1169
    58
(** rev **)
lcp@1169
    59
lcp@1169
    60
goal List.thy "rev(xs@ys) = rev(ys) @ rev(xs)";
lcp@1169
    61
by (list.induct_tac "xs" 1);
clasohm@1264
    62
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_Nil2,append_assoc])));
lcp@1169
    63
qed "rev_append";
lcp@1169
    64
lcp@1169
    65
goal List.thy "rev(rev l) = l";
lcp@1169
    66
by (list.induct_tac "l" 1);
clasohm@1264
    67
by (ALLGOALS (asm_simp_tac (!simpset addsimps [rev_append])));
lcp@1169
    68
qed "rev_rev_ident";
lcp@1169
    69
lcp@1169
    70
clasohm@923
    71
(** mem **)
clasohm@923
    72
clasohm@923
    73
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
clasohm@923
    74
by (list.induct_tac "xs" 1);
clasohm@1264
    75
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
    76
qed "mem_append";
clasohm@923
    77
clasohm@923
    78
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
clasohm@923
    79
by (list.induct_tac "xs" 1);
clasohm@1264
    80
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
    81
qed "mem_filter";
clasohm@923
    82
paulson@1812
    83
(** setOfList **)
paulson@1812
    84
paulson@1812
    85
goal thy "setOfList (xs@ys) = (setOfList xs Un setOfList ys)";
paulson@1812
    86
by (list.induct_tac "xs" 1);
paulson@1812
    87
by (ALLGOALS Asm_simp_tac);
paulson@1812
    88
by (Fast_tac 1);
paulson@1812
    89
qed "setOfList_append";
paulson@1812
    90
paulson@1812
    91
goal thy "(x mem xs) = (x: setOfList xs)";
paulson@1812
    92
by (list.induct_tac "xs" 1);
paulson@1812
    93
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@1812
    94
by (Fast_tac 1);
paulson@1812
    95
qed "setOfList_mem_eq";
paulson@1812
    96
paulson@1812
    97
clasohm@923
    98
(** list_all **)
clasohm@923
    99
clasohm@923
   100
goal List.thy "(Alls x:xs.True) = True";
clasohm@923
   101
by (list.induct_tac "xs" 1);
clasohm@1264
   102
by (ALLGOALS Asm_simp_tac);
clasohm@923
   103
qed "list_all_True";
clasohm@923
   104
clasohm@923
   105
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
clasohm@923
   106
by (list.induct_tac "xs" 1);
clasohm@1264
   107
by (ALLGOALS Asm_simp_tac);
clasohm@923
   108
qed "list_all_conj";
clasohm@923
   109
clasohm@923
   110
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
clasohm@923
   111
by (list.induct_tac "xs" 1);
clasohm@1264
   112
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
berghofe@1760
   113
by (Fast_tac 1);
clasohm@923
   114
qed "list_all_mem_conv";
clasohm@923
   115
clasohm@923
   116
clasohm@923
   117
(** list_case **)
clasohm@923
   118
clasohm@923
   119
goal List.thy
clasohm@923
   120
 "P(list_case a f xs) = ((xs=[] --> P(a)) & \
clasohm@923
   121
\                         (!y ys. xs=y#ys --> P(f y ys)))";
clasohm@923
   122
by (list.induct_tac "xs" 1);
clasohm@1264
   123
by (ALLGOALS Asm_simp_tac);
berghofe@1760
   124
by (Fast_tac 1);
clasohm@923
   125
qed "expand_list_case";
clasohm@923
   126
clasohm@923
   127
goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
lcp@1169
   128
by (list.induct_tac "xs" 1);
berghofe@1760
   129
by (Fast_tac 1);
berghofe@1760
   130
by (Fast_tac 1);
clasohm@923
   131
bind_thm("list_eq_cases",
clasohm@923
   132
  impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
clasohm@923
   133
clasohm@923
   134
(** flat **)
clasohm@923
   135
clasohm@923
   136
goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
clasohm@923
   137
by (list.induct_tac "xs" 1);
clasohm@1264
   138
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_assoc])));
clasohm@923
   139
qed"flat_append";
clasohm@923
   140
nipkow@962
   141
(** length **)
nipkow@962
   142
nipkow@962
   143
goal List.thy "length(xs@ys) = length(xs)+length(ys)";
nipkow@962
   144
by (list.induct_tac "xs" 1);
clasohm@1264
   145
by (ALLGOALS Asm_simp_tac);
nipkow@962
   146
qed"length_append";
nipkow@1301
   147
Addsimps [length_append];
nipkow@1301
   148
nipkow@1301
   149
goal List.thy "length (map f l) = length l";
nipkow@1301
   150
by (list.induct_tac "l" 1);
nipkow@1301
   151
by (ALLGOALS Simp_tac);
nipkow@1301
   152
qed "length_map";
nipkow@1301
   153
Addsimps [length_map];
nipkow@962
   154
lcp@1169
   155
goal List.thy "length(rev xs) = length(xs)";
lcp@1169
   156
by (list.induct_tac "xs" 1);
nipkow@1301
   157
by (ALLGOALS Asm_simp_tac);
lcp@1169
   158
qed "length_rev";
nipkow@1301
   159
Addsimps [length_rev];
lcp@1169
   160
clasohm@923
   161
(** nth **)
clasohm@923
   162
clasohm@923
   163
val [nth_0,nth_Suc] = nat_recs nth_def; 
clasohm@923
   164
store_thm("nth_0",nth_0);
clasohm@923
   165
store_thm("nth_Suc",nth_Suc);
nipkow@1301
   166
Addsimps [nth_0,nth_Suc];
nipkow@1301
   167
nipkow@1301
   168
goal List.thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)";
nipkow@1301
   169
by (list.induct_tac "xs" 1);
nipkow@1301
   170
(* case [] *)
nipkow@1301
   171
by (Asm_full_simp_tac 1);
nipkow@1301
   172
(* case x#xl *)
nipkow@1301
   173
by (rtac allI 1);
nipkow@1301
   174
by (nat_ind_tac "n" 1);
nipkow@1301
   175
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   176
qed_spec_mp "nth_map";
nipkow@1301
   177
Addsimps [nth_map];
nipkow@1301
   178
nipkow@1301
   179
goal List.thy "!n. n < length xs --> list_all P xs --> P(nth n xs)";
nipkow@1301
   180
by (list.induct_tac "xs" 1);
nipkow@1301
   181
(* case [] *)
nipkow@1301
   182
by (Simp_tac 1);
nipkow@1301
   183
(* case x#xl *)
nipkow@1301
   184
by (rtac allI 1);
nipkow@1301
   185
by (nat_ind_tac "n" 1);
nipkow@1301
   186
by (ALLGOALS Asm_full_simp_tac);
nipkow@1485
   187
qed_spec_mp "list_all_nth";
nipkow@1301
   188
nipkow@1301
   189
goal List.thy "!n. n < length xs --> (nth n xs) mem xs";
nipkow@1301
   190
by (list.induct_tac "xs" 1);
nipkow@1301
   191
(* case [] *)
nipkow@1301
   192
by (Simp_tac 1);
nipkow@1301
   193
(* case x#xl *)
nipkow@1301
   194
by (rtac allI 1);
nipkow@1301
   195
by (nat_ind_tac "n" 1);
nipkow@1301
   196
(* case 0 *)
nipkow@1301
   197
by (Asm_full_simp_tac 1);
nipkow@1301
   198
(* case Suc x *)
nipkow@1301
   199
by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
nipkow@1485
   200
qed_spec_mp "nth_mem";
nipkow@1301
   201
Addsimps [nth_mem];
nipkow@1301
   202
nipkow@1327
   203
(** drop **)
nipkow@1327
   204
nipkow@1419
   205
goal thy "drop 0 xs = xs";
nipkow@1419
   206
by (list.induct_tac "xs" 1);
nipkow@1419
   207
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   208
qed "drop_0";
nipkow@1327
   209
nipkow@1419
   210
goal thy "drop (Suc n) (x#xs) = drop n xs";
paulson@1552
   211
by (Simp_tac 1);
nipkow@1419
   212
qed "drop_Suc_Cons";
nipkow@1327
   213
nipkow@1419
   214
Delsimps [drop_Cons];
nipkow@1419
   215
Addsimps [drop_0,drop_Suc_Cons];
nipkow@1327
   216
nipkow@1327
   217
(** take **)
nipkow@1327
   218
nipkow@1419
   219
goal thy "take 0 xs = []";
nipkow@1419
   220
by (list.induct_tac "xs" 1);
nipkow@1419
   221
by (ALLGOALS Asm_simp_tac);
nipkow@1327
   222
qed "take_0";
nipkow@1327
   223
nipkow@1419
   224
goal thy "take (Suc n) (x#xs) = x # take n xs";
paulson@1552
   225
by (Simp_tac 1);
nipkow@1419
   226
qed "take_Suc_Cons";
nipkow@1327
   227
nipkow@1419
   228
Delsimps [take_Cons];
nipkow@1419
   229
Addsimps [take_0,take_Suc_Cons];
clasohm@923
   230
clasohm@923
   231
(** Additional mapping lemmas **)
clasohm@923
   232
nipkow@995
   233
goal List.thy "map (%x.x) = (%xs.xs)";
nipkow@995
   234
by (rtac ext 1);
clasohm@923
   235
by (list.induct_tac "xs" 1);
clasohm@1264
   236
by (ALLGOALS Asm_simp_tac);
clasohm@923
   237
qed "map_ident";
clasohm@923
   238
clasohm@923
   239
goal List.thy "map f (xs@ys) = map f xs @ map f ys";
clasohm@923
   240
by (list.induct_tac "xs" 1);
clasohm@1264
   241
by (ALLGOALS Asm_simp_tac);
clasohm@923
   242
qed "map_append";
clasohm@923
   243
clasohm@923
   244
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)";
clasohm@923
   245
by (list.induct_tac "xs" 1);
clasohm@1264
   246
by (ALLGOALS Asm_simp_tac);
clasohm@923
   247
qed "map_compose";
clasohm@923
   248
lcp@1169
   249
goal List.thy "rev(map f l) = map f (rev l)";
lcp@1169
   250
by (list.induct_tac "l" 1);
clasohm@1264
   251
by (ALLGOALS (asm_simp_tac (!simpset addsimps [map_append])));
lcp@1169
   252
qed "rev_map_distrib";
lcp@1169
   253
lcp@1169
   254
goal List.thy "rev(flat ls) = flat (map rev (rev ls))";
lcp@1169
   255
by (list.induct_tac "ls" 1);
clasohm@1264
   256
by (ALLGOALS (asm_simp_tac (!simpset addsimps 
lcp@1169
   257
       [map_append, flat_append, rev_append, append_Nil2])));
lcp@1169
   258
qed "rev_flat";
lcp@1169
   259
clasohm@1264
   260
Addsimps
clasohm@923
   261
  [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
clasohm@923
   262
   mem_append, mem_filter,
nipkow@1202
   263
   rev_append, rev_rev_ident,
clasohm@923
   264
   map_ident, map_append, map_compose,
nipkow@1301
   265
   flat_append, list_all_True, list_all_conj];
clasohm@923
   266