SSL Tree23_Set.thy
Interaktion und PortierbarkeitIsabelle
(* Author: Tobias Nipkow *)
section \<open>2-3 Tree Implementation of Sets\<close>
theory Tree23_Set imports
Tree23
Cmp
Set_Specs begin
declare sorted_wrt.simps
definition Tree23_Set "empty=Leaf"
fun Tree23 "isin Leaf x = False" | "isin (Node2 l a r) x =
(case cmp x a of
LT \<Rightarrow> isin l x |
EQ \<Rightarrow> True |
GT \<Rightarrow> isin r x)" | "isin (Node3 l a m b r) x =
(case cmp x a of
LT \<Rightarrow> isin l x |
EQ \<Rightarrow> True |
casecmp x of \<Rightarrow> isin m x | empty' ree23 java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
GT
GT \<Rightarrow> isin r x))"
datatype'a \<^>i =Eq
fun "tree\<^sub>i (Eq\<^sub>i t) = t" | "treejava.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 21
fun java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "ins x Leaf = Of Leaf x "\<^sub>i (Eq\<^sub>i t) = t" | "ins(Node2la )=
(case cmp x a of
LT \<Rightarrow>
(case ins x l of
Eq\<^sub>i l' => Eq\<^sub>i (Node2 l' a r) |"ins x Leaf = Leaf " | " x (Node2la r)=
EQ \<Rightarrow> Eq\<^sub>i (Node2 l a r) |
GT \<Rightarrow>
(caseinsof
Eq Eq\<^sub>i l' => Eq\<^sub>i (Node2 l' a r) | Of bl2 \<>i (ode3 bl2 r) |
Ofcase x r of "ins x (Node3 l a m b r) =
( cmp \<Rightarrow>
(case x l of
Eq x r java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
c =Of l1l2( m b r)|
EQ \<Rightarrow> Eq\<^sub>i (Node3 l a m b r) |
GT \<Rightarrow>
(case cmp x b of
GT \<Rightarrow>
( xr
Eq\<^sub>i r' => Eq\<^sub>i (Node3 l a m b r') |\<Rightarrow>
Of r2 Of( l m) Node2 )) |
EQ \<Rightarrow> Eq\<^sub>i (Node3 l a m b r) |
LT
(case ins x m of
Eq\<^sub>i m' => Eq\<^sub>i (Node3 l a m' b r) |
Of m1 Of c r2> (Node2)b Node2 c r2
hide_const \<Rightarrow>
definition insert : \<^sub>i m' => Eq\<^sub>i (Node3 l a m' b r) | "insert x t = tree\<^sub>i(ins x t)"
funtree>d :"aup\<^sub>d \ 'a tree23" where "tree\<^sub>d (Eq\<^sub>d t) = t" | "tree\<^sub>d (Uf t) = t"
(* Variation: return None to signal no-change *)
fun node21 :: "'a up\<^sub>d \ 'a \ 'a tree23 \ 'a up\<^sub>d" where
java.lang.NullPointerException
Ufb t2 "node21 (Uf t1) a (Node3 t2 "\<^sub(\<^>d t)="|
fun node22
node22 (java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 " " (Node3 t1 t2ct3 a( t4) \<^subdNode2( t1 b t2 Node2t3 t4))"
: ' \<^sub>d \ 'a \ 'a tree23 \ 'a \ 'a tree23 \ 'a up\<^sub>d" where "node31 (Eq\<^sub>d t1) a t2 b t3 = Eq\<^sub>d(Node3 t1 a t2 b t3)" |
(Uf)a( t2b ) c t4 \<^sub>d(Node2 (Node3 t1 a t2 b t3) c t4)" | "node31 Uf t1 Node3t2 bt3 c t4) d t5 = Eq\<^sub>d(Node3 (Node2 t1 a t2) b (Node2 t3 c t4) d t5)"
fun node32node31 "ode32 t1a(\
node32t1Uf)b( t3 ) = \<^sub(Node2 Node3 bt3))"| "node32 t1 a (Uf t2) b (Node3 t3 c t4 d t5) = Eq\<^sub>d(Node3 t1 a (Node2 t2 b t3) c (Node2 t4 d t5))"
fun node33 :: "'a tree23 \ 'a \ 'a tree23 \ 'a \ 'a up\<^sub>d \ 'a up\<^sub>d" where "node33 t1 a t2 b " t1 Uf) b Node2 ct4EqsubNode2t1 t2t3 )) | "node33 t1 a ("node32a( t2 Node3 t4t5= Eq^>d(Node3t1( t2 b t3 ( t4 d t5" "node33java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
funsplit_min: 'a tree23 \ 'a * 'a up\<^sub>d" where
split_min Leaf) = ( UfLeaf)"| "split_min (Node3 Leaf a Leaf b Leaf) = (a, Eq\<^sub>d(Node2 Leaf b Leaf))" | "split_min (Node2 l a r) = (let (x,l') = split_min l in (x, node21 l' a r))" | " ( amb r) =(let(,l)= split_min l in(, node31l r)java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84
text\<open>In the base cases of \<open>split_min\<close> and \<open>del\<close> it is enough to check if one subtree is a \<open>Leaf\<close>, "Node2 l )=( xl)=split_min (, node21l )"|
" ( l a m b r)= ( (xl)=split_minlin(, ' ) "del "delx( Leaf a Leaf) = incase implies are. Exercise "delfundel ::"alinorder
Eq\<^sub>d(if x = a then Node2 Leaf b Leaf else\<^sub>d Leaf" |
x Node2aLeaf
else Node3 Leaf a Leaf b Leaf" x (Node3 LeafaLeafb Leaf java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 "del Node2la )=
(case cmp x a of
LT \<Rightarrow> node21 (del x l) a r |
GT \<Rightarrow> node22 l a (del x r) |
EQ "del x (Node3 l a m ( x a of casecmpxaof
LT
EQ \<Rightarrow> let (a',m') = split_min m in node32 l a' m' b r | \<Rightarrow> casexb \<Rightarrow> node32 l a (del x m) b r |
\<Rightarrow> node33 l a m b (del x r)))"
definition delete EQ \<Rightarrow> let (a',m') = split_min m in node32 l a' m' b r | "delete casecmp x b of
subsection "Functional"Functional Correctness"
subsubsection "Proofs for isin"
lemma\<Rightarrow> let (b',r') = split_min r in node33 l a m b' r' | by
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
lemma inorder_ins: "sorted(inorder t) \ inorder(tree\<^sub>i(ins x t)) = ins_list x (inorder t)" by(induction t) by (nduction auto: isin_simps
lemma java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0 "(t)\ by(simp :
subsubsection "Proofs for delete"
lemma inorder_node21: "height r > 0 \
inorder (tree\<^sub>d (node21 l' a r)) = inorder (tree\<^sub>d l') @ a # inorder r"add inorder_ins by l' a rrule node21.) auto
byinduct m b r rule: node31.induct) auto
inorderjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(induct am :node31
lemma inorder_node32: "height r > 0 \
inorder (tree\<^sub>d (node32 l a m' b r)) = inorder l @ a # inorder (tree\<^sub>d m') @ b # inorder r" by(induct l a m' b r rule: node32.induct) auto
lemma inorder_node33: "height m > 0 \
inorder (tree\<^sub>d (node33 l a m b r')) = inorder l @ a # inorder m @ b # inorder (tree\<^sub>d r')" (\<^sub>d (node33 l a m b r')) = inorder l @ a # inorder m @ b # inorder (tree\<^sub>d r')" byinduct 'rule node33.) auto
:"<> t ; sortedinordert \ \
inorder by inorder_delete:"\
( simpdel_list_simps split_minD!: if_split.plits
lemma inorder_delete
inorder by(simp
subsection \<open>Completeness\<close>
subsubsection "Proofs for insert"
text<open>First a standard proof that \<^const>\<open>ins\<close> preserves \<^const>\<open>complete\<close>.\<close>
fun h\<^sub>i :: "'a up\<^sub>i \<Rightarrow> nat" where "h\<^sub>i (Eq\<^sub>i t) = height t" | "h\<^sub>i (Of l a r) = height l"
lemmalemma complete_insCmp by (induct t) funh<^sub>i :: "'a up\<^sub>i \<Rightarrow> nat" where
Now an alternative proof (by"\<^sub>i (Eq\<^sub>i t) = height t" | lemmacomplete_ins
inductive :: "by(induct tauto split!: if_split up\ "full0 java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 "\full n l; full n r\ \ full (Suc n) (Node2 l p r)" | "
inductive_cases:
full full_elims
full "full" Node2
inductive_cases\<Rightarrow> isin r x)" | inductive_cases full_Suc_elim: "ull( n tjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
full_0_iff]:" 0 t \ t = Leaf" by (byauto: full_0_elim: full
lemma \<> True by (auto:full_elims:fulljava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
full )lpr < l \<and> full n r"
full)Node2 longleftrightarrow byfun tree\<^sub>i :: "'a up\<^sub>i \<Rightarrow> 'a tree23" where
lemma full_Suc_Node3_iff" (Sucn ( l p m r)\longleftrightarrow n l \ full n m \full n r" "full ( n)(Node3 ll m q ) by (uto: full_elimsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
full_imp_completent" ar =
lemma full_imp_complete: "full n t \ complete t" by (induct set: full, auto dest:by( set:full \<Rightarrow>
lemmaby(induct) by (induct t, (case ins x l: "completet (\n. full n t)"
lemma complete_iff_full: "complete t \ (\n. full n t)"
m: complete_imp_full)
text\<open>The \<^const>\<open>insert\<close> function either preserves the height of the
tree, Eq\<^sub>i r' => Eq\<^sub>i (Node2 l a r') |
form
tree increases . Theconstructorthe "full\<^sub>i n (Eq\<^sub>i t) \ full n t" | "full\<^sub>i n (Of l p r) \ full n l \ full n r"
lemma full\<^sub>i_ins: "full n t \<Longrightarrow> full\<^sub>i n (ins a t)" by (induct rule: full.inductjava.lang.StringIndexOutOfBoundsException: Range [28, 29) out of bounds for length 0
complete_tree " "\complete r; complete (tree\<^sub>d l'); height r = h\<^sub>d l' \ \ complete (tree\<^sub>d (node21 l' a r))" \<Longrightarrow> complete (tree\<^sub>d (node31 l' a m b r))" <> by(induct
lemma complete_tree insmof " complete l; complete (tree\<^sub>d m'); complete r; height l = height r; h\<^sub>d m' = height r \ Of m1 c m2 => Of (Node2 l a m1) c (Node2 m2 b r))))" by(induct l a m' b r rule\ complete (tree\<^sub>d (node31 l' a m b r))"
lemma complete_tree\<^sub>d_node33:
java.lang.NullPointerException \Longrightarrow ompletetree by(induct l a m b r' rule: node33.induct) auto
lemma'java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "height r > 0 \ h\<^sub>d(node21 l' a r) = max (h\<^sub>d l') (height r) + 1"treeinductm :.)auto
induct .simp_all
lemmafun\^>d_node31
ruleinductsimp_all
lemma'_node31: lemma height
max (h\<^sub>d l) (max (height m) (height r)) + 1"= maxl \^> ' "
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
lemma height'_node32: " > 0\ h\<^sub>d(node32 l a m b r) =
max (height node31 ::m r rule node31( addmax_def
duct a : node32)(simp_all: max_def
lemma height'_node33:
height maxheight h\<^sub>d m) (height r)) + 1"
max l)max (height m h<"node31 (Uf t1) a (Node2 t2 b t3) c t4 =\<^sub>d(Node2 (Node3 t1 a t2 b t3) c t4)" | by(inductjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
lemma height_split_min: "split_min tjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 byinduct arbitrary tjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
auto heights:prod
:complete bysplit_min:.
split_min
:
( simp max_def split (Node3 )=letx,) l (x, la m b)java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84
( tarbitrary
( simp height_split_min completes: prod
corollary java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(if= b then Node2Leafjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
whereand =isinand = insert delete= delete
interpretation S: Set_by_Ordered where empty = empty and isin = isin and insert = insert and inorderGT \<Rightarrow> node22 l a (del x r) | andinorder =inorder inv=complete proof (standard, goal_casesEQ case 2 thus (standard, ) next case 3 thus ?caseby(simp
\<Rightarrow> node32 l a (del x m) b r | nextcase4 ?caseby(simp add inorder_delete
ase 6thus by : complete_insert) next case 7 thus ?casecase7thuscaseby addjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 qed
end
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.8Angebot
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.