Symmetric polynomials P75097


Statement
 

pdf   zip

A polynomial pp in three variables aa, bb and cc is symmetric if and only if p(a,b,c)=p(a,c,b)=p(b,a,c)=p(a, b, c) = p(a, c, b) = p(b, a, c) = \dots for the six permutations of the variables.

For example, a+b+ca+b+c, ab+bc+acab+bc+ac, 3a2b2c23a^2b^2c^2 and 7abc+a2bc+ab2c+abc27abc+a^2bc+ab^2c+abc^2 are symmetric polynomials, while ab+acab+ac and a2bcab2c+abc2a^2bc - ab^2c + abc^2 are not.

We introduce the notation [aii bjj ckk] with ijki \ge j \ge k to denote the symmetric polynomial that results from adding all the monomials of the form aibjcka^ib^jc^k for any permutation of aa, bb and cc, where all the resulting monomials appear with coefficient 1. For example, [a] =a+b+c= a+b+c, [ab] =ab+bc+ca= ab + bc + ca, and [a2bc] =a2bc+ab2c+abc2= a^2bc + ab^2c + abc^2. (Note the special cases for the notation when the exponent of a variable is zero or one.)

Symmetric polynomials that do not have any variables of degree larger than one, that is, [a], [ab] and [abc], are called elementary symmetric polynomials. The fundamental theorem of symmetric polynomials, already known to Newton, states that any symmetric polynomial can be expressed as the sum and product of elementary symmetric polynomials.

Here, we don’t ask you to find these expressions. Instead, we ask you a much simpler task: calculate the product between a symmetric polynomial [aii bjj ckk] and an elementary symmetric polynomial. (If you do this, you are not far away from establishing a recurrence relation and explicitly finding the expressions from the fundamental theorem.)

Input

Input consists of several cases, each with the product of a symmetric polynomial and an elementary symmetric polynomial. Assume i1i \ge 1 and 0kji10000 \le k \le j \le i \le 1000.

Output

For every product, print its result. Make sure that the terms are in lexicographical order, that is, first the term with the largest ii, and in case of a tie, first the term with the largest jj.

Public test cases
  • Input

    [a]*[a]
    [ab]*[a]
    [a^2b]*[ab]
    [a^3b]*[ab]
    [a^3b]*[abc]
    [a^1000b^700c^42]*[ab]
    

    Output

    [a^2] + 2[ab]
    [a^2b] + 3[abc]
    [a^3b^2] + 2[a^3bc] + 2[a^2b^2c]
    [a^4b^2] + 2[a^4bc] + [a^3b^2c]
    [a^4b^2c]
    [a^1001b^701c^42] + [a^1001b^700c^43] + [a^1000b^701c^43]
    
  • Information
    Author
    Omer Gimenez
    Language
    English
    Official solutions
    C++
    User solutions
    C++