%display latex
Two reference pages for symmetric functions in Sage.
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}).$$
Our goal is to find the discriminant of $f$ for $n=2$ and $n=3$ using symmetric functions.
n = 2
F = QQ['z']
F.inject_variables()
R = PolynomialRing(F,'x',n)
R.inject_variables()
x = R.gens()
Defining z Defining x0, x1
Question : Define the polynomial $f$ with the indeterminates $z, x_0$ and $x_1$.
f = prod((z-x[i]) for i in range(0,n))
f
if n==2 :
A = QQ['z,x0,x1']
assert A(f)(z=x[0]) == 0
Remark that $f$ is symmetric w.r.t the variables $x_0$ and $x_1$. Then the fundamental theorem of symmetric polynomials tells us that we can express $f$ in terms of elementary symmetric polynomials.
Definition: The elementary symmetric polynomial $e_k$ is defined to be the sum of all monomials of degree $k$ with no squares.
e = SymmetricFunctions(QQ[z]).e()
for k in range(5):
show(e[k].expand(4))
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$.
g = e.from_polynomial(f)
g
g.expand(n)
Definition : The discriminant of $f$ is given by $$\Delta(f) = \prod_{i>j} (x_i-x_j)^2$$ where $x_i$ are the roots of $f$.
Recall that the Vandermonde matrix $$ M = \begin{bmatrix} 1 & 1 & \dots & 1 \\ x_0 & x_1 & \dots & x_{n-1} \\ x_0^2 & x_1^2 & \dots & x_{n-1}^2 \\ \vdots & \vdots & \ddots & \vdots \\ x_0^{n-1} & x_1^{n-1} & \dots & x_{n-1}^{n-1} \end{bmatrix} $$
has determinant $\det M = \prod_{i>j} (x_i-x_j)$. So $\Delta(f) = (\det M)^2$.
Question : Check that $\Delta(f) = \det(M^2)$ for $n=2$.
M = matrix.vandermonde(x)
M
(M.determinant())^2
(M.determinant())^2 == prod((x[i]-x[j])^2 for i in range(n) for j in range(n) if i>j)
Proposition: Let $A$ be a $n \times n $ matrix, then we have $\det(A)^2 = \det(A^\bot A)$.
We can check that on a random $3 \times 3$ matrix on $\mathbb{Q}$.
A = matrix.random(QQ, 3, algorithm='diagonalizable')
(A.determinant())^2 == (A.transpose()*A).determinant()
In the case of the Vandermonde matrix, we get the following.
T = M.transpose()*M
T
We recognize the power sum symmetric polynomials.
Definition: The power sum symmetric polynomials $p_k$ are defined to be $\sum_i x_i^k$.
p = SymmetricFunctions(QQ[z]).p()
for k in range(4):
show(p[k].expand(4))
Question : Express the coefficients of $ T := M^\bot M$ in terms of power sum symmetric polynomials.
T_p = matrix([[p.from_polynomial(T[i,j]) for j in range(n)] for i in range(n)])
T_p
Question : Compute the determinant of the matrix $T_p$.
T_p.determinant()
Question : Express the result in terms of elementary symmetric polynomials and find the discriminant of $f$.
e(T_p.determinant())
Remember $a=1$, $b=-e_1$ and $c=e_2$. As expected we obtain that $\Delta = b^2 - 4c$.
n = 3
F = QQ['z']
F.inject_variables(verbose=False)
R = PolynomialRing(F,'x',n)
R.inject_variables(verbose=False)
x = R.gens()
f = prod((z-x[i]) for i in range(0,3))
show("f in terms of elementary symmetric functions : \t",e.from_polynomial(f))
def discriminant_with_sym_func(n) :
M = matrix.vandermonde(x)
T = M.transpose()*M
M_p = matrix([[p.from_polynomial(T[i,j]) for j in range(n)] for i in range(n)])
return e(M_p.determinant())
show("the discriminant of f : \t",discriminant_with_sym_func(3))
Remember that the discriminant of $z^3+bz^2+cz+d$ is $$b^2c^2+18bcd-4c^3-4b^3d-27d^2$$
var('b,c,d')
D = b^2*c^2+18*b*c*d-4*c^3-4*b^3*d-27*d^2
show(D)
D = D.substitute({b:e[1].expand(n), c:e[2].expand(n), d:e[3].expand(n)})
e.from_polynomial(R((D)))
e.from_polynomial(R((D))) == discriminant_with_sym_func(3)
A = QQ['y']['x0','x1']
B = QQ['y','x0','x1']
A.random_element()
f = _
B(f)
B(f).subs(y=B.gens()[1])
A(B(f))
For more on binder and rise : https://opendreamkit.org/2018/07/23/live-online-slides-with-sagemath-jupyter-rise-binder/