5
$\begingroup$

Though not unbearable, I always feel a little nervous when typing partial derivatives at a specified place e.g. $u^{(1,0)}(0,x)$, which happens a lot when setting initial/boundary conditions for PDEs. As far as I know, people usually turn to the following 2 ways to obtain the partial derivative:

(* 1 *)
Derivative[1, 0][u][0, x]
(* 2 *)
D[u[t, x], t] /. t -> 0

Both are tedious in my view. Is there a better way to input it? Create an auxiliary function? Shortcut? Template?

$\endgroup$
5
$\begingroup$

I've thought out 2 auxiliary functions.

A possible improvement for the Derivative approach:

d /: u_^d[a__][b__] := Derivative[a][u][b]

Then $u^{(1,0)}(0,x)$ can be obtained by

u^d[1, 0][0, x]

But I'm not sure if typing Shift+6 is simpler than typing [+]

A possible improvement for the D approach:

d2[u_, y__] := 
 Module[{pos = Position[{y}, _Equal]}, 
  D[u, Sequence @@ MapAt[First, {y}, pos]] /. Rule @@@ Extract[{y}, pos]]

Then $u^{(1,0)}(0,x)$ can be obtained by

d2[u[t, x], t == 0]

Notice the syntax of d2 is quite similar to D so you can do something like the following:

d2[u[t, y, x], t == 0, x, {t, 2}, x == 1, x]
Derivative[3, 0, 3][u][0, y, 1]
$\endgroup$
4
$\begingroup$

If you do this often why not create a shortcut or template as you mentioned in the question? This has the advantage of formatting directly without having to use Evaluate in Place etc, or introducing a custom notation. Example:

Derivative[Placeholder[], Placeholder[]][Placeholder[]] // 
  PasteButton // CreatePalette

Makes:

enter image description here

If preferred a keyboard shortcut can be added to KeyEventsTranslation.tr or a menu item to MenuSetup.tr.

  • Note: you can enter additional arguments within the parentheses, e.g.:

    enter image description here

    (* Derivative[1,4,3,2][foo][bar,baz] *)
    
$\endgroup$
  • 1
    $\begingroup$ Thanks for showing the usage of CreatePalette etc. (I'm really unfamiliar with these stuff!) One disadvantage of template in my view, is that I can't move out of it in a easy way. (If I use Tab, the cursor just… loops! ) $\endgroup$ – xzczd May 9 '16 at 9:33
  • $\begingroup$ @xzczd Would Derivative[Placeholder[], Placeholder[]][Placeholder[]][Placeholder[], Placeholder[]] // PasteButton // CreatePalette suit you better? Or use right cursor key or End? $\endgroup$ – Mr.Wizard May 9 '16 at 9:35
  • $\begingroup$ Personally I feel right cursor key and End aren't quite convenient since they're a little... far away from my finger. Anyway, your new added example is better, now I just need to type right cursor key only once :) $\endgroup$ – xzczd May 9 '16 at 9:44
  • $\begingroup$ @xzczd Please try Ctrl + Space $\endgroup$ – Mr.Wizard May 9 '16 at 10:19
  • $\begingroup$ Ctrl+Space is even more troublesome… see this. But just noticed Rojo has mentioned the Ctrl+Tab shortcut in a comment under that post, and it seems to be a good choice. $\endgroup$ – xzczd May 9 '16 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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