-- Mathlib/.lake/packages/lean4/src/lean/Std/Data/DHashMap/Internal/WF.lean
theorem toListModel_alterₘ [BEq α] [Hashable α] [LawfulBEq α] {m : Raw₀ α β} (h : Raw.WFImp m.1)
    {a : α} {f : Option (β a) → Option (β a)} :
    Perm (toListModel (m.alterₘ a f).1.2) (alterKey a f (toListModel m.1.2))

Proof state:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
⊢ toListModel
      (match f none with
          | none => m
          | some b => (m.consₘ a b).expandIfNecessary).val.buckets ~
    alterKey a f (toListModel m.val.buckets)

Tactic:
rw [alterKey, getValueCast?_eq_none hc]

Result:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
⊢ toListModel
      (match f none with
          | none => m
          | some b => (m.consₘ a b).expandIfNecessary).val.buckets ~
    match f none with
    | none => eraseKey a (toListModel m.val.buckets)
    | some v => insertEntry a v (toListModel m.val.buckets)

Proof state:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
⊢ toListModel
      (match f none with
          | none => m
          | some b => (m.consₘ a b).expandIfNecessary).val.buckets ~
    match f none with
    | none => eraseKey a (toListModel m.val.buckets)
    | some v => insertEntry a v (toListModel m.val.buckets)

Tactic:
split

Result:
case h_1
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
heq✝ : f none = none
⊢ toListModel m.val.buckets ~
    match f none with
    | none => eraseKey a (toListModel m.val.buckets)
    | some v => insertEntry a v (toListModel m.val.buckets)

case h_2
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
b✝ : β a
heq✝ : f none = some b✝
⊢ toListModel (m.consₘ a b✝).expandIfNecessary.val.buckets ~
    match f none with
    | none => eraseKey a (toListModel m.val.buckets)
    | some v => insertEntry a v (toListModel m.val.buckets)

Proof state:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
b✝ : β a
hs : f none = some b✝
⊢ toListModel (m.consₘ a b✝).val.buckets ~ insertEntry a b✝ (toListModel m.val.buckets)

Tactic:
refine Perm.trans (toListModel_consₘ m h _ _) ?_

Result:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
b✝ : β a
hs : f none = some b✝
⊢ ⟨a, b✝⟩ :: toListModel m.val.buckets ~ insertEntry a b✝ (toListModel m.val.buckets)

Proof state:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
hn : f none = none
⊢ toListModel m.val.buckets ~ eraseKey a (toListModel m.val.buckets)

Tactic:
rw [eraseKey_of_containsKey_eq_false]

Result:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
hn : f none = none
⊢ containsKey a (toListModel m.val.buckets) = false

Proof state:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
b✝ : β a
hs : f none = some b✝
⊢ ⟨a, b✝⟩ :: toListModel m.val.buckets ~ insertEntry a b✝ (toListModel m.val.buckets)

Tactic:
rw [insertEntry_of_containsKey_eq_false]

Result:
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
hc : containsKey a (toListModel m.val.buckets) = false
x✝ : Option (β a)
b✝ : β a
hs : f none = some b✝
⊢ containsKey a (toListModel m.val.buckets) = false

Proof state:
case isTrue
α : Type u
β : α → Type v
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : LawfulBEq α
m : Raw₀ α β
h : Raw.WFImp m.val
a : α
f : Option (β a) → Option (β a)
h✝ : m.containsₘ a = true
⊢ toListModel
      (let buckets' := updateBucket m.val.buckets ⋯ a fun l => AssocList.alter a f l;
          let size' := if containsₘ ⟨withComputedSize buckets', ⋯⟩ a = true then m.val.size else m.val.size - 1;
          ⟨{ size := size', buckets := buckets' }, ⋯⟩).val.buckets ~
    alterKey a f (toListModel m.val.buckets)

Tactic:
exact toListModel_updateBucket_alter h

Result:
no goals