1
$\begingroup$

Suppose I want to explore $\nabla \times \nabla V$ where $V$ is some scalar function. It basically results in a zero. But I would only know why if I solve it on paper. I wanted to use Mathematica for it and I have found some solutions but I want something cleaner.

pdConv[
  Curl[{Subscript[f, x][x, y, z], Subscript[f, y][x, y, z], Subscript[f, z][x, y, z]}, 
  {x, y, z}
  ] /. {Subscript[f, x] -> Defer[D[V, x]],
        Subscript[f, y] -> Defer[D[V, y]],      
        Subscript[f, z] -> Defer[D[V, z]]}
]

This gives this output:

pretty-printed output

I did have to do some unpleasant hackery and the other simpler attempt is

pdConv[Curl[{Hold[D[V[x, y, z], x]], 
Hold[D[V[x, y, z], y]], 
Hold[D[V[x, y, z], z]]}, {x, y, z}]]

This gives this output

output containing explicit Hold

which is just perfect, but I don't like the Hold appearing in the output and HoldForm,Inactivate,Inactive give weird stuff.

I have copied a function called pdConv from the Wolfram Blog that converts partial differential expressions to TraditionalForm. It is really helpful. Here is its definition:

pdConv[f_] := TraditionalForm[f /. Derivative[inds__][g_][vars___] :> 
(Defer[D[g[vars],##1]] & ) @@ (Transpose[{{vars}, {inds}}] /. {{var_, 0} :> 
Sequence[], {(var_)*1} :> {var}})]

What would be some more cleaner approaches?

$\endgroup$
1
  • 3
    $\begingroup$ Not sure why you need all this machinery: Curl[Grad[f[x, y, z], {x, y, z}], {x, y, z}] returns {0, 0, 0} directly. You can also apply pdConv to the intermediate result of Grad, but I would not do computation of the results of *Form functions, as those are output wrappers only ("pretty-printers"). $\endgroup$ – MarcoB Jan 3 at 19:51
2
$\begingroup$

If you're willing to tweak a system option, you can do this to make HoldForm be treated the same Hold by differentiation code:

SetSystemOptions["DifferentiationOptions" -> "ExcludedFunctions" -> 
    Append[
        SystemOptions["DifferentiationOptions" -> "ExcludedFunctions"][[-1, -1, -1, -1]],
        HoldForm
    ]
]

You can now use your code with HoldForm instead of Hold. I'm a bit surprised that HoldForm isn't in that list by default. I'll see about adding it to get it to format as you want.

$\endgroup$

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.