Theorem: Batteries.RBNode.Balanced.append
File: .lake/packages/batteries/Batteries/Data/RBMap/WF.lean

tactic: unfold append
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l r : RBNode α
hl : l.Balanced c₁ n
hr : r.Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (l.append r) n
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l r : RBNode α
hl : l.Balanced c₁ n
hr : r.Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match l, r with
    | nil, x => x
    | x, nil => x
    | node red a x b, node red c y d =>
      match b.append c with
      | node red b' z c' => node red (node red a x b') z (node red c' y d)
      | bc => node red a x (node red bc y d)
    | node black a x b, node black c y d =>
      match b.append c with
      | node red b' z c' => node red (node black a x b') z (node black c' y d)
      | bc => a.balLeft x (node black bc y d)
    | a@h:(node black l v r), node red b x c => node red (a.append b) x c
    | node red a x b, c@h:(node black l v r) => node red a x (b.append c))
    n

tactic: split
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l r : RBNode α
hl : l.Balanced c₁ n
hr : r.Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match l, r with
    | nil, x => x
    | x, nil => x
    | node red a x b, node red c y d =>
      match b.append c with
      | node red b' z c' => node red (node red a x b') z (node red c' y d)
      | bc => node red a x (node red bc y d)
    | node black a x b, node black c y d =>
      match b.append c with
      | node red b' z c' => node red (node black a x b') z (node black c' y d)
      | bc => a.balLeft x (node black bc y d)
    | a@h:(node black l v r), node red b x c => node red (a.append b) x c
    | node red a x b, c@h:(node black l v r) => node red a x (b.append c))
    n
state_after: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
r : RBNode α
hr : r.Balanced c₂ n
x✝¹ x✝ : RBNode α
hl : nil.Balanced c₁ n
⊢ RedRed (c₁ = black → c₂ ≠ black) r n

case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l : RBNode α
hl : l.Balanced c₁ n
x✝² x✝¹ : RBNode α
x✝ : l = nil → False
hr : nil.Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) l n

case h_3
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node red c✝ y✝ d✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match b✝.append c✝ with
    | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝)
    | bc => node red a✝ x✝ (node red bc y✝ d✝))
    n

case h_4
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ c✝ : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b✝).Balanced c₁ n
hr : (node black c✝ y✝ d✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match b✝.append c✝ with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    n

case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
hr : (node red b✝ x✝ c✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) n

case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node black l✝ v✝ r✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) n

tactic: exact .balanced hr
state_before: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
r : RBNode α
hr : r.Balanced c₂ n
x✝¹ x✝ : RBNode α
hl : nil.Balanced c₁ n
⊢ RedRed (c₁ = black → c₂ ≠ black) r n
state_after: no goals

tactic: exact .balanced hl
state_before: case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l : RBNode α
hl : l.Balanced c₁ n
x✝² x✝¹ : RBNode α
x✝ : l = nil → False
hr : nil.Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) l n
state_after: no goals

tactic: have .red ha hb := hl
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝)
    | bc => node red a✝ x✝ (node red bc y✝ d✝))
    n
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
⊢ RedRed (red = black → c₂ ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝)
    | bc => node red a✝ x✝ (node red bc y✝ d✝))
    n

tactic: have .red hc hd := hr
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
⊢ RedRed (red = black → c₂ ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝)
    | bc => node red a✝ x✝ (node red bc y✝ d✝))
    n
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
⊢ RedRed (red = black → red ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝)
    | bc => node red a✝ x✝ (node red bc y✝ d✝))
    n

tactic: split
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
w✝ : RBColor
IH : (b.append c).Balanced w✝ n
⊢ RedRed (red = black → red ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node red a✝ x✝ b') z (node red c' y✝ d✝)
    | bc => node red a✝ x✝ (node red bc y✝ d✝))
    n
state_after: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝¹ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝¹.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
w✝ : RBColor
IH : (b.append c).Balanced w✝ n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : b.append c = node red a✝ x✝ b✝
⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n

case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
w✝ : RBColor
IH : (b.append c).Balanced w✝ n
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝¹ (node red (b.append c) y✝ d✝)) n

