I need a script to authomatically symmetrize a given polynomial. For example, if the input is


the output should be


The same principle should work also for higher order polynomial. For example, if the input is


the output should be


The input is, in general, a polynomial. If the input is


the output should be


It may happen that some terms come with some powers. If the input is

x^2 z

the output should be either

(xxz + xxz +xzx+ xzx + zxx + zxx)/6



Both these ouputs are good. Thanks in advance for the help.

  • $\begingroup$ Are you always dealing with monomials, or should a solution expect things like x y + w z? $\endgroup$ – J. M. will be back soon Oct 14 '18 at 16:03
  • $\begingroup$ The input could be a polynomial as well. For example, if the input is $xy+wz$, the output should be $(xy+yx+wz+zw)/2$, but I know a priori what are the variables that come into play. Moreover, of course, it may appen to have things like $x^2y$ as input. In this case, the output should be either $(xxz+xzx+xxz+xzx+zxx+zxx)/6$ or $(2x^2z + 2xzx+ 2zx^2)/6$. Both outputs are ok for me. $\endgroup$ – AndreaPaco Oct 14 '18 at 16:08
  • $\begingroup$ @J.M.iscomputer-less, I've edited the question in order to meke my question more precise. $\endgroup$ – AndreaPaco Oct 14 '18 at 16:19

What about this?

f[NonCommutativeMultiply[x__]] := Mean[Permutations[NonCommutativeMultiply[x]]]

f[x ** y ** z]

1/6 (x ** y ** z + x ** z ** y + y ** x ** z + y ** z ** x + z ** x ** y + z ** y ** x)


f[x_Times] := f /@ x
f[x_Plus] := f /@ x
f[x_?NumericQ] := x

allows us to treat also polynomials:

f[3 x ** x ** y + y ** y ** y + 54 x ** z ** y]

x ** x ** y + x ** y ** x + y ** x ** x + y ** y ** y + 9 (x ** y ** z + x ** z ** y + y ** x ** z + y ** z ** x + z ** x ** y + z ** y ** x)

  • $\begingroup$ Thanks for your help. Can it handle a generic polynomial $P(x,y,z)$ such as $P(x,y,z)=3x^2y+y^3+54xzy$? $\endgroup$ – AndreaPaco Oct 14 '18 at 16:22
  • $\begingroup$ Thanks a lot for the update. You gave me a huge help. Just a curiosity more. In the input the non-commutative multiplication $**$ is already made explicit. Is there a way to authomatically turn a traditional multiplication (such as $x*y$) into a non-commutative one, (such as $x**y$)? $\endgroup$ – AndreaPaco Oct 14 '18 at 16:32
  • 1
    $\begingroup$ Yes, you can always tuse replacement rules, e.g. x x y //. {Power[a_, k_Integer?Positive] :> NonCommutativeMultiply @@ ConstantArray[a, k], Times -> NonCommutativeMultiply} (however this won't work out with the coefficients). $\endgroup$ – Henrik Schumacher Oct 14 '18 at 16:45

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.