File: .lake/packages/batteries/Batteries/Data/RBMap/Basic.lean

full_name: Batteries.RBColor.black
code: /--
In a red-black tree, every node has a color which is either "red" or "black"
(this particular choice of colors is conventional). A nil node is considered black.
-/
inductive RBColor where
  /-- A red node is required to have black children. -/
  | red
  /-- Every path from the root to a leaf must pass through the same number of black nodes. -/
  | black
  deriving Repr
goal: Batteries.RBColor

full_name: Batteries.RBColor
code: /--
In a red-black tree, every node has a color which is either "red" or "black"
(this particular choice of colors is conventional). A nil node is considered black.
-/
inductive RBColor where
  /-- A red node is required to have black children. -/
  | red
  /-- Every path from the root to a leaf must pass through the same number of black nodes. -/
  | black
  deriving Repr
goal: Type

full_name: Batteries.instReprRBColor
code: /--
In a red-black tree, every node has a color which is either "red" or "black"
(this particular choice of colors is conventional). A nil node is considered black.
-/
inductive RBColor where
  /-- A red node is required to have black children. -/
  | red
  /-- Every path from the root to a leaf must pass through the same number of black nodes. -/
  | black
  deriving Repr
goal: Repr Batteries.RBColor

full_name: Batteries.RBColor.red
code: /--
In a red-black tree, every node has a color which is either "red" or "black"
(this particular choice of colors is conventional). A nil node is considered black.
-/
inductive RBColor where
  /-- A red node is required to have black children. -/
  | red
  /-- Every path from the root to a leaf must pass through the same number of black nodes. -/
  | black
  deriving Repr
goal: Batteries.RBColor

full_name: Batteries.RBNode.node
code: /--
A red-black tree. (This is an internal implementation detail of the `RBSet` type,
which includes the invariants of the tree.) This is a binary search tree augmented with
a "color" field which is either red or black for each node and used to implement
the re-balancing operations.
See: [Red–black tree](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree)
-/
inductive RBNode (α : Type u) where
  /-- An empty tree. -/
  | nil
  /-- A node consists of a value `v`, a subtree `l` of smaller items,
  and a subtree `r` of larger items. The color `c` is either `red` or `black`
  and participates in the red-black balance invariant (see `Balanced`). -/
  | node (c : RBColor) (l : RBNode α) (v : α) (r : RBNode α)
  deriving Repr
goal: Batteries.RBNode α

full_name: Batteries.RBNode
code: /--
A red-black tree. (This is an internal implementation detail of the `RBSet` type,
which includes the invariants of the tree.) This is a binary search tree augmented with
a "color" field which is either red or black for each node and used to implement
the re-balancing operations.
See: [Red–black tree](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree)
-/
inductive RBNode (α : Type u) where
  /-- An empty tree. -/
  | nil
  /-- A node consists of a value `v`, a subtree `l` of smaller items,
  and a subtree `r` of larger items. The color `c` is either `red` or `black`
  and participates in the red-black balance invariant (see `Balanced`). -/
  | node (c : RBColor) (l : RBNode α) (v : α) (r : RBNode α)
  deriving Repr
goal: Type u

full_name: Batteries.RBNode.nil
code: /--
A red-black tree. (This is an internal implementation detail of the `RBSet` type,
which includes the invariants of the tree.) This is a binary search tree augmented with
a "color" field which is either red or black for each node and used to implement
the re-balancing operations.
See: [Red–black tree](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree)
-/
inductive RBNode (α : Type u) where
  /-- An empty tree. -/
  | nil
  /-- A node consists of a value `v`, a subtree `l` of smaller items,
  and a subtree `r` of larger items. The color `c` is either `red` or `black`
  and participates in the red-black balance invariant (see `Balanced`). -/
  | node (c : RBColor) (l : RBNode α) (v : α) (r : RBNode α)
  deriving Repr
goal: Batteries.RBNode α

full_name: Batteries.instReprRBNode
code: /--
A red-black tree. (This is an internal implementation detail of the `RBSet` type,
which includes the invariants of the tree.) This is a binary search tree augmented with
a "color" field which is either red or black for each node and used to implement
the re-balancing operations.
See: [Red–black tree](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree)
-/
inductive RBNode (α : Type u) where
  /-- An empty tree. -/
  | nil
  /-- A node consists of a value `v`, a subtree `l` of smaller items,
  and a subtree `r` of larger items. The color `c` is either `red` or `black`
  and participates in the red-black balance invariant (see `Balanced`). -/
  | node (c : RBColor) (l : RBNode α) (v : α) (r : RBNode α)
  deriving Repr
goal: {α : Type u_1} → [inst : Repr α] → Repr (Batteries.RBNode α)

full_name: Batteries.RBNode.instEmptyCollection
code: instance : EmptyCollection (RBNode α) 
goal: EmptyCollection (Batteries.RBNode α)

full_name: Batteries.RBNode.min?
code: /-- The minimum element of a tree is the left-most value. -/
protected def min? : RBNode α → Option α
  
goal: Batteries.RBNode α → Option α

full_name: Batteries.RBNode.max?
code: /-- The maximum element of a tree is the right-most value. -/
protected def max? : RBNode α → Option α
  
goal: Batteries.RBNode α → Option α

full_name: Batteries.RBNode.fold
code: /--
Fold a function in tree order along the nodes. `v₀` is used at `nil` nodes and
`f` is used to combine results at branching nodes.
-/
@[specialize] def fold (v₀ : σ) (f : σ → α → σ → σ) : RBNode α → σ
  
goal: Batteries.RBNode α → σ

full_name: Batteries.RBNode.foldl
code: /-- Fold a function on the values from left to right (in increasing order). -/
@[specialize] def foldl (f : σ → α → σ) : (init : σ) → RBNode α → σ
  
goal: Batteries.RBNode α → σ

full_name: Batteries.RBNode.foldr
code: /-- Fold a function on the values from right to left (in decreasing order). -/
@[specialize] def foldr (f : α → σ → σ) : RBNode α → (init : σ) → σ
  
goal: Batteries.RBNode α → σ → σ

full_name: Batteries.RBNode.toList
code: /-- `O(n)`. Convert the tree to a list in ascending order. -/
def toList (t : RBNode α) : List α 
goal: List α

full_name: Batteries.RBNode.forM
code: /-- Run monadic function `f` on each element of the tree (in increasing order). -/
@[specialize] def forM [Monad m] (f : α → m PUnit) : RBNode α → m PUnit
  
goal: Batteries.RBNode α → m PUnit

full_name: Batteries.RBNode.foldlM
code: /-- Fold a monadic function on the values from left to right (in increasing order). -/
@[specialize] def foldlM [Monad m] (f : σ → α → m σ) : (init : σ) → RBNode α → m σ
  
goal: Batteries.RBNode α → m σ

full_name: Batteries.RBNode.forIn
code: /-- Implementation of `for x in t` loops over a `RBNode` (in increasing order). -/
@[inline] protected def forIn [Monad m]
    (as : RBNode α) (init : σ) (f : α → σ → m (ForInStep σ)) : m σ 
goal: m σ

full_name: Batteries.RBNode.forIn.visit
code: /-- Implementation of `for x in t` loops over a `RBNode` (in increasing order). -/
@[inline] protected def forIn [Monad m]
    (as : RBNode α) (init : σ) (f : α → σ → m (ForInStep σ)) : m σ 
goal: Batteries.RBNode α → σ → m (ForInStep σ)

full_name: Batteries.RBNode.instForIn
code: instance : ForIn m (RBNode α) α 
goal: ForIn m (Batteries.RBNode α) α

full_name: Batteries.RBNode.Stream
code: /--
An auxiliary data structure (an iterator) over an `RBNode` which lazily
pulls elements from the left.
-/
protected inductive Stream (α : Type _)
  /-- The stream is empty. -/
  | nil
  /-- We are ready to deliver element `v` with right child `r`,
  and where `tail` represents all the subtrees we have yet to destructure. -/
  | cons (v : α) (r : RBNode α) (tail : RBNode.Stream α)
goal: Type u_1

full_name: Batteries.RBNode.Stream.nil
code: /--
An auxiliary data structure (an iterator) over an `RBNode` which lazily
pulls elements from the left.
-/
protected inductive Stream (α : Type _)
  /-- The stream is empty. -/
  | nil
  /-- We are ready to deliver element `v` with right child `r`,
  and where `tail` represents all the subtrees we have yet to destructure. -/
  | cons (v : α) (r : RBNode α) (tail : RBNode.Stream α)
goal: Batteries.RBNode.Stream α

full_name: Batteries.RBNode.Stream.cons
code: /--
An auxiliary data structure (an iterator) over an `RBNode` which lazily
pulls elements from the left.
-/
protected inductive Stream (α : Type _)
  /-- The stream is empty. -/
  | nil
  /-- We are ready to deliver element `v` with right child `r`,
  and where `tail` represents all the subtrees we have yet to destructure. -/
  | cons (v : α) (r : RBNode α) (tail : RBNode.Stream α)
