Consider an expression of type


and a set of replacement rules


If I evaluate now the expression


the output will be


However, I need that the arguments of f are left unevaluated after the replacement rules are applied. In particular, I need my output to be


I tried with HoldAllComplete and similars as attributes to f, but this seems not to work


1 Answer 1


You can change your rule slightly to reflect the fact that you want to leave the f expression unchanged:

f[a, b] + a + b /. {expr : f[__] :> expr, a -> 1, b -> 2}

3 + f[a, b]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.