src/ZF/List.ML
author paulson
Fri, 14 Aug 1998 18:37:28 +0200
changeset 5321 f8848433d240
parent 5147 825877190618
child 5529 4a54acae6a15
permissions -rw-r--r--
got rid of some goal thy commands
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
     1
(*  Title:      ZF/List.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Datatype definition of Lists
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
     9
open List;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    11
(*** Aspects of the datatype definition ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    13
Addsimps list.case_eqns;
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    14
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    15
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
(*An elimination rule, for type-checking*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    17
val ConsE = list.mk_cases list.con_defs "Cons(a,l) : list(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
(*Proving freeness results*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    20
val Cons_iff     = list.mk_free "Cons(a,l)=Cons(a',l') <-> a=a' & l=l'";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    21
val Nil_Cons_iff = list.mk_free "~ Nil=Cons(a,l)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
(*Perform induction on l, then prove the major premise using prems. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
fun list_ind_tac a prems i = 
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    25
    EVERY [res_inst_tac [("x",a)] list.induct i,
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
    26
           rename_last_tac a ["1"] (i+2),
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
    27
           ares_tac prems i];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    29
Goal "list(A) = {0} + (A * list(A))";
525
e62519a8497d ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents: 516
diff changeset
    30
let open list;  val rew = rewrite_rule con_defs in  
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    31
by (blast_tac (claset() addSIs (map rew intrs) addEs [rew elim]) 1)
525
e62519a8497d ZF/List, ex/Brouwer,Data,LList,Ntree,TF,Term: much simplified proof of _unfold
lcp
parents: 516
diff changeset
    32
end;
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    33
qed "list_unfold";
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    34
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
(**  Lemmas to justify using "list" in other recursive type definitions **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
    37
Goalw list.defs "A<=B ==> list(A) <= list(B)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
by (rtac lfp_mono 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    39
by (REPEAT (rtac list.bnd_mono 1));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    41
qed "list_mono";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
(*There is a similar proof by list induction.*)
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    44
Goalw (list.defs@list.con_defs) "list(univ(A)) <= univ(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
by (rtac lfp_lowerbound 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
by (rtac (A_subset_univ RS univ_mono) 2);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    47
by (blast_tac (claset() addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
    48
                            Pair_in_univ]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    49
qed "list_univ";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
908
1f99a44c10cb Updated comment about list_subset_univ and list_into_univ.
lcp
parents: 782
diff changeset
    51
(*These two theorems justify datatypes involving list(nat), list(A), ...*)
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    52
bind_thm ("list_subset_univ", ([list_mono, list_univ] MRS subset_trans));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
    54
Goal "[| l: list(A);  A <= univ(B) |] ==> l: univ(B)";
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    55
by (REPEAT (ares_tac [list_subset_univ RS subsetD] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    56
qed "list_into_univ";
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 279
diff changeset
    57
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
    58
val major::prems = Goal
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
    "[| l: list(A);    \
15
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    60
\       c: C(Nil);       \
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    61
\       !!x y. [| x: A;  y: list(A) |] ==> h(x,y): C(Cons(x,y))  \
6c6d2f6e3185 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
    62
\    |] ==> list_case(c,h,l) : C(l)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    63
by (rtac (major RS list.induct) 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    64
by (ALLGOALS (asm_simp_tac (simpset() addsimps (list.case_eqns @ prems))));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    65
qed "list_case_type";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
(** For recursion **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    70
Goalw list.con_defs "rank(a) < rank(Cons(a,l))";
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
    71
by (simp_tac rank_ss 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    72
qed "rank_Cons1";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    74
Goalw list.con_defs "rank(l) < rank(Cons(a,l))";
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
    75
by (simp_tac rank_ss 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    76
qed "rank_Cons2";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    78
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    79
(*** List functions ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    80
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    81
(** hd and tl **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    82
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    83
Goalw [hd_def] "hd(Cons(a,l)) = a";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    84
by (resolve_tac list.case_eqns 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    85
qed "hd_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    86
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    87
Goalw [tl_def] "tl(Nil) = Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    88
by (resolve_tac list.case_eqns 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    89
qed "tl_Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    90
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    91
Goalw [tl_def] "tl(Cons(a,l)) = l";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    92
by (resolve_tac list.case_eqns 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
    93
qed "tl_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    94
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    95
Addsimps [hd_Cons, tl_Nil, tl_Cons];
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    96
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
    97
Goal "l: list(A) ==> tl(l) : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
    98
by (etac list.elim 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
    99
by (ALLGOALS (asm_simp_tac (simpset() addsimps list.intrs)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   100
qed "tl_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   101
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   102
(** drop **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   103
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   104
Goalw [drop_def] "drop(0, l) = l";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   105
by (rtac rec_0 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   106
qed "drop_0";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   107
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5067
diff changeset
   108
Goalw [drop_def] "i:nat ==> drop(i, Nil) = Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   109
by (etac nat_induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   110
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   111
qed "drop_Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   112
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   113
Goalw [drop_def]
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   114
    "i:nat ==> drop(succ(i), Cons(a,l)) = drop(i,l)";
2493
bdeb5024353a Removal of sum_cs and eq_cs
paulson
parents: 2469
diff changeset
   115
by (rtac sym 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   116
by (etac nat_induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   117
by (Simp_tac 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   118
by (Asm_simp_tac 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   119
qed "drop_succ_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   120
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   121
Addsimps [drop_0, drop_Nil, drop_succ_Cons];
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   122
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   123
Goalw [drop_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   124
    "[| i:nat; l: list(A) |] ==> drop(i,l) : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   125
by (etac nat_induct 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   126
by (ALLGOALS (asm_simp_tac (simpset() addsimps [tl_type])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   127
qed "drop_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   128
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   129
(** list_rec -- by Vset recursion **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   130
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   131
Goal "list_rec(Nil,c,h) = c";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   132
by (rtac (list_rec_def RS def_Vrec RS trans) 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   133
by (simp_tac (simpset() addsimps list.case_eqns) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   134
qed "list_rec_Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   135
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   136
Goal "list_rec(Cons(a,l), c, h) = h(a, l, list_rec(l,c,h))";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   137
by (rtac (list_rec_def RS def_Vrec RS trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   138
by (simp_tac (rank_ss addsimps (rank_Cons2::list.case_eqns)) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   139
qed "list_rec_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   140
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   141
Addsimps [list_rec_Nil, list_rec_Cons];
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   142
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   143
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   144
(*Type checking -- proved by induction, as usual*)
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   145
val prems = Goal
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   146
    "[| l: list(A);    \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   147
\       c: C(Nil);       \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   148
\       !!x y r. [| x:A;  y: list(A);  r: C(y) |] ==> h(x,y,r): C(Cons(x,y))  \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   149
\    |] ==> list_rec(l,c,h) : C(l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   150
by (list_ind_tac "l" prems 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   151
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   152
qed "list_rec_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   153
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   154
(** Versions for use with definitions **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   155
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   156
val [rew] = Goal "[| !!l. j(l)==list_rec(l, c, h) |] ==> j(Nil) = c";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   157
by (rewtac rew);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   158
by (rtac list_rec_Nil 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   159
qed "def_list_rec_Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   160
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   161
val [rew] = Goal "[| !!l. j(l)==list_rec(l, c, h) |] ==> j(Cons(a,l)) = h(a,l,j(l))";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   162
by (rewtac rew);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   163
by (rtac list_rec_Cons 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   164
qed "def_list_rec_Cons";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   165
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   166
fun list_recs def = map standard
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 908
diff changeset
   167
        ([def] RL [def_list_rec_Nil, def_list_rec_Cons]);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   168
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   169
(** map **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   170
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   171
val [map_Nil,map_Cons] = list_recs map_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   172
Addsimps [map_Nil, map_Cons];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   173
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   174
val prems = Goalw [map_def] 
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   175
    "[| l: list(A);  !!x. x: A ==> h(x): B |] ==> map(h,l) : list(B)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   176
by (REPEAT (ares_tac (prems @ list.intrs @ [list_rec_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   177
qed "map_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   178
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   179
Goal "l: list(A) ==> map(h,l) : list({h(u). u:A})";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   180
by (etac map_type 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   181
by (etac RepFunI 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   182
qed "map_type2";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   183
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   184
(** length **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   185
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   186
val [length_Nil,length_Cons] = list_recs length_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   187
Addsimps [length_Nil,length_Cons];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   188
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   189
Goalw [length_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   190
    "l: list(A) ==> length(l) : nat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   191
by (REPEAT (ares_tac [list_rec_type, nat_0I, nat_succI] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   192
qed "length_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   193
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   194
(** app **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   195
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   196
val [app_Nil,app_Cons] = list_recs app_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   197
Addsimps [app_Nil, app_Cons];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   198
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   199
Goalw [app_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   200
    "[| xs: list(A);  ys: list(A) |] ==> xs@ys : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   201
by (REPEAT (ares_tac [list_rec_type, list.Cons_I] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   202
qed "app_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   203
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   204
(** rev **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   205
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   206
val [rev_Nil,rev_Cons] = list_recs rev_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   207
Addsimps [rev_Nil,rev_Cons] ;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   208
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   209
Goalw [rev_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   210
    "xs: list(A) ==> rev(xs) : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   211
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   212
qed "rev_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   213
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   214
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   215
(** flat **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   216
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   217
val [flat_Nil,flat_Cons] = list_recs flat_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   218
Addsimps [flat_Nil,flat_Cons];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   219
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   220
Goalw [flat_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   221
    "ls: list(list(A)) ==> flat(ls) : list(A)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   222
by (REPEAT (ares_tac (list.intrs @ [list_rec_type, app_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   223
qed "flat_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   224
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   225
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   226
(** set_of_list **)
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   227
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   228
val [set_of_list_Nil,set_of_list_Cons] = list_recs set_of_list_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   229
Addsimps [set_of_list_Nil,set_of_list_Cons];
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   230
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   231
Goalw [set_of_list_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   232
    "l: list(A) ==> set_of_list(l) : Pow(A)";
2033
639de962ded4 Ran expandshort; used stac instead of ssubst
paulson
parents: 1926
diff changeset
   233
by (etac list_rec_type 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   234
by (ALLGOALS (Blast_tac));
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   235
qed "set_of_list_type";
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   236
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   237
Goal "xs: list(A) ==> \
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   238
\         set_of_list (xs@ys) = set_of_list(xs) Un set_of_list(ys)";
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   239
by (etac list.induct 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   240
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Un_cons])));
1926
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   241
qed "set_of_list_append";
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   242
1957ae3f9301 Addition of function set_of_list
paulson
parents: 1663
diff changeset
   243
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   244
(** list_add **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   245
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   246
val [list_add_Nil,list_add_Cons] = list_recs list_add_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   247
Addsimps [list_add_Nil,list_add_Cons];
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   248
5067
62b6288e6005 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
   249
Goalw [list_add_def] 
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   250
    "xs: list(nat) ==> list_add(xs) : nat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   251
by (REPEAT (ares_tac [list_rec_type, nat_0I, add_type] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   252
qed "list_add_type";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   253
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   254
val list_typechecks =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   255
    list.intrs @
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   256
    [list_rec_type, map_type, map_type2, app_type, length_type, 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   257
     rev_type, flat_type, list_add_type];
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   258
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   259
simpset_ref() := simpset() setSolver (type_auto_tac list_typechecks);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   260
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   261
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   262
(*** theorems about map ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   263
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   264
Goal "l: list(A) ==> map(%u. u, l) = l";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   265
by (list_ind_tac "l" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   266
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   267
qed "map_ident";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   268
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   269
Goal "l: list(A) ==> map(h, map(j,l)) = map(%u. h(j(u)), l)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   270
by (list_ind_tac "l" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   271
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   272
qed "map_compose";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   273
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   274
Goal "xs: list(A) ==> map(h, xs@ys) = map(h,xs) @ map(h,ys)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   275
by (list_ind_tac "xs" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   276
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   277
qed "map_app_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   278
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   279
Goal "ls: list(list(A)) ==> map(h, flat(ls)) = flat(map(map(h),ls))";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   280
by (list_ind_tac "ls" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   281
by (ALLGOALS (asm_simp_tac (simpset() addsimps [map_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   282
qed "map_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   283
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   284
Goal "l: list(A) ==> \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   285
\    list_rec(map(h,l), c, d) = \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   286
\    list_rec(l, c, %x xs r. d(h(x), map(h,xs), r))";
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   287
by (list_ind_tac "l" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   288
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   289
qed "list_rec_map";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   290
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   291
(** theorems about list(Collect(A,P)) -- used in ex/term.ML **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   292
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   293
(* c : list(Collect(B,P)) ==> c : list(B) *)
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   294
bind_thm ("list_CollectD", (Collect_subset RS list_mono RS subsetD));
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   295
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   296
Goal "l: list({x:A. h(x)=j(x)}) ==> map(h,l) = map(j,l)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   297
by (list_ind_tac "l" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   298
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   299
qed "map_list_Collect";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   300
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   301
(*** theorems about length ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   302
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   303
Goal "xs: list(A) ==> length(map(h,xs)) = length(xs)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   304
by (list_ind_tac "xs" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   305
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   306
qed "length_map";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   307
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   308
Goal "xs: list(A) ==> length(xs@ys) = length(xs) #+ length(ys)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   309
by (list_ind_tac "xs" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   310
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   311
qed "length_app";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   312
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   313
(* [| m: nat; n: nat |] ==> m #+ succ(n) = succ(n) #+ m 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   314
   Used for rewriting below*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   315
val add_commute_succ = nat_succI RSN (2,add_commute);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   316
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   317
Goal "xs: list(A) ==> length(rev(xs)) = length(xs)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   318
by (list_ind_tac "xs" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   319
by (ALLGOALS (asm_simp_tac (simpset() addsimps [length_app, add_commute_succ])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   320
qed "length_rev";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   321
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   322
Goal "ls: list(list(A)) ==> length(flat(ls)) = list_add(map(length,ls))";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   323
by (list_ind_tac "ls" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   324
by (ALLGOALS (asm_simp_tac (simpset() addsimps [length_app])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   325
qed "length_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   326
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   327
(** Length and drop **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   328
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   329
(*Lemma for the inductive step of drop_length*)
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   330
Goal "xs: list(A) ==> \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   331
\          ALL x.  EX z zs. drop(length(xs), Cons(x,xs)) = Cons(z,zs)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   332
by (etac list.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   333
by (ALLGOALS Asm_simp_tac);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   334
by (Blast_tac 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   335
qed "drop_length_Cons_lemma";
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   336
bind_thm ("drop_length_Cons", (drop_length_Cons_lemma RS spec));
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   337
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   338
Goal "l: list(A) ==> ALL i: length(l).  EX z zs. drop(i,l) = Cons(z,zs)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   339
by (etac list.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   340
by (ALLGOALS Asm_simp_tac);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   341
by (rtac conjI 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   342
by (etac drop_length_Cons 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   343
by (rtac ballI 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   344
by (rtac natE 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   345
by (etac ([asm_rl, length_type, Ord_nat] MRS Ord_trans) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   346
by (assume_tac 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   347
by (ALLGOALS Asm_simp_tac);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   348
by (ALLGOALS (blast_tac (claset() addIs [succ_in_naturalD, length_type])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   349
qed "drop_length_lemma";
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   350
bind_thm ("drop_length", (drop_length_lemma RS bspec));
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   351
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   352
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   353
(*** theorems about app ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   354
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   355
Goal "xs: list(A) ==> xs@Nil=xs";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   356
by (etac list.induct 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   357
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   358
qed "app_right_Nil";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   359
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   360
Goal "xs: list(A) ==> (xs@ys)@zs = xs@(ys@zs)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   361
by (list_ind_tac "xs" [] 1);
3016
15763781afb0 Conversion to use blast_tac
paulson
parents: 2637
diff changeset
   362
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   363
qed "app_assoc";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   364
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   365
Goal "ls: list(list(A)) ==> flat(ls@ms) = flat(ls)@flat(ms)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   366
by (list_ind_tac "ls" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   367
by (ALLGOALS (asm_simp_tac (simpset() addsimps [app_assoc])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   368
qed "flat_app_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   369
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   370
(*** theorems about rev ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   371
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   372
Goal "l: list(A) ==> rev(map(h,l)) = map(h,rev(l))";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   373
by (list_ind_tac "l" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   374
by (ALLGOALS (asm_simp_tac (simpset() addsimps [map_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   375
qed "rev_map_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   376
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   377
(*Simplifier needs the premises as assumptions because rewriting will not
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   378
  instantiate the variable ?A in the rules' typing conditions; note that
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   379
  rev_type does not instantiate ?A.  Only the premises do.
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   380
*)
5147
825877190618 More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5137
diff changeset
   381
Goal "[| xs: list(A);  ys: list(A) |] ==> rev(xs@ys) = rev(ys)@rev(xs)";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   382
by (etac list.induct 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   383
by (ALLGOALS (asm_simp_tac (simpset() addsimps [app_right_Nil,app_assoc])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   384
qed "rev_app_distrib";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   385
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   386
Goal "l: list(A) ==> rev(rev(l))=l";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   387
by (list_ind_tac "l" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   388
by (ALLGOALS (asm_simp_tac (simpset() addsimps [rev_app_distrib])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   389
qed "rev_rev_ident";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   390
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   391
Goal "ls: list(list(A)) ==> rev(flat(ls)) = flat(map(rev,rev(ls)))";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   392
by (list_ind_tac "ls" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   393
by (ALLGOALS (asm_simp_tac (simpset() addsimps 
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   394
       [map_app_distrib, flat_app_distrib, rev_app_distrib, app_right_Nil])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   395
qed "rev_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   396
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   397
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   398
(*** theorems about list_add ***)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   399
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   400
Goal "[| xs: list(nat);  ys: list(nat) |] ==> \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   401
\    list_add(xs@ys) = list_add(ys) #+ list_add(xs)";
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   402
by (list_ind_tac "xs" [] 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   403
by (ALLGOALS 
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   404
    (asm_simp_tac (simpset() addsimps [add_0_right, add_assoc RS sym])));
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   405
by (rtac (add_commute RS subst_context) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   406
by (REPEAT (ares_tac [refl, list_add_type] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   407
qed "list_add_app";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   408
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   409
Goal "l: list(nat) ==> list_add(rev(l)) = list_add(l)";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   410
by (list_ind_tac "l" [] 1);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   411
by (ALLGOALS
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   412
    (asm_simp_tac (simpset() addsimps [list_add_app, add_0_right])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   413
qed "list_add_rev";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   414
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   415
Goal "ls: list(list(nat)) ==> list_add(flat(ls)) = list_add(map(list_add,ls))";
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   416
by (list_ind_tac "ls" [] 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   417
by (ALLGOALS (asm_simp_tac (simpset() addsimps [list_add_app])));
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   418
by (REPEAT (ares_tac [refl, list_add_type, map_type, add_commute] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   419
qed "list_add_flat";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   420
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   421
(** New induction rule **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   422
5321
f8848433d240 got rid of some goal thy commands
paulson
parents: 5147
diff changeset
   423
val major::prems = Goal
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   424
    "[| l: list(A);  \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   425
\       P(Nil);        \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   426
\       !!x y. [| x: A;  y: list(A);  P(y) |] ==> P(y @ [x]) \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   427
\    |] ==> P(l)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   428
by (rtac (major RS rev_rev_ident RS subst) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   429
by (rtac (major RS rev_type RS list.induct) 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 3840
diff changeset
   430
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 525
diff changeset
   431
qed "list_append_induct";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 484
diff changeset
   432