Theorem: Std.RBNode.Ordered.balance2
File: Std/Data/RBMap/WF.lean

tactic: unfold balance2
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
r : RBNode α
lv : All (fun x => cmpLT cmp x v) l
vr : All (fun x => cmpLT cmp v x) r
hl : Ordered cmp l
hr : Ordered cmp r
⊢ Ordered cmp (balance2 l v r)

tactic: split
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
r : RBNode α
lv : All (fun x => cmpLT cmp x v) l
vr : All (fun x => cmpLT cmp v x) r
hl : Ordered cmp l
hr : Ordered cmp r
⊢ Ordered cmp
    (match l, v, r with
    | a, x, node red (node red b y c) z d => node red (node black a x b) y (node black c z d)
    | a, x, node red b y (node red c z d) => node red (node black a x b) y (node black c z d)
    | a, x, b => node black a x b)

tactic: next b y c z d =>
have ⟨_, ⟨vy, vb, _⟩, _⟩ := vr; have ⟨⟨yz, _, cz⟩, zd, ⟨by_, yc, hy, hz⟩, hd⟩ := hr
exact ⟨⟨vy, vy.trans_r lv, by_⟩, ⟨yz, yc, yz.trans_l zd⟩, ⟨lv, vb, hl, hy⟩, cz, zd, hz, hd⟩
state_before: case h_1
α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝² : RBNode α
x✝¹ : α
x✝ b✝ : RBNode α
y✝ : α
c✝ : RBNode α
z✝ : α
d✝ : RBNode α
vr : All (fun x => cmpLT cmp v x) (node red (node red b✝ y✝ c✝) z✝ d✝)
hr : Ordered cmp (node red (node red b✝ y✝ c✝) z✝ d✝)
⊢ Ordered cmp (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝))

tactic: have ⟨_, ⟨vy, vb, _⟩, _⟩ := vr
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝² : RBNode α
x✝¹ : α
x✝ b : RBNode α
y : α
c : RBNode α
z : α
d : RBNode α
vr : All (fun x => cmpLT cmp v x) (node red (node red b y c) z d)
hr : Ordered cmp (node red (node red b y c) z d)
⊢ Ordered cmp (node red (node black l v b) y (node black c z d))

tactic: have ⟨⟨yz, _, cz⟩, zd, ⟨by_, yc, hy, hz⟩, hd⟩ := hr
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝² : RBNode α
x✝¹ : α
x✝ b : RBNode α
y : α
c : RBNode α
z : α
d : RBNode α
vr : All (fun x => cmpLT cmp v x) (node red (node red b y c) z d)
hr : Ordered cmp (node red (node red b y c) z d)
left✝ : (fun x => cmpLT cmp v x) z
vy : (fun x => cmpLT cmp v x) y
vb : All (fun x => cmpLT cmp v x) b
right✝¹ : All (fun x => cmpLT cmp v x) c
right✝ : All (fun x => cmpLT cmp v x) d
⊢ Ordered cmp (node red (node black l v b) y (node black c z d))

tactic: exact ⟨⟨vy, vy.trans_r lv, by_⟩, ⟨yz, yc, yz.trans_l zd⟩, ⟨lv, vb, hl, hy⟩, cz, zd, hz, hd⟩
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝² : RBNode α
x✝¹ : α
x✝ b : RBNode α
y : α
c : RBNode α
z : α
d : RBNode α
vr : All (fun x => cmpLT cmp v x) (node red (node red b y c) z d)
hr : Ordered cmp (node red (node red b y c) z d)
left✝¹ : (fun x => cmpLT cmp v x) z
vy : (fun x => cmpLT cmp v x) y
vb : All (fun x => cmpLT cmp v x) b
right✝¹ : All (fun x => cmpLT cmp v x) c
right✝ : All (fun x => cmpLT cmp v x) d
yz : (fun x => cmpLT cmp x z) y
left✝ : All (fun x => cmpLT cmp x z) b
cz : All (fun x => cmpLT cmp x z) c
zd : All (fun x => cmpLT cmp z x) d
by_ : All (fun x => cmpLT cmp x y) b
yc : All (fun x => cmpLT cmp y x) c
hy : Ordered cmp b
hz : Ordered cmp c
hd : Ordered cmp d
⊢ Ordered cmp (node red (node black l v b) y (node black c z d))