goal: Batteries.RBNode.Stream α

full_name: Batteries.RBNode.toStream
code: /-- `O(log n)`. Turn a node into a stream, by descending along the left spine. -/
def toStream : RBNode α → (_ : RBNode.Stream α := .nil) → RBNode.Stream α
  
goal: Batteries.RBNode α → optParam (Batteries.RBNode.Stream α) Batteries.RBNode.Stream.nil → Batteries.RBNode.Stream α

full_name: Batteries.RBNode.Stream.next?
code: /-- `O(1)` amortized, `O(log n)` worst case: Get the next element from the stream. -/
def next? : RBNode.Stream α → Option (α × RBNode.Stream α)
  
goal: Batteries.RBNode.Stream α → Option (α × Batteries.RBNode.Stream α)

full_name: Batteries.RBNode.Stream.foldl
code: /-- Fold a function on the values from left to right (in increasing order). -/
@[specialize] def foldl (f : σ → α → σ) : (init : σ) → RBNode.Stream α → σ
  
goal: Batteries.RBNode.Stream α → σ

full_name: Batteries.RBNode.Stream.foldr
code: /-- Fold a function on the values from right to left (in decreasing order). -/
@[specialize] def foldr (f : α → σ → σ) : RBNode.Stream α → (init : σ) → σ
  
goal: Batteries.RBNode.Stream α → σ → σ

full_name: Batteries.RBNode.Stream.toList
code: /-- `O(n)`. Convert the stream to a list in ascending order. -/
def toList (t : RBNode.Stream α) : List α 
goal: List α

full_name: Batteries.RBNode.instToStreamStream
code: instance : ToStream (RBNode α) (RBNode.Stream α) 
goal: ToStream (Batteries.RBNode α) (Batteries.RBNode.Stream α)

full_name: Batteries.RBNode.instStreamStream
code: instance : Stream (RBNode.Stream α) α 
goal: Stream (Batteries.RBNode.Stream α) α

full_name: Batteries.RBNode.all
code: /-- Returns `true` iff every element of the tree satisfies `p`. -/
@[specialize] def all (p : α → Bool) : RBNode α → Bool
  
goal: Batteries.RBNode α → Bool

full_name: Batteries.RBNode.any
code: /-- Returns `true` iff any element of the tree satisfies `p`. -/
@[specialize] def any (p : α → Bool) : RBNode α → Bool
  
goal: Batteries.RBNode α → Bool

full_name: Batteries.RBNode.All
code: /-- Asserts that `p` holds on every element of the tree. -/
def All (p : α → Prop) : RBNode α → Prop
  
goal: Batteries.RBNode α → Prop

full_name: Batteries.RBNode.All.imp
code: theorem All.imp (H : ∀ {x : α}, p x → q x) : ∀ {t : RBNode α}, t.All p → t.All q
  
goal: Batteries.RBNode.All p t → Batteries.RBNode.All q t

full_name: Batteries.RBNode.all_iff
code: theorem all_iff {t : RBNode α} : t.all p ↔ t.All (p ·) 
goal: Batteries.RBNode.all p t = true ↔ Batteries.RBNode.All (fun x => p x = true) t

full_name: Batteries.RBNode.instDecidableAllOfDecidablePred
code: instance {t : RBNode α} [DecidablePred p] : Decidable (t.All p) 
goal: Decidable (Batteries.RBNode.All p t)

full_name: Batteries.RBNode.Any
code: /-- Asserts that `p` holds on some element of the tree. -/
def Any (p : α → Prop) : RBNode α → Prop
  
goal: Batteries.RBNode α → Prop

full_name: Batteries.RBNode.any_iff
code: theorem any_iff {t : RBNode α} : t.any p ↔ t.Any (p ·) 
goal: Batteries.RBNode.any p t = true ↔ Batteries.RBNode.Any (fun x => p x = true) t

full_name: Batteries.RBNode.instDecidableAnyOfDecidablePred
code: instance {t : RBNode α} [DecidablePred p] : Decidable (t.Any p) 
goal: Decidable (Batteries.RBNode.Any p t)

full_name: Batteries.RBNode.EMem
code: /-- True if `x` is an element of `t` "exactly", i.e. up to equality, not the `cmp` relation. -/
def EMem (x : α) (t : RBNode α) : Prop 
goal: Prop

full_name: Batteries.RBNode.instMembership
code: instance : Membership α (RBNode α) 
goal: Membership α (Batteries.RBNode α)

full_name: Batteries.RBNode.MemP
code: /-- True if the specified `cut` matches at least one element of of `t`. -/
def MemP (cut : α → Ordering) (t : RBNode α) : Prop 
goal: Prop

full_name: Batteries.RBNode.Mem
code: /-- True if `x` is equivalent to an element of `t`. -/
@[reducible] def Mem (cmp : α → α → Ordering) (x : α) (t : RBNode α) : Prop 
goal: Prop

full_name: Batteries.RBNode.Slow.instDecidableEMem
code: @[nolint docBlame] scoped instance Slow.instDecidableEMem [DecidableEq α] {t : RBNode α} :
    Decidable (EMem x t) 
goal: Decidable (Batteries.RBNode.EMem x t)

full_name: Batteries.RBNode.Slow.instDecidableMemP
code: @[nolint docBlame] scoped instance Slow.instDecidableMemP {t : RBNode α} :
    Decidable (MemP cut t) 
goal: Decidable (Batteries.RBNode.MemP cut t)

full_name: Batteries.RBNode.Slow.instDecidableMem
code: @[nolint docBlame] scoped instance Slow.instDecidableMem {t : RBNode α} :
    Decidable (Mem cmp x t) 
goal: Decidable (Batteries.RBNode.Mem cmp x t)

full_name: Batteries.RBNode.all₂
code: /--
Asserts that `t₁` and `t₂` have the same number of elements in the same order,
and `R` holds pairwise between them. The tree structure is ignored.
-/
@[specialize] def all₂ (R : α → β → Bool) (t₁ : RBNode α) (t₂ : RBNode β) : Bool 
goal: Bool

full_name: Batteries.RBNode.instBEq
code: instance [BEq α] : BEq (RBNode α) 
goal: BEq (Batteries.RBNode α)

full_name: Batteries.RBNode.cmpLT
code: /--
We say that `x < y` under the comparator `cmp` if `cmp x y = .lt`.

* In order to avoid assuming the comparator is always lawful, we use a
  local `∀ [TransCmp cmp]` binder in the relation so that the ordering
  properties of the tree only need to hold if the comparator is lawful.
* The `Nonempty` wrapper is a no-op because this is already a proposition,
  but it prevents the `[TransCmp cmp]` binder from being introduced when we don't want it.
-/
def cmpLT (cmp : α → α → Ordering) (x y : α) : Prop 
goal: Prop

full_name: Batteries.RBNode.cmpLT_iff
code: theorem cmpLT_iff [TransCmp cmp] : cmpLT cmp x y ↔ cmp x y = .lt 
goal: ∀ {α : Sort u_1} {cmp : α → α → Ordering} {x y : α} [inst : Batteries.TransCmp cmp],
  Batteries.RBNode.cmpLT cmp x y ↔ cmp x y = Ordering.lt

full_name: Batteries.RBNode.instDecidableCmpLTOfTransCmp
code: instance (cmp) [TransCmp cmp] : Decidable (cmpLT cmp x y) 
goal: {α : Sort u_1} →
  {x y : α} → (cmp : α → α → Ordering) → [inst : Batteries.TransCmp cmp] → Decidable (Batteries.RBNode.cmpLT cmp x y)

full_name: Batteries.RBNode.cmpEq
code: /-- We say that `x ≈ y` under the comparator `cmp` if `cmp x y = .eq`. See also `cmpLT`. -/
def cmpEq (cmp : α → α → Ordering) (x y : α) : Prop 
goal: Prop

full_name: Batteries.RBNode.cmpEq_iff
code: theorem cmpEq_iff [TransCmp cmp] : cmpEq cmp x y ↔ cmp x y = .eq 
goal: ∀ {α : Sort u_1} {cmp : α → α → Ordering} {x y : α} [inst : Batteries.TransCmp cmp],
  Batteries.RBNode.cmpEq cmp x y ↔ cmp x y = Ordering.eq

full_name: Batteries.RBNode.instDecidableCmpEqOfTransCmp
code: instance (cmp) [TransCmp cmp] : Decidable (cmpEq cmp x y) 
goal: {α : Sort u_1} →
  {x y : α} → (cmp : α → α → Ordering) → [inst : Batteries.TransCmp cmp] → Decidable (Batteries.RBNode.cmpEq cmp x y)

full_name: Batteries.RBNode.isOrdered
code: /-- `O(n)`. Verifies an ordering relation on the nodes of the tree. -/
def isOrdered (cmp : α → α → Ordering)
    (t : RBNode α) (l : Option α := none) (r : Option α := none) : Bool 
