[1]:
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))

import sympy as sp
import numpy as np
import itertools as it
import pysymmpol as sy
import pysymmpol.utils as ut
from IPython.display import display, Latex

Class: HomogeneousPolynomial

Now we deal witht the Complete Homogeneous Symmetric Polynomials. The idea of this module is very straightforward, but it has some subtleties that we need to discuss. Let us first initialize the first 3 polynomials, zero included.

[2]:
n = 3
homogeneous = [sy.HomogeneousPolynomial(i) for i in range(n+1)]

Coordinates t as tuples

We initialize the Miwa coordinates using the sympy definitions. It is a tuple. Observe that the polynomial of degree ‘\(n\)’ depends on the coordinate \(t_n\).

[3]:
t = sp.symbols(f't1:{n+1}')
t
[3]:
(t1, t2, t3)

We can now expand the Complete Homogeneous Polynomials with the method explicit().

[4]:
for a in homogeneous:
    display(a.explicit(t))
    print(10*'-')
1
----------
$\displaystyle t_{1}$
----------
$\displaystyle \frac{t_{1}^{2}}{2} + t_{2}$
----------
$\displaystyle \frac{t_{1}^{3}}{6} + t_{1} t_{2} + t_{3}$
----------

Coordinates t as dictionary

The inconvenience of the miwa coordinates as a tuple is that the conventions are that the first coordinate is \(t_1\) but since the tuples and lists start at \(0\), is might be confusing to always manipulate expressions in with \(t[n] = t_{n+1}\). So, it is better to use dictionaries as in the definition of the Miwa coordinates, where the keys become our indices. The explict methods accepts the argument as a dictionary.

t = dict(enumerate(sp.symbols(f’t1:{n+1}’), 1))

In the utils.py, we have a function create_miwa(n) that creates the appropriate dictionaries for us. In fact., it creates one additional coordinate.

[5]:
t_dict = ut.create_miwa(n)
[6]:
t_dict
[6]:
{1: t1, 2: t2, 3: t3}
[7]:
for a in homogeneous:
    display(a.explicit(t_dict))
    print(10*'-')
1
----------
$\displaystyle t_{1}$
----------
$\displaystyle \frac{t_{1}^{2}}{2} + t_{2}$
----------
$\displaystyle \frac{t_{1}^{3}}{6} + t_{1} t_{2} + t_{3}$
----------

Sympy Polynomials

Sometimes, it might be useful to access all the Polynomials methods in sympy. The method accepts a boolean argument. Its default value is False, but if we pass the True argument, the explicit method will return a sympy polynomial. Using the explicit sympy expression also helps us with some internal symplifications that the crude answer does not give.

[9]:
homogeneous[2].explicit(t_dict, True)
[9]:
$\displaystyle \operatorname{Poly}{\left( \frac{1}{2} t_{1}^{2} + t_{2}, t_{1}, t_{2}, domain=\mathbb{Q} \right)}$

x-Coordinates

Another important aspect is to consider the homogeneous polynomials in the x-coordinates. Given the coordinates \(x = (x_1, \dots, x_m)\), the Miwa coordinates are

\[t_p = \frac{1}{p} \sum_{j=1}^m x_j^p\ ; \qquad p \geq 1\]

(another reason to use the Miwa coordinates as a dictionary). Therefore, one should also want to express the Homogeneous Polynomials in these coordinates. One easy way to accomplish this is with the numpy arrays, for example, suppose that m=2, \(\vec{x} = (x_1, x_2)\), then

[14]:
m = 2
x = np.array(sp.symbols(f'x1:{m+1}'))
[15]:
x
[15]:
array([x1, x2], dtype=object)

We can now define the t as a comprehension

[16]:
t = {j: sum(x**j)/j for j in range(1, n+1)}
[17]:
for a in homogeneous:
    display(a.explicit(t, True))
    print(10*'-')
1
----------
$\displaystyle \operatorname{Poly}{\left( x_{1} + x_{2}, x_{1}, x_{2}, domain=\mathbb{Q} \right)}$
----------
$\displaystyle \operatorname{Poly}{\left( x_{1}^{2} + x_{1}x_{2} + x_{2}^{2}, x_{1}, x_{2}, domain=\mathbb{Q} \right)}$
----------
$\displaystyle \operatorname{Poly}{\left( x_{1}^{3} + x_{1}^{2}x_{2} + x_{1}x_{2}^{2} + x_{2}^{3}, x_{1}, x_{2}, domain=\mathbb{Q} \right)}$
----------

In the utils.py, we have a function that creates the x coordinate fox us. It receives 2 arguments, n and m defined above, where the second has default m=1.

[20]:
tt = ut.tx_power_sum(homogeneous[-1].level, m)
tt
[20]:
(x1 + x2, x1**2/2 + x2**2/2, x1**3/3 + x2**3/3)
[21]:
for a in homogeneous:
    display(a.explicit(tt, True))
    print(10*'-')
1
----------
$\displaystyle \operatorname{Poly}{\left( x_{1} + x_{2}, x_{1}, x_{2}, domain=\mathbb{Q} \right)}$
----------
$\displaystyle \operatorname{Poly}{\left( x_{1}^{2} + x_{1}x_{2} + x_{2}^{2}, x_{1}, x_{2}, domain=\mathbb{Q} \right)}$
----------
$\displaystyle \operatorname{Poly}{\left( x_{1}^{3} + x_{1}^{2}x_{2} + x_{1}x_{2}^{2} + x_{2}^{3}, x_{1}, x_{2}, domain=\mathbb{Q} \right)}$
----------