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

tactic: unfold balance2
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
⊢ ∃ c, Balanced (balance2 l v r) c (n + 1)

tactic: split
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
⊢ ∃ c,
    Balanced
      (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)
      c (n + 1)

tactic: have .redred _ (.red ha hb) hc := hr
state_before: case h_1
α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
hl : Balanced l c n
x✝² : RBNode α
x✝¹ : α
x✝ b✝ : RBNode α
y✝ : α
c✝ : RBNode α
z✝ : α
d✝ : RBNode α
hr : RedRed p (node red (node red b✝ y✝ c✝) z✝ d✝) n
⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1)

tactic: exact ⟨_, .red (.black hl ha) (.black hb hc)⟩
state_before: case h_1
α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
hl : Balanced l c n
x✝² : RBNode α
x✝¹ : α
x✝ b✝ : RBNode α
y✝ : α
c✝ : RBNode α
z✝ : α
d✝ : RBNode α
hr : RedRed p (node red (node red b✝ y✝ c✝) z✝ d✝) n
c₂✝ : RBColor
a✝ : p
ha : Balanced b✝ black n
hb : Balanced c✝ black n
hc : Balanced d✝ c₂✝ n
⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1)

tactic: have .redred _ ha (.red hb hc) := hr
state_before: case h_2
α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
hl : Balanced l c n
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
hr : RedRed p (node red b✝ y✝ (node red c✝ z✝ d✝)) n
⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1)

tactic: exact ⟨_, .red (.black hl ha) (.black hb hc)⟩
state_before: case h_2
α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
hl : Balanced l c n
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
hr : RedRed p (node red b✝ y✝ (node red c✝ z✝ d✝)) n
c₁✝ : RBColor
a✝ : p
ha : Balanced b✝ c₁✝ n
hb : Balanced c✝ black n
hc : Balanced d✝ black n
⊢ ∃ c, Balanced (node red (node black l v b✝) y✝ (node black c✝ z✝ d✝)) c (n + 1)

tactic: next H1 H2 => match hr with
| .balanced hr => exact ⟨_, .black hl hr⟩
| .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black hl (.red ha hb)⟩
| .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl
| .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl
state_before: case h_3
α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
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
⊢ ∃ c, Balanced (node black l v r) c (n + 1)

tactic: match hr with
| .balanced hr => exact ⟨_, .black hl hr⟩
| .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black hl (.red ha hb)⟩
| .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl
| .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
x✝² : RBNode α
x✝¹ : α
x✝ : RBNode α
H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False
H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False
⊢ ∃ c, Balanced (node black l v r) c (n + 1)

tactic: exact ⟨_, .black hl hr⟩
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r✝ : RBNode α
hl : Balanced l c n
hr✝ : RedRed p r✝ n
x✝² : RBNode α
x✝¹ : α
x✝ r : RBNode α
c✝ : RBColor
hr : Balanced r c✝ n
H1 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red (node red b y c) z d → False
H2 : ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α), r = node red b y (node red c z d) → False
⊢ ∃ c, Balanced (node black l v r) c (n + 1)

tactic: exact ⟨_, .black hl (.red ha hb)⟩
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
x✝³ : RBNode α
x✝² : α
x✝¹ a✝¹ b✝ : RBNode α
x✝ : α
a✝ : p
ha : Balanced a✝¹ black n
hb : Balanced b✝ black n
H1 :
  ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α),
    node red a✝¹ x✝ b✝ = node red (node red b y c) z d → False
H2 :
  ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α),
    node red a✝¹ x✝ b✝ = node red b y (node red c z d) → False
⊢ ∃ c, Balanced (node black l v (node red a✝¹ x✝ b✝)) c (n + 1)

tactic: cases H1 _ _ _ _ _ rfl
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
x✝³ : RBNode α
x✝² : α
x✝¹ l✝ : RBNode α
v✝ : α
r✝ b✝ : RBNode α
c₂✝ : RBColor
x✝ : α
a✝³ : p
a✝² : Balanced l✝ black n
a✝¹ : Balanced r✝ black n
a✝ : Balanced b✝ c₂✝ n
H1 :
  ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α),
    node red (node red l✝ v✝ r✝) x✝ b✝ = node red (node red b y c) z d → False
H2 :
  ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α),
    node red (node red l✝ v✝ r✝) x✝ b✝ = node red b y (node red c z d) → False
⊢ ∃ c, Balanced (node black l v (node red (node red l✝ v✝ r✝) x✝ b✝)) c (n + 1)

tactic: cases H2 _ _ _ _ _ rfl
state_before: α : Type u_1
c : RBColor
n : Nat
p : Prop
l : RBNode α
v : α
r : RBNode α
hl : Balanced l c n
hr : RedRed p r n
x✝³ : RBNode α
x✝² : α
x✝¹ a✝⁴ : RBNode α
c₁✝ : RBColor
l✝ : RBNode α
v✝ : α
r✝ : RBNode α
x✝ : α
a✝³ : p
a✝² : Balanced a✝⁴ c₁✝ n
a✝¹ : Balanced l✝ black n
a✝ : Balanced r✝ black n
H1 :
  ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α),
    node red a✝⁴ x✝ (node red l✝ v✝ r✝) = node red (node red b y c) z d → False
H2 :
  ∀ (b : RBNode α) (y : α) (c : RBNode α) (z : α) (d : RBNode α),
    node red a✝⁴ x✝ (node red l✝ v✝ r✝) = node red b y (node red c z d) → False
⊢ ∃ c, Balanced (node black l v (node red a✝⁴ x✝ (node red l✝ v✝ r✝))) c (n + 1)