[PYTHON] Play with Poincare series and SymPy

This post is an article for December 11, 2019 in 2019 Numerical Calculation Advent Calendar, but it is almost poem ...

Poincare series (loose definition)

V = \bigoplus_{k = 0}^\infty V_k

Let be a graded vector space ($ \ deg V_k = k $). At this time, ** Poincare series ** $ P (V; t) $ of $ V $ is the following formal power series. $ P(V; t) := \sum_{k = 0}^\infty (\dim V_k)\ t^k $ Defined in. That is, a formal power series in which the coefficient of each power $ k $ of $ t $ is equal to the dimension of the homogeneous component $ V_k $ of $ V $.

Example 1. (a fairly simple example)

Let $ V = \ mathbb {C} [x] $ (complex coefficient one-variable polynomial ring), and let $ V_k, \ (k = 0, 1, 2 ...) $ be the entire $ k $ homogeneous polynomial. Let's consider it as a vector space. Then $ \ mathbb {C} [x] $ can be regarded as a graded vector space, but since there is only one variable, the $ k $ homogeneous polynomial is $ a_k x ^ k, (a_k \ in \ mathbb {C} There is only one in the form of) . In other words $ \forall k, \ \ \dim V_k = 1 $$ It will be. Therefore, the Poincare series $ P (\ mathbb {C} [x]; t) $ of $ \ mathbb {C} [x] $ is $ P(\mathbb{C}[x]; t) = \sum_{k = 0}^\infty t^k = 1 + t + t^2 + t^3 + \dots $ I can find it. Recalling the geometric progression formula, this is $ P(\mathbb{C}[x]; t) = \frac{1}{1 - t} $ You can write it in a closed form. (Since it is a formal power series, write it like this without considering convergence.)

Example 2. (Two-variable polynomial ring)

Now consider a two-variable polynomial ring $ V = \ mathbb {C} [x, y] $. The $ k $ homogeneous component $ V_k $ of $ V $ is the vector space of the entire $ k $ homogeneous polynomial as above. In this case, $ \ dim V_k $ changes depending on the value of $ k $. Looking from the smaller one

\begin{align}
V_0 &= \text{Span}\langle 1 \rangle, \\
V_1 &= \text{Span}\langle x, y\rangle, \\
V_2 &= \text{Span}\langle x^2, xy, y^2\rangle, \\
V_3 &= \text{Span}\langle x^3, x^2y, xy^2, y^3\rangle, \\
&...
\end{align}

And so on, you can see that $ \ dim V_k = k + 1 . Therefore $ P(\mathbb{C}[x, y]; t) = \sum_{k = 0}^\infty (k + 1)t^k $$ is. This can be transformed in a good way by using the term derivative,

\begin{align}
P(\mathbb{C}[x, y]; t) &= \sum_{k = 0}^\infty \frac{d}{dt}t^{k + 1} \\
&= \frac{d}{dt} \left( t \sum_{k = 0} t^{k} \right) = \frac{d}{dt} \frac{t}{1 - t} = \frac{1}{(1 - t)^2}
\end{align}

You can write it in a closed form.

Example 3. (3-variable polynomial ring)

Similarly, what if $ V = \ mathbb {C} [x, y, z] $, $ V_k $ is a subspace spanning the entire $ k $ homogeneous polynomial? $ V_k $ is based on a homogeneous expression of the form $ x ^ p y ^ q z ^ r $, $ p + q + r = k $, but such a homogeneous expression is

\frac{(k + 2)!}{k!2!} = \dbinom{k + 2}{2}

You can see that there are different types $ P(\mathbb{C}[x, y, z]; t) = \sum_{k = 0}^\infty \dbinom{k + 2}{2} t^k $ It will be. Now, can this be written in a closed form? It seems that you can understand by thinking about the term differentiation again, but this time I will consider a slightly different method. $ \frac{1}{(1 - x)(1 - y)(1 - z)} = \sum_{p = 0}^\infty x^p \sum_{q = 0}^\infty y^q \sum_{r = 0}^\infty z^r = \sum_{p, q, r = 0}^\infty x^p y^q z^r $ Considering the series, the base $ x ^ p y ^ q z ^ r $ of $ \ mathbb {C} [x, y, z] $ appears on the right side exactly once. The $ k $ homogeneous part is $ x ^ {p_1} y ^ {q_1} z ^ {r_1} + x ^ {p_2} y ^ {q_2} z ^ {r_2} + ... + x ^ {p_N} y ^ {q_N} z ^ {r_N} $ gives $ p_i + q_i + r_i = k, \ (i = 1, 2, ..., N, \ \ N = \ dim (V_k)) $ I am. If you substitute $ x = y = z = t $ here, it will be exactly in the form of $ (1 + 1 + ... + 1) t ^ k = \ dim (V_k) \ t ^ k , so in fact $ P(\mathbb{C}[x, y, z]; t) = \frac{1}{(1 - t)(1 - t)(1 - t)} = \frac{1}{(1 - t)^3} $ It turned out to be. In other words $ \frac{1}{(1 - t)^3} = \sum_{k = 0}^\infty \dbinom{k + 2}{2} t^k \ \ \ \ \cdots \ (★) $$ is. (As you can infer, for general $ n $, $ P (\ mathbb {C} [x_1, ..., x_n]; t) = \ dfrac {1} {(1 --t) ^ n } It will be $. )

