Symmetrize a polynomial forgetting the commutativity property of multiplication

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












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



xy


the output should be



(xy+yx)/2


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



 xyz


the output should be



(xyz+xzy+yxz+yzx+zxy+zyx)/6


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



xy+wz


the output should be



(xy+yx+wz+zw)/2



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


or



(2x^2z+2xzx+2zx^2)/6


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










share|improve this question























  • Are you always dealing with monomials, or should a solution expect things like x y + w z?
    – J. M. is computer-less♦
    2 hours ago










  • 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.
    – AndreaPaco
    2 hours ago











  • @J.M.iscomputer-less, I've edited the question in order to meke my question more precise.
    – AndreaPaco
    1 hour ago














up vote
1
down vote

favorite
1












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



xy


the output should be



(xy+yx)/2


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



 xyz


the output should be



(xyz+xzy+yxz+yzx+zxy+zyx)/6


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



xy+wz


the output should be



(xy+yx+wz+zw)/2



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


or



(2x^2z+2xzx+2zx^2)/6


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










share|improve this question























  • Are you always dealing with monomials, or should a solution expect things like x y + w z?
    – J. M. is computer-less♦
    2 hours ago










  • 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.
    – AndreaPaco
    2 hours ago











  • @J.M.iscomputer-less, I've edited the question in order to meke my question more precise.
    – AndreaPaco
    1 hour ago












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





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



xy


the output should be



(xy+yx)/2


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



 xyz


the output should be



(xyz+xzy+yxz+yzx+zxy+zyx)/6


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



xy+wz


the output should be



(xy+yx+wz+zw)/2



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


or



(2x^2z+2xzx+2zx^2)/6


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










share|improve this question















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



xy


the output should be



(xy+yx)/2


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



 xyz


the output should be



(xyz+xzy+yxz+yzx+zxy+zyx)/6


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



xy+wz


the output should be



(xy+yx+wz+zw)/2



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


or



(2x^2z+2xzx+2zx^2)/6


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







polynomials algebraic-manipulation algebra






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago

























asked 2 hours ago









AndreaPaco

1324




1324











  • Are you always dealing with monomials, or should a solution expect things like x y + w z?
    – J. M. is computer-less♦
    2 hours ago










  • 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.
    – AndreaPaco
    2 hours ago











  • @J.M.iscomputer-less, I've edited the question in order to meke my question more precise.
    – AndreaPaco
    1 hour ago
















  • Are you always dealing with monomials, or should a solution expect things like x y + w z?
    – J. M. is computer-less♦
    2 hours ago










  • 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.
    – AndreaPaco
    2 hours ago











  • @J.M.iscomputer-less, I've edited the question in order to meke my question more precise.
    – AndreaPaco
    1 hour ago















Are you always dealing with monomials, or should a solution expect things like x y + w z?
– J. M. is computer-less♦
2 hours ago




Are you always dealing with monomials, or should a solution expect things like x y + w z?
– J. M. is computer-less♦
2 hours ago












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.
– AndreaPaco
2 hours ago





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.
– AndreaPaco
2 hours ago













@J.M.iscomputer-less, I've edited the question in order to meke my question more precise.
– AndreaPaco
1 hour ago




@J.M.iscomputer-less, I've edited the question in order to meke my question more precise.
– AndreaPaco
1 hour ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










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)




Adding



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)







share|improve this answer






















  • 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$?
    – AndreaPaco
    1 hour ago










  • 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$)?
    – AndreaPaco
    1 hour ago







  • 1




    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).
    – Henrik Schumacher
    1 hour ago










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183830%2fsymmetrize-a-polynomial-forgetting-the-commutativity-property-of-multiplication%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










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)




Adding



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)







share|improve this answer






















  • 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$?
    – AndreaPaco
    1 hour ago










  • 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$)?
    – AndreaPaco
    1 hour ago







  • 1




    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).
    – Henrik Schumacher
    1 hour ago














up vote
2
down vote



accepted










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)




Adding



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)







share|improve this answer






















  • 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$?
    – AndreaPaco
    1 hour ago










  • 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$)?
    – AndreaPaco
    1 hour ago







  • 1




    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).
    – Henrik Schumacher
    1 hour ago












up vote
2
down vote



accepted







up vote
2
down vote



accepted






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)




Adding



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)







share|improve this answer














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)




Adding



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)








share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 1 hour ago









Henrik Schumacher

41.8k260125




41.8k260125











  • 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$?
    – AndreaPaco
    1 hour ago










  • 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$)?
    – AndreaPaco
    1 hour ago







  • 1




    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).
    – Henrik Schumacher
    1 hour ago
















  • 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$?
    – AndreaPaco
    1 hour ago










  • 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$)?
    – AndreaPaco
    1 hour ago







  • 1




    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).
    – Henrik Schumacher
    1 hour ago















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$?
– AndreaPaco
1 hour ago




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$?
– AndreaPaco
1 hour ago












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$)?
– AndreaPaco
1 hour ago





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$)?
– AndreaPaco
1 hour ago





1




1




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).
– Henrik Schumacher
1 hour ago




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).
– Henrik Schumacher
1 hour ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183830%2fsymmetrize-a-polynomial-forgetting-the-commutativity-property-of-multiplication%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery