src/HOL/List.ML
author clasohm
Wed Oct 04 13:10:03 1995 +0100 (1995-10-04)
changeset 1264 3eb91524b938
parent 1202 968cd786a748
child 1301 42782316d510
permissions -rw-r--r--
added local simpsets; removed IOA from 'make test'
clasohm@923
     1
(*  Title: 	HOL/List
clasohm@923
     2
    ID:         $Id$
clasohm@923
     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
clasohm@923
    53
lcp@1169
    54
(** rev **)
lcp@1169
    55
lcp@1169
    56
goal List.thy "rev(xs@ys) = rev(ys) @ rev(xs)";
lcp@1169
    57
by (list.induct_tac "xs" 1);
clasohm@1264
    58
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_Nil2,append_assoc])));
lcp@1169
    59
qed "rev_append";
lcp@1169
    60
lcp@1169
    61
goal List.thy "rev(rev l) = l";
lcp@1169
    62
by (list.induct_tac "l" 1);
clasohm@1264
    63
by (ALLGOALS (asm_simp_tac (!simpset addsimps [rev_append])));
lcp@1169
    64
qed "rev_rev_ident";
lcp@1169
    65
lcp@1169
    66
clasohm@923
    67
(** mem **)
clasohm@923
    68
clasohm@923
    69
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
clasohm@923
    70
by (list.induct_tac "xs" 1);
clasohm@1264
    71
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
    72
qed "mem_append";
clasohm@923
    73
clasohm@923
    74
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
clasohm@923
    75
by (list.induct_tac "xs" 1);
clasohm@1264
    76
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923
    77
qed "mem_filter";
clasohm@923
    78
clasohm@923
    79
(** list_all **)
clasohm@923
    80
clasohm@923
    81
goal List.thy "(Alls x:xs.True) = True";
clasohm@923
    82
by (list.induct_tac "xs" 1);
clasohm@1264
    83
by (ALLGOALS Asm_simp_tac);
clasohm@923
    84
qed "list_all_True";
clasohm@923
    85
clasohm@923
    86
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
clasohm@923
    87
by (list.induct_tac "xs" 1);
clasohm@1264
    88
by (ALLGOALS Asm_simp_tac);
clasohm@923
    89
qed "list_all_conj";
clasohm@923
    90
clasohm@923
    91
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
clasohm@923
    92
by (list.induct_tac "xs" 1);
clasohm@1264
    93
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
lcp@1169
    94
by (fast_tac HOL_cs 1);
clasohm@923
    95
qed "list_all_mem_conv";
clasohm@923
    96
clasohm@923
    97
clasohm@923
    98
(** list_case **)
clasohm@923
    99
clasohm@923
   100
goal List.thy
clasohm@923
   101
 "P(list_case a f xs) = ((xs=[] --> P(a)) & \
clasohm@923
   102
\                         (!y ys. xs=y#ys --> P(f y ys)))";
clasohm@923
   103
by (list.induct_tac "xs" 1);
clasohm@1264
   104
by (ALLGOALS Asm_simp_tac);
lcp@1169
   105
by (fast_tac HOL_cs 1);
clasohm@923
   106
qed "expand_list_case";
clasohm@923
   107
clasohm@923
   108
goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
lcp@1169
   109
by (list.induct_tac "xs" 1);
lcp@1169
   110
by (fast_tac HOL_cs 1);
lcp@1169
   111
by (fast_tac HOL_cs 1);
clasohm@923
   112
bind_thm("list_eq_cases",
clasohm@923
   113
  impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
clasohm@923
   114
clasohm@923
   115
(** flat **)
clasohm@923
   116
clasohm@923
   117
goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
clasohm@923
   118
by (list.induct_tac "xs" 1);
clasohm@1264
   119
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_assoc])));
clasohm@923
   120
qed"flat_append";
clasohm@923
   121
nipkow@962
   122
(** length **)
nipkow@962
   123
nipkow@962
   124
goal List.thy "length(xs@ys) = length(xs)+length(ys)";
nipkow@962
   125
by (list.induct_tac "xs" 1);
clasohm@1264
   126
by (ALLGOALS Asm_simp_tac);
nipkow@962
   127
qed"length_append";
nipkow@962
   128
lcp@1169
   129
goal List.thy "length(rev xs) = length(xs)";
lcp@1169
   130
by (list.induct_tac "xs" 1);
clasohm@1264
   131
by (ALLGOALS (asm_simp_tac (!simpset addsimps [length_append])));
lcp@1169
   132
qed "length_rev";
lcp@1169
   133
clasohm@923
   134
(** nth **)
clasohm@923
   135
clasohm@923
   136
val [nth_0,nth_Suc] = nat_recs nth_def; 
clasohm@923
   137
store_thm("nth_0",nth_0);
clasohm@923
   138
store_thm("nth_Suc",nth_Suc);
clasohm@923
   139
clasohm@923
   140
(** Additional mapping lemmas **)
clasohm@923
   141
nipkow@995
   142
goal List.thy "map (%x.x) = (%xs.xs)";
nipkow@995
   143
by (rtac ext 1);
clasohm@923
   144
by (list.induct_tac "xs" 1);
clasohm@1264
   145
by (ALLGOALS Asm_simp_tac);
clasohm@923
   146
qed "map_ident";
clasohm@923
   147
clasohm@923
   148
goal List.thy "map f (xs@ys) = map f xs @ map f ys";
clasohm@923
   149
by (list.induct_tac "xs" 1);
clasohm@1264
   150
by (ALLGOALS Asm_simp_tac);
clasohm@923
   151
qed "map_append";
clasohm@923
   152
clasohm@923
   153
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)";
clasohm@923
   154
by (list.induct_tac "xs" 1);
clasohm@1264
   155
by (ALLGOALS Asm_simp_tac);
clasohm@923
   156
qed "map_compose";
clasohm@923
   157
lcp@1169
   158
goal List.thy "rev(map f l) = map f (rev l)";
lcp@1169
   159
by (list.induct_tac "l" 1);
clasohm@1264
   160
by (ALLGOALS (asm_simp_tac (!simpset addsimps [map_append])));
lcp@1169
   161
qed "rev_map_distrib";
lcp@1169
   162
lcp@1169
   163
goal List.thy "rev(flat ls) = flat (map rev (rev ls))";
lcp@1169
   164
by (list.induct_tac "ls" 1);
clasohm@1264
   165
by (ALLGOALS (asm_simp_tac (!simpset addsimps 
lcp@1169
   166
       [map_append, flat_append, rev_append, append_Nil2])));
lcp@1169
   167
qed "rev_flat";
lcp@1169
   168
clasohm@1264
   169
Addsimps
clasohm@923
   170
  [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
clasohm@923
   171
   mem_append, mem_filter,
nipkow@1202
   172
   rev_append, rev_rev_ident,
clasohm@923
   173
   map_ident, map_append, map_compose,
nipkow@962
   174
   flat_append, length_append, list_all_True, list_all_conj, nth_0, nth_Suc];
clasohm@923
   175