l3lab/ntp-mathlib huggingface dataset:
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]; decide
      · have : size rll = 0 ∧ size rlr = 0 := by
          have := balancedSz_zero.1 hr.1
          rwa [size, sr.2.1.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sr.2.1.2.1.size_eq_zero.1 this.1
        cases sr.2.1.2.2.size_eq_zero.1 this.2
        obtain rfl : rls = 1 := sr.2.1.1
        rw [if_neg, if_pos, rotateL, if_neg]; · rfl
        all_goals dsimp only [size]; decide
      · symm; rw [zero_add, if_neg, if_pos, rotateL]
        · dsimp only [size_node]; split_ifs
          · simp [node3L, node']; abel
          · simp [node4L, node', sr.2.1.1]; abel
        · apply Nat.zero_lt_succ
        · exact not_le_of_gt (Nat.succ_lt_succ (add_pos sr.2.1.pos sr.2.2.pos))
  · cases' r with rs rl rx rr
    · rw [sl.eq_node'] at hl ⊢
      cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;>
        dsimp [balance, balance']
      · rfl
      · have : size lrl = 0 ∧ size lrr = 0 := by
          have := balancedSz_zero.1 hl.1.symm
          rwa [size, sl.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sl.2.2.2.1.size_eq_zero.1 this.1
        cases sl.2.2.2.2.size_eq_zero.1 this.2
        obtain rfl : lrs = 1 := sl.2.2.1
        rw [if_neg, if_neg, if_pos, rotateR, if_neg]; · rfl
        all_goals dsimp only [size]; decide
      · have : size lll = 0 ∧ size llr = 0 := by
          have := balancedSz_zero.1 hl.1
          rwa [size, sl.2.1.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
        cases sl.2.1.2.1.size_eq_zero.1 this.1
        cases sl.2.1.2.2.size_eq_zero.1 this.2
        obtain rfl : lls = 1 := sl.2.1.1
        rw [if_neg, if_neg, if_pos, rotateR, if_pos]; · rfl
        all_goals dsimp only [size]; decide
      · symm; rw [if_neg, if_neg, if_pos, rotateR]
        · dsimp only [size_node]; split_ifs
          · simp [node3R, node']; abel
          · simp [node4R, node', sl.2.2.1]; abel
        · apply Nat.zero_lt_succ
        · 

Proof state:
case node.nil.node.node.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr))
sl : Sized (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))
⊢ ¬0 > delta * (lls + lrs + 1)

Next tactic:
apply Nat.not_lt_zero
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
sl : Sized l
sr : Sized r
H1 : size l = 0 → size r ≤ 1
H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
⊢ balanceL l x r = balance l x r

Next tactic:
cases' r with rs rl rx rr
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · 

Proof state:
case nil
α : Type u_1
l : Ordnode α
x : α
sl : Sized l
sr : Sized nil
H1 : size l = 0 → size nil ≤ 1
H2 : 1 ≤ size l → 1 ≤ size nil → size nil ≤ delta * size l
⊢ balanceL l x nil = balance l x nil

Next tactic:
rfl
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · 

Proof state:
case node
α : Type u_1
l : Ordnode α
x : α
sl : Sized l
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
H1 : size l = 0 → size (node rs rl rx rr) ≤ 1
H2 : 1 ≤ size l → 1 ≤ size (node rs rl rx rr) → size (node rs rl rx rr) ≤ delta * size l
⊢ balanceL l x (node rs rl rx rr) = balance l x (node rs rl rx rr)

Next tactic:
cases' l with ls ll lx lr
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · 

Proof state:
case node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
sl : Sized nil
H1 : size nil = 0 → size (node rs rl rx rr) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs rl rx rr) → size (node rs rl rx rr) ≤ delta * size nil
⊢ balanceL nil x (node rs rl rx rr) = balance nil x (node rs rl rx rr)

Next tactic:
have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        

Proof state:
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
sl : Sized nil
H1 : size nil = 0 → size (node rs rl rx rr) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs rl rx rr) → size (node rs rl rx rr) ≤ delta * size nil
⊢ size rl = 0 ∧ size rr = 0

Next tactic:
have := H1 rfl
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        

Proof state:
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
sl : Sized nil
H1 : size nil = 0 → size (node rs rl rx rr) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs rl rx rr) → size (node rs rl rx rr) ≤ delta * size nil
this : size (node rs rl rx rr) ≤ 1
⊢ size rl = 0 ∧ size rr = 0

Next tactic:
rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      

Proof state:
case node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
sl : Sized nil
H1 : size nil = 0 → size (node rs rl rx rr) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs rl rx rr) → size (node rs rl rx rr) ≤ delta * size nil
this : size rl = 0 ∧ size rr = 0
⊢ balanceL nil x (node rs rl rx rr) = balance nil x (node rs rl rx rr)

Next tactic:
cases sr.2.1.size_eq_zero.1 this.1
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      

Proof state:
case node.nil.refl
α : Type u_1
x : α
rs : ℕ
rx : α
rr : Ordnode α
sl : Sized nil
sr : Sized (node rs nil rx rr)
H1 : size nil = 0 → size (node rs nil rx rr) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs nil rx rr) → size (node rs nil rx rr) ≤ delta * size nil
this : size nil = 0 ∧ size rr = 0
⊢ balanceL nil x (node rs nil rx rr) = balance nil x (node rs nil rx rr)

Next tactic:
cases sr.2.2.size_eq_zero.1 this.2
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      

Proof state:
case node.nil.refl.refl
α : Type u_1
x : α
rs : ℕ
rx : α
sl : Sized nil
sr : Sized (node rs nil rx nil)
H1 : size nil = 0 → size (node rs nil rx nil) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs nil rx nil) → size (node rs nil rx nil) ≤ delta * size nil
this : size nil = 0 ∧ size nil = 0
⊢ balanceL nil x (node rs nil rx nil) = balance nil x (node rs nil rx nil)

