src/HOL/Metis_Examples/Binary_Tree.thy
changeset 63167 0909deb8059b
parent 58889 5b7a9633cfa8
equal deleted inserted replaced
63166:143f58bb34f9 63167:0909deb8059b
     3     Author:     Jasmin Blanchette, TU Muenchen
     3     Author:     Jasmin Blanchette, TU Muenchen
     4 
     4 
     5 Metis example featuring binary trees.
     5 Metis example featuring binary trees.
     6 *)
     6 *)
     7 
     7 
     8 section {* Metis Example Featuring Binary Trees *}
     8 section \<open>Metis Example Featuring Binary Trees\<close>
     9 
     9 
    10 theory Binary_Tree
    10 theory Binary_Tree
    11 imports Main
    11 imports Main
    12 begin
    12 begin
    13 
    13 
    51 
    51 
    52 primrec append :: "'a bt => 'a bt => 'a bt" where
    52 primrec append :: "'a bt => 'a bt => 'a bt" where
    53   "append Lf t = t"
    53   "append Lf t = t"
    54 | "append (Br a t1 t2) t = Br a (append t1 t) (append t2 t)"
    54 | "append (Br a t1 t2) t = Br a (append t1 t) (append t2 t)"
    55 
    55 
    56 text {* \medskip BT simplification *}
    56 text \<open>\medskip BT simplification\<close>
    57 
    57 
    58 lemma n_leaves_reflect: "n_leaves (reflect t) = n_leaves t"
    58 lemma n_leaves_reflect: "n_leaves (reflect t) = n_leaves t"
    59 proof (induct t)
    59 proof (induct t)
    60   case Lf thus ?case
    60   case Lf thus ?case
    61   proof -
    61   proof -
    80 lemma depth_reflect: "depth (reflect t) = depth t"
    80 lemma depth_reflect: "depth (reflect t) = depth t"
    81 apply (induct t)
    81 apply (induct t)
    82  apply (metis depth.simps(1) reflect.simps(1))
    82  apply (metis depth.simps(1) reflect.simps(1))
    83 by (metis depth.simps(2) max.commute reflect.simps(2))
    83 by (metis depth.simps(2) max.commute reflect.simps(2))
    84 
    84 
    85 text {*
    85 text \<open>
    86 The famous relationship between the numbers of leaves and nodes.
    86 The famous relationship between the numbers of leaves and nodes.
    87 *}
    87 \<close>
    88 
    88 
    89 lemma n_leaves_nodes: "n_leaves t = Suc (n_nodes t)"
    89 lemma n_leaves_nodes: "n_leaves t = Suc (n_nodes t)"
    90 apply (induct t)
    90 apply (induct t)
    91  apply (metis n_leaves.simps(1) n_nodes.simps(1))
    91  apply (metis n_leaves.simps(1) n_nodes.simps(1))
    92 by auto
    92 by auto
   195 apply (induct t)
   195 apply (induct t)
   196  apply (metis Nil_is_rev_conv postorder.simps(1) preorder.simps(1)
   196  apply (metis Nil_is_rev_conv postorder.simps(1) preorder.simps(1)
   197               reflect.simps(1))
   197               reflect.simps(1))
   198 by (metis preorder_reflect reflect_reflect_ident rev_swap)
   198 by (metis preorder_reflect reflect_reflect_ident rev_swap)
   199 
   199 
   200 text {*
   200 text \<open>
   201 Analogues of the standard properties of the append function for lists.
   201 Analogues of the standard properties of the append function for lists.
   202 *}
   202 \<close>
   203 
   203 
   204 lemma append_assoc [simp]: "append (append t1 t2) t3 = append t1 (append t2 t3)"
   204 lemma append_assoc [simp]: "append (append t1 t2) t3 = append t1 (append t2 t3)"
   205 apply (induct t1)
   205 apply (induct t1)
   206  apply (metis append.simps(1))
   206  apply (metis append.simps(1))
   207 by (metis append.simps(2))
   207 by (metis append.simps(2))