[GOAL]
α : Type u_1
a b : ℕ
h₁ : delta * a < b
h₂ : delta * b < a
⊢ 0 < delta
[PROOFSTEP]
decide
[GOAL]
α : Type u_1
a b : ℕ
h₁ : delta * a < b
h₂ : delta * b < a
⊢ a ≤ delta * (delta * a)
[PROOFSTEP]
simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta)
[GOAL]
α : Type u_1
a b : ℕ
h₁ : delta * a < b
h₂ : delta * b < a
⊢ 1 ≤ delta * delta
[PROOFSTEP]
decide
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
h : Sized (node s l x r)
⊢ node s l x r = Ordnode.node' l x r
[PROOFSTEP]
rw [h.1]
[GOAL]
α : Type u_1
t : Ordnode α
hl : Sized t
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
⊢ C t
[PROOFSTEP]
induction t with
| nil => exact H0
| node _ _ _ _ t_ih_l t_ih_r =>
  rw [hl.eq_node']
  exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
[GOAL]
α : Type u_1
t : Ordnode α
hl : Sized t
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
⊢ C t
[PROOFSTEP]
induction t with
| nil => exact H0
| node _ _ _ _ t_ih_l t_ih_r =>
  rw [hl.eq_node']
  exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
[GOAL]
case nil
α : Type u_1
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
hl : Sized nil
⊢ C nil
[PROOFSTEP]

| nil => exact H0
[GOAL]
case nil
α : Type u_1
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
hl : Sized nil
⊢ C nil
[PROOFSTEP]
exact H0
[GOAL]
case node
α : Type u_1
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l : Sized l✝ → C l✝
t_ih_r : Sized r✝ → C r✝
hl : Sized (node size✝ l✝ x✝ r✝)
⊢ C (node size✝ l✝ x✝ r✝)
[PROOFSTEP]

| node _ _ _ _ t_ih_l t_ih_r =>
  rw [hl.eq_node']
  exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
[GOAL]
case node
α : Type u_1
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l : Sized l✝ → C l✝
t_ih_r : Sized r✝ → C r✝
hl : Sized (node size✝ l✝ x✝ r✝)
⊢ C (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
rw [hl.eq_node']
[GOAL]
case node
α : Type u_1
C : Ordnode α → Prop
H0 : C nil
H1 : ∀ (l : Ordnode α) (x : α) (r : Ordnode α), C l → C r → C (Ordnode.node' l x r)
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l : Sized l✝ → C l✝
t_ih_r : Sized r✝ → C r✝
hl : Sized (node size✝ l✝ x✝ r✝)
⊢ C (Ordnode.node' l✝ x✝ r✝)
[PROOFSTEP]
exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
h₁ : s = size l + size r + 1
h₂ : Sized l
h₃ : Sized r
⊢ size (node s l x r) = realSize (node s l x r)
[PROOFSTEP]
rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
h₁ : s = size l + size r + 1
h₂ : Sized l
h₃ : Sized r
⊢ realSize l + realSize r + 1 = realSize (node (realSize l + realSize r + 1) l x r)
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
t : Ordnode α
ht : Sized t
⊢ size t = 0 ↔ t = nil
[PROOFSTEP]
cases t <;> [simp; simp [ht.1]]
[GOAL]
α : Type u_1
t : Ordnode α
ht : Sized t
⊢ size t = 0 ↔ t = nil
[PROOFSTEP]
cases t
[GOAL]
case nil
α : Type u_1
ht : Sized nil
⊢ size nil = 0 ↔ nil = nil
[PROOFSTEP]
simp
[GOAL]
case node
α : Type u_1
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
ht : Sized (node size✝ l✝ x✝ r✝)
⊢ size (node size✝ l✝ x✝ r✝) = 0 ↔ node size✝ l✝ x✝ r✝ = nil
[PROOFSTEP]
simp [ht.1]
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
h : Sized (node s l x r)
⊢ 0 < s
[PROOFSTEP]
rw [h.1]
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
h : Sized (node s l x r)
⊢ 0 < size l + size r + 1
[PROOFSTEP]
apply Nat.le_add_left
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (dual (node s l x r)) = node s l x r
[PROOFSTEP]
rw [dual, dual, dual_dual l, dual_dual r]
[GOAL]
α : Type u_1
t : Ordnode α
⊢ size (dual t) = size t
[PROOFSTEP]
cases t
[GOAL]
case nil
α : Type u_1
⊢ size (dual nil) = size nil
[PROOFSTEP]
rfl
[GOAL]
case node
α : Type u_1
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ size (dual (node size✝ l✝ x✝ r✝)) = size (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
⊢ Decidable (Balanced nil)
[PROOFSTEP]
unfold Balanced
[GOAL]
α : Type u_1
⊢ Decidable True
[PROOFSTEP]
infer_instance
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
⊢ Decidable (Balanced (node size✝ l x✝ r))
[PROOFSTEP]
unfold Balanced
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
⊢ Decidable (BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r)
[PROOFSTEP]
haveI := Balanced.dec l
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
this : Decidable (Balanced l)
⊢ Decidable (BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r)
[PROOFSTEP]
haveI := Balanced.dec r
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
this✝ : Decidable (Balanced l)
this : Decidable (Balanced r)
⊢ Decidable (BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r)
[PROOFSTEP]
infer_instance
[GOAL]
α : Type u_1
l r : ℕ
⊢ l + r ≤ 1 → r + l ≤ 1
[PROOFSTEP]
rw [add_comm]
[GOAL]
α : Type u_1
l r : ℕ
⊢ r + l ≤ 1 → r + l ≤ 1
[PROOFSTEP]
exact id
[GOAL]
α : Type u_1
l : ℕ
⊢ BalancedSz l 0 ↔ l ≤ 1
[PROOFSTEP]
simp (config := { contextual := true }) [BalancedSz]
[GOAL]
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
H : BalancedSz l r₁
⊢ BalancedSz l r₂
[PROOFSTEP]
refine' or_iff_not_imp_left.2 fun h => _
[GOAL]
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
H : BalancedSz l r₁
h : ¬l + r₂ ≤ 1
⊢ l ≤ delta * r₂ ∧ r₂ ≤ delta * l
[PROOFSTEP]
refine' ⟨_, h₂.resolve_left h⟩
[GOAL]
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
H : BalancedSz l r₁
h : ¬l + r₂ ≤ 1
⊢ l ≤ delta * r₂
[PROOFSTEP]
cases H with
| inl H =>
  cases r₂
  · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
  · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
| inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
[GOAL]
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
H : BalancedSz l r₁
h : ¬l + r₂ ≤ 1
⊢ l ≤ delta * r₂
[PROOFSTEP]
cases H with
| inl H =>
  cases r₂
  · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
  · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
| inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
[GOAL]
case inl
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
h : ¬l + r₂ ≤ 1
H : l + r₁ ≤ 1
⊢ l ≤ delta * r₂
[PROOFSTEP]

| inl H =>
  cases r₂
  · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
  · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
[GOAL]
case inl
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
h : ¬l + r₂ ≤ 1
H : l + r₁ ≤ 1
⊢ l ≤ delta * r₂
[PROOFSTEP]
cases r₂
[GOAL]
case inl.zero
α : Type u_1
l r₁ : ℕ
H : l + r₁ ≤ 1
h₁ : r₁ ≤ Nat.zero
h₂ : l + Nat.zero ≤ 1 ∨ Nat.zero ≤ delta * l
h : ¬l + Nat.zero ≤ 1
⊢ l ≤ delta * Nat.zero
[PROOFSTEP]
cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
[GOAL]
case inl.succ
α : Type u_1
l r₁ : ℕ
H : l + r₁ ≤ 1
n✝ : ℕ
h₁ : r₁ ≤ Nat.succ n✝
h₂ : l + Nat.succ n✝ ≤ 1 ∨ Nat.succ n✝ ≤ delta * l
h : ¬l + Nat.succ n✝ ≤ 1
⊢ l ≤ delta * Nat.succ n✝
[PROOFSTEP]
exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
[GOAL]
case inr
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
h : ¬l + r₂ ≤ 1
H : l ≤ delta * r₁ ∧ r₁ ≤ delta * l
⊢ l ≤ delta * r₂
[PROOFSTEP]

| inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
[GOAL]
case inr
α : Type u_1
l r₁ r₂ : ℕ
h₁ : r₁ ≤ r₂
h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l
h : ¬l + r₂ ≤ 1
H : l ≤ delta * r₁ ∧ r₁ ≤ delta * l
⊢ l ≤ delta * r₂
[PROOFSTEP]
exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
b : BalancedSz (size l) (size r)
bl : Balanced l
br : Balanced r
⊢ BalancedSz (size (Ordnode.dual r)) (size (Ordnode.dual l))
[PROOFSTEP]
rw [size_dual, size_dual]
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
b : BalancedSz (size l) (size r)
bl : Balanced l
br : Balanced r
⊢ BalancedSz (size r) (size l)
[PROOFSTEP]
exact b.symm
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (node' l x r) = node' (dual r) x (dual l)
[PROOFSTEP]
simp [node', add_comm]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l)
[PROOFSTEP]
simp [node3L, node3R, dual_node', add_comm]
[GOAL]
α : 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)
[PROOFSTEP]
simp [node3L, node3R, dual_node', add_comm]
[GOAL]
α : 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)
[PROOFSTEP]
cases m
[GOAL]
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)
[PROOFSTEP]
simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
[GOAL]
α : 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)
[PROOFSTEP]
cases m
[GOAL]
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)
[PROOFSTEP]
simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (rotateL l x r) = rotateR (dual r) x (dual l)
[PROOFSTEP]
cases r
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x : α
⊢ dual (rotateL l x nil) = rotateR (dual nil) x (dual l)
[PROOFSTEP]
simp [rotateL, rotateR, dual_node']
[GOAL]
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)
[PROOFSTEP]
simp [rotateL, rotateR, dual_node']
[GOAL]
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)
[PROOFSTEP]
split_ifs
[GOAL]
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)
[PROOFSTEP]
simp [dual_node3L, dual_node4L, node3R, add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [dual_node3L, dual_node4L, node3R, add_comm]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (rotateR l x r) = rotateL (dual r) x (dual l)
[PROOFSTEP]
rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (balance' l x r) = balance' (dual r) x (dual l)
[PROOFSTEP]
simp [balance', add_comm]
[GOAL]
α : 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)
[PROOFSTEP]
split_ifs with h h_1 h_2
[GOAL]
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)
[PROOFSTEP]
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
[GOAL]
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)
[PROOFSTEP]
cases delta_lt_false h_1 h_2
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (balanceL l x r) = balanceR (dual r) x (dual l)
[PROOFSTEP]
unfold balanceL balanceR
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id r = t → Ordnode α) (id r)
        (fun h =>
          (_ : nil = id r) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 l x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id l = id l))
        (fun rs l_1 x_1 r_1 h =>
          (_ : node rs l_1 x_1 r_1 = id r) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ node (rs + 1) nil x r)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  if ls > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r_2 h =>
                        (_ : node lls l x_2 r_2 = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls + rs + 1) ll lx (node (rs + lrs + 1) lr x r)
                                else
                                  node (ls + rs + 1) (node (lls + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs + 1) lrr x r))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs + 1) l x r)
              (_ : id l = id l))
        (_ : id r = id r)) =
    Ordnode.casesOn (motive := fun t => id (dual r) = t → Ordnode α) (id (dual r))
      (fun h =>
        (_ : nil = id (dual r)) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual l))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual l) = id (dual l)))
      (fun ls l_1 x_1 r_1 h =>
        (_ : node ls l_1 x_1 r_1 = id (dual r)) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ node (ls + 1) (dual r) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                if rs > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r_2 h =>
                      (_ : node rrs l x_2 r_2 = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) (dual r) x rl) rx rr
                              else
                                node (ls + rs + 1) (node (ls + size rll + 1) (dual r) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls + rs + 1) (dual r) x (dual l))
            (_ : id (dual l) = id (dual l)))
      (_ : id (dual r) = id (dual r))
[PROOFSTEP]
cases' r with rs rl rx rr
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x : α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 l x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id l = id l))
        (fun rs l_1 x_1 r h =>
          (_ : node rs l_1 x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ node (rs + 1) nil x nil)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  if ls > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls + rs + 1) ll lx (node (rs + lrs + 1) lr x nil)
                                else
                                  node (ls + rs + 1) (node (lls + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs + 1) l x nil)
              (_ : id l = id l))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual l))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual l) = id (dual l)))
      (fun ls l_1 x_1 r h =>
        (_ : node ls l_1 x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ node (ls + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                if rs > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls + rs + 1) (node (ls + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls + rs + 1) (dual nil) x (dual l))
            (_ : id (dual l) = id (dual l)))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
cases' l with ls ll lx lr
[GOAL]
case nil.nil
α : Type u_1
x : α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 nil x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id nil = id nil))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ node (rs + 1) nil x nil)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  if ls > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls + rs + 1) ll lx (node (rs + lrs + 1) lr x nil)
                                else
                                  node (ls + rs + 1) (node (lls + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs + 1) nil x nil)
              (_ : id nil = id nil))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual nil))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual nil) = id (dual nil)))
      (fun ls l x_1 r h =>
        (_ : node ls l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ node (ls + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                if rs > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then node (ls + rs + 1) (node (ls + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls + rs + 1) (node (ls + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls + rs + 1) (dual nil) x (dual nil))
            (_ : id (dual nil) = id (dual nil)))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
rfl
[GOAL]
case nil.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                    (fun h =>
                      (_ : nil = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls ll lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll_1 lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll_1 lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll_1 = id ll_1))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                      (fun h => (_ : nil = id ll_1) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll_1) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then
                                  node (ls_1 + rs + 1) ll_1 lx_1 (node (rs + lrs + 1) lr_1 x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll_1 = id ll_1)
                  else node (ls_1 + rs + 1) (node ls ll lx lr) x nil)
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr))) (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls ll lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr)))
            (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls ll lx lr)))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
cases' ll with lls lll llx llr
[GOAL]
case nil.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls nil lx lr) = t → Ordnode α) (id (node ls nil lx lr))
              (fun h => (_ : nil = id (node ls nil lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll lx_1 lr_1 h =>
                (_ : node ls_1 ll lx_1 lr_1 = id (node ls nil lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls nil lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll = id ll))
              (_ : id (node ls nil lx lr) = id (node ls nil lx lr)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls nil lx lr) = t → Ordnode α) (id (node ls nil lx lr))
              (fun h => (_ : nil = id (node ls nil lx lr)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll lx_1 lr_1 h =>
                (_ : node ls_1 ll lx_1 lr_1 = id (node ls nil lx lr)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then node (ls_1 + rs + 1) ll lx_1 (node (rs + lrs + 1) lr_1 x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll = id ll)
                  else node (ls_1 + rs + 1) (node ls nil lx lr) x nil)
              (_ : id (node ls nil lx lr) = id (node ls nil lx lr)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls nil lx lr)) = t → Ordnode α)
            (id (dual (node ls nil lx lr))) (fun h => (_ : nil = id (dual (node ls nil lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls nil lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls nil lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls nil lx lr)) = id (dual (node ls nil lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls nil lx lr)) = t → Ordnode α)
            (id (dual (node ls nil lx lr)))
            (fun h => (_ : nil = id (dual (node ls nil lx lr))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls nil lx lr))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls nil lx lr)))
            (_ : id (dual (node ls nil lx lr)) = id (dual (node ls nil lx lr))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case nil.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls (node lls lll llx llr) lx lr) = t → Ordnode α)
              (id (node ls (node lls lll llx llr) lx lr))
              (fun h => (_ : nil = id (node ls (node lls lll llx llr) lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll lx_1 lr_1 h =>
                (_ : node ls_1 ll lx_1 lr_1 = id (node ls (node lls lll llx llr) lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls (node lls lll llx llr) lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll = id ll))
              (_ : id (node ls (node lls lll llx llr) lx lr) = id (node ls (node lls lll llx llr) lx lr)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls (node lls lll llx llr) lx lr) = t → Ordnode α)
              (id (node ls (node lls lll llx llr) lx lr))
              (fun h => (_ : nil = id (node ls (node lls lll llx llr) lx lr)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll lx_1 lr_1 h =>
                (_ : node ls_1 ll lx_1 lr_1 = id (node ls (node lls lll llx llr) lx lr)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then node (ls_1 + rs + 1) ll lx_1 (node (rs + lrs + 1) lr_1 x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll = id ll)
                  else node (ls_1 + rs + 1) (node ls (node lls lll llx llr) lx lr) x nil)
              (_ : id (node ls (node lls lll llx llr) lx lr) = id (node ls (node lls lll llx llr) lx lr)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls (node lls lll llx llr) lx lr)) = t → Ordnode α)
            (id (dual (node ls (node lls lll llx llr) lx lr)))
            (fun h => (_ : nil = id (dual (node ls (node lls lll llx llr) lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls (node lls lll llx llr) lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls (node lls lll llx llr) lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls (node lls lll llx llr) lx lr)) = id (dual (node ls (node lls lll llx llr) lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls (node lls lll llx llr) lx lr)) = t → Ordnode α)
            (id (dual (node ls (node lls lll llx llr) lx lr)))
            (fun h => (_ : nil = id (dual (node ls (node lls lll llx llr) lx lr))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls (node lls lll llx llr) lx lr))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls (node lls lll llx llr) lx lr)))
            (_ : id (dual (node ls (node lls lll llx llr) lx lr)) = id (dual (node ls (node lls lll llx llr) lx lr))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case nil.node.nil.nil
α : Type u_1
x : α
ls : ℕ
lx : α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls nil lx nil) = t → Ordnode α) (id (node ls nil lx nil))
              (fun h => (_ : nil = id (node ls nil lx nil)) ▸ Ordnode.singleton x)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls nil lx nil)) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 (node ls nil lx nil) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll lx_1 (node (lrs + 1) lr x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id (node ls nil lx nil) = id (node ls nil lx nil)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls nil lx nil) = t → Ordnode α) (id (node ls nil lx nil))
              (fun h => (_ : nil = id (node ls nil lx nil)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls nil lx nil)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls_1 + rs + 1) ll lx_1 (node (rs + lrs + 1) lr x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls_1 + rs + 1) (node ls nil lx nil) x nil)
              (_ : id (node ls nil lx nil) = id (node ls nil lx nil)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls nil lx nil)) = t → Ordnode α)
            (id (dual (node ls nil lx nil))) (fun h => (_ : nil = id (dual (node ls nil lx nil))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls nil lx nil))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls nil lx nil)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls nil lx nil)) = id (dual (node ls nil lx nil))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls nil lx nil)) = t → Ordnode α)
            (id (dual (node ls nil lx nil)))
            (fun h => (_ : nil = id (dual (node ls nil lx nil))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls nil lx nil))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls nil lx nil)))
            (_ : id (dual (node ls nil lx nil)) = id (dual (node ls nil lx nil))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
dsimp only [dual, id]
[GOAL]
case nil.node.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls nil lx (node lrs lrl lrx lrr)) = t → Ordnode α)
              (id (node ls nil lx (node lrs lrl lrx lrr)))
              (fun h => (_ : nil = id (node ls nil lx (node lrs lrl lrx lrr))) ▸ Ordnode.singleton x)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls nil lx (node lrs lrl lrx lrr))) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 (node ls nil lx (node lrs lrl lrx lrr)) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll lx_1 (node (lrs + 1) lr x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id (node ls nil lx (node lrs lrl lrx lrr)) = id (node ls nil lx (node lrs lrl lrx lrr))))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls nil lx (node lrs lrl lrx lrr)) = t → Ordnode α)
              (id (node ls nil lx (node lrs lrl lrx lrr)))
              (fun h => (_ : nil = id (node ls nil lx (node lrs lrl lrx lrr))) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls nil lx (node lrs lrl lrx lrr))) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls_1 + rs + 1) ll lx_1 (node (rs + lrs + 1) lr x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls_1 + rs + 1) (node ls nil lx (node lrs lrl lrx lrr)) x nil)
              (_ : id (node ls nil lx (node lrs lrl lrx lrr)) = id (node ls nil lx (node lrs lrl lrx lrr))))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls nil lx (node lrs lrl lrx lrr))) = t → Ordnode α)
            (id (dual (node ls nil lx (node lrs lrl lrx lrr))))
            (fun h => (_ : nil = id (dual (node ls nil lx (node lrs lrl lrx lrr)))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls nil lx (node lrs lrl lrx lrr)))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls nil lx (node lrs lrl lrx lrr))))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls nil lx (node lrs lrl lrx lrr))) = id (dual (node ls nil lx (node lrs lrl lrx lrr)))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls nil lx (node lrs lrl lrx lrr))) = t → Ordnode α)
            (id (dual (node ls nil lx (node lrs lrl lrx lrr))))
            (fun h => (_ : nil = id (dual (node ls nil lx (node lrs lrl lrx lrr)))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls nil lx (node lrs lrl lrx lrr)))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls nil lx (node lrs lrl lrx lrr))))
            (_ : id (dual (node ls nil lx (node lrs lrl lrx lrr))) = id (dual (node ls nil lx (node lrs lrl lrx lrr)))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
dsimp only [dual, id]
[GOAL]
case nil.node.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls (node lls lll llx llr) lx nil) = t → Ordnode α)
              (id (node ls (node lls lll llx llr) lx nil))
              (fun h => (_ : nil = id (node ls (node lls lll llx llr) lx nil)) ▸ Ordnode.singleton x)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls (node lls lll llx llr) lx nil)) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 (node ls (node lls lll llx llr) lx nil) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll lx_1 (node (lrs + 1) lr x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id (node ls (node lls lll llx llr) lx nil) = id (node ls (node lls lll llx llr) lx nil)))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t => id (node ls (node lls lll llx llr) lx nil) = t → Ordnode α)
              (id (node ls (node lls lll llx llr) lx nil))
              (fun h => (_ : nil = id (node ls (node lls lll llx llr) lx nil)) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls (node lls lll llx llr) lx nil)) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls_1 + rs + 1) ll lx_1 (node (rs + lrs + 1) lr x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls_1 + rs + 1) (node ls (node lls lll llx llr) lx nil) x nil)
              (_ : id (node ls (node lls lll llx llr) lx nil) = id (node ls (node lls lll llx llr) lx nil)))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls (node lls lll llx llr) lx nil)) = t → Ordnode α)
            (id (dual (node ls (node lls lll llx llr) lx nil)))
            (fun h => (_ : nil = id (dual (node ls (node lls lll llx llr) lx nil))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls (node lls lll llx llr) lx nil))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls (node lls lll llx llr) lx nil)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls (node lls lll llx llr) lx nil)) = id (dual (node ls (node lls lll llx llr) lx nil))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls (node lls lll llx llr) lx nil)) = t → Ordnode α)
            (id (dual (node ls (node lls lll llx llr) lx nil)))
            (fun h => (_ : nil = id (dual (node ls (node lls lll llx llr) lx nil))) ▸ node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls (node lls lll llx llr) lx nil))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else node (ls_1 + rs + 1) (dual nil) x (dual (node ls (node lls lll llx llr) lx nil)))
            (_ : id (dual (node ls (node lls lll llx llr) lx nil)) = id (dual (node ls (node lls lll llx llr) lx nil))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
dsimp only [dual, id]
[GOAL]
case nil.node.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
        (fun h =>
          (_ : nil = id nil) ▸
            Ordnode.casesOn (motive := fun t =>
              id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) = t → Ordnode α)
              (id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))
              (fun h => (_ : nil = id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) ▸ Ordnode.singleton x)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h =>
                            (_ : nil = lr) ▸ node 2 (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll lx_1 (node (lrs + 1) lr x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ :
                id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) =
                  id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))))
        (fun rs l x_1 r h =>
          (_ : node rs l x_1 r = id nil) ▸
            Ordnode.casesOn (motive := fun t =>
              id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) = t → Ordnode α)
              (id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))
              (fun h =>
                (_ : nil = id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) ▸ node (rs + 1) nil x nil)
              (fun ls_1 ll lx_1 lr h =>
                (_ : node ls_1 ll lx_1 lr = id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) ▸
                  if ls_1 > delta * rs then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then node (ls_1 + rs + 1) ll lx_1 (node (rs + lrs + 1) lr x nil)
                                else
                                  node (ls_1 + rs + 1) (node (lls + size lrl + 1) ll lx_1 lrl) lrx
                                    (node (size lrr + rs + 1) lrr x nil))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls_1 + rs + 1) (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil)
              (_ :
                id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) =
                  id (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))))
        (_ : id nil = id nil)) =
    Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
      (fun h =>
        (_ : nil = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t =>
            id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) = t → Ordnode α)
            (id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))))
            (fun h =>
              (_ : nil = id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h =>
                          (_ : nil = rl) ▸
                            node 2 nil x (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ :
              id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) =
                id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual nil)) ▸
          Ordnode.casesOn (motive := fun t =>
            id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) = t → Ordnode α)
            (id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))))
            (fun h =>
              (_ : nil = id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))) ▸
                node (ls_1 + 1) (dual nil) x nil)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))) ▸
                if rs > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr) (fun h => (_ : nil = id rr) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr) ▸
                        Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                          (fun h => (_ : nil = id rl) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs + 1) (node (ls_1 + rls + 1) (dual nil) x rl) rx rr
                              else
                                node (ls_1 + rs + 1) (node (ls_1 + size rll + 1) (dual nil) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx rr))
                          (_ : id rl = id rl))
                    (_ : id rr = id rr)
                else
                  node (ls_1 + rs + 1) (dual nil) x (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))))
            (_ :
              id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr))) =
                id (dual (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)))))
      (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
dsimp only [dual, id]
[GOAL]
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)
[PROOFSTEP]
try rfl
[GOAL]
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)
[PROOFSTEP]
rfl
[GOAL]
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))
[PROOFSTEP]
try rfl
[GOAL]
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))
[PROOFSTEP]
rfl
[GOAL]
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)))
[PROOFSTEP]
try rfl
[GOAL]
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)))
[PROOFSTEP]
rfl
[GOAL]
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)))
[PROOFSTEP]
split_ifs with h
[GOAL]
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))
[PROOFSTEP]
repeat simp [h, add_comm]
[GOAL]
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))
[PROOFSTEP]
simp [h, add_comm]
[GOAL]

[PROOFSTEP]
simp [h, add_comm]
[GOAL]
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)))
[PROOFSTEP]
repeat simp [h, add_comm]
[GOAL]
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)))
[PROOFSTEP]
simp [h, add_comm]
[GOAL]

[PROOFSTEP]
simp [h, add_comm]
[GOAL]
case node
α : Type u_1
l : Ordnode α
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 l x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id l = id l))
        (fun rs_1 l_1 x_1 r h =>
          (_ : node rs_1 l_1 x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id l = t → Ordnode α) (id l)
              (fun h => (_ : nil = id l) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id l) ▸
                  if ls > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then
                                  node (ls + rs_1 + 1) ll lx (node (rs_1 + lrs + 1) lr x (node rs rl rx rr))
                                else
                                  node (ls + rs_1 + 1) (node (lls + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs_1 + 1) l x (node rs rl rx rr))
              (_ : id l = id l))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual l)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual l))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual l) = id (dual l)))
      (fun ls l_1 x_1 r h =>
        (_ : node ls l_1 x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual l) = t → Ordnode α) (id (dual l))
            (fun h => (_ : nil = id (dual l)) ▸ node (ls + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual l)) ▸
                if rs_1 > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls + rs_1 + 1) (node (ls + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1 rr_1
                              else
                                node (ls + rs_1 + 1) (node (ls + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls + rs_1 + 1) (dual (node rs rl rx rr)) x (dual l))
            (_ : id (dual l) = id (dual l)))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
[PROOFSTEP]
cases' l with ls ll lx lr
[GOAL]
case node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ Ordnode.singleton x)
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                    (fun h =>
                      (_ : nil = id ll) ▸
                        Ordnode.casesOn (motive := fun t => lr = t → Ordnode α) lr
                          (fun h => (_ : nil = lr) ▸ node 2 nil x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr) ▸ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x))
                          (_ : lr = lr))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll) ▸
                        Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                          (fun h => (_ : nil = id lr) ▸ node 3 ll lx (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr) ▸
                              if lrs < ratio * lls then node (ls + 1) ll lx (node (lrs + 1) lr x nil)
                              else
                                node (ls + 1) (node (lls + size lrl + 1) ll lx lrl) lrx (node (size lrr + 1) lrr x nil))
                          (_ : id lr = id lr))
                    (_ : id ll = id ll))
              (_ : id nil = id nil))
        (fun rs_1 l x_1 r h =>
          (_ : node rs_1 l x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id nil = t → Ordnode α) (id nil)
              (fun h => (_ : nil = id nil) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls ll lx lr h =>
                (_ : node ls ll lx lr = id nil) ▸
                  if ls > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll = t → Ordnode α) (id ll)
                      (fun h => (_ : nil = id ll) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll) ▸
                          Ordnode.casesOn (motive := fun t => id lr = t → Ordnode α) (id lr)
                            (fun h => (_ : nil = id lr) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr) ▸
                                if lrs < ratio * lls then
                                  node (ls + rs_1 + 1) ll lx (node (rs_1 + lrs + 1) lr x (node rs rl rx rr))
                                else
                                  node (ls + rs_1 + 1) (node (lls + size lrl + 1) ll lx lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr = id lr))
                      (_ : id ll = id ll)
                  else node (ls + rs_1 + 1) nil x (node rs rl rx rr))
              (_ : id nil = id nil))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual nil)) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual nil))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual nil) = id (dual nil)))
      (fun ls l x_1 r h =>
        (_ : node ls l x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual nil) = t → Ordnode α) (id (dual nil))
            (fun h => (_ : nil = id (dual nil)) ▸ node (ls + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual nil)) ▸
                if rs_1 > delta * ls then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls + rs_1 + 1) (node (ls + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1 rr_1
                              else
                                node (ls + rs_1 + 1) (node (ls + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls + rs_1 + 1) (dual (node rs rl rx rr)) x (dual nil))
            (_ : id (dual nil) = id (dual nil)))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
[PROOFSTEP]
rfl
[GOAL]
case node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ dual
      (Ordnode.casesOn (motive := fun t => id (node rs rl rx rr) = t → Ordnode α) (id (node rs rl rx rr))
        (fun h =>
          (_ : nil = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ Ordnode.singleton x)
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                    (fun h =>
                      (_ : nil = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => lr_1 = t → Ordnode α) lr_1
                          (fun h => (_ : nil = lr_1) ▸ node 2 (node ls ll lx lr) x nil)
                          (fun size l lrx r h =>
                            (_ : node size l lrx r = lr_1) ▸ node 3 (Ordnode.singleton lx_1) lrx (Ordnode.singleton x))
                          (_ : lr_1 = lr_1))
                    (fun lls l x_1 r h =>
                      (_ : node lls l x_1 r = id ll_1) ▸
                        Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                          (fun h => (_ : nil = id lr_1) ▸ node 3 ll_1 lx_1 (Ordnode.singleton x))
                          (fun lrs lrl lrx lrr h =>
                            (_ : node lrs lrl lrx lrr = id lr_1) ▸
                              if lrs < ratio * lls then node (ls_1 + 1) ll_1 lx_1 (node (lrs + 1) lr_1 x nil)
                              else
                                node (ls_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                  (node (size lrr + 1) lrr x nil))
                          (_ : id lr_1 = id lr_1))
                    (_ : id ll_1 = id ll_1))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (fun rs_1 l x_1 r h =>
          (_ : node rs_1 l x_1 r = id (node rs rl rx rr)) ▸
            Ordnode.casesOn (motive := fun t => id (node ls ll lx lr) = t → Ordnode α) (id (node ls ll lx lr))
              (fun h => (_ : nil = id (node ls ll lx lr)) ▸ node (rs_1 + 1) nil x (node rs rl rx rr))
              (fun ls_1 ll_1 lx_1 lr_1 h =>
                (_ : node ls_1 ll_1 lx_1 lr_1 = id (node ls ll lx lr)) ▸
                  if ls_1 > delta * rs_1 then
                    Ordnode.casesOn (motive := fun t => id ll_1 = t → Ordnode α) (id ll_1)
                      (fun h => (_ : nil = id ll_1) ▸ nil)
                      (fun lls l x_2 r h =>
                        (_ : node lls l x_2 r = id ll_1) ▸
                          Ordnode.casesOn (motive := fun t => id lr_1 = t → Ordnode α) (id lr_1)
                            (fun h => (_ : nil = id lr_1) ▸ nil)
                            (fun lrs lrl lrx lrr h =>
                              (_ : node lrs lrl lrx lrr = id lr_1) ▸
                                if lrs < ratio * lls then
                                  node (ls_1 + rs_1 + 1) ll_1 lx_1 (node (rs_1 + lrs + 1) lr_1 x (node rs rl rx rr))
                                else
                                  node (ls_1 + rs_1 + 1) (node (lls + size lrl + 1) ll_1 lx_1 lrl) lrx
                                    (node (size lrr + rs_1 + 1) lrr x (node rs rl rx rr)))
                            (_ : id lr_1 = id lr_1))
                      (_ : id ll_1 = id ll_1)
                  else node (ls_1 + rs_1 + 1) (node ls ll lx lr) x (node rs rl rx rr))
              (_ : id (node ls ll lx lr) = id (node ls ll lx lr)))
        (_ : id (node rs rl rx rr) = id (node rs rl rx rr))) =
    Ordnode.casesOn (motive := fun t => id (dual (node rs rl rx rr)) = t → Ordnode α) (id (dual (node rs rl rx rr)))
      (fun h =>
        (_ : nil = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr))) (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ Ordnode.singleton x)
            (fun rs rl rx rr h =>
              (_ : node rs rl rx rr = id (dual (node ls ll lx lr))) ▸
                Ordnode.casesOn (motive := fun t => id rr = t → Ordnode α) (id rr)
                  (fun h =>
                    (_ : nil = id rr) ▸
                      Ordnode.casesOn (motive := fun t => rl = t → Ordnode α) rl
                        (fun h => (_ : nil = rl) ▸ node 2 nil x (dual (node ls ll lx lr)))
                        (fun size l rlx r h =>
                          (_ : node size l rlx r = rl) ▸ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx))
                        (_ : rl = rl))
                  (fun rrs l x_1 r h =>
                    (_ : node rrs l x_1 r = id rr) ▸
                      Ordnode.casesOn (motive := fun t => id rl = t → Ordnode α) (id rl)
                        (fun h => (_ : nil = id rl) ▸ node 3 (Ordnode.singleton x) rx rr)
                        (fun rls rll rlx rlr h =>
                          (_ : node rls rll rlx rlr = id rl) ▸
                            if rls < ratio * rrs then node (rs + 1) (node (rls + 1) nil x rl) rx rr
                            else
                              node (rs + 1) (node (size rll + 1) nil x rll) rlx (node (size rlr + rrs + 1) rlr rx rr))
                        (_ : id rl = id rl))
                  (_ : id rr = id rr))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (fun ls_1 l x_1 r h =>
        (_ : node ls_1 l x_1 r = id (dual (node rs rl rx rr))) ▸
          Ordnode.casesOn (motive := fun t => id (dual (node ls ll lx lr)) = t → Ordnode α)
            (id (dual (node ls ll lx lr)))
            (fun h => (_ : nil = id (dual (node ls ll lx lr))) ▸ node (ls_1 + 1) (dual (node rs rl rx rr)) x nil)
            (fun rs_1 rl_1 rx_1 rr_1 h =>
              (_ : node rs_1 rl_1 rx_1 rr_1 = id (dual (node ls ll lx lr))) ▸
                if rs_1 > delta * ls_1 then
                  Ordnode.casesOn (motive := fun t => id rr_1 = t → Ordnode α) (id rr_1)
                    (fun h => (_ : nil = id rr_1) ▸ nil)
                    (fun rrs l x_2 r h =>
                      (_ : node rrs l x_2 r = id rr_1) ▸
                        Ordnode.casesOn (motive := fun t => id rl_1 = t → Ordnode α) (id rl_1)
                          (fun h => (_ : nil = id rl_1) ▸ nil)
                          (fun rls rll rlx rlr h =>
                            (_ : node rls rll rlx rlr = id rl_1) ▸
                              if rls < ratio * rrs then
                                node (ls_1 + rs_1 + 1) (node (ls_1 + rls + 1) (dual (node rs rl rx rr)) x rl_1) rx_1
                                  rr_1
                              else
                                node (ls_1 + rs_1 + 1) (node (ls_1 + size rll + 1) (dual (node rs rl rx rr)) x rll) rlx
                                  (node (size rlr + rrs + 1) rlr rx_1 rr_1))
                          (_ : id rl_1 = id rl_1))
                    (_ : id rr_1 = id rr_1)
                else node (ls_1 + rs_1 + 1) (dual (node rs rl rx rr)) x (dual (node ls ll lx lr)))
            (_ : id (dual (node ls ll lx lr)) = id (dual (node ls ll lx lr))))
      (_ : id (dual (node rs rl rx rr)) = id (dual (node rs rl rx rr)))
