Define functions
Something like this
func[poly_, var__] := Module[{n}, n = Length[var];
Sum[var[[n + 1 - i]] D[poly, var[[i]]], {i, 1, n}]]
func[a x1^2 + b x2^3, {x1, x2}]
2 a x1 x2 + 3 b x1 x2^2
Working out the example from the edit:
expr = x1^2 + x2^2 + x3^2 + x4^2 + x5^2;
Extract the variables:
var = Variables @ expr
{x1, x2, x3, x4, x5}
Then compute the sum:
Sum[var[[Length @ var + 1 - i]] D[expr, var[[i]]], {i, 1, Length @ var}]
2 x3^2 + 4 x2 x4 + 4 x1 x5
Those intermediate steps can be gathered into a single function:
operator[input_] := Block[{var},
var = Variables @ input;
Sum[var[[Length @ var + 1 - i]] D[input, var[[i]]], {i, 1, Length @ var}]
]
operator[expr]
2 x3^2 + 4 x2 x4 + 4 x1 x5
In case of expressions like
a x1^2 + x2^2 + b x3^2 + 2 x4^2 + c x5^2
also a, b, c
will be treated as variables by Variables
. If some symbols are to be treated as parameters, it's probably simplest and safest to manually set which symbols are variables and which are not, like in Sumit's answer below. Also, Variables
works well on polynomials, but fails e.g. with this:
Variables @ Sin[x]
{Sin[x]}