tactic: next a x b y c _ =>
have ⟨vx, va, _⟩ := vr; have ⟨ax, xy, ha, hy⟩ := hr
exact ⟨⟨vx, vx.trans_r lv, ax⟩, xy, ⟨lv, va, hl, ha⟩, hy⟩
state_before: case h_2
α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝³ : RBNode α
x✝² : α
x✝¹ b✝ : RBNode α
y✝ : α
c✝ : RBNode α
z✝ : α
d✝ : RBNode α
x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), b✝ = node red b y c → False
vr : All (fun x => cmpLT cmp v x) (node red b✝ y✝ (node red c✝ z✝ d✝))
hr : Ordered cmp (node red b✝ y✝ (node red c✝ z✝ d✝))
⊢ Ordered cmp (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝))

tactic: have ⟨vx, va, _⟩ := vr
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝³ : RBNode α
x✝² : α
x✝¹ a : RBNode α
x : α
b : RBNode α
y : α
c : RBNode α
x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), a = node red b y c → False
vr : All (fun x => cmpLT cmp v x) (node red a x (node red b y c))
hr : Ordered cmp (node red a x (node red b y c))
⊢ Ordered cmp (node red (node black l v a) x (node black b y c))

tactic: have ⟨ax, xy, ha, hy⟩ := hr
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝³ : RBNode α
x✝² : α
x✝¹ a : RBNode α
x : α
b : RBNode α
y : α
c : RBNode α
x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), a = node red b y c → False
vr : All (fun x => cmpLT cmp v x) (node red a x (node red b y c))
hr : Ordered cmp (node red a x (node red b y c))
vx : (fun x => cmpLT cmp v x) x
va : All (fun x => cmpLT cmp v x) a
right✝ : All (fun x => cmpLT cmp v x) (node red b y c)
⊢ Ordered cmp (node red (node black l v a) x (node black b y c))

tactic: exact ⟨⟨vx, vx.trans_r lv, ax⟩, xy, ⟨lv, va, hl, ha⟩, hy⟩
state_before: α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
lv : All (fun x => cmpLT cmp x v) l
hl : Ordered cmp l
x✝³ : RBNode α
x✝² : α
x✝¹ a : RBNode α
x : α
b : RBNode α
y : α
c : RBNode α
x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α), a = node red b y c → False
vr : All (fun x => cmpLT cmp v x) (node red a x (node red b y c))
hr : Ordered cmp (node red a x (node red b y c))
vx : (fun x => cmpLT cmp v x) x
va : All (fun x => cmpLT cmp v x) a
right✝ : All (fun x => cmpLT cmp v x) (node red b y c)
ax : All (fun x_1 => cmpLT cmp x_1 x) a
xy : All (fun x_1 => cmpLT cmp x x_1) (node red b y c)
ha : Ordered cmp a
hy : Ordered cmp (node red b y c)
⊢ Ordered cmp (node red (node black l v a) x (node black b y c))

tactic: exact ⟨lv, vr, hl, hr⟩
state_before: case h_3
α : Type u_1
cmp : α → α → Ordering
l : RBNode α
v : α
r : RBNode α
lv : All (fun x => cmpLT cmp x v) l
vr : All (fun x => cmpLT cmp v x) r
hl : Ordered cmp l
hr : Ordered cmp r
x✝⁴ : RBNode α
x✝³ : α
x✝² : RBNode α
x✝¹ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False
x✝ : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False
⊢ Ordered cmp (node black l v r)