3
$\begingroup$

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$

$\endgroup$
1
  • $\begingroup$ What is the desired output? $\endgroup$
    – Syed
    Mar 29, 2022 at 15:05

2 Answers 2

5
$\begingroup$

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[1][x_] := x^2;
a'[x] /. a -> Function[x, b[1][x]]
$\endgroup$
5
$\begingroup$
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

enter image description here

$\endgroup$

Your Answer

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

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