src/ZF/ex/BT_Fn.ML
author lcp
Tue Aug 16 18:58:42 1994 +0200 (1994-08-16)
changeset 532 851df239ac8b
parent 29 4ec9b266ccd1
permissions -rw-r--r--
ZF/Makefile,ROOT.ML, ZF/ex/Integ.thy: updated for EquivClass
clasohm@0
     1
(*  Title: 	ZF/bt.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
clasohm@0
     6
For bt.thy.  Binary trees
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
open BT_Fn;
clasohm@0
    10
clasohm@0
    11
clasohm@0
    12
clasohm@0
    13
(** bt_rec -- by Vset recursion **)
clasohm@0
    14
lcp@29
    15
goalw BT.thy BT.con_defs "rank(l) < rank(Br(a,l,r))";
lcp@7
    16
by (simp_tac rank_ss 1);
clasohm@0
    17
val rank_Br1 = result();
clasohm@0
    18
lcp@29
    19
goalw BT.thy BT.con_defs "rank(r) < rank(Br(a,l,r))";
lcp@7
    20
by (simp_tac rank_ss 1);
clasohm@0
    21
val rank_Br2 = result();
clasohm@0
    22
clasohm@0
    23
goal BT_Fn.thy "bt_rec(Lf,c,h) = c";
clasohm@0
    24
by (rtac (bt_rec_def RS def_Vrec RS trans) 1);
lcp@7
    25
by (simp_tac (ZF_ss addsimps BT.case_eqns) 1);
clasohm@0
    26
val bt_rec_Lf = result();
clasohm@0
    27
clasohm@0
    28
goal BT_Fn.thy
clasohm@0
    29
    "bt_rec(Br(a,l,r), c, h) = h(a, l, r, bt_rec(l,c,h), bt_rec(r,c,h))";
clasohm@0
    30
by (rtac (bt_rec_def RS def_Vrec RS trans) 1);
lcp@29
    31
by (simp_tac (rank_ss addsimps (BT.case_eqns @ [rank_Br1, rank_Br2])) 1);
clasohm@0
    32
val bt_rec_Br = result();
clasohm@0
    33
clasohm@0
    34
(*Type checking -- proved by induction, as usual*)
clasohm@0
    35
val prems = goal BT_Fn.thy
clasohm@0
    36
    "[| t: bt(A);    \
clasohm@0
    37
\       c: C(Lf);       \
clasohm@0
    38
\       !!x y z r s. [| x:A;  y:bt(A);  z:bt(A);  r:C(y);  s:C(z) |] ==> \
clasohm@0
    39
\		     h(x,y,z,r,s): C(Br(x,y,z))  \
clasohm@0
    40
\    |] ==> bt_rec(t,c,h) : C(t)";
clasohm@0
    41
by (bt_ind_tac "t" prems 1);
lcp@7
    42
by (ALLGOALS (asm_simp_tac (ZF_ss addsimps
clasohm@0
    43
			    (prems@[bt_rec_Lf,bt_rec_Br]))));
clasohm@0
    44
val bt_rec_type = result();
clasohm@0
    45
clasohm@0
    46
(** Versions for use with definitions **)
clasohm@0
    47
clasohm@0
    48
val [rew] = goal BT_Fn.thy "[| !!t. j(t)==bt_rec(t, c, h) |] ==> j(Lf) = c";
clasohm@0
    49
by (rewtac rew);
clasohm@0
    50
by (rtac bt_rec_Lf 1);
clasohm@0
    51
val def_bt_rec_Lf = result();
clasohm@0
    52
clasohm@0
    53
val [rew] = goal BT_Fn.thy
clasohm@0
    54
    "[| !!t. j(t)==bt_rec(t, c, h) |] ==> j(Br(a,l,r)) = h(a,l,r,j(l),j(r))";
clasohm@0
    55
by (rewtac rew);
clasohm@0
    56
by (rtac bt_rec_Br 1);
clasohm@0
    57
val def_bt_rec_Br = result();
clasohm@0
    58
clasohm@0
    59
fun bt_recs def = map standard ([def] RL [def_bt_rec_Lf, def_bt_rec_Br]);
clasohm@0
    60
clasohm@0
    61
(** n_nodes **)
clasohm@0
    62
clasohm@0
    63
