-- Mathlib/.lake/packages/batteries/Batteries/Data/HashMap/WF.lean
theorem erase_size [BEq α] [Hashable α] {m : Imp α β} {k}
    (h : m.size = m.buckets.size) :
    (erase m k).size = (erase m k).buckets.size

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
c✝ : Bool
H : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = true
w✝¹ w✝ : List (AssocList α β)
left✝ : w✝¹.length = (mkIdx ⋯ (hash k).toUSize).val.toNat
⊢ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList.length =
    (List.eraseP (fun x => x.fst == k) m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList).length + 1

Tactic:
simp only [AssocList.contains_eq, List.any_eq_true] at H

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
c✝ : Bool
w✝¹ w✝ : List (AssocList α β)
left✝ : w✝¹.length = (mkIdx ⋯ (hash k).toUSize).val.toNat
H : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
⊢ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList.length =
    (List.eraseP (fun x => x.fst == k) m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList).length + 1

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
⊢ (m.erase k).size = (m.erase k).buckets.size

Tactic:
dsimp [erase, cond]

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
⊢ (match AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] with
      | true =>
        { size := m.size - 1,
          buckets :=
            m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
              (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
      | false => { size := m.size, buckets := m.buckets }).size =
    (match AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] with
        | true =>
          { size := m.size - 1,
            buckets :=
              m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
                (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
        | false => { size := m.size, buckets := m.buckets }).buckets.size

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h✝ : m.size = m.buckets.size
c✝ : Bool
w✝⁴ w✝³ : List (AssocList α β)
left✝² : w✝⁴.length = (mkIdx ⋯ (hash k).toUSize).val.toNat
H : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
a : α × β
h₁ : a ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
h₂ : (a.fst == k) = true
w✝² : α × β
w✝¹ w✝ : List (α × β)
left✝¹ : ∀ (b : α × β), b ∈ w✝¹ → ¬(b.fst == k) = true
left✝ : (w✝².fst == k) = true
h : m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList = w✝¹ ++ w✝² :: w✝
eq : List.eraseP (fun x => x.fst == k) m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList = w✝¹ ++ w✝
⊢ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList.length = (w✝¹ ++ w✝).length + 1

Tactic:
simp [h]

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h✝ : m.size = m.buckets.size
c✝ : Bool
w✝⁴ w✝³ : List (AssocList α β)
left✝² : w✝⁴.length = (mkIdx ⋯ (hash k).toUSize).val.toNat
H : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
a : α × β
h₁ : a ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
h₂ : (a.fst == k) = true
w✝² : α × β
w✝¹ w✝ : List (α × β)
left✝¹ : ∀ (b : α × β), b ∈ w✝¹ → ¬(b.fst == k) = true
left✝ : (w✝².fst == k) = true
h : m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList = w✝¹ ++ w✝² :: w✝
eq : List.eraseP (fun x => x.fst == k) m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList = w✝¹ ++ w✝
⊢ w✝¹.length + (w✝.length + 1) = w✝¹.length + w✝.length + 1

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
⊢ (match AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] with
      | true =>
        { size := m.size - 1,
          buckets :=
            m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
              (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
      | false => { size := m.size, buckets := m.buckets }).size =
    (match AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] with
        | true =>
          { size := m.size - 1,
            buckets :=
              m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
                (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
        | false => { size := m.size, buckets := m.buckets }).buckets.size

Tactic:
split

Result:
case h_1
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
c✝ : Bool
heq✝ : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = true
⊢ { size := m.size - 1,
        buckets :=
          m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.size =
    { size := m.size - 1,
          buckets :=
            m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
              (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.buckets.size

case h_2
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
c✝ : Bool
heq✝ : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = false
⊢ { size := m.size, buckets := m.buckets }.size = { size := m.size, buckets := m.buckets }.buckets.size

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
c✝ : Bool
H : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = true
w✝¹ w✝ : List (AssocList α β)
h₁ : m.buckets.val.toList = w✝¹ ++ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val] :: w✝
left✝ : w✝¹.length = (mkIdx ⋯ (hash k).toUSize).val.toNat
eq :
  (m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
          (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯).val.toList =
    w✝¹ ++ AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] :: w✝
⊢ (List.map (fun x => x.toList.length) m.buckets.val.toList).sum - 1 =
    (List.map (fun x => x.toList.length)
        (w✝¹ ++ AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] :: w✝)).sum

Tactic:
simp only [h₁, Array.length_toList, Array.ugetElem_eq_getElem, List.map_append, List.map_cons,
  Nat.sum_append, List.sum_cons, AssocList.toList_erase]

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
h : m.size = m.buckets.size
c✝ : Bool
H : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = true
w✝¹ w✝ : List (AssocList α β)
h₁ : m.buckets.val.toList = w✝¹ ++ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val] :: w✝
left✝ : w✝¹.length = (mkIdx ⋯ (hash k).toUSize).val.toNat
eq :
  (m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
          (AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯).val.toList =
    w✝¹ ++ AssocList.erase k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] :: w✝
⊢ (List.map (fun x => x.toList.length) w✝¹).sum +
        (m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList.length +
          (List.map (fun x => x.toList.length) w✝).sum) -
      1 =
    (List.map (fun x => x.toList.length) w✝¹).sum +
      ((List.eraseP (fun x => x.fst == k) m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList).length +
        (List.map (fun x => x.toList.length) w✝).sum)