fun (in linorder) heap :: "('a*'b) tree → bool"where "heap Leaf = True" | "heap (Node l (m, _) r) = ((∀x ∈ set_tree l ∪ set_tree r. m ≤ x) ∧ heap l ∧ heap r)"
fun ltree :: "'a lheap → bool"where "ltree Leaf = True" | "ltree (Node l (a, n) r) = (min_height l ≥ min_height r ∧ n = min_height r + 1 ∧ ltree l & ltree r)"
definition node :: "'a lheap → 'a → 'a lheap → 'a lheap"where "node l a r = (let mhl = mht l; mhr = mht r in if mhl ≥ mhr then Node l (a,mhr+1) r else Node r (a,mhl+1) l)"
fun get_min :: "'a lheap → 'a"where "get_min(Node l (a, n) r) = a"
text‹For function ‹merge›:› unbundle pattern_aliases
fun merge :: "'a::ord lheap → 'a lheap → 'a lheap"where "merge Leaf t = t" | "merge t Leaf = t" | "merge (Node l1 (a1, n1) r1 =: t1) (Node l2 (a2, n2) r2 =: t2) = (if a1 ≤ a2 then node l1 a1 (merge r1 t2) else node l2 a2 (merge t1 r2))"
text‹Termination of @{const merge}: by sum or lexicographic product of the sizes
the two arguments. Isabelle uses a lexicographic product.›
text‹Last step of functional correctness proof: combine all the above lemmas
show that leftist heaps satisfy the specification of priority queues with merge.›
interpretation lheap: Priority_Queue_Merge where empty = empty and is_empty = "λt. t = Leaf" and insert = insert and del_min = del_min and get_min = get_min and merge = merge and invar = "λt. heap t ∧ ltree t"and mset = mset_tree proof(standard, goal_cases) case1show ?caseby (simp add: empty_def) next case (2 q) show ?caseby (cases q) auto next case3show ?caseby(rule mset_insert) next case4show ?caseby(rule mset_del_min) next case5thus ?caseby(simp add: get_min mset_tree_empty set_tree_mset) next case6thus ?caseby(simp add: empty_def) next case7thus ?caseby(simp add: heap_insert ltree_insert) next case8thus ?caseby(simp add: heap_del_min ltree_del_min) next case9thus ?caseby (simp add: mset_merge) next case10thus ?caseby (simp add: heap_merge ltree_merge) qed
subsection"Complexity"
text‹Auxiliary time functions (which are both 0):›
time_fun mht
time_fun node
lemma T_mht_0[simp]: "T_mht t = 0" by(cases t)auto
lemma T_merge_min_height: "ltree l ==> ltree r ==> T_merge l r ≤ min_height l + min_height r + 1" proof(induction l r rule: merge.induct) case3thus ?caseby(auto) qed simp_all
corollary T_merge_log: assumes"ltree l""ltree r" shows"T_merge l r ≤ log 2 (size1 l) + log 2 (size1 r) + 1" using le_log2_of_power[OF min_height_size1[of l]]
le_log2_of_power[OF min_height_size1[of r]] T_merge_min_height[of l r] assms by linarith
corollary T_insert_log: "ltree t ==> T_insert x t ≤ log 2 (size1 t) + 2" using T_merge_log[of "Node Leaf (x, 1) Leaf" t] by(simp split: tree.split)
corollary T_del_min_log: assumes"ltree t" shows"T_del_min t ≤ 2 * log 2 (size1 t) + 1" proof(cases t rule: tree2_cases) case Leaf thus ?thesis using assms by simp next case [simp]: (Node l _ _ r) show ?thesis using‹ltree t› T_merge_log[of l r]
log_mono[of 2"size1 l""size1 t"] log_mono[of 2"size1 r""size1 t"] by (simp del: T_merge.simps) qed
end
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.11Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-06-29)
¤
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.