# making a function including a derivative of other equations as variables [duplicate]

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!

• 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). Commented Aug 8, 2017 at 22:44
• @aardvark2012 I'm gonna try it, but strange behaviour! why should Mathematica do that?!