tactic: next e =>
have .red hb' hc' := e ▸ IH
exact .redred nofun (.red ha hb') (.red hc' hd)
state_before: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝¹ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝¹.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
w✝ : RBColor
IH : (b.append c).Balanced w✝ n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : b.append c = node red a✝ x✝ b✝
⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n
state_after: no goals

tactic: have .red hb' hc' := e ▸ IH
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝¹ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝¹.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
w✝ : RBColor
IH : (b.append c).Balanced w✝ n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : b.append c = node red a✝ x✝ b✝
⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝¹ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝¹.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : b.append c = node red a✝ x✝ b✝
hb' : a✝.Balanced black n
hc' : b✝.Balanced black n
IH : (b.append c).Balanced red n
⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n

tactic: exact .redred nofun (.red ha hb') (.red hc' hd)
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝¹ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝¹.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : b.append c = node red a✝ x✝ b✝
hb' : a✝.Balanced black n
hc' : b✝.Balanced black n
IH : (b.append c).Balanced red n
⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n
state_after: no goals

tactic: next bcc _ H =>
match bcc, append b c, IH, H with
| black, _, IH, _ => exact .redred nofun ha (.red IH hd)
| red, _, .red .., H => cases H _ _ _ rfl
state_before: case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝¹ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
w✝ : RBColor
IH : (b.append c).Balanced w✝ n
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝¹ (node red (b.append c) y✝ d✝)) n
state_after: no goals

tactic: match bcc, append b c, IH, H with
| black, _, IH, _ => exact .redred nofun ha (.red IH hd)
| red, _, .red .., H => cases H _ _ _ rfl
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝ b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
bcc : RBColor
IH : (b.append c).Balanced bcc n
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝ (node red (b.append c) y✝ d✝)) n
state_after: no goals

tactic: exact .redred nofun ha (.red IH hd)
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ a✝ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node red a✝ x✝² b).Balanced c₁ n
hr : (node red c y✝ d✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
bcc : RBColor
IH✝ : (b.append c).Balanced bcc n
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
x✝¹ : RBNode α
IH : x✝¹.Balanced black n
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), x✝¹ = node red a x b → False
⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝² (node red x✝¹ y✝ d✝)) n
state_after: no goals

tactic: cases H _ _ _ rfl
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝² : RBNode α
x✝¹ : α
b c : RBNode α
y✝¹ : α
d✝ : RBNode α
hl : (node red a✝² x✝¹ b).Balanced c₁ n
hr : (node red c y✝¹ d✝).Balanced c₂ n
ha : a✝².Balanced black n
hb : b.Balanced black n
hc : c.Balanced black n
hd : d✝.Balanced black n
bcc : RBColor
IH : (b.append c).Balanced bcc n
l✝ : RBNode α
H✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
x✝ y✝ : RBNode α
v✝ : α
a✝¹ : x✝.Balanced black n
a✝ : y✝.Balanced black n
H : ∀ (a : RBNode α) (x : α) (b : RBNode α), node red x✝ v✝ y✝ = node red a x b → False
⊢ RedRed (red = black → red ≠ black) (node red a✝² x✝¹ (node red (node red x✝ v✝ y✝) y✝¹ d✝)) n
state_after: no goals

