Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac 18040: implement minimal polynomial for matrices over the symbol…
Browse files Browse the repository at this point in the history
…ic ring
  • Loading branch information
pjbruin committed Mar 23, 2015
1 parent 7f1fbd5 commit 35a3314
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sage/interfaces/maxima_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
# keepfloat -- don't automatically convert floats to rationals
init_code = ['display2d : false', 'domain : complex', 'keepfloat : true',
'load(to_poly_solve)', 'load(simplify_sum)',
'load(abs_integrate)']
'load(abs_integrate)', 'load(diag)']

# Turn off the prompt labels, since computing them *very
# dramatically* slows down the maxima interpret after a while.
Expand Down
6 changes: 0 additions & 6 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1924,12 +1924,6 @@ cdef class Matrix(matrix1.Matrix):
sage: factor(A.minpoly('y'))
(y + 1) * (y + 2)^2

We can take the minimal polynomial of symbolic matrices::

sage: t = var('t')
sage: m = matrix(2,[1,2,4,t])
sage: m.minimal_polynomial()
x^2 + (-t - 1)*x + t - 8
"""
f = self.fetch('minpoly')
if not f is None:
Expand Down
35 changes: 34 additions & 1 deletion src/sage/matrix/matrix_symbolic_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Conversion to Maxima::
"""


from sage.rings.polynomial.all import PolynomialRing
from sage.structure.element cimport ModuleElement, RingElement, Element
from sage.structure.factorization import Factorization

Expand Down Expand Up @@ -451,6 +451,39 @@ cdef class Matrix_symbolic_dense(matrix_generic_dense.Matrix_generic_dense):
self.cache(cache_key, cp)
return cp

def minpoly(self, var='x'):
"""
Return the minimal polynomial of ``self``.
EXAMPLES::
sage: M = Matrix.identity(SR, 2)
sage: M.minpoly()
x - 1
sage: t = var('t')
sage: m = matrix(2, [1, 2, 4, t])
sage: m.minimal_polynomial()
x^2 + (-t - 1)*x + t - 8
TESTS:
Check that the variable `x` can occur in the matrix::
sage: m = matrix([[x]])
sage: m.minimal_polynomial('y')
y - x
"""
mp = self.fetch('minpoly')
if mp is None:
mp = self._maxima_lib_().jordan().minimalPoly().expand()
d = mp.hipow('x')
mp = [mp.coeff('x', i) for i in xrange(0, d + 1)]
mp = PolynomialRing(self.base_ring(), 'x')(mp)
self.cache('minpoly', mp)
return mp.change_variable_name(var)

def fcp(self, var='x'):
"""
Return the factorization of the characteristic polynomial of self.
Expand Down

0 comments on commit 35a3314

Please sign in to comment.