[PROOFSTEP]
dsimp only [dual, id]
[GOAL]
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 = id ll) ▸ nil)
          (fun size l x_1 r l_ih r_ih h =>
            (_ : node size l x_1 r = id ll) ▸
              rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
                (fun size_1 l x_2 r l_ih r_ih h =>
                  (_ : node size_1 l x_2 r = id lr) ▸
                    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 = id (dual ll)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (dual ll)) ▸
            rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (dual lr)) ▸
                  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))
[PROOFSTEP]
split_ifs
[GOAL]
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 = id ll) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id ll) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  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 = id (dual ll)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual ll)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                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))
[PROOFSTEP]
swap
[GOAL]
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))
[PROOFSTEP]
simp [add_comm]
[GOAL]
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 = id ll) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id ll) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  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 = id (dual ll)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual ll)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                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))
[PROOFSTEP]
cases' ll with lls lll llx llr
[GOAL]
case pos.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id nil) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) nil lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              lr (_ : id lr = id lr))
        nil (_ : id nil = id nil)) =
    rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual nil)) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                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 nil)
                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 nil)))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual nil) (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case pos.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
lr : Ordnode α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => lr = t → Ordnode α) (fun h => (_ : nil = id lr) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id lr) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + size_1 + 1) lr x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              lr (_ : id lr = id lr))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual lr = t → Ordnode α) (fun h => (_ : nil = id (dual lr)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual lr)) ▸
                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 (node lls lll llx llr))
                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 (node lls lll llx llr))))
            (dual lr) (_ : id (dual lr) = id (dual lr)))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case pos.nil.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id nil) ▸
            rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id nil) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) nil lx (node (rs + size_1 + 1) nil x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              nil (_ : id nil = id nil))
        nil (_ : id nil = id nil)) =
    rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual nil)) ▸
          rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual nil)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual nil)) lx
                    (dual nil)
                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 nil)))
            (dual nil) (_ : id (dual nil) = id (dual nil)))
      (dual nil) (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
try rfl
[GOAL]
case pos.nil.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
⊢ dual
      (rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id nil) ▸
            rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id nil) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) nil lx (node (rs + size_1 + 1) nil x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              nil (_ : id nil = id nil))
        nil (_ : id nil = id nil)) =
    rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual nil)) ▸
          rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual nil)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual nil)) lx
                    (dual nil)
                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 nil)))
            (dual nil) (_ : id (dual nil) = id (dual nil)))
      (dual nil) (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
rfl
[GOAL]
case pos.nil.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id nil) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) nil lx (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        nil (_ : id nil = id nil)) =
    rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual nil)) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual nil)
                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 nil)))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual nil) (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
try rfl
[GOAL]
case pos.nil.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id nil) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) nil lx (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        nil (_ : id nil = id nil)) =
    rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual nil)) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual nil)
                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 nil)))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual nil) (_ : id (dual nil) = id (dual nil))
[PROOFSTEP]
rfl
[GOAL]
case pos.node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id nil) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + size_1 + 1) nil x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              nil (_ : id nil = id nil))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual nil)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual nil)) lx
                    (dual (node lls lll llx llr))
                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 (node lls lll llx llr))))
            (dual nil) (_ : id (dual nil) = id (dual nil)))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
[PROOFSTEP]
try rfl
[GOAL]
case pos.node.nil
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => nil = t → Ordnode α) (fun h => (_ : nil = id nil) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id nil) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + size_1 + 1) nil x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              nil (_ : id nil = id nil))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual nil = t → Ordnode α) (fun h => (_ : nil = id (dual nil)) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual nil)) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1) (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual nil)) lx
                    (dual (node lls lll llx llr))
                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 (node lls lll llx llr))))
            (dual nil) (_ : id (dual nil) = id (dual nil)))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