tactic: have .black ha hb := hl
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
hr : (node black c y✝ d✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    n
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
ha : a✝.Balanced c₁✝ n✝
hb : b.Balanced c₂✝ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
⊢ RedRed (black = black → c₂ ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    (n✝ + 1)

tactic: have .black hc hd := hr
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
ha : a✝.Balanced c₁✝ n✝
hb : b.Balanced c₂✝ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
⊢ RedRed (black = black → c₂ ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    (n✝ + 1)
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
⊢ RedRed (black = black → black ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    (n✝ + 1)

tactic: have IH := hb.append hc
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
⊢ RedRed (black = black → black ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    (n✝ + 1)
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
⊢ RedRed (black = black → black ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    (n✝ + 1)

tactic: split
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
⊢ RedRed (black = black → black ≠ black)
    (match b.append c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => a✝.balLeft x✝ (node black bc y✝ d✝))
    (n✝ + 1)
state_after: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝¹ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝¹.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : b.append c = node red a✝ x✝ b✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) (n✝ + 1)

case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
⊢ RedRed (black = black → black ≠ black) (a✝.balLeft x✝¹ (node black (b.append c) y✝ d✝)) (n✝ + 1)

tactic: next e => match e ▸ IH with
| .balanced (.red hb' hc') | .redred _ hb' hc' =>
  exact .balanced (.red (.black ha hb') (.black hc' hd))
state_before: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝¹ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝¹.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : b.append c = node red a✝ x✝ b✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) (n✝ + 1)
state_after: no goals

tactic: match e ▸ IH with
| .balanced (.red hb' hc') | .redred _ hb' hc' =>
exact .balanced (.red (.black ha hb') (.black hc' hd))
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝¹ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝¹ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝¹.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : b.append c = node red a✝ x✝ b✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝¹ x✝¹ a✝) x✝ (node black b✝ y✝ d✝)) (n✝ + 1)
state_after: no goals

tactic: exact .balanced (.red (.black ha hb') (.black hc' hd))
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝² : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝² x✝¹ b).Balanced c₁ n
c₁✝² : RBColor
n✝ : Nat
c₂✝² : RBColor
ha : a✝².Balanced c₁✝² n✝
hb : b.Balanced c₂✝² n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝¹ c₂✝¹ : RBColor
hc : c.Balanced c₁✝¹ n✝
hd : d✝.Balanced c₂✝¹ n✝
IH : RedRed (c₂✝² = black → c₁✝¹ ≠ black) (b.append c) n✝
l✝ a✝¹ : RBNode α
x✝ : α
b✝ : RBNode α
e : b.append c = node red a✝¹ x✝ b✝
c₁✝ c₂✝ : RBColor
a✝ : c₂✝² = black → c₁✝¹ ≠ black
hb' : a✝¹.Balanced c₁✝ n✝
hc' : b✝.Balanced c₂✝ n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝² x✝¹ a✝¹) x✝ (node black b✝ y✝ d✝)) (n✝ + 1)
state_after: no goals

tactic: unfold balLeft
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
⊢ RedRed (black = black → black ≠ black) (a✝.balLeft x✝¹ (node black bc y✝ d✝)) (n✝ + 1)
state_after: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
⊢ RedRed (black = black → black ≠ black)
    (match a✝ with
    | node red a x b => node red (node black a x b) x✝¹ (node black bc y✝ d✝)
    | l =>
      match node black bc y✝ d✝ with
      | node black a y b => l.balance2 x✝¹ (node red a y b)
      | node red (node black a y b) z c => node red (node black l x✝¹ a) y (b.balance2 z c.setRed)
      | r => node red l x✝¹ r)
    (n✝ + 1)

tactic: split
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝¹ b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
⊢ RedRed (black = black → black ≠ black)
    (match a✝ with
    | node red a x b => node red (node black a x b) x✝¹ (node black bc y✝ d✝)
    | l =>
      match node black bc y✝ d✝ with
      | node black a y b => l.balance2 x✝¹ (node red a y b)
      | node red (node black a y b) z c => node red (node black l x✝¹ a) y (b.balance2 z c.setRed)
      | r => node red l x✝¹ r)
    (n✝ + 1)
state_after: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
hl : (node black (node red a✝ x✝ b✝) x✝² b).Balanced c₁ n
ha : (node red a✝ x✝ b✝).Balanced c₁✝¹ n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1)

case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ a✝ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝² b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝ = node red a x b → False
⊢ RedRed (black = black → black ≠ black)
    (match node black bc y✝ d✝ with
    | node black a y b => a✝.balance2 x✝² (node red a y b)
    | node red (node black a y b) z c => node red (node black a✝ x✝² a) y (b.balance2 z c.setRed)
    | r => node red a✝ x✝² r)
    (n✝ + 1)

tactic: have .red ha' hb' := ha
state_before: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
hl : (node black (node red a✝ x✝ b✝) x✝² b).Balanced c₁ n
ha : (node red a✝ x✝ b✝).Balanced c₁✝¹ n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1)
state_after: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
hl : (node black (node red a✝ x✝ b✝) x✝² b).Balanced c₁ n
ha : (node red a✝ x✝ b✝).Balanced c₁✝¹ n✝
ha' : a✝.Balanced black n✝
hb' : b✝.Balanced black n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1)

