diff -r 9dabb405a3ba -r 22fe10b4c0c6 src/HOL/Data_Structures/Braun_Tree.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Data_Structures/Braun_Tree.thy Sun Oct 07 16:28:38 2018 +0200 @@ -0,0 +1,50 @@ +(* Author: Tobias Nipkow *) + +section \Braun Trees\ + +theory Braun_Tree +imports "HOL-Library.Tree_Real" +begin + +text \Braun Trees were studied by Braun and Rem~\cite{BraunRem} +and later Hoogerwoord~\cite{Hoogerwoord} who gave them their name.\ + +fun braun :: "'a tree \ bool" where +"braun Leaf = True" | +"braun (Node l x r) = (size r \ size l \ size l \ size r + 1 \ braun l \ braun r)" + +text \The shape of a Braun-tree is uniquely determined by its size:\ + +lemma braun_unique: "\ braun (t1::unit tree); braun t2; size t1 = size t2 \ \ t1 = t2" +proof (induction t1 arbitrary: t2) + case Leaf thus ?case by simp +next + case (Node l1 _ r1) + from Node.prems(3) have "t2 \ Leaf" by auto + then obtain l2 x2 r2 where [simp]: "t2 = Node l2 x2 r2" by (meson neq_Leaf_iff) + with Node.prems have "size l1 = size l2 \ size r1 = size r2" by simp + thus ?case using Node.prems(1,2) Node.IH by auto +qed + +text \Braun trees are balanced:\ + +lemma balanced_if_braun: "braun t \ balanced t" +proof(induction t) + case Leaf show ?case by (simp add: balanced_def) +next + case (Node l x r) + have "size l = size r \ size l = size r + 1" (is "?A \ ?B") + using Node.prems by auto + thus ?case + proof + assume "?A" + thus ?thesis using Node + apply(simp add: balanced_def min_def max_def) + by (metis Node.IH balanced_optimal le_antisym le_refl) + next + assume "?B" + thus ?thesis using Node by(intro balanced_Node_if_wbal1) auto + qed +qed + +end \ No newline at end of file