[PROOFSTEP]
rfl
[GOAL]
case pos.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                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 (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
[PROOFSTEP]
try rfl
[GOAL]
case pos.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                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 (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
[PROOFSTEP]
rfl
[GOAL]
case pos.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (rec (motive := fun t => node lls lll llx llr = t → Ordnode α)
        (fun h => (_ : nil = id (node lls lll llx llr)) ▸ nil)
        (fun size l x_1 r l_ih r_ih h =>
          (_ : node size l x_1 r = id (node lls lll llx llr)) ▸
            rec (motive := fun t => node lrs lrl lrx lrr = t → Ordnode α)
              (fun h => (_ : nil = id (node lrs lrl lrx lrr)) ▸ nil)
              (fun size_1 l x_2 r l_ih r_ih h =>
                (_ : node size_1 l x_2 r = id (node lrs lrl lrx lrr)) ▸
                  if size_1 < ratio * size then
                    node (ls + rs + 1) (node lls lll llx llr) lx
                      (node (rs + size_1 + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
                  else
                    node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                      (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
              (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
        (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))) =
    rec (motive := fun t => dual (node lls lll llx llr) = t → Ordnode α)
      (fun h => (_ : nil = id (dual (node lls lll llx llr))) ▸ nil)
      (fun size l x_1 r l_ih r_ih h =>
        (_ : node size l x_1 r = id (dual (node lls lll llx llr))) ▸
          rec (motive := fun t => dual (node lrs lrl lrx lrr) = t → Ordnode α)
            (fun h => (_ : nil = id (dual (node lrs lrl lrx lrr))) ▸ nil)
            (fun size_1 l x_2 r l_ih r_ih h =>
              (_ : node size_1 l x_2 r = id (dual (node lrs lrl lrx lrr))) ▸
                if size_1 < ratio * size then
                  node (rs + ls + 1)
                    (node (rs + size_1 + 1) (node rs (dual rr) rx (dual rl)) x (dual (node lrs lrl lrx lrr))) lx
                    (dual (node lls lll llx llr))
                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 (node lls lll llx llr))))
            (dual (node lrs lrl lrx lrr)) (_ : id (dual (node lrs lrl lrx lrr)) = id (dual (node lrs lrl lrx lrr))))
      (dual (node lls lll llx llr)) (_ : id (dual (node lls lll llx llr)) = id (dual (node lls lll llx llr)))
[PROOFSTEP]
dsimp only [dual, id]
[GOAL]
case pos.node.node
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
⊢ dual
      (if lrs < ratio * lls then
        node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + lrs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
      else
        node (ls + rs + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
          (node (size lrr + rs + 1) lrr x (node rs rl rx rr))) =
    if lrs < ratio * lls then
      node (rs + ls + 1) (node (rs + lrs + 1) (node rs (dual rr) rx (dual rl)) x (node lrs (dual lrr) lrx (dual lrl)))
        lx (node lls (dual llr) llx (dual lll))
    else
      node (rs + ls + 1) (node (rs + size (dual lrr) + 1) (node rs (dual rr) rx (dual rl)) x (dual lrr)) lrx
        (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
[PROOFSTEP]
split_ifs with h
[GOAL]
case pos
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
h : lrs < ratio * lls
⊢ dual
      (node (ls + rs + 1) (node lls lll llx llr) lx (node (rs + lrs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))) =
    node (rs + ls + 1) (node (rs + lrs + 1) (node rs (dual rr) rx (dual rl)) x (node lrs (dual lrr) lrx (dual lrl))) lx
      (node lls (dual llr) llx (dual lll))
[PROOFSTEP]
simp [h, add_comm]
[GOAL]
case neg
α : Type u_1
x : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
ls : ℕ
lx : α
h✝ : ls > delta * rs
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
h : ¬lrs < ratio * lls
⊢ dual
      (node (ls + rs + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
        (node (size lrr + rs + 1) lrr x (node rs rl rx rr))) =
    node (rs + ls + 1) (node (rs + size (dual lrr) + 1) (node rs (dual rr) rx (dual rl)) x (dual lrr)) lrx
      (node (size (dual lrl) + lls + 1) (dual lrl) lx (node lls (dual llr) llx (dual lll)))
[PROOFSTEP]
simp [h, add_comm]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
⊢ dual (balanceR l x r) = balanceL (dual r) x (dual l)
[PROOFSTEP]
rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
hl : Sized l
hm : Sized m
hr : Sized r
⊢ Sized (Ordnode.node4L l x m y r)
[PROOFSTEP]
cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
hl : Sized l
hm : Sized m
hr : Sized r
⊢ Sized (Ordnode.node4L l x m y r)
[PROOFSTEP]
cases m
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
hl : Sized l
hr : Sized r
hm : Sized nil
⊢ Sized (Ordnode.node4L l x nil y r)
[PROOFSTEP]
exact (hl.node' hm).node' hr
[GOAL]
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
hl : Sized l
hr : Sized r
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ Sized (Ordnode.node4L l x (node size✝ l✝ x✝ r✝) y r)
[PROOFSTEP]
exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ size (node3L l x m y r) = size l + size m + size r + 2
[PROOFSTEP]
dsimp [node3L, node', size]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ (((match l with
            | nil => 0
            | node sz l x r => sz) +
            match m with
            | nil => 0
            | node sz l x r => sz) +
          1 +
        match r with
        | nil => 0
        | node sz l x r => sz) +
      1 =
    (((match l with
          | nil => 0
          | node sz l x r => sz) +
          match m with
          | nil => 0
          | node sz l x r => sz) +
        match r with
        | nil => 0
        | node sz l x r => sz) +
      2
[PROOFSTEP]
rw [add_right_comm _ 1]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ size (node3R l x m y r) = size l + size m + size r + 2
[PROOFSTEP]
dsimp [node3R, node', size]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ (match l with
        | nil => 0
        | node sz l x r => sz) +
        (((match m with
            | nil => 0
            | node sz l x r => sz) +
            match r with
            | nil => 0
            | node sz l x r => sz) +
          1) +
      1 =
    (((match l with
          | nil => 0
          | node sz l x r => sz) +
          match m with
          | nil => 0
          | node sz l x r => sz) +
        match r with
        | nil => 0
        | node sz l x r => sz) +
      2
[PROOFSTEP]
rw [← add_assoc, ← add_assoc]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
hm : Sized m
⊢ size (node4L l x m y r) = size l + size m + size r + 2
[PROOFSTEP]
cases m <;> simp [node4L, node3L, node'] <;> [skip; simp [size, hm.1]]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
hm : Sized m
⊢ size (node4L l x m y r) = size l + size m + size r + 2
[PROOFSTEP]
cases m
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
hm : Sized nil
⊢ size (node4L l x nil y r) = size l + size nil + size r + 2
[PROOFSTEP]
simp [node4L, node3L, node']
[GOAL]
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size (node4L l x (node size✝ l✝ x✝ r✝) y r) = size l + size (node size✝ l✝ x✝ r✝) + size r + 2
[PROOFSTEP]
simp [node4L, node3L, node']
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
hm : Sized nil
⊢ size l + 1 + size r = size l + size r + 1
[PROOFSTEP]
skip
[GOAL]
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size l + size l✝ + 1 + (size r✝ + size r + 1) = size l + size✝ + size r + 1
[PROOFSTEP]
simp [size, hm.1]
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
hm : Sized nil
⊢ size l + 1 + size r = size l + size r + 1
[PROOFSTEP]
abel
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
hm : Sized nil
⊢ size l + 1 + size r = size l + size r + 1
[PROOFSTEP]
abel
[GOAL]
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size l + size l✝ + 1 + (size r✝ + size r + 1) = size l + (size l✝ + size r✝ + 1) + size r + 1
[PROOFSTEP]
abel
[GOAL]
case node
α : Type u_1
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size l + size l✝ + 1 + (size r✝ + size r + 1) = size l + (size l✝ + size r✝ + 1) + size r + 1
[PROOFSTEP]
abel
[GOAL]
α : Type u_1
l : Ordnode α
x✝ : α
r : Ordnode α
sl : Sized l
sr : Sized r
⊢ size l + size r + 1 = size (Ordnode.dual r) + size (Ordnode.dual l) + 1
[PROOFSTEP]
simp [size_dual, add_comm]
[GOAL]
α : Type u_1
t : Ordnode α
h : Sized (Ordnode.dual t)
⊢ Sized t
[PROOFSTEP]
rw [← dual_dual t]
[GOAL]
α : Type u_1
t : Ordnode α
h : Sized (Ordnode.dual t)
⊢ Sized (Ordnode.dual (Ordnode.dual t))
[PROOFSTEP]
exact h.dual
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ Sized (Ordnode.rotateL l x r)
[PROOFSTEP]
cases r
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x : α
hl : Sized l
hr : Sized nil
⊢ Sized (Ordnode.rotateL l x nil)
[PROOFSTEP]
exact hl.node' hr
[GOAL]
case node
α : Type u_1
l : Ordnode α
x : α
hl : Sized l
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hr : Sized (node size✝ l✝ x✝ r✝)
⊢ Sized (Ordnode.rotateL l x (node size✝ l✝ x✝ r✝))
[PROOFSTEP]
rw [rotateL]
[GOAL]
case node
α : Type u_1
l : Ordnode α
x : α
hl : Sized l
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hr : Sized (node size✝ l✝ x✝ r✝)
⊢ Sized (if size l✝ < ratio * size r✝ then Ordnode.node3L l x l✝ x✝ r✝ else Ordnode.node4L l x l✝ x✝ r✝)
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
hl : Sized l
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hr : Sized (node size✝ l✝ x✝ r✝)
h✝ : size l✝ < ratio * size r✝
⊢ Sized (Ordnode.node3L l x l✝ x✝ r✝)
[PROOFSTEP]
exact hl.node3L hr.2.1 hr.2.2
[GOAL]
case neg
α : Type u_1
l : Ordnode α
x : α
hl : Sized l
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hr : Sized (node size✝ l✝ x✝ r✝)
h✝ : ¬size l✝ < ratio * size r✝
⊢ Sized (Ordnode.node4L l x l✝ x✝ r✝)
[PROOFSTEP]
exact hl.node4L hr.2.1 hr.2.2
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ Sized (Ordnode.dual (Ordnode.rotateR l x r))
[PROOFSTEP]
rw [dual_rotateR]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ Sized (Ordnode.rotateL (Ordnode.dual r) x (Ordnode.dual l))
[PROOFSTEP]
exact hr.dual.rotateL hl.dual
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hm : Sized r
⊢ size (Ordnode.rotateL l x r) = size l + size r + 1
[PROOFSTEP]
cases r
[GOAL]
case nil
α : Type u_1
l : Ordnode α
x : α
hm : Sized nil
⊢ size (Ordnode.rotateL l x nil) = size l + size nil + 1
[PROOFSTEP]
simp [Ordnode.rotateL]
[GOAL]
case node
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size (Ordnode.rotateL l x (node size✝ l✝ x✝ r✝)) = size l + size (node size✝ l✝ x✝ r✝) + 1
[PROOFSTEP]
simp [Ordnode.rotateL]
[GOAL]
case node
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size (if size l✝ < ratio * size r✝ then Ordnode.node3L l x l✝ x✝ r✝ else Ordnode.node4L l x l✝ x✝ r✝) =
    size l + size✝ + 1
[PROOFSTEP]
simp [size, hm.1]
[GOAL]
case node
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
⊢ size (if size l✝ < ratio * size r✝ then Ordnode.node3L l x l✝ x✝ r✝ else Ordnode.node4L l x l✝ x✝ r✝) =
    size l + (size l✝ + size r✝ + 1) + 1
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
h✝ : size l✝ < ratio * size r✝
⊢ size (Ordnode.node3L l x l✝ x✝ r✝) = size l + (size l✝ + size r✝ + 1) + 1
[PROOFSTEP]
simp [node3L_size, node4L_size hm.2.1]
[GOAL]
case neg
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
h✝ : ¬size l✝ < ratio * size r✝
⊢ size (Ordnode.node4L l x l✝ x✝ r✝) = size l + (size l✝ + size r✝ + 1) + 1
[PROOFSTEP]
simp [node3L_size, node4L_size hm.2.1]
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
h✝ : size l✝ < ratio * size r✝
⊢ size l + size l✝ + size r✝ + 1 = size l + (size l✝ + size r✝ + 1)
[PROOFSTEP]
abel
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
h✝ : size l✝ < ratio * size r✝
⊢ size l + size l✝ + size r✝ + 1 = size l + (size l✝ + size r✝ + 1)
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
h✝ : ¬size l✝ < ratio * size r✝
⊢ size l + size l✝ + size r✝ + 1 = size l + (size l✝ + size r✝ + 1)
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
hm : Sized (node size✝ l✝ x✝ r✝)
h✝ : ¬size l✝ < ratio * size r✝
⊢ size l + size l✝ + size r✝ + 1 = size l + (size l✝ + size r✝ + 1)
[PROOFSTEP]
abel
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
⊢ size (Ordnode.rotateR l x r) = size l + size r + 1
[PROOFSTEP]
rw [← size_dual, dual_rotateR, hl.dual.rotateL_size, size_dual, size_dual, add_comm (size l)]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ Sized (Ordnode.balance' l x r)
[PROOFSTEP]
unfold balance'
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ Sized
    (if size l + size r ≤ 1 then Ordnode.node' l x r
    else
      if size r > delta * size l then Ordnode.rotateL l x r
      else if size l > delta * size r then Ordnode.rotateR l x r else Ordnode.node' l x r)
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝ : size l + size r ≤ 1
⊢ Sized (Ordnode.node' l x r)
[PROOFSTEP]
exact hl.node' hr
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝¹ : ¬size l + size r ≤ 1
h✝ : size r > delta * size l
⊢ Sized (Ordnode.rotateL l x r)
[PROOFSTEP]
exact hl.rotateL hr
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝² : ¬size l + size r ≤ 1
h✝¹ : ¬size r > delta * size l
h✝ : size l > delta * size r
⊢ Sized (Ordnode.rotateR l x r)
[PROOFSTEP]
exact hl.rotateR hr
[GOAL]
case neg
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝² : ¬size l + size r ≤ 1
h✝¹ : ¬size r > delta * size l
h✝ : ¬size l > delta * size r
⊢ Sized (Ordnode.node' l x r)
[PROOFSTEP]
exact hl.node' hr
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ size (balance' l x r) = size l + size r + 1
[PROOFSTEP]
unfold balance'
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
⊢ size
      (if size l + size r ≤ 1 then node' l x r
      else
        if size r > delta * size l then rotateL l x r
        else if size l > delta * size r then rotateR l x r else node' l x r) =
    size l + size r + 1
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝ : size l + size r ≤ 1
⊢ size (node' l x r) = size l + size r + 1
[PROOFSTEP]
rfl
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝¹ : ¬size l + size r ≤ 1
h✝ : size r > delta * size l
⊢ size (rotateL l x r) = size l + size r + 1
[PROOFSTEP]
exact hr.rotateL_size
[GOAL]
case pos
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝² : ¬size l + size r ≤ 1
h✝¹ : ¬size r > delta * size l
h✝ : size l > delta * size r
⊢ size (rotateR l x r) = size l + size r + 1
[PROOFSTEP]
exact hl.rotateR_size
[GOAL]
case neg
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Sized l
hr : Sized r
h✝² : ¬size l + size r ≤ 1
h✝¹ : ¬size r > delta * size l
h✝ : ¬size l > delta * size r
⊢ size (node' l x r) = size l + size r + 1
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
P : α → Prop
x : α
⊢ Any P {x} → P x
[PROOFSTEP]
rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩)
[GOAL]
case inr.inl
α : Type u_1
P : α → Prop
x : α
h : P x
⊢ P x
[PROOFSTEP]
exact h
[GOAL]
α : Type u_1
P : α → Prop
⊢ ∀ (x : α), Emem x nil → P x
[PROOFSTEP]
rintro _ ⟨⟩
[GOAL]
α : Type u_1
P : α → Prop
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
⊢ All P (node size✝ l x r) ↔ ∀ (x_1 : α), Emem x_1 (node size✝ l x r) → P x_1
[PROOFSTEP]
simp [All, Emem, all_iff_forall, Any, or_imp, forall_and]
[GOAL]
α : Type u_1
P : α → Prop
⊢ Any P nil → ∃ x, Emem x nil ∧ P x
[PROOFSTEP]
rintro ⟨⟩
[GOAL]
α : Type u_1
P : α → Prop
⊢ (∃ x, Emem x nil ∧ P x) → Any P nil
[PROOFSTEP]
rintro ⟨_, ⟨⟩, _⟩
[GOAL]
α : Type u_1
P : α → Prop
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
⊢ Any P (node size✝ l x r) ↔ ∃ x_1, Emem x_1 (node size✝ l x r) ∧ P x_1
[PROOFSTEP]
simp only [Emem]
[GOAL]
α : Type u_1
P : α → Prop
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
⊢ Any P (node size✝ l x r) ↔ ∃ x_1, Any (Eq x_1) (node size✝ l x r) ∧ P x_1
[PROOFSTEP]
simp [Any, any_iff_exists, or_and_right, exists_or]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ All P (node3L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r
[PROOFSTEP]
simp [node3L, all_node', and_assoc]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ All P (node4L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r
[PROOFSTEP]
cases m
[GOAL]
case nil
α : Type u_1
P : α → Prop
l : Ordnode α
x y : α
r : Ordnode α
⊢ All P (node4L l x nil y r) ↔ All P l ∧ P x ∧ All P nil ∧ P y ∧ All P r
[PROOFSTEP]
simp [node4L, all_node', All, all_node3L, and_assoc]
[GOAL]
case node
α : Type u_1
P : α → Prop
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ All P (node4L l x (node size✝ l✝ x✝ r✝) y r) ↔ All P l ∧ P x ∧ All P (node size✝ l✝ x✝ r✝) ∧ P y ∧ All P r
[PROOFSTEP]
simp [node4L, all_node', All, all_node3L, and_assoc]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
⊢ All P (node4R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r
[PROOFSTEP]
cases m
[GOAL]
case nil
α : Type u_1
P : α → Prop
l : Ordnode α
x y : α
r : Ordnode α
⊢ All P (node4R l x nil y r) ↔ All P l ∧ P x ∧ All P nil ∧ P y ∧ All P r
[PROOFSTEP]
simp [node4R, all_node', All, all_node3R, and_assoc]
[GOAL]
case node
α : Type u_1
P : α → Prop
l : Ordnode α
x y : α
r : Ordnode α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ All P (node4R l x (node size✝ l✝ x✝ r✝) y r) ↔ All P l ∧ P x ∧ All P (node size✝ l✝ x✝ r✝) ∧ P y ∧ All P r
[PROOFSTEP]
simp [node4R, all_node', All, all_node3R, and_assoc]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
⊢ All P (rotateL l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
cases r
[GOAL]
case nil
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
⊢ All P (rotateL l x nil) ↔ All P l ∧ P x ∧ All P nil
[PROOFSTEP]
simp [rotateL, all_node']
[GOAL]
case node
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ All P (rotateL l x (node size✝ l✝ x✝ r✝)) ↔ All P l ∧ P x ∧ All P (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
simp [rotateL, all_node']
[GOAL]
case node
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ All P (if size l✝ < ratio * size r✝ then node3L l x l✝ x✝ r✝ else node4L l x l✝ x✝ r✝) ↔
    All P l ∧ P x ∧ All P (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
h✝ : size l✝ < ratio * size r✝
⊢ All P (node3L l x l✝ x✝ r✝) ↔ All P l ∧ P x ∧ All P (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
simp [all_node3L, all_node4L, All, and_assoc]
[GOAL]
case neg
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
h✝ : ¬size l✝ < ratio * size r✝
⊢ All P (node4L l x l✝ x✝ r✝) ↔ All P l ∧ P x ∧ All P (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
simp [all_node3L, all_node4L, All, and_assoc]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
⊢ All P (rotateR l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
rw [← all_dual, dual_rotateR, all_rotateL]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
⊢ All P (dual r) ∧ P x ∧ All P (dual l) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
simp [all_dual, and_comm, and_left_comm, and_assoc]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
⊢ All P (balance' l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
rw [balance']
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
⊢ All P
      (if size l + size r ≤ 1 then node' l x r
      else
        if size r > delta * size l then rotateL l x r
        else if size l > delta * size r then rotateR l x r else node' l x r) ↔
    All P l ∧ P x ∧ All P r
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
h✝ : size l + size r ≤ 1
⊢ All P (node' l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
simp [all_node', all_rotateL, all_rotateR]
[GOAL]
case pos
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
h✝¹ : ¬size l + size r ≤ 1
h✝ : size r > delta * size l
⊢ All P (rotateL l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
simp [all_node', all_rotateL, all_rotateR]
[GOAL]
case pos
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
h✝² : ¬size l + size r ≤ 1
h✝¹ : ¬size r > delta * size l
h✝ : size l > delta * size r
⊢ All P (rotateR l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
simp [all_node', all_rotateL, all_rotateR]
[GOAL]
case neg
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
h✝² : ¬size l + size r ≤ 1
h✝¹ : ¬size r > delta * size l
h✝ : ¬size l > delta * size r
⊢ All P (node' l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
simp [all_node', all_rotateL, all_rotateR]
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
r' : List α
⊢ foldr List.cons (node size✝ l x r) r' = toList (node size✝ l x r) ++ r'
[PROOFSTEP]
rw [foldr, foldr_cons_eq_toList l, foldr_cons_eq_toList r, ← List.cons_append, ← List.append_assoc, ←
  foldr_cons_eq_toList l]
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
r' : List α
⊢ foldr List.cons l (x :: toList r) ++ r' = toList (node size✝ l x r) ++ r'
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
⊢ toList (node s l x r) = toList l ++ x :: toList r
[PROOFSTEP]
rw [toList, foldr, foldr_cons_eq_toList]
[GOAL]
α : Type u_1
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
⊢ toList l ++ x :: foldr List.cons r [] = toList l ++ x :: toList r
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
x : α
t : Ordnode α
⊢ Emem x t ↔ x ∈ toList t
[PROOFSTEP]
unfold Emem
[GOAL]
α : Type u_1
x : α
t : Ordnode α
⊢ Any (Eq x) t ↔ x ∈ toList t
[PROOFSTEP]
induction t
[GOAL]
case nil
α : Type u_1
x : α
⊢ Any (Eq x) nil ↔ x ∈ toList nil
[PROOFSTEP]
simp [Any, *, or_assoc]
[GOAL]
case node
α : Type u_1
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
l_ih✝ : Any (Eq x) l✝ ↔ x ∈ toList l✝
r_ih✝ : Any (Eq x) r✝ ↔ x ∈ toList r✝
⊢ Any (Eq x) (node size✝ l✝ x✝ r✝) ↔ x ∈ toList (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
simp [Any, *, or_assoc]
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
⊢ List.length (toList (node size✝ l x✝ r)) = realSize (node size✝ l x✝ r)
[PROOFSTEP]
rw [toList_node, List.length_append, List.length_cons, length_toList' l, length_toList' r]
[GOAL]
α : Type u_1
size✝ : ℕ
l : Ordnode α
x✝ : α
r : Ordnode α
⊢ realSize l + Nat.succ (realSize r) = realSize (node size✝ l x✝ r)
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
t : Ordnode α
h : Sized t
⊢ List.length (toList t) = size t
[PROOFSTEP]
rw [length_toList', size_eq_realSize h]
[GOAL]
α : Type u_1
t₁ t₂ : Ordnode α
h₁ : Sized t₁
h₂ : Sized t₂
h : toList t₁ = toList t₂
⊢ size t₁ = size t₂
[PROOFSTEP]
rw [← length_toList h₁, h, length_toList h₂]
[GOAL]
α : Type u_1
inst✝¹ : LE α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
h : Sized t
h_mem : x ∈ t
⊢ 0 < size t
[PROOFSTEP]
cases t
[GOAL]
case nil
α : Type u_1
inst✝¹ : LE α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
h : Sized nil
h_mem : x ∈ nil
⊢ 0 < size nil
[PROOFSTEP]
{contradiction
}
[GOAL]
case nil
α : Type u_1
inst✝¹ : LE α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
h : Sized nil
h_mem : x ∈ nil
⊢ 0 < size nil
[PROOFSTEP]
contradiction
[GOAL]
case node
α : Type u_1
inst✝¹ : LE α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
h : Sized (node size✝ l✝ x✝ r✝)
h_mem : x ∈ node size✝ l✝ x✝ r✝
⊢ 0 < size (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
{simp [h.1]
}
[GOAL]
case node
α : Type u_1
inst✝¹ : LE α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
h : Sized (node size✝ l✝ x✝ r✝)
h_mem : x ∈ node size✝ l✝ x✝ r✝
⊢ 0 < size (node size✝ l✝ x✝ r✝)
[PROOFSTEP]
simp [h.1]
[GOAL]
α : Type u_1
t : Ordnode α
x : α
⊢ findMax' x (dual t) = findMin' t x
[PROOFSTEP]
rw [← findMin'_dual, dual_dual]
[GOAL]
α : Type u_1
t : Ordnode α
⊢ findMax (dual t) = findMin t
[PROOFSTEP]
rw [← findMin_dual, dual_dual]
[GOAL]
α : Type u_1
size✝ sz : ℕ
l' : Ordnode α
y : α
r' : Ordnode α
x : α
r : Ordnode α
⊢ dual (eraseMin (node size✝ (node sz l' y r') x r)) = eraseMax (dual (node size✝ (node sz l' y r') x r))
[PROOFSTEP]
rw [eraseMin, dual_balanceR, dual_eraseMin (node sz l' y r'), dual, dual, dual, eraseMax]
[GOAL]
α : Type u_1
t : Ordnode α
⊢ dual (eraseMax t) = eraseMin (dual t)
[PROOFSTEP]
rw [← dual_dual (eraseMin _), dual_eraseMin, dual_dual]
[GOAL]
α : Type u_1
x✝ ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
x : α
r : Ordnode α
⊢ splitMin' (node ls ll lx lr) x r = (findMin' (node ls ll lx lr) x, eraseMin (node x✝ (node ls ll lx lr) x r))
[PROOFSTEP]
rw [splitMin', splitMin_eq ls ll lx lr, findMin', eraseMin]
[GOAL]
α : Type u_1
x✝ : ℕ
l : Ordnode α
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
⊢ splitMax' l x (node ls ll lx lr) = (eraseMax (node x✝ l x (node ls ll lx lr)), findMax' x (node ls ll lx lr))
[PROOFSTEP]
rw [splitMax', splitMax_eq ls ll lx lr, findMax', eraseMax]
[GOAL]
α : Type u_1
t : Ordnode α
⊢ merge t nil = t
[PROOFSTEP]
cases t
[GOAL]
case nil
α : Type u_1
⊢ merge nil nil = nil
[PROOFSTEP]
rfl
[GOAL]
case node
α : Type u_1
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
⊢ merge (node size✝ l✝ x✝ r✝) nil = node size✝ l✝ x✝ r✝
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ dual (Ordnode.insert x (node size✝ l y r)) = Ordnode.insert x (dual (node size✝ l y r))
[PROOFSTEP]
have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual (Ordnode.insert x (node size✝ l y r)) = Ordnode.insert x (dual (node size✝ l y r))
[PROOFSTEP]
rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y]
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match cmpLE x y with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap (cmpLE x y) with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))
[PROOFSTEP]
cases cmpLE x y
[GOAL]
case lt
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match Ordering.lt with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap Ordering.lt with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))
[PROOFSTEP]
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
[GOAL]
case eq
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match Ordering.eq with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap Ordering.eq with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))
[PROOFSTEP]
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
[GOAL]
case gt
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
this : cmpLE x y = cmpLE y x
⊢ dual
      (match Ordering.gt with
      | Ordering.lt => balanceL (Ordnode.insert x l) y r
      | Ordering.eq => node size✝ l x r
      | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.swap Ordering.gt with
    | Ordering.lt => balanceL (Ordnode.insert x (dual r)) y (dual l)
    | Ordering.eq => node size✝ (dual r) x (dual l)
    | Ordering.gt => balanceR (dual r) y (Ordnode.insert x (dual l))
[PROOFSTEP]
simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
⊢ balance l x r = balance' l x r
[PROOFSTEP]
cases' l with ls ll lx lr
[GOAL]
case nil
α : Type u_1
x : α
r : Ordnode α
hr : Balanced r
sr : Sized r
hl : Balanced nil
sl : Sized nil
⊢ balance nil x r = balance' nil x r
[PROOFSTEP]
cases' r with rs rl rx rr
[GOAL]
case nil.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
hr : Balanced nil
sr : Sized nil
⊢ balance nil x nil = balance' nil x nil
[PROOFSTEP]
rfl
[GOAL]
case nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ balance nil x (node rs rl rx rr) = balance' nil x (node rs rl rx rr)
[PROOFSTEP]
rw [sr.eq_node'] at hr ⊢
[GOAL]
case nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node' rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ balance nil x (node' rl rx rr) = balance' nil x (node' rl rx rr)
[PROOFSTEP]
cases' rl with rls rll rlx rlr
[GOAL]
case nil.node.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rr : Ordnode α
hr : Balanced (node' nil rx rr)
sr : Sized (node rs nil rx rr)
⊢ balance nil x (node' nil rx rr) = balance' nil x (node' nil rx rr)
[PROOFSTEP]
cases' rr with rrs rrl rrx rrr
[GOAL]
case nil.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rr : Ordnode α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx rr)
sr : Sized (node rs (node rls rll rlx rlr) rx rr)
⊢ balance nil x (node' (node rls rll rlx rlr) rx rr) = balance' nil x (node' (node rls rll rlx rlr) rx rr)
[PROOFSTEP]
cases' rr with rrs rrl rrx rrr
[GOAL]
case nil.node.nil.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
hr : Balanced (node' nil rx nil)
sr : Sized (node rs nil rx nil)
⊢ balance nil x (node' nil rx nil) = balance' nil x (node' nil rx nil)
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case nil.node.nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
⊢ balance nil x (node' nil rx (node rrs rrl rrx rrr)) = balance' nil x (node' nil rx (node rrs rrl rrx rrr))
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case nil.node.node.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
⊢ balance nil x (node' (node rls rll rlx rlr) rx nil) = balance' nil x (node' (node rls rll rlx rlr) rx nil)
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case nil.node.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ balance nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)) =
    balance' nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case nil.node.nil.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
hr : Balanced (node' nil rx nil)
sr : Sized (node rs nil rx nil)
⊢ node 2 nil x (node' nil rx nil) =
    if 0 + (0 + 1) ≤ 1 then node' nil x (node' nil rx nil)
    else
      if 0 + 1 > 0 then rotateL nil x (node' nil rx nil)
      else if 0 > delta * (0 + 1) then rotateR nil x (node' nil rx nil) else node' nil x (node' nil rx nil)
[PROOFSTEP]
rfl
[GOAL]
case nil.node.nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
⊢ node 3 (Ordnode.singleton x) rx (node rrs rrl rrx rrr) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs rrl rrx rrr))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs rrl rrx rrr))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs rrl rrx rrr))
        else node' nil x (node' nil rx (node rrs rrl rrx rrr))
[PROOFSTEP]
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
[GOAL]
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
⊢ size rrl = 0 ∧ size rrr = 0
[PROOFSTEP]
have := balancedSz_zero.1 hr.1.symm
[GOAL]
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
this : size (node rrs rrl rrx rrr) ≤ 1
⊢ size rrl = 0 ∧ size rrr = 0
[PROOFSTEP]
rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
[GOAL]
case nil.node.nil.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs rrl rrx rrr))
sr : Sized (node rs nil rx (node rrs rrl rrx rrr))
this : size rrl = 0 ∧ size rrr = 0
⊢ node 3 (Ordnode.singleton x) rx (node rrs rrl rrx rrr) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs rrl rrx rrr))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs rrl rrx rrr))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs rrl rrx rrr))
        else node' nil x (node' nil rx (node rrs rrl rrx rrr))
[PROOFSTEP]
cases sr.2.2.2.1.size_eq_zero.1 this.1
[GOAL]
case nil.node.nil.node.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrx : α
rrr : Ordnode α
hr : Balanced (node' nil rx (node rrs nil rrx rrr))
sr : Sized (node rs nil rx (node rrs nil rrx rrr))
this : size nil = 0 ∧ size rrr = 0
⊢ node 3 (Ordnode.singleton x) rx (node rrs nil rrx rrr) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs nil rrx rrr))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs nil rrx rrr))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs nil rrx rrr))
        else node' nil x (node' nil rx (node rrs nil rrx rrr))
[PROOFSTEP]
cases sr.2.2.2.2.size_eq_zero.1 this.2
[GOAL]
case nil.node.nil.node.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rrs : ℕ
rrx : α
hr : Balanced (node' nil rx (node rrs nil rrx nil))
sr : Sized (node rs nil rx (node rrs nil rrx nil))
this : size nil = 0 ∧ size nil = 0
⊢ node 3 (Ordnode.singleton x) rx (node rrs nil rrx nil) =
    if 0 + (0 + rrs + 1) ≤ 1 then node' nil x (node' nil rx (node rrs nil rrx nil))
    else
      if 0 + rrs + 1 > 0 then rotateL nil x (node' nil rx (node rrs nil rrx nil))
      else
        if 0 > delta * (0 + rrs + 1) then rotateR nil x (node' nil rx (node rrs nil rrx nil))
        else node' nil x (node' nil rx (node rrs nil rrx nil))
[PROOFSTEP]
obtain rfl : rrs = 1 := sr.2.2.1
[GOAL]
case nil.node.nil.node.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ node 3 (Ordnode.singleton x) rx (node 1 nil rrx nil) =
    if 0 + (0 + 1 + 1) ≤ 1 then node' nil x (node' nil rx (node 1 nil rrx nil))
    else
      if 0 + 1 + 1 > 0 then rotateL nil x (node' nil rx (node 1 nil rrx nil))
      else
        if 0 > delta * (0 + 1 + 1) then rotateR nil x (node' nil rx (node 1 nil rrx nil))
        else node' nil x (node' nil rx (node 1 nil rrx nil))
[PROOFSTEP]
rw [if_neg, if_pos, rotateL, if_pos]
[GOAL]
case nil.node.nil.node.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ node 3 (Ordnode.singleton x) rx (node 1 nil rrx nil) = node3L nil x nil rx (node 1 nil rrx nil)
[PROOFSTEP]
rfl
[GOAL]
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ size nil < ratio * size (node 1 nil rrx nil)
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ 0 + 1 + 1 > 0
case nil.node.nil.node.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ ¬0 + (0 + 1 + 1) ≤ 1
[PROOFSTEP]
all_goals dsimp only [size]; decide
[GOAL]
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ size nil < ratio * size (node 1 nil rrx nil)
[PROOFSTEP]
dsimp only [size]
[GOAL]
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ 0 < ratio * 1
[PROOFSTEP]
decide
[GOAL]
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ 0 + 1 + 1 > 0
[PROOFSTEP]
dsimp only [size]
[GOAL]
case nil.node.nil.node.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ 0 + 1 + 1 > 0
[PROOFSTEP]
decide
[GOAL]
case nil.node.nil.node.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ ¬0 + (0 + 1 + 1) ≤ 1
[PROOFSTEP]
dsimp only [size]
[GOAL]
case nil.node.nil.node.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rrx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' nil rx (node 1 nil rrx nil))
sr : Sized (node rs nil rx (node 1 nil rrx nil))
⊢ ¬0 + (0 + 1 + 1) ≤ 1
[PROOFSTEP]
decide
[GOAL]
case nil.node.node.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
⊢ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx) =
    if 0 + (rls + 1) ≤ 1 then node' nil x (node' (node rls rll rlx rlr) rx nil)
    else
      if rls + 1 > 0 then rotateL nil x (node' (node rls rll rlx rlr) rx nil)
      else
        if 0 > delta * (rls + 1) then rotateR nil x (node' (node rls rll rlx rlr) rx nil)
        else node' nil x (node' (node rls rll rlx rlr) rx nil)
[PROOFSTEP]
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
[GOAL]
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
⊢ size rll = 0 ∧ size rlr = 0
[PROOFSTEP]
have := balancedSz_zero.1 hr.1
[GOAL]
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
this : size (node rls rll rlx rlr) ≤ 1
⊢ size rll = 0 ∧ size rlr = 0
[PROOFSTEP]
rwa [size, sr.2.1.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
[GOAL]
case nil.node.node.nil
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
this : size rll = 0 ∧ size rlr = 0
⊢ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx) =
    if 0 + (rls + 1) ≤ 1 then node' nil x (node' (node rls rll rlx rlr) rx nil)
    else
      if rls + 1 > 0 then rotateL nil x (node' (node rls rll rlx rlr) rx nil)
      else
        if 0 > delta * (rls + 1) then rotateR nil x (node' (node rls rll rlx rlr) rx nil)
        else node' nil x (node' (node rls rll rlx rlr) rx nil)
[PROOFSTEP]
cases sr.2.1.2.1.size_eq_zero.1 this.1
[GOAL]
case nil.node.node.nil.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rlx : α
rlr : Ordnode α
hr : Balanced (node' (node rls nil rlx rlr) rx nil)
sr : Sized (node rs (node rls nil rlx rlr) rx nil)
this : size nil = 0 ∧ size rlr = 0
⊢ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx) =
    if 0 + (rls + 1) ≤ 1 then node' nil x (node' (node rls nil rlx rlr) rx nil)
    else
      if rls + 1 > 0 then rotateL nil x (node' (node rls nil rlx rlr) rx nil)
      else
        if 0 > delta * (rls + 1) then rotateR nil x (node' (node rls nil rlx rlr) rx nil)
        else node' nil x (node' (node rls nil rlx rlr) rx nil)
[PROOFSTEP]
cases sr.2.1.2.2.size_eq_zero.1 this.2
[GOAL]
case nil.node.node.nil.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rlx : α
hr : Balanced (node' (node rls nil rlx nil) rx nil)
sr : Sized (node rs (node rls nil rlx nil) rx nil)
this : size nil = 0 ∧ size nil = 0
⊢ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx) =
    if 0 + (rls + 1) ≤ 1 then node' nil x (node' (node rls nil rlx nil) rx nil)
    else
      if rls + 1 > 0 then rotateL nil x (node' (node rls nil rlx nil) rx nil)
      else
        if 0 > delta * (rls + 1) then rotateR nil x (node' (node rls nil rlx nil) rx nil)
        else node' nil x (node' (node rls nil rlx nil) rx nil)
[PROOFSTEP]
obtain rfl : rls = 1 := sr.2.1.1
[GOAL]
case nil.node.node.nil.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx) =
    if 0 + (1 + 1) ≤ 1 then node' nil x (node' (node 1 nil rlx nil) rx nil)
    else
      if 1 + 1 > 0 then rotateL nil x (node' (node 1 nil rlx nil) rx nil)
      else
        if 0 > delta * (1 + 1) then rotateR nil x (node' (node 1 nil rlx nil) rx nil)
        else node' nil x (node' (node 1 nil rlx nil) rx nil)
[PROOFSTEP]
rw [if_neg, if_pos, rotateL, if_neg]
[GOAL]
case nil.node.node.nil.refl.refl
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ node 3 (Ordnode.singleton x) rlx (Ordnode.singleton rx) = node4L nil x (node 1 nil rlx nil) rx nil
[PROOFSTEP]
rfl
[GOAL]
case nil.node.node.nil.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ ¬size (node 1 nil rlx nil) < ratio * size nil
case nil.node.node.nil.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ 1 + 1 > 0
case nil.node.node.nil.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ ¬0 + (1 + 1) ≤ 1
[PROOFSTEP]
all_goals dsimp only [size]; decide
[GOAL]
case nil.node.node.nil.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ ¬size (node 1 nil rlx nil) < ratio * size nil
[PROOFSTEP]
dsimp only [size]
[GOAL]
case nil.node.node.nil.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ ¬1 < ratio * 0
[PROOFSTEP]
decide
[GOAL]
case nil.node.node.nil.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ 1 + 1 > 0
[PROOFSTEP]
dsimp only [size]
[GOAL]
case nil.node.node.nil.refl.refl.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ 1 + 1 > 0
[PROOFSTEP]
decide
[GOAL]
case nil.node.node.nil.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ ¬0 + (1 + 1) ≤ 1
[PROOFSTEP]
dsimp only [size]
[GOAL]
case nil.node.node.nil.refl.refl.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx rlx : α
this : size nil = 0 ∧ size nil = 0
hr : Balanced (node' (node 1 nil rlx nil) rx nil)
sr : Sized (node rs (node 1 nil rlx nil) rx nil)
⊢ ¬0 + (1 + 1) ≤ 1
[PROOFSTEP]
decide
[GOAL]
case nil.node.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ (if rls < ratio * rrs then
      node (rls + rrs + 1 + 1) (node (rls + 1) nil x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
    else
      node (rls + rrs + 1 + 1) (node (size rll + 1) nil x rll) rlx
        (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))) =
    if 0 + (rls + rrs + 1) ≤ 1 then node' nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
    else
      if rls + rrs + 1 > 0 then rotateL nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
      else
        if 0 > delta * (rls + rrs + 1) then rotateR nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
        else node' nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
[PROOFSTEP]
symm
[GOAL]
case nil.node.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ (if 0 + (rls + rrs + 1) ≤ 1 then node' nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
    else
      if rls + rrs + 1 > 0 then rotateL nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
      else
        if 0 > delta * (rls + rrs + 1) then rotateR nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
        else node' nil x (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))) =
    if rls < ratio * rrs then
      node (rls + rrs + 1 + 1) (node (rls + 1) nil x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
    else
      node (rls + rrs + 1 + 1) (node (size rll + 1) nil x rll) rlx
        (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))
[PROOFSTEP]
rw [zero_add, if_neg, if_pos, rotateL]
[GOAL]
case nil.node.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ (if size (node rls rll rlx rlr) < ratio * size (node rrs rrl rrx rrr) then
      node3L nil x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)
    else node4L nil x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)) =
    if rls < ratio * rrs then
      node (rls + rrs + 1 + 1) (node (rls + 1) nil x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
    else
      node (rls + rrs + 1 + 1) (node (size rll + 1) nil x rll) rlx
        (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))
[PROOFSTEP]
dsimp only [size_node]
[GOAL]
case nil.node.node.node
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ (if rls < ratio * rrs then node3L nil x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)
    else node4L nil x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)) =
    if rls < ratio * rrs then
      node (rls + rrs + 1 + 1) (node (rls + 1) nil x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
    else
      node (rls + rrs + 1 + 1) (node (size rll + 1) nil x rll) rlx
        (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
h✝ : rls < ratio * rrs
⊢ node3L nil x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr) =
    node (rls + rrs + 1 + 1) (node (rls + 1) nil x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
[PROOFSTEP]
simp [node3L, node']
[GOAL]
case pos
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
h✝ : rls < ratio * rrs
⊢ rls + 1 + rrs = rls + rrs + 1
[PROOFSTEP]
abel
[GOAL]
case pos
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
h✝ : rls < ratio * rrs
⊢ rls + 1 + rrs = rls + rrs + 1
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
h✝ : ¬rls < ratio * rrs
⊢ node4L nil x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr) =
    node (rls + rrs + 1 + 1) (node (size rll + 1) nil x rll) rlx
      (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))
[PROOFSTEP]
simp [node4L, node', sr.2.1.1]
[GOAL]
case neg
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
h✝ : ¬rls < ratio * rrs
⊢ size rll + 1 + (size rlr + rrs + 1) = size rll + size rlr + 1 + rrs + 1
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
h✝ : ¬rls < ratio * rrs
⊢ size rll + 1 + (size rlr + rrs + 1) = size rll + size rlr + 1 + rrs + 1
[PROOFSTEP]
abel
[GOAL]
case nil.node.node.node.hc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ rls + rrs + 1 > 0
[PROOFSTEP]
apply Nat.zero_lt_succ
[GOAL]
case nil.node.node.node.hnc
α : Type u_1
x : α
hl : Balanced nil
sl : Sized nil
rs : ℕ
rx : α
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node' (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
⊢ ¬rls + rrs + 1 ≤ 1
[PROOFSTEP]
exact not_le_of_gt (Nat.succ_lt_succ (add_pos sr.2.1.pos sr.2.2.pos))
[GOAL]
case node
α : Type u_1
x : α
r : Ordnode α
hr : Balanced r
sr : Sized r
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
⊢ balance (node ls ll lx lr) x r = balance' (node ls ll lx lr) x r
[PROOFSTEP]
cases' r with rs rl rx rr
[GOAL]
case node.nil
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
hr : Balanced nil
sr : Sized nil
⊢ balance (node ls ll lx lr) x nil = balance' (node ls ll lx lr) x nil
[PROOFSTEP]
rw [sl.eq_node'] at hl ⊢
[GOAL]
case node.nil
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node' ll lx lr)
sl : Sized (node ls ll lx lr)
hr : Balanced nil
sr : Sized nil
⊢ balance (node' ll lx lr) x nil = balance' (node' ll lx lr) x nil
[PROOFSTEP]
cases' ll with lls lll llx llr
[GOAL]
case node.nil.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
hr : Balanced nil
sr : Sized nil
hl : Balanced (node' nil lx lr)
sl : Sized (node ls nil lx lr)
⊢ balance (node' nil lx lr) x nil = balance' (node' nil lx lr) x nil
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case node.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx lr)
sl : Sized (node ls (node lls lll llx llr) lx lr)
⊢ balance (node' (node lls lll llx llr) lx lr) x nil = balance' (node' (node lls lll llx llr) lx lr) x nil
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case node.nil.nil.nil
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
hl : Balanced (node' nil lx nil)
sl : Sized (node ls nil lx nil)
⊢ balance (node' nil lx nil) x nil = balance' (node' nil lx nil) x nil
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case node.nil.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node' nil lx (node lrs lrl lrx lrr))
sl : Sized (node ls nil lx (node lrs lrl lrx lrr))
⊢ balance (node' nil lx (node lrs lrl lrx lrr)) x nil = balance' (node' nil lx (node lrs lrl lrx lrr)) x nil
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case node.nil.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
⊢ balance (node' (node lls lll llx llr) lx nil) x nil = balance' (node' (node lls lll llx llr) lx nil) x nil
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case node.nil.node.node
α : 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))
⊢ balance (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil =
    balance' (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
[PROOFSTEP]
dsimp [balance, balance']
[GOAL]
case node.nil.nil.nil
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
hl : Balanced (node' nil lx nil)
sl : Sized (node ls nil lx nil)
⊢ node 2 (node' nil lx nil) x nil =
    if 1 ≤ 1 then node' (node' nil lx nil) x nil
    else
      if 0 > delta * (0 + 1) then rotateL (node' nil lx nil) x nil
      else if 0 + 1 > 0 then rotateR (node' nil lx nil) x nil else node' (node' nil lx nil) x nil
[PROOFSTEP]
rfl
[GOAL]
case node.nil.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node' nil lx (node lrs lrl lrx lrr))
sl : Sized (node ls nil lx (node lrs lrl lrx lrr))
⊢ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x) =
    if 0 + lrs + 1 ≤ 1 then node' (node' nil lx (node lrs lrl lrx lrr)) x nil
    else
      if 0 > delta * (0 + lrs + 1) then rotateL (node' nil lx (node lrs lrl lrx lrr)) x nil
      else
        if 0 + lrs + 1 > 0 then rotateR (node' nil lx (node lrs lrl lrx lrr)) x nil
        else node' (node' nil lx (node lrs lrl lrx lrr)) x nil
[PROOFSTEP]
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
[GOAL]
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node' nil lx (node lrs lrl lrx lrr))
sl : Sized (node ls nil lx (node lrs lrl lrx lrr))
⊢ size lrl = 0 ∧ size lrr = 0
[PROOFSTEP]
have := balancedSz_zero.1 hl.1.symm
[GOAL]
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node' nil lx (node lrs lrl lrx lrr))
sl : Sized (node ls nil lx (node lrs lrl lrx lrr))
this : size (node lrs lrl lrx lrr) ≤ 1
⊢ size lrl = 0 ∧ size lrr = 0
[PROOFSTEP]
rwa [size, sl.2.2.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
[GOAL]
case node.nil.nil.node
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node' nil lx (node lrs lrl lrx lrr))
sl : Sized (node ls nil lx (node lrs lrl lrx lrr))
this : size lrl = 0 ∧ size lrr = 0
⊢ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x) =
    if 0 + lrs + 1 ≤ 1 then node' (node' nil lx (node lrs lrl lrx lrr)) x nil
    else
      if 0 > delta * (0 + lrs + 1) then rotateL (node' nil lx (node lrs lrl lrx lrr)) x nil
      else
        if 0 + lrs + 1 > 0 then rotateR (node' nil lx (node lrs lrl lrx lrr)) x nil
        else node' (node' nil lx (node lrs lrl lrx lrr)) x nil
[PROOFSTEP]
cases sl.2.2.2.1.size_eq_zero.1 this.1
[GOAL]
case node.nil.nil.node.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrx : α
lrr : Ordnode α
hl : Balanced (node' nil lx (node lrs nil lrx lrr))
sl : Sized (node ls nil lx (node lrs nil lrx lrr))
this : size nil = 0 ∧ size lrr = 0
⊢ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x) =
    if 0 + lrs + 1 ≤ 1 then node' (node' nil lx (node lrs nil lrx lrr)) x nil
    else
      if 0 > delta * (0 + lrs + 1) then rotateL (node' nil lx (node lrs nil lrx lrr)) x nil
      else
        if 0 + lrs + 1 > 0 then rotateR (node' nil lx (node lrs nil lrx lrr)) x nil
        else node' (node' nil lx (node lrs nil lrx lrr)) x nil
[PROOFSTEP]
cases sl.2.2.2.2.size_eq_zero.1 this.2
[GOAL]
case node.nil.nil.node.refl.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrs : ℕ
lrx : α
hl : Balanced (node' nil lx (node lrs nil lrx nil))
sl : Sized (node ls nil lx (node lrs nil lrx nil))
this : size nil = 0 ∧ size nil = 0
⊢ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x) =
    if 0 + lrs + 1 ≤ 1 then node' (node' nil lx (node lrs nil lrx nil)) x nil
    else
      if 0 > delta * (0 + lrs + 1) then rotateL (node' nil lx (node lrs nil lrx nil)) x nil
      else
        if 0 + lrs + 1 > 0 then rotateR (node' nil lx (node lrs nil lrx nil)) x nil
        else node' (node' nil lx (node lrs nil lrx nil)) x nil
[PROOFSTEP]
obtain rfl : lrs = 1 := sl.2.2.1
[GOAL]
case node.nil.nil.node.refl.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x) =
    if 0 + 1 + 1 ≤ 1 then node' (node' nil lx (node 1 nil lrx nil)) x nil
    else
      if 0 > delta * (0 + 1 + 1) then rotateL (node' nil lx (node 1 nil lrx nil)) x nil
      else
        if 0 + 1 + 1 > 0 then rotateR (node' nil lx (node 1 nil lrx nil)) x nil
        else node' (node' nil lx (node 1 nil lrx nil)) x nil
[PROOFSTEP]
rw [if_neg, if_neg, if_pos, rotateR, if_neg]
[GOAL]
case node.nil.nil.node.refl.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ node 3 (Ordnode.singleton lx) lrx (Ordnode.singleton x) = node4R nil lx (node 1 nil lrx nil) x nil
[PROOFSTEP]
rfl
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬size (node 1 nil lrx nil) < ratio * size nil
case node.nil.nil.node.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ 0 + 1 + 1 > 0
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬0 > delta * (0 + 1 + 1)
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬0 + 1 + 1 ≤ 1
[PROOFSTEP]
all_goals dsimp only [size]; decide
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬size (node 1 nil lrx nil) < ratio * size nil
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬1 < ratio * 0
[PROOFSTEP]
decide
[GOAL]
case node.nil.nil.node.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ 0 + 1 + 1 > 0
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.nil.node.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ 0 + 1 + 1 > 0
[PROOFSTEP]
decide
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬0 > delta * (0 + 1 + 1)
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬0 > delta * (0 + 1 + 1)
[PROOFSTEP]
decide
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬0 + 1 + 1 ≤ 1
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.nil.node.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lrx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' nil lx (node 1 nil lrx nil))
sl : Sized (node ls nil lx (node 1 nil lrx nil))
⊢ ¬0 + 1 + 1 ≤ 1
[PROOFSTEP]
decide
[GOAL]
case node.nil.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
⊢ node 3 (node lls lll llx llr) lx (Ordnode.singleton x) =
    if lls + 1 ≤ 1 then node' (node' (node lls lll llx llr) lx nil) x nil
    else
      if 0 > delta * (lls + 1) then rotateL (node' (node lls lll llx llr) lx nil) x nil
      else
        if lls + 1 > 0 then rotateR (node' (node lls lll llx llr) lx nil) x nil
        else node' (node' (node lls lll llx llr) lx nil) x nil
[PROOFSTEP]
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
[GOAL]
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
⊢ size lll = 0 ∧ size llr = 0
[PROOFSTEP]
have := balancedSz_zero.1 hl.1
[GOAL]
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
this : size (node lls lll llx llr) ≤ 1
⊢ size lll = 0 ∧ size llr = 0
[PROOFSTEP]
rwa [size, sl.2.1.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
[GOAL]
case node.nil.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
this : size lll = 0 ∧ size llr = 0
⊢ node 3 (node lls lll llx llr) lx (Ordnode.singleton x) =
    if lls + 1 ≤ 1 then node' (node' (node lls lll llx llr) lx nil) x nil
    else
      if 0 > delta * (lls + 1) then rotateL (node' (node lls lll llx llr) lx nil) x nil
      else
        if lls + 1 > 0 then rotateR (node' (node lls lll llx llr) lx nil) x nil
        else node' (node' (node lls lll llx llr) lx nil) x nil
[PROOFSTEP]
cases sl.2.1.2.1.size_eq_zero.1 this.1
[GOAL]
case node.nil.node.nil.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
llx : α
llr : Ordnode α
hl : Balanced (node' (node lls nil llx llr) lx nil)
sl : Sized (node ls (node lls nil llx llr) lx nil)
this : size nil = 0 ∧ size llr = 0
⊢ node 3 (node lls nil llx llr) lx (Ordnode.singleton x) =
    if lls + 1 ≤ 1 then node' (node' (node lls nil llx llr) lx nil) x nil
    else
      if 0 > delta * (lls + 1) then rotateL (node' (node lls nil llx llr) lx nil) x nil
      else
        if lls + 1 > 0 then rotateR (node' (node lls nil llx llr) lx nil) x nil
        else node' (node' (node lls nil llx llr) lx nil) x nil
[PROOFSTEP]
cases sl.2.1.2.2.size_eq_zero.1 this.2
[GOAL]
case node.nil.node.nil.refl.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
lls : ℕ
llx : α
hl : Balanced (node' (node lls nil llx nil) lx nil)
sl : Sized (node ls (node lls nil llx nil) lx nil)
this : size nil = 0 ∧ size nil = 0
⊢ node 3 (node lls nil llx nil) lx (Ordnode.singleton x) =
    if lls + 1 ≤ 1 then node' (node' (node lls nil llx nil) lx nil) x nil
    else
      if 0 > delta * (lls + 1) then rotateL (node' (node lls nil llx nil) lx nil) x nil
      else
        if lls + 1 > 0 then rotateR (node' (node lls nil llx nil) lx nil) x nil
        else node' (node' (node lls nil llx nil) lx nil) x nil
[PROOFSTEP]
obtain rfl : lls = 1 := sl.2.1.1
[GOAL]
case node.nil.node.nil.refl.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ node 3 (node 1 nil llx nil) lx (Ordnode.singleton x) =
    if 1 + 1 ≤ 1 then node' (node' (node 1 nil llx nil) lx nil) x nil
    else
      if 0 > delta * (1 + 1) then rotateL (node' (node 1 nil llx nil) lx nil) x nil
      else
        if 1 + 1 > 0 then rotateR (node' (node 1 nil llx nil) lx nil) x nil
        else node' (node' (node 1 nil llx nil) lx nil) x nil
[PROOFSTEP]
rw [if_neg, if_neg, if_pos, rotateR, if_pos]
[GOAL]
case node.nil.node.nil.refl.refl
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ node 3 (node 1 nil llx nil) lx (Ordnode.singleton x) = node3R (node 1 nil llx nil) lx nil x nil
[PROOFSTEP]
rfl
[GOAL]
case node.nil.node.nil.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ size nil < ratio * size (node 1 nil llx nil)
case node.nil.node.nil.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ 1 + 1 > 0
case node.nil.node.nil.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ ¬0 > delta * (1 + 1)
case node.nil.node.nil.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ ¬1 + 1 ≤ 1
[PROOFSTEP]
all_goals dsimp only [size]; decide
[GOAL]
case node.nil.node.nil.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ size nil < ratio * size (node 1 nil llx nil)
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.node.nil.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ 0 < ratio * 1
[PROOFSTEP]
decide
[GOAL]
case node.nil.node.nil.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ 1 + 1 > 0
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.node.nil.refl.refl.hc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ 1 + 1 > 0
[PROOFSTEP]
decide
[GOAL]
case node.nil.node.nil.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ ¬0 > delta * (1 + 1)
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.node.nil.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ ¬0 > delta * (1 + 1)
[PROOFSTEP]
decide
[GOAL]
case node.nil.node.nil.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ ¬1 + 1 ≤ 1
[PROOFSTEP]
dsimp only [size]
[GOAL]
case node.nil.node.nil.refl.refl.hnc
α : Type u_1
x : α
ls : ℕ
lx : α
hr : Balanced nil
sr : Sized nil
llx : α
this : size nil = 0 ∧ size nil = 0
hl : Balanced (node' (node 1 nil llx nil) lx nil)
sl : Sized (node ls (node 1 nil llx nil) lx nil)
⊢ ¬1 + 1 ≤ 1
[PROOFSTEP]
decide
[GOAL]
case node.nil.node.node
α : 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))
⊢ (if lrs < ratio * lls then
      node (lls + lrs + 1 + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
    else
      node (lls + lrs + 1 + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
        (node (size lrr + 1) lrr x nil)) =
    if lls + lrs + 1 ≤ 1 then node' (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
    else
      if 0 > delta * (lls + lrs + 1) then rotateL (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
      else
        if lls + lrs + 1 > 0 then rotateR (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
        else node' (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
[PROOFSTEP]
symm
[GOAL]
case node.nil.node.node
α : 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))
⊢ (if lls + lrs + 1 ≤ 1 then node' (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
    else
      if 0 > delta * (lls + lrs + 1) then rotateL (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
      else
        if lls + lrs + 1 > 0 then rotateR (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil
        else node' (node' (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x nil) =
    if lrs < ratio * lls then
      node (lls + lrs + 1 + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
    else
      node (lls + lrs + 1 + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
        (node (size lrr + 1) lrr x nil)
[PROOFSTEP]
rw [if_neg, if_neg, if_pos, rotateR]
[GOAL]
case node.nil.node.node
α : 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))
⊢ (if size (node lrs lrl lrx lrr) < ratio * size (node lls lll llx llr) then
      node3R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x nil
    else node4R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x nil) =
    if lrs < ratio * lls then
      node (lls + lrs + 1 + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
    else
      node (lls + lrs + 1 + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
        (node (size lrr + 1) lrr x nil)
[PROOFSTEP]
dsimp only [size_node]
[GOAL]
case node.nil.node.node
α : 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))
⊢ (if lrs < ratio * lls then node3R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x nil
    else node4R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x nil) =
    if lrs < ratio * lls then
      node (lls + lrs + 1 + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
    else
      node (lls + lrs + 1 + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
        (node (size lrr + 1) lrr x nil)
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : 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))
h✝ : lrs < ratio * lls
⊢ node3R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x nil =
    node (lls + lrs + 1 + 1) (node lls lll llx llr) lx (node (lrs + 1) (node lrs lrl lrx lrr) x nil)
[PROOFSTEP]
simp [node3R, node']
[GOAL]
case pos
α : 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))
h✝ : lrs < ratio * lls
⊢ lls + (lrs + 1) = lls + lrs + 1
[PROOFSTEP]
abel
[GOAL]
case pos
α : 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))
h✝ : lrs < ratio * lls
⊢ lls + (lrs + 1) = lls + lrs + 1
[PROOFSTEP]
abel
[GOAL]
case neg
α : 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))
h✝ : ¬lrs < ratio * lls
⊢ node4R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x nil =
    node (lls + lrs + 1 + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
      (node (size lrr + 1) lrr x nil)
[PROOFSTEP]
simp [node4R, node', sl.2.2.1]
[GOAL]
case neg
α : 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))
h✝ : ¬lrs < ratio * lls
⊢ lls + size lrl + 1 + (size lrr + 1) = lls + (size lrl + size lrr + 1) + 1
[PROOFSTEP]
abel
[GOAL]
case neg
α : 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))
h✝ : ¬lrs < ratio * lls
⊢ lls + size lrl + 1 + (size lrr + 1) = lls + (size lrl + size lrr + 1) + 1
[PROOFSTEP]
abel
[GOAL]
case node.nil.node.node.hc
α : 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))
⊢ lls + lrs + 1 > 0
[PROOFSTEP]
apply Nat.zero_lt_succ
[GOAL]
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)
[PROOFSTEP]
apply Nat.not_lt_zero
[GOAL]
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))
⊢ ¬lls + lrs + 1 ≤ 1
[PROOFSTEP]
exact not_le_of_gt (Nat.succ_lt_succ (add_pos sl.2.1.pos sl.2.2.pos))
[GOAL]
case node.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ balance (node ls ll lx lr) x (node rs rl rx rr) = balance' (node ls ll lx lr) x (node rs rl rx rr)
[PROOFSTEP]
simp [balance, balance']
[GOAL]
case node.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ (if delta * ls < rs then
      rec (motive := fun t => rl = t → Ordnode α) (fun h => nil)
        (fun size l x_1 r l_ih r_ih h =>
          rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
            (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
              if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x rl) rx rr
              else
                node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                  (node (Ordnode.size r + size_1 + 1) r rx rr))
            rr (_ : id rr = id rr))
        rl (_ : id rl = id rl)
    else
      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)) =
    if ls + rs ≤ 1 then node' (node ls ll lx lr) x (node rs rl rx rr)
    else
      if delta * ls < rs then rotateL (node ls ll lx lr) x (node rs rl rx rr)
      else
        if delta * rs < ls then rotateR (node ls ll lx lr) x (node rs rl rx rr)
        else node' (node ls ll lx lr) x (node rs rl rx rr)
[PROOFSTEP]
symm
[GOAL]
case node.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ (if ls + rs ≤ 1 then node' (node ls ll lx lr) x (node rs rl rx rr)
    else
      if delta * ls < rs then rotateL (node ls ll lx lr) x (node rs rl rx rr)
      else
        if delta * rs < ls then rotateR (node ls ll lx lr) x (node rs rl rx rr)
        else node' (node ls ll lx lr) x (node rs rl rx rr)) =
    if delta * ls < rs then
      rec (motive := fun t => rl = t → Ordnode α) (fun h => nil)
        (fun size l x_1 r l_ih r_ih h =>
          rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
            (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
              if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x rl) rx rr
              else
                node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                  (node (Ordnode.size r + size_1 + 1) r rx rr))
            rr (_ : id rr = id rr))
        rl (_ : id rl = id rl)
    else
      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)
[PROOFSTEP]
rw [if_neg]
[GOAL]
case node.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ (if delta * ls < rs then rotateL (node ls ll lx lr) x (node rs rl rx rr)
    else
      if delta * rs < ls then rotateR (node ls ll lx lr) x (node rs rl rx rr)
      else node' (node ls ll lx lr) x (node rs rl rx rr)) =
    if delta * ls < rs then
      rec (motive := fun t => rl = t → Ordnode α) (fun h => nil)
        (fun size l x_1 r l_ih r_ih h =>
          rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
            (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
              if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x rl) rx rr
              else
                node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                  (node (Ordnode.size r + size_1 + 1) r rx rr))
            rr (_ : id rr = id rr))
        rl (_ : id rl = id rl)
    else
      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)
[PROOFSTEP]
split_ifs with h h_1
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : delta * ls < rs
⊢ rotateL (node ls ll lx lr) x (node rs rl rx rr) =
    rec (motive := fun t => rl = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x rl) rx rr
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx rr))
          rr (_ : id rr = id rr))
      rl (_ : id rl = id rl)
[PROOFSTEP]
have rd : delta ≤ size rl + size rr :=
  by
  have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sl.pos) h
  rwa [sr.1, Nat.lt_succ_iff] at this
[GOAL]
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : delta * ls < rs
⊢ delta ≤ size rl + size rr
[PROOFSTEP]
have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sl.pos) h
[GOAL]
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : delta * ls < rs
this : delta * Nat.succ 0 < rs
⊢ delta ≤ size rl + size rr
[PROOFSTEP]
rwa [sr.1, Nat.lt_succ_iff] at this
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : delta * ls < rs
rd : delta ≤ size rl + size rr
⊢ rotateL (node ls ll lx lr) x (node rs rl rx rr) =
    rec (motive := fun t => rl = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x rl) rx rr
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx rr))
          rr (_ : id rr = id rr))
      rl (_ : id rl = id rl)
[PROOFSTEP]
cases' rl with rls rll rlx rlr
[GOAL]
case pos.nil
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
rr : Ordnode α
h : delta * ls < rs
hr : Balanced (node rs nil rx rr)
sr : Sized (node rs nil rx rr)
rd : delta ≤ size nil + size rr
⊢ rotateL (node ls ll lx lr) x (node rs nil rx rr) =
    rec (motive := fun t => nil = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x nil) rx rr
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx rr))
          rr (_ : id rr = id rr))
      nil (_ : id nil = id nil)
[PROOFSTEP]
rw [size, zero_add] at rd
[GOAL]
case pos.nil
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
rr : Ordnode α
h : delta * ls < rs
hr : Balanced (node rs nil rx rr)
sr : Sized (node rs nil rx rr)
rd : delta ≤ size rr
⊢ rotateL (node ls ll lx lr) x (node rs nil rx rr) =
    rec (motive := fun t => nil = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x nil) rx rr
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx rr))
          rr (_ : id rr = id rr))
      nil (_ : id nil = id nil)
[PROOFSTEP]
exact absurd (le_trans rd (balancedSz_zero.1 hr.1.symm)) (by decide)
[GOAL]
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
rr : Ordnode α
h : delta * ls < rs
hr : Balanced (node rs nil rx rr)
sr : Sized (node rs nil rx rr)
rd : delta ≤ size rr
⊢ ¬delta ≤ 1
[PROOFSTEP]
decide
[GOAL]
case pos.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
rr : Ordnode α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx rr)
sr : Sized (node rs (node rls rll rlx rlr) rx rr)
rd : delta ≤ size (node rls rll rlx rlr) + size rr
⊢ rotateL (node ls ll lx lr) x (node rs (node rls rll rlx rlr) rx rr) =
    rec (motive := fun t => node rls rll rlx rlr = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => rr = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then
              node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x (node rls rll rlx rlr)) rx rr
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx rr))
          rr (_ : id rr = id rr))
      (node rls rll rlx rlr) (_ : id (node rls rll rlx rlr) = id (node rls rll rlx rlr))
[PROOFSTEP]
cases' rr with rrs rrl rrx rrr
[GOAL]
case pos.node.nil
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
rd : delta ≤ size (node rls rll rlx rlr) + size nil
⊢ rotateL (node ls ll lx lr) x (node rs (node rls rll rlx rlr) rx nil) =
    rec (motive := fun t => node rls rll rlx rlr = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => nil = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then
              node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x (node rls rll rlx rlr)) rx nil
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx nil))
          nil (_ : id nil = id nil))
      (node rls rll rlx rlr) (_ : id (node rls rll rlx rlr) = id (node rls rll rlx rlr))
[PROOFSTEP]
exact absurd (le_trans rd (balancedSz_zero.1 hr.1)) (by decide)
[GOAL]
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx nil)
sr : Sized (node rs (node rls rll rlx rlr) rx nil)
rd : delta ≤ size (node rls rll rlx rlr) + size nil
⊢ ¬delta ≤ 1
[PROOFSTEP]
decide
[GOAL]
case pos.node.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
⊢ rotateL (node ls ll lx lr) x (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)) =
    rec (motive := fun t => node rls rll rlx rlr = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => node rrs rrl rrx rrr = t → Ordnode α) (fun h => nil)
          (fun size_1 l_1 x_2 r_1 l_ih r_ih h =>
            if size < ratio * size_1 then
              node (ls + rs + 1) (node (ls + size + 1) (node ls ll lx lr) x (node rls rll rlx rlr)) rx
                (node rrs rrl rrx rrr)
            else
              node (ls + rs + 1) (node (ls + Ordnode.size l + 1) (node ls ll lx lr) x l) x_1
                (node (Ordnode.size r + size_1 + 1) r rx (node rrs rrl rrx rrr)))
          (node rrs rrl rrx rrr) (_ : id (node rrs rrl rrx rrr) = id (node rrs rrl rrx rrr)))
      (node rls rll rlx rlr) (_ : id (node rls rll rlx rlr) = id (node rls rll rlx rlr))
[PROOFSTEP]
dsimp [rotateL]
[GOAL]
case pos.node.node
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
⊢ (if rls < ratio * rrs then node3L (node ls ll lx lr) x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)
    else node4L (node ls ll lx lr) x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr)) =
    if rls < ratio * rrs then
      node (ls + rs + 1) (node (ls + rls + 1) (node ls ll lx lr) x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
    else
      node (ls + rs + 1) (node (ls + size rll + 1) (node ls ll lx lr) x rll) rlx
        (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
h✝ : rls < ratio * rrs
⊢ node3L (node ls ll lx lr) x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr) =
    node (ls + rs + 1) (node (ls + rls + 1) (node ls ll lx lr) x (node rls rll rlx rlr)) rx (node rrs rrl rrx rrr)
[PROOFSTEP]
simp [node3L, node', sr.1]
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
h✝ : rls < ratio * rrs
⊢ ls + rls + 1 + rrs = ls + (rls + rrs + 1)
[PROOFSTEP]
abel
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
h✝ : rls < ratio * rrs
⊢ ls + rls + 1 + rrs = ls + (rls + rrs + 1)
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
h✝ : ¬rls < ratio * rrs
⊢ node4L (node ls ll lx lr) x (node rls rll rlx rlr) rx (node rrs rrl rrx rrr) =
    node (ls + rs + 1) (node (ls + size rll + 1) (node ls ll lx lr) x rll) rlx
      (node (size rlr + rrs + 1) rlr rx (node rrs rrl rrx rrr))
[PROOFSTEP]
simp [node4L, node', sr.1, sr.2.1.1]
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
h✝ : ¬rls < ratio * rrs
⊢ ls + size rll + 1 + (size rlr + rrs + 1) = ls + (size rll + size rlr + 1 + rrs + 1)
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rx : α
h : delta * ls < rs
rls : ℕ
rll : Ordnode α
rlx : α
rlr : Ordnode α
rrs : ℕ
rrl : Ordnode α
rrx : α
rrr : Ordnode α
hr : Balanced (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
sr : Sized (node rs (node rls rll rlx rlr) rx (node rrs rrl rrx rrr))
rd : delta ≤ size (node rls rll rlx rlr) + size (node rrs rrl rrx rrr)
h✝ : ¬rls < ratio * rrs
⊢ ls + size rll + 1 + (size rlr + rrs + 1) = ls + (size rll + size rlr + 1 + rrs + 1)
[PROOFSTEP]
abel
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
⊢ rotateR (node ls ll lx lr) x (node rs rl rx rr) =
    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)
[PROOFSTEP]
have ld : delta ≤ size ll + size lr :=
  by
  have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sr.pos) h_1
  rwa [sl.1, Nat.lt_succ_iff] at this
[GOAL]
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
⊢ delta ≤ size ll + size lr
[PROOFSTEP]
have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sr.pos) h_1
[GOAL]
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
this : delta * Nat.succ 0 < ls
⊢ delta ≤ size ll + size lr
[PROOFSTEP]
rwa [sl.1, Nat.lt_succ_iff] at this
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
ld : delta ≤ size ll + size lr
⊢ rotateR (node ls ll lx lr) x (node rs rl rx rr) =
    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)
[PROOFSTEP]
cases' ll with lls lll llx llr
[GOAL]
case pos.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
hl : Balanced (node ls nil lx lr)
sl : Sized (node ls nil lx lr)
ld : delta ≤ size nil + size lr
⊢ rotateR (node ls nil lx lr) x (node rs rl rx rr) =
    rec (motive := fun t => nil = 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) nil lx (node (size_1 + rs + 1) lr x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          lr (_ : id lr = id lr))
      nil (_ : id nil = id nil)
[PROOFSTEP]
rw [size, zero_add] at ld
[GOAL]
case pos.nil
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
hl : Balanced (node ls nil lx lr)
sl : Sized (node ls nil lx lr)
ld : delta ≤ size lr
⊢ rotateR (node ls nil lx lr) x (node rs rl rx rr) =
    rec (motive := fun t => nil = 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) nil lx (node (size_1 + rs + 1) lr x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) nil lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          lr (_ : id lr = id lr))
      nil (_ : id nil = id nil)
[PROOFSTEP]
exact absurd (le_trans ld (balancedSz_zero.1 hl.1.symm)) (by decide)
[GOAL]
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
hl : Balanced (node ls nil lx lr)
sl : Sized (node ls nil lx lr)
ld : delta ≤ size lr
⊢ ¬delta ≤ 1
[PROOFSTEP]
decide
[GOAL]
case pos.node
α : Type u_1
x : α
ls : ℕ
lx : α
lr : Ordnode α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node ls (node lls lll llx llr) lx lr)
sl : Sized (node ls (node lls lll llx llr) lx lr)
ld : delta ≤ size (node lls lll llx llr) + size lr
⊢ rotateR (node ls (node lls lll llx llr) lx lr) x (node rs rl rx rr) =
    rec (motive := fun t => node lls lll llx llr = 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) (node lls lll llx llr) lx (node (size_1 + rs + 1) lr x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          lr (_ : id lr = id lr))
      (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))
[PROOFSTEP]
cases' lr with lrs lrl lrx lrr
[GOAL]
case pos.node.nil
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node ls (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
ld : delta ≤ size (node lls lll llx llr) + size nil
⊢ rotateR (node ls (node lls lll llx llr) lx nil) x (node rs rl rx rr) =
    rec (motive := fun t => node lls lll llx llr = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => nil = 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) (node lls lll llx llr) lx (node (size_1 + rs + 1) nil x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          nil (_ : id nil = id nil))
      (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))
[PROOFSTEP]
exact absurd (le_trans ld (balancedSz_zero.1 hl.1)) (by decide)
[GOAL]
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
hl : Balanced (node ls (node lls lll llx llr) lx nil)
sl : Sized (node ls (node lls lll llx llr) lx nil)
ld : delta ≤ size (node lls lll llx llr) + size nil
⊢ ¬delta ≤ 1
[PROOFSTEP]
decide
[GOAL]
case pos.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
⊢ rotateR (node ls (node lls lll llx llr) lx (node lrs lrl lrx lrr)) x (node rs rl rx rr) =
    rec (motive := fun t => node lls lll llx llr = t → Ordnode α) (fun h => nil)
      (fun size l x_1 r l_ih r_ih h =>
        rec (motive := fun t => node lrs lrl lrx lrr = 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) (node lls lll llx llr) lx
                (node (size_1 + rs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
            else
              node (ls + rs + 1) (node (size + Ordnode.size l + 1) (node lls lll llx llr) lx l) x_2
                (node (Ordnode.size r + rs + 1) r x (node rs rl rx rr)))
          (node lrs lrl lrx lrr) (_ : id (node lrs lrl lrx lrr) = id (node lrs lrl lrx lrr)))
      (node lls lll llx llr) (_ : id (node lls lll llx llr) = id (node lls lll llx llr))
[PROOFSTEP]
dsimp [rotateR]
[GOAL]
case pos.node.node
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
⊢ (if lrs < ratio * lls then node3R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x (node rs rl rx rr)
    else node4R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x (node rs rl rx rr)) =
    if lrs < ratio * lls then
      node (ls + rs + 1) (node lls lll llx llr) lx (node (lrs + rs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
    else
      node (ls + rs + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
        (node (size lrr + rs + 1) lrr x (node rs rl rx rr))
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
h✝ : lrs < ratio * lls
⊢ node3R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x (node rs rl rx rr) =
    node (ls + rs + 1) (node lls lll llx llr) lx (node (lrs + rs + 1) (node lrs lrl lrx lrr) x (node rs rl rx rr))
[PROOFSTEP]
simp [node3R, node', sl.1]
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
h✝ : lrs < ratio * lls
⊢ lls + (lrs + rs + 1) = lls + lrs + 1 + rs
[PROOFSTEP]
abel
[GOAL]
case pos
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
h✝ : lrs < ratio * lls
⊢ lls + (lrs + rs + 1) = lls + lrs + 1 + rs
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
h✝ : ¬lrs < ratio * lls
⊢ node4R (node lls lll llx llr) lx (node lrs lrl lrx lrr) x (node rs rl rx rr) =
    node (ls + rs + 1) (node (lls + size lrl + 1) (node lls lll llx llr) lx lrl) lrx
      (node (size lrr + rs + 1) lrr x (node rs rl rx rr))
[PROOFSTEP]
simp [node4R, node', sl.1, sl.2.2.1]
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
h✝ : ¬lrs < ratio * lls
⊢ lls + size lrl + 1 + (size lrr + rs + 1) = lls + (size lrl + size lrr + 1) + 1 + rs
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
lx : α
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
lls : ℕ
lll : Ordnode α
llx : α
llr : Ordnode α
lrs : ℕ
lrl : Ordnode α
lrx : α
lrr : Ordnode α
hl : Balanced (node ls (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))
ld : delta ≤ size (node lls lll llx llr) + size (node lrs lrl lrx lrr)
h✝ : ¬lrs < ratio * lls
⊢ lls + size lrl + 1 + (size lrr + rs + 1) = lls + (size lrl + size lrr + 1) + 1 + rs
[PROOFSTEP]
abel
[GOAL]
case neg
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
h : ¬delta * ls < rs
h_1 : ¬delta * rs < ls
⊢ node' (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)
[PROOFSTEP]
simp [node']
[GOAL]
case node.node.hnc
α : Type u_1
x : α
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
hl : Balanced (node ls ll lx lr)
sl : Sized (node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Balanced (node rs rl rx rr)
sr : Sized (node rs rl rx rr)
⊢ ¬ls + rs ≤ 1
[PROOFSTEP]
exact not_le_of_gt (add_le_add (Nat.succ_le_of_lt sl.pos) (Nat.succ_le_of_lt sr.pos))
[GOAL]
α : 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
[PROOFSTEP]
cases' r with rs rl rx rr
[GOAL]
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
[PROOFSTEP]
rfl
[GOAL]
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)
[PROOFSTEP]
cases' l with ls ll lx lr
[GOAL]
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)
[PROOFSTEP]
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
[GOAL]
α : 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
[PROOFSTEP]
have := H1 rfl
[GOAL]
α : 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
[PROOFSTEP]
rwa [size, sr.1, Nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this
[GOAL]
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)
[PROOFSTEP]
cases sr.2.1.size_eq_zero.1 this.1
[GOAL]
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)
[PROOFSTEP]
cases sr.2.2.size_eq_zero.1 this.2
[GOAL]
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)
[PROOFSTEP]
rw [sr.eq_node']
[GOAL]
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)
[PROOFSTEP]
rfl
[GOAL]
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)
[PROOFSTEP]
replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos)
[GOAL]
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)
[PROOFSTEP]
simp [balanceL, balance, H2]
[GOAL]
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)
[PROOFSTEP]
split_ifs
[GOAL]
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)
[PROOFSTEP]
simp [add_comm]
[GOAL]
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)
[PROOFSTEP]
simp [add_comm]
[GOAL]
α : Type u_1
n m : ℕ
⊢ Raised n m ↔ n ≤ m ∧ m ≤ n + 1
[PROOFSTEP]
constructor
[GOAL]
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
[PROOFSTEP]
rintro (rfl | rfl)
[GOAL]
case mp.inl
α : Type u_1
m : ℕ
⊢ m ≤ m ∧ m ≤ m + 1
[PROOFSTEP]
exact ⟨le_rfl, Nat.le_succ _⟩
[GOAL]
case mp.inr
α : Type u_1
n : ℕ
⊢ n ≤ n + 1 ∧ n + 1 ≤ n + 1
[PROOFSTEP]
exact ⟨Nat.le_succ _, le_rfl⟩
[GOAL]
case mpr
α : Type u_1
n m : ℕ
⊢ n ≤ m ∧ m ≤ n + 1 → Raised n m
[PROOFSTEP]
rintro ⟨h₁, h₂⟩
[GOAL]
case mpr.intro
α : Type u_1
n m : ℕ
h₁ : n ≤ m
h₂ : m ≤ n + 1
⊢ Raised n m
[PROOFSTEP]
rcases eq_or_lt_of_le h₁ with (rfl | h₁)
[GOAL]
case mpr.intro.inl
α : Type u_1
n : ℕ
h₁ : n ≤ n
h₂ : n ≤ n + 1
⊢ Raised n n
[PROOFSTEP]
exact Or.inl rfl
[GOAL]
case mpr.intro.inr
α : Type u_1
n m : ℕ
h₁✝ : n ≤ m
h₂ : m ≤ n + 1
h₁ : n < m
⊢ Raised n m
[PROOFSTEP]
exact Or.inr (le_antisymm h₂ h₁)
[GOAL]
α : Type u_1
n m : ℕ
H : Raised n m
⊢ Nat.dist n m ≤ 1
[PROOFSTEP]
cases' raised_iff.1 H with H1 H2
[GOAL]
case intro
α : Type u_1
n m : ℕ
H : Raised n m
H1 : n ≤ m
H2 : m ≤ n + 1
⊢ Nat.dist n m ≤ 1
[PROOFSTEP]
rwa [Nat.dist_eq_sub_of_le H1, tsub_le_iff_left]
[GOAL]
α : Type u_1
n m : ℕ
H : Raised n m
⊢ Nat.dist m n ≤ 1
[PROOFSTEP]
rw [Nat.dist_comm]
[GOAL]
α : Type u_1
n m : ℕ
H : Raised n m
⊢ Nat.dist n m ≤ 1
[PROOFSTEP]
exact H.dist_le
[GOAL]
α : Type u_1
k n m : ℕ
H : Raised n m
⊢ Raised (k + n) (k + m)
[PROOFSTEP]
rcases H with (rfl | rfl)
[GOAL]
case inl
α : Type u_1
k m : ℕ
⊢ Raised (k + m) (k + m)
[PROOFSTEP]
exact Or.inl rfl
[GOAL]
case inr
α : Type u_1
k n : ℕ
⊢ Raised (k + n) (k + (n + 1))
[PROOFSTEP]
exact Or.inr rfl
[GOAL]
α : Type u_1
k n m : ℕ
H : Raised n m
⊢ Raised (n + k) (m + k)
[PROOFSTEP]
rw [add_comm, add_comm m]
[GOAL]
α : Type u_1
k n m : ℕ
H : Raised n m
⊢ Raised (k + n) (k + m)
[PROOFSTEP]
exact H.add_left _
[GOAL]
α : 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₂))
[PROOFSTEP]
rw [node', size, size]
[GOAL]
α : 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)
[PROOFSTEP]
generalize size r₂ = m at H ⊢
[GOAL]
α : 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)
[PROOFSTEP]
rcases H with (rfl | rfl)
[GOAL]
case inl
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
⊢ Raised (size l + size r₁ + 1) (size l + size r₁ + 1)
[PROOFSTEP]
exact Or.inl rfl
[GOAL]
case inr
α : Type u_1
l : Ordnode α
x₁ x₂ : α
r₁ r₂ : Ordnode α
⊢ Raised (size l + size r₁ + 1) (size l + (size r₁ + 1) + 1)
[PROOFSTEP]
exact Or.inr rfl
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ balanceL l x r = balance' l x r
[PROOFSTEP]
rw [← balance_eq_balance' hl hr sl sr, balanceL_eq_balance sl sr]
[GOAL]
case H1
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ size l = 0 → size r ≤ 1
[PROOFSTEP]
intro l0
[GOAL]
case H1
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
l0 : size l = 0
⊢ size r ≤ 1
[PROOFSTEP]
rw [l0] at H
[GOAL]
case H1
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' 0 ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz 0 r'
l0 : size l = 0
⊢ size r ≤ 1
[PROOFSTEP]
rcases H with (⟨_, ⟨⟨⟩⟩ | ⟨⟨⟩⟩, H⟩ | ⟨r', e, H⟩)
[GOAL]
case H1.inl.intro.intro.inl.refl
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l0 : size l = 0
H : BalancedSz 0 (size r)
⊢ size r ≤ 1
[PROOFSTEP]
exact balancedSz_zero.1 H.symm
[GOAL]
case H1.inr.intro.intro
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l0 : size l = 0
r' : ℕ
e : Raised (size r) r'
H : BalancedSz 0 r'
⊢ size r ≤ 1
[PROOFSTEP]
exact le_trans (raised_iff.1 e).1 (balancedSz_zero.1 H.symm)
[GOAL]
case H2
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
[PROOFSTEP]
intro l1 _
[GOAL]
case H2
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
⊢ size r ≤ delta * size l
[PROOFSTEP]
rcases H with (⟨l', e, H | ⟨_, H₂⟩⟩ | ⟨r', e, H | ⟨_, H₂⟩⟩)
[GOAL]
case H2.inl.intro.intro.inl
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
l' : ℕ
e : Raised l' (size l)
H : l' + size r ≤ 1
⊢ size r ≤ delta * size l
[PROOFSTEP]
exact le_trans (le_trans (Nat.le_add_left _ _) H) (mul_pos (by decide) l1 : (0 : ℕ) < _)
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
l' : ℕ
e : Raised l' (size l)
H : l' + size r ≤ 1
⊢ 0 < delta
[PROOFSTEP]
decide
[GOAL]
case H2.inl.intro.intro.inr.intro
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
l' : ℕ
e : Raised l' (size l)
left✝ : l' ≤ delta * size r
H₂ : size r ≤ delta * l'
⊢ size r ≤ delta * size l
[PROOFSTEP]
exact le_trans H₂ (Nat.mul_le_mul_left _ (raised_iff.1 e).1)
[GOAL]
case H2.inr.intro.intro.inl
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
r' : ℕ
e : Raised (size r) r'
H : size l + r' ≤ 1
⊢ size r ≤ delta * size l
[PROOFSTEP]
cases raised_iff.1 e
[GOAL]
case H2.inr.intro.intro.inl.intro
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
r' : ℕ
e : Raised (size r) r'
H : size l + r' ≤ 1
left✝ : size r ≤ r'
right✝ : r' ≤ size r + 1
⊢ size r ≤ delta * size l
[PROOFSTEP]
unfold delta
[GOAL]
case H2.inr.intro.intro.inl.intro
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
r' : ℕ
e : Raised (size r) r'
H : size l + r' ≤ 1
left✝ : size r ≤ r'
right✝ : r' ≤ size r + 1
⊢ size r ≤ 3 * size l
[PROOFSTEP]
linarith
[GOAL]
case H2.inr.intro.intro.inr.intro
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
l1 : 1 ≤ size l
a✝ : 1 ≤ size r
r' : ℕ
e : Raised (size r) r'
left✝ : size l ≤ delta * r'
H₂ : r' ≤ delta * size l
⊢ size r ≤ delta * size l
[PROOFSTEP]
exact le_trans (raised_iff.1 e).1 H₂
[GOAL]
α : Type u_1
l r : Ordnode α
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ (∃ l', Raised l' (size (dual r)) ∧ BalancedSz l' (size (dual l))) ∨
    ∃ r', Raised (size (dual l)) r' ∧ BalancedSz (size (dual r)) r'
[PROOFSTEP]
rw [size_dual, size_dual]
[GOAL]
α : Type u_1
l r : Ordnode α
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ (∃ l', Raised l' (size r) ∧ BalancedSz l' (size l)) ∨ ∃ r', Raised (size l) r' ∧ BalancedSz (size r) r'
[PROOFSTEP]
exact H.symm.imp (Exists.imp fun _ => And.imp_right BalancedSz.symm) (Exists.imp fun _ => And.imp_right BalancedSz.symm)
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ size (balanceL l x r) = size l + size r + 1
[PROOFSTEP]
rw [balanceL_eq_balance' hl hr sl sr H, size_balance' sl sr]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ All P (balanceL l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
rw [balanceL_eq_balance' hl hr sl sr H, all_balance']
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ balanceR l x r = balance' l x r
[PROOFSTEP]
rw [← dual_dual (balanceR l x r), dual_balanceR,
  balanceL_eq_balance' hr.dual hl.dual sr.dual sl.dual (balance_sz_dual H), ← dual_balance', dual_dual]
[GOAL]
α : Type u_1
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ size (balanceR l x r) = size l + size r + 1
[PROOFSTEP]
rw [balanceR_eq_balance' hl hr sl sr H, size_balance' sl sr]
[GOAL]
α : Type u_1
P : α → Prop
l : Ordnode α
x : α
r : Ordnode α
hl : Balanced l
hr : Balanced r
sl : Sized l
sr : Sized r
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ All P (balanceR l x r) ↔ All P l ∧ P x ∧ All P r
[PROOFSTEP]
rw [balanceR_eq_balance' hl hr sl sr H, all_balance']
[GOAL]
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
h : Bounded nil o₁ o₂
⊢ Bounded (Ordnode.dual nil) o₂ o₁
[PROOFSTEP]
cases o₁
[GOAL]
case none
α : Type u_1
inst✝ : Preorder α
o₂ : WithTop α
h : Bounded nil none o₂
⊢ Bounded (Ordnode.dual nil) o₂ none
[PROOFSTEP]
cases o₂
[GOAL]
case some
α : Type u_1
inst✝ : Preorder α
o₂ : WithTop α
val✝ : α
h : Bounded nil (some val✝) o₂
⊢ Bounded (Ordnode.dual nil) o₂ (some val✝)
[PROOFSTEP]
cases o₂
[GOAL]
case none.none
α : Type u_1
inst✝ : Preorder α
h : Bounded nil none none
⊢ Bounded (Ordnode.dual nil) none none
[PROOFSTEP]
trivial
[GOAL]
case none.some
α : Type u_1
inst✝ : Preorder α
val✝ : α
h : Bounded nil none (some val✝)
⊢ Bounded (Ordnode.dual nil) (some val✝) none
[PROOFSTEP]
trivial
[GOAL]
case some.none
α : Type u_1
inst✝ : Preorder α
val✝ : α
h : Bounded nil (some val✝) none
⊢ Bounded (Ordnode.dual nil) none (some val✝)
[PROOFSTEP]
trivial
[GOAL]
case some.some
α : Type u_1
inst✝ : Preorder α
val✝¹ val✝ : α
h : Bounded nil (some val✝¹) (some val✝)
⊢ Bounded (Ordnode.dual nil) (some val✝) (some val✝¹)
[PROOFSTEP]
trivial
[GOAL]
α : Type u_1
inst✝ : Preorder α
t : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Bounded (Ordnode.dual t) o₂ o₁
⊢ Bounded t o₁ o₂
[PROOFSTEP]
have := Bounded.dual h
[GOAL]
α : Type u_1
inst✝ : Preorder α
t : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Bounded (Ordnode.dual t) o₂ o₁
this : Bounded (Ordnode.dual (Ordnode.dual t)) o₁ o₂
⊢ Bounded t o₁ o₂
[PROOFSTEP]
rwa [dual_dual, OrderDual.Preorder.dual_dual] at this
[GOAL]
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
h : Bounded nil o₁ o₂
⊢ Bounded nil ⊥ o₂
[PROOFSTEP]
cases o₂
[GOAL]
case none
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
h : Bounded nil o₁ none
⊢ Bounded nil ⊥ none
[PROOFSTEP]
trivial
[GOAL]
case some
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
val✝ : α
h : Bounded nil o₁ (some val✝)
⊢ Bounded nil ⊥ (some val✝)
[PROOFSTEP]
trivial
[GOAL]
α : Type u_1
inst✝ : Preorder α
o₁ : WithBot α
o₂ : WithTop α
h : Bounded nil o₁ o₂
⊢ Bounded nil o₁ ⊤
[PROOFSTEP]
cases o₁
[GOAL]
case none
α : Type u_1
inst✝ : Preorder α
o₂ : WithTop α
h : Bounded nil none o₂
⊢ Bounded nil none ⊤
[PROOFSTEP]
trivial
[GOAL]
case some
α : Type u_1
inst✝ : Preorder α
o₂ : WithTop α
val✝ : α
h : Bounded nil (some val✝) o₂
⊢ Bounded nil (some val✝) ⊤
[PROOFSTEP]
trivial
[GOAL]
α : Type u_1
inst✝ : Preorder α
t₁ t₂ : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
x : α
h₁ : Bounded t₁ o₁ ↑x
h₂ : Bounded t₂ (↑x) o₂
⊢ All (fun y => All (fun z => y < z) t₂) t₁
[PROOFSTEP]
refine h₁.mem_lt.imp fun y yx => ?_
[GOAL]
α : Type u_1
inst✝ : Preorder α
t₁ t₂ : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
x : α
h₁ : Bounded t₁ o₁ ↑x
h₂ : Bounded t₂ (↑x) o₂
y : α
yx : y < x
⊢ All (fun z => y < z) t₂
[PROOFSTEP]
exact h₂.mem_gt.imp fun z xz => lt_trans yx xz
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
ol : Bounded l o₁ ↑x
Or : Bounded r (↑x) o₂
sl : Sized l
sr : Sized r
b : BalancedSz (size l) (size r)
bl : Balanced l
br : Balanced r
ol' : Bounded (Ordnode.dual l) (↑x) o₁
sl' : Sized (Ordnode.dual l)
bl' : Balanced (Ordnode.dual l)
or' : Bounded (Ordnode.dual r) o₂ ↑x
sr' : Sized (Ordnode.dual r)
br' : Balanced (Ordnode.dual r)
⊢ size l + size r + 1 = size (Ordnode.dual r) + size (Ordnode.dual l) + 1
[PROOFSTEP]
simp [size_dual, add_comm]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
ol : Bounded l o₁ ↑x
Or : Bounded r (↑x) o₂
sl : Sized l
sr : Sized r
b : BalancedSz (size l) (size r)
bl : Balanced l
br : Balanced r
ol' : Bounded (Ordnode.dual l) (↑x) o₁
sl' : Sized (Ordnode.dual l)
bl' : Balanced (Ordnode.dual l)
or' : Bounded (Ordnode.dual r) o₂ ↑x
sr' : Sized (Ordnode.dual r)
br' : Balanced (Ordnode.dual r)
⊢ BalancedSz (size (Ordnode.dual r)) (size (Ordnode.dual l))
[PROOFSTEP]
rw [size_dual, size_dual]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
ol : Bounded l o₁ ↑x
Or : Bounded r (↑x) o₂
sl : Sized l
sr : Sized r
b : BalancedSz (size l) (size r)
bl : Balanced l
br : Balanced r
ol' : Bounded (Ordnode.dual l) (↑x) o₁
sl' : Sized (Ordnode.dual l)
bl' : Balanced (Ordnode.dual l)
or' : Bounded (Ordnode.dual r) o₂ ↑x
sr' : Sized (Ordnode.dual r)
br' : Balanced (Ordnode.dual r)
⊢ BalancedSz (size r) (size l)
[PROOFSTEP]
exact b.symm
[GOAL]
α : Type u_1
inst✝ : Preorder α
t : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₂ (Ordnode.dual t) o₁
⊢ Valid' o₁ t o₂
[PROOFSTEP]
have := Valid'.dual h
[GOAL]
α : Type u_1
inst✝ : Preorder α
t : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₂ (Ordnode.dual t) o₁
this : Valid' o₁ (Ordnode.dual (Ordnode.dual t)) o₂
⊢ Valid' o₁ t o₂
[PROOFSTEP]
rwa [dual_dual, OrderDual.Preorder.dual_dual] at this
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c d : ℕ
lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9
mr₂ : b + c + 1 ≤ 3 * d
mm₁ : b ≤ 3 * c
⊢ b < 3 * a + 1
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
b c d : ℕ
mr₂ : b + c + 1 ≤ 3 * d
⊢ c ≤ 3 * d
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
b c d : ℕ
mr₁ : 2 * d ≤ b + c + 1
mm₁ : b ≤ 3 * c
⊢ d ≤ 3 * c
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c d : ℕ
lr₁ : 3 * a ≤ b + c + 1 + d
mr₂ : b + c + 1 ≤ 3 * d
mm₁ : b ≤ 3 * c
⊢ a + b + 1 ≤ 3 * (c + d + 1)
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c d : ℕ
lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9
mr₁ : 2 * d ≤ b + c + 1
mm₂ : c ≤ 3 * b
⊢ c + d + 1 ≤ 3 * (a + b + 1)
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
m : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hm : Valid' (↑x) m ↑y
hr : Valid' (↑y) r o₂
Hm : 0 < size m
H :
  size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨
    0 < size l ∧
      ratio * size r ≤ size m ∧
        delta * size l ≤ size m + size r ∧ 3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r
⊢ Valid' o₁ (Ordnode.node4L l x m y r) o₂
[PROOFSTEP]
cases' m with s ml z mr
[GOAL]
case nil
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
hm : Valid' (↑x) nil ↑y
Hm : 0 < size nil
H :
  size l = 0 ∧ size nil = 1 ∧ size r ≤ 1 ∨
    0 < size l ∧
      ratio * size r ≤ size nil ∧
        delta * size l ≤ size nil + size r ∧ 3 * (size nil + size r) ≤ 16 * size l + 9 ∧ size nil ≤ delta * size r
⊢ Valid' o₁ (Ordnode.node4L l x nil y r) o₂
[PROOFSTEP]
cases Hm
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
H :
  size l = 0 ∧ size (Ordnode.node s ml z mr) = 1 ∧ size r ≤ 1 ∨
    0 < size l ∧
      ratio * size r ≤ size (Ordnode.node s ml z mr) ∧
        delta * size l ≤ size (Ordnode.node s ml z mr) + size r ∧
          3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9 ∧
            size (Ordnode.node s ml z mr) ≤ delta * size r
⊢ Valid' o₁ (Ordnode.node4L l x (Ordnode.node s ml z mr) y r) o₂
[PROOFSTEP]
suffices :
  BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
H :
  size l = 0 ∧ size (Ordnode.node s ml z mr) = 1 ∧ size r ≤ 1 ∨
    0 < size l ∧
      ratio * size r ≤ size (Ordnode.node s ml z mr) ∧
        delta * size l ≤ size (Ordnode.node s ml z mr) + size r ∧
          3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9 ∧
            size (Ordnode.node s ml z mr) ≤ delta * size r
this :
  BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
⊢ Valid' o₁ (Ordnode.node4L l x (Ordnode.node s ml z mr) y r) o₂
case this
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
H :
  size l = 0 ∧ size (Ordnode.node s ml z mr) = 1 ∧ size r ≤ 1 ∨
    0 < size l ∧
      ratio * size r ≤ size (Ordnode.node s ml z mr) ∧
        delta * size l ≤ size (Ordnode.node s ml z mr) + size r ∧
          3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9 ∧
            size (Ordnode.node s ml z mr) ≤ delta * size r
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
exact Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2
[GOAL]
case this
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
H :
  size l = 0 ∧ size (Ordnode.node s ml z mr) = 1 ∧ size r ≤ 1 ∨
    0 < size l ∧
      ratio * size r ≤ size (Ordnode.node s ml z mr) ∧
        delta * size l ≤ size (Ordnode.node s ml z mr) + size r ∧
          3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9 ∧
            size (Ordnode.node s ml z mr) ≤ delta * size r
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩)
[GOAL]
case this.inl.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size (Ordnode.node s ml z mr) = 1
r0 : size r ≤ 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [hm.2.size_eq, Nat.succ_inj', add_eq_zero_iff] at m1
[GOAL]
case this.inl.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
r0 : size r ≤ 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [l0, m1.1, m1.2]
[GOAL]
case this.inl.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
r0 : size r ≤ 1
⊢ BalancedSz 0 0 ∧ BalancedSz 0 (size r) ∧ BalancedSz (0 + 0 + 1) (0 + size r + 1)
[PROOFSTEP]
revert r0
[GOAL]
case this.inl.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
⊢ size r ≤ 1 → BalancedSz 0 0 ∧ BalancedSz 0 (size r) ∧ BalancedSz (0 + 0 + 1) (0 + size r + 1)
[PROOFSTEP]
rcases size r with (_ | _ | _) <;> [decide; decide; (intro r0; unfold BalancedSz delta; linarith)]
[GOAL]
case this.inl.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
⊢ size r ≤ 1 → BalancedSz 0 0 ∧ BalancedSz 0 (size r) ∧ BalancedSz (0 + 0 + 1) (0 + size r + 1)
[PROOFSTEP]
rcases size r with (_ | _ | _)
[GOAL]
case this.inl.intro.intro.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
⊢ Nat.zero ≤ 1 → BalancedSz 0 0 ∧ BalancedSz 0 Nat.zero ∧ BalancedSz (0 + 0 + 1) (0 + Nat.zero + 1)
[PROOFSTEP]
decide
[GOAL]
case this.inl.intro.intro.succ.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
⊢ Nat.succ Nat.zero ≤ 1 →
    BalancedSz 0 0 ∧ BalancedSz 0 (Nat.succ Nat.zero) ∧ BalancedSz (0 + 0 + 1) (0 + Nat.succ Nat.zero + 1)
[PROOFSTEP]
decide
[GOAL]
case this.inl.intro.intro.succ.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
n✝ : ℕ
⊢ Nat.succ (Nat.succ n✝) ≤ 1 →
    BalancedSz 0 0 ∧ BalancedSz 0 (Nat.succ (Nat.succ n✝)) ∧ BalancedSz (0 + 0 + 1) (0 + Nat.succ (Nat.succ n✝) + 1)
[PROOFSTEP]
intro r0
[GOAL]
case this.inl.intro.intro.succ.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
n✝ : ℕ
r0 : Nat.succ (Nat.succ n✝) ≤ 1
⊢ BalancedSz 0 0 ∧ BalancedSz 0 (Nat.succ (Nat.succ n✝)) ∧ BalancedSz (0 + 0 + 1) (0 + Nat.succ (Nat.succ n✝) + 1)
[PROOFSTEP]
unfold BalancedSz delta
[GOAL]
case this.inl.intro.intro.succ.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : size l = 0
m1 : size ml = 0 ∧ size mr = 0
n✝ : ℕ
r0 : Nat.succ (Nat.succ n✝) ≤ 1
⊢ (0 + 0 ≤ 1 ∨ 0 ≤ 3 * 0 ∧ 0 ≤ 3 * 0) ∧
    (0 + Nat.succ (Nat.succ n✝) ≤ 1 ∨ 0 ≤ 3 * Nat.succ (Nat.succ n✝) ∧ Nat.succ (Nat.succ n✝) ≤ 3 * 0) ∧
      (0 + 0 + 1 + (0 + Nat.succ (Nat.succ n✝) + 1) ≤ 1 ∨
        0 + 0 + 1 ≤ 3 * (0 + Nat.succ (Nat.succ n✝) + 1) ∧ 0 + Nat.succ (Nat.succ n✝) + 1 ≤ 3 * (0 + 0 + 1))
[PROOFSTEP]
linarith
[GOAL]
case this.inr.intro.intro.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size (Ordnode.node s ml z mr)
lr₁ : delta * size l ≤ size (Ordnode.node s ml z mr) + size r
lr₂ : 3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9
mr₂ : size (Ordnode.node s ml z mr) ≤ delta * size r
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size r) with r0 r0
[GOAL]
case this.inr.intro.intro.intro.intro.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size (Ordnode.node s ml z mr)
lr₁ : delta * size l ≤ size (Ordnode.node s ml z mr) + size r
lr₂ : 3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9
mr₂ : size (Ordnode.node s ml z mr) ≤ delta * size r
r0 : size r = 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [r0] at mr₂
[GOAL]
case this.inr.intro.intro.intro.intro.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size (Ordnode.node s ml z mr)
lr₁ : delta * size l ≤ size (Ordnode.node s ml z mr) + size r
lr₂ : 3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9
mr₂ : size (Ordnode.node s ml z mr) ≤ delta * 0
r0 : size r = 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
cases not_le_of_lt Hm mr₂
[GOAL]
case this.inr.intro.intro.intro.intro.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size (Ordnode.node s ml z mr)
lr₁ : delta * size l ≤ size (Ordnode.node s ml z mr) + size r
lr₂ : 3 * (size (Ordnode.node s ml z mr) + size r) ≤ 16 * size l + 9
mr₂ : size (Ordnode.node s ml z mr) ≤ delta * size r
r0 : size r > 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂
[GOAL]
case this.inr.intro.intro.intro.intro.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
by_cases mm : size ml + size mr ≤ 1
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
have r1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
⊢ 0 < ratio
[PROOFSTEP]
decide
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
r1 : size r = 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [r1, add_assoc] at lr₁
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
r1 : size r = 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
have l1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1)) l0
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
r1 : size r = 1
⊢ 0 < delta
[PROOFSTEP]
decide
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
r1 : size r = 1
l1 : size l = 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [l1, r1]
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : size ml + size mr ≤ 1
r1 : size r = 1
l1 : size l = 1
⊢ BalancedSz 1 (size ml) ∧ BalancedSz (size mr) 1 ∧ BalancedSz (1 + size ml + 1) (size mr + 1 + 1)
[PROOFSTEP]
revert mm
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
⊢ size ml + size mr ≤ 1 →
    BalancedSz 1 (size ml) ∧ BalancedSz (size mr) 1 ∧ BalancedSz (1 + size ml + 1) (size mr + 1 + 1)
[PROOFSTEP]
cases size ml
[GOAL]
case pos.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
⊢ Nat.zero + size mr ≤ 1 →
    BalancedSz 1 Nat.zero ∧ BalancedSz (size mr) 1 ∧ BalancedSz (1 + Nat.zero + 1) (size mr + 1 + 1)
[PROOFSTEP]
cases size mr
[GOAL]
case pos.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝ : ℕ
⊢ Nat.succ n✝ + size mr ≤ 1 →
    BalancedSz 1 (Nat.succ n✝) ∧ BalancedSz (size mr) 1 ∧ BalancedSz (1 + Nat.succ n✝ + 1) (size mr + 1 + 1)
[PROOFSTEP]
cases size mr
[GOAL]
case pos.zero.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
⊢ Nat.zero + Nat.zero ≤ 1 →
    BalancedSz 1 Nat.zero ∧ BalancedSz Nat.zero 1 ∧ BalancedSz (1 + Nat.zero + 1) (Nat.zero + 1 + 1)
[PROOFSTEP]
intro mm
[GOAL]
case pos.zero.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝ : ℕ
⊢ Nat.zero + Nat.succ n✝ ≤ 1 →
    BalancedSz 1 Nat.zero ∧ BalancedSz (Nat.succ n✝) 1 ∧ BalancedSz (1 + Nat.zero + 1) (Nat.succ n✝ + 1 + 1)
[PROOFSTEP]
intro mm
[GOAL]
case pos.succ.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝ : ℕ
⊢ Nat.succ n✝ + Nat.zero ≤ 1 →
    BalancedSz 1 (Nat.succ n✝) ∧ BalancedSz Nat.zero 1 ∧ BalancedSz (1 + Nat.succ n✝ + 1) (Nat.zero + 1 + 1)
[PROOFSTEP]
intro mm
[GOAL]
case pos.succ.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝¹ n✝ : ℕ
⊢ Nat.succ n✝¹ + Nat.succ n✝ ≤ 1 →
    BalancedSz 1 (Nat.succ n✝¹) ∧ BalancedSz (Nat.succ n✝) 1 ∧ BalancedSz (1 + Nat.succ n✝¹ + 1) (Nat.succ n✝ + 1 + 1)
[PROOFSTEP]
intro mm
[GOAL]
case pos.zero.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
mm : Nat.zero + Nat.zero ≤ 1
⊢ BalancedSz 1 Nat.zero ∧ BalancedSz Nat.zero 1 ∧ BalancedSz (1 + Nat.zero + 1) (Nat.zero + 1 + 1)
[PROOFSTEP]
decide
[GOAL]
case pos.zero.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝ : ℕ
mm : Nat.zero + Nat.succ n✝ ≤ 1
⊢ BalancedSz 1 Nat.zero ∧ BalancedSz (Nat.succ n✝) 1 ∧ BalancedSz (1 + Nat.zero + 1) (Nat.succ n✝ + 1 + 1)
[PROOFSTEP]
rw [Nat.zero_eq, zero_add] at mm
[GOAL]
case pos.zero.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝ : ℕ
mm : Nat.succ n✝ ≤ 1
⊢ BalancedSz 1 Nat.zero ∧ BalancedSz (Nat.succ n✝) 1 ∧ BalancedSz (1 + Nat.zero + 1) (Nat.succ n✝ + 1 + 1)
[PROOFSTEP]
rcases mm with (_ | ⟨⟨⟩⟩)
[GOAL]
case pos.zero.succ.refl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
⊢ BalancedSz 1 Nat.zero ∧ BalancedSz (Nat.succ 0) 1 ∧ BalancedSz (1 + Nat.zero + 1) (Nat.succ 0 + 1 + 1)
[PROOFSTEP]
decide
[GOAL]
case pos.succ.zero
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝ : ℕ
mm : Nat.succ n✝ + Nat.zero ≤ 1
⊢ BalancedSz 1 (Nat.succ n✝) ∧ BalancedSz Nat.zero 1 ∧ BalancedSz (1 + Nat.succ n✝ + 1) (Nat.zero + 1 + 1)
[PROOFSTEP]
rcases mm with (_ | ⟨⟨⟩⟩)
[GOAL]
case pos.succ.zero.refl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
⊢ BalancedSz 1 (Nat.succ 0) ∧ BalancedSz Nat.zero 1 ∧ BalancedSz (1 + Nat.succ 0 + 1) (Nat.zero + 1 + 1)
[PROOFSTEP]
decide
[GOAL]
case pos.succ.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝¹ n✝ : ℕ
mm : Nat.succ n✝¹ + Nat.succ n✝ ≤ 1
⊢ BalancedSz 1 (Nat.succ n✝¹) ∧ BalancedSz (Nat.succ n✝) 1 ∧ BalancedSz (1 + Nat.succ n✝¹ + 1) (Nat.succ n✝ + 1 + 1)
[PROOFSTEP]
rw [Nat.succ_add] at mm
[GOAL]
case pos.succ.succ
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + (1 + 1)
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
r1 : size r = 1
l1 : size l = 1
n✝¹ n✝ : ℕ
mm : Nat.succ (n✝¹ + Nat.succ n✝) ≤ 1
⊢ BalancedSz 1 (Nat.succ n✝¹) ∧ BalancedSz (Nat.succ n✝) 1 ∧ BalancedSz (1 + Nat.succ n✝¹ + 1) (Nat.succ n✝ + 1 + 1)
[PROOFSTEP]
rcases mm with (_ | ⟨⟨⟩⟩)
[GOAL]
case neg
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩
[GOAL]
case neg.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size ml) with ml0 ml0
[GOAL]
case neg.intro.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml = 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [ml0, mul_zero, le_zero_iff] at mm₂
[GOAL]
case neg.intro.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr = 0
ml0 : size ml = 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
rw [ml0, mm₂] at mm
[GOAL]
case neg.intro.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬0 + 0 ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr = 0
ml0 : size ml = 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
cases mm (by decide)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬0 + 0 ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr = 0
ml0 : size ml = 0
⊢ 0 + 0 ≤ 1
[PROOFSTEP]
decide
[GOAL]
case neg.intro.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
have : 2 * size l ≤ size ml + size mr + 1 :=
  by
  have := Nat.mul_le_mul_left ratio lr₁
  rw [mul_left_comm, mul_add] at this
  have := le_trans this (add_le_add_left mr₁ _)
  rw [← Nat.succ_mul] at this
  exact (mul_le_mul_left (by decide)).1 this
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
⊢ 2 * size l ≤ size ml + size mr + 1
[PROOFSTEP]
have := Nat.mul_le_mul_left ratio lr₁
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : ratio * (delta * size l) ≤ ratio * (size ml + size mr + 1 + size r)
⊢ 2 * size l ≤ size ml + size mr + 1
[PROOFSTEP]
rw [mul_left_comm, mul_add] at this
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : delta * (ratio * size l) ≤ ratio * (size ml + size mr + 1) + ratio * size r
⊢ 2 * size l ≤ size ml + size mr + 1
[PROOFSTEP]
have := le_trans this (add_le_add_left mr₁ _)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this✝ : delta * (ratio * size l) ≤ ratio * (size ml + size mr + 1) + ratio * size r
this : delta * (ratio * size l) ≤ ratio * (size ml + size mr + 1) + (size ml + size mr + 1)
⊢ 2 * size l ≤ size ml + size mr + 1
[PROOFSTEP]
rw [← Nat.succ_mul] at this
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this✝ : delta * (ratio * size l) ≤ ratio * (size ml + size mr + 1) + ratio * size r
this : delta * (ratio * size l) ≤ Nat.succ ratio * (size ml + size mr + 1)
⊢ 2 * size l ≤ size ml + size mr + 1
[PROOFSTEP]
exact (mul_le_mul_left (by decide)).1 this
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this✝ : delta * (ratio * size l) ≤ ratio * (size ml + size mr + 1) + ratio * size r
this : delta * (ratio * size l) ≤ Nat.succ ratio * (size ml + size mr + 1)
⊢ 0 < delta
[PROOFSTEP]
decide
[GOAL]
case neg.intro.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ BalancedSz (size l) (size ml) ∧
    BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1)
[PROOFSTEP]
refine' ⟨Or.inr ⟨_, _⟩, Or.inr ⟨_, _⟩, Or.inr ⟨_, _⟩⟩
[GOAL]
case neg.intro.inr.refine'_1
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size l ≤ delta * size ml
[PROOFSTEP]
refine' (mul_le_mul_left (by decide)).1 (le_trans this _)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ 0 < 2
[PROOFSTEP]
decide
[GOAL]
case neg.intro.inr.refine'_1
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size ml + size mr + 1 ≤ 2 * (delta * size ml)
[PROOFSTEP]
rw [two_mul, Nat.succ_le_iff]
[GOAL]
case neg.intro.inr.refine'_1
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size ml + size mr < delta * size ml + delta * size ml
[PROOFSTEP]
refine' add_lt_add_of_lt_of_le _ mm₂
[GOAL]
case neg.intro.inr.refine'_1
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size ml < delta * size ml
[PROOFSTEP]
simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ 1 < 3
[PROOFSTEP]
decide
[GOAL]
case neg.intro.inr.refine'_2
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size ml ≤ delta * size l
[PROOFSTEP]
exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁)
[GOAL]
case neg.intro.inr.refine'_3
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size mr ≤ delta * size r
[PROOFSTEP]
exact Valid'.node4L_lemma₂ mr₂
[GOAL]
case neg.intro.inr.refine'_4
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size r ≤ delta * size mr
[PROOFSTEP]
exact Valid'.node4L_lemma₃ mr₁ mm₁
[GOAL]
case neg.intro.inr.refine'_5
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size l + size ml + 1 ≤ delta * (size mr + size r + 1)
[PROOFSTEP]
exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁
[GOAL]
case neg.intro.inr.refine'_6
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑y) r o₂
s : ℕ
ml : Ordnode α
z : α
mr : Ordnode α
hm : Valid' (↑x) (Ordnode.node s ml z mr) ↑y
Hm : 0 < size (Ordnode.node s ml z mr)
l0 : 0 < size l
mr₁ : ratio * size r ≤ size ml + size mr + 1
lr₁ : delta * size l ≤ size ml + size mr + 1 + size r
lr₂ : 3 * (size ml + size mr + 1 + size r) ≤ 16 * size l + 9
mr₂ : size ml + size mr + 1 ≤ delta * size r
r0 : size r > 0
mm : ¬size ml + size mr ≤ 1
mm₁ : size ml ≤ delta * size mr
mm₂ : size mr ≤ delta * size ml
ml0 : size ml > 0
this : 2 * size l ≤ size ml + size mr + 1
⊢ size mr + size r + 1 ≤ delta * (size l + size ml + 1)
[PROOFSTEP]
exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c : ℕ
H2 : 3 * a ≤ b + c
hb₂ : c ≤ 3 * b
⊢ a ≤ 3 * b
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c : ℕ
H3 : 2 * (b + c) ≤ 9 * a + 3
h : b < 2 * c
⊢ b < 3 * a + 1
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c : ℕ
H2 : 3 * a ≤ b + c
h : b < 2 * c
⊢ a + b < 3 * c
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b : ℕ
H3 : 2 * b ≤ 9 * a + 3
⊢ 3 * b ≤ 16 * a + 9
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size l < size r
H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
⊢ Valid' o₁ (Ordnode.rotateL l x r) o₂
[PROOFSTEP]
cases' r with rs rl rx rr
[GOAL]
case nil
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) nil o₂
H1 : ¬size l + size nil ≤ 1
H2 : delta * size l < size nil
H3 : 2 * size nil ≤ 9 * size l + 5 ∨ size nil ≤ 3
⊢ Valid' o₁ (Ordnode.rotateL l x nil) o₂
[PROOFSTEP]
cases H2
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l < size (Ordnode.node rs rl rx rr)
H3 : 2 * size (Ordnode.node rs rl rx rr) ≤ 9 * size l + 5 ∨ size (Ordnode.node rs rl rx rr) ≤ 3
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
rw [hr.2.size_eq, Nat.lt_succ_iff] at H2
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * size (Ordnode.node rs rl rx rr) ≤ 9 * size l + 5 ∨ size (Ordnode.node rs rl rx rr) ≤ 3
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
rw [hr.2.size_eq] at H3
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr + 1) ≤ 9 * size l + 5 ∨ size rl + size rr + 1 ≤ 3
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 :=
  H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by
  intro l0; rw [l0] at H3
  exact (or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
⊢ size l = 0 → size rl + size rr ≤ 2
[PROOFSTEP]
intro l0
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
l0 : size l = 0
⊢ size rl + size rr ≤ 2
[PROOFSTEP]
rw [l0] at H3
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * 0 + 3 ∨ size rl + size rr ≤ 2
l0 : size l = 0
⊢ size rl + size rr ≤ 2
[PROOFSTEP]
exact (or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * 0 + 3 ∨ size rl + size rr ≤ 2
l0 : size l = 0
h : 2 * (size rl + size rr) ≤ 9 * 0 + 3
⊢ 0 < 2
[PROOFSTEP]
decide
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * 0 + 3 ∨ size rl + size rr ≤ 2
l0 : size l = 0
h : 2 * (size rl + size rr) ≤ 9 * 0 + 3
⊢ 9 * 0 + 3 ≤ 2 * 2
[PROOFSTEP]
decide
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l =>
  (or_iff_left_of_imp <| by intro; linarith).1 H3
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
l0 : 1 ≤ size l
⊢ size rl + size rr ≤ 2 → 2 * (size rl + size rr) ≤ 9 * size l + 3
[PROOFSTEP]
intro
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
l0 : 1 ≤ size l
a✝ : size rl + size rr ≤ 2
⊢ 2 * (size rl + size rr) ≤ 9 * size l + 3
[PROOFSTEP]
linarith
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by intros; linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
⊢ ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
[PROOFSTEP]
intros
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
a✝² b✝ : ℕ
a✝¹ : 1 ≤ a✝²
a✝ : a✝² + b✝ ≤ 2
⊢ b✝ ≤ 1
[PROOFSTEP]
linarith
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb =>
  absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
l0 : size l > 0
hb : size rl + size rr ≤ 1
⊢ ¬delta * Nat.succ 0 ≤ 1
[PROOFSTEP]
decide
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
⊢ Valid' o₁ (Ordnode.rotateL l x (Ordnode.node rs rl rx rr)) o₂
[PROOFSTEP]
rw [rotateL]
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
⊢ Valid' o₁ (if size rl < ratio * size rr then Ordnode.node3L l x rl rx rr else Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
split_ifs with h
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
⊢ Valid' o₁ (Ordnode.node3L l x rl rx rr) o₂
[PROOFSTEP]
have rr0 : size rr > 0 := (mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
⊢ 0 < ratio
[PROOFSTEP]
decide
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
⊢ Valid' o₁ (Ordnode.node3L l x rl rx rr) o₂
[PROOFSTEP]
suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by
  exact hl.node3L hr.left hr.right this.1 this.2
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
this : BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr)
⊢ Valid' o₁ (Ordnode.node3L l x rl rx rr) o₂
[PROOFSTEP]
exact hl.node3L hr.left hr.right this.1 this.2
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
⊢ BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr)
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size l) with l0 l0
[GOAL]
case pos.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
⊢ BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr)
[PROOFSTEP]
rw [l0]
[GOAL]
case pos.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
replace H3 := H3_0 l0
[GOAL]
case pos.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
have := hr.3.1
[GOAL]
case pos.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
this : BalancedSz (size rl) (size rr)
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size rl) with rl0 rl0
[GOAL]
case pos.inl.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
this : BalancedSz (size rl) (size rr)
rl0 : size rl = 0
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
rw [rl0] at this ⊢
[GOAL]
case pos.inl.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
this : BalancedSz 0 (size rr)
rl0 : size rl = 0
⊢ BalancedSz 0 0 ∧ BalancedSz (0 + 0 + 1) (size rr)
[PROOFSTEP]
rw [le_antisymm (balancedSz_zero.1 this.symm) rr0]
[GOAL]
case pos.inl.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
this : BalancedSz 0 (size rr)
rl0 : size rl = 0
⊢ BalancedSz 0 0 ∧ BalancedSz (0 + 0 + 1) 1
[PROOFSTEP]
decide
[GOAL]
case pos.inl.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
this : BalancedSz (size rl) (size rr)
rl0 : size rl > 0
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0
[GOAL]
case pos.inl.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
this : BalancedSz (size rl) (size rr)
rl0 : size rl > 0
rr1 : size rr = 1
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
rw [add_comm] at H3
[GOAL]
case pos.inl.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rr + size rl ≤ 2
this : BalancedSz (size rl) (size rr)
rl0 : size rl > 0
rr1 : size rr = 1
⊢ BalancedSz 0 (size rl) ∧ BalancedSz (0 + size rl + 1) (size rr)
[PROOFSTEP]
rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0]
[GOAL]
case pos.inl.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l = 0
H3 : size rr + size rl ≤ 2
this : BalancedSz (size rl) (size rr)
rl0 : size rl > 0
rr1 : size rr = 1
⊢ BalancedSz 0 1 ∧ BalancedSz (0 + 1 + 1) 1
[PROOFSTEP]
decide
[GOAL]
case pos.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
⊢ BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr)
[PROOFSTEP]
replace H3 := H3p l0
[GOAL]
case pos.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3
⊢ BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr)
[PROOFSTEP]
rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩
[GOAL]
case pos.inr.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3
left✝ : size rl ≤ delta * size rr
hb₂ : size rr ≤ delta * size rl
⊢ BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr)
[PROOFSTEP]
refine' ⟨Or.inr ⟨_, _⟩, Or.inr ⟨_, _⟩⟩
[GOAL]
case pos.inr.intro.refine'_1
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3
left✝ : size rl ≤ delta * size rr
hb₂ : size rr ≤ delta * size rl
⊢ size l ≤ delta * size rl
[PROOFSTEP]
exact Valid'.rotateL_lemma₁ H2 hb₂
[GOAL]
case pos.inr.intro.refine'_2
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3
left✝ : size rl ≤ delta * size rr
hb₂ : size rr ≤ delta * size rl
⊢ size rl ≤ delta * size l
[PROOFSTEP]
exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h)
[GOAL]
case pos.inr.intro.refine'_3
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3
left✝ : size rl ≤ delta * size rr
hb₂ : size rr ≤ delta * size rl
⊢ size l + size rl + 1 ≤ delta * size rr
[PROOFSTEP]
exact Valid'.rotateL_lemma₃ H2 h
[GOAL]
case pos.inr.intro.refine'_4
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : size rl < ratio * size rr
rr0 : size rr > 0
l0 : size l > 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3
left✝ : size rl ≤ delta * size rr
hb₂ : size rr ≤ delta * size rl
⊢ size rr ≤ delta * (size l + size rl + 1)
[PROOFSTEP]
exact le_trans hb₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _))
[GOAL]
case neg
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size rl) with rl0 rl0
[GOAL]
case neg.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl = 0
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
rw [rl0, not_lt, le_zero_iff, Nat.mul_eq_zero] at h
[GOAL]
case neg.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ratio = 0 ∨ size rr = 0
rl0 : size rl = 0
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
replace h := h.resolve_left (by decide)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ratio = 0 ∨ size rr = 0
rl0 : size rl = 0
⊢ ¬ratio = 0
[PROOFSTEP]
decide
[GOAL]
case neg.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
rl0 : size rl = 0
h : size rr = 0
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
erw [rl0, h, le_zero_iff, Nat.mul_eq_zero] at H2
[GOAL]
case neg.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta = 0 ∨ size l = 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
rl0 : size rl = 0
h : size rr = 0
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + (0 + 0 + 1) ≤ 1
H2 : delta = 0 ∨ size l = 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
rl0 : size rl = 0
h : size rr = 0
⊢ ¬delta = 0
[PROOFSTEP]
decide
[GOAL]
case neg.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬0 + (0 + 0 + 1) ≤ 1
H2 : delta = 0 ∨ size l = 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
rl0 : size rl = 0
h : size rr = 0
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
cases H1 (by decide)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬0 + (0 + 0 + 1) ≤ 1
H2 : delta = 0 ∨ size l = 0
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
rl0 : size rl = 0
h : size rr = 0
⊢ 0 + (0 + 0 + 1) ≤ 1
[PROOFSTEP]
decide
[GOAL]
case neg.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
⊢ Valid' o₁ (Ordnode.node4L l x rl rx rr) o₂
[PROOFSTEP]
refine' hl.node4L hr.left hr.right rl0 _
[GOAL]
case neg.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size l) with l0 l0
[GOAL]
case neg.inr.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
replace H3 := H3_0 l0
[GOAL]
case neg.inr.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size rr) with rr0 rr0
[GOAL]
case neg.inr.inl.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
rr0 : size rr = 0
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
have := hr.3.1
[GOAL]
case neg.inr.inl.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
rr0 : size rr = 0
this : BalancedSz (size rl) (size rr)
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
rw [rr0] at this
[GOAL]
case neg.inr.inl.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
rr0 : size rr = 0
this : BalancedSz (size rl) 0
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩
[GOAL]
case neg.inr.inl.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
rr0 : size rr > 0
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l = 0
H3 : size rl + size rr ≤ 2
rr0 : size rr > 0
⊢ size rr + size rl ≤ 2
[PROOFSTEP]
rwa [add_comm]
[GOAL]
case neg.inr.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
hr : Valid' (↑x) (Ordnode.node rs rl rx rr) o₂
H1 : ¬size l + size (Ordnode.node rs rl rx rr) ≤ 1
H2 : delta * size l ≤ size rl + size rr
H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2
H3_0 : size l = 0 → size rl + size rr ≤ 2
H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3
ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1
hlp : size l > 0 → ¬size rl + size rr ≤ 1
h : ¬size rl < ratio * size rr
rl0 : size rl > 0
l0 : size l > 0
⊢ size l = 0 ∧ size rl = 1 ∧ size rr ≤ 1 ∨
    0 < size l ∧
      ratio * size rr ≤ size rl ∧
        delta * size l ≤ size rl + size rr ∧ 3 * (size rl + size rr) ≤ 16 * size l + 9 ∧ size rl ≤ delta * size rr
