src/ZF/ex/BT.ML
author paulson
Tue, 22 Sep 1998 15:22:18 +0200
changeset 5530 c361279ebc66
parent 5268 59ef39008514
child 6046 2c8a8be36c94
permissions -rw-r--r--
tidying
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
     1
(*  Title:      ZF/ex/BT.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
     4
    Copyright   1994  University of Cambridge
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Datatype definition of binary trees
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
     9
open BT;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    11
Addsimps bt.case_eqns;
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    12
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
(*Perform induction on l, then prove the major premise using prems. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
fun bt_ind_tac a prems i = 
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    15
    EVERY [res_inst_tac [("x",a)] bt.induct i,
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
    16
           rename_last_tac a ["1","2"] (i+2),
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
    17
           ares_tac prems i];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
(**  Lemmas to justify using "bt" in other recursive type definitions **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    22
Goalw bt.defs "A<=B ==> bt(A) <= bt(B)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
by (rtac lfp_mono 1);
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    24
by (REPEAT (rtac bt.bnd_mono 1));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    26
qed "bt_mono";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
5068
fb28eaa07e01 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    28
Goalw (bt.defs@bt.con_defs) "bt(univ(A)) <= univ(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
by (rtac lfp_lowerbound 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
by (rtac (A_subset_univ RS univ_mono) 2);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    31
by (fast_tac (claset() addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
    32
                            Pair_in_univ]) 1);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    33
qed "bt_univ";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    35
bind_thm ("bt_subset_univ", ([bt_mono, bt_univ] MRS subset_trans));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    37
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    38
(** bt_rec -- by Vset recursion **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    39
5068
fb28eaa07e01 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    40
Goalw bt.con_defs "rank(l) < rank(Br(a,l,r))";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    41
by (simp_tac rank_ss 1);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    42
qed "rank_Br1";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    43
5068
fb28eaa07e01 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    44
Goalw bt.con_defs "rank(r) < rank(Br(a,l,r))";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    45
by (simp_tac rank_ss 1);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    46
qed "rank_Br2";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    47
5068
fb28eaa07e01 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    48
Goal "bt_rec(Lf,c,h) = c";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    49
by (rtac (bt_rec_def RS def_Vrec RS trans) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    50
by (Simp_tac 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 515
diff changeset
    51
qed "bt_rec_Lf";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    52
5268
59ef39008514 even more tidying of Goal commands
paulson
parents: 5137
diff changeset
    53
Goal "bt_rec(Br(a,l,r), c, h) = h(a, l, r, bt_rec(l,c,h), bt_rec(r,c,h))";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    54
by (rtac (bt_rec_def RS def_Vrec RS trans) 1);
5530
c361279ebc66 tidying
paulson
parents: 5268
diff changeset
    55
by (simp_tac (rank_ss addsimps bt.case_eqns @ [rank_Br1, rank_Br2]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 515
diff changeset
    56
qed "bt_rec_Br";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    57
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    58
Addsimps [bt_rec_Lf, bt_rec_Br];
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    59
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    60
(*Type checking -- proved by induction, as usual*)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    61
val prems = goal BT.thy
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    62
    "[| t: bt(A);    \
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    63
\       c: C(Lf);       \
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    64
\       !!x y z r s. [| x:A;  y:bt(A);  z:bt(A);  r:C(y);  s:C(z) |] ==> \
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
    65
\                    h(x,y,z,r,s): C(Br(x,y,z))  \
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    66
\    |] ==> bt_rec(t,c,h) : C(t)";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    67
by (bt_ind_tac "t" prems 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    68
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 515
diff changeset
    69
qed "bt_rec_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    70
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    71
(** Versions for use with definitions **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    72
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    73
val [rew] = goal BT.thy "[| !!t. j(t)==bt_rec(t, c, h) |] ==> j(Lf) = c";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    74
by (rewtac rew);
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    75
by (rtac bt_rec_Lf 1);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    76
qed "def_bt_rec_Lf";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    77
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    78
val [rew] = goal BT.thy
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    79
    "[| !!t. j(t)==bt_rec(t, c, h) |] ==> j(Br(a,l,r)) = h(a,l,r,j(l),j(r))";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    80
by (rewtac rew);
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    81
by (rtac bt_rec_Br 1);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    82
qed "def_bt_rec_Br";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    83
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    84
fun bt_recs def = map standard ([def] RL [def_bt_rec_Lf, def_bt_rec_Br]);
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    85
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    86
(** n_nodes **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    87
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    88
val [n_nodes_Lf,n_nodes_Br] = bt_recs n_nodes_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    89
Addsimps [n_nodes_Lf, n_nodes_Br];
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    90
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    91
val prems = goalw BT.thy [n_nodes_def] 
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    92
    "xs: bt(A) ==> n_nodes(xs) : nat";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    93
by (REPEAT (ares_tac (prems @ [bt_rec_type, nat_0I, nat_succI, add_type]) 1));
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    94
qed "n_nodes_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    95
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    96
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    97
(** n_leaves **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    98
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    99
val [n_leaves_Lf,n_leaves_Br] = bt_recs n_leaves_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
   100
Addsimps [n_leaves_Lf, n_leaves_Br];
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   101
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   102
val prems = goalw BT.thy [n_leaves_def] 
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   103
    "xs: bt(A) ==> n_leaves(xs) : nat";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   104
by (REPEAT (ares_tac (prems @ [bt_rec_type, nat_0I, nat_succI, add_type]) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 515
diff changeset
   105
qed "n_leaves_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   106
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   107
(** bt_reflect **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   108
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   109
val [bt_reflect_Lf, bt_reflect_Br] = bt_recs bt_reflect_def;
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
   110
Addsimps [bt_reflect_Lf, bt_reflect_Br];
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   111
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
   112
Goalw [bt_reflect_def] "xs: bt(A) ==> bt_reflect(xs) : bt(A)";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   113
by (REPEAT (ares_tac (bt.intrs @ [bt_rec_type]) 1));
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   114
qed "bt_reflect_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   115
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   116
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   117
(** BT simplification **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   118
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   119
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   120
val bt_typechecks =
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   121
    bt.intrs @ [bt_rec_type, n_nodes_type, n_leaves_type, bt_reflect_type];
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   122
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
   123
Addsimps bt_typechecks;
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   124
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   125
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   126
(*** theorems about n_leaves ***)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   127
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   128
val prems = goal BT.thy
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   129
    "t: bt(A) ==> n_leaves(bt_reflect(t)) = n_leaves(t)";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   130
by (bt_ind_tac "t" prems 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   131
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_commute, n_leaves_type])));
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   132
qed "n_leaves_reflect";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   133
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   134
val prems = goal BT.thy
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   135
    "t: bt(A) ==> n_leaves(t) = succ(n_nodes(t))";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   136
by (bt_ind_tac "t" prems 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
   137
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_succ_right])));
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   138
qed "n_leaves_nodes";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   139
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   140
(*** theorems about bt_reflect ***)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   141
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   142
val prems = goal BT.thy
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   143
    "t: bt(A) ==> bt_reflect(bt_reflect(t))=t";
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   144
by (bt_ind_tac "t" prems 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
   145
by (ALLGOALS Asm_simp_tac);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
   146
qed "bt_reflect_bt_reflect_ident";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   147
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   148