# Creating the Nabla operator (also known as Del operator) as an operator

How can I define the nabla operator (also known as Del operator) as a an operator, acting on everything to the right of the operator!

Also taking \[Del]^2 would give the second derivivates.

I wish to be able to write \[Del]f[x,y,z] and then evaluate it according to the nabla operator.

What I have now, is just a simple expression:

Del = {D[#, x], D[#, y], D[#, z]} &


But it would be nice to be able to use the actual \[Del] for notation.

I've looked at different examples including: http://reference.wolfram.com/language/ref/NonCommutativeMultiply.html

But I really don't understand any of what's going on there.

• I wonder if it is possible to use Del for the divergence and curl operators. The direct substitution of dot and cross products do not work. – galadog Feb 4 '15 at 15:54
• Your definition of the square is not consistent with conventional practice, where it would give the laplacian instead of just a vector of second derivatives. I don't think it's a good idea to overload Times and Power with these interpretations. Better use clearly distinct notation to make code easier to understand. – Jens Mar 5 '15 at 17:24
• If you are using v10, please check details sections of Grad and Laplacian, and related Div and Curl. These symbols have new input forms quite close to what you're asking for. – kirma Mar 5 '15 at 19:51
• closely related: Having the derivative be an operator – Kuba Mar 9 '17 at 13:30
• Yes, that is done automatically. Try HoldForm[Curl[v, {x, y, z}]] and see how it formats. This is different from interpreting that form when you enter it. Traditional notation is ambiguous. When you are talking to a computer you want to be clear and unambiguous. – Szabolcs Mar 9 '17 at 14:08

Well, over-pursuing similarity of Mathematica code and traditional math notation does more harm than good, still, it's possible to create a nabla operator in Mathematica, here's my approach:

(*$PrePrint=.*)$PrePrint = # /.
Derivative[id__][f_][args__] :>
HoldForm@D[f[args], #] &[
Sequence @@ (DeleteCases[Transpose[{{args}, {id}}], {_, 0}] /. {x_, 1} :> x)]] &;

Clear[$independentVariable, ▽, Δ]$independentVariable = {x, y, z};
▽ /: ▽ f_ := Grad[f, $independentVariable] ▽·f_ := Div[f,$independentVariable]
▽ /: ▽\[Cross]f_ := Curl[f, $independentVariable] ▽·▽ := Δ ▽ /: ▽^2 := Δ Δ /: Δ f_ := Laplacian[f,$independentVariable]
CenterDot /: (v_·▽) f_ := Grad[f, $independentVariable].v CenterDot /: (m_?MatrixQ·▽)\[Cross]f_ := TensorContract[LeviCivitaTensor[3].D[f, {$independentVariable}].m\[Transpose], {2, 3}]


Usage:

▽ f[x, y, z]


▽·{f[x, y, z], g[x, y, z], h[x, y, z]}


▽\[Cross]{f[x, y, z], g[x, y, z], h[x, y, z]}


▽·▽ f[x, y, z]
▽^2 f[x, y, z]
Δ f[x, y, z]


({Subscript[v, x], Subscript[v, y], Subscript[v, z]}·▽) f[x, y, z]


({Subscript[v, x], Subscript[v, y], Subscript[v, z]}·▽){f[x, y, z], g[x, y, z],h[x, y, z]}


Alst = Array[Subscript[A, ##] &, {3, 3}];
vector = #[x, y, z] & /@ {u, v, w};
test1 = (Alst·▽)\[Cross]vector


Notice the · is \[CenterDot], and ▽ is \[EmptyDownTriangle] rather than \[Del].

To type ▽ easier, try the technique in this and this post.

Not sure if the solution will fail in more complicated cases.

BTW the $PrePrint function is modified from the code here. • I have merged these questions moving your answer in the process, as requested. – Mr.Wizard Mar 12 '17 at 6:33 Does it not work as written? Del = {D[#, x], D[#, y], D[#, z]} &; ∇f[x, y, z] $\left\{f^{(1,0,0)}(x,y,z),f^{(0,1,0)}(x,y,z),f^{(0,0,1)}(x,y,z)\right\}$To extend this in the way that I believe you want you can use the Notation Package. First: Needs["Notation"];  Then paste and evaluate: Cell[BoxData[ RowBox[{"Notation", "[", RowBox[{ TemplateBox[{RowBox[{ SuperscriptBox["\[Del]", "n_"], "expr_"}]}, "NotationTemplateTag"], " ", "\[DoubleLongRightArrow]", " ", TemplateBox[{RowBox[{ RowBox[{"del", "[", "n_", "]"}], "[", "expr_", "]"}]}, "NotationTemplateTag"]}], "]"}]], "Input"]  Which should look like this in the Notebook: (Or enter the equivalent using the Notation Palette.) Then add these definitions: Del = del[1]; del[n_Integer?Positive][expr_] := D[expr, {#, n}] & /@ {x, y, z}  Finally:$\left\{f^{(1,0,0)}(x,y,z),f^{(0,1,0)}(x,y,z),f^{(0,0,1)}(x,y,z)\right\}\left\{f^{(2,0,0)}(x,y,z),f^{(0,2,0)}(x,y,z),f^{(0,0,2)}(x,y,z)\right\}\left\{f^{(3,0,0)}(x,y,z),f^{(0,3,0)}(x,y,z),f^{(0,0,3)}(x,y,z)\right\}\$

• It does seem to Work for just \[del], But do you also know if there is any way to make mathematica interpret the \[Del]^2f[x,y,z] as the second derivatives of the function f[x,y,z]? – TehHO Feb 3 '15 at 9:48
• @TehHO Possibly so, but my first attempt failed. I'll work on it. – Mr.Wizard Feb 3 '15 at 9:58
• Well, as far as I can tell, \[Del]^2 represent Laplacian and there is no definition for \[Del]^3, see the corresponding wiki page for more details. – xzczd Mar 12 '17 at 4:44

Try

grad[f_] := {D[f, x], D[f, y], D[f, z]}


then

grad[x + y]


returns

{1, 1, 0}
`