monomial_symmetrize, a Python code which symmetrizes the coefficients of equivalent monomials in a polynomial.
The polynomial is assumed to be written as a sum of monomials.
Each monomial is of total degree D.
Each monomial involves factors selected from a B-dimensional space.
Each monomial has a coefficient C.
Every possible permutation of D factors from a B dimensional space is used to form a separate monomial.
For instance, if D = 3 and B = 2, the polynomial has the form
      P = C111 X1 X1 X1
        + C112 X1 X1 X2
        + C121 X1 X2 X1
        + C122 X1 X2 X2
        + C211 X2 X1 X1
        + C212 X2 X1 X2
        + C221 X2 X2 X1
        + C222 X2 X2 X2
    
    There are 4 equivalence classes of monomials, with representatives X1 X1 X1, X1 X1 X2, X1 X2 X2 and X2 X2 X2. (Two monomial are equivalent if one is simply a permutation of the other.) It is the task of this function to take the values of D, B and the coefficient vector C, and produce a new coefficient vector C2. The C2 vector is computed by averaging the coefficients of equivalent monomials.
By grouping the equivalent monomials, we have
      P = C111 X1 X1 X1
        + C112 X1 X1 X2 + C121 X1 X2 X1 + C211 X2 X1 X1
        + C122 X1 X2 X2 + C212 X2 X1 X2 + C221 X2 X2 X1
        + C222 X2 X2 X2
      and taking advantage of the equivalence of the monomials, we can write:
      P = C111 X1 X1 X1
        + ( C112 + C121 + C211 ) / 3 * ( X1 X1 X2 + X1 X2 X1 + X2 X1 X1 )
        + ( C122 + C212 + C221 ) / 3 * ( X1 X2 X2 + X2 X1 X2 + X2 X2 X1 )
        + C222 X2 X2 X2
      which means that our equivalent polynomial P2 can be written in the form
      P2 =  C111                     * X1 X1 X1
        + ( C112 + C121 + C211 ) / 3 * X1 X1 X2
        + ( C112 + C121 + C211 ) / 3 * X1 X2 X1
        + ( C122 + C212 + C221 ) / 3 * X1 X2 X2
        + ( C112 + C121 + C211 ) / 3 * X2 X1 X1
        + ( C122 + C212 + C221 ) / 3 * X2 X1 X2
        + ( C122 + C212 + C221 ) / 3 * X2 X2 X1
        +   C222                     * X2 X2 X2
     where, now, the equivalent monomials have equal coefficients.
    
    The information on this web page is distributed under the MIT license.
monomial_symmetrize is available in a MATLAB version and an Octave version and a Python version.
monomial, a Python code which enumerates, lists, ranks, unranks and randomizes multivariate monomials in a space of M dimensions, with total degree less than N, equal to N, or lying within a given range.
vector, a Python code which considers a problem involving vectors, which can be considered to belong to equivalence classes, for which an arbitrary collection of coefficients must be gathered, averaged, and then scattered again.