Numerical calculation (?)

Now, I would like to actually calculate the first number term of the power series to confirm that this (★) formula really seems to hold. What should I do?

In this article, I'll try to calculate by programming with Python.

First, you should calculate the binomial coefficient on the right side. The Python library SciPy has a function comb that calculates the binomial coefficient. If you decide to use this to calculate up to the first 10 terms,

from scipy.special import comb
combinations = [comb(k + 2, k, exact=True) for k in range(10)]
print(combinations)

All you have to do is execute the program. Result is

[1, 3, 6, 10, 15, 21, 28, 36, 45, 55]

have become.

Now, what about the left side?

General expression of Taylor expansion around $ t = 0 $

f(t) = f(0) + f'(0)t + \frac{1}{2!}f''(0)t^2 + \frac{1}{3!}f'''(0)t^3 + ... = \sum_{k=0}^\infty \frac{1}{k!} \frac{d^kf(0)}{dt^k}t^k

Recalling that, the coefficient is the $ k $ derivative at $ t = 0 $ on the left side divided by $ k! $. Let's calculate this by programming with Python. Such computer algebra calculations can be performed using a library called SymPy. Similarly, if you decide to calculate up to the first 10 terms, you will need to calculate the ** 10th derivative (!) **, which is very complicated by manual calculation, but you can easily find it by writing a program. I will. The actual program is as follows. (I used scipy to calculate the factorial.)

from sympy import *
from scipy.special import factorial
t = Symbol('t')
P = 1 / (1 - t) ** 3
coeffs = []
for k in range(10):
    dk = diff(P, t, k).subs([(t, 0)])
    coeff = dk / factorial(k, exact=True)
    coeffs.append(coeff)

print(coeffs)

The execution result is still

[1, 3, 6, 10, 15, 21, 28, 36, 45, 55]

It was confirmed that the coefficients on the left and right sides match up to the first 10 terms of the power series expansion.


Impressions

I was vaguely thinking that I wanted to calculate such combinatorical things with a computer, so I wrote it though it is very simple.

References

-[Rhapsody of Polygon (Getting Started Mathematics)](https://www.amazon.co.jp/%E5%A4%9A%E9%A0%85%E5%BC%8F%E3%81%AE%E3 % 83% A9% E3% 83% 97% E3% 82% BD% E3% 83% 87% E3% 82% A3% E3% 83% BC-% E3% 81% AF% E3% 81% 98% E3% 82% 81% E3% 82% 88% E3% 81% 86% E6% 95% B0% E5% AD% A6-% E8% A5% BF% E5% B1% B1-% E4% BA% AB / dp / 4535608415)

Recommended Posts

Play with Poincare series and SymPy
Multiple integrals with Python and Sympy
Fractal to make and play with Python
Play with MoleculeNet's PDBBind and DeepChem's RDKitGridFeaturizer
Load csv with pandas and play with Index
Play with Prophet
Play with PyTorch
Play with 2016-Python
Play with CentOS 8
Play with Pyramid
Play with Fathom
Understand grid points and play with contour lines.
Play with Othello (Reversi)
Solve simultaneous ordinary differential equations with Python and SymPy.
How to loop and play gif video with openCV
Overlay graphs with sympy
With and without WSGI
With Sympy, don't worry
[How to!] Learn and play Super Mario with Tensorflow !!
[Python] How to play with class variables with decorator and metaclass
[Let's play with Python] Image processing to monochrome and dots
BASIC and C and assembler speed comparison and optimization play with IchigoJam
Play with Mastodon's archive in Python 2 Count replies and favourites
Play with the password mechanism of GitHub Webhook and Python
With me, cp, and Subprocess
[Python] Solve equations with sympy
Programming with Python and Tkinter
Encryption and decryption with Python
Let's play with 4D 4th
Let's play with Amedas data-Part 1
Working with tkinter and mouse
Python and hardware-Using RS232C with Python-
Play with push notifications with imap4lib
Play around with Linux partitions
Equation of motion with sympy
Let's play with Amedas data-Part 4
Play with Jupyter Notebook (IPython Notebook)
[Python] Play with Discord's Webhook.
Play RocketChat with API / Python
Super-resolution with SRGAN and ESRGAN
group_by with sqlalchemy and sum
Let's play with Amedas data-Part 3
python with pyenv and venv
Let's play with Amedas data-Part 2
Play with ASE MD module
With me, NER and Flair
Works with Python and R
Play with A3RT (Text Suggest)
Play with Statistical Modeling: Quantify J-League Team Strength with Stan and Python