Theorem: Batteries.RBNode.Ordered.upperBound?_exists
File: .lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean

tactic: refine ⟨fun ⟨x, hx⟩ => ⟨_, upperBound?_mem hx, upperBound?_ge hx⟩, fun H => ?_⟩
state_before: α : 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
state_after: α : 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

tactic: obtain ⟨x, hx, e⟩ := H
state_before: α : 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
state_after: case intro.intro
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
t : RBNode α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
h : Ordered cmp t
x : α
hx : x ∈ t
e : cut x ≠ Ordering.gt
⊢ ∃ x, upperBound? cut t = some x

tactic: cases hx
state_before: 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
state_after: no goals

tactic: simp [upperBound?]
state_before: 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, upperBound? cut (node c✝ l✝ v✝ r✝) = some x
state_after: 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
state_before: 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
state_after: 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

tactic: exact upperBound?_of_some
state_before: 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
state_after: no goals

tactic: rcases hx with rfl | hx | hx
state_before: 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
state_after: 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

tactic: contradiction
state_before: 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
state_after: no goals

tactic: next hv => cases e <| IsCut.gt_trans (All_def.1 h.1 _ hx).1 hv
state_before: 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
state_after: no goals

tactic: cases e <| IsCut.gt_trans (All_def.1 h.1 _ hx).1 hv
state_before: α : 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
hv : cut v✝ = Ordering.gt
hx : Any (fun x_1 => x = x_1) l✝
⊢ ∃ x, upperBound? cut r✝ = some x
state_after: no goals

tactic: exact ihr h.2.2.2 _ hx e
state_before: 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
state_after: no goals

tactic: exact ⟨_, rfl⟩
state_before: 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
state_after: no goals