Theorem: Ordnode.Valid'.glue_aux
File: Mathlib/Data/Ordmap/Ordset.lean

tactic: cases' l with ls ll lx lr
state_before: α : 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
bal : BalancedSz (size l) (size r)
⊢ Valid' o₁ (glue l r) o₂ ∧ size (glue l r) = size l + size r

tactic: cases' r with rs rl rx rr
state_before: case node
α : Type u_1
inst✝ : Preorder α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hr : Valid' o₁ r o₂
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
sep : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
bal : BalancedSz (size (Ordnode.node ls ll lx lr)) (size r)
⊢ Valid' o₁ (glue (Ordnode.node ls ll lx lr) r) o₂ ∧
    size (glue (Ordnode.node ls ll lx lr) r) = size (Ordnode.node ls ll lx lr) + size r

tactic: dsimp [glue]
state_before: case node.node
α : 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))
⊢ Valid' o₁ (glue (Ordnode.node ls ll lx lr) (Ordnode.node rs rl rx rr)) o₂ ∧
    size (glue (Ordnode.node ls ll lx lr) (Ordnode.node rs rl rx rr)) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)

tactic: split_ifs
state_before: case node.node
α : 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))
⊢ Valid' o₁
      (if ls > rs then Ordnode.balanceR (splitMax' ll lx lr).fst (splitMax' ll lx lr).snd (Ordnode.node rs rl rx rr)
      else Ordnode.balanceL (Ordnode.node ls ll lx lr) (splitMin' rl rx rr).fst (splitMin' rl rx rr).snd)
      o₂ ∧
    size
        (if ls > rs then Ordnode.balanceR (splitMax' ll lx lr).fst (splitMax' ll lx lr).snd (Ordnode.node rs rl rx rr)
        else Ordnode.balanceL (Ordnode.node ls ll lx lr) (splitMin' rl rx rr).fst (splitMin' rl rx rr).snd) =
      ls + rs

tactic: exact ⟨hr, (zero_add _).symm⟩
state_before: case nil
α : Type u_1
inst✝ : Preorder α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hr : Valid' o₁ r o₂
hl : Valid' o₁ nil o₂
sep : All (fun x => All (fun y => x < y) r) nil
bal : BalancedSz (size nil) (size r)
⊢ Valid' o₁ (glue nil r) o₂ ∧ size (glue nil r) = size nil + size r

tactic: exact ⟨hl, rfl⟩
state_before: case node.nil
α : 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₂
hr : Valid' o₁ nil o₂
sep : All (fun x => All (fun y => x < y) nil) (Ordnode.node ls ll lx lr)
bal : BalancedSz (size (Ordnode.node ls ll lx lr)) (size nil)
⊢ Valid' o₁ (glue (Ordnode.node ls ll lx lr) nil) o₂ ∧
    size (glue (Ordnode.node ls ll lx lr) nil) = size (Ordnode.node ls ll lx lr) + size nil