goal: Bool

full_name: Batteries.RBNode.balance1
code: /-- The first half of Okasaki's `balance`, concerning red-red sequences in the left child. -/
@[inline] def balance1 : RBNode α → α → RBNode α → RBNode α
  
goal: Batteries.RBNode α → α → Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.balance2
code: /-- The second half of Okasaki's `balance`, concerning red-red sequences in the right child. -/
@[inline] def balance2 : RBNode α → α → RBNode α → RBNode α
  
goal: Batteries.RBNode α → α → Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.isRed
code: /-- Returns `red` if the node is red, otherwise `black`. (Nil nodes are treated as `black`.) -/
@[inline] def isRed : RBNode α → RBColor
  
goal: Batteries.RBNode α → Batteries.RBColor

full_name: Batteries.RBNode.isBlack
code: /--
Returns `black` if the node is black, otherwise `red`.
(Nil nodes are treated as `red`, which is not the usual convention but useful for deletion.)
-/
@[inline] def isBlack : RBNode α → RBColor
  
goal: Batteries.RBNode α → Batteries.RBColor

full_name: Batteries.RBNode.setBlack
code: /-- Changes the color of the root to `black`. -/
def setBlack : RBNode α → RBNode α
  
goal: Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.reverse
code: /-- `O(n)`. Reverses the ordering of the tree without any rebalancing. -/
@[simp] def reverse : RBNode α → RBNode α
  
goal: Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.ins
code: /--
The core of the `insert` function. This adds an element `x` to a balanced red-black tree.
Importantly, the result of calling `ins` is not a proper red-black tree,
because it has a broken balance invariant.
(See `Balanced.ins` for the balance invariant of `ins`.)
The `insert` function does the final fixup needed to restore the invariant.
-/
@[specialize] def ins (cmp : α → α → Ordering) (x : α) : RBNode α → RBNode α
  
