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

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

full_name: Batteries.RBNode.All_and
code: theorem All_and {t : RBNode α} : t.All (fun a => p a ∧ q a) ↔ t.All p ∧ t.All q 
goal: Batteries.RBNode.All (fun a => p a ∧ q a) t ↔ Batteries.RBNode.All p t ∧ Batteries.RBNode.All q t

full_name: Batteries.RBNode.cmpLT.flip
code: protected theorem cmpLT.flip (h₁ : cmpLT cmp x y) : cmpLT (flip cmp) y x 
goal: ∀ {α : Sort u_1} {cmp : α → α → Ordering} {x y : α},
  Batteries.RBNode.cmpLT cmp x y → Batteries.RBNode.cmpLT (flip cmp) y x

full_name: Batteries.RBNode.cmpLT.trans
code: theorem cmpLT.trans (h₁ : cmpLT cmp x y) (h₂ : cmpLT cmp y z) : cmpLT cmp x z 
goal: ∀ {α : Sort u_1} {cmp : α → α → Ordering} {x y z : α},
  Batteries.RBNode.cmpLT cmp x y → Batteries.RBNode.cmpLT cmp y z → Batteries.RBNode.cmpLT cmp x z

full_name: Batteries.RBNode.cmpLT.trans_l
code: theorem cmpLT.trans_l {cmp x y} (H : cmpLT cmp x y) {t : RBNode α}
    (h : t.All (cmpLT cmp y ·)) : t.All (cmpLT cmp x ·) 
goal: Batteries.RBNode.All (fun x_1 => Batteries.RBNode.cmpLT cmp x x_1) t

full_name: Batteries.RBNode.cmpLT.trans_r
code: theorem cmpLT.trans_r {cmp x y} (H : cmpLT cmp x y) {a : RBNode α}
    (h : a.All (cmpLT cmp · x)) : a.All (cmpLT cmp · y) 
goal: Batteries.RBNode.All (fun x => Batteries.RBNode.cmpLT cmp x y) a

full_name: Batteries.RBNode.cmpEq.lt_congr_left
code: theorem cmpEq.lt_congr_left (H : cmpEq cmp x y) : cmpLT cmp x z ↔ cmpLT cmp y z 
goal: ∀ {α : Sort u_1} {cmp : α → α → Ordering} {x y z : α},
  Batteries.RBNode.cmpEq cmp x y → (Batteries.RBNode.cmpLT cmp x z ↔ Batteries.RBNode.cmpLT cmp y z)

full_name: Batteries.RBNode.cmpEq.lt_congr_right
code: theorem cmpEq.lt_congr_right (H : cmpEq cmp y z) : cmpLT cmp x y ↔ cmpLT cmp x z 
goal: ∀ {α : Sort u_1} {cmp : α → α → Ordering} {y z x : α},
  Batteries.RBNode.cmpEq cmp y z → (Batteries.RBNode.cmpLT cmp x y ↔ Batteries.RBNode.cmpLT cmp x z)

full_name: Batteries.RBNode.reverse_reverse
code: @[simp] theorem reverse_reverse (t : RBNode α) : t.reverse.reverse = t 
goal: t.reverse.reverse = t

