List.ML
author nipkow
Mon, 13 Feb 1995 15:12:08 +0100
changeset 212 2740293cc458
parent 210 1a3d3b5b5d15
child 233 f02021cf7cec
permissions -rw-r--r--
Added "flat"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
113
0b9b8eb74101 HOL/List: rotated arguments of List_case, list_case
lcp
parents: 83
diff changeset
     1
(*  Title: 	HOL/List
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
     3
    Author: 	Tobias Nipkow
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
     4
    Copyright   1994 TU Muenchen
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     5
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
     6
List lemmas
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     7
*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     8
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     9
open List;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    10
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    11
val [Nil_not_Cons,Cons_not_Nil] = list.distinct;
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    12
202
c533bc92e882 added bind_thm for theorems made by "standard ..."
clasohm
parents: 199
diff changeset
    13
bind_thm("Cons_neq_Nil", Cons_not_Nil RS notE);
199
ad45e477926c replaced store_thm by bind_thm
clasohm
parents: 196
diff changeset
    14
bind_thm("Nil_neq_Cons", sym RS Cons_neq_Nil);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    15
202
c533bc92e882 added bind_thm for theorems made by "standard ..."
clasohm
parents: 199
diff changeset
    16
bind_thm("Cons_inject", (hd list.inject) RS iffD1 RS conjE);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    17
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    18
val list_ss = HOL_ss addsimps list.simps;
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    19
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    20
goal List.thy "!x. xs ~= x#xs";
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    21
by (list.induct_tac "xs" 1);
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    22
by (ALLGOALS (asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    23
qed "not_Cons_self";
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    24
48
21291189b51e changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents: 44
diff changeset
    25
goal List.thy "(xs ~= []) = (? y ys. xs = y#ys)";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    26
by (list.induct_tac "xs" 1);
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    27
by(simp_tac list_ss 1);
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    28
by(asm_simp_tac list_ss 1);
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    29
by(REPEAT(resolve_tac [exI,refl,conjI] 1));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    30
qed "neq_Nil_conv";
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    31
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    32
val list_ss = arith_ss addsimps list.simps @
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    33
  [null_Nil, null_Cons, hd_Cons, tl_Cons, ttl_Nil, ttl_Cons,
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    34
   mem_Nil, mem_Cons,
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    35
   append_Nil, append_Cons,
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    36
   map_Nil, map_Cons,
212
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
    37
   flat_Nil, flat_Cons,
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    38
   list_all_Nil, list_all_Cons,
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    39
   filter_Nil, filter_Cons];
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    40
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    41
13
61b65ffb4186 added append "@"
nipkow
parents: 5
diff changeset
    42
(** @ - append **)
61b65ffb4186 added append "@"
nipkow
parents: 5
diff changeset
    43
61b65ffb4186 added append "@"
nipkow
parents: 5
diff changeset
    44
goal List.thy "(xs@ys)@zs = xs@(ys@zs)";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    45
by (list.induct_tac "xs" 1);
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    46
by(ALLGOALS(asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    47
qed "append_assoc";
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    48
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    49
goal List.thy "xs @ [] = xs";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    50
by (list.induct_tac "xs" 1);
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    51
by(ALLGOALS(asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    52
qed "append_Nil2";
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    53
203
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
    54
goal List.thy "(xs@ys = []) = (xs=[] & ys=[])";
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
    55
by (list.induct_tac "xs" 1);
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
    56
by(ALLGOALS(asm_simp_tac list_ss));
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
    57
qed "append_is_Nil";
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
    58
210
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
    59
goal List.thy "(xs @ ys = xs @ zs) = (ys=zs)";
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
    60
by (list.induct_tac "xs" 1);
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
    61
by(ALLGOALS(asm_simp_tac list_ss));
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
    62
qed "same_append_eq";
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
    63
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
    64
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    65
(** mem **)
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    66
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    67
goal List.thy "x mem (xs@ys) = (x mem xs | x mem ys)";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    68
by (list.induct_tac "xs" 1);
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    69
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    70
qed "mem_append";
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    71
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    72
goal List.thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    73
by (list.induct_tac "xs" 1);
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    74
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    75
qed "mem_filter";
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    76
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    77
(** list_all **)
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    78
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    79
goal List.thy "(Alls x:xs.True) = True";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    80
by (list.induct_tac "xs" 1);
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    81
by(ALLGOALS(asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    82
qed "list_all_True";
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    83
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    84
goal List.thy "list_all(p,xs@ys) = (list_all(p,xs) & list_all(p,ys))";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    85
by (list.induct_tac "xs" 1);
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    86
by(ALLGOALS(asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    87
qed "list_all_conj";
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    88
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    89
goal List.thy "(Alls x:xs.P(x)) = (!x. x mem xs --> P(x))";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
    90
by (list.induct_tac "xs" 1);
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    91
by(ALLGOALS(asm_simp_tac (list_ss setloop (split_tac [expand_if]))));
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    92
by(fast_tac HOL_cs 1);
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
    93
qed "list_all_mem_conv";
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    94
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
    95
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    96
(** list_case **)
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    97
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    98
goal List.thy
113
0b9b8eb74101 HOL/List: rotated arguments of List_case, list_case
lcp
parents: 83
diff changeset
    99
 "P(list_case(a,f,xs)) = ((xs=[] --> P(a)) & \
48
21291189b51e changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents: 44
diff changeset
   100
\                         (!y ys. xs=y#ys --> P(f(y,ys))))";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   101
by (list.induct_tac "xs" 1);
44
64eda8afe2b4 deleted duplicate rewrite rules
nipkow
parents: 40
diff changeset
   102
by(ALLGOALS(asm_simp_tac list_ss));
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   103
by(fast_tac HOL_cs 1);
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
   104
qed "expand_list_case";
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   105
210
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   106
goal List.thy  "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   107
by(list.induct_tac "xs" 1);
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   108
by(fast_tac HOL_cs 1);
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   109
by(fast_tac HOL_cs 1);
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   110
bind_thm("list_eq_cases",
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   111
  impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   112
212
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   113
(** flat **)
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   114
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   115
goal List.thy  "flat(xs@ys) = flat(xs)@flat(ys)";
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   116
by (list.induct_tac "xs" 1);
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   117
by(ALLGOALS(asm_simp_tac (list_ss addsimps [append_assoc])));
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   118
qed"flat_append";
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   119
203
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
   120
(** nth **)
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
   121
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
   122
val [nth_0,nth_Suc] = nat_recs nth_def; 
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
   123
store_thm("nth_0",nth_0);
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
   124
store_thm("nth_Suc",nth_Suc);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   125
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   126
(** Additional mapping lemmas **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   127
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   128
goal List.thy "map(%x.x, xs) = xs";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   129
by (list.induct_tac "xs" 1);
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   130
by (ALLGOALS (asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
   131
qed "map_ident";
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   132
83
e886a3010f8b HOL/List/map_append,map_compose: new
lcp
parents: 48
diff changeset
   133
goal List.thy "map(f, xs@ys) = map(f,xs) @ map(f,ys)";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   134
by (list.induct_tac "xs" 1);
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   135
by (ALLGOALS (asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
   136
qed "map_append";
83
e886a3010f8b HOL/List/map_append,map_compose: new
lcp
parents: 48
diff changeset
   137
e886a3010f8b HOL/List/map_append,map_compose: new
lcp
parents: 48
diff changeset
   138
goalw List.thy [o_def] "map(f o g, xs) = map(f, map(g, xs))";
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   139
by (list.induct_tac "xs" 1);
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   140
by (ALLGOALS (asm_simp_tac list_ss));
171
16c4ea954511 replaced 'val ... = result()' by 'qed "..."'
clasohm
parents: 128
diff changeset
   141
qed "map_compose";
83
e886a3010f8b HOL/List/map_append,map_compose: new
lcp
parents: 48
diff changeset
   142
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 20
diff changeset
   143
val list_ss = list_ss addsimps
210
1a3d3b5b5d15 More rewrite rules.
nipkow
parents: 203
diff changeset
   144
  [not_Cons_self, append_assoc, append_Nil2, append_is_Nil, same_append_eq,
203
d465d3be2744 Added "nth" and some lemmas.
nipkow
parents: 202
diff changeset
   145
   mem_append, mem_filter,
196
61620d959717 Moved the old List to ex and replaced it by one defined via
nipkow
parents: 171
diff changeset
   146
   map_ident, map_append, map_compose,
212
2740293cc458 Added "flat"
nipkow
parents: 210
diff changeset
   147
   flat_append, list_all_True, list_all_conj, nth_0, nth_Suc];
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   148