-- Mathlib/.lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean
theorem Ordered.upperBound?_exists [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) :
    (∃ x, t.upperBound? cut = some x) ↔ ∃ x ∈ t, cut x ≠ .gt

Proof state:
case intro.intro.node.h_2.inr.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
hx : Any (fun x_1 => x = x_1) l✝
⊢ ∃ x, upperBound? cut r✝ = some x

Tactic:
next hv => cases e <| IsCut.gt_trans (All_def.1 h.1 _ hx).1 hv

Result:
no goals

Proof state:
case intro.intro.nil
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
h : Ordered cmp nil
x : α
hx : x ∈ nil
e : cut x ≠ Ordering.gt
⊢ ∃ x, upperBound? cut nil = some x

Tactic:
cases hx

Result:
no goals

Proof state:
case intro.intro.node.h_2.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
x : α
e : cut x ≠ Ordering.gt
x✝ : Ordering
h : Ordered cmp (node c✝ l✝ x r✝)
heq✝ : cut x = Ordering.gt
⊢ ∃ x, upperBound? cut r✝ = some x

Tactic:
contradiction

Result:
no goals

Proof state:
case intro.intro.node
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
hx : x ∈ node c✝ l✝ v✝ r✝
e : cut x ≠ Ordering.gt
⊢ ∃ x,
    (match cut v✝ with
      | Ordering.lt => upperBound? cut l✝ (some v✝)
      | Ordering.gt => upperBound? cut r✝
      | Ordering.eq => some v✝) =
      some x

Tactic:
split

Result:
case intro.intro.node.h_1
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
hx : x ∈ node c✝ l✝ v✝ r✝
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.lt
⊢ ∃ x, upperBound? cut l✝ (some v✝) = some x

case intro.intro.node.h_2
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
hx : x ∈ node c✝ l✝ v✝ r✝
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
⊢ ∃ x, upperBound? cut r✝ = some x

case intro.intro.node.h_3
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
hx : x ∈ node c✝ l✝ v✝ r✝
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.eq
⊢ ∃ x, some v✝ = some x

Proof state:
case intro.intro.node.h_2
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
hx : x ∈ node c✝ l✝ v✝ r✝
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
⊢ ∃ x, upperBound? cut r✝ = some x

Tactic:
rcases hx with rfl | hx | hx

Result:
case intro.intro.node.h_2.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
x : α
e : cut x ≠ Ordering.gt
x✝ : Ordering
h : Ordered cmp (node c✝ l✝ x r✝)
heq✝ : cut x = Ordering.gt
⊢ ∃ x, upperBound? cut r✝ = some x

case intro.intro.node.h_2.inr.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
hx : Any (fun x_1 => x = x_1) l✝
⊢ ∃ x, upperBound? cut r✝ = some x

case intro.intro.node.h_2.inr.inr
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
hx : Any (fun x_1 => x = x_1) r✝
⊢ ∃ x, upperBound? cut r✝ = some x

Proof state:
case intro.intro.node.h_2.inr.inr
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
hx : Any (fun x_1 => x = x_1) r✝
⊢ ∃ x, upperBound? cut r✝ = some x

Tactic:
exact ihr h.2.2.2 _ hx e

Result:
no goals

Proof state:
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
t : RBNode α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
h : Ordered cmp t
⊢ (∃ x, upperBound? cut t = some x) ↔ ∃ x, x ∈ t ∧ cut x ≠ Ordering.gt

Tactic:
refine ⟨fun ⟨x, hx⟩ => ⟨_, upperBound?_mem hx, upperBound?_ge hx⟩, fun H => ?_⟩

Result:
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
t : RBNode α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
h : Ordered cmp t
H : ∃ x, x ∈ t ∧ cut x ≠ Ordering.gt
⊢ ∃ x, upperBound? cut t = some x

Proof state:
case intro.intro.node.h_1
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
l_ih✝ : Ordered cmp l✝ → ∀ (x : α), x ∈ l✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut l✝ = some x
ihr : Ordered cmp r✝ → ∀ (x : α), x ∈ r✝ → cut x ≠ Ordering.gt → ∃ x, upperBound? cut r✝ = some x
h : Ordered cmp (node c✝ l✝ v✝ r✝)
x : α
hx : x ∈ node c✝ l✝ v✝ r✝
e : cut x ≠ Ordering.gt
x✝ : Ordering
heq✝ : cut v✝ = Ordering.lt
⊢ ∃ x, upperBound? cut l✝ (some v✝) = some x

Tactic:
exact upperBound?_of_some

Result:
no goals