-- Mathlib/.lake/packages/lean4/src/lean/Std/Data/DHashMap/Internal/List/Associative.lean
theorem getKeyD_alterKey {k k' fallback : α} {f : Option (β k) → Option (β k)}
    (l : List ((a : α) × β a)) (hl : DistinctKeys l) :
    getKeyD k' (alterKey k f l) fallback =
      if k == k' then
        if (f (getValueCast? k l)).isSome then k else fallback
      else
        getKeyD k' l fallback

Proof state:
case refl
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
heq : (k == k) = true
⊢ (if (f (getValueCast? k l)).isSome = true then some k else none).getD fallback =
    if (f (getValueCast? k l)).isSome = true then k else fallback

Tactic:
split <;> rfl

Result:
no goals

Proof state:
case isTrue
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
h✝ : (k == k') = true
⊢ (if (f (getValueCast? k l)).isSome = true then some k else none).getD fallback =
    if (f (getValueCast? k l)).isSome = true then k else fallback

Tactic:
next heq =>
cases eq_of_beq heq
split <;> rfl

Result:
no goals

Proof state:
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
⊢ getKeyD k' (alterKey k f l) fallback =
    if (k == k') = true then if (f (getValueCast? k l)).isSome = true then k else fallback else getKeyD k' l fallback

Tactic:
simp only [hl, getKeyD_eq_getKey?, getKey?_alterKey, beq_iff_eq, Function.comp_apply]

Result:
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
⊢ (if (k == k') = true then if (f (getValueCast? k l)).isSome = true then some k else none else getKey? k' l).getD
      fallback =
    if (k == k') = true then if (f (getValueCast? k l)).isSome = true then k else fallback
    else (getKey? k' l).getD fallback

Proof state:
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
heq : (k == k') = true
⊢ (if (f (getValueCast? k l)).isSome = true then some k else none).getD fallback =
    if (f (getValueCast? k l)).isSome = true then k else fallback

Tactic:
cases eq_of_beq heq

Result:
case refl
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
heq : (k == k) = true
⊢ (if (f (getValueCast? k l)).isSome = true then some k else none).getD fallback =
    if (f (getValueCast? k l)).isSome = true then k else fallback

Proof state:
case isFalse
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
h✝ : ¬(k == k') = true
⊢ (getKey? k' l).getD fallback = (getKey? k' l).getD fallback

Tactic:
rfl

Result:
no goals

Proof state:
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
⊢ (if (k == k') = true then if (f (getValueCast? k l)).isSome = true then some k else none else getKey? k' l).getD
      fallback =
    if (k == k') = true then if (f (getValueCast? k l)).isSome = true then k else fallback
    else (getKey? k' l).getD fallback

Tactic:
split

Result:
case isTrue
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
h✝ : (k == k') = true
⊢ (if (f (getValueCast? k l)).isSome = true then some k else none).getD fallback =
    if (f (getValueCast? k l)).isSome = true then k else fallback

case isFalse
α : Type u
β : α → Type v
inst✝¹ : BEq α
inst✝ : LawfulBEq α
k k' fallback : α
f : Option (β k) → Option (β k)
l : List ((a : α) × β a)
hl : DistinctKeys l
h✝ : ¬(k == k') = true
⊢ (getKey? k' l).getD fallback = (getKey? k' l).getD fallback