tactic: rw [splitMax_eq]
state_before: case node.node.inl
α : 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
⊢ Valid' o₁ (Ordnode.balanceR (splitMax' ll lx lr).fst (splitMax' ll lx lr).snd (Ordnode.node rs rl rx rr)) o₂ ∧
    size (Ordnode.balanceR (splitMax' ll lx lr).fst (splitMax' ll lx lr).snd (Ordnode.node rs rl rx rr)) = ls + rs

tactic: cases' Valid'.eraseMax_aux hl with v e
state_before: case node.node.inl
α : 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
⊢ Valid' o₁
      (Ordnode.balanceR (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (Ordnode.balanceR (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).fst
          (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr)) =
      ls + rs

case node.node.inl.s
α : 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
⊢ ℕ

tactic: suffices H
state_before: case node.node.inl.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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
⊢ Valid' o₁
      (Ordnode.balanceR (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (Ordnode.balanceR (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).fst
          (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr)) =
      ls + rs

case node.node.inl.s
α : 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
⊢ ℕ

tactic: refine' ⟨Valid'.balanceR v (hr.of_gt _ _) H, _⟩
state_before: case node.node.inl.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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
H : ?m.349956
⊢ Valid' o₁
      (Ordnode.balanceR (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (Ordnode.balanceR (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).fst
          (eraseMax (Ordnode.node ?node.node.inl.s ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr)) =
      ls + rs

case H
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
⊢ ?m.349956

case node.node.inl.s
α : 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
⊢ ℕ

tactic: refine' findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂)
  lx lr hl.1.2.to_nil (sep.2.2.imp _)
state_before: case node.node.inl.intro.refine'_1
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
H :
  (∃ l',
      Raised (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) l' ∧
        BalancedSz l' (size (Ordnode.node rs rl rx rr))) ∨
    ∃ r',
      Raised r' (size (Ordnode.node rs rl rx rr)) ∧
        BalancedSz (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) r'
⊢ Bounded nil (↑(eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).snd) o₂

tactic: exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1)
state_before: case node.node.inl.intro.refine'_1
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
H :
  (∃ l',
      Raised (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) l' ∧
        BalancedSz l' (size (Ordnode.node rs rl rx rr))) ∨
    ∃ r',
      Raised r' (size (Ordnode.node rs rl rx rr)) ∧
        BalancedSz (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) r'
⊢ ∀ (a : α), All (fun y => a < y) (Ordnode.node rs rl rx rr) → Bounded nil (↑a) o₂

tactic: rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]
state_before: case node.node.inl.intro.refine'_3
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
H :
  (∃ l',
      Raised (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) l' ∧
        BalancedSz l' (size (Ordnode.node rs rl rx rr))) ∨
    ∃ r',
      Raised r' (size (Ordnode.node rs rl rx rr)) ∧
        BalancedSz (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) r'
⊢ size
      (Ordnode.balanceR (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr)) =
    ls + rs

tactic: rfl
state_before: case node.node.inl.intro.refine'_3
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
H :
  (∃ l',
      Raised (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) l' ∧
        BalancedSz l' (size (Ordnode.node rs rl rx rr))) ∨
    ∃ r',
      Raised r' (size (Ordnode.node rs rl rx rr)) ∧
        BalancedSz (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) r'
⊢ size (Ordnode.node' ll lx lr) + size (Ordnode.node rs rl rx rr) = size ll + size lr + 1 + rs

tactic: refine' Or.inl ⟨_, Or.inr e, _⟩
state_before: case H
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
⊢ (∃ l',
      Raised (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) l' ∧
        BalancedSz l' (size (Ordnode.node rs rl rx rr))) ∨
    ∃ r',
      Raised r' (size (Ordnode.node rs rl rx rr)) ∧
        BalancedSz (size (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).fst) r'

tactic: rwa [hl.2.eq_node'] at bal
state_before: case H
α : 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' o₁ (eraseMax (Ordnode.node' ll lx lr)) ↑(findMax' lx lr)
e : size (Ordnode.node' ll lx lr) = size (eraseMax (Ordnode.node' ll lx lr)) + 1
⊢ BalancedSz (size (Ordnode.node' ll lx lr)) (size (Ordnode.node rs rl rx rr))

tactic: rw [splitMin_eq]
state_before: case node.node.inr
α : 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
⊢ Valid' o₁ (Ordnode.balanceL (Ordnode.node ls ll lx lr) (splitMin' rl rx rr).fst (splitMin' rl rx rr).snd) o₂ ∧
    size (Ordnode.balanceL (Ordnode.node ls ll lx lr) (splitMin' rl rx rr).fst (splitMin' rl rx rr).snd) = ls + rs

tactic: cases' Valid'.eraseMin_aux hr with v e
state_before: case node.node.inr
α : 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
⊢ Valid' o₁
      (Ordnode.balanceL (Ordnode.node ls ll lx lr)
        (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).snd)
      o₂ ∧
    size
        (Ordnode.balanceL (Ordnode.node ls ll lx lr)
          (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).fst
          (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).snd) =
      ls + rs

case node.node.inr.s
α : 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
⊢ ℕ

tactic: suffices H
state_before: case node.node.inr.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
⊢ Valid' o₁
      (Ordnode.balanceL (Ordnode.node ls ll lx lr)
        (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).snd)
      o₂ ∧
    size
        (Ordnode.balanceL (Ordnode.node ls ll lx lr)
          (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).fst
          (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).snd) =
      ls + rs

case node.node.inr.s
α : 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
⊢ ℕ

tactic: refine' ⟨Valid'.balanceL (hl.of_lt _ _) v H, _⟩
state_before: case node.node.inr.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
H : ?m.351034
⊢ Valid' o₁
      (Ordnode.balanceL (Ordnode.node ls ll lx lr)
        (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).snd)
      o₂ ∧
    size
        (Ordnode.balanceL (Ordnode.node ls ll lx lr)
          (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).fst
          (findMin' rl rx, eraseMin (Ordnode.node ?node.node.inr.s rl rx rr)).snd) =
      ls + rs

case H
α : 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
⊢ ?m.351034

case node.node.inr.s
α : 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
⊢ ℕ

tactic: refine' @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α))
  rl rx (sep.2.1.1.imp _) hr.1.1.to_nil
state_before: case node.node.inr.intro.refine'_1
α : 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
H :
  (∃ l',
      Raised l' (size (Ordnode.node ls ll lx lr)) ∧
        BalancedSz l' (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd)) ∨
    ∃ r',
      Raised (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd) r' ∧
        BalancedSz (size (Ordnode.node ls ll lx lr)) r'
⊢ Bounded nil o₁ ↑(findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).fst

tactic: exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h)
state_before: case node.node.inr.intro.refine'_1
α : 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
H :
  (∃ l',
      Raised l' (size (Ordnode.node ls ll lx lr)) ∧
        BalancedSz l' (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd)) ∨
    ∃ r',
      Raised (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd) r' ∧
        BalancedSz (size (Ordnode.node ls ll lx lr)) r'
⊢ ∀ (a : α), lx < a → Bounded nil o₁ ↑a

tactic: rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]
state_before: case node.node.inr.intro.refine'_3
α : 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
H :
  (∃ l',
      Raised l' (size (Ordnode.node ls ll lx lr)) ∧
        BalancedSz l' (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd)) ∨
    ∃ r',
      Raised (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd) r' ∧
        BalancedSz (size (Ordnode.node ls ll lx lr)) r'
⊢ size
      (Ordnode.balanceL (Ordnode.node ls ll lx lr)
        (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd) =
    ls + rs

tactic: rfl
state_before: case node.node.inr.intro.refine'_3
α : 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
H :
  (∃ l',
      Raised l' (size (Ordnode.node ls ll lx lr)) ∧
        BalancedSz l' (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd)) ∨
    ∃ r',
      Raised (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd) r' ∧
        BalancedSz (size (Ordnode.node ls ll lx lr)) r'
⊢ size (Ordnode.node ls ll lx lr) + size (Ordnode.node' rl rx rr) = ls + (size rl + size rr + 1)

tactic: refine' Or.inr ⟨_, Or.inr e, _⟩
state_before: case H
α : 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
⊢ (∃ l',
      Raised l' (size (Ordnode.node ls ll lx lr)) ∧
        BalancedSz l' (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd)) ∨
    ∃ r',
      Raised (size (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).snd) r' ∧
        BalancedSz (size (Ordnode.node ls ll lx lr)) r'

tactic: rwa [hr.2.eq_node'] at bal
state_before: case H
α : 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))