src/HOL/List.ML
author clasohm
Fri Mar 03 12:02:25 1995 +0100 (1995-03-03)
changeset 923 ff1574a81019
child 962 136308504cd9
permissions -rw-r--r--
new version of HOL with curried function application
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
val list_ss = HOL_ss addsimps list.simps;
clasohm@923
    19
clasohm@923
    20
goal List.thy "!x. xs ~= x#xs";
clasohm@923
    21
by (list.induct_tac "xs" 1);
clasohm@923
    22
by (ALLGOALS (asm_simp_tac list_ss));
clasohm@923
    23
qed "not_Cons_self";
clasohm@923
    24
clasohm@923
    25
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
clasohm@923
    26
by (list.induct_tac "xs" 1);
clasohm@923
    27
by(simp_tac list_ss 1);
clasohm@923
    28
by(asm_simp_tac list_ss 1);
clasohm@923
    29
by(REPEAT(resolve_tac [exI,refl,conjI] 1));
clasohm@923
    30
qed "neq_Nil_conv";
clasohm@923
    31
clasohm@923
    32
val list_ss = arith_ss addsimps list.simps @
clasohm@923
    33
  [null_Nil, null_Cons, hd_Cons, tl_Cons, ttl_Nil, ttl_Cons,
clasohm@923
    34
   mem_Nil, mem_Cons,
clasohm@923
    35
   append_Nil, append_Cons,
clasohm@923
    36
   map_Nil, map_Cons,
clasohm@923
    37
   flat_Nil, flat_Cons,
clasohm@923
    38
   list_all_Nil, list_all_Cons,
clasohm@923
    39
   filter_Nil, filter_Cons];
clasohm@923
    40
clasohm@923
    41
clasohm@923
    42
(** @ - append **)
clasohm@923
    43
clasohm@923
    44
goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
clasohm@923
    45
by (list.induct_tac "xs" 1);
clasohm@923
    46
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
    47
qed "append_assoc";
clasohm@923
    48
clasohm@923
    49
goal List.thy "xs @ [] = xs";
clasohm@923
    50
by (list.induct_tac "xs" 1);
clasohm@923
    51
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
    52
qed "append_Nil2";
clasohm@923
    53
clasohm@923
    54
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
clasohm@923
    55
by (list.induct_tac "xs" 1);
clasohm@923
    56
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
    57
qed "append_is_Nil";
clasohm@923
    58
clasohm@923
    59
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
clasohm@923
    60
by (list.induct_tac "xs" 1);
clasohm@923
    61
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
    62
qed "same_append_eq";
clasohm@923
    63
clasohm@923
    64
clasohm@923
    65
(** mem **)
clasohm@923
    66
clasohm@923
    67
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
clasohm@923
    68
by (list.induct_tac "xs" 1);
clasohm@923
    69
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
clasohm@923
    70
qed "mem_append";
clasohm@923
    71
clasohm@923
    72
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
clasohm@923
    73
by (list.induct_tac "xs" 1);
clasohm@923
    74
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
clasohm@923
    75
qed "mem_filter";
clasohm@923
    76
clasohm@923
    77
(** list_all **)
clasohm@923
    78
clasohm@923
    79
goal List.thy "(Alls x:xs.True) = True";
clasohm@923
    80
by (list.induct_tac "xs" 1);
clasohm@923
    81
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
    82
qed "list_all_True";
clasohm@923
    83
clasohm@923
    84
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
clasohm@923
    85
by (list.induct_tac "xs" 1);
clasohm@923
    86
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
    87
qed "list_all_conj";
clasohm@923
    88
clasohm@923
    89
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
clasohm@923
    90
by (list.induct_tac "xs" 1);
clasohm@923
    91
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
clasohm@923
    92
by(fast_tac HOL_cs 1);
clasohm@923
    93
qed "list_all_mem_conv";
clasohm@923
    94
clasohm@923
    95
clasohm@923
    96
(** list_case **)
clasohm@923
    97
clasohm@923
    98
goal List.thy
clasohm@923
    99
 "P(list_case a f xs) = ((xs=[] --> P(a)) & \
clasohm@923
   100
\                         (!y ys. xs=y#ys --> P(f y ys)))";
clasohm@923
   101
by (list.induct_tac "xs" 1);
clasohm@923
   102
by(ALLGOALS(asm_simp_tac list_ss));
clasohm@923
   103
by(fast_tac HOL_cs 1);
clasohm@923
   104
qed "expand_list_case";
clasohm@923
   105
clasohm@923
   106
goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
clasohm@923
   107
by(list.induct_tac "xs" 1);
clasohm@923
   108
by(fast_tac HOL_cs 1);
clasohm@923
   109
by(fast_tac HOL_cs 1);
clasohm@923
   110
bind_thm("list_eq_cases",
clasohm@923
   111
  impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
clasohm@923
   112
clasohm@923
   113
(** flat **)
clasohm@923
   114
clasohm@923
   115
goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
clasohm@923
   116
by (list.induct_tac "xs" 1);
clasohm@923
   117
by(ALLGOALS(asm_simp_tac (list_ss addsimps [append_assoc])));
clasohm@923
   118
qed"flat_append";
clasohm@923
   119
clasohm@923
   120
(** nth **)
clasohm@923
   121
clasohm@923
   122
val [nth_0,nth_Suc] = nat_recs nth_def; 
clasohm@923
   123
store_thm("nth_0",nth_0);
clasohm@923
   124
store_thm("nth_Suc",nth_Suc);
clasohm@923
   125
clasohm@923
   126
(** Additional mapping lemmas **)
clasohm@923
   127
clasohm@923
   128
goal List.thy "map (%x.x) xs = xs";
clasohm@923
   129
by (list.induct_tac "xs" 1);
clasohm@923
   130
by (ALLGOALS (asm_simp_tac list_ss));
clasohm@923
   131
qed "map_ident";
clasohm@923
   132
clasohm@923
   133
goal List.thy "map f (xs@ys) = map f xs @ map f ys";
clasohm@923
   134
by (list.induct_tac "xs" 1);
clasohm@923
   135
by (ALLGOALS (asm_simp_tac list_ss));
clasohm@923
   136
qed "map_append";
clasohm@923
   137
clasohm@923
   138
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)";
clasohm@923
   139
by (list.induct_tac "xs" 1);
clasohm@923
   140
by (ALLGOALS (asm_simp_tac list_ss));
clasohm@923
   141
qed "map_compose";
clasohm@923
   142
clasohm@923
   143
val list_ss = list_ss addsimps
clasohm@923
   144
  [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
clasohm@923
   145
   mem_append, mem_filter,
clasohm@923
   146
   map_ident, map_append, map_compose,
clasohm@923
   147
   flat_append, list_all_True, list_all_conj, nth_0, nth_Suc];
clasohm@923
   148