Additional lemmas for Red-black trees #
Equations
A cut is like a homomorphism of orderings: it is a monotonic predicate with respect to cmp
,
but it can make things that are distinguished by cmp
equal.
This is sufficient for find?
to locate an element on which cut
returns .eq
,
but there may be other elements, not returned by find?
, on which cut
also returns .eq
.
- le_lt_trans {x y : α} [Batteries.TransCmp cmp] : cmp x y ≠ Ordering.gt → cut x = Ordering.lt → cut y = Ordering.lt
The set
{x | cut x = .lt}
is downward-closed. - le_gt_trans {x y : α} [Batteries.TransCmp cmp] : cmp x y ≠ Ordering.gt → cut y = Ordering.gt → cut x = Ordering.gt
The set
{x | cut x = .gt}
is upward-closed.
Instances
IsStrictCut
upgrades the IsCut
property to ensure that at most one element of the tree
can match the cut, and hence find?
will return the unique such element if one exists.
- le_lt_trans {x y : α} [Batteries.TransCmp cmp] : cmp x y ≠ Ordering.gt → cut x = Ordering.lt → cut y = Ordering.lt
- le_gt_trans {x y : α} [Batteries.TransCmp cmp] : cmp x y ≠ Ordering.gt → cut y = Ordering.gt → cut x = Ordering.gt
If
cut = x
, thencut
andx
have compare the same with respect to other elements.
Instances
A "representable cut" is one generated by cmp a
for some a
. This is always a valid cut.
Auxiliary definition for zoom_ins
: set the root of the tree to v
, creating a node if necessary.
Equations
- Batteries.RBNode.setRoot v Batteries.RBNode.nil = Batteries.RBNode.node Batteries.RBColor.red Batteries.RBNode.nil v Batteries.RBNode.nil
- Batteries.RBNode.setRoot v (Batteries.RBNode.node c a v_1 b) = Batteries.RBNode.node c a v b
Instances For
Auxiliary definition for zoom_ins
: set the root of the tree to v
, creating a node if necessary.
Equations
- Batteries.RBNode.nil.delRoot = Batteries.RBNode.nil
- (Batteries.RBNode.node c a v b).delRoot = a.append b
Instances For
The value x
returned by upperBound?
is greater or equal to the cut
.
The value x
returned by upperBound?
is greater or equal to the cut
.
The value x
returned by lowerBound?
is less or equal to the cut
.
The value x
returned by lowerBound?
is less or equal to the cut
.
A statement of the least-ness of the result of upperBound?
. If x
is the return value of
upperBound?
and it is strictly greater than the cut, then any other y < x
in the tree is in fact
strictly less than the cut (so there is no exact match, and nothing closer to the cut).
A statement of the greatest-ness of the result of lowerBound?
. If x
is the return value of
lowerBound?
and it is strictly less than the cut, then any other y > x
in the tree is in fact
strictly greater than the cut (so there is no exact match, and nothing closer to the cut).
A stronger version of lowerBound?_greatest
that holds when the cut is strict.
A stronger version of upperBound?_least
that holds when the cut is strict.
The list of elements to the left of the hole. (This function is intended for specification purposes only.)
Equations
- Batteries.RBNode.Path.root.listL = []
- (Batteries.RBNode.Path.left c parent v r).listL = parent.listL
- (Batteries.RBNode.Path.right c l v parent).listL = parent.listL ++ (l.toList ++ [v])
Instances For
The list of elements to the right of the hole. (This function is intended for specification purposes only.)
Equations
- Batteries.RBNode.Path.root.listR = []
- (Batteries.RBNode.Path.left c parent v r).listR = v :: r.toList ++ parent.listR
- (Batteries.RBNode.Path.right c l v parent).listR = parent.listR
Instances For
Wraps a list of elements with the left and right elements of the path.
Instances For
Asserts that p
holds on all elements to the left of the hole.
Equations
- Batteries.RBNode.Path.AllL p Batteries.RBNode.Path.root = True
- Batteries.RBNode.Path.AllL p (Batteries.RBNode.Path.left c parent v r) = Batteries.RBNode.Path.AllL p parent
- Batteries.RBNode.Path.AllL p (Batteries.RBNode.Path.right c l v parent) = (Batteries.RBNode.All p l ∧ p v ∧ Batteries.RBNode.Path.AllL p parent)
Instances For
Asserts that p
holds on all elements to the right of the hole.
Equations
- Batteries.RBNode.Path.AllR p Batteries.RBNode.Path.root = True
- Batteries.RBNode.Path.AllR p (Batteries.RBNode.Path.left c parent v r) = (Batteries.RBNode.Path.AllR p parent ∧ p v ∧ Batteries.RBNode.All p r)
- Batteries.RBNode.Path.AllR p (Batteries.RBNode.Path.right c l v parent) = Batteries.RBNode.Path.AllR p parent
Instances For
Equations
- Batteries.RBSet.instDecidableMemOfTransCmp = decidable_of_iff (t.contains x = true) ⋯
The value x
returned by upperBoundP?
is greater or equal to the cut
.
The value y
returned by upperBound? x
is greater or equal to x
.
The value x
returned by lowerBoundP?
is less or equal to the cut
.
The value y
returned by lowerBound? x
is less or equal to x
.
A statement of the least-ness of the result of upperBoundP?
. If x
is the return value of
upperBoundP?
and it is strictly greater than the cut, then any other y < x
in the tree is in
fact strictly less than the cut (so there is no exact match, and nothing closer to the cut).
A statement of the greatest-ness of the result of lowerBoundP?
. If x
is the return value of
lowerBoundP?
and it is strictly less than the cut, then any other y > x
in the tree is in fact
strictly greater than the cut (so there is no exact match, and nothing closer to the cut).
A stronger version of upperBoundP?_least
that holds when the cut is strict.
A stronger version of lowerBoundP?_greatest
that holds when the cut is strict.
A "representable cut" is one generated by cmp a
for some a
. This is always a valid cut.