tactic: exact .balanced (.red (.black ha' hb') (.black hbc hd))
state_before: case h_1
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
hl : (node black (node red a✝ x✝ b✝) x✝² b).Balanced c₁ n
ha : (node red a✝ x✝ b✝).Balanced c₁✝¹ n✝
ha' : a✝.Balanced black n✝
hb' : b✝.Balanced black n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1)
state_after: no goals

tactic: exact have ⟨c, h⟩ := RedRed.balance2 ha (.redred trivial hbc hd); .balanced h
state_before: case h_2
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝⁴ x✝³ a✝ : RBNode α
x✝² : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝ x✝² b).Balanced c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : a✝.Balanced c₁✝¹ n✝
hb : b.Balanced c₂✝¹ n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : c.Balanced c₁✝ n✝
hd : d✝.Balanced c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (b.append c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : bc.Balanced c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), a✝ = node red a x b → False
⊢ RedRed (black = black → black ≠ black)
    (match node black bc y✝ d✝ with
    | node black a y b => a✝.balance2 x✝² (node red a y b)
    | node red (node black a y b) z c => node red (node black a✝ x✝² a) y (b.balance2 z c.setRed)
    | r => node red a✝ x✝² r)
    (n✝ + 1)
state_after: no goals

tactic: cases H _ _ _ rfl
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝³ x✝² a✝⁴ : RBNode α
x✝¹ : α
b c : RBNode α
y✝ : α
d✝ : RBNode α
hl : (node black a✝⁴ x✝¹ b).Balanced c₁ n
c₁✝² : RBColor
n✝ : Nat
c₂✝² : RBColor
ha : a✝⁴.Balanced c₁✝² n✝
hb : b.Balanced c₂✝² n✝
hr : (node black c y✝ d✝).Balanced c₂ (n✝ + 1)
c₁✝¹ c₂✝¹ : RBColor
hc : c.Balanced c₁✝¹ n✝
hd : d✝.Balanced c₂✝¹ n✝
IH : RedRed (c₂✝² = black → c₁✝¹ ≠ black) (b.append c) n✝
l✝ : RBNode α
H✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), b.append c = node red a x b_1 → False
a✝³ : RBNode α
c₁✝ : RBColor
b✝ : RBNode α
c₂✝ : RBColor
x✝ : α
a✝² : c₂✝² = black → c₁✝¹ ≠ black
a✝¹ : a✝³.Balanced c₁✝ n✝
a✝ : b✝.Balanced c₂✝ n✝
H : ∀ (a : RBNode α) (x : α) (b : RBNode α), node red a✝³ x✝ b✝ = node red a x b → False
⊢ RedRed (black = black → black ≠ black) (a✝⁴.balLeft x✝¹ (node black (node red a✝³ x✝ b✝) y✝ d✝)) (n✝ + 1)
state_after: no goals

tactic: have .red hc hd := hr
state_before: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
hr : (node red b✝ x✝ c✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) n
state_after: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
hr : (node red b✝ x✝ c✝).Balanced c₂ n
hc : b✝.Balanced black n
hd : c✝.Balanced black n
⊢ RedRed (c₁ = black → red ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) n

tactic: have IH := hl.append hc
state_before: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
hr : (node red b✝ x✝ c✝).Balanced c₂ n
hc : b✝.Balanced black n
hd : c✝.Balanced black n
⊢ RedRed (c₁ = black → red ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) n
state_after: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
hr : (node red b✝ x✝ c✝).Balanced c₂ n
hc : b✝.Balanced black n
hd : c✝.Balanced black n
IH : RedRed (c₁ = black → black ≠ black) ((node black l✝ v✝ r✝).append b✝) n
⊢ RedRed (c₁ = black → red ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) n

