# HG changeset patch # User nipkow # Date 1565618260 -7200 # Node ID 8d4abdbc6de9cd82e7f87cff2cee9f4a38d02f04 # Parent f0b2635ee17f7023272df21968013bc9b4274f89 simplified defs (thanks to Mohammad) diff -r f0b2635ee17f -r 8d4abdbc6de9 src/HOL/Data_Structures/Set2_Join_RBT.thy --- a/src/HOL/Data_Structures/Set2_Join_RBT.thy Sun Aug 11 22:36:34 2019 +0200 +++ b/src/HOL/Data_Structures/Set2_Join_RBT.thy Mon Aug 12 15:57:40 2019 +0200 @@ -20,7 +20,7 @@ \ fun joinL :: "'a rbt \ 'a \ 'a rbt \ 'a rbt" where "joinL l x r = - (if bheight l = bheight r then R l x r + (if bheight l \ bheight r then R l x r else case r of B l' x' r' \ baliL (joinL l x l') x' r' | R l' x' r' \ R (joinL l x l') x' r')" @@ -43,31 +43,6 @@ declare joinL.simps[simp del] declare joinR.simps[simp del] -text \ -One would expect \<^const>\joinR\ to be be completely dual to \<^const>\joinL\. -Thus the condition should be \<^prop>\bheight l = bheight r\. What we have done -is totalize the function. On the intended domain (\<^prop>\bheight l \ bheight r\) -the two versions behave exactly the same, including complexity. Thus from a programmer's -perspective they are equivalent. However, not from a verifier's perspective: -the total version of \<^const>\joinR\ is easier -to reason about because lemmas about it may not require preconditions. In particular -\<^prop>\set_tree (joinR l x r) = set_tree l \ {x} \ set_tree r\ -is provable outright and hence also -\<^prop>\set_tree (join l x r) = set_tree l \ {x} \ set_tree r\. -This is necessary because locale \<^locale>\Set2_Join\ unconditionally assumes -exactly that. Adding preconditions to this assumptions significantly complicates -the proofs within \<^locale>\Set2_Join\, which we want to avoid. - -Why not work with the partial version of \<^const>\joinR\ and add the precondition -\<^prop>\bheight l \ bheight r\ to lemmas about \<^const>\joinR\? After all, that is how -we worked with \<^const>\joinL\, and \<^const>\join\ ensures that \<^const>\joinL\ and \<^const>\joinR\ -are only called under the respective precondition. But function \<^const>\bheight\ -makes the difference: it descends along the left spine, just like \<^const>\joinL\. -Function \<^const>\joinR\, however, descends along the right spine and thus \<^const>\bheight\ -may change all the time. Thus we would need the further precondition \<^prop>\invh l\. -This is what we really wanted to avoid in order to satisfy the unconditional assumption -in \<^locale>\Set2_Join\. -\ subsection "Properties"