{ "cells": [ { "cell_type": "code", "execution_count": 29, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "%display latex" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

Interactive tutorials,
an example on symmetric functions

\n", "\n", "

Pauline Hubert
\n", "Joint work with Mélodie Lapointe

\n", "

ACA July 2019 - Montreal

" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

1. Sage

\n", "
\"Sage
\n", "\n", " \n", "\n", "
\"Jupyter
\n", " " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

2. Symmetric Functions Tutorial

\n", "\n", "

Two reference pages for symmetric functions in Sage.

\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "

Why a new tutorial on symmetric functions?

\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
The new tutorial !
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

3. Find the discriminant of a polynomial using symmetric functions

\n", "\n", "
\n", "\n", "Reference about [discriminant](https://fr.wikipedia.org/wiki/Discriminant)." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

Exercise

\n", "\n", "Let $f$ by a monic polynomial on $z$ and $x_0, x_1, \\dots, x_{n-1}$ its roots. Then we have $$f(z) = (z-x_0)(z-x_1)\\dots (z-x_{n-1}).$$\n", "\n", "Our goal is to find the discriminant of $f$ for $n=2$ and $n=3$ using symmetric functions. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

Part 1 : $n=2$

" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "n = 2" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defining z\n", "Defining x0, x1\n" ] } ], "source": [ "F = QQ['z']\n", "F.inject_variables()\n", "R = PolynomialRing(F,'x',n)\n", "R.inject_variables()\n", "x = R.gens()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "*Question* : Define the polynomial $f$ with the indeterminates $z, x_0$ and $x_1$. " ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "scrolled": true, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "x0*x1 + (-z)*x0 + (-z)*x1 + z^2" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f = prod((z-x[i]) for i in range(0,n))\n", "f" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "if n==2 :\n", " A = QQ['z,x0,x1']\n", " assert A(f)(z=x[0]) == 0" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Remark that $f$ is symmetric w.r.t the variables $x_0$ and $x_1$. Then [the fundamental theorem of symmetric polynomials](https://en.wikipedia.org/wiki/Elementary_symmetric_polynomial#Fundamental_theorem_of_symmetric_polynomials) tells us that we can express $f$ in terms of elementary symmetric polynomials. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "**Definition:** The elementary symmetric polynomial $e_k$ is defined to be the sum of all monomials of degree $k$ with no squares. " ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "1" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0 + x1 + x2 + x3" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0*x1 + x0*x2 + x1*x2 + x0*x3 + x1*x3 + x2*x3" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0*x1*x2 + x0*x1*x3 + x0*x2*x3 + x1*x2*x3" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0*x1*x2*x3" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "e = SymmetricFunctions(QQ[z]).e()\n", "\n", "for k in range(5):\n", " show(e[k].expand(4))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "*Question* : Show that the coefficients of $f = z^2+bz+c$ in terms of elementary symmetric functions are $b=-e_1$ and $c=e_2$." ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "z^2*e[] - z*e[1] + e[2]" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = e.from_polynomial(f)\n", "g" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "scrolled": true, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "x0*x1 + (-z)*x0 + (-z)*x1 + z^2" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.expand(n)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "**Definition :** The discriminant of $f$ is given by\n", "$$\\Delta(f) = \\prod_{i>j} (x_i-x_j)^2$$ \n", "where $x_i$ are the roots of $f$. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Recall that the Vandermonde matrix \n", "$$ M = \\begin{bmatrix} \n", "1 & 1 & \\dots & 1 \\\\\n", "x_0 & x_1 & \\dots & x_{n-1} \\\\ \n", "x_0^2 & x_1^2 & \\dots & x_{n-1}^2 \\\\\n", "\\vdots & \\vdots & \\ddots & \\vdots \\\\\n", "x_0^{n-1} & x_1^{n-1} & \\dots & x_{n-1}^{n-1} \n", "\\end{bmatrix} $$\n", "\n", "has determinant $\\det M = \\prod_{i>j} (x_i-x_j)$. So $\\Delta(f) = (\\det M)^2$." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "*Question* : Check that $\\Delta(f) = \\det(M^2)$ for $n=2$." ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 1 x0]\n", "[ 1 x1]" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M = matrix.vandermonde(x)\n", "M" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "x0^2 + (-2)*x0*x1 + x1^2" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(M.determinant())^2" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(M.determinant())^2 == prod((x[i]-x[j])^2 for i in range(n) for j in range(n) if i>j)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "**Proposition:** Let $A$ be a $n \\times n $ matrix, then we have $\\det(A)^2 = \\det(A^\\bot A)$. \n", "\n", "We can check that on a random $3 \\times 3$ matrix on $\\mathbb{Q}$. " ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = matrix.random(QQ, 3, algorithm='diagonalizable')\n", "(A.determinant())^2 == (A.transpose()*A).determinant()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "In the case of the Vandermonde matrix, we get the following. " ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 2 x0 + x1]\n", "[ x0 + x1 x0^2 + x1^2]" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T = M.transpose()*M\n", "T" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "We recognize the power sum symmetric polynomials. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "**Definition:** The power sum symmetric polynomials $p_k$ are defined to be $\\sum_i x_i^k$. " ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "1" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0 + x1 + x2 + x3" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0^2 + x1^2 + x2^2 + x3^2" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "x0^3 + x1^3 + x2^3 + x3^3" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "p = SymmetricFunctions(QQ[z]).p()\n", "\n", "for k in range(4):\n", " show(p[k].expand(4))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "*Question* : Express the coefficients of $ T := M^\\bot M$ in terms of power sum symmetric polynomials. " ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[2*p[] p[1]]\n", "[ p[1] p[2]]" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T_p = matrix([[p.from_polynomial(T[i,j]) for j in range(n)] for i in range(n)])\n", "T_p" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "*Question* : Compute the determinant of the matrix $T_p$." ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-p[1, 1] + 2*p[2]" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T_p.determinant()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "*Question* : Express the result in terms of elementary symmetric polynomials and find the discriminant of $f$." ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e[1, 1] - 4*e[2]" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e(T_p.determinant())" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Remember $a=1$, $b=-e_1$ and $c=e_2$. As expected we obtain that $\\Delta = b^2 - 4c$." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

Part 2 : $n=3$

" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "n = 3 \n", "F = QQ['z']\n", "F.inject_variables(verbose=False)\n", "R = PolynomialRing(F,'x',n)\n", "R.inject_variables(verbose=False)\n", "x = R.gens()" ] }, { "cell_type": "code", "execution_count": 50, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "'f in terms of elementary symmetric functions : \\t' z^3*e[] - z^2*e[1] + z*e[2] - e[3]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "f = prod((z-x[i]) for i in range(0,3))\n", "show(\"f in terms of elementary symmetric functions : \\t\",e.from_polynomial(f))" ] }, { "cell_type": "code", "execution_count": 51, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def discriminant_with_sym_func(n) :\n", " M = matrix.vandermonde(x)\n", " T = M.transpose()*M\n", " M_p = matrix([[p.from_polynomial(T[i,j]) for j in range(n)] for i in range(n)])\n", " return e(M_p.determinant())" ] }, { "cell_type": "code", "execution_count": 52, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "'the discriminant of f : \\t' e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3] - 8*e[4, 1, 1] + 24*e[4, 2]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show(\"the discriminant of f : \\t\",discriminant_with_sym_func(3))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Remember that the discriminant of $z^3+bz^2+cz+d$ is $$b^2c^2+18bcd-4c^3-4b^3d-27d^2$$" ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "b^2*c^2 - 4*b^3*d - 4*c^3 + 18*b*c*d - 27*d^2" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "var('b,c,d')\n", "D = b^2*c^2+18*b*c*d-4*c^3-4*b^3*d-27*d^2\n", "show(D)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "e[2, 2, 1, 1] - 4*e[2, 2, 2] - 4*e[3, 1, 1, 1] + 18*e[3, 2, 1] - 27*e[3, 3] - 8*e[4, 1, 1] + 24*e[4, 2]" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "D = D.substitute({b:e[1].expand(n), c:e[2].expand(n), d:e[3].expand(n)})\n", "e.from_polynomial(R((D))) " ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "True" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e.from_polynomial(R((D))) == discriminant_with_sym_func(3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "A = QQ['y']['x0','x1']" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "B = QQ['y','x0','x1']" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "A.random_element()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "f = _" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "B(f)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "B(f).subs(y=B.gens()[1])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "A(B(f))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "

Conclusion

\n", "\n", "
\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "\n", "\n", "For more on binder and rise : https://opendreamkit.org/2018/07/23/live-online-slides-with-sagemath-jupyter-rise-binder/" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "
Thank you !
" ] } ], "metadata": { "celltoolbar": "Diaporama", "kernelspec": { "display_name": "SageMath 8.7", "language": "", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15" }, "rise": { "scroll": true, "theme": "sky" } }, "nbformat": 4, "nbformat_minor": 2 }