# Simple ways to evaluate a derivative at a point?

The contrast in behavior between, say,

f[x_] = Sin[x^2];
f'[2]


vs.

u[x_, y_] = Cos[x + y^2];


has always bothered my students---and me! (Why does it do it this way?)

Anyway, I tell them to handle ${\partial u\over \partial x}\Big|_{x=2}$ via

Is this the "simplest" way? How else might we accomplish this?

I realize that this is a subjective question, but our context is this is a class where we use Mathematica as a tool rather than a class centered on Mathematica itself. Thus, I want to keep the commands and code required as reasonably elementary as possible (and preferably resembling their paper-and-pencil mathematical work).

-
Seems to be a dupe of this; anyway, look up SeriesCoefficient[]. –  Ｊ. Ｍ. Nov 10 '12 at 17:09
@texasAUtiger I have edited your question; but in the process may be answered it? In other words what's wrong with Derivative[1, 0][u][2, y]? –  chris Nov 10 '12 at 17:20
@J. M.: I see what you mean, but unlike the first answer in the link I don't want to appeal to limits since we aren't emphasizing what a partial derivative is but rather just need to evaluate partials at values to accomplish other things. The second answer does address the issue, but I'd say the code is more complicated than a replacement rule. YMMV of course. –  JohnD Nov 10 '12 at 17:21
@chris: Indeed I think you have. I re-edited it to show what I do, leaving you room to formally answer the question with what you had. I just did not know that Derivative[...] functioned differently than using the partial symbol in the palette (at least in the sense here). –  JohnD Nov 10 '12 at 17:29
Related: Wolfram Blog By the way, do you understand why there is contrast in behavior? –  Vitaliy Kaurov Nov 10 '12 at 18:22

You could use as input:

 Derivative[1, 0][u][2, y]


You can implement the formating rule (Thanks to @Rojo)

 Format[Derivative[i_, j_][a_]] := Row[{"\[PartialD]"^(i + j), a}]/
Row[Row[{"\[PartialD]", #}] & /@ {"x"^i, "y"^j}]
Format[(h : Derivative[i_, j_][a_])[x0_, y0_]] :=
RawBoxes@SubscriptBox[RowBox[{MakeBoxes@h, "\[VerticalLine]"}],
MakeBoxes@Row[{Row[{x, "=", x0}], ",", Row[{y, "=", y0}]}]]


so that

   Derivative[1, 2][u][2, 3]


returns

Note that I arbitrary assumed the variables were x,y since I have no way to know from the input alone what the variables are.

This solution also works with input such as

Derivative[1, 2][f][1, x]


Derivative[0, 0][f][1, 3]


Derivative[2, 0][f][1, 3]


More generally, provided you use (from @Jens see link below)

Derivative /:
MakeBoxes[Derivative[\[Alpha]__][f1_][vars__Symbol],
Module[{bb, dd, sp},
MakeBoxes[dd, _] ^=
If[Length[{\[Alpha]}] == 1, "\[DifferentialD]", "\[PartialD]"];
MakeBoxes[sp, _] ^= "\[ThinSpace]";
bb /: MakeBoxes[bb[x__], _] := RowBox[Map[ToBoxes[#] &, {x}]];
FractionBox[ToBoxes[bb[dd^Plus[\[Alpha]], f1]],
ToBoxes[Apply[bb,  Riffle[Map[bb[dd, #] &,
Select[({vars}^{\[Alpha]}), (# =!= 1 &)]], sp]]]]]

D[u[x,y,z],{x,2},{y,3},{z,2}]


Or extending the above rule to arbitrary dimensions (again from @Rojo I am just a secretary here !)

Format[Derivative[i__][a_]] :=
Row[{"\[PartialD]"^Total[{i}], a}]/
Times @@ MapIndexed[Subscript["\[PartialD]x", First@#2]^#1 &, {i}]


and

Format[(h : Derivative[i__][a_])[vals__]] :=
RawBoxes@SubscriptBox[RowBox[{MakeBoxes@h, "\[VerticalLine]"}],
ToBoxes@Row[ Riffle[MapIndexed[
Row[{Subscript["x", First@#2], "=", #1}] &, {vals}], ","]]]


so that

Derivative[2, 3, 1][u][1, 2, 3]


returns

-
This formatting is also found in my answer here, where I give another link to the Wolfram Blog. –  Jens Nov 10 '12 at 17:54
@Jens right! I was trying to find out where I pinched that formatting. I used to use a package called DFormat which your method made obsolete. Thanks! –  chris Nov 10 '12 at 17:58

Perhaps you could add an input alias such as

AppendTo[CurrentValue[\$FrontEndSession, InputAliases],
"der" -> SuperscriptBox["\[SelectionPlaceholder]",
TagBox[RowBox[{"(", "\[Placeholder]", ")"}], Derivative]]]


and then use Esc+der+Esc, and enter the derivatives separated by commas

-