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

Proof state:
case refine_1
α : Type u_1
β : Type u_2
inst✝³ : BEq α
inst✝² : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
x : α × β
hx₁ : x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
hx₂ : (x.fst == k) = true
inst✝¹ : PartialEquivBEq α
inst✝ : LawfulHashable α
H : List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val].toList
⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true)
    (List.replaceF (fun x => bif x.fst == k then some (k, v) else none)
      m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList)

Tactic:
exact pairwise_replaceF H

Result:
no goals

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
v : β
h✝ : m.buckets.WF
c✝ : Bool
x a : α × β
h₁ : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash a.fst).toUSize).val.toNat].toList ∧ (x.fst == a.fst) = true
hx₁ : x ∈ m.buckets.val[(mkIdx ⋯ (hash a.fst).toUSize).val.toNat].toList
hx₂ : (x.fst == a.fst) = true
H :
  ∀ (a_1 : α × β),
    a_1 ∈ m.buckets.val[(mkIdx ⋯ (hash a.fst).toUSize).val.toNat].toList →
      ((hash a_1.fst).toUSize % USize.ofNat m.buckets.val.size).toNat = (mkIdx ⋯ (hash a.fst).toUSize).val.toNat
h :
  a ∈
    List.replaceF (fun x => bif x.fst == a.fst then some (a.fst, v) else none)
      m.buckets.val[(mkIdx ⋯ (hash a.fst).toUSize).val.toNat].toList
⊢ ((hash a.fst).toUSize % USize.ofNat m.buckets.val.size).toNat = (mkIdx ⋯ (hash a.fst).toUSize).val.toNat

Tactic:
rfl

Result:
no goals

Proof state:
case refine_2.head
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∀ (x : α × β), x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList → ¬(x.fst == k) = true
H :
  AssocList.All
    (fun k_1 x => ((hash k_1).toUSize % USize.ofNat m.buckets.val.size).toNat = (mkIdx ⋯ (hash k).toUSize).val.toNat)
    m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val]
⊢ ((hash (k, v).fst).toUSize % USize.ofNat m.buckets.val.size).toNat = (mkIdx ⋯ (hash k).toUSize).val.toNat

Tactic:
rfl

Result:
no goals

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
⊢ { size := m.size,
        buckets :=
          m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.replace k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.buckets.WF

Tactic:
have ⟨x, hx₁, hx₂⟩ := h₁

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
x : α × β
hx₁ : x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
hx₂ : (x.fst == k) = true
⊢ { size := m.size,
        buckets :=
          m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.replace k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.buckets.WF

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∀ (x : α × β), x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList → ¬(x.fst == k) = true
⊢ (if numBucketsForCapacity (m.size + 1) ≤ m.buckets.val.size then
        { size := m.size + 1,
          buckets :=
            m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
              (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
      else
        expand (m.size + 1)
          (m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯)).buckets.WF

Tactic:
suffices _ by split <;> [exact this; refine expand_WF this]

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∀ (x : α × β), x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList → ¬(x.fst == k) = true
⊢ { size := m.size + 1,
        buckets :=
          m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.buckets.WF

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
v : β
h✝¹ : m.buckets.WF
c✝ : Bool
x a : α × β
k : α
h : a ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
h₁ : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
hx₁ : x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
hx₂ : (x.fst == k) = true
H :
  ∀ (a : α × β),
    a ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList →
      ((hash a.fst).toUSize % USize.ofNat m.buckets.val.size).toNat = (mkIdx ⋯ (hash k).toUSize).val.toNat
h✝ :
  a ∈
    List.replaceF (fun x => bif x.fst == k then some (k, v) else none)
      m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList
⊢ ((hash a.fst).toUSize % USize.ofNat m.buckets.val.size).toNat = (mkIdx ⋯ (hash k).toUSize).val.toNat

Tactic:
exact H _ h

Result:
no goals

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = true
⊢ { size := m.size,
        buckets :=
          m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.replace k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.buckets.WF

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 : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : ∃ x, x ∈ m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat].toList ∧ (x.fst == k) = true
⊢ { size := m.size,
        buckets :=
          m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.replace k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }.buckets.WF

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] = false
⊢ (if numBucketsForCapacity (m.size + 1) ≤ m.buckets.val.size then
        { size := m.size + 1,
          buckets :=
            m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
              (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
      else
        expand (m.size + 1)
          (m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯)).buckets.WF

Tactic:
rw [Bool.eq_false_iff] at h₁

Result:
α : Type u_1
β : Type u_2
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
k : α
v : β
h : m.buckets.WF
c✝ : Bool
h₁ : AssocList.contains k m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat] ≠ true
⊢ (if numBucketsForCapacity (m.size + 1) ≤ m.buckets.val.size then
        { size := m.size + 1,
          buckets :=
            m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
              (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯ }
      else
        expand (m.size + 1)
          (m.buckets.update (mkIdx ⋯ (hash k).toUSize).val
            (AssocList.cons k v m.buckets.val[(mkIdx ⋯ (hash k).toUSize).val.toNat]) ⋯)).buckets.WF