Theorem: Std.RBNode.Balanced.append
File: Std/Data/RBMap/WF.lean

tactic: unfold append
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l r : RBNode α
hl : Balanced l c₁ n
hr : Balanced r c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (append l r) n

tactic: split
state_before: α : Type u_1
c₁ : RBColor
n : Nat
c₂ : RBColor
l r : RBNode α
hl : Balanced l c₁ n
hr : Balanced r 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 append b 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 append b c with
      | node red b' z c' => node red (node black a x b') z (node black c' y d)
      | bc => balLeft a x (node black bc y d)
    | a@h:(node black l v r), node red b x c => node red (append a b) x c
    | node red a x b, c@h:(node black l v r) => node red a x (append b c))
    n

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

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

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 : Balanced (node red a✝ x✝ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match append b 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 : Balanced (node red a✝ x✝ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b black n
⊢ RedRed (red = black → c₂ ≠ black)
    (match append b 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 : Balanced (node red a✝ x✝ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
w✝ : RBColor
IH : Balanced (append b c) w✝ n
⊢ RedRed (red = black → red ≠ black)
    (match append b 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: next e =>
have .red hb' hc' := e ▸ IH
exact .redred (fun.) (.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 : Balanced (node red a✝¹ x✝¹ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝¹ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
w✝ : RBColor
IH : Balanced (append b c) w✝ n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : append b 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

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 : Balanced (node red a✝¹ x✝¹ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝¹ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
w✝ : RBColor
IH : Balanced (append b c) w✝ n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : append b 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

tactic: exact .redred (fun.) (.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 : Balanced (node red a✝¹ x✝¹ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝¹ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : append b c = node red a✝ x✝ b✝
hb' : Balanced a✝ black n
hc' : Balanced b✝ black n
IH : Balanced (append b c) red n
⊢ RedRed (red = black → red ≠ black) (node red (node red a✝¹ x✝¹ a✝) x✝ (node red b✝ y✝ d✝)) n

tactic: next bcc _ H =>
match bcc, append b c, IH, H with
| black, _, IH, _ => exact .redred (fun.) 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 : Balanced (node red a✝ x✝¹ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
w✝ : RBColor
IH : Balanced (append b c) w✝ n
l✝ : RBNode α
x✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝¹ (node red (append b c) y✝ d✝)) n

tactic: match bcc, append b c, IH, H with
| black, _, IH, _ => exact .redred (fun.) 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 : Balanced (node red a✝ x✝ b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
bcc : RBColor
IH : Balanced (append b c) bcc n
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
⊢ RedRed (red = black → red ≠ black) (node red a✝ x✝ (node red (append b c) y✝ d✝)) n

tactic: exact .redred (fun.) 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 : Balanced (node red a✝ x✝² b) c₁ n
hr : Balanced (node red c y✝ d✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
bcc : RBColor
IH✝ : Balanced (append b c) bcc n
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
x✝¹ : RBNode α
IH : Balanced x✝¹ 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

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 : Balanced (node red a✝² x✝¹ b) c₁ n
hr : Balanced (node red c y✝¹ d✝) c₂ n
ha : Balanced a✝² black n
hb : Balanced b black n
hc : Balanced c black n
hd : Balanced d✝ black n
bcc : RBColor
IH : Balanced (append b c) bcc n
l✝ : RBNode α
H✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
x✝ y✝ : RBNode α
v✝ : α
a✝¹ : Balanced x✝ black n
a✝ : Balanced y✝ 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

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 : Balanced (node black a✝ x✝ b) c₁ n
hr : Balanced (node black c y✝ d✝) c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black)
    (match append b c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => balLeft a✝ x✝ (node black bc y✝ d✝))
    n

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 : Balanced (node black a✝ x✝ b) c₁ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
ha : Balanced a✝ c₁✝ n✝
hb : Balanced b c₂✝ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
⊢ RedRed (black = black → c₂ ≠ black)
    (match append b c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => balLeft a✝ 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 : Balanced (node black a✝ x✝ b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
⊢ RedRed (black = black → black ≠ black)
    (match append b c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => balLeft a✝ 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 : Balanced (node black a✝ x✝ b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
⊢ RedRed (black = black → black ≠ black)
    (match append b c with
    | node red b' z c' => node red (node black a✝ x✝ b') z (node black c' y✝ d✝)
    | bc => balLeft a✝ x✝ (node black bc 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 : Balanced (node black a✝¹ x✝¹ b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝¹ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
heq✝ : append b 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)

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 : Balanced (node black a✝¹ x✝¹ b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝¹ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
e : append b 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)

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 : Balanced (node black a✝² x✝¹ b) c₁ n
c₁✝² : RBColor
n✝ : Nat
c₂✝² : RBColor
ha : Balanced a✝² c₁✝² n✝
hb : Balanced b c₂✝² n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝¹ c₂✝¹ : RBColor
hc : Balanced c c₁✝¹ n✝
hd : Balanced d✝ c₂✝¹ n✝
IH : RedRed (c₂✝² = black → c₁✝¹ ≠ black) (append b c) n✝
l✝ a✝¹ : RBNode α
x✝ : α
b✝ : RBNode α
e : append b c = node red a✝¹ x✝ b✝
c₁✝ c₂✝ : RBColor
a✝ : c₂✝² = black → c₁✝¹ ≠ black
hb' : Balanced a✝¹ c₁✝ n✝
hc' : Balanced b✝ c₂✝ n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝² x✝¹ a✝¹) x✝ (node black b✝ y✝ d✝)) (n✝ + 1)

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 : Balanced (node black a✝ x✝¹ b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : Balanced bc c✝ n✝
x✝ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
⊢ RedRed (black = black → black ≠ black) (balLeft a✝ 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 : Balanced (node black a✝ x✝¹ b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : Balanced bc 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 => balance2 l x✝¹ (node red a y b)
      | node red (node black a y b) z c => node red (node black l x✝¹ a) y (balance2 b z (setRed c))
      | r => node red l 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 : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : Balanced bc c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
hl : Balanced (node black (node red a✝ x✝ b✝) x✝² b) c₁ n
ha : Balanced (node red a✝ x✝ b✝) c₁✝¹ 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 : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : Balanced bc c✝ n✝
x✝¹ : ∀ (a : RBNode α) (x : α) (b : RBNode α), bc = node red a x b → False
l✝ a✝ : RBNode α
x✝ : α
b✝ : RBNode α
hl : Balanced (node black (node red a✝ x✝ b✝) x✝² b) c₁ n
ha : Balanced (node red a✝ x✝ b✝) c₁✝¹ n✝
ha' : Balanced a✝ black n✝
hb' : Balanced b✝ black n✝
⊢ RedRed (black = black → black ≠ black) (node red (node black a✝ x✝ b✝) x✝² (node black bc y✝ d✝)) (n✝ + 1)

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 : Balanced (node black a✝ x✝² b) c₁ n
c₁✝¹ : RBColor
n✝ : Nat
c₂✝¹ : RBColor
ha : Balanced a✝ c₁✝¹ n✝
hb : Balanced b c₂✝¹ n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝ c₂✝ : RBColor
hc : Balanced c c₁✝ n✝
hd : Balanced d✝ c₂✝ n✝
IH : RedRed (c₂✝¹ = black → c₁✝ ≠ black) (append b c) n✝
l✝¹ : RBNode α
H : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
bc : RBNode α
c✝ : RBColor
hbc : Balanced bc 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 => balance2 a✝ x✝² (node red a y b)
    | node red (node black a y b) z c => node red (node black a✝ x✝² a) y (balance2 b z (setRed c))
    | r => node red a✝ x✝² r)
    (n✝ + 1)

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 : Balanced (node black a✝⁴ x✝¹ b) c₁ n
c₁✝² : RBColor
n✝ : Nat
c₂✝² : RBColor
ha : Balanced a✝⁴ c₁✝² n✝
hb : Balanced b c₂✝² n✝
hr : Balanced (node black c y✝ d✝) c₂ (n✝ + 1)
c₁✝¹ c₂✝¹ : RBColor
hc : Balanced c c₁✝¹ n✝
hd : Balanced d✝ c₂✝¹ n✝
IH : RedRed (c₂✝² = black → c₁✝¹ ≠ black) (append b c) n✝
l✝ : RBNode α
H✝ : ∀ (a : RBNode α) (x : α) (b_1 : RBNode α), append b c = node red a x b_1 → False
a✝³ : RBNode α
c₁✝ : RBColor
b✝ : RBNode α
c₂✝ : RBColor
x✝ : α
a✝² : c₂✝² = black → c₁✝¹ ≠ black
a✝¹ : Balanced a✝³ c₁✝ n✝
a✝ : Balanced b✝ c₂✝ n✝
H : ∀ (a : RBNode α) (x : α) (b : RBNode α), node red a✝³ x✝ b✝ = node red a x b → False
⊢ RedRed (black = black → black ≠ black) (balLeft a✝⁴ x✝¹ (node black (node red a✝³ x✝ b✝) y✝ d✝)) (n✝ + 1)

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 : Balanced (node black l✝ v✝ r✝) c₁ n
hr : Balanced (node red b✝ x✝ c✝) c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (node red (append (node black l✝ v✝ r✝) 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 : Balanced (node black l✝ v✝ r✝) c₁ n
hr : Balanced (node red b✝ x✝ c✝) c₂ n
hc : Balanced b✝ black n
hd : Balanced c✝ black n
⊢ RedRed (c₁ = black → red ≠ black) (node red (append (node black l✝ v✝ r✝) 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 : Balanced (node black l✝ v✝ r✝) c₁ n
hr : Balanced (node red b✝ x✝ c✝) c₂ n
hc : Balanced b✝ black n
hd : Balanced c✝ black n
IH : RedRed (c₁ = black → black ≠ black) (append (node black l✝ v✝ r✝) b✝) n
⊢ RedRed (c₁ = black → red ≠ black) (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) n

tactic: exact .redred (fun.) 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 : Balanced (node black l✝ v✝ r✝) c₁ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
ha : Balanced l✝ c₁✝ n✝
hb : Balanced r✝ c₂✝ n✝
hr : Balanced (node red b✝ x✝ c✝) c₂ (n✝ + 1)
hc : Balanced b✝ black (n✝ + 1)
hd : Balanced c✝ black (n✝ + 1)
IH✝ : RedRed (black = black → black ≠ black) (append (node black l✝ v✝ r✝) b✝) (n✝ + 1)
c : RBColor
IH : Balanced (append (node black l✝ v✝ r✝) b✝) c (n✝ + 1)
⊢ RedRed (black = black → red ≠ black) (node red (append (node black l✝ v✝ r✝) b✝) x✝ c✝) (n✝ + 1)

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 : Balanced (node red a✝ x✝ b✝) c₁ n
hr : Balanced (node black l✝ v✝ r✝) c₂ n
⊢ RedRed (c₁ = black → c₂ ≠ black) (node red a✝ x✝ (append b✝ (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 : Balanced (node red a✝ x✝ b✝) c₁ n
hr : Balanced (node black l✝ v✝ r✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b✝ black n
⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (append b✝ (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 : Balanced (node red a✝ x✝ b✝) c₁ n
hr : Balanced (node black l✝ v✝ r✝) c₂ n
ha : Balanced a✝ black n
hb : Balanced b✝ black n
IH : RedRed (black = black → c₂ ≠ black) (append b✝ (node black l✝ v✝ r✝)) n
⊢ RedRed (red = black → c₂ ≠ black) (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) n

tactic: exact .redred (fun.) 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 : Balanced (node black l✝ v✝ r✝) c₂ n
c₁✝ : RBColor
n✝ : Nat
c₂✝ : RBColor
hc : Balanced l✝ c₁✝ n✝
hd : Balanced r✝ c₂✝ n✝
hl : Balanced (node red a✝ x✝ b✝) c₁ (n✝ + 1)
ha : Balanced a✝ black (n✝ + 1)
hb : Balanced b✝ black (n✝ + 1)
IH✝ : RedRed (black = black → black ≠ black) (append b✝ (node black l✝ v✝ r✝)) (n✝ + 1)
c : RBColor
IH : Balanced (append b✝ (node black l✝ v✝ r✝)) c (n✝ + 1)
⊢ RedRed (red = black → black ≠ black) (node red a✝ x✝ (append b✝ (node black l✝ v✝ r✝))) (n✝ + 1)