src/HOL/Library/Tree.thy
changeset 60505 9e6584184315
parent 59928 b9b7f913a19a
child 60506 83231b558ce4
equal deleted inserted replaced
60498:c8141ac6f03f 60505:9e6584184315
    22 lemma size1_simps[simp]:
    22 lemma size1_simps[simp]:
    23   "size1 \<langle>\<rangle> = 1"
    23   "size1 \<langle>\<rangle> = 1"
    24   "size1 \<langle>l, x, r\<rangle> = size1 l + size1 r"
    24   "size1 \<langle>l, x, r\<rangle> = size1 l + size1 r"
    25 by (simp_all add: size1_def)
    25 by (simp_all add: size1_def)
    26 
    26 
       
    27 lemma size_0_iff_Leaf[simp]: "size t = 0 \<longleftrightarrow> t = Leaf"
       
    28 by(cases t) auto
       
    29 
    27 lemma neq_Leaf_iff: "(t \<noteq> \<langle>\<rangle>) = (\<exists>l a r. t = \<langle>l, a, r\<rangle>)"
    30 lemma neq_Leaf_iff: "(t \<noteq> \<langle>\<rangle>) = (\<exists>l a r. t = \<langle>l, a, r\<rangle>)"
    28 by (cases t) auto
    31 by (cases t) auto
    29 
    32 
    30 lemma finite_set_tree[simp]: "finite(set_tree t)"
    33 lemma finite_set_tree[simp]: "finite(set_tree t)"
    31 by(induction t) auto
    34 by(induction t) auto
   122 lemma (in linorder) distinct_inorder_if_bst: "bst t \<Longrightarrow> distinct (inorder t)"
   125 lemma (in linorder) distinct_inorder_if_bst: "bst t \<Longrightarrow> distinct (inorder t)"
   123 apply (induction t)
   126 apply (induction t)
   124  apply simp
   127  apply simp
   125 apply(fastforce elim: order.asym)
   128 apply(fastforce elim: order.asym)
   126 done
   129 done
       
   130 
       
   131 
       
   132 subsection "The heap predicate"
       
   133 
       
   134 fun heap :: "'a::linorder tree \<Rightarrow> bool" where
       
   135 "heap Leaf = True" |
       
   136 "heap (Node l m r) =
       
   137   (heap l \<and> heap r \<and> (\<forall>x \<in> set_tree l \<union> set_tree r. m \<le> x))"
   127 
   138 
   128 
   139 
   129 subsection "Function @{text mirror}"
   140 subsection "Function @{text mirror}"
   130 
   141 
   131 fun mirror :: "'a tree \<Rightarrow> 'a tree" where
   142 fun mirror :: "'a tree \<Rightarrow> 'a tree" where