src/HOL/List.ML
author regensbu
Fri, 06 Oct 1995 16:17:08 +0100
changeset 1273 6960ec882bca
parent 1264 3eb91524b938
child 1301 42782316d510
permissions -rw-r--r--
added 8bit pragmas
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
goal List.thy "!x. xs ~= x#xs";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    20
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
qed "not_Cons_self";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    25
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    26
by (Asm_simp_tac 1);
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    27
by (REPEAT(resolve_tac [exI,refl,conjI] 1));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
qed "neq_Nil_conv";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
(** @ - append **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    35
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
qed "append_assoc";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
goal List.thy "xs @ [] = xs";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    40
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
qed "append_Nil2";
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
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    45
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
qed "append_is_Nil";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    50
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
qed "same_append_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    54
(** rev **)
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    55
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    56
goal List.thy "rev(xs@ys) = rev(ys) @ rev(xs)";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    57
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    58
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_Nil2,append_assoc])));
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    59
qed "rev_append";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    60
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    61
goal List.thy "rev(rev l) = l";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    62
by (list.induct_tac "l" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    63
by (ALLGOALS (asm_simp_tac (!simpset addsimps [rev_append])));
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    64
qed "rev_rev_ident";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    65
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    66
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    71
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    76
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    83
by (ALLGOALS Asm_simp_tac);
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    88
by (ALLGOALS Asm_simp_tac);
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
    93
by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
    94
by (fast_tac HOL_cs 1);
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   104
by (ALLGOALS Asm_simp_tac);
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   105
by (fast_tac HOL_cs 1);
923
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)";
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   109
by (list.induct_tac "xs" 1);
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   110
by (fast_tac HOL_cs 1);
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   111
by (fast_tac HOL_cs 1);
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   119
by (ALLGOALS (asm_simp_tac (!simpset addsimps [append_assoc])));
923
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);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   126
by (ALLGOALS Asm_simp_tac);
962
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
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   129
goal List.thy "length(rev xs) = length(xs)";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   130
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   131
by (ALLGOALS (asm_simp_tac (!simpset addsimps [length_append])));
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   132
qed "length_rev";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   133
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
(** nth **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
val [nth_0,nth_Suc] = nat_recs nth_def; 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
store_thm("nth_0",nth_0);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
store_thm("nth_Suc",nth_Suc);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
(** Additional mapping lemmas **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
995
95c148a7b9c4 generalized map (%x.x) xs = xs to map (%x.x) = (%xs.xs)
nipkow
parents: 974
diff changeset
   142
goal List.thy "map (%x.x) = (%xs.xs)";
95c148a7b9c4 generalized map (%x.x) xs = xs to map (%x.x) = (%xs.xs)
nipkow
parents: 974
diff changeset
   143
by (rtac ext 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   145
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   146
qed "map_ident";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148
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
   149
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   150
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   151
qed "map_append";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   152
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   153
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
   154
by (list.induct_tac "xs" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   155
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   156
qed "map_compose";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   157
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   158
goal List.thy "rev(map f l) = map f (rev l)";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   159
by (list.induct_tac "l" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   160
by (ALLGOALS (asm_simp_tac (!simpset addsimps [map_append])));
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   161
qed "rev_map_distrib";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   162
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   163
goal List.thy "rev(flat ls) = flat (map rev (rev ls))";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   164
by (list.induct_tac "ls" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   165
by (ALLGOALS (asm_simp_tac (!simpset addsimps 
1169
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   166
       [map_append, flat_append, rev_append, append_Nil2])));
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   167
qed "rev_flat";
5873833cf37f Added function rev and its properties length_rev, etc.
lcp
parents: 995
diff changeset
   168
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1202
diff changeset
   169
Addsimps
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   170
  [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
   171
   mem_append, mem_filter,
1202
968cd786a748 Added rev_append and rev_rev_ident to list_ss.
nipkow
parents: 1169
diff changeset
   172
   rev_append, rev_rev_ident,
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   173
   map_ident, map_append, map_compose,
962
136308504cd9 Added a few thms to nat_ss and list_ss
nipkow
parents: 923
diff changeset
   174
   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
   175