0
$\begingroup$

I'm trying to make a function where I'm making a derivative of a polynomial but it does not work as I expect. Consider this example

poly1=a*x^2 + t
poly2=D[poly1,x]
fun1[x_,t_]:=D[a*x^2 + t,x]
fun2[x_,t_]:=D[poly1,x]
fun3[x_,t_]:=poly2

now if I put

fun1[y,z]

or

fun3[y,z]

the result is what I want/expect:

$2ay$

but if I put

fun2[y,z]

the result is

$0$

Why is that?

I have a very long polynomial which I want to define as a function of derivatives of some polynomials of x and t. how I can solve the issue?

P.S. I have absolutely no idea what should I put as tag here!

$\endgroup$
3
  • 2
    $\begingroup$ When you pass y to fun2 in the x slot, it tries to differentiate poly1 with respect to y, which of course is zero. It works if you make poly1 a function: poly1[x_, t_] := a*x^2 + t (and call it appropriately). $\endgroup$ Commented Aug 8, 2017 at 22:44
  • $\begingroup$ @aardvark2012 I'm gonna try it, but strange behaviour! why should Mathematica do that?! $\endgroup$
    – Foad
    Commented Aug 8, 2017 at 23:06
  • 2
    $\begingroup$ You should read tutorial/ImmediateAndDelayedDefinitions, but this behavior is entirely logical and consistent. $\endgroup$ Commented Aug 9, 2017 at 1:53

0