author | wenzelm |
Fri, 07 Aug 2020 22:28:04 +0200 | |
changeset 72118 | 84f716e72fa3 |
parent 71846 | 1a884605a08b |
child 72269 | 88880eecd7fe |
permissions | -rw-r--r-- |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
1 |
(* Author: Tobias Nipkow *) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
2 |
|
68261 | 3 |
section "Join-Based Implementation of Sets" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
4 |
|
68261 | 5 |
theory Set2_Join |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
6 |
imports |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
7 |
Isin2 |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
8 |
begin |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
9 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
10 |
text \<open>This theory implements the set operations \<open>insert\<close>, \<open>delete\<close>, |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
11 |
\<open>union\<close>, \<open>inter\<close>section and \<open>diff\<close>erence. The implementation is based on binary search trees. |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
12 |
All operations are reduced to a single operation \<open>join l x r\<close> that joins two BSTs \<open>l\<close> and \<open>r\<close> |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
13 |
and an element \<open>x\<close> such that \<open>l < x < r\<close>. |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
14 |
|
69597 | 15 |
The theory is based on theory \<^theory>\<open>HOL-Data_Structures.Tree2\<close> where nodes have an additional field. |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
16 |
This field is ignored here but it means that this theory can be instantiated |
69597 | 17 |
with red-black trees (see theory \<^file>\<open>Set2_Join_RBT.thy\<close>) and other balanced trees. |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
18 |
This approach is very concrete and fixes the type of trees. |
69597 | 19 |
Alternatively, one could assume some abstract type \<^typ>\<open>'t\<close> of trees with suitable decomposition |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
20 |
and recursion operators on it.\<close> |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
21 |
|
68261 | 22 |
locale Set2_Join = |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
23 |
fixes join :: "('a::linorder*'b) tree \<Rightarrow> 'a \<Rightarrow> ('a*'b) tree \<Rightarrow> ('a*'b) tree" |
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
24 |
fixes inv :: "('a*'b) tree \<Rightarrow> bool" |
68261 | 25 |
assumes set_join: "set_tree (join l a r) = set_tree l \<union> {a} \<union> set_tree r" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
26 |
assumes bst_join: "bst (Node l (a, b) r) \<Longrightarrow> bst (join l a r)" |
68261 | 27 |
assumes inv_Leaf: "inv \<langle>\<rangle>" |
68969 | 28 |
assumes inv_join: "\<lbrakk> inv l; inv r \<rbrakk> \<Longrightarrow> inv (join l a r)" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
29 |
assumes inv_Node: "\<lbrakk> inv (Node l (a,b) r) \<rbrakk> \<Longrightarrow> inv l \<and> inv r" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
30 |
begin |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
31 |
|
71846 | 32 |
declare set_join [simp] Let_def[simp] |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
33 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
34 |
subsection "\<open>split_min\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
35 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
36 |
fun split_min :: "('a*'b) tree \<Rightarrow> 'a \<times> ('a*'b) tree" where |
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
37 |
"split_min (Node l (a, _) r) = |
68969 | 38 |
(if l = Leaf then (a,r) else let (m,l') = split_min l in (m, join l' a r))" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
39 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
40 |
lemma split_min_set: |
70582 | 41 |
"\<lbrakk> split_min t = (m,t'); t \<noteq> Leaf \<rbrakk> \<Longrightarrow> m \<in> set_tree t \<and> set_tree t = {m} \<union> set_tree t'" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
42 |
proof(induction t arbitrary: t' rule: tree2_induct) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
43 |
case Node thus ?case by(auto split: prod.splits if_splits dest: inv_Node) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
44 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
45 |
case Leaf thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
46 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
47 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
48 |
lemma split_min_bst: |
68969 | 49 |
"\<lbrakk> split_min t = (m,t'); bst t; t \<noteq> Leaf \<rbrakk> \<Longrightarrow> bst t' \<and> (\<forall>x \<in> set_tree t'. m < x)" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
50 |
proof(induction t arbitrary: t' rule: tree2_induct) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
51 |
case Node thus ?case by(fastforce simp: split_min_set bst_join split: prod.splits if_splits) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
52 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
53 |
case Leaf thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
54 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
55 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
56 |
lemma split_min_inv: |
68969 | 57 |
"\<lbrakk> split_min t = (m,t'); inv t; t \<noteq> Leaf \<rbrakk> \<Longrightarrow> inv t'" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
58 |
proof(induction t arbitrary: t' rule: tree2_induct) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
59 |
case Node thus ?case by(auto simp: inv_join split: prod.splits if_splits dest: inv_Node) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
60 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
61 |
case Leaf thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
62 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
63 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
64 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
65 |
subsection "\<open>join2\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
66 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
67 |
definition join2 :: "('a*'b) tree \<Rightarrow> ('a*'b) tree \<Rightarrow> ('a*'b) tree" where |
68969 | 68 |
"join2 l r = (if r = Leaf then l else let (m,r') = split_min r in join l m r')" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
69 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
70 |
lemma set_join2[simp]: "set_tree (join2 l r) = set_tree l \<union> set_tree r" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
71 |
by(simp add: join2_def split_min_set split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
72 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
73 |
lemma bst_join2: "\<lbrakk> bst l; bst r; \<forall>x \<in> set_tree l. \<forall>y \<in> set_tree r. x < y \<rbrakk> |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
74 |
\<Longrightarrow> bst (join2 l r)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
75 |
by(simp add: join2_def bst_join split_min_set split_min_bst split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
76 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
77 |
lemma inv_join2: "\<lbrakk> inv l; inv r \<rbrakk> \<Longrightarrow> inv (join2 l r)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
78 |
by(simp add: join2_def inv_join split_min_set split_min_inv split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
79 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
80 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
81 |
subsection "\<open>split\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
82 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
83 |
fun split :: "('a*'b)tree \<Rightarrow> 'a \<Rightarrow> ('a*'b)tree \<times> bool \<times> ('a*'b)tree" where |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
84 |
"split Leaf k = (Leaf, False, Leaf)" | |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
85 |
"split (Node l (a, _) r) x = |
70572 | 86 |
(case cmp x a of |
87 |
LT \<Rightarrow> let (l1,b,l2) = split l x in (l1, b, join l2 a r) | |
|
88 |
GT \<Rightarrow> let (r1,b,r2) = split r x in (join l a r1, b, r2) | |
|
89 |
EQ \<Rightarrow> (l, True, r))" |
|
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
90 |
|
68969 | 91 |
lemma split: "split t x = (l,xin,r) \<Longrightarrow> bst t \<Longrightarrow> |
92 |
set_tree l = {a \<in> set_tree t. a < x} \<and> set_tree r = {a \<in> set_tree t. x < a} |
|
93 |
\<and> (xin = (x \<in> set_tree t)) \<and> bst l \<and> bst r" |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
94 |
proof(induction t arbitrary: l xin r rule: tree2_induct) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
95 |
case Leaf thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
96 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
97 |
case Node thus ?case by(force split!: prod.splits if_splits intro!: bst_join) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
98 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
99 |
|
68969 | 100 |
lemma split_inv: "split t x = (l,xin,r) \<Longrightarrow> inv t \<Longrightarrow> inv l \<and> inv r" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
101 |
proof(induction t arbitrary: l xin r rule: tree2_induct) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
102 |
case Leaf thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
103 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
104 |
case Node |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
105 |
thus ?case by(force simp: inv_join split!: prod.splits if_splits dest!: inv_Node) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
106 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
107 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
108 |
declare split.simps[simp del] |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
109 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
110 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
111 |
subsection "\<open>insert\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
112 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
113 |
definition insert :: "'a \<Rightarrow> ('a*'b) tree \<Rightarrow> ('a*'b) tree" where |
68969 | 114 |
"insert x t = (let (l,_,r) = split t x in join l x r)" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
115 |
|
70582 | 116 |
lemma set_tree_insert: "bst t \<Longrightarrow> set_tree (insert x t) = {x} \<union> set_tree t" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
117 |
by(auto simp add: insert_def split split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
118 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
119 |
lemma bst_insert: "bst t \<Longrightarrow> bst (insert x t)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
120 |
by(auto simp add: insert_def bst_join dest: split split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
121 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
122 |
lemma inv_insert: "inv t \<Longrightarrow> inv (insert x t)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
123 |
by(force simp: insert_def inv_join dest: split_inv split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
124 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
125 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
126 |
subsection "\<open>delete\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
127 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
128 |
definition delete :: "'a \<Rightarrow> ('a*'b) tree \<Rightarrow> ('a*'b) tree" where |
68969 | 129 |
"delete x t = (let (l,_,r) = split t x in join2 l r)" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
130 |
|
68969 | 131 |
lemma set_tree_delete: "bst t \<Longrightarrow> set_tree (delete x t) = set_tree t - {x}" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
132 |
by(auto simp: delete_def split split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
133 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
134 |
lemma bst_delete: "bst t \<Longrightarrow> bst (delete x t)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
135 |
by(force simp add: delete_def intro: bst_join2 dest: split split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
136 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
137 |
lemma inv_delete: "inv t \<Longrightarrow> inv (delete x t)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
138 |
by(force simp: delete_def inv_join2 dest: split_inv split: prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
139 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
140 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
141 |
subsection "\<open>union\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
142 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
143 |
fun union :: "('a*'b)tree \<Rightarrow> ('a*'b)tree \<Rightarrow> ('a*'b)tree" where |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
144 |
"union t1 t2 = |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
145 |
(if t1 = Leaf then t2 else |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
146 |
if t2 = Leaf then t1 else |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
147 |
case t1 of Node l1 (a, _) r1 \<Rightarrow> |
68969 | 148 |
let (l2,_ ,r2) = split t2 a; |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
149 |
l' = union l1 l2; r' = union r1 r2 |
68969 | 150 |
in join l' a r')" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
151 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
152 |
declare union.simps [simp del] |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
153 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
154 |
lemma set_tree_union: "bst t2 \<Longrightarrow> set_tree (union t1 t2) = set_tree t1 \<union> set_tree t2" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
155 |
proof(induction t1 t2 rule: union.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
156 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
157 |
then show ?case |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
158 |
by (auto simp: union.simps[of t1 t2] split split: tree.split prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
159 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
160 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
161 |
lemma bst_union: "\<lbrakk> bst t1; bst t2 \<rbrakk> \<Longrightarrow> bst (union t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
162 |
proof(induction t1 t2 rule: union.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
163 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
164 |
thus ?case |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
165 |
by(fastforce simp: union.simps[of t1 t2] set_tree_union split intro!: bst_join |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
166 |
split: tree.split prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
167 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
168 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
169 |
lemma inv_union: "\<lbrakk> inv t1; inv t2 \<rbrakk> \<Longrightarrow> inv (union t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
170 |
proof(induction t1 t2 rule: union.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
171 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
172 |
thus ?case |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
173 |
by(auto simp:union.simps[of t1 t2] inv_join split_inv |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
174 |
split!: tree.split prod.split dest: inv_Node) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
175 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
176 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
177 |
subsection "\<open>inter\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
178 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
179 |
fun inter :: "('a*'b)tree \<Rightarrow> ('a*'b)tree \<Rightarrow> ('a*'b)tree" where |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
180 |
"inter t1 t2 = |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
181 |
(if t1 = Leaf then Leaf else |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
182 |
if t2 = Leaf then Leaf else |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
183 |
case t1 of Node l1 (a, _) r1 \<Rightarrow> |
68969 | 184 |
let (l2,ain,r2) = split t2 a; |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
185 |
l' = inter l1 l2; r' = inter r1 r2 |
68969 | 186 |
in if ain then join l' a r' else join2 l' r')" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
187 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
188 |
declare inter.simps [simp del] |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
189 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
190 |
lemma set_tree_inter: |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
191 |
"\<lbrakk> bst t1; bst t2 \<rbrakk> \<Longrightarrow> set_tree (inter t1 t2) = set_tree t1 \<inter> set_tree t2" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
192 |
proof(induction t1 t2 rule: inter.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
193 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
194 |
show ?case |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
195 |
proof (cases t1 rule: tree2_cases) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
196 |
case Leaf thus ?thesis by (simp add: inter.simps) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
197 |
next |
68969 | 198 |
case [simp]: (Node l1 a _ r1) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
199 |
show ?thesis |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
200 |
proof (cases "t2 = Leaf") |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
201 |
case True thus ?thesis by (simp add: inter.simps) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
202 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
203 |
case False |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
204 |
let ?L1 = "set_tree l1" let ?R1 = "set_tree r1" |
68969 | 205 |
have *: "a \<notin> ?L1 \<union> ?R1" using \<open>bst t1\<close> by (fastforce) |
206 |
obtain l2 ain r2 where sp: "split t2 a = (l2,ain,r2)" using prod_cases3 by blast |
|
207 |
let ?L2 = "set_tree l2" let ?R2 = "set_tree r2" let ?K = "if ain then {a} else {}" |
|
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
208 |
have t2: "set_tree t2 = ?L2 \<union> ?R2 \<union> ?K" and |
68969 | 209 |
**: "?L2 \<inter> ?R2 = {}" "a \<notin> ?L2 \<union> ?R2" "?L1 \<inter> ?R2 = {}" "?L2 \<inter> ?R1 = {}" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
210 |
using split[OF sp] \<open>bst t1\<close> \<open>bst t2\<close> by (force, force, force, force, force) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
211 |
have IHl: "set_tree (inter l1 l2) = set_tree l1 \<inter> set_tree l2" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
212 |
using "1.IH"(1)[OF _ False _ _ sp[symmetric]] "1.prems"(1,2) split[OF sp] by simp |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
213 |
have IHr: "set_tree (inter r1 r2) = set_tree r1 \<inter> set_tree r2" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
214 |
using "1.IH"(2)[OF _ False _ _ sp[symmetric]] "1.prems"(1,2) split[OF sp] by simp |
68969 | 215 |
have "set_tree t1 \<inter> set_tree t2 = (?L1 \<union> ?R1 \<union> {a}) \<inter> (?L2 \<union> ?R2 \<union> ?K)" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
216 |
by(simp add: t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
217 |
also have "\<dots> = (?L1 \<inter> ?L2) \<union> (?R1 \<inter> ?R2) \<union> ?K" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
218 |
using * ** by auto |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
219 |
also have "\<dots> = set_tree (inter t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
220 |
using IHl IHr sp inter.simps[of t1 t2] False by(simp) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
221 |
finally show ?thesis by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
222 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
223 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
224 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
225 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
226 |
lemma bst_inter: "\<lbrakk> bst t1; bst t2 \<rbrakk> \<Longrightarrow> bst (inter t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
227 |
proof(induction t1 t2 rule: inter.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
228 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
229 |
thus ?case |
71846 | 230 |
by(fastforce simp: inter.simps[of t1 t2] set_tree_inter split |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
231 |
intro!: bst_join bst_join2 split: tree.split prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
232 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
233 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
234 |
lemma inv_inter: "\<lbrakk> inv t1; inv t2 \<rbrakk> \<Longrightarrow> inv (inter t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
235 |
proof(induction t1 t2 rule: inter.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
236 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
237 |
thus ?case |
71846 | 238 |
by(auto simp: inter.simps[of t1 t2] inv_join inv_join2 split_inv |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
239 |
split!: tree.split prod.split dest: inv_Node) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
240 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
241 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
242 |
subsection "\<open>diff\<close>" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
243 |
|
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
244 |
fun diff :: "('a*'b)tree \<Rightarrow> ('a*'b)tree \<Rightarrow> ('a*'b)tree" where |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
245 |
"diff t1 t2 = |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
246 |
(if t1 = Leaf then Leaf else |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
247 |
if t2 = Leaf then t1 else |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
248 |
case t2 of Node l2 (a, _) r2 \<Rightarrow> |
68969 | 249 |
let (l1,_,r1) = split t1 a; |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
250 |
l' = diff l1 l2; r' = diff r1 r2 |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
251 |
in join2 l' r')" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
252 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
253 |
declare diff.simps [simp del] |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
254 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
255 |
lemma set_tree_diff: |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
256 |
"\<lbrakk> bst t1; bst t2 \<rbrakk> \<Longrightarrow> set_tree (diff t1 t2) = set_tree t1 - set_tree t2" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
257 |
proof(induction t1 t2 rule: diff.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
258 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
259 |
show ?case |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
260 |
proof (cases t2 rule: tree2_cases) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
261 |
case Leaf thus ?thesis by (simp add: diff.simps) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
262 |
next |
68969 | 263 |
case [simp]: (Node l2 a _ r2) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
264 |
show ?thesis |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
265 |
proof (cases "t1 = Leaf") |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
266 |
case True thus ?thesis by (simp add: diff.simps) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
267 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
268 |
case False |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
269 |
let ?L2 = "set_tree l2" let ?R2 = "set_tree r2" |
68969 | 270 |
obtain l1 ain r1 where sp: "split t1 a = (l1,ain,r1)" using prod_cases3 by blast |
271 |
let ?L1 = "set_tree l1" let ?R1 = "set_tree r1" let ?K = "if ain then {a} else {}" |
|
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
272 |
have t1: "set_tree t1 = ?L1 \<union> ?R1 \<union> ?K" and |
68969 | 273 |
**: "a \<notin> ?L1 \<union> ?R1" "?L1 \<inter> ?R2 = {}" "?L2 \<inter> ?R1 = {}" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
274 |
using split[OF sp] \<open>bst t1\<close> \<open>bst t2\<close> by (force, force, force, force) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
275 |
have IHl: "set_tree (diff l1 l2) = set_tree l1 - set_tree l2" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
276 |
using "1.IH"(1)[OF False _ _ _ sp[symmetric]] "1.prems"(1,2) split[OF sp] by simp |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
277 |
have IHr: "set_tree (diff r1 r2) = set_tree r1 - set_tree r2" |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
278 |
using "1.IH"(2)[OF False _ _ _ sp[symmetric]] "1.prems"(1,2) split[OF sp] by simp |
68969 | 279 |
have "set_tree t1 - set_tree t2 = (?L1 \<union> ?R1) - (?L2 \<union> ?R2 \<union> {a})" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
280 |
by(simp add: t1) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
281 |
also have "\<dots> = (?L1 - ?L2) \<union> (?R1 - ?R2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
282 |
using ** by auto |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
283 |
also have "\<dots> = set_tree (diff t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
284 |
using IHl IHr sp diff.simps[of t1 t2] False by(simp) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
285 |
finally show ?thesis by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
286 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
287 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
288 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
289 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
290 |
lemma bst_diff: "\<lbrakk> bst t1; bst t2 \<rbrakk> \<Longrightarrow> bst (diff t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
291 |
proof(induction t1 t2 rule: diff.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
292 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
293 |
thus ?case |
71846 | 294 |
by(fastforce simp: diff.simps[of t1 t2] set_tree_diff split |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
295 |
intro!: bst_join bst_join2 split: tree.split prod.split) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
296 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
297 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
298 |
lemma inv_diff: "\<lbrakk> inv t1; inv t2 \<rbrakk> \<Longrightarrow> inv (diff t1 t2)" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
299 |
proof(induction t1 t2 rule: diff.induct) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
300 |
case (1 t1 t2) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
301 |
thus ?case |
71846 | 302 |
by(auto simp: diff.simps[of t1 t2] inv_join inv_join2 split_inv |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
303 |
split!: tree.split prod.split dest: inv_Node) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
304 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
305 |
|
69597 | 306 |
text \<open>Locale \<^locale>\<open>Set2_Join\<close> implements locale \<^locale>\<open>Set2\<close>:\<close> |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
307 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
308 |
sublocale Set2 |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
309 |
where empty = Leaf and insert = insert and delete = delete and isin = isin |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
310 |
and union = union and inter = inter and diff = diff |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
311 |
and set = set_tree and invar = "\<lambda>t. inv t \<and> bst t" |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
312 |
proof (standard, goal_cases) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
313 |
case 1 show ?case by (simp) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
314 |
next |
67967 | 315 |
case 2 thus ?case by(simp add: isin_set_tree) |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
316 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
317 |
case 3 thus ?case by (simp add: set_tree_insert) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
318 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
319 |
case 4 thus ?case by (simp add: set_tree_delete) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
320 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
321 |
case 5 thus ?case by (simp add: inv_Leaf) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
322 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
323 |
case 6 thus ?case by (simp add: bst_insert inv_insert) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
324 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
325 |
case 7 thus ?case by (simp add: bst_delete inv_delete) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
326 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
327 |
case 8 thus ?case by(simp add: set_tree_union) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
328 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
329 |
case 9 thus ?case by(simp add: set_tree_inter) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
330 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
331 |
case 10 thus ?case by(simp add: set_tree_diff) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
332 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
333 |
case 11 thus ?case by (simp add: bst_union inv_union) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
334 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
335 |
case 12 thus ?case by (simp add: bst_inter inv_inter) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
336 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
337 |
case 13 thus ?case by (simp add: bst_diff inv_diff) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
338 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
339 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
340 |
end |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
341 |
|
68261 | 342 |
interpretation unbal: Set2_Join |
70755
3fb16bed5d6c
replaced new type ('a,'b) tree by old type ('a*'b) tree.
nipkow
parents:
70582
diff
changeset
|
343 |
where join = "\<lambda>l x r. Node l (x, ()) r" and inv = "\<lambda>t. True" |
67966
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
344 |
proof (standard, goal_cases) |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
345 |
case 1 show ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
346 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
347 |
case 2 thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
348 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
349 |
case 3 thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
350 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
351 |
case 4 thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
352 |
next |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
353 |
case 5 thus ?case by simp |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
354 |
qed |
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
355 |
|
f13796496e82
Added binary set operations with join-based implementation
nipkow
parents:
diff
changeset
|
356 |
end |