# How to define a vector operator?

I know how to define a single-variable differential operator like

Clear[Op]
Op[x_] := a D[#, {x, 1}] &


and I can do operations like

Op[x][f[x]]         (* af'[x]    *)
Op[x][Op[x][f[x]]]  (* a^2f''[x] *)


However, how about if I want to do a vectorial operator, i.e. something like

$$\hat O = \vec a \cdot \vec \nabla_x,$$

so that when operating on some scalar function of $$x = |\vec x|$$, e.g. $$f(x)$$ we have

$$\hat O f(x) = \vec a \cdot \vec \nabla_x f(x) = f'(x) \frac{\vec a \cdot \vec x}{x}\, ,\\ \left(\hat O\right)^2 f(x) = \left(\vec a \cdot \vec \nabla_x\right)^2 f(x) = \left( f''(x) - \frac{f'(x)}{x} \right) \frac{(\vec a \cdot \vec x)^2}{x^2} + \frac{f'(x)}{x} a^2\, .$$

How do I define an operator like this?

I would prefer operations to be done symbolically, without the need to specify a coordinate system.

• You could use op[vars_]:=Array[a,Length[vars]].Grad[#,vars]&. Example: With[{xs=Array[x,2]}, op[xs][f[Sqrt[xs.xs]]]]. Your "without the need to specify a coordinate system" is confusing because it can mean a million different things, you should explain it in detail if it is an important part of your question, or drop it. Aug 16, 2022 at 3:56