tactic: have .black ha hb := hl
state_before: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
hr : (node red b✝ x✝ c✝).Balanced c₂ n
hc : b✝.Balanced black n
hd : c✝.Balanced black n
IH : RedRed (c₁ = black → black ≠ black) ((node black l✝ v✝ r✝).append b✝) n
⊢ RedRed (c₁ = black → red ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) n
state_after: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
ha : l✝.Balanced c₁✝ n✝
hb : r✝.Balanced c₂✝ n✝
hr : (node red b✝ x✝ c✝).Balanced c₂ (n✝ + 1)
hc : b✝.Balanced black (n✝ + 1)
hd : c✝.Balanced black (n✝ + 1)
IH : RedRed (black = black → black ≠ black) ((node black l✝ v✝ r✝).append b✝) (n✝ + 1)
⊢ RedRed (black = black → red ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) (n✝ + 1)

tactic: exact .redred nofun IH hd
state_before: case h_5
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
x✝ : α
c✝ : RBNode α
hl : (node black l✝ v✝ r✝).Balanced c₁ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
ha : l✝.Balanced c₁✝ n✝
hb : r✝.Balanced c₂✝ n✝
hr : (node red b✝ x✝ c✝).Balanced c₂ (n✝ + 1)
hc : b✝.Balanced black (n✝ + 1)
hd : c✝.Balanced black (n✝ + 1)
IH✝ : RedRed (black = black → black ≠ black) ((node black l✝ v✝ r✝).append b✝) (n✝ + 1)
c : RBColor
IH : ((node black l✝ v✝ r✝).append b✝).Balanced c (n✝ + 1)
⊢ RedRed (black = black → red ≠ black) (node red ((node black l✝ v✝ r✝).append b✝) x✝ c✝) (n✝ + 1)
state_after: no goals

tactic: have .red ha hb := hl
state_before: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node black l✝ v✝ r✝).Balanced c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) n
state_after: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node black l✝ v✝ r✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b✝.Balanced black n
⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) n

tactic: have IH := hb.append hr
state_before: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node black l✝ v✝ r✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b✝.Balanced black n
⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) n
state_after: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node black l✝ v✝ r✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b✝.Balanced black n
IH : RedRed (black = black → c₂ ≠ black) (b✝.append (node black l✝ v✝ r✝)) n
⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) n

tactic: have .black hc hd := hr
state_before: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hl : (node red a✝ x✝ b✝).Balanced c₁ n
hr : (node black l✝ v✝ r✝).Balanced c₂ n
ha : a✝.Balanced black n
hb : b✝.Balanced black n
IH : RedRed (black = black → c₂ ≠ black) (b✝.append (node black l✝ v✝ r✝)) n
⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) n
state_after: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hr : (node black l✝ v✝ r✝).Balanced c₂ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
hc : l✝.Balanced c₁✝ n✝
hd : r✝.Balanced c₂✝ n✝
hl : (node red a✝ x✝ b✝).Balanced c₁ (n✝ + 1)
ha : a✝.Balanced black (n✝ + 1)
hb : b✝.Balanced black (n✝ + 1)
IH : RedRed (black = black → black ≠ black) (b✝.append (node black l✝ v✝ r✝)) (n✝ + 1)
⊢ RedRed (red = black → black ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) (n✝ + 1)

tactic: exact .redred nofun ha IH
state_before: case h_6
α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
x✝² x✝¹ a✝ : RBNode α
x✝ : α
b✝ l✝ : RBNode α
v✝ : α
r✝ : RBNode α
hr : (node black l✝ v✝ r✝).Balanced c₂ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
hc : l✝.Balanced c₁✝ n✝
hd : r✝.Balanced c₂✝ n✝
hl : (node red a✝ x✝ b✝).Balanced c₁ (n✝ + 1)
ha : a✝.Balanced black (n✝ + 1)
hb : b✝.Balanced black (n✝ + 1)
IH✝ : RedRed (black = black → black ≠ black) (b✝.append (node black l✝ v✝ r✝)) (n✝ + 1)
c : RBColor
IH : (b✝.append (node black l✝ v✝ r✝)).Balanced c (n✝ + 1)
⊢ RedRed (red = black → black ≠ black) (node red a✝ x✝ (b✝.append (node black l✝ v✝ r✝))) (n✝ + 1)
state_after: no goals