SSL Tree23_Set.thy
Interaktion und PortierbarkeitIsabelle
(* Author: Tobias Nipkow *)
section \<open>2-3 Tree Implementation of Sets\<close>
theory imports"
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
( cmpbof begin
declareLT
definition :: "at"where "empty = Leaf"
fun isin :: "'a::linorder tree23 \ 'a \ bool" where "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 cmpupsub \<^sub>i "'a tree23" | Of "'a tree23" 'a "'a tree23"
LT \<Rightarrow> isin l x |
EQ\<Rightarrow> True |
GT \<Rightarrow>
(case cmp x b of
LT \<Rightarrow> isin m x |
EQ \<Rightarrow> True |
GT \<Rightarrow> isin r x))"
datatype'a up\<^sub>i = Eq\<^sub>i "'a tree23" | Of "'a tree23" 'a "'a tree23"
fun tree\<^sub>i :: "'a up\<^sub>i \<Rightarrow> 'a tree23" where
tree "tree\<^sub>i (Of l a r) = Node2 l a r"
fun ins ::"ins x Node2 r java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
insOfxLeafjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
ins )
(case cmpEQ
LT \<Rightarrow>
(case ins x r of
Eq
l1 =>Eq^sub(ode3 l1 l2ar)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
EQ \<Rightarrow> Eq\<^sub>i (Node2 l a r) |
GT \<Rightarrow>
( insjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 case x a ofLT
Of insof "ins (Node3 la mb ) =
(case cmp x a of
LT \<Rightarrow>
(case ins x l of
Ofl1 l2> (Node2 c ) a Node2r) java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
Of l1 c l2 = (aseins r of
EQ \<Rightarrow> Eq\<^sub>i (Node3 l a m b r) |
GT
(case cmp x b of
GT \<Rightarrow>
r1c =>Of Node2am b( r1 cr2
Eq\<^sub>i r' => Eq\<^sub>i (Node3 l a m b r') | LT \<Rightarrow>
r1 =Of l a m b ( r1 )) |
EQ \<Rightarrow> Eq\<^sub>i (Node3 l a m b r) |
LT
(case ins x m of
Eq
Of m1 c m2 => Of (Node2 l a m1) c (Node2 m2 b r))))"
hide_const insert \<^sub: ' up\<^sub>d \ 'a tree23" where
java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
datatype"node21(Eq\<^sub>d t1) a t2 = Eq\<^sub>d(Node2 t1 a t2)" |
fun tree"node21 (Uf t1) a (Node2 t2 t3)= Uf(Node3 t1 a t2 b t3)" |
tree>d Eqsub)=t | "tree\<^sub>d (Uf t) = t"
(* Variation: return None to signal no-change *)
" t1 a(q<^sub>d t2) = Eq\<^sub>d(Node2 t1 a t2)" | "node21 (Eq\<^sub>d t1) a t2 = Eq\<^sub>d(Node2 t1 a t2)" | "node21 (Uf t1) a (Node2 t2 b t3) = Uf(Node3 t1 a t2 b t3)" | "node21 (Uf t1) a (Node3 t2 b t3 c t4) = Eq\<^sub>d(Node2 (Node2 t1 a t2) b (Node2 t3 c t4))"
funnode22b ) Uf=Eq>( Node2)c( a t4 "node22 funnode31 :"aup "node22 (Node2 t1 b t2) a (Uf t3) = Uf(Node3 t1 b t2 a t3)" | "node22 (Node3 t1"node31 t1 Node2 t3 =Eq
fun node31()a( c t4) d t5 = Eq " (Eq\<^sub>d t1) a t2 b t3 = Eq\<^sub>d(Node3 t1 a t2 b t3)" | "ode32 Eq<^sub>d t2) b t3 = Eq\<^sub>d(Node3 t1 a t2 b t3)" | "node31 (Uf t1) a (Node3 t2 b t3 c t4) d t5 = Eq\<^sub>d(Node3 (Node2 t1 a t2) b (Node2 t3 c t4) d t5)"
fun node32 :: "'a tree23"node32 a ( t2 Node2 ct4Eq>d t1a( t2b c t4 java.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87 "node32 t1 a (Eq\<^sub>d t2) b t3 = Eq\<^sub>d(Node3 t1 a t2 b t3)" |
node32 a( t2b( t3c ) = \<^>d(Node2 a (Node3 b t3ct4"|
t1 Uf) b( t3c d ) \<sub a Node2) cNode2))
fun node33 :: "'a tree23 \ 'a \ 'a tree23 \ 'a \ 'a up\<^sub>d \ 'a up\<^sub>d" where fun split_min : " \ 'a * 'a up\<^sub>d" where "node33 " (Node2 a Leafa,Uf Leaf) java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 "split_minNode3la r) =(let x' split_min x node31 'amb )"
fun split_min :: "'a tree23 \ 'a * 'a up\<^sub>d" where "split_min (Node2 Leaf a Leafjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "split_min (Node3 Leaf a Leaf b Leaf) = (a, Eq\<^sub>d(Node2 Leaf b Leaf))" | "plit_min ( lar let(,' split_min lin(, node21 'ar) |
split_minNode3 let,' = split_min in x,node31l a mbr))"
Node2a Leaf in which completeness that so the others.\<close>
del 'a:: \ 'a tree23 \ 'a up\<^sub>d" where "del x Leaf=Eq "del x (Node2 Leaf a Leaf) =
(if x = if =b then Leaf Leaf
del )=
Eq\<^sub>d(if x = a then Node2 Leaf b Leaf else if x = b then Node2 Leaf a Leaf
else Node3 Leaf x ( ar java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 "del \ let (a',r') = split_min r in node22 l a' r')" | casecmp
( cmp \<Rightarrow> node31 (del x l) a m b r |EQ
EQGT "del x (Node3 l a m ( cmp b of
(case cmp LT
LT EQ\<Rightarrow> let (b',r') = split_min r in node33 l a m b' r' |GT
EQ\<Rightarrow> let (a',m') = split_min m in node32 l a' m' b r |
GT\<Rightarrow>
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
EQ
GT \<Rightarrow> node33 l a m b (del x r)))"
definition delete :: "
subsection "Functional Correctness"
subsubsection "Proofs for isin"
lemma isin_set: "sorted(inorder t) java.lang.StringIndexOutOfBoundsException: Range [0, 36) out of bounds for length 0
i t)( simp)
subsubsection
lemma inorder_ins: "sorted(inorder t) \ inorder(tree\<^sub>i(ins x t)) = ins_list x (inorder t)" by(induction t) ( "sortedinorder t) inorder(insert a t) = ins_list a (inorder t)"
lemmainorder_insert
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(simp add:insert_def)
subsubsection "Proofs for delete"
lemma(induct :induct
inorder by(induct l' a r rule: node21.induct) auto
lemma inorder_node22: "height l > 0 \
inorder (treelemmainorder_node22" l > 0 \ byinduct l ar :node22auto
lemma inorder_node31" m > 0\
inorder
( l' a
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" l' b rrule: .induct) auto by(induct l a m' b r rule: node32.induct) auto
lemma inorder_node33: "height m > 0 \
inordertree by(induct l a m b r' rule: node33.induct) auto
lemmaby( l a mbr :induct "split_min tlemmas inorder_nodes=inorder_node21 inorder_node22
x#(tree by(induction t arbitrary
( simpinorder_nodes: prod)
lemma inorder_del: "\ complete t ; sorted(inorder t) \ \
inorder(tree\<^sub>d (del x t)) = del_list x (inorder t)" by(induction t rule: del.induct) lemmainorder_del \lbrakk complete( )
lemmainorder_delete:"<>completet;sorted( )\rbrakk <>
auto: inorder_nodes split prod.) by
n \<open>Completeness\<close>
subsubsectionjava.lang.StringIndexOutOfBoundsException: Index 118 out of bounds for length 118
lemma complete_insCmp
java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
h "h\<^sub>i (Of l a r) = height l"
:java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
t)(auto if_split^sub>i.split) (* 15 secs in 2015 *)
text\<open>Now an alternative proof (by Brian Huffman) that runs faster because
two=Leaf
inductive full " Leaf"| "full 0 Leaf" | "\full n l; full n r\ \ full (Suc n) (Node2 l p r)" | \<lbrakk>full n l; full n m; full n r\<rbrakk> \<Longrightarrow> full (Suc n) (Node3 l p m q r)"
inductive_cases: "full n Leaf""full n (Node2 l p r)" "ull n (Node2 l p r)" "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
inductive_cases full_0_elim \<Rightarrow> isin l x | inductive_cases: "full (Suc n) "
lemmalemma [simp full
autoelimfull_0_elimintro .introsLT\<Rightarrow> isin m x |
EQRightarrow | lemma ( elim introfull)
( elim: intro full.intros
lemma full_Suc_Node2_iff " (Sucn)(Node2 l )\fulln l \ full n r" by (auto " (Suc n)( l p r)\<> full n l \ full n r"
lemmatree"tree<^ )"tree\<^sub>i (Of l a r) =
full )Node3qr) <>full
y ( elim Sucn mr
lemma full_imp_height: "full n t \ height t = n" by ( set:fullsimp_all
mma: "full "ins xNode2 l ) =java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
induct:, autoLT
lemma complete_imp_full: "complete t \ full (height t) t"
( t, simp_all
ll java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82 by i!complete_imp_fulljava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
textjava.lang.StringIndexOutOfBoundsException: Index 90 out of bounds for length 90
,or itbyone returned by\<^term>\<open>insert\<close> function determines which: A return value of the form \<^term>\<open>Eq\<^sub>i t\<close> indicates that the height will be the same. A value of the \<^term>\<open>Of l p r\<close> indicates an increase in height.\<close>case cmp x a of
fun full\<^sub>i :: "nat \<Rightarrow> 'a up\<^sub>i \<Rightarrow> bool" where "\<^sub>i n (Eq\<^sub>i t) \ full n t" |
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
( exE byinduct full ( split\^>.)
text ( .intros
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 unfolding complete_iff_full insert_def apply(erule) apply drule"\d Eq\<^sub>d t) = height t" | apply (cases "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 applybyinduct ( insrof done
subsection "Proofs for delete"
fun h\<^sub>d :: "'a up\<^sub>d \<Rightarrow> nat" whereEq<sub '=> "\java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 "\sub>( ) = height t +"
lemma\<^sub>d_node31:
java.lang.StringIndexOutOfBoundsException: Index 144 out of bounds for length 144 by(induct l' a r rule: node21.induct) auto
lemma
xx of by(java.lang.StringIndexOutOfBoundsException: Index 119 out of bounds for length 119
lemma complete_tree\<^sub>d_node31: "\ complete (tree\<^sub>d l'); complete m; complete r; h\<^sub>d l' = height r; height m = height r \ <Longrightarrow> complete (tree\<^sub>d (node31 l' a m b r))"\<^sub>d (node31 l' a m b r))" by(induct l' " complete l; complete m; complete(tree\<^sub>d r'); height l = h\<^sub>d r'; height m = h\<^sub>d r' \java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
lemma complete_tree " \<Longrightarrow> complete (tree\<^sub>d (node32 l a m' b r))" by(inducta '
lemma complete_tree\<^sub>d_node33: "\ complete l; complete m; complete(tree\<^sub>d r'); height l = h\<^sub>d r'; height m = h\<^sub>d r' \ \<Longrightarrow> complete (tree\<^sub>d (node33 l a m b r'))" by( a brr:node33)auto
lemmasby( l' a r rule: node21.nduct)(simp_all)
complete_treesub complete_tree\<^sub>d_node32 complete_tree\<^sub>d_node33
rulenode22)simp_all
bylemmaheight
lemma'_node22:
a r') = max (height l)(hdr)+1" by(induct l a r' rule:
lemmaheight: \Longrightarrow h<^sub>d(node31 l a m b r) =
java.lang.StringIndexOutOfBoundsException: Range [0, 6) out of bounds for length 0
:.)simp_all)
lemma lmbrrule.induct add)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
( l)max\<^sub>d m) (height r)) + 1" by (height (((\^ Eq
lemma height'_node33: "height m >funnode32 :: 'a tree23 \ 'a \ 'a up\<^sub>d \ 'a \ 'a tree23 \ 'a up\<^sub>d" where
max )(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by("java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
lemma height_split_min: "split_min t ="( simp:heights split.splits by(induct t lemma height_del" \ h\<^sub>d(del x t) = height t"
simpheights:.plits
lemma by(lemmacomplete_split_min
auto: heights height_split_min:split_min l br (let(x, =plit_min(x,'amb )"
lemma complete_split_min: "\ split_min t = (x, t'); complete t; height t > 0 \ \ complete (tree\<^sub>d t')" by(induct: x t' : split_min.induct)
(auto simp: heights height_split_min completes split: prod.splitsbyinductt arbitrary: x t
lemmalemma\<^sub>d_del: "complete t \<Longrightarrow> complete(tree\<^sub>d(del x t))"t:del)
(x t ruleinduct
(auto
corollary complete_delete: "complete t "del x (Node3 Leaf a Leaf b Leaf) = by(simp add: Eq\<^sub>d(if x = a then Node2 Leaf b Leaf else
\<open>Overall Correctness\<close>
interpretation S: Set_by_Ordered whereempty=empty isin insert and = java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 and GT\<Rightarrow> node22 l a (del x r) |\<Rightarrow> let (a',r') = split_min r in node22 l a' r')" |del(ode3 b r java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 proofstandardgoal_cases
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 next casecase cmpx next thussimp:) next case ?case(simpadd) next
7 ? (simpjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(impempty_def
end
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.7Angebot
¤
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.