[PROOFSTEP]
exact Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size r < size l
H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₁ (Ordnode.rotateR l x r) o₂
[PROOFSTEP]
refine' Valid'.dual_iff.2 _
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size r < size l
H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₂ (Ordnode.dual (Ordnode.rotateR l x r)) o₁
[PROOFSTEP]
rw [dual_rotateR]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size r < size l
H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₂ (Ordnode.rotateL (Ordnode.dual r) x (Ordnode.dual l)) o₁
[PROOFSTEP]
refine' hr.dual.rotateL hl.dual _ _ _
[GOAL]
case refine'_1
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size r < size l
H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ ¬size (Ordnode.dual r) + size (Ordnode.dual l) ≤ 1
[PROOFSTEP]
rwa [size_dual, size_dual, add_comm]
[GOAL]
case refine'_2
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size r < size l
H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ delta * size (Ordnode.dual r) < size (Ordnode.dual l)
[PROOFSTEP]
rwa [size_dual, size_dual]
[GOAL]
case refine'_3
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H1 : ¬size l + size r ≤ 1
H2 : delta * size r < size l
H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ 2 * size (Ordnode.dual l) ≤ 9 * size (Ordnode.dual r) + 5 ∨ size (Ordnode.dual l) ≤ 3
[PROOFSTEP]
rwa [size_dual, size_dual]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
H₂ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₁ (balance' l x r) o₂
[PROOFSTEP]
rw [balance']
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
H₂ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₁
    (if size l + size r ≤ 1 then Ordnode.node' l x r
    else
      if size r > delta * size l then Ordnode.rotateL l x r
      else if size l > delta * size r then Ordnode.rotateR l x r else Ordnode.node' l x r)
    o₂
[PROOFSTEP]
split_ifs with h h_1 h_2
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
H₂ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
h : size l + size r ≤ 1
⊢ Valid' o₁ (Ordnode.node' l x r) o₂
[PROOFSTEP]
exact hl.node' hr (Or.inl h)
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
H₂ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
h : ¬size l + size r ≤ 1
h_1 : size r > delta * size l
⊢ Valid' o₁ (Ordnode.rotateL l x r) o₂
[PROOFSTEP]
exact hl.rotateL hr h h_1 H₁
[GOAL]
case pos
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
H₂ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
h : ¬size l + size r ≤ 1
h_1 : ¬size r > delta * size l
h_2 : size l > delta * size r
⊢ Valid' o₁ (Ordnode.rotateR l x r) o₂
[PROOFSTEP]
exact hl.rotateR hr h h_2 H₂
[GOAL]
case neg
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
H₂ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
h : ¬size l + size r ≤ 1
h_1 : ¬size r > delta * size l
h_2 : ¬size l > delta * size r
⊢ Valid' o₁ (Ordnode.node' l x r) o₂
[PROOFSTEP]
exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩)
[GOAL]
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
⊢ 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
[PROOFSTEP]
suffices @size α r ≤ 3 * (size l + 1)
  by
  cases' Nat.eq_zero_or_pos (size l) with l0 l0
  · apply Or.inr; rwa [l0] at this
  change 1 ≤ _ at l0 ; apply Or.inl; linarith
