-- Mathlib/.lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean
theorem Ordered.memP_iff_find? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) :
    MemP cut t ↔ ∃ x, t.find? cut = some x

Proof state:
case inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
ev : cut v✝ = Ordering.gt
ev' : cut v✝ = Ordering.eq
⊢ MemP cut r

Tactic:
cases ev.symm.trans ev'

Result:
no goals

Proof state:
case inr.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
ev : cut v✝ = Ordering.lt
hx : Any (fun x => cut x = Ordering.eq) l
⊢ MemP cut l

Tactic:
exact hx

Result:
no goals

Proof state:
case node
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
H : MemP cut (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
⊢ ∃ x,
    (match cut v✝ with
      | Ordering.lt => find? cut l
      | Ordering.gt => find? cut r
      | Ordering.eq => some v✝) =
      some x

Tactic:
split

Result:
case node.h_1
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
H : MemP cut (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
heq✝ : cut v✝ = Ordering.lt
⊢ ∃ x, find? cut l = some x

case node.h_2
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
H : MemP cut (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
heq✝ : cut v✝ = Ordering.gt
⊢ ∃ x, find? cut r = some x

case node.h_3
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
H : MemP cut (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
heq✝ : cut v✝ = Ordering.eq
⊢ ∃ x, some v✝ = some x

Proof state:
case nil
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
ht : Ordered cmp nil
H : MemP cut nil
⊢ False

Tactic:
cases H

Result:
no goals

Proof state:
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
H : MemP cut (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
ev : cut v✝ = Ordering.lt
⊢ ∃ x, find? cut l = some x

Tactic:
refine ihl hl ?_

Result:
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
H : MemP cut (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
ev : cut v✝ = Ordering.lt
⊢ MemP cut l

Proof state:
case inr.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
ev : cut v✝ = Ordering.gt
hx : Any (fun x => cut x = Ordering.eq) l
⊢ MemP cut r

Tactic:
have ⟨z, hz, ez⟩ := Any_def.1 hx

Result:
case inr.inl
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
c✝ : RBColor
l : RBNode α
v✝ : α
r : RBNode α
ihl : Ordered cmp l → MemP cut l → ∃ x, find? cut l = some x
ihr : Ordered cmp r → MemP cut r → ∃ x, find? cut r = some x
ht : Ordered cmp (node c✝ l v✝ r)
lx : All (fun x => cmpLT cmp x v✝) l
xr : All (fun x => cmpLT cmp v✝ x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝ : Ordering
ev : cut v✝ = Ordering.gt
hx : Any (fun x => cut x = Ordering.eq) l
z : α
hz : z ∈ l
ez : cut z = Ordering.eq
⊢ MemP cut r