src/HOL/Library/Tree.thy
changeset 64540 f1f4ba6d02c9
parent 64533 172f3a047f4a
child 64771 23c56f483775
equal deleted inserted replaced
64539:a868c83aa66e 64540:f1f4ba6d02c9
   170 
   170 
   171 lemma height_subtrees: "s \<in> subtrees t \<Longrightarrow> height s \<le> height t"
   171 lemma height_subtrees: "s \<in> subtrees t \<Longrightarrow> height s \<le> height t"
   172 by (induction t) auto
   172 by (induction t) auto
   173 
   173 
   174 
   174 
   175 lemma min_hight_le_height: "min_height t \<le> height t"
   175 lemma min_height_le_height: "min_height t \<le> height t"
   176 by(induction t) auto
   176 by(induction t) auto
   177 
   177 
   178 lemma min_height_map_tree[simp]: "min_height (map_tree f t) = min_height t"
   178 lemma min_height_map_tree[simp]: "min_height (map_tree f t) = min_height t"
   179 by (induction t) auto
   179 by (induction t) auto
   180 
   180 
   192 
   192 
   193 lemma complete_iff_height: "complete t \<longleftrightarrow> (min_height t = height t)"
   193 lemma complete_iff_height: "complete t \<longleftrightarrow> (min_height t = height t)"
   194 apply(induction t)
   194 apply(induction t)
   195  apply simp
   195  apply simp
   196 apply (simp add: min_def max_def)
   196 apply (simp add: min_def max_def)
   197 by (metis le_antisym le_trans min_hight_le_height)
   197 by (metis le_antisym le_trans min_height_le_height)
   198 
   198 
   199 lemma size1_if_complete: "complete t \<Longrightarrow> size1 t = 2 ^ height t"
   199 lemma size1_if_complete: "complete t \<Longrightarrow> size1 t = 2 ^ height t"
   200 by (induction t) auto
   200 by (induction t) auto
   201 
   201 
   202 lemma size_if_complete: "complete t \<Longrightarrow> size t = 2 ^ height t - 1"
   202 lemma size_if_complete: "complete t \<Longrightarrow> size t = 2 ^ height t - 1"
   343     finally show ?thesis
   343     finally show ?thesis
   344       using power_eq_0_iff[of "2::nat" "height t'"] by linarith
   344       using power_eq_0_iff[of "2::nat" "height t'"] by linarith
   345   qed
   345   qed
   346   hence *: "min_height t < height t'" by simp
   346   hence *: "min_height t < height t'" by simp
   347   have "min_height t + 1 = height t"
   347   have "min_height t + 1 = height t"
   348     using min_hight_le_height[of t] assms(1) False
   348     using min_height_le_height[of t] assms(1) False
   349     by (simp add: complete_iff_height balanced_def)
   349     by (simp add: complete_iff_height balanced_def)
   350   with * show ?thesis by arith
   350   with * show ?thesis by arith
   351 qed
   351 qed
   352 
   352 
   353 
   353