[GOAL]
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
this : size r ≤ 3 * (size l + 1)
⊢ 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size l) with l0 l0
[GOAL]
case inl
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
this : size r ≤ 3 * (size l + 1)
l0 : size l = 0
⊢ 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
[PROOFSTEP]
apply Or.inr
[GOAL]
case inl.h
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
this : size r ≤ 3 * (size l + 1)
l0 : size l = 0
⊢ size r ≤ 3
[PROOFSTEP]
rwa [l0] at this
[GOAL]
case inr
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
this : size r ≤ 3 * (size l + 1)
l0 : size l > 0
⊢ 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
[PROOFSTEP]
change 1 ≤ _ at l0
[GOAL]
case inr
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
this : size r ≤ 3 * (size l + 1)
l0 : 1 ≤ size l
⊢ 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
[PROOFSTEP]
apply Or.inl
[GOAL]
case inr.h
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
this : size r ≤ 3 * (size l + 1)
l0 : 1 ≤ size l
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
linarith
[GOAL]
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
r' : ℕ
H1 : BalancedSz l' r'
H2 : Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l'
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩)
[GOAL]
case inl.intro
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
hl : Nat.dist (size l) l' ≤ 1
H1 : BalancedSz l' (size r)
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
rcases H1 with (h | ⟨_, h₂⟩)
[GOAL]
case inr.intro
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l r : Ordnode α
r' : ℕ
hr : Nat.dist (size r) r' ≤ 1
H1 : BalancedSz (size l) r'
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
rcases H1 with (h | ⟨_, h₂⟩)
[GOAL]
case inl.intro.inl
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
hl : Nat.dist (size l) l' ≤ 1
h : l' + size r ≤ 1
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _))
[GOAL]
case inl.intro.inr.intro
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l : Ordnode α
l' : ℕ
r : Ordnode α
hl : Nat.dist (size l) l' ≤ 1
left✝ : l' ≤ delta * size r
h₂ : size r ≤ delta * l'
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
exact le_trans h₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _))
[GOAL]
case inr.intro.inl
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l r : Ordnode α
r' : ℕ
hr : Nat.dist (size r) r' ≤ 1
h : size l + r' ≤ 1
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
exact le_trans (Nat.dist_tri_left' _ _) (le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by linarith))
[GOAL]
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l r : Ordnode α
r' : ℕ
hr : Nat.dist (size r) r' ≤ 1
h : size l + r' ≤ 1
⊢ 1 + 1 ≤ 3 * (size l + 1)
[PROOFSTEP]
linarith
[GOAL]
case inr.intro.inr.intro
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l r : Ordnode α
r' : ℕ
hr : Nat.dist (size r) r' ≤ 1
left✝ : size l ≤ delta * r'
h₂ : r' ≤ delta * size l
⊢ size r ≤ 3 * (size l + 1)
[PROOFSTEP]
rw [Nat.mul_succ]
[GOAL]
case inr.intro.inr.intro
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l r : Ordnode α
r' : ℕ
hr : Nat.dist (size r) r' ≤ 1
left✝ : size l ≤ delta * r'
h₂ : r' ≤ delta * size l
⊢ size r ≤ 3 * size l + 3
[PROOFSTEP]
exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide)))
[GOAL]
α✝ : Type u_1
inst✝ : Preorder α✝
α : Type u_2
l r : Ordnode α
r' : ℕ
hr : Nat.dist (size r) r' ≤ 1
left✝ : size l ≤ delta * r'
h₂ : r' ≤ delta * size l
⊢ 1 ≤ 3
[PROOFSTEP]
decide
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')
⊢ Valid' o₁ (Ordnode.balance l x r) o₂
[PROOFSTEP]
rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')
⊢ Valid' o₁ (Ordnode.balance' l x r) o₂
[PROOFSTEP]
exact hl.balance' hr H
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₁ (balanceL l x r) o₂
[PROOFSTEP]
rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ Valid' o₁ (Ordnode.balance' l x r) o₂
[PROOFSTEP]
refine' hl.balance'_aux hr (Or.inl _) H₃
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size r) with r0 r0
[GOAL]
case inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r = 0
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
rw [r0]
[GOAL]
case inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r = 0
⊢ 2 * 0 ≤ 9 * size l + 5
[PROOFSTEP]
exact Nat.zero_le _
[GOAL]
case inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r > 0
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
cases' Nat.eq_zero_or_pos (size l) with l0 l0
[GOAL]
case inr.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r > 0
l0 : size l = 0
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
rw [l0]
[GOAL]
case inr.inl
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r > 0
l0 : size l = 0
⊢ 2 * size r ≤ 9 * 0 + 5
[PROOFSTEP]
exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide)
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r > 0
l0 : size l = 0
⊢ 2 * 1 ≤ 9 * 0 + 5
[PROOFSTEP]
decide
[GOAL]
case inr.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r > 0
l0 : size l > 0
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
replace H₂ : _ ≤ 3 * _ := H₂ l0 r0
[GOAL]
case inr.inr
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size l = 0 → size r ≤ 1
H₃ : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3
r0 : size r > 0
l0 : size l > 0
H₂ : size r ≤ 3 * size l
⊢ 2 * size r ≤ 9 * size l + 5
[PROOFSTEP]
linarith
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ Valid' o₁ (Ordnode.balanceL l x r) o₂
[PROOFSTEP]
rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ Valid' o₁ (Ordnode.balance' l x r) o₂
[PROOFSTEP]
refine' hl.balance' hr _
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r'
⊢ ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')
[PROOFSTEP]
rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩)
[GOAL]
case inl.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
l' : ℕ
e : Raised l' (size l)
H : BalancedSz l' (size r)
⊢ ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')
[PROOFSTEP]
exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩
[GOAL]
case inr.intro.intro
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
r' : ℕ
e : Raised (size r) r'
H : BalancedSz (size l) r'
⊢ ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')
[PROOFSTEP]
exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size r = 0 → size l ≤ 1
H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r
H₃ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
⊢ Valid' o₁ (balanceR l x r) o₂
[PROOFSTEP]
rw [Valid'.dual_iff, dual_balanceR]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size r = 0 → size l ≤ 1
H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r
H₃ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
⊢ Valid' o₂ (Ordnode.balanceL (Ordnode.dual r) x (Ordnode.dual l)) o₁
[PROOFSTEP]
have := hr.dual.balanceL_aux hl.dual
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size r = 0 → size l ≤ 1
H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r
H₃ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
this :
  (size (Ordnode.dual r) = 0 → size (Ordnode.dual l) ≤ 1) →
    (1 ≤ size (Ordnode.dual r) → 1 ≤ size (Ordnode.dual l) → size (Ordnode.dual l) ≤ delta * size (Ordnode.dual r)) →
      2 * size (Ordnode.dual r) ≤ 9 * size (Ordnode.dual l) + 5 ∨ size (Ordnode.dual r) ≤ 3 →
        Valid' o₂ (Ordnode.balanceL (Ordnode.dual r) x (Ordnode.dual l)) o₁
⊢ Valid' o₂ (Ordnode.balanceL (Ordnode.dual r) x (Ordnode.dual l)) o₁
[PROOFSTEP]
rw [size_dual, size_dual] at this
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H₁ : size r = 0 → size l ≤ 1
H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r
H₃ : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3
this :
  (size r = 0 → size l ≤ 1) →
    (1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r) →
      2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3 → Valid' o₂ (Ordnode.balanceL (Ordnode.dual r) x (Ordnode.dual l)) o₁
⊢ Valid' o₂ (Ordnode.balanceL (Ordnode.dual r) x (Ordnode.dual l)) o₁
[PROOFSTEP]
exact this H₁ H₂ H₃
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ Valid' o₁ (Ordnode.balanceR l x r) o₂
[PROOFSTEP]
rw [Valid'.dual_iff, dual_balanceR]
[GOAL]
α : Type u_1
inst✝ : Preorder α
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ l ↑x
hr : Valid' (↑x) r o₂
H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r'
⊢ Valid' o₂ (Ordnode.balanceL (Ordnode.dual r) x (Ordnode.dual l)) o₁
[PROOFSTEP]
exact hr.dual.balanceL hl.dual (balance_sz_dual H)
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
H : Valid' o₁ (Ordnode.node s l x r) o₂
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x r)) ↑(findMax' x r) ∧
    size (Ordnode.node' l x r) = size (eraseMax (Ordnode.node' l x r)) + 1