val [n_nodes_Lf,n_nodes_Br] = bt_recs n_nodes_def;
clasohm@0
    64
clasohm@0
    65
val prems = goalw BT_Fn.thy [n_nodes_def] 
clasohm@0
    66
    "xs: bt(A) ==> n_nodes(xs) : nat";
clasohm@0
    67
by (REPEAT (ares_tac (prems @ [bt_rec_type, nat_0I, nat_succI, add_type]) 1));
clasohm@0
    68
val n_nodes_type = result();
clasohm@0
    69
clasohm@0
    70
clasohm@0
    71
(** n_leaves **)
clasohm@0
    72
clasohm@0
    73
val [n_leaves_Lf,n_leaves_Br] = bt_recs n_leaves_def;
clasohm@0
    74
clasohm@0
    75
val prems = goalw BT_Fn.thy [n_leaves_def] 
clasohm@0
    76
    "xs: bt(A) ==> n_leaves(xs) : nat";
clasohm@0
    77
by (REPEAT (ares_tac (prems @ [bt_rec_type, nat_0I, nat_succI, add_type]) 1));
clasohm@0
    78
val n_leaves_type = result();
clasohm@0
    79
clasohm@0
    80
(** bt_reflect **)
clasohm@0
    81
clasohm@0
    82
val [bt_reflect_Lf, bt_reflect_Br] = bt_recs bt_reflect_def;
clasohm@0
    83
clasohm@0
    84
val prems = goalw BT_Fn.thy [bt_reflect_def] 
clasohm@0
    85
    "xs: bt(A) ==> bt_reflect(xs) : bt(A)";
clasohm@0
    86
by (REPEAT (ares_tac (prems @ [bt_rec_type, LfI, BrI]) 1));
clasohm@0
    87
val bt_reflect_type = result();
clasohm@0
    88
clasohm@0
    89
clasohm@0
    90
(** BT_Fn simplification **)
clasohm@0
    91
clasohm@0
    92
clasohm@0
    93
val bt_typechecks =
clasohm@0
    94
      [LfI, BrI, bt_rec_type, n_nodes_type, n_leaves_type, bt_reflect_type];
clasohm@0
    95
clasohm@0
    96
val bt_ss = arith_ss 
lcp@7
    97
    addsimps BT.case_eqns
lcp@7
    98
    addsimps bt_typechecks
lcp@7
    99
    addsimps [bt_rec_Lf, bt_rec_Br, 
clasohm@0
   100
	     n_nodes_Lf, n_nodes_Br,
clasohm@0
   101
	     n_leaves_Lf, n_leaves_Br,
clasohm@0
   102
	     bt_reflect_Lf, bt_reflect_Br];
clasohm@0
   103
clasohm@0
   104
clasohm@0
   105
(*** theorems about n_leaves ***)
clasohm@0
   106
clasohm@0
   107
val prems = goal BT_Fn.thy
clasohm@0
   108
    "t: bt(A) ==> n_leaves(bt_reflect(t)) = n_leaves(t)";
clasohm@0
   109
by (bt_ind_tac "t" prems 1);
lcp@7
   110
by (ALLGOALS (asm_simp_tac bt_ss));
clasohm@0
   111
by (REPEAT (ares_tac [add_commute, n_leaves_type] 1));
clasohm@0
   112
val n_leaves_reflect = result();
clasohm@0
   113
clasohm@0
   114
val prems = goal BT_Fn.thy
clasohm@0
   115
    "t: bt(A) ==> n_leaves(t) = succ(n_nodes(t))";
clasohm@0
   116
by (bt_ind_tac "t" prems 1);
lcp@7
   117
by (ALLGOALS (asm_simp_tac (bt_ss addsimps [add_succ_right])));
clasohm@0
   118
val n_leaves_nodes = result();
clasohm@0
   119
clasohm@0
   120
(*** theorems about bt_reflect ***)
clasohm@0
   121
clasohm@0
   122
val prems = goal BT_Fn.thy
clasohm@0
   123
    "t: bt(A) ==> bt_reflect(bt_reflect(t))=t";
clasohm@0
   124
by (bt_ind_tac "t" prems 1);
lcp@7
   125
by (ALLGOALS (asm_simp_tac bt_ss));
clasohm@0
   126
val bt_reflect_bt_reflect_ident = result();
clasohm@0
   127
clasohm@0
   128