l3lab/ntp-mathlib huggingface dataset:
theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l)

Next tactic:
simp [node3L, node3R, dual_node', add_comm]
theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l)

Next tactic:
cases m
theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by
  cases m <;> 

Proof state:
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
⊢ dual (node4L l x nil y r) = node4R (dual r) y (dual nil) x (dual l)

Next tactic:
simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by
  cases m <;> 

Proof state:
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ dual (node4L l x (node size✝ l✝ x✝ r✝) y r) = node4R (dual r) y (dual (node size✝ l✝ x✝ r✝)) x (dual l)

Next tactic:
simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l)

Next tactic:
cases m
theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by
  cases m <;> 

Proof state:
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
⊢ dual (node4R l x nil y r) = node4L (dual r) y (dual nil) x (dual l)

Next tactic:
simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
    dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by
  cases m <;> 

Proof state:
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ dual (node4R l x (node size✝ l✝ x✝ r✝) y r) = node4L (dual r) y (dual (node size✝ l✝ x✝ r✝)) x (dual l)

Next tactic:
simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (rotateL l x r) = rotateR (dual r) x (dual l)

Next tactic:
cases r
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
  cases r <;> 

Proof state:
case nil
α : Type u_1
l : Ordnode α
x : α
⊢ dual (rotateL l x nil) = rotateR (dual nil) x (dual l)

Next tactic:
simp [rotateL, rotateR, dual_node']
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
  cases r <;> 

Proof state:
case node
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ dual (rotateL l x (node size✝ l✝ x✝ r✝)) = rotateR (dual (node size✝ l✝ x✝ r✝)) x (dual l)

Next tactic:
simp [rotateL, rotateR, dual_node']
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
  cases r <;> simp [rotateL, rotateR, dual_node']; 

Proof state:
case node
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ dual (if size l✝ < ratio * size r✝ then node3L l x l✝ x✝ r✝ else node4L l x l✝ x✝ r✝) =
    if size l✝ < ratio * size r✝ then node3R (dual r✝) x✝ (dual l✝) x (dual l)
    else node4R (dual r✝) x✝ (dual l✝) x (dual l)

Next tactic:
split_ifs
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
  cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;>
    

Proof state:
case pos
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
h✝ : size l✝ < ratio * size r✝
⊢ dual (node3L l x l✝ x✝ r✝) = node3R (dual r✝) x✝ (dual l✝) x (dual l)

Next tactic:
simp [dual_node3L, dual_node4L, node3R, add_comm]
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
  cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;>
    

Proof state:
case neg
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
h✝ : ¬size l✝ < ratio * size r✝
⊢ dual (node4L l x l✝ x✝ r✝) = node4R (dual r✝) x✝ (dual l✝) x (dual l)

Next tactic:
simp [dual_node3L, dual_node4L, node3R, add_comm]
theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (rotateR l x r) = rotateL (dual r) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (rotateR l x r) = rotateL (dual r) x (dual l)

Next tactic:
rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (balance' l x r) = balance' (dual r) x (dual l)

Next tactic:
simp [balance', add_comm]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; 

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual
      (if size l + size r ≤ 1 then node' l x r
      else
        if delta * size l < size r then rotateL l x r
        else if delta * size r < size l then rotateR l x r else node' l x r) =
    if size l + size r ≤ 1 then node' (dual r) x (dual l)
    else
      if delta * size r < size l then rotateL (dual r) x (dual l)
      else if delta * size l < size r then rotateR (dual r) x (dual l) else node' (dual r) x (dual l)

Next tactic:
split_ifs with h h_1 h_2
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
    

Proof state:
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
h : size l + size r ≤ 1
⊢ dual (node' l x r) = node' (dual r) x (dual l)

Next tactic:
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
    

Proof state:
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
h : ¬size l + size r ≤ 1
h_1 : delta * size l < size r
h_2 : delta * size r < size l
⊢ dual (rotateL l x r) = rotateL (dual r) x (dual l)

Next tactic:
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
    

Proof state:
case neg
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
h : ¬size l + size r ≤ 1
h_1 : delta * size l < size r
h_2 : ¬delta * size r < size l
⊢ dual (rotateL l x r) = rotateR (dual r) x (dual l)

Next tactic:
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
    

Proof state:
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
h : ¬size l + size r ≤ 1
h_1 : ¬delta * size l < size r
h✝ : delta * size r < size l
⊢ dual (rotateR l x r) = rotateL (dual r) x (dual l)

Next tactic:
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
    

Proof state:
case neg
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
h : ¬size l + size r ≤ 1
h_1 : ¬delta * size l < size r
h✝ : ¬delta * size r < size l
⊢ dual (node' l x r) = node' (dual r) x (dual l)

Next tactic:
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balance' l x r) = balance' (dual r) x (dual l) := by
  simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
    simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
  

Proof state:
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
h : ¬size l + size r ≤ 1
h_1 : delta * size l < size r
h_2 : delta * size r < size l
⊢ rotateR (dual r) x (dual l) = rotateL (dual r) x (dual l)

Next tactic:
cases delta_lt_false h_1 h_2
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  

Proof state:
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (balanceL l x r) = balanceR (dual r) x (dual l)

Next tactic:
unfold balanceL balanceR
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      

Proof state:
case nil.node.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ node 3 (node 1 nil x nil) lrx (node 1 nil lx nil) = node 3 (Ordnode.singleton x) lrx (Ordnode.singleton lx)

Next tactic:
try rfl
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try 

Proof state:
case nil.node.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ node 3 (node 1 nil x nil) lrx (node 1 nil lx nil) = node 3 (Ordnode.singleton x) lrx (Ordnode.singleton lx)

Next tactic:
rfl
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      

Proof state:
case nil.node.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ node 3 (node 1 nil x nil) lx (node lls (dual llr) llx (dual lll)) =
    node 3 (Ordnode.singleton x) lx (node lls (dual llr) llx (dual lll))

Next tactic:
try rfl
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try 

Proof state:
case nil.node.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ node 3 (node 1 nil x nil) lx (node lls (dual llr) llx (dual lll)) =
    node 3 (Ordnode.singleton x) lx (node lls (dual llr) llx (dual lll))

Next tactic:
rfl
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      

Proof state:
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))

Next tactic:
try rfl
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try 

Proof state:
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))

Next tactic:
rfl
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    

Proof state:
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
      else
        node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    if lrs < ratio * lls then
      node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))
    else
      node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))