Next tactic:
rw [sr.eq_node']
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      rw [sr.eq_node']; 

Proof state:
case node.nil.refl.refl
α : Type u_1
x : α
rs : ℕ
rx : α
sl : Sized nil
sr : Sized (node rs nil rx nil)
H1 : size nil = 0 → size (node rs nil rx nil) ≤ 1
H2 : 1 ≤ size nil → 1 ≤ size (node rs nil rx nil) → size (node rs nil rx nil) ≤ delta * size nil
this : size nil = 0 ∧ size nil = 0
⊢ balanceL nil x (node' nil rx nil) = balance nil x (node' nil rx nil)

Next tactic:
rfl
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      rw [sr.eq_node']; rfl
    · 

Proof state:
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
sl : Sized (node ls ll lx lr)
H1 : size (node ls ll lx lr) = 0 → size (node rs rl rx rr) ≤ 1
H2 :
  1 ≤ size (node ls ll lx lr) → 1 ≤ size (node rs rl rx rr) → size (node rs rl rx rr) ≤ delta * size (node ls ll lx lr)
⊢ balanceL (node ls ll lx lr) x (node rs rl rx rr) = balance (node ls ll lx lr) x (node rs rl rx rr)

Next tactic:
replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      rw [sr.eq_node']; rfl
    · replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
      

Proof state:
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
sl : Sized (node ls ll lx lr)
H1 : size (node ls ll lx lr) = 0 → size (node rs rl rx rr) ≤ 1
H2 : ¬rs > delta * ls
⊢ balanceL (node ls ll lx lr) x (node rs rl rx rr) = balance (node ls ll lx lr) x (node rs rl rx rr)

Next tactic:
simp [balanceL, balance, H2]
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      rw [sr.eq_node']; rfl
    · replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
      simp [balanceL, balance, H2]; 

Proof state:
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
sl : Sized (node ls ll lx lr)
H1 : size (node ls ll lx lr) = 0 → size (node rs rl rx rr) ≤ 1
H2 : ¬rs > delta * ls
⊢ (if delta * rs < ls then
      rec (motive := fun t => ll = t → Ordnode α) (fun h => nil)
        (fun size l x_1 r l_ih r_ih h =>
          rec (motive := fun t => lr = t → Ordnode α) (fun h => nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              if size_1 < ratio * size then node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
              else
                node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                  (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
            lr (_ : id lr = id lr))
        ll (_ : id ll = id ll)
    else node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    if delta * rs < ls then
      rec (motive := fun t => ll = t → Ordnode α) (fun h => nil)
        (fun size l x_1 r l_ih r_ih h =>
          rec (motive := fun t => lr = t → Ordnode α) (fun h => nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              if size_1 < ratio * size then node (ls + rs + 1) ll lx (node (size_1 + rs + 1) lr x (node rs rl rx rr))
              else
                node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                  (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
            lr (_ : id lr = id lr))
        ll (_ : id ll = id ll)
    else node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)

Next tactic:
split_ifs
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      rw [sr.eq_node']; rfl
    · replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
      simp [balanceL, balance, H2]; split_ifs <;> 

Proof state:
case pos
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
sl : Sized (node ls ll lx lr)
H1 : size (node ls ll lx lr) = 0 → size (node rs rl rx rr) ≤ 1
H2 : ¬rs > delta * ls
h✝ : delta * rs < ls
⊢ rec (motive := fun t => ll = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => lr = t → Ordnode α) (fun h => nil)
          (fun size_1 l x_2 r l_ih r_ih h =>
            if size_1 < ratio * size then node (ls + rs + 1) ll lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          lr (_ : id lr = id lr))
      ll (_ : id ll = id ll) =
    rec (motive := fun t => ll = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => lr = t → Ordnode α) (fun h => nil)
          (fun size_1 l x_2 r l_ih r_ih h =>
            if size_1 < ratio * size then node (ls + rs + 1) ll lx (node (size_1 + rs + 1) lr x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) ll lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          lr (_ : id lr = id lr))
      ll (_ : id ll = id ll)

Next tactic:
simp [add_comm]
theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1)
    (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) :
    @balanceL α l x r = balance l x r := by
  cases' r with rs rl rx rr
  · rfl
  · cases' l with ls ll lx lr
    · have : size rl = 0 ∧ size rr = 0 := by
        have := H1 rfl
        rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
      cases sr.2.1.size_eq_zero.1 this.1
      cases sr.2.2.size_eq_zero.1 this.2
      rw [sr.eq_node']; rfl
    · replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
      simp [balanceL, balance, H2]; split_ifs <;> 

Proof state:
case neg
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
sr : Sized (node rs rl rx rr)
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
sl : Sized (node ls ll lx lr)
H1 : size (node ls ll lx lr) = 0 → size (node rs rl rx rr) ≤ 1
H2 : ¬rs > delta * ls
h✝ : ¬delta * rs < ls
⊢ node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr) =
    node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)

Next tactic:
simp [add_comm]
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  

Proof state:
α : Type u_1
n m : ℕ
⊢ Raised n m ↔ n ≤ m ∧ m ≤ n + 1

Next tactic:
constructor
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; 

Proof state:
case mp
α : Type u_1
n m : ℕ
⊢ Raised n m → n ≤ m ∧ m ≤ n + 1
case mpr α : Type u_1 n m : ℕ ⊢ n ≤ m ∧ m ≤ n + 1 → Raised n m

Next tactic:
rintro (rfl | rfl)
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; rintro (rfl | rfl)
  · 

Proof state:
case mp.inl
α : Type u_1
m : ℕ
⊢ m ≤ m ∧ m ≤ m + 1

Next tactic:
exact ⟨le_rfl, Nat.le_succ _⟩
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; rintro (rfl | rfl)
  · exact ⟨le_rfl, Nat.le_succ _⟩
  · 

Proof state:
case mp.inr
α : Type u_1
n : ℕ
⊢ n ≤ n + 1 ∧ n + 1 ≤ n + 1

Next tactic:
exact ⟨Nat.le_succ _, le_rfl⟩
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; rintro (rfl | rfl)
  · exact ⟨le_rfl, Nat.le_succ _⟩
  · exact ⟨Nat.le_succ _, le_rfl⟩
  · 

Proof state:
case mpr
α : Type u_1
n m : ℕ
⊢ n ≤ m ∧ m ≤ n + 1 → Raised n m

Next tactic:
rintro ⟨h₁, h₂⟩
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; rintro (rfl | rfl)
  · exact ⟨le_rfl, Nat.le_succ _⟩
  · exact ⟨Nat.le_succ _, le_rfl⟩
  · rintro ⟨h₁, h₂⟩
    

Proof state:
case mpr.intro
α : Type u_1
n m : ℕ
h₁ : n ≤ m
h₂ : m ≤ n + 1
⊢ Raised n m

Next tactic:
rcases eq_or_lt_of_le h₁ with (rfl | h₁)
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; rintro (rfl | rfl)
  · exact ⟨le_rfl, Nat.le_succ _⟩
  · exact ⟨Nat.le_succ _, le_rfl⟩
  · rintro ⟨h₁, h₂⟩
    rcases eq_or_lt_of_le h₁ with (rfl | h₁)
    · 

Proof state:
case mpr.intro.inl
α : Type u_1
n : ℕ
h₁ : n ≤ n
h₂ : n ≤ n + 1
⊢ Raised n n

Next tactic:
exact Or.inl rfl
theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by
  constructor; rintro (rfl | rfl)
  · exact ⟨le_rfl, Nat.le_succ _⟩
  · exact ⟨Nat.le_succ _, le_rfl⟩
  · rintro ⟨h₁, h₂⟩
    rcases eq_or_lt_of_le h₁ with (rfl | h₁)
    · exact Or.inl rfl
    · 

Proof state:
case mpr.intro.inr
α : Type u_1
n m : ℕ
h₁✝ : n ≤ m
h₂ : m ≤ n + 1
h₁ : n < m
⊢ Raised n m

Next tactic:
exact Or.inr (le_antisymm h₂ h₁)
theorem Raised.dist_le {n m} (H : Raised n m) : Nat.dist n m ≤ 1 := by
  

Proof state:
α : Type u_1
n m : ℕ
H : Raised n m
⊢ Nat.dist n m ≤ 1

Next tactic:
cases' raised_iff.1 H with H1 H2
theorem Raised.dist_le {n m} (H : Raised n m) : Nat.dist n m ≤ 1 := by
  cases' raised_iff.1 H with H1 H2; 

Proof state:
case intro
α : Type u_1
n m : ℕ
H : Raised n m
H1 : n ≤ m
H2 : m ≤ n + 1
⊢ Nat.dist n m ≤ 1

Next tactic:
rwa [Nat.dist_eq_sub_of_le H1, tsub_le_iff_left]
theorem Raised.dist_le' {n m} (H : Raised n m) : Nat.dist m n ≤ 1 := by
  

Proof state:
α : Type u_1
n m : ℕ
H : Raised n m
⊢ Nat.dist m n ≤ 1

Next tactic:
rw [Nat.dist_comm]
theorem Raised.dist_le' {n m} (H : Raised n m) : Nat.dist m n ≤ 1 := by
  rw [Nat.dist_comm]; 

Proof state:
α : Type u_1
n m : ℕ
H : Raised n m
⊢ Nat.dist n m ≤ 1

Next tactic:
exact H.dist_le
theorem Raised.add_left (k) {n m} (H : Raised n m) : Raised (k + n) (k + m) := by
  

Proof state:
α : Type u_1
k n m : ℕ
H : Raised n m
⊢ Raised (k + n) (k + m)

Next tactic:
rcases H with (rfl | rfl)
theorem Raised.add_left (k) {n m} (H : Raised n m) : Raised (k + n) (k + m) := by
  rcases H with (rfl | rfl)
  · 

Proof state:
case inl
α : Type u_1
k m : ℕ
⊢ Raised (k + m) (k + m)

Next tactic:
exact Or.inl rfl
theorem Raised.add_left (k) {n m} (H : Raised n m) : Raised (k + n) (k + m) := by
  rcases H with (rfl | rfl)
  · exact Or.inl rfl
  · 

Proof state:
case inr
α : Type u_1
k n : ℕ
⊢ Raised (k + n) (k + (n + 1))

Next tactic:
exact Or.inr rfl
theorem Raised.add_right (k) {n m} (H : Raised n m) : Raised (n + k) (m + k) := by
  

Proof state:
α : Type u_1
k n m : ℕ
H : Raised n m
⊢ Raised (n + k) (m + k)

Next tactic:
rw [add_comm, add_comm m]
theorem Raised.add_right (k) {n m} (H : Raised n m) : Raised (n + k) (m + k) := by
  rw [add_comm, add_comm m]; 

Proof state:
α : Type u_1
k n m : ℕ
H : Raised n m
⊢ Raised (k + n) (k + m)

Next tactic:
exact H.add_left _
theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) :
    Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
H : Raised (size r₁) (size r₂)
⊢ Raised (size (node' l x₁ r₁)) (size (node' l x₂ r₂))

Next tactic:
rw [node', size, size]
theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) :
    Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by
  rw [node', size, size]; 

Proof state:
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
H : Raised (size r₁) (size r₂)
⊢ Raised (size l + size r₁ + 1) (size l + size r₂ + 1)

Next tactic:
generalize size r₂ = m at H ⊢
theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) :
    Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by
  rw [node', size, size]; generalize size r₂ = m at H ⊢
  

Proof state:
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
m : ℕ
H : Raised (size r₁) m
⊢ Raised (size l + size r₁ + 1) (size l + m + 1)

Next tactic:
rcases H with (rfl | rfl)
theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) :
    Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by
  rw [node', size, size]; generalize size r₂ = m at H ⊢
  rcases H with (rfl | rfl)
  · 

Proof state:
case inl
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
⊢ Raised (size l + size r₁ + 1) (size l + size r₁ + 1)

Next tactic:
exact Or.inl rfl
theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) :
    Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by
  rw [node', size, size]; generalize size r₂ = m at H ⊢
  rcases H with (rfl | rfl)
  · exact Or.inl rfl
  · 

Proof state:
case inr
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
⊢ Raised (size l + size r₁ + 1) (size l + (size r₁ + 1) + 1)

Next tactic:
exact Or.inr rfl