[PROOFSTEP]
have := H.2.eq_node'
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
H : Valid' o₁ (Ordnode.node s l x r) o₂
this : Ordnode.node s l x r = Ordnode.node' l x r
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x r)) ↑(findMax' x r) ∧
    size (Ordnode.node' l x r) = size (eraseMax (Ordnode.node' l x r)) + 1
[PROOFSTEP]
rw [this] at H
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
H : Valid' o₁ (Ordnode.node' l x r) o₂
this : Ordnode.node s l x r = Ordnode.node' l x r
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x r)) ↑(findMax' x r) ∧
    size (Ordnode.node' l x r) = size (eraseMax (Ordnode.node' l x r)) + 1
[PROOFSTEP]
clear this
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
H : Valid' o₁ (Ordnode.node' l x r) o₂
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x r)) ↑(findMax' x r) ∧
    size (Ordnode.node' l x r) = size (eraseMax (Ordnode.node' l x r)) + 1
[PROOFSTEP]
induction' r with rs rl rx rr _ IHrr generalizing l x o₁
[GOAL]
case nil
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x nil) o₂
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x nil)) ↑(findMax' x nil) ∧
    size (Ordnode.node' l x nil) = size (eraseMax (Ordnode.node' l x nil)) + 1
[PROOFSTEP]
exact ⟨H.left, rfl⟩
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node rs rl rx rr)) o₂
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x (Ordnode.node rs rl rx rr))) ↑(findMax' x (Ordnode.node rs rl rx rr)) ∧
    size (Ordnode.node' l x (Ordnode.node rs rl rx rr)) =
      size (eraseMax (Ordnode.node' l x (Ordnode.node rs rl rx rr))) + 1
[PROOFSTEP]
have := H.2.2.2.eq_node'
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node rs rl rx rr)) o₂
this : Ordnode.node rs rl rx rr = Ordnode.node' rl rx rr
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x (Ordnode.node rs rl rx rr))) ↑(findMax' x (Ordnode.node rs rl rx rr)) ∧
    size (Ordnode.node' l x (Ordnode.node rs rl rx rr)) =
      size (eraseMax (Ordnode.node' l x (Ordnode.node rs rl rx rr))) + 1
[PROOFSTEP]
rw [this] at H ⊢
[GOAL]
case node
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node' rl rx rr)) o₂
this : Ordnode.node rs rl rx rr = Ordnode.node' rl rx rr
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x (Ordnode.node' rl rx rr))) ↑(findMax' x (Ordnode.node' rl rx rr)) ∧
    size (Ordnode.node' l x (Ordnode.node' rl rx rr)) = size (eraseMax (Ordnode.node' l x (Ordnode.node' rl rx rr))) + 1
[PROOFSTEP]
rcases IHrr H.right with ⟨h, e⟩
[GOAL]
case node.intro
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node' rl rx rr)) o₂
this : Ordnode.node rs rl rx rr = Ordnode.node' rl rx rr
h : Valid' (↑x) (eraseMax (Ordnode.node' rl rx rr)) ↑(findMax' rx rr)
e : size (Ordnode.node' rl rx rr) = size (eraseMax (Ordnode.node' rl rx rr)) + 1
⊢ Valid' o₁ (eraseMax (Ordnode.node' l x (Ordnode.node' rl rx rr))) ↑(findMax' x (Ordnode.node' rl rx rr)) ∧
    size (Ordnode.node' l x (Ordnode.node' rl rx rr)) = size (eraseMax (Ordnode.node' l x (Ordnode.node' rl rx rr))) + 1
[PROOFSTEP]
refine' ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), _⟩
[GOAL]
case node.intro
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node' rl rx rr)) o₂
this : Ordnode.node rs rl rx rr = Ordnode.node' rl rx rr
h : Valid' (↑x) (eraseMax (Ordnode.node' rl rx rr)) ↑(findMax' rx rr)
e : size (Ordnode.node' rl rx rr) = size (eraseMax (Ordnode.node' rl rx rr)) + 1
⊢ size (Ordnode.node' l x (Ordnode.node' rl rx rr)) = size (eraseMax (Ordnode.node' l x (Ordnode.node' rl rx rr))) + 1
[PROOFSTEP]
rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)]
[GOAL]
case node.intro
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node' rl rx rr)) o₂
this : Ordnode.node rs rl rx rr = Ordnode.node' rl rx rr
h : Valid' (↑x) (eraseMax (Ordnode.node' rl rx rr)) ↑(findMax' rx rr)
e : size (Ordnode.node' rl rx rr) = size (eraseMax (Ordnode.node' rl rx rr)) + 1
⊢ size (Ordnode.node' l x (Ordnode.node' rl rx rr)) = size l + size (eraseMax (Ordnode.node' rl rx rr)) + 1 + 1
[PROOFSTEP]
rw [size, e]
[GOAL]
case node.intro
α : Type u_1
inst✝ : Preorder α
s : ℕ
l✝ : Ordnode α
x✝ : α
r : Ordnode α
o₁✝ : WithBot α
o₂ : WithTop α
H✝ : Valid' o₁✝ (Ordnode.node' l✝ x✝ r) o₂
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
l_ih✝ :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rl) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rl)) ↑(findMax' x rl) ∧
        size (Ordnode.node' l x rl) = size (eraseMax (Ordnode.node' l x rl)) + 1
IHrr :
  ∀ {l : Ordnode α} {x : α} {o₁ : WithBot α},
    Valid' o₁ (Ordnode.node' l x rr) o₂ →
      Valid' o₁ (eraseMax (Ordnode.node' l x rr)) ↑(findMax' x rr) ∧
        size (Ordnode.node' l x rr) = size (eraseMax (Ordnode.node' l x rr)) + 1
l : Ordnode α
x : α
o₁ : WithBot α
H : Valid' o₁ (Ordnode.node' l x (Ordnode.node' rl rx rr)) o₂
this : Ordnode.node rs rl rx rr = Ordnode.node' rl rx rr
h : Valid' (↑x) (eraseMax (Ordnode.node' rl rx rr)) ↑(findMax' rx rr)
e : size (Ordnode.node' rl rx rr) = size (eraseMax (Ordnode.node' rl rx rr)) + 1
⊢ size l + (size (eraseMax (Ordnode.node' rl rx rr)) + 1) + 1 =
    size l + size (eraseMax (Ordnode.node' rl rx rr)) + 1 + 1
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
H : Valid' o₁ (Ordnode.node s l x r) o₂
⊢ Valid' (↑(findMin' l x)) (eraseMin (Ordnode.node' l x r)) o₂ ∧
    size (Ordnode.node' l x r) = size (eraseMin (Ordnode.node' l x r)) + 1
[PROOFSTEP]
have := H.dual.eraseMax_aux
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : ℕ
l : Ordnode α
x : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
H : Valid' o₁ (Ordnode.node s l x r) o₂
this :
  Valid' o₂ (eraseMax (Ordnode.node' (Ordnode.dual r) x (Ordnode.dual l))) ↑(findMax' x (Ordnode.dual l)) ∧
    size (Ordnode.node' (Ordnode.dual r) x (Ordnode.dual l)) =
      size (eraseMax (Ordnode.node' (Ordnode.dual r) x (Ordnode.dual l))) + 1
⊢ Valid' (↑(findMin' l x)) (eraseMin (Ordnode.node' l x r)) o₂ ∧
    size (Ordnode.node' l x r) = size (eraseMin (Ordnode.node' l x r)) + 1
[PROOFSTEP]
rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual] at this
[GOAL]
α : Type u_1
inst✝ : Preorder α
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
h : Valid (node size✝ l x r)
⊢ Valid (eraseMin (node size✝ l x r))
[PROOFSTEP]
rw [h.2.eq_node']
[GOAL]
α : Type u_1
inst✝ : Preorder α
size✝ : ℕ
l : Ordnode α
x : α
r : Ordnode α
h : Valid (node size✝ l x r)
⊢ Valid (eraseMin (node' l x r))
[PROOFSTEP]
exact h.eraseMin_aux.1.valid
[GOAL]
α : Type u_1
inst✝ : Preorder α
t : Ordnode α
h : Valid t
⊢ Valid (eraseMax t)
[PROOFSTEP]
rw [Valid.dual_iff, dual_eraseMax]
[GOAL]
α : Type u_1
inst✝ : Preorder α
t : Ordnode α
h : Valid t
⊢ Valid (eraseMin (dual t))
[PROOFSTEP]
exact eraseMin.valid h.dual
[GOAL]
α : 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
[PROOFSTEP]
cases' l with ls ll lx lr
[GOAL]
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
[PROOFSTEP]
exact ⟨hr, (zero_add _).symm⟩
[GOAL]
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
[PROOFSTEP]
cases' r with rs rl rx rr
[GOAL]
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
[PROOFSTEP]
exact ⟨hl, rfl⟩
[GOAL]
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)
[PROOFSTEP]
dsimp [glue]
[GOAL]
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
[PROOFSTEP]
split_ifs
[GOAL]
case pos
α : 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
[PROOFSTEP]
rw [splitMax_eq]
[GOAL]
case pos
α : 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 ?pos.s✝ ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (Ordnode.balanceR (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).fst
          (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr)) =
      ls + rs
case pos.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
⊢ ℕ
[PROOFSTEP]
cases' Valid'.eraseMax_aux hl with v e
[GOAL]
case pos.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 ?pos.s✝ ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (Ordnode.balanceR (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).fst
          (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr)) =
      ls + rs
case pos.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
⊢ ℕ
[PROOFSTEP]
suffices H
[GOAL]
case pos.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.354852
⊢ Valid' o₁
      (Ordnode.balanceR (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).fst
        (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).snd (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (Ordnode.balanceR (eraseMax (Ordnode.node ?pos.s✝ ll lx lr), findMax' lx lr).fst
          (eraseMax (Ordnode.node ?pos.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.354852
case pos.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
⊢ ℕ
[PROOFSTEP]
refine' ⟨Valid'.balanceR v (hr.of_gt _ _) H, _⟩
[GOAL]
case pos.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₂
[PROOFSTEP]
refine' findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂) lx lr hl.1.2.to_nil (sep.2.2.imp _)
[GOAL]
case pos.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₂
[PROOFSTEP]
exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1)
[GOAL]
case pos.intro.refine'_2
α : 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'
⊢ All (fun x => x > (eraseMax (Ordnode.node (size ll + size lr + 1) ll lx lr), findMax' lx lr).snd)
    (Ordnode.node rs rl rx rr)
[PROOFSTEP]
exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2
[GOAL]
case pos.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
[PROOFSTEP]
rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]
[GOAL]
case pos.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
[PROOFSTEP]
rfl
[GOAL]
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'
[PROOFSTEP]
refine' Or.inl ⟨_, Or.inr e, _⟩
[GOAL]
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))
[PROOFSTEP]
rwa [hl.2.eq_node'] at bal
[GOAL]
case neg
α : 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
[PROOFSTEP]
rw [splitMin_eq]
[GOAL]
case neg
α : 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 ?neg.s✝ rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).snd)
      o₂ ∧
    size
        (Ordnode.balanceL (Ordnode.node ls ll lx lr) (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).fst
          (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).snd) =
      ls + rs
case neg.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
⊢ ℕ
[PROOFSTEP]
cases' Valid'.eraseMin_aux hr with v e
[GOAL]
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
⊢ Valid' o₁
      (Ordnode.balanceL (Ordnode.node ls ll lx lr) (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).snd)
      o₂ ∧
    size
        (Ordnode.balanceL (Ordnode.node ls ll lx lr) (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).fst
          (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).snd) =
      ls + rs
case neg.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
⊢ ℕ
[PROOFSTEP]
suffices H
[GOAL]
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
H : ?m.355955
⊢ Valid' o₁
      (Ordnode.balanceL (Ordnode.node ls ll lx lr) (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).fst
        (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).snd)
      o₂ ∧
    size
        (Ordnode.balanceL (Ordnode.node ls ll lx lr) (findMin' rl rx, eraseMin (Ordnode.node ?neg.s✝ rl rx rr)).fst
          (findMin' rl rx, eraseMin (Ordnode.node ?neg.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.355955
case neg.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
⊢ ℕ
[PROOFSTEP]
refine' ⟨Valid'.balanceL (hl.of_lt _ _) v H, _⟩
[GOAL]
case neg.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
[PROOFSTEP]
refine' @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α)) rl rx (sep.2.1.1.imp _) hr.1.1.to_nil
[GOAL]
case neg.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
[PROOFSTEP]
exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h)
[GOAL]
case neg.intro.refine'_2
α : 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'
⊢ All (fun x => x < (findMin' rl rx, eraseMin (Ordnode.node (size rl + size rr + 1) rl rx rr)).fst)
    (Ordnode.node ls ll lx lr)
[PROOFSTEP]
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)
[GOAL]
case neg.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
[PROOFSTEP]
rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]
[GOAL]
case neg.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)
[PROOFSTEP]
rfl
[GOAL]
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'
[PROOFSTEP]
refine' Or.inr ⟨_, Or.inr e, _⟩
[GOAL]
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))
[PROOFSTEP]
rwa [hr.2.eq_node'] at bal
[GOAL]
α : Type u_1
inst✝ : Preorder α
a b c : ℕ
h₁ : 3 * a < b + c + 1
h₂ : b ≤ 3 * c
⊢ 2 * (a + b) ≤ 9 * c + 5
[PROOFSTEP]
linarith
[GOAL]
α : 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
[PROOFSTEP]
rw [hl.2.1] at e
[GOAL]
α : 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
[PROOFSTEP]
rw [hl.2.1, hr.2.1, delta] at h
[GOAL]
α : 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
[PROOFSTEP]
rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩)
[GOAL]
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
[PROOFSTEP]
linarith
[GOAL]
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
[PROOFSTEP]
suffices H₂
[GOAL]
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
H₂ : ?m.365245
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs
case H₂
α : 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
⊢ ?m.365245
[PROOFSTEP]
suffices H₁
[GOAL]
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
H₂ : ?m.365245
H₁ : ?m.365252
⊢ Valid' o₁ (Ordnode.balanceL t rx rr) o₂ ∧ size (Ordnode.balanceL t rx rr) = ls + rs
case H₁
α : 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.365245
⊢ ?m.365252
case H₂
α : 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
⊢ ?m.365245
[PROOFSTEP]
refine' ⟨Valid'.balanceL_aux v hr.right H₁ H₂ _, _⟩
[GOAL]
case inr.intro.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
[PROOFSTEP]
rw [e]
[GOAL]
case inr.intro.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
[PROOFSTEP]
exact Or.inl (Valid'.merge_lemma h hr₁)
[GOAL]
case inr.intro.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
[PROOFSTEP]
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]
[GOAL]
case inr.intro.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)
[PROOFSTEP]
abel
[GOAL]
case inr.intro.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)
[PROOFSTEP]
abel
[GOAL]
case H₁
α : 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
[PROOFSTEP]
rw [e, add_right_comm]
[GOAL]
case H₁
α : 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
[PROOFSTEP]
rintro ⟨⟩
[GOAL]
case H₂
α : 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
[PROOFSTEP]
intro _ _
[GOAL]
case H₂
α : 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
[PROOFSTEP]
rw [e]
[GOAL]
case H₂
α : 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)
[PROOFSTEP]
unfold delta at hr₂ ⊢
[GOAL]
case H₂
α : 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)
[PROOFSTEP]
linarith
[GOAL]
α : 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
[PROOFSTEP]
induction' l with ls ll lx lr _ IHlr generalizing o₁ o₂ r
[GOAL]
case nil
α : 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
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
[PROOFSTEP]
exact ⟨hr, (zero_add _).symm⟩
[GOAL]
case node
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
hr : Valid' o₁ r o₂
sep : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
⊢ Valid' o₁ (merge (Ordnode.node ls ll lx lr) r) o₂ ∧
    size (merge (Ordnode.node ls ll lx lr) r) = size (Ordnode.node ls ll lx lr) + size r
[PROOFSTEP]
induction' r with rs rl rx rr IHrl _ generalizing o₁ o₂
[GOAL]
case node.nil
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
o₁ : WithBot α
o₂ : WithTop α
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)
⊢ Valid' o₁ (merge (Ordnode.node ls ll lx lr) nil) o₂ ∧
    size (merge (Ordnode.node ls ll lx lr) nil) = size (Ordnode.node ls ll lx lr) + size nil
[PROOFSTEP]
exact ⟨hl, rfl⟩
[GOAL]
case node.node
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
⊢ Valid' o₁ (merge (Ordnode.node ls ll lx lr) (Ordnode.node rs rl rx rr)) o₂ ∧
    size (merge (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)
[PROOFSTEP]
rw [merge_node]
[GOAL]
case node.node
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
⊢ Valid' o₁
      (if delta * ls < rs then Ordnode.balanceL (merge (Ordnode.node ls ll lx lr) rl) rx rr
      else
        if delta * rs < ls then Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))
        else Ordnode.glue (Ordnode.node ls ll lx lr) (Ordnode.node rs rl rx rr))
      o₂ ∧
    size
        (if delta * ls < rs then Ordnode.balanceL (merge (Ordnode.node ls ll lx lr) rl) rx rr
        else
          if delta * rs < ls then Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))
          else Ordnode.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)