goal: Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.insert
code: /--
`insert cmp t v` inserts element `v` into the tree, using the provided comparator
`cmp` to put it in the right place and automatically rebalancing the tree as necessary.
-/
@[specialize] def insert (cmp : α → α → Ordering) (t : RBNode α) (v : α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.setRed
code: /-- Recolor the root of the tree to `red` if possible. -/
def setRed : RBNode α → RBNode α
  
goal: Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.balLeft
code: /-- Rebalancing a tree which has shrunk on the left. -/
def balLeft (l : RBNode α) (v : α) (r : RBNode α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.balRight
code: /-- Rebalancing a tree which has shrunk on the right. -/
def balRight (l : RBNode α) (v : α) (r : RBNode α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.size
code: /-- The number of nodes in the tree. -/
@[simp] def size : RBNode α → Nat
  
goal: Batteries.RBNode α → Nat

full_name: Batteries.RBNode.append
code: /-- Concatenate two trees with the same black-height. -/
def append : RBNode α → RBNode α → RBNode α
  
goal: Batteries.RBNode α → Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.del
code: /--
The core of the `erase` function. The tree returned from this function has a broken invariant,
which is restored in `erase`.
-/
@[specialize] def del (cut : α → Ordering) : RBNode α → RBNode α
  
goal: Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.erase
code: /--
The `erase cut t` function removes an element from the tree `t`.
The `cut` function is used to locate an element in the tree:
it returns `.gt` if we go too high and `.lt` if we go too low;
if it returns `.eq` we will remove the element.
(The function `cmp k` for some key `k` is a valid cut function, but we can also use cuts that
are not of this form as long as they are suitably monotonic.)
-/
@[specialize] def erase (cut : α → Ordering) (t : RBNode α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.find?
code: /-- Finds an element in the tree satisfying the `cut` function. -/
@[specialize] def find? (cut : α → Ordering) : RBNode α → Option α
  
goal: Batteries.RBNode α → Option α

full_name: Batteries.RBNode.upperBound?
code: /-- `upperBound? cut` retrieves the smallest entry larger than or equal to `cut`, if it exists. -/
@[specialize] def upperBound? (cut : α → Ordering) : RBNode α → (ub : Option α := .none) → Option α
  
goal: Batteries.RBNode α → optParam (Option α) none → Option α

full_name: Batteries.RBNode.lowerBound?
code: /-- `lowerBound? cut` retrieves the largest entry smaller than or equal to `cut`, if it exists. -/
@[specialize] def lowerBound? (cut : α → Ordering) : RBNode α → (lb : Option α := .none) → Option α
  
goal: Batteries.RBNode α → optParam (Option α) none → Option α

full_name: Batteries.RBNode.root?
code: /-- Returns the root of the tree, if any. -/
def root? : RBNode α → Option α
  
goal: Batteries.RBNode α → Option α

full_name: Batteries.RBNode.map
code: /--
`O(n)`. Map a function on every value in the tree.
This requires `IsMonotone` on the function in order to preserve the order invariant.
-/
@[specialize] def map (f : α → β) : RBNode α → RBNode β
  
goal: Batteries.RBNode α → Batteries.RBNode β

full_name: Batteries.RBNode.toArray
code: /-- Converts the tree into an array in increasing sorted order. -/
def toArray (n : RBNode α) : Array α 
goal: Array α

full_name: Batteries.RBNode.Path.root
code: /--
A `RBNode.Path α` is a "cursor" into an `RBNode` which represents the path
from the root to a subtree. Note that the path goes from the target subtree
up to the root, which is reversed from the normal way data is stored in the tree.
See [Zipper](https://en.wikipedia.org/wiki/Zipper_(data_structure)) for more information.
-/
inductive Path (α : Type u) where
  /-- The root of the tree, which is the end of the path of parents. -/
  | root
  /-- A path that goes down the left subtree. -/
  | left (c : RBColor) (parent : Path α) (v : α) (r : RBNode α)
  /-- A path that goes down the right subtree. -/
  | right (c : RBColor) (l : RBNode α) (v : α) (parent : Path α)
goal: Batteries.RBNode.Path α

full_name: Batteries.RBNode.Path
code: /--
A `RBNode.Path α` is a "cursor" into an `RBNode` which represents the path
from the root to a subtree. Note that the path goes from the target subtree
up to the root, which is reversed from the normal way data is stored in the tree.
See [Zipper](https://en.wikipedia.org/wiki/Zipper_(data_structure)) for more information.
-/
inductive Path (α : Type u) where
  /-- The root of the tree, which is the end of the path of parents. -/
  | root
  /-- A path that goes down the left subtree. -/
  | left (c : RBColor) (parent : Path α) (v : α) (r : RBNode α)
  /-- A path that goes down the right subtree. -/
  | right (c : RBColor) (l : RBNode α) (v : α) (parent : Path α)
goal: Type u

full_name: Batteries.RBNode.Path.left
code: /--
A `RBNode.Path α` is a "cursor" into an `RBNode` which represents the path
from the root to a subtree. Note that the path goes from the target subtree
up to the root, which is reversed from the normal way data is stored in the tree.
See [Zipper](https://en.wikipedia.org/wiki/Zipper_(data_structure)) for more information.
-/
inductive Path (α : Type u) where
  /-- The root of the tree, which is the end of the path of parents. -/
  | root
  /-- A path that goes down the left subtree. -/
  | left (c : RBColor) (parent : Path α) (v : α) (r : RBNode α)
  /-- A path that goes down the right subtree. -/
  | right (c : RBColor) (l : RBNode α) (v : α) (parent : Path α)
goal: Batteries.RBNode.Path α

full_name: Batteries.RBNode.Path.right
code: /--
A `RBNode.Path α` is a "cursor" into an `RBNode` which represents the path
from the root to a subtree. Note that the path goes from the target subtree
up to the root, which is reversed from the normal way data is stored in the tree.
See [Zipper](https://en.wikipedia.org/wiki/Zipper_(data_structure)) for more information.
-/
inductive Path (α : Type u) where
  /-- The root of the tree, which is the end of the path of parents. -/
  | root
  /-- A path that goes down the left subtree. -/
  | left (c : RBColor) (parent : Path α) (v : α) (r : RBNode α)
  /-- A path that goes down the right subtree. -/
  | right (c : RBColor) (l : RBNode α) (v : α) (parent : Path α)
goal: Batteries.RBNode.Path α

full_name: Batteries.RBNode.Path.fill
code: /-- Fills the `Path` with a subtree. -/
def Path.fill : Path α → RBNode α → RBNode α
  
goal: Batteries.RBNode.Path α → Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.zoom
code: /--
Like `find?`, but instead of just returning the element, it returns the entire subtree
at the element and a path back to the root for reconstructing the tree.
-/
@[specialize] def zoom (cut : α → Ordering) : RBNode α → (e : Path α := .root) → RBNode α × Path α
  
goal: Batteries.RBNode α →
  optParam (Batteries.RBNode.Path α) Batteries.RBNode.Path.root → Batteries.RBNode α × Batteries.RBNode.Path α

full_name: Batteries.RBNode.Path.ins
code: /--
This function does the second part of `RBNode.ins`,
which unwinds the stack and rebuilds the tree.
-/
def Path.ins : Path α → RBNode α → RBNode α
  
goal: Batteries.RBNode.Path α → Batteries.RBNode α → Batteries.RBNode α

full_name: Batteries.RBNode.Path.insertNew
code: /--
`path.insertNew v` inserts element `v` into the tree, assuming that `path` is zoomed in
on a `nil` node such that inserting a new element at this position is valid.
-/
@[inline] def Path.insertNew (path : Path α) (v : α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.Path.insert
code: /--
`path.insert t v` inserts element `v` into the tree, assuming that `(t, path)` was the result of a
previous `zoom` operation (so either the root of `t` is equivalent to `v` or it is empty).
-/
def Path.insert (path : Path α) (t : RBNode α) (v : α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.Path.del
code: /--
`path.del t c` does the second part of `RBNode.del`, which unwinds the stack
and rebuilds the tree. The `c` argument is the color of the node before the deletion
(we used `t₀.isBlack` for this in `RBNode.del` but the original tree is no longer
available in this formulation).
-/
def Path.del : Path α → RBNode α → RBColor → RBNode α
  
goal: Batteries.RBNode.Path α → Batteries.RBNode α → Batteries.RBColor → Batteries.RBNode α

full_name: Batteries.RBNode.Path.erase
code: /--
`path.erase t v` removes the root element of `t` from the tree, assuming that `(t, path)` was
the result of a previous `zoom` operation.
-/
def Path.erase (path : Path α) (t : RBNode α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.modify
code: /--
`modify cut f t` uses `cut` to find an element,
then modifies the element using `f` and reinserts it into the tree.

Because the tree structure is not modified,
`f` must not modify the ordering properties of the element.

The element in `t` is used linearly if `t` is unshared.
-/
@[specialize] def modify (cut : α → Ordering) (f : α → α) (t : RBNode α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.alter
code: /--
`alter cut f t` simultaneously handles inserting, erasing and replacing an element
using a function `f : Option α → Option α`. It is passed the result of `t.find? cut`
and can either return `none` to remove the element or `some a` to replace/insert
the element with `a` (which must have the same ordering properties as the original element).

The element is used linearly if `t` is unshared.
-/
@[specialize] def alter (cut : α → Ordering) (f : Option α → Option α) (t : RBNode α) : RBNode α 
goal: Batteries.RBNode α

full_name: Batteries.RBNode.Ordered
code: /--
The ordering invariant of a red-black tree, which is a binary search tree.
This says that every element of a left subtree is less than the root, and
every element in the right subtree is greater than the root, where the
less than relation `x < y` is understood to mean `cmp x y = .lt`.

Because we do not assume that `cmp` is lawful when stating this property,
we write it in such a way that if `cmp` is not lawful then the condition holds trivially.
That way we can prove the ordering invariants without assuming `cmp` is lawful.
-/
def Ordered (cmp : α → α → Ordering) : RBNode α → Prop
  
goal: Batteries.RBNode α → Prop

full_name: Batteries.RBNode.Slow.instDecidableOrdered
code: @[nolint docBlame] scoped instance Slow.instDecidableOrdered (cmp) [TransCmp cmp] :
    ∀ t : RBNode α, Decidable (Ordered cmp t)
  
goal: Decidable (Batteries.RBNode.Ordered cmp t)

full_name: Batteries.RBNode.Balanced
code: /--
The red-black balance invariant. `Balanced t c n` says that the color of the root node is `c`,
and the black-height (the number of black nodes on any path from the root) of the tree is `n`.
Additionally, every red node must have black children.
-/
inductive Balanced : RBNode α → RBColor → Nat → Prop where
  /-- A nil node is balanced with black-height 0, and it is considered black. -/
  | protected nil : Balanced nil black 0
  /-- A red node is balanced with black-height `n`
  if its children are both black with with black-height `n`. -/
  | protected red : Balanced x black n → Balanced y black n → Balanced (node red x v y) red n
  /-- A black node is balanced with black-height `n + 1`
  if its children both have black-height `n`. -/
  | protected black : Balanced x c₁ n → Balanced y c₂ n → Balanced (node black x v y) black (n + 1)
goal: Batteries.RBNode α → Batteries.RBColor → Nat → Prop

full_name: Batteries.RBNode.Balanced.black
code: /--
The red-black balance invariant. `Balanced t c n` says that the color of the root node is `c`,
and the black-height (the number of black nodes on any path from the root) of the tree is `n`.
Additionally, every red node must have black children.
-/
inductive Balanced : RBNode α → RBColor → Nat → Prop where
  /-- A nil node is balanced with black-height 0, and it is considered black. -/
  | protected nil : Balanced nil black 0
  /-- A red node is balanced with black-height `n`
  if its children are both black with with black-height `n`. -/
  | protected red : Balanced x black n → Balanced y black n → Balanced (node red x v y) red n
  /-- A black node is balanced with black-height `n + 1`
  if its children both have black-height `n`. -/
  | protected black : Balanced x c₁ n → Balanced y c₂ n → Balanced (node black x v y) black (n + 1)
goal: x.Balanced c₁ n →
  y.Balanced c₂ n → (Batteries.RBNode.node Batteries.RBColor.black x v y).Balanced Batteries.RBColor.black (n + 1)

full_name: Batteries.RBNode.Balanced.red
code: /--
The red-black balance invariant. `Balanced t c n` says that the color of the root node is `c`,
and the black-height (the number of black nodes on any path from the root) of the tree is `n`.
Additionally, every red node must have black children.
-/
inductive Balanced : RBNode α → RBColor → Nat → Prop where
  /-- A nil node is balanced with black-height 0, and it is considered black. -/
  | protected nil : Balanced nil black 0
  /-- A red node is balanced with black-height `n`
  if its children are both black with with black-height `n`. -/
  | protected red : Balanced x black n → Balanced y black n → Balanced (node red x v y) red n
  /-- A black node is balanced with black-height `n + 1`
  if its children both have black-height `n`. -/
  | protected black : Balanced x c₁ n → Balanced y c₂ n → Balanced (node black x v y) black (n + 1)
goal: x.Balanced Batteries.RBColor.black n →
  y.Balanced Batteries.RBColor.black n →
    (Batteries.RBNode.node Batteries.RBColor.red x v y).Balanced Batteries.RBColor.red n

full_name: Batteries.RBNode.Balanced.nil
code: /--
The red-black balance invariant. `Balanced t c n` says that the color of the root node is `c`,
and the black-height (the number of black nodes on any path from the root) of the tree is `n`.
Additionally, every red node must have black children.
-/
inductive Balanced : RBNode α → RBColor → Nat → Prop where
  /-- A nil node is balanced with black-height 0, and it is considered black. -/
  | protected nil : Balanced nil black 0
  /-- A red node is balanced with black-height `n`
  if its children are both black with with black-height `n`. -/
  | protected red : Balanced x black n → Balanced y black n → Balanced (node red x v y) red n
  /-- A black node is balanced with black-height `n + 1`
  if its children both have black-height `n`. -/
  | protected black : Balanced x c₁ n → Balanced y c₂ n → Balanced (node black x v y) black (n + 1)
goal: Batteries.RBNode.nil.Balanced Batteries.RBColor.black 0

full_name: Batteries.RBNode.WF.insert
code: /--
The well-formedness invariant for a red-black tree. The first constructor is the real invariant,
and the others allow us to "cheat" in this file and define `insert` and `erase`,
which have more complex proofs that are delayed to `Batteries.Data.RBMap.Lemmas`.
-/
inductive WF (cmp : α → α → Ordering) : RBNode α → Prop
  /-- The actual well-formedness invariant: a red-black tree has the
  ordering and balance invariants. -/
  | mk : t.Ordered cmp → t.Balanced c n → WF cmp t
  /-- Inserting into a well-formed tree yields another well-formed tree.
  (See `Ordered.insert` and `Balanced.insert` for the actual proofs.) -/
  | insert : WF cmp t → WF cmp (t.insert cmp a)
  /-- Erasing from a well-formed tree yields another well-formed tree.
  (See `Ordered.erase` and `Balanced.erase` for the actual proofs.) -/
  | erase : WF cmp t → WF cmp (t.erase cut)
goal: Batteries.RBNode.WF cmp t → Batteries.RBNode.WF cmp (Batteries.RBNode.insert cmp t a)

full_name: Batteries.RBNode.WF
code: /--
The well-formedness invariant for a red-black tree. The first constructor is the real invariant,
and the others allow us to "cheat" in this file and define `insert` and `erase`,
which have more complex proofs that are delayed to `Batteries.Data.RBMap.Lemmas`.
-/
inductive WF (cmp : α → α → Ordering) : RBNode α → Prop
  /-- The actual well-formedness invariant: a red-black tree has the
  ordering and balance invariants. -/
  | mk : t.Ordered cmp → t.Balanced c n → WF cmp t
  /-- Inserting into a well-formed tree yields another well-formed tree.
  (See `Ordered.insert` and `Balanced.insert` for the actual proofs.) -/
  | insert : WF cmp t → WF cmp (t.insert cmp a)
  /-- Erasing from a well-formed tree yields another well-formed tree.
  (See `Ordered.erase` and `Balanced.erase` for the actual proofs.) -/
  | erase : WF cmp t → WF cmp (t.erase cut)
goal: Batteries.RBNode α → Prop

full_name: Batteries.RBNode.WF.erase
code: /--
The well-formedness invariant for a red-black tree. The first constructor is the real invariant,
and the others allow us to "cheat" in this file and define `insert` and `erase`,
which have more complex proofs that are delayed to `Batteries.Data.RBMap.Lemmas`.
-/
inductive WF (cmp : α → α → Ordering) : RBNode α → Prop
  /-- The actual well-formedness invariant: a red-black tree has the
  ordering and balance invariants. -/
  | mk : t.Ordered cmp → t.Balanced c n → WF cmp t
  /-- Inserting into a well-formed tree yields another well-formed tree.
  (See `Ordered.insert` and `Balanced.insert` for the actual proofs.) -/
  | insert : WF cmp t → WF cmp (t.insert cmp a)
  /-- Erasing from a well-formed tree yields another well-formed tree.
  (See `Ordered.erase` and `Balanced.erase` for the actual proofs.) -/
  | erase : WF cmp t → WF cmp (t.erase cut)
goal: Batteries.RBNode.WF cmp t → Batteries.RBNode.WF cmp (Batteries.RBNode.erase cut t)

full_name: Batteries.RBNode.WF.mk
code: /--
The well-formedness invariant for a red-black tree. The first constructor is the real invariant,
and the others allow us to "cheat" in this file and define `insert` and `erase`,
which have more complex proofs that are delayed to `Batteries.Data.RBMap.Lemmas`.
-/
inductive WF (cmp : α → α → Ordering) : RBNode α → Prop
  /-- The actual well-formedness invariant: a red-black tree has the
  ordering and balance invariants. -/
  | mk : t.Ordered cmp → t.Balanced c n → WF cmp t
  /-- Inserting into a well-formed tree yields another well-formed tree.
  (See `Ordered.insert` and `Balanced.insert` for the actual proofs.) -/
  | insert : WF cmp t → WF cmp (t.insert cmp a)
  /-- Erasing from a well-formed tree yields another well-formed tree.
  (See `Ordered.erase` and `Balanced.erase` for the actual proofs.) -/
  | erase : WF cmp t → WF cmp (t.erase cut)
goal: Batteries.RBNode.Ordered cmp t → t.Balanced c n → Batteries.RBNode.WF cmp t

full_name: Batteries.RBSet
code: /--
An `RBSet` is a self-balancing binary search tree.
The `cmp` function is the comparator that will be used for performing searches;
it should satisfy the requirements of `TransCmp` for it to have sensible behavior.
-/
def RBSet (α : Type u) (cmp : α → α → Ordering) : Type u 
goal: Type u

full_name: Batteries.mkRBSet
code: /-- `O(1)`. Construct a new empty tree. -/
@[inline] def mkRBSet (α : Type u) (cmp : α → α → Ordering) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.empty
code: /-- `O(1)`. Construct a new empty tree. -/
@[inline] def empty : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.instEmptyCollection
code: instance (α : Type u) (cmp : α → α → Ordering) : EmptyCollection (RBSet α cmp) 
goal: EmptyCollection (Batteries.RBSet α cmp)

full_name: Batteries.RBSet.instInhabited
code: instance (α : Type u) (cmp : α → α → Ordering) : Inhabited (RBSet α cmp) 
goal: Inhabited (Batteries.RBSet α cmp)

full_name: Batteries.RBSet.single
code: /-- `O(1)`. Construct a new tree with one element `v`. -/
@[inline] def single (v : α) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.foldl
code: /-- `O(n)`. Fold a function on the values from left to right (in increasing order). -/
@[inline] def foldl (f : σ → α → σ) (init : σ) (t : RBSet α cmp) : σ 
goal: σ

full_name: Batteries.RBSet.foldr
code: /-- `O(n)`. Fold a function on the values from right to left (in decreasing order). -/
@[inline] def foldr (f : α → σ → σ) (init : σ) (t : RBSet α cmp) : σ 
goal: σ

full_name: Batteries.RBSet.foldlM
code: /-- `O(n)`. Fold a monadic function on the values from left to right (in increasing order). -/
@[inline] def foldlM [Monad m] (f : σ → α → m σ) (init : σ) (t : RBSet α cmp) : m σ 
goal: m σ

full_name: Batteries.RBSet.forM
code: /-- `O(n)`. Run monadic function `f` on each element of the tree (in increasing order). -/
@[inline] def forM [Monad m] (f : α → m PUnit) (t : RBSet α cmp) : m PUnit 
goal: m PUnit

full_name: Batteries.RBSet.instForIn
code: instance : ForIn m (RBSet α cmp) α 
goal: ForIn m (Batteries.RBSet α cmp) α

full_name: Batteries.RBSet.instToStreamStream
code: instance : ToStream (RBSet α cmp) (RBNode.Stream α) 
goal: ToStream (Batteries.RBSet α cmp) (Batteries.RBNode.Stream α)

full_name: Batteries.RBSet.isEmpty
code: /-- `O(1)`. Is the tree empty? -/
@[inline] def isEmpty : RBSet α cmp → Bool
  
goal: Batteries.RBSet α cmp → Bool

full_name: Batteries.RBSet.toList
code: /-- `O(n)`. Convert the tree to a list in ascending order. -/
@[inline] def toList (t : RBSet α cmp) : List α 
goal: List α

full_name: Batteries.RBSet.min?
code: /-- `O(log n)`. Returns the entry `a` such that `a ≤ k` for all keys in the RBSet. -/
@[inline] protected def min? (t : RBSet α cmp) : Option α 
goal: Option α

full_name: Batteries.RBSet.max?
code: /-- `O(log n)`. Returns the entry `a` such that `a ≥ k` for all keys in the RBSet. -/
@[inline] protected def max? (t : RBSet α cmp) : Option α 
goal: Option α

full_name: Batteries.RBSet.instRepr
code: instance [Repr α] : Repr (RBSet α cmp) 
goal: Repr (Batteries.RBSet α cmp)

full_name: Batteries.RBSet.insert
code: /-- `O(log n)`. Insert element `v` into the tree. -/
@[inline] def insert (t : RBSet α cmp) (v : α) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.insertMany
code: /--
Insert all elements from a collection into a `RBSet α cmp`.
-/
def insertMany [ForIn Id ρ α] (s : RBSet α cmp) (as : ρ) :
    RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.erase
code: /--
`O(log n)`. Remove an element from the tree using a cut function.
The `cut` function is used to locate an element in the tree:
it returns `.gt` if we go too high and `.lt` if we go too low;
if it returns `.eq` we will remove the element.
(The function `cmp k` for some key `k` is a valid cut function, but we can also use cuts that
are not of this form as long as they are suitably monotonic.)
-/
@[inline] def erase (t : RBSet α cmp) (cut : α → Ordering) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.findP?
code: /-- `O(log n)`. Find an element in the tree using a cut function. -/
@[inline] def findP? (t : RBSet α cmp) (cut : α → Ordering) : Option α 
goal: Option α

full_name: Batteries.RBSet.find?
code: /-- `O(log n)`. Returns an element in the tree equivalent to `x` if one exists. -/
@[inline] def find? (t : RBSet α cmp) (x : α) : Option α 
goal: Option α

full_name: Batteries.RBSet.findPD
code: /-- `O(log n)`. Find an element in the tree, or return a default value `v₀`. -/
@[inline] def findPD (t : RBSet α cmp) (cut : α → Ordering) (v₀ : α) : α 
goal: α

full_name: Batteries.RBSet.upperBoundP?
code: /--
`O(log n)`. `upperBoundP cut` retrieves the smallest entry comparing `gt` or `eq` under `cut`,
if it exists. If multiple keys in the map return `eq` under `cut`, any of them may be returned.
-/
@[inline] def upperBoundP? (t : RBSet α cmp) (cut : α → Ordering) : Option α 
goal: Option α

full_name: Batteries.RBSet.upperBound?
code: /--
`O(log n)`. `upperBound? k` retrieves the largest entry smaller than or equal to `k`,
if it exists.
-/
@[inline] def upperBound? (t : RBSet α cmp) (k : α) : Option α 
goal: Option α

full_name: Batteries.RBSet.lowerBoundP?
code: /--
`O(log n)`. `lowerBoundP cut` retrieves the largest entry comparing `lt` or `eq` under `cut`,
if it exists. If multiple keys in the map return `eq` under `cut`, any of them may be returned.
-/
@[inline] def lowerBoundP? (t : RBSet α cmp) (cut : α → Ordering) : Option α 
goal: Option α

full_name: Batteries.RBSet.lowerBound?
code: /--
`O(log n)`. `lowerBound? k` retrieves the largest entry smaller than or equal to `k`,
if it exists.
-/
@[inline] def lowerBound? (t : RBSet α cmp) (k : α) : Option α 
goal: Option α

full_name: Batteries.RBSet.containsP
code: /-- `O(log n)`. Returns true if the given cut returns `eq` for something in the RBSet. -/
@[inline] def containsP (t : RBSet α cmp) (cut : α → Ordering) : Bool 
goal: Bool

full_name: Batteries.RBSet.contains
code: /-- `O(log n)`. Returns true if the given key `a` is in the RBSet. -/
@[inline] def contains (t : RBSet α cmp) (a : α) : Bool 
goal: Bool

full_name: Batteries.RBSet.ofList
code: /-- `O(n log n)`. Build a tree from an unsorted list by inserting them one at a time. -/
@[inline] def ofList (l : List α) (cmp : α → α → Ordering) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.ofArray
code: /-- `O(n log n)`. Build a tree from an unsorted array by inserting them one at a time. -/
@[inline] def ofArray (l : Array α) (cmp : α → α → Ordering) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.all
code: /-- `O(n)`. Returns true if the given predicate is true for all items in the RBSet. -/
@[inline] def all (t : RBSet α cmp) (p : α → Bool) : Bool 
goal: Bool

full_name: Batteries.RBSet.any
code: /-- `O(n)`. Returns true if the given predicate is true for any item in the RBSet. -/
@[inline] def any (t : RBSet α cmp) (p : α → Bool) : Bool 
goal: Bool

full_name: Batteries.RBSet.all₂
code: /--
Asserts that `t₁` and `t₂` have the same number of elements in the same order,
and `R` holds pairwise between them. The tree structure is ignored.
-/
@[inline] def all₂ (R : α → β → Bool) (t₁ : RBSet α cmpα) (t₂ : RBSet β cmpβ) : Bool 
goal: Bool

full_name: Batteries.RBSet.EMem
code: /-- True if `x` is an element of `t` "exactly", i.e. up to equality, not the `cmp` relation. -/
def EMem (x : α) (t : RBSet α cmp) : Prop 
goal: Prop

full_name: Batteries.RBSet.MemP
code: /-- True if the specified `cut` matches at least one element of of `t`. -/
def MemP (cut : α → Ordering) (t : RBSet α cmp) : Prop 
goal: Prop

full_name: Batteries.RBSet.Mem
code: /-- True if `x` is equivalent to an element of `t`. -/
def Mem (x : α) (t : RBSet α cmp) : Prop 
goal: Prop

full_name: Batteries.RBSet.instMembership
code: instance : Membership α (RBSet α cmp) 
goal: Membership α (Batteries.RBSet α cmp)

full_name: Batteries.RBSet.Slow.instDecidableEMem
code: @[nolint docBlame] scoped instance Slow.instDecidableEMem [DecidableEq α] {t : RBSet α cmp} :
    Decidable (EMem x t) 
goal: Decidable (Batteries.RBSet.EMem x t)

full_name: Batteries.RBSet.Slow.instDecidableMemP
code: @[nolint docBlame] scoped instance Slow.instDecidableMemP {t : RBSet α cmp} :
    Decidable (MemP cut t) 
goal: Decidable (Batteries.RBSet.MemP cut t)

full_name: Batteries.RBSet.Slow.instDecidableMem
code: @[nolint docBlame] scoped instance Slow.instDecidableMem {t : RBSet α cmp} :
    Decidable (Mem x t) 
goal: Decidable (Batteries.RBSet.Mem x t)

full_name: Batteries.RBSet.instBEq
code: /--
Returns true if `t₁` and `t₂` are equal as sets (assuming `cmp` and `==` are compatible),
ignoring the internal tree structure.
-/
instance [BEq α] : BEq (RBSet α cmp) 
goal: BEq (Batteries.RBSet α cmp)

full_name: Batteries.RBSet.size
code: /-- `O(n)`. The number of items in the RBSet. -/
def size (m : RBSet α cmp) : Nat 
goal: Nat

full_name: Batteries.RBSet.min!
code: /-- `O(log n)`. Returns the minimum element of the tree, or panics if the tree is empty. -/
@[inline] def min! [Inhabited α] (t : RBSet α cmp) : α 
goal: α

full_name: Batteries.RBSet.max!
code: /-- `O(log n)`. Returns the maximum element of the tree, or panics if the tree is empty. -/
@[inline] def max! [Inhabited α] (t : RBSet α cmp) : α 
goal: α

full_name: Batteries.RBSet.findP!
code: /--
`O(log n)`. Attempts to find the value with key `k : α` in `t` and panics if there is no such key.
-/
@[inline] def findP! [Inhabited α] (t : RBSet α cmp) (cut : α → Ordering) : α 
goal: α

full_name: Batteries.RBSet.find!
code: /--
`O(log n)`. Attempts to find the value with key `k : α` in `t` and panics if there is no such key.
-/
@[inline] def find! [Inhabited α] (t : RBSet α cmp) (k : α) : α 
goal: α

full_name: Batteries.RBSet.ModifyWF
code: /-- The predicate asserting that the result of `modifyP` is safe to construct. -/
class ModifyWF (t : RBSet α cmp) (cut : α → Ordering) (f : α → α) : Prop where
  /-- The resulting tree is well formed. -/
  wf : (t.1.modify cut f).WF cmp
goal: Prop

full_name: Batteries.RBSet.ModifyWF.wf
code: /-- The predicate asserting that the result of `modifyP` is safe to construct. -/
class ModifyWF (t : RBSet α cmp) (cut : α → Ordering) (f : α → α) : Prop where
  /-- The resulting tree is well formed. -/
  wf : (t.1.modify cut f).WF cmp
goal: Batteries.RBNode.WF cmp (Batteries.RBNode.modify cut f t.val)

full_name: Batteries.RBSet.modifyP
code: /--
`O(log n)`. In-place replace an element found by `cut`.
This takes the element out of the tree while `f` runs,
so it uses the element linearly if `t` is unshared.

The `ModifyWF` assumption is required because `f` may change
the ordering properties of the element, which would break the invariants.
-/
def modifyP (t : RBSet α cmp) (cut : α → Ordering) (f : α → α)
    [wf : ModifyWF t cut f] : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.AlterWF.wf
code: /-- The predicate asserting that the result of `alterP` is safe to construct. -/
class AlterWF (t : RBSet α cmp) (cut : α → Ordering) (f : Option α → Option α) : Prop where
  /-- The resulting tree is well formed. -/
  wf : (t.1.alter cut f).WF cmp
goal: Batteries.RBNode.WF cmp (Batteries.RBNode.alter cut f t.val)

full_name: Batteries.RBSet.AlterWF
code: /-- The predicate asserting that the result of `alterP` is safe to construct. -/
class AlterWF (t : RBSet α cmp) (cut : α → Ordering) (f : Option α → Option α) : Prop where
  /-- The resulting tree is well formed. -/
  wf : (t.1.alter cut f).WF cmp
goal: Prop

full_name: Batteries.RBSet.alterP
code: /--
`O(log n)`. `alterP cut f t` simultaneously handles inserting, erasing and replacing an element
using a function `f : Option α → Option α`. It is passed the result of `t.findP? cut`
and can either return `none` to remove the element or `some a` to replace/insert
the element with `a` (which must have the same ordering properties as the original element).

The element is used linearly if `t` is unshared.

The `AlterWF` assumption is required because `f` may change
the ordering properties of the element, which would break the invariants.
-/
def alterP (t : RBSet α cmp) (cut : α → Ordering) (f : Option α → Option α)
    [wf : AlterWF t cut f] : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.union
code: /--
`O(n₂ * log (n₁ + n₂))`. Merges the maps `t₁` and `t₂`.
If equal keys exist in both, the key from `t₂` is preferred.
-/
def union (t₁ t₂ : RBSet α cmp) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.instUnion
code: instance : Union (RBSet α cmp) 
goal: Union (Batteries.RBSet α cmp)

full_name: Batteries.RBSet.mergeWith
code: /--
`O(n₂ * log (n₁ + n₂))`. Merges the maps `t₁` and `t₂`. If equal keys exist in both,
then use `mergeFn a₁ a₂` to produce the new merged value.
-/
def mergeWith (mergeFn : α → α → α) (t₁ t₂ : RBSet α cmp) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.intersectWith
code: /--
`O(n₁ * log (n₁ + n₂))`. Intersects the maps `t₁` and `t₂`
using `mergeFn a b` to produce the new value.
-/
def intersectWith (cmp : α → β → Ordering) (mergeFn : α → β → γ)
    (t₁ : RBSet α cmpα) (t₂ : RBSet β cmpβ) : RBSet γ cmpγ 
goal: Batteries.RBSet γ cmpγ

full_name: Batteries.RBSet.filter
code: /-- `O(n * log n)`. Constructs the set of all elements satisfying `p`. -/
def filter (t : RBSet α cmp) (p : α → Bool) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.map
code: /--
`O(n * log n)`. Map a function on every value in the set.
If the function is monotone, consider using the more efficient `RBSet.mapMonotone` instead.
-/
def map (t : RBSet α cmpα) (f : α → β) : RBSet β cmpβ 
goal: Batteries.RBSet β cmpβ

full_name: Batteries.RBSet.sdiff
code: /--
`O(n₁ * (log n₁ + log n₂))`. Constructs the set of all elements of `t₁` that are not in `t₂`.
-/
def sdiff (t₁ t₂ : RBSet α cmp) : RBSet α cmp 
goal: Batteries.RBSet α cmp

full_name: Batteries.RBSet.instSDiff
code: instance : SDiff (Batteries.RBSet α cmp) 
goal: SDiff (Batteries.RBSet α cmp)

full_name: Batteries.RBMap
code: /--
An `RBMap` is a self-balancing binary search tree, used to store a key-value map.
The `cmp` function is the comparator that will be used for performing searches;
it should satisfy the requirements of `TransCmp` for it to have sensible behavior.
-/
def RBMap (α : Type u) (β : Type v) (cmp : α → α → Ordering) : Type (max u v) 
goal: Type (max u v)

full_name: Batteries.mkRBMap
code: /-- `O(1)`. Construct a new empty map. -/
@[inline] def mkRBMap (α : Type u) (β : Type v) (cmp : α → α → Ordering) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.empty
code: /-- `O(1)`. Construct a new empty map. -/
@[inline] def RBMap.empty {α : Type u} {β : Type v} {cmp : α → α → Ordering} : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.instEmptyCollectionRBMap
code: instance (α : Type u) (β : Type v) (cmp : α → α → Ordering) : EmptyCollection (RBMap α β cmp) 
goal: EmptyCollection (Batteries.RBMap α β cmp)

full_name: Batteries.instInhabitedRBMap
code: instance (α : Type u) (β : Type v) (cmp : α → α → Ordering) : Inhabited (RBMap α β cmp) 
goal: Inhabited (Batteries.RBMap α β cmp)

full_name: Batteries.RBMap.single
code: /-- `O(1)`. Construct a new tree with one key-value pair `k, v`. -/
@[inline] def RBMap.single (k : α) (v : β) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.foldl
code: /-- `O(n)`. Fold a function on the values from left to right (in increasing order). -/
@[inline] def foldl (f : σ → α → β → σ) : (init : σ) → RBMap α β cmp → σ
  
goal: Batteries.RBMap α β cmp → σ

full_name: Batteries.RBMap.foldr
code: /-- `O(n)`. Fold a function on the values from right to left (in decreasing order). -/
@[inline] def foldr (f : α → β → σ → σ) : (init : σ) → RBMap α β cmp → σ
  
goal: Batteries.RBMap α β cmp → σ

full_name: Batteries.RBMap.foldlM
code: /-- `O(n)`. Fold a monadic function on the values from left to right (in increasing order). -/
@[inline] def foldlM [Monad m] (f : σ → α → β → m σ) : (init : σ) → RBMap α β cmp → m σ
  
goal: Batteries.RBMap α β cmp → m σ

full_name: Batteries.RBMap.forM
code: /-- `O(n)`. Run monadic function `f` on each element of the tree (in increasing order). -/
@[inline] def forM [Monad m] (f : α → β → m PUnit) (t : RBMap α β cmp) : m PUnit 
goal: m PUnit

full_name: Batteries.RBMap.instForInProd
code: instance : ForIn m (RBMap α β cmp) (α × β) 
goal: ForIn m (Batteries.RBMap α β cmp) (α × β)

full_name: Batteries.RBMap.instToStreamStreamProd
code: instance : ToStream (RBMap α β cmp) (RBNode.Stream (α × β)) 
goal: ToStream (Batteries.RBMap α β cmp) (Batteries.RBNode.Stream (α × β))

full_name: Batteries.RBMap.keysArray
code: /-- `O(n)`. Constructs the array of keys of the map. -/
@[inline] def keysArray (t : RBMap α β cmp) : Array α 
goal: Array α

full_name: Batteries.RBMap.keysList
code: /-- `O(n)`. Constructs the list of keys of the map. -/
@[inline] def keysList (t : RBMap α β cmp) : List α 
goal: List α

full_name: Batteries.RBMap.Keys
code: /--
An "iterator" over the keys of the map. This is a trivial wrapper over the underlying map,
but it comes with a small API to use it in a `for` loop or convert it to an array or list.
-/
def Keys (α β cmp) 
goal: Type (max u_1 u_2)

full_name: Batteries.RBMap.keys
code: /--
The keys of the map. This is an `O(1)` wrapper operation, which
can be used in `for` loops or converted to an array or list.
-/
@[inline] def keys (t : RBMap α β cmp) : Keys α β cmp 
goal: Batteries.RBMap.Keys α β cmp

full_name: Batteries.RBMap.Keys.toArray
code: @[inline, inherit_doc keysArray] def Keys.toArray 
goal: Array α

full_name: Batteries.RBMap.Keys.toList
code: @[inline, inherit_doc keysList] def Keys.toList 
goal: List α

full_name: Batteries.RBMap.instCoeHeadKeysArray
code: instance : CoeHead (Keys α β cmp) (Array α) 
goal: CoeHead (Batteries.RBMap.Keys α β cmp) (Array α)

full_name: Batteries.RBMap.instCoeHeadKeysList
code: instance : CoeHead (Keys α β cmp) (List α) 
goal: CoeHead (Batteries.RBMap.Keys α β cmp) (List α)

full_name: Batteries.RBMap.instForInKeys
code: instance : ForIn m (Keys α β cmp) α 
goal: ForIn m (Batteries.RBMap.Keys α β cmp) α

full_name: Batteries.RBMap.instForMKeys
code: instance : ForM m (Keys α β cmp) α 
goal: ForM m (Batteries.RBMap.Keys α β cmp) α

full_name: Batteries.RBMap.Keys.Stream
code: /-- The result of `toStream` on a `Keys`. -/
def Keys.Stream (α β) 
goal: Type (max u_2 u_1)

full_name: Batteries.RBMap.Keys.toStream
code: /-- A stream over the iterator. -/
def Keys.toStream (t : Keys α β cmp) : Keys.Stream α β 
goal: Batteries.RBMap.Keys.Stream α β

full_name: Batteries.RBMap.Keys.Stream.next?
code: /-- `O(1)` amortized, `O(log n)` worst case: Get the next element from the stream. -/
def Keys.Stream.next? (t : Stream α β) : Option (α × Stream α β) 
goal: Option (α × Batteries.RBMap.Keys.Stream α β)

full_name: Batteries.RBMap.instToStreamKeysStream
code: instance : ToStream (Keys α β cmp) (Keys.Stream α β) 
goal: ToStream (Batteries.RBMap.Keys α β cmp) (Batteries.RBMap.Keys.Stream α β)

full_name: Batteries.RBMap.instStreamStream
code: instance : Stream (Keys.Stream α β) α 
goal: Stream (Batteries.RBMap.Keys.Stream α β) α

full_name: Batteries.RBMap.valuesArray
code: /-- `O(n)`. Constructs the array of values of the map. -/
@[inline] def valuesArray (t : RBMap α β cmp) : Array β 
goal: Array β

full_name: Batteries.RBMap.valuesList
code: /-- `O(n)`. Constructs the list of values of the map. -/
@[inline] def valuesList (t : RBMap α β cmp) : List β 
goal: List β

full_name: Batteries.RBMap.Values
code: /--
An "iterator" over the values of the map. This is a trivial wrapper over the underlying map,
but it comes with a small API to use it in a `for` loop or convert it to an array or list.
-/
def Values (α β cmp) 
goal: Type (max u_1 u_2)

full_name: Batteries.RBMap.values
code: /--
The "keys" of the map. This is an `O(1)` wrapper operation, which
can be used in `for` loops or converted to an array or list.
-/
@[inline] def values (t : RBMap α β cmp) : Values α β cmp 
goal: Batteries.RBMap.Values α β cmp

full_name: Batteries.RBMap.Values.toArray
code: @[inline, inherit_doc valuesArray] def Values.toArray 
goal: Array β

full_name: Batteries.RBMap.Values.toList
code: @[inline, inherit_doc valuesList] def Values.toList 
goal: List β

full_name: Batteries.RBMap.instCoeHeadValuesArray
code: instance : CoeHead (Values α β cmp) (Array β) 
goal: CoeHead (Batteries.RBMap.Values α β cmp) (Array β)

full_name: Batteries.RBMap.instCoeHeadValuesList
code: instance : CoeHead (Values α β cmp) (List β) 
goal: CoeHead (Batteries.RBMap.Values α β cmp) (List β)

full_name: Batteries.RBMap.instForInValues
code: instance : ForIn m (Values α β cmp) β 
goal: ForIn m (Batteries.RBMap.Values α β cmp) β

full_name: Batteries.RBMap.instForMValues
code: instance : ForM m (Values α β cmp) β 
goal: ForM m (Batteries.RBMap.Values α β cmp) β

full_name: Batteries.RBMap.Values.Stream
code: /-- The result of `toStream` on a `Values`. -/
def Values.Stream (α β) 
goal: Type (max u_2 u_1)

full_name: Batteries.RBMap.Values.toStream
code: /-- A stream over the iterator. -/
def Values.toStream (t : Values α β cmp) : Values.Stream α β 
goal: Batteries.RBMap.Values.Stream α β

full_name: Batteries.RBMap.Values.Stream.next?
code: /-- `O(1)` amortized, `O(log n)` worst case: Get the next element from the stream. -/
def Values.Stream.next? (t : Stream α β) : Option (β × Stream α β) 
goal: Option (β × Batteries.RBMap.Values.Stream α β)

full_name: Batteries.RBMap.instToStreamValuesStream
code: instance : ToStream (Values α β cmp) (Values.Stream α β) 
goal: ToStream (Batteries.RBMap.Values α β cmp) (Batteries.RBMap.Values.Stream α β)

full_name: Batteries.RBMap.instStreamStream_1
code: instance : Stream (Values.Stream α β) β 
goal: Stream (Batteries.RBMap.Values.Stream α β) β

full_name: Batteries.RBMap.isEmpty
code: /-- `O(1)`. Is the tree empty? -/
@[inline] def isEmpty : RBMap α β cmp → Bool 
goal: Batteries.RBMap α β cmp → Bool

full_name: Batteries.RBMap.toList
code: /-- `O(n)`. Convert the tree to a list in ascending order. -/
@[inline] def toList : RBMap α β cmp → List (α × β) 
goal: Batteries.RBMap α β cmp → List (α × β)

full_name: Batteries.RBMap.min?
code: /-- `O(log n)`. Returns the key-value pair `(a, b)` such that `a ≤ k` for all keys in the RBMap. -/
@[inline] protected def min? : RBMap α β cmp → Option (α × β) 
goal: Batteries.RBMap α β cmp → Option (α × β)

full_name: Batteries.RBMap.max?
code: /-- `O(log n)`. Returns the key-value pair `(a, b)` such that `a ≥ k` for all keys in the RBMap. -/
@[inline] protected def max? : RBMap α β cmp → Option (α × β) 
goal: Batteries.RBMap α β cmp → Option (α × β)

full_name: Batteries.RBMap.instRepr
code: instance [Repr α] [Repr β] : Repr (RBMap α β cmp) 
goal: Repr (Batteries.RBMap α β cmp)

full_name: Batteries.RBMap.insert
code: /-- `O(log n)`. Insert key-value pair `(k, v)` into the tree. -/
@[inline] def insert (t : RBMap α β cmp) (k : α) (v : β) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.erase
code: /-- `O(log n)`. Remove an element `k` from the map. -/
@[inline] def erase (t : RBMap α β cmp) (k : α) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.ofList
code: /-- `O(n log n)`. Build a tree from an unsorted list by inserting them one at a time. -/
@[inline] def ofList (l : List (α × β)) (cmp : α → α → Ordering) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.ofArray
code: /-- `O(n log n)`. Build a tree from an unsorted array by inserting them one at a time. -/
@[inline] def ofArray (l : Array (α × β)) (cmp : α → α → Ordering) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.findEntry?
code: /-- `O(log n)`. Find an entry in the tree with key equal to `k`. -/
@[inline] def findEntry? (t : RBMap α β cmp) (k : α) : Option (α × β) 
goal: Option (α × β)

full_name: Batteries.RBMap.find?
code: /-- `O(log n)`. Find the value corresponding to key `k`. -/
@[inline] def find? (t : RBMap α β cmp) (k : α) : Option β 
goal: Option β

full_name: Batteries.RBMap.findD
code: /-- `O(log n)`. Find the value corresponding to key `k`, or return `v₀` if it is not in the map. -/
@[inline] def findD (t : RBMap α β cmp) (k : α) (v₀ : β) : β 
goal: β

full_name: Batteries.RBMap.lowerBound?
code: /--
`O(log n)`. `lowerBound? k` retrieves the key-value pair of the largest key
smaller than or equal to `k`, if it exists.
-/
@[inline] def lowerBound? (t : RBMap α β cmp) (k : α) : Option (α × β) 
goal: Option (α × β)

full_name: Batteries.RBMap.contains
code: /-- `O(log n)`. Returns true if the given key `a` is in the RBMap. -/
@[inline] def contains (t : RBMap α β cmp) (a : α) : Bool 
goal: Bool

full_name: Batteries.RBMap.all
code: /-- `O(n)`. Returns true if the given predicate is true for all items in the RBMap. -/
@[inline] def all (t : RBMap α β cmp) (p : α → β → Bool) : Bool 
goal: Bool

full_name: Batteries.RBMap.any
code: /-- `O(n)`. Returns true if the given predicate is true for any item in the RBMap. -/
@[inline] def any (t : RBMap α β cmp) (p : α → β → Bool) : Bool 
goal: Bool

full_name: Batteries.RBMap.all₂
code: /--
Asserts that `t₁` and `t₂` have the same number of elements in the same order,
and `R` holds pairwise between them. The tree structure is ignored.
-/
@[inline] def all₂ (R : α × β → γ × δ → Bool) (t₁ : RBMap α β cmpα) (t₂ : RBMap γ δ cmpγ) : Bool 
goal: Bool

full_name: Batteries.RBMap.eqKeys
code: /-- Asserts that `t₁` and `t₂` have the same set of keys (up to equality). -/
@[inline] def eqKeys (t₁ : RBMap α β cmp) (t₂ : RBMap α γ cmp) : Bool 
goal: Bool

full_name: Batteries.RBMap.instBEq
code: /--
Returns true if `t₁` and `t₂` have the same keys and values
(assuming `cmp` and `==` are compatible), ignoring the internal tree structure.
-/
instance [BEq α] [BEq β] : BEq (RBMap α β cmp) 
goal: BEq (Batteries.RBMap α β cmp)

full_name: Batteries.RBMap.size
code: /-- `O(n)`. The number of items in the RBMap. -/
def size : RBMap α β cmp → Nat 
goal: Batteries.RBMap α β cmp → Nat

full_name: Batteries.RBMap.min!
code: /-- `O(log n)`. Returns the minimum element of the map, or panics if the map is empty. -/
@[inline] def min! [Inhabited α] [Inhabited β] : RBMap α β cmp → α × β 
goal: Batteries.RBMap α β cmp → α × β

full_name: Batteries.RBMap.max!
code: /-- `O(log n)`. Returns the maximum element of the map, or panics if the map is empty. -/
@[inline] def max! [Inhabited α] [Inhabited β] : RBMap α β cmp → α × β 
goal: Batteries.RBMap α β cmp → α × β

full_name: Batteries.RBMap.find!
code: /-- Attempts to find the value with key `k : α` in `t` and panics if there is no such key. -/
@[inline] def find! [Inhabited β] (t : RBMap α β cmp) (k : α) : β 
goal: β

full_name: Batteries.RBMap.mergeWith
code: /--
`O(n₂ * log (n₁ + n₂))`. Merges the maps `t₁` and `t₂`, if a key `a : α` exists in both,
then use `mergeFn a b₁ b₂` to produce the new merged value.
-/
def mergeWith (mergeFn : α → β → β → β) (t₁ t₂ : RBMap α β cmp) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.intersectWith
code: /--
`O(n₁ * log (n₁ + n₂))`. Intersects the maps `t₁` and `t₂`
using `mergeFn a b` to produce the new value.
-/
def intersectWith (mergeFn : α → β → γ → δ)
    (t₁ : RBMap α β cmp) (t₂ : RBMap α γ cmp) : RBMap α δ cmp 
goal: Batteries.RBMap α δ cmp

full_name: Batteries.RBMap.filter
code: /-- `O(n * log n)`. Constructs the set of all elements satisfying `p`. -/
def filter (t : RBMap α β cmp) (p : α → β → Bool) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: Batteries.RBMap.sdiff
code: /--
`O(n₁ * (log n₁ + log n₂))`. Constructs the set of all elements of `t₁` that are not in `t₂`.
-/
def sdiff (t₁ t₂ : RBMap α β cmp) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp

full_name: List.toRBMap
code: @[inherit_doc RBMap.ofList]
abbrev List.toRBMap (l : List (α × β)) (cmp : α → α → Ordering) : RBMap α β cmp 
goal: Batteries.RBMap α β cmp