Next tactic:
split_ifs with h
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> 

Proof state:
case pos
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
h : lrs < ratio * lls
⊢ dual (node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)) =
    node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))

Next tactic:
repeat simp [h, add_comm]
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> repeat 

Proof state:
case pos
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
h : lrs < ratio * lls
⊢ dual (node (ls + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)) =
    node (ls + 1) (node (lrs + 1) nil x (node lrs (dual lrr) lrx (dual lrl))) lx (node lls (dual llr) llx (dual lll))

Next tactic:
simp [h, add_comm]
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> repeat 

Proof state:

Next tactic:
simp [h, add_comm]
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> 

Proof state:
case neg
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
h : ¬lrs < ratio * lls
⊢ dual (node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
      (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))

Next tactic:
repeat simp [h, add_comm]
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> repeat 

Proof state:
case neg
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
h : ¬lrs < ratio * lls
⊢ dual (node (ls + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx (node (size lrr + 1) lrr x nil)) =
    node (ls + 1) (node (size (dual lrr) + 1) nil x (dual lrr)) lrx
      (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))

Next tactic:
simp [h, add_comm]
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> repeat simp [h, add_comm]
  · cases' l with ls ll lx lr; · rfl
    dsimp only [dual, id]
    

Proof state:
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (if ls > delta * rs 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 ls > delta * rs then
      rec (motive := fun t => dual ll = t → Ordnode α) (fun h => nil)
        (fun size l x_1 r l_ih r_ih h =>
          rec (motive := fun t => dual 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 (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx (dual ll)
              else
                node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                  (node (Ordnode.size r + size + 1) r lx (dual ll)))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
        (dual ll) (_ : id (dual ll) = id (dual ll))
    else node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))

Next tactic:
split_ifs
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> repeat simp [h, add_comm]
  · cases' l with ls ll lx lr; · rfl
    dsimp only [dual, id]
    split_ifs; 

Proof state:
case pos
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
⊢ dual
      (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 => dual ll = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => dual 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 (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual lr)) lx (dual ll)
            else
              node (rs + ls + 1) (node (rs + Ordnode.size l + 1) (node rs (dual rr) rx (dual rl)) x l) x_2
                (node (Ordnode.size r + size + 1) r lx (dual ll)))
          (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual ll) (_ : id (dual ll) = id (dual ll))
case neg
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ¬ls > delta * rs
⊢ dual (node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))

Next tactic:
swap
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
    dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
  unfold balanceL balanceR
  cases' r with rs rl rx rr
  · cases' l with ls ll lx lr; · rfl
    cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
      try rfl
    split_ifs with h <;> repeat simp [h, add_comm]
  · cases' l with ls ll lx lr; · rfl
    dsimp only [dual, id]
    split_ifs; swap; · 

Proof state:
case neg
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
h✝ : ¬ls > delta * rs
⊢ dual (node (ls + rs + 1) (node ls ll lx lr) x (node rs rl rx rr)) =
    node (rs + ls + 1) (node rs (dual rr) rx (dual rl)) x (node ls (dual lr) lx (dual ll))

Next tactic:
simp [add_comm]