# Why does the function replacement not work here?

why does the function replacement not work here?

b[1, x_] := x^2;
a'[x] /. a -> Function[x, b[1, x]]


gives $$b^{(0,1)}(1,x)$$ without evaluating further.

I would like the output to be $$2x$$

• What is the desired output?
– Syed
Mar 29, 2022 at 15:05

Mathematica can't (won't) calculate the partial derivative of the function b, if it does not know what it does for general values of all inputs.

If the other input is not meant to be a variable (but say a parameter in the function), the following definition works:

b[x_] := x^2;
a'[x] /. a -> Function[x, b[x]]

b[1, x_] := x^2;

a'[x] /. a -> Function[x, Evaluate @ b[1, x]]

2 x


### "why does the function replacement not work here?"

Attributes[Function]

{HoldAll, Protected}


That is, "all arguments to Function are to be maintained in an unevaluated form".

Wrapping body in Function[arg, body] with Evaluate causes body "to be evaluated even if it appears as the argument of a function whose attributes specify that it should be held unevaluated."

Use Trace to see why we get $$b^{(0,1)}(1,x)$$ when we don't force evaluation of b[1, x]:

a'[x] /. a -> Function[x, b[1, x]] // Trace // Column 