[PROOFSTEP]
split_ifs with h h_1
[GOAL]
case pos
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : delta * ls < rs
⊢ Valid' o₁ (Ordnode.balanceL (merge (Ordnode.node ls ll lx lr) rl) rx rr) o₂ ∧
    size (Ordnode.balanceL (merge (Ordnode.node ls ll lx lr) rl) rx rr) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)
[PROOFSTEP]
cases' IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left (sep.imp fun x h => h.1) with v e
[GOAL]
case pos.intro
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : delta * ls < rs
v : Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) ↑rx
e : size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
⊢ Valid' o₁ (Ordnode.balanceL (merge (Ordnode.node ls ll lx lr) rl) rx rr) o₂ ∧
    size (Ordnode.balanceL (merge (Ordnode.node ls ll lx lr) rl) rx rr) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)
[PROOFSTEP]
exact Valid'.merge_aux₁ hl hr h v e
[GOAL]
case pos
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
⊢ Valid' o₁ (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) o₂ ∧
    size (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)
[PROOFSTEP]
cases' IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2 with v e
[GOAL]
case pos.intro
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
v : Valid' (↑lx) (merge lr (Ordnode.node rs rl rx rr)) o₂
e : size (merge lr (Ordnode.node rs rl rx rr)) = size lr + size (Ordnode.node rs rl rx rr)
⊢ Valid' o₁ (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) o₂ ∧
    size (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)
[PROOFSTEP]
have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual
[GOAL]
case pos.intro
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
v : Valid' (↑lx) (merge lr (Ordnode.node rs rl rx rr)) o₂
e : size (merge lr (Ordnode.node rs rl rx rr)) = size lr + size (Ordnode.node rs rl rx rr)
this :
  size (Ordnode.dual (merge lr (Ordnode.node rs rl rx rr))) = rs + size (Ordnode.dual lr) →
    Valid' o₂ (Ordnode.balanceL (Ordnode.dual (merge lr (Ordnode.node rs rl rx rr))) lx (Ordnode.dual ll)) o₁ ∧
      size (Ordnode.balanceL (Ordnode.dual (merge lr (Ordnode.node rs rl rx rr))) lx (Ordnode.dual ll)) = rs + ls
⊢ Valid' o₁ (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) o₂ ∧
    size (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)
[PROOFSTEP]
rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual, add_comm rs] at this
[GOAL]
case pos.intro
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : ¬delta * ls < rs
h_1 : delta * rs < ls
v : Valid' (↑lx) (merge lr (Ordnode.node rs rl rx rr)) o₂
e : size (merge lr (Ordnode.node rs rl rx rr)) = size lr + size (Ordnode.node rs rl rx rr)
this :
  size (merge lr (Ordnode.node rs rl rx rr)) = size lr + rs →
    Valid' o₁ (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) o₂ ∧
      size (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) = ls + rs
⊢ Valid' o₁ (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) o₂ ∧
    size (Ordnode.balanceR ll lx (merge lr (Ordnode.node rs rl rx rr))) =
      size (Ordnode.node ls ll lx lr) + size (Ordnode.node rs rl rx rr)
[PROOFSTEP]
exact this e
[GOAL]
case neg
α : 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
ls : ℕ
ll : Ordnode α
lx : α
lr : Ordnode α
l_ih✝ :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ ll o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) ll → Valid' o₁ (merge ll r) o₂ ∧ size (merge ll r) = size ll + size r
IHlr :
  ∀ {r : Ordnode α} {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ lr o₂ →
      Valid' o₁ r o₂ →
        All (fun x => All (fun y => x < y) r) lr → Valid' o₁ (merge lr r) o₂ ∧ size (merge lr r) = size lr + size r
r : Ordnode α
o₁✝ : WithBot α
o₂✝ : WithTop α
hl✝ : Valid' o₁✝ (Ordnode.node ls ll lx lr) o₂✝
hr✝ : Valid' o₁✝ r o₂✝
sep✝ : All (fun x => All (fun y => x < y) r) (Ordnode.node ls ll lx lr)
rs : ℕ
rl : Ordnode α
rx : α
rr : Ordnode α
IHrl :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rl o₂ →
        All (fun x => All (fun y => x < y) rl) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rl) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rl) = size (Ordnode.node ls ll lx lr) + size rl
r_ih✝ :
  ∀ {o₁ : WithBot α} {o₂ : WithTop α},
    Valid' o₁ (Ordnode.node ls ll lx lr) o₂ →
      Valid' o₁ rr o₂ →
        All (fun x => All (fun y => x < y) rr) (Ordnode.node ls ll lx lr) →
          Valid' o₁ (merge (Ordnode.node ls ll lx lr) rr) o₂ ∧
            size (merge (Ordnode.node ls ll lx lr) rr) = size (Ordnode.node ls ll lx lr) + size rr
o₁ : WithBot α
o₂ : WithTop α
hl : Valid' o₁ (Ordnode.node ls ll lx lr) o₂
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)
h : ¬delta * ls < rs
h_1 : ¬delta * rs < ls
⊢ Valid' o₁ (Ordnode.glue (Ordnode.node ls ll lx lr) (Ordnode.node rs rl rx rr)) o₂ ∧
    size (Ordnode.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)
[PROOFSTEP]
refine' Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩)
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
⊢ Valid' o₁ (insertWith f x (node sz l y r)) o₂ ∧ Raised (size (node sz l y r)) (size (insertWith f x (node sz l y r)))
[PROOFSTEP]
rw [insertWith, cmpLE]
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
⊢ Valid' o₁
      (match if x ≤ y then if y ≤ x then Ordering.eq else Ordering.lt else Ordering.gt with
      | Ordering.lt => balanceL (insertWith f x l) y r
      | Ordering.eq => node sz l (f y) r
      | Ordering.gt => balanceR l y (insertWith f x r))
      o₂ ∧
    Raised (size (node sz l y r))
      (size
        (match if x ≤ y then if y ≤ x then Ordering.eq else Ordering.lt else Ordering.gt with
        | Ordering.lt => balanceL (insertWith f x l) y r
        | Ordering.eq => node sz l (f y) r
        | Ordering.gt => balanceR l y (insertWith f x r)))
[PROOFSTEP]
split_ifs with h_1 h_2
[GOAL]
case pos
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : y ≤ x
⊢ Valid' o₁
      (match Ordering.eq with
      | Ordering.lt => balanceL (insertWith f x l) y r
      | Ordering.eq => node sz l (f y) r
      | Ordering.gt => balanceR l y (insertWith f x r))
      o₂ ∧
    Raised (size (node sz l y r))
      (size
        (match Ordering.eq with
        | Ordering.lt => balanceL (insertWith f x l) y r
        | Ordering.eq => node sz l (f y) r
        | Ordering.gt => balanceR l y (insertWith f x r)))
[PROOFSTEP]
dsimp only
[GOAL]
case neg
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
⊢ Valid' o₁
      (match Ordering.lt with
      | Ordering.lt => balanceL (insertWith f x l) y r
      | Ordering.eq => node sz l (f y) r
      | Ordering.gt => balanceR l y (insertWith f x r))
      o₂ ∧
    Raised (size (node sz l y r))
      (size
        (match Ordering.lt with
        | Ordering.lt => balanceL (insertWith f x l) y r
        | Ordering.eq => node sz l (f y) r
        | Ordering.gt => balanceR l y (insertWith f x r)))
[PROOFSTEP]
dsimp only
[GOAL]
case neg
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
⊢ Valid' o₁
      (match Ordering.gt with
      | Ordering.lt => balanceL (insertWith f x l) y r
      | Ordering.eq => node sz l (f y) r
      | Ordering.gt => balanceR l y (insertWith f x r))
      o₂ ∧
    Raised (size (node sz l y r))
      (size
        (match Ordering.gt with
        | Ordering.lt => balanceL (insertWith f x l) y r
        | Ordering.eq => node sz l (f y) r
        | Ordering.gt => balanceR l y (insertWith f x r)))