full_name: Batteries.RBNode.reverse_eq_iff
code: theorem reverse_eq_iff {t t' : RBNode α} : t.reverse = t' ↔ t = t'.reverse 
goal: t.reverse = t' ↔ t = t'.reverse

full_name: Batteries.RBNode.reverse_balance1
code: @[simp] theorem reverse_balance1 (l : RBNode α) (v : α) (r : RBNode α) :
    (balance1 l v r).reverse = balance2 r.reverse v l.reverse 
goal: (l.balance1 v r).reverse = r.reverse.balance2 v l.reverse

full_name: Batteries.RBNode.reverse_balance2
code: @[simp] theorem reverse_balance2 (l : RBNode α) (v : α) (r : RBNode α) :
    (balance2 l v r).reverse = balance1 r.reverse v l.reverse 
goal: (l.balance2 v r).reverse = r.reverse.balance1 v l.reverse

full_name: Batteries.RBNode.All.reverse
code: @[simp] theorem All.reverse {t : RBNode α} : t.reverse.All p ↔ t.All p 
goal: Batteries.RBNode.All p t.reverse ↔ Batteries.RBNode.All p t

full_name: Batteries.RBNode.Ordered.reverse
code: /-- The `reverse` function reverses the ordering invariants. -/
protected theorem Ordered.reverse : ∀ {t : RBNode α}, t.Ordered cmp → t.reverse.Ordered (flip cmp)
  
goal: Batteries.RBNode.Ordered cmp t → Batteries.RBNode.Ordered (flip cmp) t.reverse

full_name: Batteries.RBNode.Balanced.reverse
code: protected theorem Balanced.reverse {t : RBNode α} : t.Balanced c n → t.reverse.Balanced c n
  
goal: t.Balanced c n → t.reverse.Balanced c n

full_name: Batteries.RBNode.Ordered.balance1
code: /-- The `balance1` function preserves the ordering invariants. -/
protected theorem Ordered.balance1 {l : RBNode α} {v : α} {r : RBNode α}
    (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
    (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balance1 l v r).Ordered cmp 
goal: Batteries.RBNode.Ordered cmp (l.balance1 v r)

full_name: Batteries.RBNode.balance1_All
code: @[simp] theorem balance1_All {l : RBNode α} {v : α} {r : RBNode α} :
    (balance1 l v r).All p ↔ p v ∧ l.All p ∧ r.All p 
goal: Batteries.RBNode.All p (l.balance1 v r) ↔ p v ∧ Batteries.RBNode.All p l ∧ Batteries.RBNode.All p r

full_name: Batteries.RBNode.Ordered.balance2
code: /-- The `balance2` function preserves the ordering invariants. -/
protected theorem Ordered.balance2 {l : RBNode α} {v : α} {r : RBNode α}
    (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
    (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balance2 l v r).Ordered cmp 
goal: Batteries.RBNode.Ordered cmp (l.balance2 v r)

full_name: Batteries.RBNode.balance2_All
code: @[simp] theorem balance2_All {l : RBNode α} {v : α} {r : RBNode α} :
    (balance2 l v r).All p ↔ p v ∧ l.All p ∧ r.All p 
goal: Batteries.RBNode.All p (l.balance2 v r) ↔ p v ∧ Batteries.RBNode.All p l ∧ Batteries.RBNode.All p r

full_name: Batteries.RBNode.reverse_setBlack
code: @[simp] theorem reverse_setBlack {t : RBNode α} : (setBlack t).reverse = setBlack t.reverse 
goal: t.setBlack.reverse = t.reverse.setBlack

full_name: Batteries.RBNode.Ordered.setBlack
code: protected theorem Ordered.setBlack {t : RBNode α} : (setBlack t).Ordered cmp ↔ t.Ordered cmp 
goal: Batteries.RBNode.Ordered cmp t.setBlack ↔ Batteries.RBNode.Ordered cmp t

full_name: Batteries.RBNode.Balanced.setBlack
code: protected theorem Balanced.setBlack : t.Balanced c n → ∃ n', (setBlack t).Balanced black n'
  
goal: ∀ {α : Type u_1} {t : Batteries.RBNode α} {c : Batteries.RBColor} {n : Nat},
  t.Balanced c n → ∃ n', t.setBlack.Balanced Batteries.RBColor.black n'

full_name: Batteries.RBNode.setBlack_idem
code: theorem setBlack_idem {t : RBNode α} : t.setBlack.setBlack = t.setBlack 
goal: t.setBlack.setBlack = t.setBlack

full_name: Batteries.RBNode.reverse_ins
code: @[simp] theorem reverse_ins [inst : @OrientedCmp α cmp] {t : RBNode α} :
    (ins cmp x t).reverse = ins (flip cmp) x t.reverse 
goal: (Batteries.RBNode.ins cmp x t).reverse = Batteries.RBNode.ins (flip cmp) x t.reverse

full_name: Batteries.RBNode.All.ins
code: protected theorem All.ins {x : α} {t : RBNode α}
  (h₁ : p x) (h₂ : t.All p) : (ins cmp x t).All p 
goal: Batteries.RBNode.All p (Batteries.RBNode.ins cmp x t)

full_name: Batteries.RBNode.Ordered.ins
code: /-- The `ins` function preserves the ordering invariants. -/
protected theorem Ordered.ins : ∀ {t : RBNode α}, t.Ordered cmp → (ins cmp x t).Ordered cmp
  
goal: Batteries.RBNode.Ordered cmp t → Batteries.RBNode.Ordered cmp (Batteries.RBNode.ins cmp x t)

full_name: Batteries.RBNode.isRed_reverse
code: @[simp] theorem isRed_reverse {t : RBNode α} : t.reverse.isRed = t.isRed 
goal: t.reverse.isRed = t.isRed

full_name: Batteries.RBNode.reverse_insert
code: @[simp] theorem reverse_insert [inst : @OrientedCmp α cmp] {t : RBNode α} :
    (insert cmp t x).reverse = insert (flip cmp) t.reverse x 
goal: (Batteries.RBNode.insert cmp t x).reverse = Batteries.RBNode.insert (flip cmp) t.reverse x

full_name: Batteries.RBNode.insert_setBlack
code: theorem insert_setBlack {t : RBNode α} :
    (t.insert cmp v).setBlack = (t.ins cmp v).setBlack 
goal: (Batteries.RBNode.insert cmp t v).setBlack = (Batteries.RBNode.ins cmp v t).setBlack

full_name: Batteries.RBNode.Ordered.insert
code: /-- The `insert` function preserves the ordering invariants. -/
protected theorem Ordered.insert (h : t.Ordered cmp) : (insert cmp t v).Ordered cmp 
goal: ∀ {α : Type u_1} {cmp : α → α → Ordering} {t : Batteries.RBNode α} {v : α},
  Batteries.RBNode.Ordered cmp t → Batteries.RBNode.Ordered cmp (Batteries.RBNode.insert cmp t v)

full_name: Batteries.RBNode.RedRed.redred
code: /--
The red-red invariant is a weakening of the red-black balance invariant which allows
the root to be red with red children, but does not allow any other violations.
It occurs as a temporary condition in the `insert` and `erase` functions.

The `p` parameter allows the `.redred` case to be dependent on an additional condition.
If it is false, then this is equivalent to the usual red-black invariant.
-/
inductive RedRed (p : Prop) : RBNode α → Nat → Prop where
  /-- A balanced tree has the red-red invariant. -/
  | balanced : Balanced t c n → RedRed p t n
  /-- A red node with balanced red children has the red-red invariant (if `p` is true). -/
  | redred : p → Balanced a c₁ n → Balanced b c₂ n → RedRed p (node red a x b) n
goal: ∀ {x : Type u_1} {a : Batteries.RBNode x} {c₁ : Batteries.RBColor} {n : Nat} {b : Batteries.RBNode x}
  {c₂ : Batteries.RBColor} {x_1 : x},
  p →
    a.Balanced c₁ n →
      b.Balanced c₂ n → Batteries.RBNode.RedRed p (Batteries.RBNode.node Batteries.RBColor.red a x_1 b) n

full_name: Batteries.RBNode.RedRed.balanced
code: /--
The red-red invariant is a weakening of the red-black balance invariant which allows
the root to be red with red children, but does not allow any other violations.
It occurs as a temporary condition in the `insert` and `erase` functions.

The `p` parameter allows the `.redred` case to be dependent on an additional condition.
If it is false, then this is equivalent to the usual red-black invariant.
-/
inductive RedRed (p : Prop) : RBNode α → Nat → Prop where
  /-- A balanced tree has the red-red invariant. -/
  | balanced : Balanced t c n → RedRed p t n
  /-- A red node with balanced red children has the red-red invariant (if `p` is true). -/
  | redred : p → Balanced a c₁ n → Balanced b c₂ n → RedRed p (node red a x b) n
goal: ∀ {x : Type u_1} {t : Batteries.RBNode x} {c : Batteries.RBColor} {n : Nat},
  t.Balanced c n → Batteries.RBNode.RedRed p t n

full_name: Batteries.RBNode.RedRed
code: /--
The red-red invariant is a weakening of the red-black balance invariant which allows
the root to be red with red children, but does not allow any other violations.
It occurs as a temporary condition in the `insert` and `erase` functions.

The `p` parameter allows the `.redred` case to be dependent on an additional condition.
If it is false, then this is equivalent to the usual red-black invariant.
-/
inductive RedRed (p : Prop) : RBNode α → Nat → Prop where
  /-- A balanced tree has the red-red invariant. -/
  | balanced : Balanced t c n → RedRed p t n
  /-- A red node with balanced red children has the red-red invariant (if `p` is true). -/
  | redred : p → Balanced a c₁ n → Balanced b c₂ n → RedRed p (node red a x b) n
goal: Batteries.RBNode α → Nat → Prop

full_name: Batteries.RBNode.RedRed.of_false
code: /-- When `p` is false, the red-red case is impossible so the tree is balanced. -/
protected theorem RedRed.of_false (h : ¬p) : RedRed p t n → ∃ c, Balanced t c n
  
goal: ∀ {α : Type u_1} {t : Batteries.RBNode α} {n : Nat}, ¬p → Batteries.RBNode.RedRed p t n → ∃ c, t.Balanced c n

full_name: Batteries.RBNode.RedRed.of_red
code: /-- A `red` node with the red-red invariant has balanced children. -/
protected theorem RedRed.of_red : RedRed p (node red a x b) n →
    ∃ c₁ c₂, Balanced a c₁ n ∧ Balanced b c₂ n
  
goal: ∀ {α : Type u_1} {a : Batteries.RBNode α} {x : α} {b : Batteries.RBNode α} {n : Nat},
  Batteries.RBNode.RedRed p (Batteries.RBNode.node Batteries.RBColor.red a x b) n →
    ∃ c₁ c₂, a.Balanced c₁ n ∧ b.Balanced c₂ n

full_name: Batteries.RBNode.RedRed.imp
code: /-- The red-red invariant is monotonic in `p`. -/
protected theorem RedRed.imp (h : p → q) : RedRed p t n → RedRed q t n
  
goal: ∀ {α : Type u_1} {t : Batteries.RBNode α} {n : Nat},
  (p → q) → Batteries.RBNode.RedRed p t n → Batteries.RBNode.RedRed q t n

full_name: Batteries.RBNode.RedRed.reverse
code: protected theorem RedRed.reverse : RedRed p t n → RedRed p t.reverse n
  
goal: ∀ {α : Type u_1} {t : Batteries.RBNode α} {n : Nat},
  Batteries.RBNode.RedRed p t n → Batteries.RBNode.RedRed p t.reverse n

full_name: Batteries.RBNode.RedRed.setBlack
code: /-- If `t` has the red-red invariant, then setting the root to black yields a balanced tree. -/
protected theorem RedRed.setBlack : t.RedRed p n → ∃ n', (setBlack t).Balanced black n'
  
goal: ∀ {α : Type u_1} {t : Batteries.RBNode α} {p : Prop} {n : Nat},
  Batteries.RBNode.RedRed p t n → ∃ n', t.setBlack.Balanced Batteries.RBColor.black n'

full_name: Batteries.RBNode.RedRed.balance1
code: /-- The `balance1` function repairs the balance invariant when the first argument is red-red. -/
protected theorem RedRed.balance1 {l : RBNode α} {v : α} {r : RBNode α}
    (hl : l.RedRed p n) (hr : r.Balanced c n) : ∃ c, (balance1 l v r).Balanced c (n + 1) 
goal: ∃ c, (l.balance1 v r).Balanced c (n + 1)

full_name: Batteries.RBNode.RedRed.balance2
code: /-- The `balance2` function repairs the balance invariant when the second argument is red-red. -/
protected theorem RedRed.balance2 {l : RBNode α} {v : α} {r : RBNode α}
    (hl : l.Balanced c n) (hr : r.RedRed p n) : ∃ c, (balance2 l v r).Balanced c (n + 1) 
goal: ∃ c, (l.balance2 v r).Balanced c (n + 1)

full_name: Batteries.RBNode.balance1_eq
code: /-- The `balance1` function does nothing if the first argument is already balanced. -/
theorem balance1_eq {l : RBNode α} {v : α} {r : RBNode α}
    (hl : l.Balanced c n) : balance1 l v r = node black l v r 
goal: l.balance1 v r = Batteries.RBNode.node Batteries.RBColor.black l v r

full_name: Batteries.RBNode.balance2_eq
code: /-- The `balance2` function does nothing if the second argument is already balanced. -/
theorem balance2_eq {l : RBNode α} {v : α} {r : RBNode α}
    (hr : r.Balanced c n) : balance2 l v r = node black l v r 
goal: l.balance2 v r = Batteries.RBNode.node Batteries.RBColor.black l v r

full_name: Batteries.RBNode.Balanced.ins
code: /--
The balance invariant of the `ins` function.
The result of inserting into the tree either yields a balanced tree,
or a tree which is almost balanced except that it has a red-red violation at the root.
-/
protected theorem Balanced.ins (cmp v) {t : RBNode α}
    (h : t.Balanced c n) : (ins cmp v t).RedRed (t.isRed = red) n 
goal: Batteries.RBNode.RedRed (t.isRed = Batteries.RBColor.red) (Batteries.RBNode.ins cmp v t) n

full_name: Batteries.RBNode.Balanced.insert
code: /--
The `insert` function is balanced if the input is balanced.
(We lose track of both the color and the black-height of the result,
so this is only suitable for use on the root of the tree.)
-/
theorem Balanced.insert {t : RBNode α} (h : t.Balanced c n) :
    ∃ c' n', (insert cmp t v).Balanced c' n' 
goal: ∃ c' n', (Batteries.RBNode.insert cmp t v).Balanced c' n'

full_name: Batteries.RBNode.reverse_setRed
code: @[simp] theorem reverse_setRed {t : RBNode α} : (setRed t).reverse = setRed t.reverse 
goal: t.setRed.reverse = t.reverse.setRed

full_name: Batteries.RBNode.All.setRed
code: protected theorem All.setRed {t : RBNode α} (h : t.All p) : (setRed t).All p 
goal: Batteries.RBNode.All p t.setRed

full_name: Batteries.RBNode.Ordered.setRed
code: /-- The `setRed` function preserves the ordering invariants. -/
protected theorem Ordered.setRed {t : RBNode α} : (setRed t).Ordered cmp ↔ t.Ordered cmp 
goal: Batteries.RBNode.Ordered cmp t.setRed ↔ Batteries.RBNode.Ordered cmp t

full_name: Batteries.RBNode.reverse_balLeft
code: @[simp] theorem reverse_balLeft (l : RBNode α) (v : α) (r : RBNode α) :
    (balLeft l v r).reverse = balRight r.reverse v l.reverse 
goal: (l.balLeft v r).reverse = r.reverse.balRight v l.reverse

full_name: Batteries.RBNode.reverse_balRight
code: @[simp] theorem reverse_balRight (l : RBNode α) (v : α) (r : RBNode α) :
    (balRight l v r).reverse = balLeft r.reverse v l.reverse 
goal: (l.balRight v r).reverse = r.reverse.balLeft v l.reverse

full_name: Batteries.RBNode.All.balLeft
code: protected theorem All.balLeft
    (hl : l.All p) (hv : p v) (hr : r.All p) : (balLeft l v r).All p 
goal: ∀ {α : Type u_1} {p : α → Prop} {l : Batteries.RBNode α} {v : α} {r : Batteries.RBNode α},
  Batteries.RBNode.All p l → p v → Batteries.RBNode.All p r → Batteries.RBNode.All p (l.balLeft v r)

full_name: Batteries.RBNode.Ordered.balLeft
code: /-- The `balLeft` function preserves the ordering invariants. -/
protected theorem Ordered.balLeft {l : RBNode α} {v : α} {r : RBNode α}
    (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
    (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balLeft l v r).Ordered cmp 
goal: Batteries.RBNode.Ordered cmp (l.balLeft v r)

full_name: Batteries.RBNode.Balanced.balLeft
code: /-- The balancing properties of the `balLeft` function. -/
protected theorem Balanced.balLeft (hl : l.RedRed True n) (hr : r.Balanced cr (n + 1)) :
    (balLeft l v r).RedRed (cr = red) (n + 1) 
goal: ∀ {α : Type u_1} {l : Batteries.RBNode α} {v : α} {r : Batteries.RBNode α} {cr : Batteries.RBColor} {n : Nat},
  Batteries.RBNode.RedRed True l n →
    r.Balanced cr (n + 1) → Batteries.RBNode.RedRed (cr = Batteries.RBColor.red) (l.balLeft v r) (n + 1)

full_name: Batteries.RBNode.All.balRight
code: protected theorem All.balRight
    (hl : l.All p) (hv : p v) (hr : r.All p) : (balRight l v r).All p 
goal: ∀ {α : Type u_1} {p : α → Prop} {l : Batteries.RBNode α} {v : α} {r : Batteries.RBNode α},
  Batteries.RBNode.All p l → p v → Batteries.RBNode.All p r → Batteries.RBNode.All p (l.balRight v r)

full_name: Batteries.RBNode.Ordered.balRight
code: /-- The `balRight` function preserves the ordering invariants. -/
protected theorem Ordered.balRight {l : RBNode α} {v : α} {r : RBNode α}
    (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
    (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balRight l v r).Ordered cmp 
goal: Batteries.RBNode.Ordered cmp (l.balRight v r)

full_name: Batteries.RBNode.Balanced.balRight
code: /-- The balancing properties of the `balRight` function. -/
protected theorem Balanced.balRight (hl : l.Balanced cl (n + 1)) (hr : r.RedRed True n) :
    (balRight l v r).RedRed (cl = red) (n + 1) 
goal: ∀ {α : Type u_1} {l : Batteries.RBNode α} {v : α} {r : Batteries.RBNode α} {cl : Batteries.RBColor} {n : Nat},
  l.Balanced cl (n + 1) →
    Batteries.RBNode.RedRed True r n → Batteries.RBNode.RedRed (cl = Batteries.RBColor.red) (l.balRight v r) (n + 1)

full_name: Batteries.RBNode.All.append
code: protected theorem All.append (hl : l.All p) (hr : r.All p) : (append l r).All p 
goal: ∀ {α : Type u_1} {l r : Batteries.RBNode α} {p : α → Prop},
  Batteries.RBNode.All p l → Batteries.RBNode.All p r → Batteries.RBNode.All p (l.append r)

full_name: Batteries.RBNode.Ordered.append
code: /-- The `append` function preserves the ordering invariants. -/
protected theorem Ordered.append {l : RBNode α} {v : α} {r : RBNode α}
    (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
    (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (append l r).Ordered cmp 
goal: Batteries.RBNode.Ordered cmp (l.append r)

full_name: Batteries.RBNode.Balanced.append
code: /-- The balance properties of the `append` function. -/
protected theorem Balanced.append {l r : RBNode α}
    (hl : l.Balanced c₁ n) (hr : r.Balanced c₂ n) :
    (l.append r).RedRed (c₁ = black → c₂ ≠ black) n 
goal: Batteries.RBNode.RedRed (c₁ = Batteries.RBColor.black → c₂ ≠ Batteries.RBColor.black) (l.append r) n

full_name: Batteries.RBNode.DelProp
code: /--
The invariant of the `del` function.
* If the input tree is black, then the result of deletion is a red-red tree with
  black-height lowered by 1.
* If the input tree is red or nil, then the result of deletion is a balanced tree with
  some color and the same black-height.
-/
def DelProp (p : RBColor) (t : RBNode α) (n : Nat) : Prop 
goal: Prop

full_name: Batteries.RBNode.DelProp.redred
code: /-- The `DelProp` property is a strengthened version of the red-red invariant. -/
theorem DelProp.redred (h : DelProp c t n) : ∃ n', RedRed (c = black) t n' 
goal: ∀ {α : Type u_1} {t : Batteries.RBNode α} {n : Nat},
  Batteries.RBNode.DelProp c t n → ∃ n', Batteries.RBNode.RedRed (c = Batteries.RBColor.black) t n'

full_name: Batteries.RBNode.All.del
code: protected theorem All.del : ∀ {t : RBNode α}, t.All p → (del cut t).All p
  
goal: Batteries.RBNode.All p t → Batteries.RBNode.All p (Batteries.RBNode.del cut t)

full_name: Batteries.RBNode.Ordered.del
code: /-- The `del` function preserves the ordering invariants. -/
protected theorem Ordered.del : ∀ {t : RBNode α}, t.Ordered cmp → (del cut t).Ordered cmp
  
goal: Batteries.RBNode.Ordered cmp t → Batteries.RBNode.Ordered cmp (Batteries.RBNode.del cut t)

full_name: Batteries.RBNode.Balanced.del
code: /-- The `del` function has the `DelProp` property. -/
protected theorem Balanced.del {t : RBNode α} (h : t.Balanced c n) :
    (t.del cut).DelProp t.isBlack n 
goal: Batteries.RBNode.DelProp t.isBlack (Batteries.RBNode.del cut t) n

full_name: Batteries.RBNode.Ordered.erase
code: /-- The `erase` function preserves the ordering invariants. -/
protected theorem Ordered.erase {t : RBNode α} (h : t.Ordered cmp) : (erase cut t).Ordered cmp 
goal: Batteries.RBNode.Ordered cmp (Batteries.RBNode.erase cut t)

full_name: Batteries.RBNode.Balanced.erase
code: /-- The `erase` function preserves the balance invariants. -/
protected theorem Balanced.erase {t : RBNode α}
    (h : t.Balanced c n) : ∃ n, (t.erase cut).Balanced black n 
goal: ∃ n, (Batteries.RBNode.erase cut t).Balanced Batteries.RBColor.black n

full_name: Batteries.RBNode.WF.out
code: /-- The well-formedness invariant implies the ordering and balance properties. -/
theorem WF.out {t : RBNode α} (h : t.WF cmp) : t.Ordered cmp ∧ ∃ c n, t.Balanced c n 
goal: Batteries.RBNode.Ordered cmp t ∧ ∃ c n, t.Balanced c n

full_name: Batteries.RBNode.WF_iff
code: /--
The well-formedness invariant for a red-black tree is exactly the `mk` constructor,
because the other constructors of `WF` are redundant.
-/
@[simp] theorem WF_iff {t : RBNode α} : t.WF cmp ↔ t.Ordered cmp ∧ ∃ c n, t.Balanced c n 
goal: Batteries.RBNode.WF cmp t ↔ Batteries.RBNode.Ordered cmp t ∧ ∃ c n, t.Balanced c n

full_name: Batteries.RBNode.Balanced.map
code: /-- The `map` function preserves the balance invariants. -/
protected theorem Balanced.map {t : RBNode α} : t.Balanced c n → (t.map f).Balanced c n
  
goal: ∀ {α_1 : Type u_2} {f : α → α_1} {t : Batteries.RBNode α}, t.Balanced c n → (Batteries.RBNode.map f t).Balanced c n

full_name: Batteries.RBNode.IsMonotone.lt_mono
code: /-- The property of a map function `f` which ensures the `map` operation is valid. -/
class IsMonotone (cmpα cmpβ) (f : α → β) : Prop where
  /-- If `x < y` then `f x < f y`. -/
  lt_mono : cmpLT cmpα x y → cmpLT cmpβ (f x) (f y)
goal: Batteries.RBNode.cmpLT cmpα x y → Batteries.RBNode.cmpLT cmpβ (f x) (f y)

full_name: Batteries.RBNode.IsMonotone
code: /-- The property of a map function `f` which ensures the `map` operation is valid. -/
class IsMonotone (cmpα cmpβ) (f : α → β) : Prop where
  /-- If `x < y` then `f x < f y`. -/
  lt_mono : cmpLT cmpα x y → cmpLT cmpβ (f x) (f y)
goal: Prop

full_name: Batteries.RBNode.All.map
code: /-- Sufficient condition for `map` to preserve an `All` quantifier. -/
protected theorem All.map {f : α → β} (H : ∀ {x}, p x → q (f x)) :
    ∀ {t : RBNode α}, t.All p → (t.map f).All q
  
goal: Batteries.RBNode.All p t → Batteries.RBNode.All q (Batteries.RBNode.map f t)

full_name: Batteries.RBNode.Ordered.map
code: /-- The `map` function preserves the order invariants if `f` is monotone. -/
protected theorem Ordered.map (f : α → β) [IsMonotone cmpα cmpβ f] :
    ∀ {t : RBNode α}, t.Ordered cmpα → (t.map f).Ordered cmpβ
  
goal: Batteries.RBNode.Ordered cmpα t → Batteries.RBNode.Ordered cmpβ (Batteries.RBNode.map f t)

full_name: Batteries.RBSet.mapMonotone
code: /--
`O(n)`. Map a function on every value in the set.
This requires `IsMonotone` on the function in order to preserve the order invariant.
If the function is not monotone, use `RBSet.map` instead.
-/
@[inline] def mapMonotone (f : α → β) [IsMonotone cmpα cmpβ f] (t : RBSet α cmpα) : RBSet β cmpβ 
goal: Batteries.RBSet β cmpβ

full_name: Batteries.RBMap.Imp.mapSnd
code: /--
Applies `f` to the second component.
We extract this as a function so that `IsMonotone (mapSnd f)` can be an instance.
-/
@[inline] def mapSnd (f : α → β → γ) 
goal: α × β → α × γ

full_name: Batteries.RBMap.Imp.instIsMonotoneProdByKeyFstMapSnd
code: instance (cmp : α → α → Ordering) (f : α → β → γ) :
    IsMonotone (byKey Prod.fst cmp) (byKey Prod.fst cmp) (mapSnd f) 
goal: Batteries.RBSet.IsMonotone (Ordering.byKey Prod.fst cmp) (Ordering.byKey Prod.fst cmp) (Batteries.RBMap.Imp.mapSnd f)

full_name: Batteries.RBMap.mapVal
code: /-- `O(n)`. Map a function on the values in the map. -/
def mapVal (f : α → β → γ) (t : RBMap α β cmp) : RBMap α γ cmp 
goal: Batteries.RBMap α γ cmp