I'm trying to pattern-match all the functions with head Sin
in list and replace their single input with a value.
Clear[a,x,y,z]
testList = {x, Sin[x], Sin[y],x^2*y, g[y,x], h[x,y,z], Cos[Tan[x]]}
testList /. f_Sin[a_] :> (f[a] /. a->10)
However, this is giving me
{x, Sin[x], Sin[y], x^2*y, g[y, x], h[x, y, z], Cos[Tan[x]]}
Why? What am I doing wrong?
testList /. Sin[_] -> Sin[10]
? $\endgroup$testList /. _Sin -> Sin[10]
$\endgroup$testList2 = {x, Sin[x], Sin[y][t], x^2*y, g[y, x], h[x, y, z], Cos[Tan[x]]}; testList2 /. f_Sin[a_] :> (f[a] /. a -> 10)
$\endgroup$_Sin
(and the patternf_Sin
) matches any expression with Head Sin, that is, expressionsSin[x]
andSin[y]
in yourtestList
. But the pattern_Sin[a_]
is any expression with Head Sin evaluated at a single argument and there are no such expressions in yourtestList
. $\endgroup$testList /. (f : Sin)[a_] :> (f[a] /. a -> 10)
to get the desired result. $\endgroup$