Theory Test_Embed_Tree
theory Test_Embed_Tree
imports
Lazy_Case.Lazy_Case
"../Preproc/Embed"
"../Preproc/Eval_Instances"
"HOL-Library.Tree"
begin
derive evaluate tree
text ‹Integers are not supported out of the box, so we have to rewrite some code equations.›
definition nat_diff :: "nat ⇒ nat ⇒ nat" where
"nat_diff x y = (if x < y then y - x else x - y)"
lemma nat_diff_abs_int[simp]: "nat_diff x y = nat (abs (int x - int y))"
unfolding nat_diff_def
by auto
lemma [code]:
"wbalanced Leaf = True"
"wbalanced (Node l x r) = (nat_diff (size l) (size r) ≤ 1 ∧ wbalanced l ∧ wbalanced r)"
by auto
text ‹Sets are also unsupported, so we have to rewrite @{const set_tree} to use @{const inorder}.›
lemma [code_unfold]: "(∀x ∈ set_tree l. P x) ⟷ list_all P (inorder l)"
by (induction l) auto
lemma [code]:
"heap Leaf = True"
"heap (Node l m r) = (heap l ∧ heap r ∧ (∀x ∈ set_tree l. m ≤ x) ∧ (∀x ∈ set_tree r. m ≤ x))"
by auto
text ‹@{term "(-)"} on @{typ nat} is not pattern compatible›