Ask Your Question

Revision history [back]

The matrix you defined has coefficients in the Symbolic Ring.

sage: theta = SR.var('theta')
sage: assume(theta,'real')
sage: M = matrix([[1,0],[cos(theta),-i*sin(theta)]])/sqrt(2)
sage: M
[              1/2*sqrt(2)                         0]
[   1/2*sqrt(2)*cos(theta) -1/2*I*sqrt(2)*sin(theta)]
sage: M.parent()
sage: M.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring

The characteristic polynomial you compute has coefficients in the Symbolic Ring.

sage: cp = characteristic_polynomial((M.conjugate_transpose())*M)
sage: cp
x^2 + (-1/2*cos(theta)^2 - 1/2*sin(theta)^2 - 1/2)*x + 1/4*sin(theta)^2
sage: R = cp.parent()
sage: R
Univariate Polynomial Ring in x over Symbolic Ring

You can get the list of its coefficients:

sage: cp.coefficients()
[1/4*sin(theta)^2, -1/2*cos(theta)^2 - 1/2*sin(theta)^2 - 1/2, 1]

You apply simplify_trig to each coefficient.

sage: [a.simplify_trig() for a in cp.coefficients()]
[1/4*sin(theta)^2, -1, 1]

You can then transform the list back into a polynomial.

sage: R([a.simplify_trig() for a in cp.coefficients()])
x^2 - x + 1/4*sin(theta)^2

Or you could define x as the generator of the polynomial ring over the Symbolic Ring and do this:

sage: x = polygen(SR)
sage: sum(a.simplify_trig()*x^k for k,a in enumerate(cp.coefficients()))
x^2 - x + 1/4*sin(theta)^2

The matrix you defined define has coefficients in the Symbolic Ring.

sage: theta = SR.var('theta')
sage: assume(theta,'real')
sage: M = matrix([[1,0],[cos(theta),-i*sin(theta)]])/sqrt(2)
sage: M
[              1/2*sqrt(2)                         0]
[   1/2*sqrt(2)*cos(theta) -1/2*I*sqrt(2)*sin(theta)]
sage: M.parent()
sage: M.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring

The characteristic polynomial you compute has coefficients in the Symbolic Ring.

sage: cp = characteristic_polynomial((M.conjugate_transpose())*M)
sage: cp
x^2 + (-1/2*cos(theta)^2 - 1/2*sin(theta)^2 - 1/2)*x + 1/4*sin(theta)^2
sage: R = cp.parent()
sage: R
Univariate Polynomial Ring in x over Symbolic Ring

You can get the list of its coefficients:

sage: coeffs = cp.coefficients()
sage: coeffs
[1/4*sin(theta)^2, -1/2*cos(theta)^2 - 1/2*sin(theta)^2 - 1/2, 1]

You apply simplify_trig to each coefficient.

sage: simp_coeffs = [a.simplify_trig() for a in cp.coefficients()]
coeffs]
sage: simp_coeffs
[1/4*sin(theta)^2, -1, 1]

You can then transform the list back into a polynomial.

sage: R([a.simplify_trig() for a in cp.coefficients()])
R(simp_coeffs)
x^2 - x + 1/4*sin(theta)^2

Or you could define x as the generator of the polynomial ring over the Symbolic Ring and do this:

sage: x = polygen(SR)
sage: sum(a.simplify_trig()*x^k for k,a in enumerate(cp.coefficients()))
enumerate(coeffs))
x^2 - x + 1/4*sin(theta)^2

All in one line from your definition of cp:

sage: cp.parent()([a.simplify_trig() for a in cp.coefficients()])
x^2 - x + 1/4*sin(theta)^2