# How to distribute PermutationProduct over the sum

Assuming I have two elements of the permutation group algebra $a_1$, $a_2$ such that $a_i=\sum_{p\in S_n}\alpha_pp$, I want to define a linear product $\odot$ that distributes over the sum and pulls out scalars: $a_1\odot a_2=\sum_{p\in S_n}\sum_{q\in S_n}\alpha_p\alpha_qp\odot q$, where $p\odot q\equiv PermutationProduct[p,q]$. If I try for example

Distribute[PermutationProduct[Cycles[{{}}] + Cycles[{{1, 2}}], Cycles[{{}}] - Cycles[{{1, 2}}]]}


The result is

Cycles[{}] +PermutationProduct[Cycles[{{1, 2}}],(-Cycles[{{1, 2}}])]


but I'm not sure how to make it take "constants" outside the product.

Try this:

In:= Unprotect[PermutationProduct];
PermutationProduct[left___, sum_Plus, right___] := PermutationProduct[left, #, right] & /@ sum;
PermutationProduct[left___, c_ perm_?PermutationCyclesQ, right___] := c PermutationProduct[left, perm, right];
PermutationProduct[left___, 0, right___] := 0;
Protect[PermutationProduct];


The first definition expands sums automatically, without the need of calling Distribute. The second definition extracts anything that is not a valid Cycles object (the "constants"). The third one deals with 0, a special case not covered by those two previous definitions.

Then you can do something like this:

In:= {g1, g2, g3} = RandomPermutation[5, 3]
Out= {Cycles[{{1, 5}, {2, 4, 3}}], Cycles[{{1, 2, 4, 3, 5}}], Cycles[{{2, 3, 5}}]}

In:= ((2 + a) g1 + Sqrt b g2) \[PermutationProduct] (-g3 + Pi g1/2)
Out= 1/2 (2 + a) \[Pi] Cycles[{{2, 3, 4}}] - (2 + a) Cycles[{{1, 2, 4, 5}}] + 1/2 Sqrt b \[Pi] Cycles[{{1, 4, 2, 3}}] - Sqrt b Cycles[{{1, 3, 2, 4, 5}}]


In:= PermutationProduct[Cycles[{}] + Cycles[{{1, 2}}], Cycles[{}] - Cycles[{{1, 2}}]]