Once an association construction expression has been evaluated into an atom, the keys and values of the resulting atom are kept in held form. That is, they are not reevaluated after subsequent replacement rules have been applied.
There are various work-arounds.
Operate upon the Unevaluated Association Construction Expression
If the application permits it, performing the replacement before evaluating the association into an atom is a possibility:
Unevaluated@<|1 -> Cos[a - b]|> /. {a -> 0, b -> 0}
(* <|1 -> 1|> *)
But beware that this strategy will also affect the keys, something that does not normally happen when using ReplaceAll with association atoms:
<| a -> a |> /. a -> 1
(* <| a -> 1 |> *)
Unevaluated@<| a -> a |> /. a -> 1
(* <| 1 -> 1 |> *)
Operate upon the evaluated Association Atom
If we must work with an evaluated Association atom, then we can use Map[ReplaceAll[...]] to force reevaluation of replaced values:
$expr = <| Sin[a - b] -> Cos[a - b] |>;
$rules = {a -> 0, b -> 0};
$expr // Map[ReplaceAll[$rules]]
(* <| Sin[a - b] -> 1 |> *)
As noted before, such replacements only affect the values. Should we want affect both the keys and values, then we must use AssociationMap:
$expr // AssociationMap[ReplaceAll[$rules]]
(* <| 0 -> 1 |> *)
Should we wish to perform the replacement upon only a specific key of the association, we can use MapAt:
<| x -> Cos[a - b], y -> Cos[a - b] |> //
MapAt[ReplaceAll[{a -> 0, b -> 0}], #, Key[x]] &
(* <| x -> 1, y -> Cos[a - b] |> *)
<|1 -> Cos[a - b] /. {a -> 0, b -> 0}|>– Feb 18 '22 at 07:53Normalis far more elegant. – Feb 18 '22 at 07:55