src/ZF/ex/BT.ML
author paulson
Wed, 13 Jan 1999 11:57:09 +0100
changeset 6112 5e4871c5136b
parent 6065 3b4a29166f26
child 6141 a6922171b396
permissions -rw-r--r--
datatype package improvements
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
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
     9
Addsimps bt.intrs;
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    10
6112
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    11
Goal "l : bt(A) ==> ALL x r. Br(x,l,r) ~= l";
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    12
by (induct_tac "l" 1);
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    13
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps bt.free_iffs)));
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    14
qed_spec_mp "Br_neq_left";
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    15
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    16
(*Proving a freeness theorem*)
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    17
val Br_iff = bt.mk_free "Br(a,l,r) = Br(a',l',r') <-> a=a' & l=l' & r=r'";
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    18
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    19
(*An elimination rule, for type-checking*)
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    20
val BrE = bt.mk_cases bt.con_defs "Br(a,l,r) : bt(A)";
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    21
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
(**  Lemmas to justify using "bt" in other recursive type definitions **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
5137
60205b0de9b9 Huge tidy-up: removal of leading \!\!
paulson
parents: 5068
diff changeset
    24
Goalw bt.defs "A<=B ==> bt(A) <= bt(B)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
by (rtac lfp_mono 1);
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    26
by (REPEAT (rtac bt.bnd_mono 1));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    28
qed "bt_mono";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
5068
fb28eaa07e01 isatool fixgoal;
wenzelm
parents: 4091
diff changeset
    30
Goalw (bt.defs@bt.con_defs) "bt(univ(A)) <= univ(A)";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
by (rtac lfp_lowerbound 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
by (rtac (A_subset_univ RS univ_mono) 2);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    33
by (fast_tac (claset() addSIs [zero_in_univ, Inl_in_univ, Inr_in_univ,
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1170
diff changeset
    34
                            Pair_in_univ]) 1);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    35
qed "bt_univ";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    37
bind_thm ("bt_subset_univ", [bt_mono, bt_univ] MRS subset_trans);
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    38
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    39
6112
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    40
(*Type checking for recursor -- example only; not really needed*)
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    41
val major::prems = goal BT.thy
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    42
    "[| t: bt(A);    \
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    43
\       c: C(Lf);       \
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    44
\       !!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
    45
\                    h(x,y,z,r,s): C(Br(x,y,z))  \
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    46
\    |] ==> bt_rec(c,h,t) : C(t)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    47
    (*instead of induct_tac "t", since t: bt(A) isn't an assumption*)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    48
by (rtac (major RS bt.induct) 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    49
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 515
diff changeset
    50
qed "bt_rec_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    51
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    52
(** n_nodes **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    53
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    54
Goal "t: bt(A) ==> n_nodes(t) : nat";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    55
by (induct_tac "t" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    56
by Auto_tac;
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    57
qed "n_nodes_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    58
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    59
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    60
(** n_leaves **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    61
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    62
Goal "t: bt(A) ==> n_leaves(t) : nat";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    63
by (induct_tac "t" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    64
by Auto_tac;
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 515
diff changeset
    65
qed "n_leaves_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    66
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    67
(** bt_reflect **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    68
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    69
Goal "t: bt(A) ==> bt_reflect(t) : bt(A)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    70
by (induct_tac "t" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5530
diff changeset
    71
by Auto_tac;
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    72
qed "bt_reflect_type";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    73
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    74
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    75
(** BT simplification **)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    76
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    77
6112
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    78
Addsimps [n_nodes_type, n_leaves_type, bt_reflect_type];
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    79
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    80
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    81
(*** theorems about n_leaves ***)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    82
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    83
Goal "t: bt(A) ==> n_leaves(bt_reflect(t)) = n_leaves(t)";
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    84
by (induct_tac "t" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    85
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
    86
qed "n_leaves_reflect";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    87
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    88
Goal "t: bt(A) ==> n_leaves(t) = succ(n_nodes(t))";
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    89
by (induct_tac "t" 1);
4091
771b1f6422a8 isatool fixclasimp;
wenzelm
parents: 2469
diff changeset
    90
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
    91
qed "n_leaves_nodes";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    92
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    93
(*** theorems about bt_reflect ***)
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    94
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    95
Goal "t: bt(A) ==> bt_reflect(bt_reflect(t))=t";
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    96
by (induct_tac "t" 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 1461
diff changeset
    97
by (ALLGOALS Asm_simp_tac);
782
200a16083201 added bind_thm for theorems defined by "standard ..."
clasohm
parents: 760
diff changeset
    98
qed "bt_reflect_bt_reflect_ident";
515
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
    99
abcc438e7c27 installation of new inductive/datatype sections
lcp
parents: 477
diff changeset
   100