[PROOFSTEP]
dsimp only
[GOAL]
case pos
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : y ≤ x
⊢ Valid' o₁ (node sz l (f y) r) o₂ ∧ Raised (size (node sz l y r)) (size (node sz l (f y) r))
[PROOFSTEP]
rcases h with ⟨⟨lx, xr⟩, hs, hb⟩
[GOAL]
case pos.mk.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : y ≤ x
hs : Sized (node sz l y r)
hb : Balanced (node sz l y r)
lx : Bounded l o₁ ↑y
xr : Bounded r (↑y) o₂
⊢ Valid' o₁ (node sz l (f y) r) o₂ ∧ Raised (size (node sz l y r)) (size (node sz l (f y) r))
[PROOFSTEP]
rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩
[GOAL]
case pos.mk.intro.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : y ≤ x
hs : Sized (node sz l y r)
hb : Balanced (node sz l y r)
lx : Bounded l o₁ ↑y
xr : Bounded r (↑y) o₂
xf : x ≤ f y
fx : f y ≤ x
⊢ Valid' o₁ (node sz l (f y) r) o₂ ∧ Raised (size (node sz l y r)) (size (node sz l (f y) r))
[PROOFSTEP]
refine' ⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩
[GOAL]
case neg
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
⊢ Valid' o₁ (balanceL (insertWith f x l) y r) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceL (insertWith f x l) y r))
[PROOFSTEP]
rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
vl : Valid' o₁ (insertWith f x l) ↑y
e : Raised (size l) (size (insertWith f x l))
⊢ Valid' o₁ (balanceL (insertWith f x l) y r) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceL (insertWith f x l) y r))
[PROOFSTEP]
suffices H
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
vl : Valid' o₁ (insertWith f x l) ↑y
e : Raised (size l) (size (insertWith f x l))
H : ?m.378189
⊢ Valid' o₁ (balanceL (insertWith f x l) y r) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceL (insertWith f x l) y r))
[PROOFSTEP]
refine' ⟨vl.balanceL h.right H, _⟩
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
vl : Valid' o₁ (insertWith f x l) ↑y
e : Raised (size l) (size (insertWith f x l))
H :
  (∃ l', Raised l' (size (insertWith f x l)) ∧ BalancedSz l' (size r)) ∨
    ∃ r', Raised (size r) r' ∧ BalancedSz (size (insertWith f x l)) r'
⊢ Raised (size (node sz l y r)) (size (balanceL (insertWith f x l) y r))
[PROOFSTEP]
rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq]
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
vl : Valid' o₁ (insertWith f x l) ↑y
e : Raised (size l) (size (insertWith f x l))
H :
  (∃ l', Raised l' (size (insertWith f x l)) ∧ BalancedSz l' (size r)) ∨
    ∃ r', Raised (size r) r' ∧ BalancedSz (size (insertWith f x l)) r'
⊢ Raised (size l + size r + 1) (size (insertWith f x l) + size r + 1)
[PROOFSTEP]
refine' (e.add_right _).add_right _
[GOAL]
case H
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : x ≤ y
h_2 : ¬y ≤ x
vl : Valid' o₁ (insertWith f x l) ↑y
e : Raised (size l) (size (insertWith f x l))
⊢ (∃ l', Raised l' (size (insertWith f x l)) ∧ BalancedSz l' (size r)) ∨
    ∃ r', Raised (size r) r' ∧ BalancedSz (size (insertWith f x l)) r'
[PROOFSTEP]
exact Or.inl ⟨_, e, h.3.1⟩
[GOAL]
case neg
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
⊢ Valid' o₁ (balanceR l y (insertWith f x r)) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceR l y (insertWith f x r)))
[PROOFSTEP]
have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1
[GOAL]
case neg
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
this : y < x
⊢ Valid' o₁ (balanceR l y (insertWith f x r)) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceR l y (insertWith f x r)))
[PROOFSTEP]
rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
this : y < x
vr : Valid' (↑y) (insertWith f x r) o₂
e : Raised (size r) (size (insertWith f x r))
⊢ Valid' o₁ (balanceR l y (insertWith f x r)) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceR l y (insertWith f x r)))
[PROOFSTEP]
suffices H
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
this : y < x
vr : Valid' (↑y) (insertWith f x r) o₂
e : Raised (size r) (size (insertWith f x r))
H : ?m.378711
⊢ Valid' o₁ (balanceR l y (insertWith f x r)) o₂ ∧
    Raised (size (node sz l y r)) (size (balanceR l y (insertWith f x r)))
[PROOFSTEP]
refine' ⟨h.left.balanceR vr H, _⟩
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
this : y < x
vr : Valid' (↑y) (insertWith f x r) o₂
e : Raised (size r) (size (insertWith f x r))
H :
  (∃ l', Raised (size l) l' ∧ BalancedSz l' (size (insertWith f x r))) ∨
    ∃ r', Raised r' (size (insertWith f x r)) ∧ BalancedSz (size l) r'
⊢ Raised (size (node sz l y r)) (size (balanceR l y (insertWith f x r)))
[PROOFSTEP]
rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq]
[GOAL]
case neg.intro
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
this : y < x
vr : Valid' (↑y) (insertWith f x r) o₂
e : Raised (size r) (size (insertWith f x r))
H :
  (∃ l', Raised (size l) l' ∧ BalancedSz l' (size (insertWith f x r))) ∨
    ∃ r', Raised r' (size (insertWith f x r)) ∧ BalancedSz (size l) r'
⊢ Raised (size l + size r + 1) (size l + size (insertWith f x r) + 1)
[PROOFSTEP]
refine' (e.add_left _).add_right _
[GOAL]
case H
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
f : α → α
x : α
hf : ∀ (y : α), x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x
sz : ℕ
l : Ordnode α
y : α
r : Ordnode α
o₁ : WithBot α
o₂ : WithTop α
h : Valid' o₁ (node sz l y r) o₂
bl : Bounded nil o₁ ↑x
br : Bounded nil (↑x) o₂
h_1 : ¬x ≤ y
this : y < x
vr : Valid' (↑y) (insertWith f x r) o₂
e : Raised (size r) (size (insertWith f x r))
⊢ (∃ l', Raised (size l) l' ∧ BalancedSz l' (size (insertWith f x r))) ∨
    ∃ r', Raised r' (size (insertWith f x r)) ∧ BalancedSz (size l) r'
[PROOFSTEP]
exact Or.inr ⟨_, e, h.3.1⟩
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ Ordnode.insert x (node size✝ l y r) = insertWith (fun x_1 => x) x (node size✝ l y r)
[PROOFSTEP]
unfold Ordnode.insert insertWith
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match cmpLE x y with
    | Ordering.lt => balanceL (Ordnode.insert x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match cmpLE x y with
    | Ordering.lt => balanceL (insertWith (fun x_1 => x) x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (insertWith (fun x_1 => x) x r)
[PROOFSTEP]
cases cmpLE x y
[GOAL]
case lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match Ordering.lt with
    | Ordering.lt => balanceL (Ordnode.insert x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.lt with
    | Ordering.lt => balanceL (insertWith (fun x_1 => x) x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (insertWith (fun x_1 => x) x r)
[PROOFSTEP]
simp [insert_eq_insertWith]
[GOAL]
case eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match Ordering.eq with
    | Ordering.lt => balanceL (Ordnode.insert x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.eq with
    | Ordering.lt => balanceL (insertWith (fun x_1 => x) x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (insertWith (fun x_1 => x) x r)
[PROOFSTEP]
simp [insert_eq_insertWith]
[GOAL]
case gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match Ordering.gt with
    | Ordering.lt => balanceL (Ordnode.insert x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (Ordnode.insert x r)) =
    match Ordering.gt with
    | Ordering.lt => balanceL (insertWith (fun x_1 => x) x l) y r
    | Ordering.eq => node size✝ l x r
    | Ordering.gt => balanceR l y (insertWith (fun x_1 => x) x r)
[PROOFSTEP]
simp [insert_eq_insertWith]
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
h : Valid t
⊢ Valid (Ordnode.insert x t)
[PROOFSTEP]
rw [insert_eq_insertWith]
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
h : Valid t
⊢ Valid (insertWith (fun x_1 => x) x t)
[PROOFSTEP]
exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ insert' x (node size✝ l y r) = insertWith id x (node size✝ l y r)
[PROOFSTEP]
unfold insert' insertWith
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match cmpLE x y with
    | Ordering.lt => balanceL (insert' x l) y r
    | Ordering.eq => node size✝ l y r
    | Ordering.gt => balanceR l y (insert' x r)) =
    match cmpLE x y with
    | Ordering.lt => balanceL (insertWith id x l) y r
    | Ordering.eq => node size✝ l (id y) r
    | Ordering.gt => balanceR l y (insertWith id x r)
[PROOFSTEP]
cases cmpLE x y
[GOAL]
case lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match Ordering.lt with
    | Ordering.lt => balanceL (insert' x l) y r
    | Ordering.eq => node size✝ l y r
    | Ordering.gt => balanceR l y (insert' x r)) =
    match Ordering.lt with
    | Ordering.lt => balanceL (insertWith id x l) y r
    | Ordering.eq => node size✝ l (id y) r
    | Ordering.gt => balanceR l y (insertWith id x r)
[PROOFSTEP]
simp [insert'_eq_insertWith]
[GOAL]
case eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match Ordering.eq with
    | Ordering.lt => balanceL (insert' x l) y r
    | Ordering.eq => node size✝ l y r
    | Ordering.gt => balanceR l y (insert' x r)) =
    match Ordering.eq with
    | Ordering.lt => balanceL (insertWith id x l) y r
    | Ordering.eq => node size✝ l (id y) r
    | Ordering.gt => balanceR l y (insertWith id x r)
[PROOFSTEP]
simp [insert'_eq_insertWith]
[GOAL]
case gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
l : Ordnode α
y : α
r : Ordnode α
⊢ (match Ordering.gt with
    | Ordering.lt => balanceL (insert' x l) y r
    | Ordering.eq => node size✝ l y r
    | Ordering.gt => balanceR l y (insert' x r)) =
    match Ordering.gt with
    | Ordering.lt => balanceL (insertWith id x l) y r
    | Ordering.eq => node size✝ l (id y) r
    | Ordering.gt => balanceR l y (insertWith id x r)
[PROOFSTEP]
simp [insert'_eq_insertWith]
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
h : Valid t
⊢ Valid (insert' x t)
[PROOFSTEP]
rw [insert'_eq_insertWith]
[GOAL]
α : Type u_1
inst✝² : Preorder α
inst✝¹ : IsTotal α fun x x_1 => x ≤ x_1
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
h : Valid t
⊢ Valid (insertWith id x t)
[PROOFSTEP]
exact insertWith.valid _ _ (fun _ => id) h
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
t : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ t a₂
⊢ Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ size (map f t) = size t
[PROOFSTEP]
induction t generalizing a₁ a₂ with
| nil =>
  simp [map]; apply valid'_nil
  cases a₁; · trivial
  cases a₂; · trivial
  simp [Bounded]
  exact f_strict_mono h.ord
| node _ _ _ _ t_ih_l t_ih_r =>
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  cases' t_ih_l' with t_l_valid t_l_size
  cases' t_ih_r' with t_r_valid t_r_size
  simp [map]
  constructor
  · exact And.intro t_l_valid.ord t_r_valid.ord
  · constructor
    · rw [t_l_size, t_r_size]; exact h.sz.1
    · constructor
      · exact t_l_valid.sz
      · exact t_r_valid.sz
  · constructor
    · rw [t_l_size, t_r_size]; exact h.bal.1
    · constructor
      · exact t_l_valid.bal
      · exact t_r_valid.bal
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
t : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ t a₂
⊢ Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ size (map f t) = size t
[PROOFSTEP]
induction t generalizing a₁ a₂ with
| nil =>
  simp [map]; apply valid'_nil
  cases a₁; · trivial
  cases a₂; · trivial
  simp [Bounded]
  exact f_strict_mono h.ord
| node _ _ _ _ t_ih_l t_ih_r =>
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  cases' t_ih_l' with t_l_valid t_l_size
  cases' t_ih_r' with t_r_valid t_r_size
  simp [map]
  constructor
  · exact And.intro t_l_valid.ord t_r_valid.ord
  · constructor
    · rw [t_l_size, t_r_size]; exact h.sz.1
    · constructor
      · exact t_l_valid.sz
      · exact t_r_valid.sz
  · constructor
    · rw [t_l_size, t_r_size]; exact h.bal.1
    · constructor
      · exact t_l_valid.bal
      · exact t_r_valid.bal
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Valid' (Option.map f a₁) (map f nil) (Option.map f a₂) ∧ size (map f nil) = size nil
[PROOFSTEP]

| nil =>
  simp [map]; apply valid'_nil
  cases a₁; · trivial
  cases a₂; · trivial
  simp [Bounded]
  exact f_strict_mono h.ord
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Valid' (Option.map f a₁) (map f nil) (Option.map f a₂) ∧ size (map f nil) = size nil
[PROOFSTEP]
simp [map]
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Valid' (Option.map f a₁) nil (Option.map f a₂)
[PROOFSTEP]
apply valid'_nil
[GOAL]
case nil.h
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Bounded nil (Option.map f a₁) (Option.map f a₂)
[PROOFSTEP]
cases a₁
[GOAL]
case nil.h.none
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
a₂ : WithTop α
h : Valid' none nil a₂
⊢ Bounded nil (Option.map f none) (Option.map f a₂)
[PROOFSTEP]
trivial
[GOAL]
case nil.h.some
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
a₂ : WithTop α
val✝ : α
h : Valid' (some val✝) nil a₂
⊢ Bounded nil (Option.map f (some val✝)) (Option.map f a₂)
[PROOFSTEP]
cases a₂
[GOAL]
case nil.h.some.none
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
val✝ : α
h : Valid' (some val✝) nil none
⊢ Bounded nil (Option.map f (some val✝)) (Option.map f none)
[PROOFSTEP]
trivial
[GOAL]
case nil.h.some.some
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
val✝¹ val✝ : α
h : Valid' (some val✝¹) nil (some val✝)
⊢ Bounded nil (Option.map f (some val✝¹)) (Option.map f (some val✝))
[PROOFSTEP]
simp [Bounded]
[GOAL]
case nil.h.some.some
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
val✝¹ val✝ : α
h : Valid' (some val✝¹) nil (some val✝)
⊢ f val✝¹ < f val✝
[PROOFSTEP]
exact f_strict_mono h.ord
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ l✝ a₂ → Valid' (Option.map f a₁) (map f l✝) (Option.map f a₂) ∧ size (map f l✝) = size l✝
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ r✝ a₂ → Valid' (Option.map f a₁) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]

| node _ _ _ _ t_ih_l t_ih_r =>
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  cases' t_ih_l' with t_l_valid t_l_size
  cases' t_ih_r' with t_r_valid t_r_size
  simp [map]
  constructor
  · exact And.intro t_l_valid.ord t_r_valid.ord
  · constructor
    · rw [t_l_size, t_r_size]; exact h.sz.1
    · constructor
      · exact t_l_valid.sz
      · exact t_r_valid.sz
  · constructor
    · rw [t_l_size, t_r_size]; exact h.bal.1
    · constructor
      · exact t_l_valid.bal
      · exact t_r_valid.bal
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ l✝ a₂ → Valid' (Option.map f a₁) (map f l✝) (Option.map f a₂) ∧ size (map f l✝) = size l✝
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ r✝ a₂ → Valid' (Option.map f a₁) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]
have t_ih_l' := t_ih_l h.left
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ l✝ a₂ → Valid' (Option.map f a₁) (map f l✝) (Option.map f a₂) ∧ size (map f l✝) = size l✝
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ r✝ a₂ → Valid' (Option.map f a₁) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_ih_l' : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝) ∧ size (map f l✝) = size l✝
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]
have t_ih_r' := t_ih_r h.right
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ l✝ a₂ → Valid' (Option.map f a₁) (map f l✝) (Option.map f a₂) ∧ size (map f l✝) = size l✝
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ r✝ a₂ → Valid' (Option.map f a₁) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_ih_l' : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝) ∧ size (map f l✝) = size l✝
t_ih_r' : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]
clear t_ih_l t_ih_r
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_ih_l' : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝) ∧ size (map f l✝) = size l✝
t_ih_r' : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]
cases' t_ih_l' with t_l_valid t_l_size
[GOAL]
case node.intro
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_ih_r' : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂) ∧ size (map f r✝) = size r✝
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]
cases' t_ih_r' with t_r_valid t_r_size
[GOAL]
case node.intro.intro
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Valid' (Option.map f a₁) (map f (Ordnode.node size✝ l✝ x✝ r✝)) (Option.map f a₂) ∧
    size (map f (Ordnode.node size✝ l✝ x✝ r✝)) = size (Ordnode.node size✝ l✝ x✝ r✝)
[PROOFSTEP]
simp [map]
[GOAL]
case node.intro.intro
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Valid' (Option.map f a₁) (Ordnode.node size✝ (map f l✝) (f x✝) (map f r✝)) (Option.map f a₂)
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.ord
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Bounded (Ordnode.node size✝ (map f l✝) (f x✝) (map f r✝)) (Option.map f a₁) (Option.map f a₂)
[PROOFSTEP]
exact And.intro t_l_valid.ord t_r_valid.ord
[GOAL]
case node.intro.intro.sz
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Sized (Ordnode.node size✝ (map f l✝) (f x✝) (map f r✝))
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.sz.left
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ size✝ = size (map f l✝) + size (map f r✝) + 1
[PROOFSTEP]
rw [t_l_size, t_r_size]
[GOAL]
case node.intro.intro.sz.left
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ size✝ = size l✝ + size r✝ + 1
[PROOFSTEP]
exact h.sz.1
[GOAL]
case node.intro.intro.sz.right
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Sized (map f l✝) ∧ Sized (map f r✝)
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.sz.right.left
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Sized (map f l✝)
[PROOFSTEP]
exact t_l_valid.sz
[GOAL]
case node.intro.intro.sz.right.right
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Sized (map f r✝)
[PROOFSTEP]
exact t_r_valid.sz
[GOAL]
case node.intro.intro.bal
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Balanced (Ordnode.node size✝ (map f l✝) (f x✝) (map f r✝))
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.bal.left
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ BalancedSz (size (map f l✝)) (size (map f r✝))
[PROOFSTEP]
rw [t_l_size, t_r_size]
[GOAL]
case node.intro.intro.bal.left
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ BalancedSz (size l✝) (size r✝)
[PROOFSTEP]
exact h.bal.1
[GOAL]
case node.intro.intro.bal.right
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Balanced (map f l✝) ∧ Balanced (map f r✝)
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.bal.right.left
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Balanced (map f l✝)
[PROOFSTEP]
exact t_l_valid.bal
[GOAL]
case node.intro.intro.bal.right.right
α : Type u_1
inst✝¹ : Preorder α
β : Type u_2
inst✝ : Preorder β
f : α → β
f_strict_mono : StrictMono f
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ l✝ x✝ r✝) a₂
t_l_valid : Valid' (Option.map f a₁) (map f l✝) (Option.map f ↑x✝)
t_l_size : size (map f l✝) = size l✝
t_r_valid : Valid' (Option.map f ↑x✝) (map f r✝) (Option.map f a₂)
t_r_size : size (map f r✝) = size r✝
⊢ Balanced (map f r✝)
[PROOFSTEP]
exact t_r_valid.bal
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ t a₂
⊢ Valid' a₁ (erase x t) a₂ ∧ Raised (size (erase x t)) (size t)
[PROOFSTEP]
induction t generalizing a₁ a₂ with
| nil => simp [erase, Raised]; exact h
| node _ t_l t_x t_r t_ih_l t_ih_r =>
  simp [erase]
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  cases' t_ih_l' with t_l_valid t_l_size
  cases' t_ih_r' with t_r_valid t_r_size
  cases cmpLE x t_x <;> rw [h.sz.1]
  · suffices h_balanceable
    constructor
    · exact Valid'.balanceR t_l_valid h.right h_balanceable
    · rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
      repeat apply Raised.add_right
      exact t_l_size
    · left; exists t_l.size; exact And.intro t_l_size h.bal.1
  · have h_glue := Valid'.glue h.left h.right h.bal.1
    cases' h_glue with h_glue_valid h_glue_sized
    constructor
    · exact h_glue_valid
    · right; rw [h_glue_sized]
  · suffices h_balanceable
    constructor
    · exact Valid'.balanceL h.left t_r_valid h_balanceable
    · rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
      apply Raised.add_right
      apply Raised.add_left
      exact t_r_size
    · right; exists t_r.size; exact And.intro t_r_size h.bal.1
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ t a₂
⊢ Valid' a₁ (erase x t) a₂ ∧ Raised (size (erase x t)) (size t)
[PROOFSTEP]
induction t generalizing a₁ a₂ with
| nil => simp [erase, Raised]; exact h
| node _ t_l t_x t_r t_ih_l t_ih_r =>
  simp [erase]
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  cases' t_ih_l' with t_l_valid t_l_size
  cases' t_ih_r' with t_r_valid t_r_size
  cases cmpLE x t_x <;> rw [h.sz.1]
  · suffices h_balanceable
    constructor
    · exact Valid'.balanceR t_l_valid h.right h_balanceable
    · rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
      repeat apply Raised.add_right
      exact t_l_size
    · left; exists t_l.size; exact And.intro t_l_size h.bal.1
  · have h_glue := Valid'.glue h.left h.right h.bal.1
    cases' h_glue with h_glue_valid h_glue_sized
    constructor
    · exact h_glue_valid
    · right; rw [h_glue_sized]
  · suffices h_balanceable
    constructor
    · exact Valid'.balanceL h.left t_r_valid h_balanceable
    · rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
      apply Raised.add_right
      apply Raised.add_left
      exact t_r_size
    · right; exists t_r.size; exact And.intro t_r_size h.bal.1
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Valid' a₁ (erase x nil) a₂ ∧ Raised (size (erase x nil)) (size nil)
[PROOFSTEP]

| nil => simp [erase, Raised]; exact h
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Valid' a₁ (erase x nil) a₂ ∧ Raised (size (erase x nil)) (size nil)
[PROOFSTEP]
simp [erase, Raised]
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
⊢ Valid' a₁ nil a₂
[PROOFSTEP]
exact h
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_l a₂ → Valid' a₁ (erase x t_l) a₂ ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_r a₂ → Valid' a₁ (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
⊢ Valid' a₁ (erase x (Ordnode.node size✝ t_l t_x t_r)) a₂ ∧
    Raised (size (erase x (Ordnode.node size✝ t_l t_x t_r))) (size (Ordnode.node size✝ t_l t_x t_r))
[PROOFSTEP]

| node _ t_l t_x t_r t_ih_l t_ih_r =>
  simp [erase]
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  cases' t_ih_l' with t_l_valid t_l_size
  cases' t_ih_r' with t_r_valid t_r_size
  cases cmpLE x t_x <;> rw [h.sz.1]
  · suffices h_balanceable
    constructor
    · exact Valid'.balanceR t_l_valid h.right h_balanceable
    · rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
      repeat apply Raised.add_right
      exact t_l_size
    · left; exists t_l.size; exact And.intro t_l_size h.bal.1
  · have h_glue := Valid'.glue h.left h.right h.bal.1
    cases' h_glue with h_glue_valid h_glue_sized
    constructor
    · exact h_glue_valid
    · right; rw [h_glue_sized]
  · suffices h_balanceable
    constructor
    · exact Valid'.balanceL h.left t_r_valid h_balanceable
    · rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
      apply Raised.add_right
      apply Raised.add_left
      exact t_r_size
    · right; exists t_r.size; exact And.intro t_r_size h.bal.1
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_l a₂ → Valid' a₁ (erase x t_l) a₂ ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_r a₂ → Valid' a₁ (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
⊢ Valid' a₁ (erase x (Ordnode.node size✝ t_l t_x t_r)) a₂ ∧
    Raised (size (erase x (Ordnode.node size✝ t_l t_x t_r))) (size (Ordnode.node size✝ t_l t_x t_r))
[PROOFSTEP]
simp [erase]
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_l a₂ → Valid' a₁ (erase x t_l) a₂ ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_r a₂ → Valid' a₁ (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
⊢ Valid' a₁
      (match cmpLE x t_x with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match cmpLE x t_x with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
have t_ih_l' := t_ih_l h.left
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_l a₂ → Valid' a₁ (erase x t_l) a₂ ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_r a₂ → Valid' a₁ (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_ih_l' : Valid' a₁ (erase x t_l) ↑t_x ∧ Raised (size (erase x t_l)) (size t_l)
⊢ Valid' a₁
      (match cmpLE x t_x with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match cmpLE x t_x with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
have t_ih_r' := t_ih_r h.right
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_l a₂ → Valid' a₁ (erase x t_l) a₂ ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r :
  ∀ {a₁ : WithBot α} {a₂ : WithTop α},
    Valid' a₁ t_r a₂ → Valid' a₁ (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_ih_l' : Valid' a₁ (erase x t_l) ↑t_x ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r' : Valid' (↑t_x) (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match cmpLE x t_x with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match cmpLE x t_x with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
clear t_ih_l t_ih_r
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_ih_l' : Valid' a₁ (erase x t_l) ↑t_x ∧ Raised (size (erase x t_l)) (size t_l)
t_ih_r' : Valid' (↑t_x) (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match cmpLE x t_x with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match cmpLE x t_x with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
cases' t_ih_l' with t_l_valid t_l_size
[GOAL]
case node.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_ih_r' : Valid' (↑t_x) (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
⊢ Valid' a₁
      (match cmpLE x t_x with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match cmpLE x t_x with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
cases' t_ih_r' with t_r_valid t_r_size
[GOAL]
case node.intro.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match cmpLE x t_x with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match cmpLE x t_x with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
cases cmpLE x t_x
[GOAL]
case node.intro.intro.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match Ordering.lt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.lt with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
rw [h.sz.1]
[GOAL]
case node.intro.intro.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match Ordering.eq with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.eq with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
rw [h.sz.1]
[GOAL]
case node.intro.intro.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match Ordering.gt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.gt with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      size✝
[PROOFSTEP]
rw [h.sz.1]
[GOAL]
case node.intro.intro.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match Ordering.lt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.lt with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
[PROOFSTEP]
suffices h_balanceable
[GOAL]
case node.intro.intro.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable : ?m.391248
⊢ Valid' a₁
      (match Ordering.lt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.lt with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
case h_balanceable
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ ?m.391248
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.lt.left
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable : ?m.391248
⊢ Valid' a₁
    (match Ordering.lt with
    | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
    | Ordering.eq => Ordnode.glue t_l t_r
    | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
    a₂
[PROOFSTEP]
exact Valid'.balanceR t_l_valid h.right h_balanceable
[GOAL]
case node.intro.intro.lt.right
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
⊢ Raised
    (size
      (match Ordering.lt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
    (size t_l + size t_r + 1)
[PROOFSTEP]
rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
[GOAL]
case node.intro.intro.lt.right
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
⊢ Raised (size (erase x t_l) + size t_r + 1) (size t_l + size t_r + 1)
[PROOFSTEP]
repeat apply Raised.add_right
[GOAL]
case node.intro.intro.lt.right
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
⊢ Raised (size (erase x t_l) + size t_r + 1) (size t_l + size t_r + 1)
[PROOFSTEP]
apply Raised.add_right
[GOAL]
case node.intro.intro.lt.right.H
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
⊢ Raised (size (erase x t_l) + size t_r) (size t_l + size t_r)
[PROOFSTEP]
apply Raised.add_right
[GOAL]
case node.intro.intro.lt.right.H.H
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
⊢ Raised (size (erase x t_l)) (size t_l)
[PROOFSTEP]
apply Raised.add_right
[GOAL]
case node.intro.intro.lt.right.H.H
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
⊢ Raised (size (erase x t_l)) (size t_l)
[PROOFSTEP]
exact t_l_size
[GOAL]
case h_balanceable
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ (∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)) ∨
    ∃ r', Raised r' (size t_r) ∧ BalancedSz (size (erase x t_l)) r'
[PROOFSTEP]
left
[GOAL]
case h_balanceable.h
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ ∃ l', Raised (size (erase x t_l)) l' ∧ BalancedSz l' (size t_r)
[PROOFSTEP]
exists t_l.size
[GOAL]
case h_balanceable.h
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Raised (size (erase x t_l)) (size t_l) ∧ BalancedSz (size t_l) (size t_r)
[PROOFSTEP]
exact And.intro t_l_size h.bal.1
[GOAL]
case node.intro.intro.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match Ordering.eq with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.eq with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
[PROOFSTEP]
have h_glue := Valid'.glue h.left h.right h.bal.1
[GOAL]
case node.intro.intro.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_glue : Valid' a₁ (Ordnode.glue t_l t_r) a₂ ∧ size (Ordnode.glue t_l t_r) = size t_l + size t_r
⊢ Valid' a₁
      (match Ordering.eq with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.eq with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
[PROOFSTEP]
cases' h_glue with h_glue_valid h_glue_sized
[GOAL]
case node.intro.intro.eq.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_glue_valid : Valid' a₁ (Ordnode.glue t_l t_r) a₂
h_glue_sized : size (Ordnode.glue t_l t_r) = size t_l + size t_r
⊢ Valid' a₁
      (match Ordering.eq with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.eq with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.eq.intro.left
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_glue_valid : Valid' a₁ (Ordnode.glue t_l t_r) a₂
h_glue_sized : size (Ordnode.glue t_l t_r) = size t_l + size t_r
⊢ Valid' a₁
    (match Ordering.eq with
    | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
    | Ordering.eq => Ordnode.glue t_l t_r
    | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
    a₂
[PROOFSTEP]
exact h_glue_valid
[GOAL]
case node.intro.intro.eq.intro.right
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_glue_valid : Valid' a₁ (Ordnode.glue t_l t_r) a₂
h_glue_sized : size (Ordnode.glue t_l t_r) = size t_l + size t_r
⊢ Raised
    (size
      (match Ordering.eq with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
    (size t_l + size t_r + 1)
[PROOFSTEP]
right
[GOAL]
case node.intro.intro.eq.intro.right.h
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_glue_valid : Valid' a₁ (Ordnode.glue t_l t_r) a₂
h_glue_sized : size (Ordnode.glue t_l t_r) = size t_l + size t_r
⊢ size t_l + size t_r + 1 =
    size
        (match Ordering.eq with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)) +
      1
[PROOFSTEP]
rw [h_glue_sized]
[GOAL]
case node.intro.intro.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Valid' a₁
      (match Ordering.gt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.gt with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
[PROOFSTEP]
suffices h_balanceable
[GOAL]
case node.intro.intro.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable : ?m.391865
⊢ Valid' a₁
      (match Ordering.gt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
      a₂ ∧
    Raised
      (size
        (match Ordering.gt with
        | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
        | Ordering.eq => Ordnode.glue t_l t_r
        | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
      (size t_l + size t_r + 1)
case h_balanceable
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ ?m.391865
[PROOFSTEP]
constructor
[GOAL]
case node.intro.intro.gt.left
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable : ?m.391865
⊢ Valid' a₁
    (match Ordering.gt with
    | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
    | Ordering.eq => Ordnode.glue t_l t_r
    | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r))
    a₂
[PROOFSTEP]
exact Valid'.balanceL h.left t_r_valid h_balanceable
[GOAL]
case node.intro.intro.gt.right
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised l' (size t_l) ∧ BalancedSz l' (size (erase x t_r))) ∨
    ∃ r', Raised (size (erase x t_r)) r' ∧ BalancedSz (size t_l) r'
⊢ Raised
    (size
      (match Ordering.gt with
      | Ordering.lt => Ordnode.balanceR (erase x t_l) t_x t_r
      | Ordering.eq => Ordnode.glue t_l t_r
      | Ordering.gt => Ordnode.balanceL t_l t_x (erase x t_r)))
    (size t_l + size t_r + 1)
[PROOFSTEP]
rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
[GOAL]
case node.intro.intro.gt.right
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised l' (size t_l) ∧ BalancedSz l' (size (erase x t_r))) ∨
    ∃ r', Raised (size (erase x t_r)) r' ∧ BalancedSz (size t_l) r'
⊢ Raised (size t_l + size (erase x t_r) + 1) (size t_l + size t_r + 1)
[PROOFSTEP]
apply Raised.add_right
[GOAL]
case node.intro.intro.gt.right.H
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised l' (size t_l) ∧ BalancedSz l' (size (erase x t_r))) ∨
    ∃ r', Raised (size (erase x t_r)) r' ∧ BalancedSz (size t_l) r'
⊢ Raised (size t_l + size (erase x t_r)) (size t_l + size t_r)
[PROOFSTEP]
apply Raised.add_left
[GOAL]
case node.intro.intro.gt.right.H.H
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_balanceable :
  (∃ l', Raised l' (size t_l) ∧ BalancedSz l' (size (erase x t_r))) ∨
    ∃ r', Raised (size (erase x t_r)) r' ∧ BalancedSz (size t_l) r'
⊢ Raised (size (erase x t_r)) (size t_r)
[PROOFSTEP]
exact t_r_size
[GOAL]
case h_balanceable
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ (∃ l', Raised l' (size t_l) ∧ BalancedSz l' (size (erase x t_r))) ∨
    ∃ r', Raised (size (erase x t_r)) r' ∧ BalancedSz (size t_l) r'
[PROOFSTEP]
right
[GOAL]
case h_balanceable.h
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ ∃ r', Raised (size (erase x t_r)) r' ∧ BalancedSz (size t_l) r'
[PROOFSTEP]
exists t_r.size
[GOAL]
case h_balanceable.h
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (Ordnode.node size✝ t_l t_x t_r) a₂
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ Raised (size (erase x t_r)) (size t_r) ∧ BalancedSz (size t_l) (size t_r)
[PROOFSTEP]
exact And.intro t_r_size h.bal.1
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ t a₂
h_mem : x ∈ t
⊢ size (erase x t) = size t - 1
[PROOFSTEP]
induction t generalizing a₁ a₂ with
| nil => contradiction
| node _ t_l t_x t_r t_ih_l t_ih_r =>
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  dsimp only [Membership.mem, mem] at h_mem
  unfold erase
  revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢
  · have t_ih_l := t_ih_l' h_mem
    clear t_ih_l' t_ih_r'
    have t_l_h := Valid'.erase_aux x h.left
    cases' t_l_h with t_l_valid t_l_size
    rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
        (Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
    rw [t_ih_l, h.sz.1]
    have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
    revert h_pos_t_l_size; cases' t_l.size with t_l_size <;> intro h_pos_t_l_size
    · cases h_pos_t_l_size
    · simp [Nat.succ_add]
  · rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl
  · have t_ih_r := t_ih_r' h_mem
    clear t_ih_l' t_ih_r'
    have t_r_h := Valid'.erase_aux x h.right
    cases' t_r_h with t_r_valid t_r_size
    rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
        (Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
    rw [t_ih_r, h.sz.1]
    have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
    revert h_pos_t_r_size; cases' t_r.size with t_r_size <;> intro h_pos_t_r_size
    · cases h_pos_t_r_size
    · simp [Nat.succ_add, Nat.add_succ]
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ t a₂
h_mem : x ∈ t
⊢ size (erase x t) = size t - 1
[PROOFSTEP]
induction t generalizing a₁ a₂ with
| nil => contradiction
| node _ t_l t_x t_r t_ih_l t_ih_r =>
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  dsimp only [Membership.mem, mem] at h_mem
  unfold erase
  revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢
  · have t_ih_l := t_ih_l' h_mem
    clear t_ih_l' t_ih_r'
    have t_l_h := Valid'.erase_aux x h.left
    cases' t_l_h with t_l_valid t_l_size
    rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
        (Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
    rw [t_ih_l, h.sz.1]
    have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
    revert h_pos_t_l_size; cases' t_l.size with t_l_size <;> intro h_pos_t_l_size
    · cases h_pos_t_l_size
    · simp [Nat.succ_add]
  · rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl
  · have t_ih_r := t_ih_r' h_mem
    clear t_ih_l' t_ih_r'
    have t_r_h := Valid'.erase_aux x h.right
    cases' t_r_h with t_r_valid t_r_size
    rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
        (Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
    rw [t_ih_r, h.sz.1]
    have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
    revert h_pos_t_r_size; cases' t_r.size with t_r_size <;> intro h_pos_t_r_size
    · cases h_pos_t_r_size
    · simp [Nat.succ_add, Nat.add_succ]
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
h_mem : x ∈ nil
⊢ size (erase x nil) = size nil - 1
[PROOFSTEP]

| nil => contradiction
[GOAL]
case nil
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ nil a₂
h_mem : x ∈ nil
⊢ size (erase x nil) = size nil - 1
[PROOFSTEP]
contradiction
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_l a₂ → x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_r a₂ → x ∈ t_r → size (erase x t_r) = size t_r - 1
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : x ∈ node size✝ t_l t_x t_r
⊢ size (erase x (node size✝ t_l t_x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]

| node _ t_l t_x t_r t_ih_l t_ih_r =>
  have t_ih_l' := t_ih_l h.left
  have t_ih_r' := t_ih_r h.right
  clear t_ih_l t_ih_r
  dsimp only [Membership.mem, mem] at h_mem
  unfold erase
  revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢
  · have t_ih_l := t_ih_l' h_mem
    clear t_ih_l' t_ih_r'
    have t_l_h := Valid'.erase_aux x h.left
    cases' t_l_h with t_l_valid t_l_size
    rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
        (Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
    rw [t_ih_l, h.sz.1]
    have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
    revert h_pos_t_l_size; cases' t_l.size with t_l_size <;> intro h_pos_t_l_size
    · cases h_pos_t_l_size
    · simp [Nat.succ_add]
  · rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl
  · have t_ih_r := t_ih_r' h_mem
    clear t_ih_l' t_ih_r'
    have t_r_h := Valid'.erase_aux x h.right
    cases' t_r_h with t_r_valid t_r_size
    rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
        (Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
    rw [t_ih_r, h.sz.1]
    have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
    revert h_pos_t_r_size; cases' t_r.size with t_r_size <;> intro h_pos_t_r_size
    · cases h_pos_t_r_size
    · simp [Nat.succ_add, Nat.add_succ]
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_l a₂ → x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_r a₂ → x ∈ t_r → size (erase x t_r) = size t_r - 1
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : x ∈ node size✝ t_l t_x t_r
⊢ size (erase x (node size✝ t_l t_x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
have t_ih_l' := t_ih_l h.left
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_l a₂ → x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_r a₂ → x ∈ t_r → size (erase x t_r) = size t_r - 1
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : x ∈ node size✝ t_l t_x t_r
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
⊢ size (erase x (node size✝ t_l t_x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
have t_ih_r' := t_ih_r h.right
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
t_ih_l : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_l a₂ → x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r : ∀ {a₁ : WithBot α} {a₂ : WithTop α}, Valid' a₁ t_r a₂ → x ∈ t_r → size (erase x t_r) = size t_r - 1
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : x ∈ node size✝ t_l t_x t_r
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ size (erase x (node size✝ t_l t_x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
clear t_ih_l t_ih_r
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : x ∈ node size✝ t_l t_x t_r
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ size (erase x (node size✝ t_l t_x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
dsimp only [Membership.mem, mem] at h_mem
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem :
  (match cmpLE x t_x with
    | Ordering.lt => mem x t_l
    | Ordering.eq => true
    | Ordering.gt => mem x t_r) =
    true
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ size (erase x (node size✝ t_l t_x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
unfold erase
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem :
  (match cmpLE x t_x with
    | Ordering.lt => mem x t_l
    | Ordering.eq => true
    | Ordering.gt => mem x t_r) =
    true
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ size
      (match cmpLE x t_x with
      | Ordering.lt => balanceR (erase x t_l) t_x t_r
      | Ordering.eq => glue t_l t_r
      | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
    size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
revert h_mem
[GOAL]
case node
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ (match cmpLE x t_x with
      | Ordering.lt => mem x t_l
      | Ordering.eq => true
      | Ordering.gt => mem x t_r) =
      true →
    size
        (match cmpLE x t_x with
        | Ordering.lt => balanceR (erase x t_l) t_x t_r
        | Ordering.eq => glue t_l t_r
        | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
      size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
cases cmpLE x t_x
[GOAL]
case node.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ (match Ordering.lt with
      | Ordering.lt => mem x t_l
      | Ordering.eq => true
      | Ordering.gt => mem x t_r) =
      true →
    size
        (match Ordering.lt with
        | Ordering.lt => balanceR (erase x t_l) t_x t_r
        | Ordering.eq => glue t_l t_r
        | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
      size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
intro h_mem
[GOAL]
case node.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ (match Ordering.eq with
      | Ordering.lt => mem x t_l
      | Ordering.eq => true
      | Ordering.gt => mem x t_r) =
      true →
    size
        (match Ordering.eq with
        | Ordering.lt => balanceR (erase x t_l) t_x t_r
        | Ordering.eq => glue t_l t_r
        | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
      size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
intro h_mem
[GOAL]
case node.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
⊢ (match Ordering.gt with
      | Ordering.lt => mem x t_l
      | Ordering.eq => true
      | Ordering.gt => mem x t_r) =
      true →
    size
        (match Ordering.gt with
        | Ordering.lt => balanceR (erase x t_l) t_x t_r
        | Ordering.eq => glue t_l t_r
        | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
      size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
intro h_mem
[GOAL]
case node.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem :
  (match Ordering.lt with
    | Ordering.lt => mem x t_l
    | Ordering.eq => true
    | Ordering.gt => mem x t_r) =
    true
⊢ size
      (match Ordering.lt with
      | Ordering.lt => balanceR (erase x t_l) t_x t_r
      | Ordering.eq => glue t_l t_r
      | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
    size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
dsimp only at h_mem ⊢
[GOAL]
case node.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem :
  (match Ordering.eq with
    | Ordering.lt => mem x t_l
    | Ordering.eq => true
    | Ordering.gt => mem x t_r) =
    true
⊢ size
      (match Ordering.eq with
      | Ordering.lt => balanceR (erase x t_l) t_x t_r
      | Ordering.eq => glue t_l t_r
      | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
    size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
dsimp only at h_mem ⊢
[GOAL]
case node.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem :
  (match Ordering.gt with
    | Ordering.lt => mem x t_l
    | Ordering.eq => true
    | Ordering.gt => mem x t_r) =
    true
⊢ size
      (match Ordering.gt with
      | Ordering.lt => balanceR (erase x t_l) t_x t_r
      | Ordering.eq => glue t_l t_r
      | Ordering.gt => balanceL t_l t_x (erase x t_r)) =
    size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
dsimp only at h_mem ⊢
[GOAL]
case node.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem : mem x t_l = true
⊢ size (balanceR (erase x t_l) t_x t_r) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
have t_ih_l := t_ih_l' h_mem
[GOAL]
case node.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
⊢ size (balanceR (erase x t_l) t_x t_r) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
clear t_ih_l' t_ih_r'
[GOAL]
case node.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
⊢ size (balanceR (erase x t_l) t_x t_r) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
have t_l_h := Valid'.erase_aux x h.left
[GOAL]
case node.lt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_h : Valid' a₁ (erase x t_l) ↑t_x ∧ Raised (size (erase x t_l)) (size t_l)
⊢ size (balanceR (erase x t_l) t_x t_r) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
cases' t_l_h with t_l_valid t_l_size
[GOAL]
case node.lt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
⊢ size (balanceR (erase x t_l) t_x t_r) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
    (Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
[GOAL]
case node.lt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
⊢ size (erase x t_l) + size t_r + 1 = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
rw [t_ih_l, h.sz.1]
[GOAL]
case node.lt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
⊢ size t_l - 1 + size t_r + 1 = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
[GOAL]
case node.lt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
h_pos_t_l_size : 0 < size t_l
⊢ size t_l - 1 + size t_r + 1 = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
revert h_pos_t_l_size
[GOAL]
case node.lt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
⊢ 0 < size t_l → size t_l - 1 + size t_r + 1 = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
cases' t_l.size with t_l_size
[GOAL]
case node.lt.intro.zero
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
⊢ 0 < Nat.zero → Nat.zero - 1 + size t_r + 1 = size (node (Nat.zero + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
intro h_pos_t_l_size
[GOAL]
case node.lt.intro.succ
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size✝ : Raised (size (erase x t_l)) (size t_l)
t_l_size : ℕ
⊢ 0 < Nat.succ t_l_size →
    Nat.succ t_l_size - 1 + size t_r + 1 = size (node (Nat.succ t_l_size + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
intro h_pos_t_l_size
[GOAL]
case node.lt.intro.zero
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size : Raised (size (erase x t_l)) (size t_l)
h_pos_t_l_size : 0 < Nat.zero
⊢ Nat.zero - 1 + size t_r + 1 = size (node (Nat.zero + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
cases h_pos_t_l_size
[GOAL]
case node.lt.intro.succ
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_l = true
t_ih_l : size (erase x t_l) = size t_l - 1
t_l_valid : Valid' a₁ (erase x t_l) ↑t_x
t_l_size✝ : Raised (size (erase x t_l)) (size t_l)
t_l_size : ℕ
h_pos_t_l_size : 0 < Nat.succ t_l_size
⊢ Nat.succ t_l_size - 1 + size t_r + 1 = size (node (Nat.succ t_l_size + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
simp [Nat.succ_add]
[GOAL]
case node.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem : true = true
⊢ size (glue t_l t_r) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]
[GOAL]
case node.eq
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem : true = true
⊢ size t_l + size t_r = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
rfl
[GOAL]
case node.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem : mem x t_r = true
⊢ size (balanceL t_l t_x (erase x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
have t_ih_r := t_ih_r' h_mem
[GOAL]
case node.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
t_ih_l' : x ∈ t_l → size (erase x t_l) = size t_l - 1
t_ih_r' : x ∈ t_r → size (erase x t_r) = size t_r - 1
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
⊢ size (balanceL t_l t_x (erase x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
clear t_ih_l' t_ih_r'
[GOAL]
case node.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
⊢ size (balanceL t_l t_x (erase x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
have t_r_h := Valid'.erase_aux x h.right
[GOAL]
case node.gt
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_h : Valid' (↑t_x) (erase x t_r) a₂ ∧ Raised (size (erase x t_r)) (size t_r)
⊢ size (balanceL t_l t_x (erase x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
cases' t_r_h with t_r_valid t_r_size
[GOAL]
case node.gt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ size (balanceL t_l t_x (erase x t_r)) = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
    (Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
[GOAL]
case node.gt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ size t_l + size (erase x t_r) + 1 = size (node size✝ t_l t_x t_r) - 1
[PROOFSTEP]
rw [t_ih_r, h.sz.1]
[GOAL]
case node.gt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ size t_l + (size t_r - 1) + 1 = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
[GOAL]
case node.gt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_pos_t_r_size : 0 < size t_r
⊢ size t_l + (size t_r - 1) + 1 = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
revert h_pos_t_r_size
[GOAL]
case node.gt.intro
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ 0 < size t_r → size t_l + (size t_r - 1) + 1 = size (node (size t_l + size t_r + 1) t_l t_x t_r) - 1
[PROOFSTEP]
cases' t_r.size with t_r_size
[GOAL]
case node.gt.intro.zero
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
⊢ 0 < Nat.zero → size t_l + (Nat.zero - 1) + 1 = size (node (size t_l + Nat.zero + 1) t_l t_x t_r) - 1
[PROOFSTEP]
intro h_pos_t_r_size
[GOAL]
case node.gt.intro.succ
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size✝ : Raised (size (erase x t_r)) (size t_r)
t_r_size : ℕ
⊢ 0 < Nat.succ t_r_size →
    size t_l + (Nat.succ t_r_size - 1) + 1 = size (node (size t_l + Nat.succ t_r_size + 1) t_l t_x t_r) - 1
[PROOFSTEP]
intro h_pos_t_r_size
[GOAL]
case node.gt.intro.zero
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size : Raised (size (erase x t_r)) (size t_r)
h_pos_t_r_size : 0 < Nat.zero
⊢ size t_l + (Nat.zero - 1) + 1 = size (node (size t_l + Nat.zero + 1) t_l t_x t_r) - 1
[PROOFSTEP]
cases h_pos_t_r_size
[GOAL]
case node.gt.intro.succ
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
size✝ : ℕ
t_l : Ordnode α
t_x : α
t_r : Ordnode α
a₁ : WithBot α
a₂ : WithTop α
h : Valid' a₁ (node size✝ t_l t_x t_r) a₂
h_mem : mem x t_r = true
t_ih_r : size (erase x t_r) = size t_r - 1
t_r_valid : Valid' (↑t_x) (erase x t_r) a₂
t_r_size✝ : Raised (size (erase x t_r)) (size t_r)
t_r_size : ℕ
h_pos_t_r_size : 0 < Nat.succ t_r_size
⊢ size t_l + (Nat.succ t_r_size - 1) + 1 = size (node (size t_l + Nat.succ t_r_size + 1) t_l t_x t_r) - 1
[PROOFSTEP]
simp [Nat.succ_add, Nat.add_succ]
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : Ordset α
h : s = ∅
⊢ empty ↑s = true
[PROOFSTEP]
cases h
[GOAL]
case refl
α : Type u_1
inst✝ : Preorder α
⊢ empty ↑∅ = true
[PROOFSTEP]
exact rfl
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : Ordset α
h : empty ↑s = true
⊢ s = ∅
[PROOFSTEP]
cases s with
| mk s_val _ => cases s_val <;> [rfl; cases h]
[GOAL]
α : Type u_1
inst✝ : Preorder α
s : Ordset α
h : empty ↑s = true
⊢ s = ∅
[PROOFSTEP]
cases s with
| mk s_val _ => cases s_val <;> [rfl; cases h]
[GOAL]
case mk
α : Type u_1
inst✝ : Preorder α
s_val : Ordnode α
property✝ : Valid s_val
h : empty ↑{ val := s_val, property := property✝ } = true
⊢ { val := s_val, property := property✝ } = ∅
[PROOFSTEP]

| mk s_val _ => cases s_val <;> [rfl; cases h]
[GOAL]
case mk
α : Type u_1
inst✝ : Preorder α
s_val : Ordnode α
property✝ : Valid s_val
h : empty ↑{ val := s_val, property := property✝ } = true
⊢ { val := s_val, property := property✝ } = ∅
[PROOFSTEP]
cases s_val <;> [rfl; cases h]
[GOAL]
case mk
α : Type u_1
inst✝ : Preorder α
s_val : Ordnode α
property✝ : Valid s_val
h : empty ↑{ val := s_val, property := property✝ } = true
⊢ { val := s_val, property := property✝ } = ∅
[PROOFSTEP]
cases s_val
[GOAL]
case mk.nil
α : Type u_1
inst✝ : Preorder α
property✝ : Valid Ordnode.nil
h : empty ↑{ val := Ordnode.nil, property := property✝ } = true
⊢ { val := Ordnode.nil, property := property✝ } = ∅
[PROOFSTEP]
rfl
[GOAL]
case mk.node
α : Type u_1
inst✝ : Preorder α
size✝ : ℕ
l✝ : Ordnode α
x✝ : α
r✝ : Ordnode α
property✝ : Valid (node size✝ l✝ x✝ r✝)
h : empty ↑{ val := node size✝ l✝ x✝ r✝, property := property✝ } = true
⊢ { val := node size✝ l✝ x✝ r✝, property := property✝ } = ∅
[PROOFSTEP]
cases h
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordset α
h_mem : x ∈ t
⊢ 0 < size t
[PROOFSTEP]
simp [Membership.mem, mem] at h_mem
[GOAL]
α : Type u_1
inst✝¹ : Preorder α
inst✝ : DecidableRel fun x x_1 => x ≤ x_1
x : α
t : Ordset α
h_mem : Ordnode.mem x ↑t = true
⊢ 0 < size t
[PROOFSTEP]
apply Ordnode.pos_size_of_mem t.property.sz h_mem