When I execute f[g[a, b]] /. f[g[l__]] :> f[l]
I get f[a, b]
as expected.
When I execute f[a + b] /. f[Plus[l__]] :> f[l]
I get f[a + b]
. (I expect f[a, b]
again)
Why? (Wolfram Mathematica 12.2.0)
This happens because Plus[l__]
evaluates to l__
before the pattern is even replaced. Try instead:
f[a + b] /. f[HoldPattern@Plus[l__]] :> f[l]
f[a + b] /. f[l_Plus]] :> f[l]
$\endgroup$
Commented
Mar 8, 2021 at 13:16
f[a + b]
, right?
$\endgroup$
Commented
Mar 8, 2021 at 13:20
f[Plus[a, b]] /. f[g_[l1__]] :> f[l1]
gives:f[a, b]
$\endgroup$