# How can I avoid a scoping problem when differentiating?

I simplify my real problem as follows:

I define a rule function as

Clear[rule];
rule[i_] := tt -> i;


the real rule function is not this simple.

I define a matrix function as

Clear[hh];
hh[x_, y_, i_] := {{tt, x}, {y, 1}}/. rule[i];


I want to define a function hhpar that will differentiate hh with respect to x, so I write

Clear[hhpar];
hhpar[x_, y_, i_] := D[hh[x, y, i], x];


This doesn't work and I know why. But I still can't figure out a way to write a proper hhpar. How would I do that?

• Derivative[1, 0, 0][hh][x, y, i] is equivalent to D[hh[x, y, i], x], but now you don't have to write x explicitly, so it avoids the problem. – Szabolcs Jul 6 '14 at 2:33
• @Szabolcs Wow! So quick! Thank you very much! This works, and I thought I known the reason, but it terms out that I actually didn't know the true reason is x at that time. – matheorem Jul 6 '14 at 3:11

For the sake of an answer:

Derivative[1, 0, 0][hh][x, y, i] is equivalent to D[hh[x, y, i], x], but now you don't have to write x explicitly, so it avoids the problem. – Szabolcs Jul 6 '14 at 2:33