src/HOL/Library/Tree.thy
changeset 58438 566117a31cc0
parent 58424 cbbba613b6ab
child 58467 6a3da58f7233
equal deleted inserted replaced
58437:8d124c73c37a 58438:566117a31cc0
    11   Node (left: "'a tree") (val: 'a) (right: "'a tree") ("\<langle>_, _, _\<rangle>")
    11   Node (left: "'a tree") (val: 'a) (right: "'a tree") ("\<langle>_, _, _\<rangle>")
    12   where
    12   where
    13     "left Leaf = Leaf"
    13     "left Leaf = Leaf"
    14   | "right Leaf = Leaf"
    14   | "right Leaf = Leaf"
    15 datatype_compat tree
    15 datatype_compat tree
       
    16 
       
    17 text{* Can be seen as counting the number of leaves rather than nodes: *}
       
    18 
       
    19 definition size1 :: "'a tree \<Rightarrow> nat" where
       
    20 "size1 t = size t + 1"
       
    21 
       
    22 lemma size1_simps[simp]:
       
    23   "size1 \<langle>\<rangle> = 1"
       
    24   "size1 \<langle>l, x, r\<rangle> = size1 l + size1 r"
       
    25 by (simp_all add: size1_def)
    16 
    26 
    17 lemma neq_Leaf_iff: "(t \<noteq> \<langle>\<rangle>) = (\<exists>l a r. t = \<langle>l, a, r\<rangle>)"
    27 lemma neq_Leaf_iff: "(t \<noteq> \<langle>\<rangle>) = (\<exists>l a r. t = \<langle>l, a, r\<rangle>)"
    18 by (cases t) auto
    28 by (cases t) auto
    19 
    29 
    20 lemma finite_set_tree[simp]: "finite(set_tree t)"
    30 lemma finite_set_tree[simp]: "finite(set_tree t)"