-- 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:
α : 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

Tactic:
rcases H with ev' | hx | hx

Result:
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.lt
ev' : cut v✝ = Ordering.eq
⊢ MemP cut l

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

case inr.inr
α : 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) r
⊢ MemP cut l

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

Tactic:
exact ⟨_, rfl⟩

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)
⊢ ∃ x,
    (match cut v✝ with
      | Ordering.lt => find? cut l
      | Ordering.gt => find? cut r
      | Ordering.eq => some v✝) =
      some x

Tactic:
let ⟨lx, xr, hl, hr⟩ := ht

Result:
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

Proof state:
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
t : RBNode α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
ht : Ordered cmp t
⊢ MemP cut t ↔ ∃ x, find? cut t = some x

Tactic:
refine ⟨fun H => ?_, fun ⟨x, h⟩ => find?_some_memP h⟩

Result:
α : Type u_1
cmp : α → α → Ordering
cut : α → Ordering
t : RBNode α
inst✝¹ : TransCmp cmp
inst✝ : IsCut cmp cut
ht : Ordered cmp t
H : MemP cut t
⊢ ∃ x, find? cut t = some x

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
z : α
hz : z ∈ l
ez : cut z = Ordering.eq
⊢ MemP cut r

Tactic:
cases ez.symm.trans <| IsCut.gt_trans (All_def.1 lx _ hz).1 ev

Result:
no goals

Proof state:
case inr.inr
α : 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) r
⊢ MemP cut r

Tactic:
exact hx

Result:
no goals

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.lt
ev' : cut v✝ = Ordering.eq
⊢ MemP cut l

Tactic:
cases ev.symm.trans ev'

Result:
no goals

Proof state:
case inr.inr
α : 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) r
z : α
hz : z ∈ r
ez : cut z = Ordering.eq
⊢ MemP cut l

Tactic:
cases ez.symm.trans <| IsCut.lt_trans (All_def.1 xr _ hz).1 ev

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.gt
⊢ ∃ x, find? cut r = some x

Tactic:
refine ihr hr ?_

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.gt
⊢ MemP cut r