-- 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.inl.inr.refl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ r✝ : RBNode α
ub : Option α
x✝ : Ordering
hx : cut x = Ordering.lt
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 → x ∈ l✝ → cut x = Ordering.lt → cmp x x = Ordering.lt → cut x = 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 → x ∈ r✝ → cut x = Ordering.lt → cmp x x = Ordering.lt → cut x = Ordering.gt
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
h₂ : cmp x x = Ordering.lt
⊢ cut x = Ordering.gt

Tactic:
cases TransCmp.lt_asymm h₂ h₂

Result:
no goals

Proof state:
case refl
α : 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 ∈ l✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
⊢ All (fun x => cmpLT cmp x v✝) l✝

Tactic:
exact h.1

Result:
no goals

Proof state:
α : 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 ∈ l✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
⊢ ∀ {x : α}, some v✝ = some x → All (fun x_1 => cmpLT cmp x_1 x) l✝

Tactic:
rintro _ ⟨⟨⟩⟩

Result:
case refl
α : 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 ∈ l✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
⊢ All (fun x => cmpLT cmp x v✝) l✝

Proof state:
case node.h_1.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 ∈ l✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
⊢ cut y = Ordering.gt

Tactic:
exact ihl h.2.2.1 (by rintro _ ⟨⟨⟩⟩; exact h.1) h₁ hy' hx h₂

Result:
no goals

Proof state:
case node.h_3.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.eq
h₁ : some v✝ = some x
hy' : y ∈ r✝
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
⊢ cut y = Ordering.gt

Tactic:
cases h₁

Result:
case node.h_3.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.eq
⊢ cut y = Ordering.gt