l3lab/ntp-mathlib huggingface dataset:
theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
    (sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) :
    Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by
  cases' l with ls ll lx lr; · exact ⟨hr, (zero_add _).symm⟩
  cases' r with rs rl rx rr; · exact ⟨hl, rfl⟩
  dsimp [glue]; split_ifs
  · rw [splitMax_eq]
    cases' Valid'.eraseMax_aux hl with v e
    suffices H : _ by
      refine' ⟨Valid'.balanceR v (hr.of_gt _ _) H, _⟩
      · refine' findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂)
          lx lr hl.1.2.to_nil (sep.2.2.imp _)
        exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1)
      · exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2
      · rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl
    refine' Or.inl ⟨_, Or.inr e, _⟩
    rwa [hl.2.eq_node'] at bal
  · rw [splitMin_eq]
    cases' Valid'.eraseMin_aux hr with v e
    suffices H : _ by
      refine' ⟨Valid'.balanceL (hl.of_lt _ _) v H, _⟩
      · refine' @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α))
          rl rx (sep.2.1.1.imp _) hr.1.1.to_nil
        exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h)
      · exact
          @findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx
            (all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx)
            (sep.imp fun y hy => hy.2.1)
      · rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl
    refine' Or.inr ⟨_, Or.inr e, _⟩
    

Proof state:
case neg.intro
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
sep : All (fun x => All (fun y => x < y) (Ordnode.node rs rl rx rr)) (Ordnode.node ls ll lx lr)
bal : BalancedSz (size (Ordnode.node ls ll lx lr)) (size (Ordnode.node rs rl rx rr))
h✝ : ¬ls > rs
v : Valid' (↑(findMin' rl rx)) (eraseMin (Ordnode.node' rl rx rr)) o₂
e : size (Ordnode.node' rl rx rr) = size (eraseMin (Ordnode.node' rl rx rr)) + 1
⊢ BalancedSz (size (Ordnode.node ls ll lx lr)) (size (Ordnode.node' rl rx rr))

Next tactic:
rwa [hr.2.eq_node'] at bal
theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) :
    2 * (a + b) ≤ 9 * c + 5 := by 

Proof state:
α : Type u_1
inst✝ : Preorder α
a b c : ℕ
h₁ : 3 * a < b + c + 1
h₂ : b ≤ 3 * c
⊢ 2 * (a + b) ≤ 9 * c + 5

Next tactic:
linarith
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : delta * ls < rs
v : Valid' o₁ t ↑rx
e : size t = ls + size rl
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
rw [hl.2.1] at e
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : delta * ls < rs
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
rw [hl.2.1, hr.2.1, delta] at h
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩)
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · 

Proof state:
case inl
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
H : size rl + size rr ≤ 1
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
linarith
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  

Proof state:
case inr.intro
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · rw [e, add_right_comm]; rintro ⟨⟩
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : ?m.356099
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : ?m.356099
H₁ : ?m.356105
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · 

Proof state:
case refine'_1
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t
H₁ : size t = 0 → size rr ≤ 1
⊢ 2 * size t ≤ 9 * size rr + 5 ∨ size t ≤ 3

Next tactic:
rw [e]
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; 

Proof state:
case refine'_1
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t
H₁ : size t = 0 → size rr ≤ 1
⊢ 2 * (size ll + size lr + 1 + size rl) ≤ 9 * size rr + 5 ∨ size ll + size lr + 1 + size rl ≤ 3

Next tactic:
exact Or.inl (Valid'.merge_lemma h hr₁)
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · 

Proof state:
case refine'_2
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t
H₁ : size t = 0 → size rr ≤ 1
⊢ size (Ordnode.balanceL t rx rr) = ls + rs

Next tactic:
rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        

Proof state:
case refine'_2
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t
H₁ : size t = 0 → size rr ≤ 1
⊢ size ll + size lr + 1 + size rl + size rr + 1 = size ll + size lr + 1 + (size rl + size rr + 1)

Next tactic:
abel
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · 

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t
⊢ size t = 0 → size rr ≤ 1

Next tactic:
rw [e, add_right_comm]
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · rw [e, add_right_comm]; 

Proof state:
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
H₂ : 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t
⊢ size ll + size lr + size rl + 1 = 0 → size rr ≤ 1

Next tactic:
rintro ⟨⟩
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · rw [e, add_right_comm]; rintro ⟨⟩
  · 

Proof state:
case inr.intro
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
⊢ 1 ≤ size t → 1 ≤ size rr → size rr ≤ delta * size t

Next tactic:
intro _ _
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · rw [e, add_right_comm]; rintro ⟨⟩
  · intro _ _; 

Proof state:
case inr.intro
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
a✝¹ : 1 ≤ size t
a✝ : 1 ≤ size rr
⊢ size rr ≤ delta * size t

Next tactic:
rw [e]
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · rw [e, add_right_comm]; rintro ⟨⟩
  · intro _ _; rw [e]; 

Proof state:
case inr.intro
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ delta * size rl
a✝¹ : 1 ≤ size t
a✝ : 1 ≤ size rr
⊢ size rr ≤ delta * (size ll + size lr + 1 + size rl)

Next tactic:
unfold delta at hr₂ ⊢
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
    (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
    (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
    Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
  rw [hl.2.1] at e
  rw [hl.2.1, hr.2.1, delta] at h
  rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · linarith
  suffices H₂ : _ by
    suffices H₁ : _ by
      refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
      · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
      · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
          size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
        abel
    · rw [e, add_right_comm]; rintro ⟨⟩
  · intro _ _; rw [e]; unfold delta at hr₂ ⊢; 

Proof state:
case inr.intro
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr t : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ (Ordnode.node rs rl rx rr) o₂
h : 3 * (size ll + size lr + 1) < size rl + size rr + 1
v : Valid' o₁ t ↑rx
e : size t = size ll + size lr + 1 + size rl
hr₁ : size rl ≤ delta * size rr
hr₂ : size rr ≤ 3 * size rl
a✝¹ : 1 ≤ size t
a✝ : 1 ≤ size rr
⊢ size rr ≤ 3 * (size ll + size lr + 1 + size rl)

Next tactic:
linarith
theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
    (sep : l.All fun x => r.All fun y => x < y) :
    Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by
  

Proof state:
α : Type u_1
inst✝ : Preorder α
l r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l o₂
hr : Valid' o₁ r o₂
sep : All (fun x => All (fun y => x < y) r) l
⊢ Valid' o₁ (merge l r) o₂ ∧ size (merge l r) = size l + size r

Next tactic:
induction' l with ls ll lx lr _ IHlr generalizing o₁ o₂ r
theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
    (sep : l.All fun x => r.All fun y => x < y) :
    Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by
  induction' l with ls ll lx lr _ IHlr generalizing o₁ o₂ r
  · 

Proof state:
case nil
α : Type u_1
inst✝ : Preorder α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ nil o₂
hr : Valid' o₁ r o₂
sep : All (fun x => All (fun y => x < y) r) nil
⊢ Valid' o₁ (merge nil r) o₂ ∧ size (merge nil r) = size nil + size r

Next tactic:
exact ⟨hr, (zero_add _).symm⟩