src/ZF/ex/BT.ML
changeset 6065 3b4a29166f26
parent 6046 2c8a8be36c94
child 6112 5e4871c5136b
equal deleted inserted replaced
6064:0786b5afd8ee 6065:3b4a29166f26
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1994  University of Cambridge
     4     Copyright   1994  University of Cambridge
     5 
     5 
     6 Datatype definition of binary trees
     6 Datatype definition of binary trees
     7 *)
     7 *)
     8 
       
     9 (*Perform induction on l, then prove the major premise using prems. *)
       
    10 fun bt_ind_tac a prems i = 
       
    11     EVERY [res_inst_tac [("x",a)] bt.induct i,
       
    12            rename_last_tac a ["1","2"] (i+2),
       
    13            ares_tac prems i];
       
    14 
       
    15 
     8 
    16 Addsimps bt.intrs;
     9 Addsimps bt.intrs;
    17 
    10 
    18 (**  Lemmas to justify using "bt" in other recursive type definitions **)
    11 (**  Lemmas to justify using "bt" in other recursive type definitions **)
    19 
    12 
    32 
    25 
    33 bind_thm ("bt_subset_univ", [bt_mono, bt_univ] MRS subset_trans);
    26 bind_thm ("bt_subset_univ", [bt_mono, bt_univ] MRS subset_trans);
    34 
    27 
    35 
    28 
    36 (*Type checking -- proved by induction, as usual*)
    29 (*Type checking -- proved by induction, as usual*)
    37 val prems = goal BT.thy
    30 val major::prems = goal BT.thy
    38     "[| t: bt(A);    \
    31     "[| t: bt(A);    \
    39 \       c: C(Lf);       \
    32 \       c: C(Lf);       \
    40 \       !!x y z r s. [| x:A;  y:bt(A);  z:bt(A);  r:C(y);  s:C(z) |] ==> \
    33 \       !!x y z r s. [| x:A;  y:bt(A);  z:bt(A);  r:C(y);  s:C(z) |] ==> \
    41 \                    h(x,y,z,r,s): C(Br(x,y,z))  \
    34 \                    h(x,y,z,r,s): C(Br(x,y,z))  \
    42 \    |] ==> bt_rec(c,h,t) : C(t)";
    35 \    |] ==> bt_rec(c,h,t) : C(t)";
    43 by (bt_ind_tac "t" prems 1);
    36     (*instead of induct_tac "t", since t: bt(A) isn't an assumption*)
       
    37 by (rtac (major RS bt.induct) 1);
    44 by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
    38 by (ALLGOALS (asm_simp_tac (simpset() addsimps prems)));
    45 qed "bt_rec_type";
    39 qed "bt_rec_type";
    46 
    40 
    47 (** n_nodes **)
    41 (** n_nodes **)
    48 
    42 
    49 Goal "t: bt(A) ==> n_nodes(t) : nat";
    43 Goal "t: bt(A) ==> n_nodes(t) : nat";
    50 by (bt_ind_tac "t" [] 1);
    44 by (induct_tac "t" 1);
    51 by Auto_tac;
    45 by Auto_tac;
    52 qed "n_nodes_type";
    46 qed "n_nodes_type";
    53 
    47 
    54 
    48 
    55 (** n_leaves **)
    49 (** n_leaves **)
    56 
    50 
    57 Goal "t: bt(A) ==> n_leaves(t) : nat";
    51 Goal "t: bt(A) ==> n_leaves(t) : nat";
    58 by (bt_ind_tac "t" [] 1);
    52 by (induct_tac "t" 1);
    59 by Auto_tac;
    53 by Auto_tac;
    60 qed "n_leaves_type";
    54 qed "n_leaves_type";
    61 
    55 
    62 (** bt_reflect **)
    56 (** bt_reflect **)
    63 
    57 
    64 Goal "t: bt(A) ==> bt_reflect(t) : bt(A)";
    58 Goal "t: bt(A) ==> bt_reflect(t) : bt(A)";
    65 by (bt_ind_tac "t" [] 1);
    59 by (induct_tac "t" 1);
    66 by Auto_tac;
    60 by Auto_tac;
    67 by (REPEAT (ares_tac (bt.intrs @ [bt_rec_type]) 1));
    61 by (REPEAT (ares_tac (bt.intrs @ [bt_rec_type]) 1));
    68 qed "bt_reflect_type";
    62 qed "bt_reflect_type";
    69 
    63 
    70 
    64 
    74 Addsimps [bt_rec_type, n_nodes_type, n_leaves_type, bt_reflect_type];
    68 Addsimps [bt_rec_type, n_nodes_type, n_leaves_type, bt_reflect_type];
    75 
    69 
    76 
    70 
    77 (*** theorems about n_leaves ***)
    71 (*** theorems about n_leaves ***)
    78 
    72 
    79 val prems = goal BT.thy
    73 Goal "t: bt(A) ==> n_leaves(bt_reflect(t)) = n_leaves(t)";
    80     "t: bt(A) ==> n_leaves(bt_reflect(t)) = n_leaves(t)";
    74 by (induct_tac "t" 1);
    81 by (bt_ind_tac "t" prems 1);
       
    82 by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_commute, n_leaves_type])));
    75 by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_commute, n_leaves_type])));
    83 qed "n_leaves_reflect";
    76 qed "n_leaves_reflect";
    84 
    77 
    85 val prems = goal BT.thy
    78 Goal "t: bt(A) ==> n_leaves(t) = succ(n_nodes(t))";
    86     "t: bt(A) ==> n_leaves(t) = succ(n_nodes(t))";
    79 by (induct_tac "t" 1);
    87 by (bt_ind_tac "t" prems 1);
       
    88 by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_succ_right])));
    80 by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_succ_right])));
    89 qed "n_leaves_nodes";
    81 qed "n_leaves_nodes";
    90 
    82 
    91 (*** theorems about bt_reflect ***)
    83 (*** theorems about bt_reflect ***)
    92 
    84 
    93 val prems = goal BT.thy
    85 Goal "t: bt(A) ==> bt_reflect(bt_reflect(t))=t";
    94     "t: bt(A) ==> bt_reflect(bt_reflect(t))=t";
    86 by (induct_tac "t" 1);
    95 by (bt_ind_tac "t" prems 1);
       
    96 by (ALLGOALS Asm_simp_tac);
    87 by (ALLGOALS Asm_simp_tac);
    97 qed "bt_reflect_bt_reflect_ident";
    88 qed "bt_reflect_bt_reflect_ident";
    98 
    89 
    99 
    90