-- Mathlib/.lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean
theorem Ordered.upperBound?_least_ub [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t)
    (hub : ∀ {x}, ub = some x → t.All (cmpLT cmp · x)) :
    t.upperBound? cut ub = some x → y ∈ t → cut x = .lt → cmp y x = .lt → cut y = .gt

Proof state:
case node.h_1.inr.inr
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x y : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
ihl :
  ∀ {ub : Option α},
    Ordered cmp l✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) l✝) →
        upperBound? cut l✝ ub = some x → y ∈ l✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ihr :
  ∀ {ub : Option α},
    Ordered cmp r✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) r✝) →
        upperBound? cut r✝ ub = some x → y ∈ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ub : Option α
h : Ordered cmp (node c✝ l✝ v✝ r✝)
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) (node c✝ l✝ v✝ r✝)
x✝ : Ordering
hv : cut v✝ = Ordering.lt
h₁ : upperBound? cut l✝ (some v✝) = some x
hy' : y ∈ r✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
this : cmp v✝ y = Ordering.lt
⊢ cmp x y = Ordering.lt

Tactic:
rcases upperBound?_mem_ub h₁ with h₁ | ⟨⟨⟩⟩

Result:
case node.h_1.inr.inr.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x y : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
ihl :
  ∀ {ub : Option α},
    Ordered cmp l✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) l✝) →
        upperBound? cut l✝ ub = some x → y ∈ l✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ihr :
  ∀ {ub : Option α},
    Ordered cmp r✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) r✝) →
        upperBound? cut r✝ ub = some x → y ∈ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ub : Option α
h : Ordered cmp (node c✝ l✝ v✝ r✝)
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) (node c✝ l✝ v✝ r✝)
x✝ : Ordering
hv : cut v✝ = Ordering.lt
h₁✝ : upperBound? cut l✝ (some v✝) = some x
hy' : y ∈ r✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
this : cmp v✝ y = Ordering.lt
h₁ : x ∈ l✝
⊢ cmp x y = Ordering.lt

case node.h_1.inr.inr.inr.refl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x y : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ r✝ : RBNode α
ihl :
  ∀ {ub : Option α},
    Ordered cmp l✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) l✝) →
        upperBound? cut l✝ ub = some x → y ∈ l✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ihr :
  ∀ {ub : Option α},
    Ordered cmp r✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) r✝) →
        upperBound? cut r✝ ub = some x → y ∈ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ub : Option α
x✝ : Ordering
hy' : y ∈ r✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
h : Ordered cmp (node c✝ l✝ x r✝)
hub : ∀ {x_1 : α}, ub = some x_1 → All (fun x => cmpLT cmp x x_1) (node c✝ l✝ x r✝)
hv : cut x = Ordering.lt
h₁ : upperBound? cut l✝ (some x) = some x
this : cmp x y = Ordering.lt
⊢ cmp x y = Ordering.lt

Proof state:
case node
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x y : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
ihl :
  ∀ {ub : Option α},
    Ordered cmp l✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) l✝) →
        upperBound? cut l✝ ub = some x → y ∈ l✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ihr :
  ∀ {ub : Option α},
    Ordered cmp r✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) r✝) →
        upperBound? cut r✝ ub = some x → y ∈ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ub : Option α
h : Ordered cmp (node c✝ l✝ v✝ r✝)
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) (node c✝ l✝ v✝ r✝)
⊢ upperBound? cut (node c✝ l✝ v✝ r✝) ub = some x →
    y ∈ node c✝ l✝ v✝ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt

Tactic:
simp [upperBound?]

Result:
case node
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x y : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
ihl :
  ∀ {ub : Option α},
    Ordered cmp l✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) l✝) →
        upperBound? cut l✝ ub = some x → y ∈ l✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ihr :
  ∀ {ub : Option α},
    Ordered cmp r✝ →
      (∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) r✝) →
        upperBound? cut r✝ ub = some x → y ∈ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt
ub : Option α
h : Ordered cmp (node c✝ l✝ v✝ r✝)
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) (node c✝ l✝ v✝ r✝)
⊢ (match cut v✝ with
      | Ordering.lt => upperBound? cut l✝ (some v✝)
      | Ordering.gt => upperBound? cut r✝ ub
      | Ordering.eq => some v✝) =
      some x →
    y = v✝ ∨ y ∈ l✝ ∨ y ∈ r✝ → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt