l3lab/ntp-mathlib huggingface dataset:
theorem dual_insert [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) :
    ∀ t : Ordnode α, dual (Ordnode.insert x t) = @Ordnode.insert αᵒᵈ _ _ x (dual t)
  | nil => rfl
  | node _ l y r => by
    have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl
    rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y]
    cases cmpLE x y <;>
      

Proof state:
case lt
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match Ordering.lt with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap Ordering.lt with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))

Next tactic:
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
theorem dual_insert [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) :
    ∀ t : Ordnode α, dual (Ordnode.insert x t) = @Ordnode.insert αᵒᵈ _ _ x (dual t)
  | nil => rfl
  | node _ l y r => by
    have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl
    rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y]
    cases cmpLE x y <;>
      

Proof state:
case eq
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match Ordering.eq with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap Ordering.eq with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))

Next tactic:
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
theorem dual_insert [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) :
    ∀ t : Ordnode α, dual (Ordnode.insert x t) = @Ordnode.insert αᵒᵈ _ _ x (dual t)
  | nil => rfl
  | node _ l y r => by
    have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl
    rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y]
    cases cmpLE x y <;>
      

Proof state:
case gt
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match Ordering.gt with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap Ordering.gt with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))

Next tactic:
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
⊢ balance l x r = balance' l x r

Next tactic:
cases' l with ls ll lx lr
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · 

Proof state:
case nil
α : Type u_1
x : α
r : Ordnode α
hr : Balanced r
sr : Sized r
hl : Balanced nil
sl : Sized nil
⊢ balance nil x r = balance' nil x r

Next tactic:
cases' r with rs rl rx rr
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · 

Proof state:
case nil.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
hr : Balanced nil
sr : Sized nil
⊢ balance nil x nil = balance' nil x nil

Next tactic:
rfl
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · 

Proof state:
case nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ balance nil x (node rs rl rx rr) = balance' nil x (node rs rl rx rr)

Next tactic:
rw [sr.eq_node'] at hr ⊢
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      

Proof state:
case nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node' rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ balance nil x (node' rl rx rr) = balance' nil x (node' rl rx rr)

Next tactic:
cases' rl with rls rll rlx rlr
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> 

Proof state:
case nil.node.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rr : Ordnode α
hr : Balanced (node' nil rx rr)
sr : Sized (node rs nil rx rr)
⊢ balance nil x (node' nil rx rr) = balance' nil x (node' nil rx rr)

Next tactic:
cases' rr with rrs rrl rrx rrr
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> 

Proof state:
case nil.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rr : Ordnode α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx rr)
sr : Sized (node rs (node rls rll rlx rlr) rx rr)
⊢ balance nil x (node' (node rls rll rlx rlr) rx rr) = balance' nil x (node' (node rls rll rlx rlr) rx rr)

Next tactic:
cases' rr with rrs rrl rrx rrr
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        

Proof state:
case nil.node.nil.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
hr : Balanced (node' nil rx nil)
sr : Sized (node rs nil rx nil)
⊢ balance nil x (node' nil rx nil) = balance' nil x (node' nil rx nil)

Next tactic:
dsimp [balance, balance']
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        

Proof state:
case nil.node.nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
⊢ balance nil x (node' nil rx (node rrs rrl rrx rrr)) = balance' nil x (node' nil rx (node rrs rrl rrx rrr))

Next tactic:
dsimp [balance, balance']
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        

Proof state:
case nil.node.node.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
⊢ balance nil x (node' (node rls rll rlx rlr) rx nil) = balance' nil x (node' (node rls rll rlx rlr) rx nil)

Next tactic:
dsimp [balance, balance']
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        

Proof state:
case nil.node.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ balance nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)) =
    balance' nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))

Next tactic:
dsimp [balance, balance']
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · 

Proof state:
case nil.node.nil.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
hr : Balanced (node' nil rx nil)
sr : Sized (node rs nil rx nil)
⊢ node 2 nil x (node' nil rx nil) =
    if 0 + (0 + 1) ≤ 1 then node' nil x (node' nil rx nil)
    else
      if 0 + 1 > 0 then rotateL nil x (node' nil rx nil)
      else if 0 > delta * (0 + 1) then rotateR nil x (node' nil rx nil) else node' nil x (node' nil rx nil)

Next tactic:
rfl
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · 

Proof state:
case nil.node.nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
⊢ node 3 (Ordnode.singleton x) rx (node rrs rrl rrx rrr) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs rrl rrx rrr))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs rrl rrx rrr))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs rrl rrx rrr))
        else node' nil x (node' nil rx (node rrs rrl rrx rrr))

Next tactic:
have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          

Proof state:
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
⊢ size rrl = 0 ∧ size rrr = 0

Next tactic:
have := balancedSz_zero.1 hr.1.symm
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          

Proof state:
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
this : size (node rrs rrl rrx rrr) ≤ 1
⊢ size rrl = 0 ∧ size rrr = 0

Next tactic:
rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        

Proof state:
case nil.node.nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
this : size rrl = 0 ∧ size rrr = 0
⊢ node 3 (Ordnode.singleton x) rx (node rrs rrl rrx rrr) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs rrl rrx rrr))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs rrl rrx rrr))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs rrl rrx rrr))
        else node' nil x (node' nil rx (node rrs rrl rrx rrr))

Next tactic:
cases sr.2.2.2.1.size_eq_zero.1 this.1
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        

Proof state:
case nil.node.nil.node.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs nil rrx rrr))
sr : Sized (node rs nil rx (node rrs nil rrx rrr))
this : size nil = 0 ∧ size rrr = 0
⊢ node 3 (Ordnode.singleton x) rx (node rrs nil rrx rrr) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs nil rrx rrr))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs nil rrx rrr))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs nil rrx rrr))
        else node' nil x (node' nil rx (node rrs nil rrx rrr))

Next tactic:
cases sr.2.2.2.2.size_eq_zero.1 this.2
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        cases sr.2.2.2.2.size_eq_zero.1 this.2
        

Proof state:
case nil.node.nil.node.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrx : α
hr : Balanced (node' nil rx (node rrs nil rrx nil))
sr : Sized (node rs nil rx (node rrs nil rrx nil))
this : size nil = 0 ∧ size nil = 0
⊢ node 3 (Ordnode.singleton x) rx (node rrs nil rrx nil) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs nil rrx nil))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs nil rrx nil))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs nil rrx nil))
        else node' nil x (node' nil rx (node rrs nil rrx nil))

Next tactic:
obtain rfl : rrs = 1 := sr.2.2.1
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        cases sr.2.2.2.2.size_eq_zero.1 this.2
        obtain rfl : rrs = 1 := sr.2.2.1
        

Proof state:
case nil.node.nil.node.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ node 3 (Ordnode.singleton x) rx (node 1 nil rrx nil) =
    if 0 + (0 + 1 + 1) ≤ 1 then node' nil x (node' nil rx (node 1 nil rrx nil))
    else
      if 0 + 1 + 1 > 0 then rotateL nil x (node' nil rx (node 1 nil rrx nil))
      else
        if 0 > delta * (0 + 1 + 1) then rotateR nil x (node' nil rx (node 1 nil rrx nil))
        else node' nil x (node' nil rx (node 1 nil rrx nil))

Next tactic:
rw [if_neg, if_pos, rotateL, if_pos]
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        cases sr.2.2.2.2.size_eq_zero.1 this.2
        obtain rfl : rrs = 1 := sr.2.2.1
        rw [if_neg, if_pos, rotateL, if_pos]; · 

Proof state:
case nil.node.nil.node.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ node 3 (Ordnode.singleton x) rx (node 1 nil rrx nil) = node3L nil x nil rx (node 1 nil rrx nil)

Next tactic:
rfl
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        cases sr.2.2.2.2.size_eq_zero.1 this.2
        obtain rfl : rrs = 1 := sr.2.2.1
        rw [if_neg, if_pos, rotateL, if_pos]; · rfl
        

Proof state:
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ size nil < ratio * size (node 1 nil rrx nil)
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ 0 + 1 + 1 > 0
case nil.node.nil.node.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ ¬0 + (0 + 1 + 1) ≤ 1

Next tactic:
all_goals dsimp only [size]; decide
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        cases sr.2.2.2.2.size_eq_zero.1 this.2
        obtain rfl : rrs = 1 := sr.2.2.1
        rw [if_neg, if_pos, rotateL, if_pos]; · rfl
        all_goals 

Proof state:
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ size nil < ratio * size (node 1 nil rrx nil)

Next tactic:
dsimp only [size]
theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l)
    (sr : Sized r) : @balance α l x r = balance' l x r := by
  cases' l with ls ll lx lr
  · cases' r with rs rl rx rr
    · rfl
    · rw [sr.eq_node'] at hr ⊢
      cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size rrl = 0 ∧ size rrr = 0 := by
          have := balancedSz_zero.1 hr.1.symm
          rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.2.2.1.size_eq_zero.1 this.1
        cases sr.2.2.2.2.size_eq_zero.1 this.2
        obtain rfl : rrs = 1 := sr.2.2.1
        rw [if_neg, if_pos, rotateL, if_pos]; · rfl
        all_goals dsimp only [size]; 

Proof state:
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ 0 < ratio * 1

Next tactic:
decide