src/HOL/Data_Structures/Set2_BST2_Join.thy
changeset 67967 5a4280946a25
parent 67966 f13796496e82
equal deleted inserted replaced
67966:f13796496e82 67967:5a4280946a25
    18 This field is ignored here but it means that this theory can be instantiated
    18 This field is ignored here but it means that this theory can be instantiated
    19 with red-black trees (see theory @{file "Set2_BST2_Join_RBT.thy"}) and other balanced trees.
    19 with red-black trees (see theory @{file "Set2_BST2_Join_RBT.thy"}) and other balanced trees.
    20 This approach is very concrete and fixes the type of trees.
    20 This approach is very concrete and fixes the type of trees.
    21 Alternatively, one could assume some abstract type @{typ 't} of trees with suitable decomposition
    21 Alternatively, one could assume some abstract type @{typ 't} of trees with suitable decomposition
    22 and recursion operators on it.\<close>
    22 and recursion operators on it.\<close>
    23 
       
    24 fun set_tree :: "('a,'b) tree \<Rightarrow> 'a set" where
       
    25 "set_tree Leaf = {}" |
       
    26 "set_tree (Node _ l x r) = Set.insert x (set_tree l \<union> set_tree r)"
       
    27 
       
    28 fun bst :: "('a::linorder,'b) tree \<Rightarrow> bool" where
       
    29 "bst Leaf = True" |
       
    30 "bst (Node _ l a r) = (bst l \<and> bst r \<and> (\<forall>x \<in> set_tree l. x < a) \<and> (\<forall>x \<in> set_tree r. a < x))"
       
    31 
       
    32 lemma isin_iff: "bst t \<Longrightarrow> isin t x \<longleftrightarrow> x \<in> set_tree t"
       
    33 by(induction t) auto
       
    34 
    23 
    35 locale Set2_BST2_Join =
    24 locale Set2_BST2_Join =
    36 fixes join :: "('a::linorder,'b) tree \<Rightarrow> 'a \<Rightarrow> ('a,'b) tree \<Rightarrow> ('a,'b) tree"
    25 fixes join :: "('a::linorder,'b) tree \<Rightarrow> 'a \<Rightarrow> ('a,'b) tree \<Rightarrow> ('a,'b) tree"
    37 fixes inv :: "('a,'b) tree \<Rightarrow> bool"
    26 fixes inv :: "('a,'b) tree \<Rightarrow> bool"
    38 assumes inv_Leaf: "inv \<langle>\<rangle>"
    27 assumes inv_Leaf: "inv \<langle>\<rangle>"
   324 and union = union and inter = inter and diff = diff
   313 and union = union and inter = inter and diff = diff
   325 and set = set_tree and invar = "\<lambda>t. inv t \<and> bst t"
   314 and set = set_tree and invar = "\<lambda>t. inv t \<and> bst t"
   326 proof (standard, goal_cases)
   315 proof (standard, goal_cases)
   327   case 1 show ?case by (simp)
   316   case 1 show ?case by (simp)
   328 next
   317 next
   329   case 2 thus ?case by(simp add: isin_iff)
   318   case 2 thus ?case by(simp add: isin_set_tree)
   330 next
   319 next
   331   case 3 thus ?case by (simp add: set_tree_insert)
   320   case 3 thus ?case by (simp add: set_tree_insert)
   332 next
   321 next
   333   case 4 thus ?case by (simp add: set_tree_delete)
   322   case 4 thus ?case by (simp add: set_tree_delete)
   334 next
   323 next