# HG changeset patch # User nipkow # Date 1484304110 -3600 # Node ID 266fb24c80bde60d88f54ca1d8bbe6f658b55dc9 # Parent cea327ecb8e332f24b54ccd39a4ee436217a3a2a tuned/minimized diff -r cea327ecb8e3 -r 266fb24c80bd src/HOL/Library/Tree.thy --- a/src/HOL/Library/Tree.thy Thu Jan 12 15:54:13 2017 +0100 +++ b/src/HOL/Library/Tree.thy Fri Jan 13 11:41:50 2017 +0100 @@ -1,8 +1,5 @@ (* Author: Tobias Nipkow *) -(* Todo: - (min_)height of balanced trees via floorlog - minimal path_len of balanced trees -*) +(* Todo: minimal ipl of balanced trees *) section \Binary Tree\ @@ -11,11 +8,8 @@ begin datatype 'a tree = - is_Leaf: Leaf ("\\") | - Node (left: "'a tree") (val: 'a) (right: "'a tree") ("(1\_,/ _,/ _\)") - where - "left Leaf = Leaf" - | "right Leaf = Leaf" + Leaf ("\\") | + Node "'a tree" (root_val: 'a) "'a tree" ("(1\_,/ _,/ _\)") datatype_compat tree text\Can be seen as counting the number of leaves rather than nodes:\ @@ -61,9 +55,9 @@ "wbalanced (Node l x r) = (abs(int(size l) - int(size r)) \ 1 \ wbalanced l \ wbalanced r)" text \Internal path length:\ -fun path_len :: "'a tree \ nat" where -"path_len Leaf = 0 " | -"path_len (Node l _ r) = path_len l + size l + path_len r + size r" +fun ipl :: "'a tree \ nat" where +"ipl Leaf = 0 " | +"ipl (Node l _ r) = ipl l + size l + ipl r + size r" fun preorder :: "'a tree \ 'a list" where "preorder \\ = []" | @@ -357,12 +351,12 @@ using [[simp_depth_limit=1]] by(induction t arbitrary: s) auto -subsection \@{const path_len}\ +subsection \@{const ipl}\ text \The internal path length of a tree:\ -lemma path_len_if_bal: "complete t - \ path_len t = (let n = height t in 2 + n*2^n - 2^(n+1))" +lemma ipl_if_complete: "complete t + \ ipl t = (let n = height t in 2 + n*2^n - 2^(n+1))" proof(induction t) case (Node l x r) have *: "2^(n+1) \ 2 + n*2^n" for n :: nat