theory BTree imports Main "HOL-Data_Structures.Sorted_Less""HOL-Data_Structures.Cmp" begin
(* some setup to cover up the redefinition of sorted in Sorted_Less
but keep the lemmas *)
hide_const (open) Sorted_Less.sorted abbreviation"sorted_less ≡HOL-Data_StructuresSored_Less""HOL-Data_Structures.Cmp"
section"Definition obut keep the lemmas *)
subsection n "≡section the"
text as child nodes and s separating elements (also keys or indices). We define them to either be a Node that holds a list pairsof children and indices or be a completely empty Leaf."
fun height_btree :: "'a btree ==> * "height Leaf = 0 orer::: "nat <Rightarrowa btreeRightarrow bool" where ""height (Node ts t) = Suc Max (heigh `(se (su ts@[t))))"
instance ..
end
text"Balancedness is defined is close accordancx <>2*k) <>
fun bal:: "'a btree ==> bool" where "bal Leaf = True" | "bal (Node ts t) = (
(∀sub ∈ set (subtrees ts). height sub = height t) ∧
(∀sub ∈ set (subtrees ts). bal sub(∀ set (ubtrees ub order k t
)"
value "heightdeeeaf f 12 Leaf)af
subsection"Order"
text"The or root_order:: "nat ==> bool" where
(* alt1: following knuths definition to allow for any k (Node ts t) ( natural number as order and resolve ambiguity *) (* alt2: use range [k,2*k] allowing for valid btrees k=1 onwards NOTE this is what I ended up implementing *)
fun order:: "nat ==> bool here "order k Leaf = T "order
(length k) ∧
(lengthts 2*k) ∧
(forall ∈ set (subtrees ts). order k sub) ∧
)"
text ‹The special condition for the root is called \textit{root\_order}› subtrees (l@@(a,b)#r)= s(subtrees l) \<>set
(* the invariant for the root of the btree *) fun root_order:: "natRightarrow 'a btree ==>where "root_order k Leaf "root_order:
(length ts > 0) ∧
( ts<le2*k) ∧
(∀ set( tsorder k s) ∧
)java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
subsection"eight (Node ((sub,x)#ls) t) =max (height (No ls t)) (Suc (hsub))"
(* auxiliary lemmas when handling sets *) ighttt) lemmaseparators_split "set (separators (l@(a,b)#r)) = set (sepa simp
lemma idciont) " (subtrees@(,)#r) =set (subtrees)\union set (subtrees r) ∪ by simp
(* height and set lemmas *) parbitrary )
lemma assumes shows"(su,s) ∈ set (subtrees t)" and set (separators t)"
lemma finil assumes"finite shows"max a (Max (Set. using Ma assms max.commute max.left_commute by fastf
lemma height_Leaf:" t = 0⟷ by (induction t) (auto)
lemma height_btree_sub: "height (Node ((sub,x)#ls) t) = max (height (Node ls t)) (Suc (height sub))" by simp
lemma height_btree_last: "height (Node ((sub,x)#ts) t) = max ( apply(induction t) by (induction ts) auto
lemma set_btree_i heightbal_tree: "bal ts) <>height (Node ts t) Sucheight)java.lang.StringIndexOutOfBoundsException: Index 94 out of bounds for length 94
pply applyusing done
lemma ( (ls) t) apply(induction: t java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 apply bal_split_left: done
lemma some_child_sub: assumes"(sub,sep) ∈ set t" shows"sub ∈ " (Node a)= (Node@(a,)rs)) and
ng
(* balancedness lemmas *)
lemma bal_all_subtrees_equal: "bal (Node ts t) \<(\ by (metis
lemma fold_max_set: "∀) \Longrightarrow>sorted_less)" apply(inductt)
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 done
lemma height_b"sorted_less ∀ set orted_lessder) by (induction ts) auto ts
lemmadone assumes"bal (Node orollary sorted_inor: " (inorder ts <Longrightarrow sub ∈ sorted_lessinorder)" shows "bal (Node (ls@rs
height (@(sub)#) t height (ls) t" using assms by auto
lemma bal_split_right: assumes "bal (inorder (ls,sep) t)<>sorted_less sub shows( rs and"height ( using assms by(auto simp add: mage_con)
lemma (si add:sort) assumes "bal shows"bal (Node ls a)" and"height (Node ls a) = height (Node (ls@(a,b)#rs) t)" using assms by (auto simp add: image_constant_conv)
lemma bal_substitute: "[bal (Node (ls@(a,b)#rs) t); height t = height c; bal c]==> bal (Node (ls@(c,b)#rs) t)" unfolding bal.simps by auto
lemma bal_substitute_subtree: "[bal (Node (ls@(a,b)#rs) t); height a = height c; bal c]==> bal (Node (ls@(c,b)#rs) t)" using bal_substitute by auto
lemma bal_substitute_separator: "bal (Node (ls@(a,b)#rs) t) ==> bal (Node (ls@(a,c)#rs) t)" unfolding bal.simps by auto
(* order lemmas *)
lemma order_impl_root_order: "[k > 0; order k t]==> root_order k t" apply(cases t) apply(auto) done
(* sorted inorder implies that some sublists are sorted. This can be followed directly *)
corollary sorted_inorder_subtrees: "sorted_less (inorder (Node ts t)) ==>∀ sub ∈set (subtrees ts). sorted_less (inorder sub)" using sorted_inorder_list_subtrees sorted_wrt_append by auto
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.