{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d2d1122d-0102-419a-886c-ba6809156c5d", "metadata": {}, "outputs": [], "source": [ "import os \n", "import sys\n", "sys.path.insert(0, os.path.abspath('../..'))\n", "\n", "import sympy as sp\n", "import numpy as np\n", "import itertools as it\n", "import pysymmpol as sy\n", "import pysymmpol.utils as ut\n", "from IPython.display import display, Latex" ] }, { "cell_type": "markdown", "id": "26aaf230-3259-4418-b151-5802179ce54c", "metadata": {}, "source": [ "# Class: HomogeneousPolynomial" ] }, { "cell_type": "markdown", "id": "0ae78aa1-a9a2-4ff0-9203-b24d8e9da6aa", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 2, "id": "a0364f14-5b6f-4a9a-8895-e84e3a3d56b6", "metadata": {}, "outputs": [], "source": [ "n = 3\n", "homogeneous = [sy.HomogeneousPolynomial(i) for i in range(n+1)]" ] }, { "cell_type": "markdown", "id": "06d311a3-794e-49ff-b3e7-a4b52a08ac7f", "metadata": {}, "source": [ "## Coordinates t as tuples" ] }, { "cell_type": "markdown", "id": "5413e79b-9e40-4281-941d-d4ebe1bdd4da", "metadata": {}, "source": [ "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$." ] }, { "cell_type": "code", "execution_count": 3, "id": "c06034e6-729c-4ca9-a0f7-779939968273", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(t1, t2, t3)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t = sp.symbols(f't1:{n+1}')\n", "t" ] }, { "cell_type": "markdown", "id": "fa516170-4df5-4fad-a0b2-a99cf1a9876e", "metadata": {}, "source": [ "We can now expand the Complete Homogeneous Polynomials with the method explicit(). " ] }, { "cell_type": "code", "execution_count": 4, "id": "bff7f2ba-9fd8-4dbb-9d6a-f65b696b9ff4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle t_{1}$" ], "text/plain": [ "t1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{t_{1}^{2}}{2} + t_{2}$" ], "text/plain": [ "t1**2/2 + t2" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{t_{1}^{3}}{6} + t_{1} t_{2} + t_{3}$" ], "text/plain": [ "t1**3/6 + t1*t2 + t3" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] } ], "source": [ "for a in homogeneous:\n", " display(a.explicit(t))\n", " print(10*'-')" ] }, { "cell_type": "markdown", "id": "9e6582e2-5baf-4be8-b5b6-07fc12aa827f", "metadata": {}, "source": [ "## Coordinates t as dictionary" ] }, { "cell_type": "markdown", "id": "307ecb05-8734-4d1b-9c0e-2b20b5f31b00", "metadata": {}, "source": [ "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.** \n", "\n", "> t = dict(enumerate(sp.symbols(f't1:{n+1}'), 1))\n", "\n", "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. " ] }, { "cell_type": "code", "execution_count": 5, "id": "a0485434-6090-40f3-9dbe-187ee003a231", "metadata": {}, "outputs": [], "source": [ "t_dict = ut.create_miwa(n)" ] }, { "cell_type": "code", "execution_count": 6, "id": "23e00e0e-8011-435e-a860-90d1215e79a5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1: t1, 2: t2, 3: t3}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_dict" ] }, { "cell_type": "code", "execution_count": 7, "id": "8c7ab6e0-7898-4959-b339-3c9e34a91f67", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle t_{1}$" ], "text/plain": [ "t1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{t_{1}^{2}}{2} + t_{2}$" ], "text/plain": [ "t1**2/2 + t2" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{t_{1}^{3}}{6} + t_{1} t_{2} + t_{3}$" ], "text/plain": [ "t1**3/6 + t1*t2 + t3" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] } ], "source": [ "for a in homogeneous:\n", " display(a.explicit(t_dict))\n", " print(10*'-')" ] }, { "cell_type": "markdown", "id": "42f02037-4f03-4c78-943d-82da41640403", "metadata": {}, "source": [ "## Sympy Polynomials" ] }, { "cell_type": "markdown", "id": "fc087ec7-6141-4b8e-8832-dfc959b4e194", "metadata": {}, "source": [ "Sometimes, it might be useful to access all the Polynomials methods in sympy. \n", "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. " ] }, { "cell_type": "code", "execution_count": 9, "id": "7e3b922f-1b0b-4a32-bfdf-79aa52685593", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Poly}{\\left( \\frac{1}{2} t_{1}^{2} + t_{2}, t_{1}, t_{2}, domain=\\mathbb{Q} \\right)}$" ], "text/plain": [ "Poly(1/2*t1**2 + t2, t1, t2, domain='QQ')" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "homogeneous[2].explicit(t_dict, True)" ] }, { "cell_type": "markdown", "id": "b58f1fed-147a-4f65-a943-387249f5792d", "metadata": {}, "source": [ "## x-Coordinates" ] }, { "cell_type": "markdown", "id": "3efbc006-ef2e-4750-bcd4-4afa369f2ed5", "metadata": {}, "source": [ "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\n", "$$ \n", "t_p = \\frac{1}{p} \\sum_{j=1}^m x_j^p\\ ; \\qquad p \\geq 1 \n", "$$\n", "(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, \n", "for example, suppose that m=2, $\\vec{x} = (x_1, x_2)$, then" ] }, { "cell_type": "code", "execution_count": 14, "id": "1668f6f6-d82c-42a7-bf6b-a4714c054983", "metadata": {}, "outputs": [], "source": [ "m = 2\n", "x = np.array(sp.symbols(f'x1:{m+1}'))" ] }, { "cell_type": "code", "execution_count": 15, "id": "05c347db-0772-4521-b2b8-df00f189cb7b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([x1, x2], dtype=object)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "markdown", "id": "91ffbffb-e470-4199-9782-53910bb7fbe8", "metadata": {}, "source": [ "We can now define the t as a comprehension" ] }, { "cell_type": "code", "execution_count": 16, "id": "b3d0289c-08d4-4388-9ab8-328d48b56ef7", "metadata": {}, "outputs": [], "source": [ "t = {j: sum(x**j)/j for j in range(1, n+1)}" ] }, { "cell_type": "code", "execution_count": 17, "id": "3d483a03-255a-49ee-9403-f6997cd91c85", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Poly}{\\left( x_{1} + x_{2}, x_{1}, x_{2}, domain=\\mathbb{Q} \\right)}$" ], "text/plain": [ "Poly(x1 + x2, x1, x2, domain='QQ')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Poly}{\\left( x_{1}^{2} + x_{1}x_{2} + x_{2}^{2}, x_{1}, x_{2}, domain=\\mathbb{Q} \\right)}$" ], "text/plain": [ "Poly(x1**2 + x1*x2 + x2**2, x1, x2, domain='QQ')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\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)}$" ], "text/plain": [ "Poly(x1**3 + x1**2*x2 + x1*x2**2 + x2**3, x1, x2, domain='QQ')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] } ], "source": [ "for a in homogeneous:\n", " display(a.explicit(t, True))\n", " print(10*'-')" ] }, { "cell_type": "markdown", "id": "ba0b9487-da45-4549-8850-dc818caa416b", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 20, "id": "7b2c8e96-afd0-4b7d-bb1f-db4e0f6ca704", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(x1 + x2, x1**2/2 + x2**2/2, x1**3/3 + x2**3/3)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tt = ut.tx_power_sum(homogeneous[-1].level, m)\n", "tt" ] }, { "cell_type": "code", "execution_count": 21, "id": "eeaa0c93-b4ef-4ef9-8fb8-d14533a3ea02", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Poly}{\\left( x_{1} + x_{2}, x_{1}, x_{2}, domain=\\mathbb{Q} \\right)}$" ], "text/plain": [ "Poly(x1 + x2, x1, x2, domain='QQ')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\operatorname{Poly}{\\left( x_{1}^{2} + x_{1}x_{2} + x_{2}^{2}, x_{1}, x_{2}, domain=\\mathbb{Q} \\right)}$" ], "text/plain": [ "Poly(x1**2 + x1*x2 + x2**2, x1, x2, domain='QQ')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] }, { "data": { "text/latex": [ "$\\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)}$" ], "text/plain": [ "Poly(x1**3 + x1**2*x2 + x1*x2**2 + x2**3, x1, x2, domain='QQ')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "----------\n" ] } ], "source": [ "for a in homogeneous:\n", " display(a.explicit(tt, True))\n", " print(10*'-')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 5 }