src/HOL/List.ML
author nipkow
Mon, 27 Mar 1995 18:29:23 +0200
changeset 974 68d58134fad6
parent 962 136308504cd9
child 995 95c148a7b9c4
permissions -rw-r--r--
Added recursion equations for foldl to list_ss.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     1
(*  Title: 	HOL/List
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     3
    Author: 	Tobias Nipkow
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994 TU Muenchen
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
List lemmas
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
open List;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
val [Nil_not_Cons,Cons_not_Nil] = list.distinct;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
bind_thm("Cons_neq_Nil", Cons_not_Nil RS notE);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
bind_thm("Nil_neq_Cons", sym RS Cons_neq_Nil);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
bind_thm("Cons_inject", (hd list.inject) RS iffD1 RS conjE);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
val list_ss = HOL_ss addsimps list.simps;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
goal List.thy "!x. xs ~= x#xs";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
by (ALLGOALS (asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
qed "not_Cons_self";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
by(simp_tac list_ss 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
by(asm_simp_tac list_ss 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
by(REPEAT(resolve_tac [exI,refl,conjI] 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
qed "neq_Nil_conv";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
val list_ss = arith_ss addsimps list.simps @
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
  [null_Nil, null_Cons, hd_Cons, tl_Cons, ttl_Nil, ttl_Cons,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
   mem_Nil, mem_Cons,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
   append_Nil, append_Cons,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
   map_Nil, map_Cons,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
   flat_Nil, flat_Cons,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
   list_all_Nil, list_all_Cons,
962
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
    39
   filter_Nil, filter_Cons,
974
68d58134fad6 Added recursion equations for foldl to list_ss.
nipkow
parents: 962
diff changeset
    40
   foldl_Nil, foldl_Cons,
962
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
    41
   length_Nil, length_Cons];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
(** @ - append **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
qed "append_assoc";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
goal List.thy "xs @ [] = xs";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
qed "append_Nil2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
qed "append_is_Nil";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
qed "same_append_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
(** mem **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
qed "mem_append";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
qed "mem_filter";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
(** list_all **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
goal List.thy "(Alls x:xs.True) = True";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
qed "list_all_True";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
goal List.thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
qed "list_all_conj";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
by(fast_tac HOL_cs 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
qed "list_all_mem_conv";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
(** list_case **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
goal List.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
 "P(list_case a f xs) = ((xs=[] --> P(a)) & \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
\                         (!y ys. xs=y#ys --> P(f y ys)))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
by(ALLGOALS(asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   105
by(fast_tac HOL_cs 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
qed "expand_list_case";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
by(list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
by(fast_tac HOL_cs 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
by(fast_tac HOL_cs 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
bind_thm("list_eq_cases",
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
  impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
(** flat **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
by(ALLGOALS(asm_simp_tac (list_ss addsimps [append_assoc])));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
qed"flat_append";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
962
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   122
(** length **)
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   123
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   124
goal List.thy "length(xs@ys) = length(xs)+length(ys)";
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   125
by (list.induct_tac "xs" 1);
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   126
by(ALLGOALS(asm_simp_tac list_ss));
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   127
qed"length_append";
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   128
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   129
(** nth **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   130
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
val [nth_0,nth_Suc] = nat_recs nth_def; 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   132
store_thm("nth_0",nth_0);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   133
store_thm("nth_Suc",nth_Suc);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
(** Additional mapping lemmas **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
goal List.thy "map (%x.x) xs = xs";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
by (ALLGOALS (asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
qed "map_ident";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
goal List.thy "map f (xs@ys) = map f xs @ map f ys";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   143
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
by (ALLGOALS (asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
qed "map_append";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   146
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
goalw List.thy [o_def] "map (f o g) xs = map f (map g xs)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148
by (list.induct_tac "xs" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   149
by (ALLGOALS (asm_simp_tac list_ss));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   150
qed "map_compose";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   151
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   152
val list_ss = list_ss addsimps
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   153
  [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   154
   mem_append, mem_filter,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   155
   map_ident, map_append, map_compose,
962
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   156
   flat_append, length_append, list_all_True, list_all_conj, nth_0, nth_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   157