-- 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 nil
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
x y : α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
ub : Option α
h : Ordered cmp nil
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) nil
⊢ upperBound? cut nil ub = some x → y ∈ nil → cut x = Ordering.lt → cmp y x = Ordering.lt → cut y = Ordering.gt

Tactic:
nofun

Result:
no goals

Proof state:
case node.h_3.inl
α : 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
h : Ordered cmp (node c✝ l✝ y r✝)
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) (node c✝ l✝ y r✝)
hv : cut y = Ordering.eq
h₁ : some y = some x
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
⊢ cut y = Ordering.gt

Tactic:
cases h₁

Result:
case node.h_3.inl.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.eq
h₂ : cmp x x = Ordering.lt
⊢ cut x = Ordering.gt

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

Tactic:
exact ihr h.2.2.2 (fun h => (hub h).2.2) h₁ hy' hx h₂

Result:
no goals

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

Tactic:
cases h₁

Result:
case node.h_3.inr.inl.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 ∈ l✝
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

Proof state:
case node.h_1.inl.inl
α : 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
h : Ordered cmp (node c✝ l✝ y r✝)
hub : ∀ {x : α}, ub = some x → All (fun x_1 => cmpLT cmp x_1 x) (node c✝ l✝ y r✝)
hv : cut y = Ordering.lt
h₁✝ : upperBound? cut l✝ (some y) = some x
hx : cut x = Ordering.lt
h₂ : cmp y x = Ordering.lt
h₁ : x ∈ l✝
⊢ cut y = Ordering.gt

Tactic:
cases TransCmp.lt_asymm h₂ (All_def.1 h.1 _ h₁).1

Result:
no goals

Proof state:
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

Tactic:
cases hx.symm.trans hv

Result:
no goals