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

Commit 35a3314

Browse files
committed
Trac 18040: implement minimal polynomial for matrices over the symbolic ring
1 parent 7f1fbd5 commit 35a3314

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/sage/interfaces/maxima_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
# keepfloat -- don't automatically convert floats to rationals
142142
init_code = ['display2d : false', 'domain : complex', 'keepfloat : true',
143143
'load(to_poly_solve)', 'load(simplify_sum)',
144-
'load(abs_integrate)']
144+
'load(abs_integrate)', 'load(diag)']
145145

146146
# Turn off the prompt labels, since computing them *very
147147
# dramatically* slows down the maxima interpret after a while.

src/sage/matrix/matrix2.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,12 +1924,6 @@ cdef class Matrix(matrix1.Matrix):
19241924
sage: factor(A.minpoly('y'))
19251925
(y + 1) * (y + 2)^2
19261926

1927-
We can take the minimal polynomial of symbolic matrices::
1928-
1929-
sage: t = var('t')
1930-
sage: m = matrix(2,[1,2,4,t])
1931-
sage: m.minimal_polynomial()
1932-
x^2 + (-t - 1)*x + t - 8
19331927
"""
19341928
f = self.fetch('minpoly')
19351929
if not f is None:

src/sage/matrix/matrix_symbolic_dense.pyx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Conversion to Maxima::
148148
149149
"""
150150

151-
151+
from sage.rings.polynomial.all import PolynomialRing
152152
from sage.structure.element cimport ModuleElement, RingElement, Element
153153
from sage.structure.factorization import Factorization
154154

@@ -451,6 +451,39 @@ cdef class Matrix_symbolic_dense(matrix_generic_dense.Matrix_generic_dense):
451451
self.cache(cache_key, cp)
452452
return cp
453453

454+
def minpoly(self, var='x'):
455+
"""
456+
Return the minimal polynomial of ``self``.
457+
458+
EXAMPLES::
459+
460+
sage: M = Matrix.identity(SR, 2)
461+
sage: M.minpoly()
462+
x - 1
463+
464+
sage: t = var('t')
465+
sage: m = matrix(2, [1, 2, 4, t])
466+
sage: m.minimal_polynomial()
467+
x^2 + (-t - 1)*x + t - 8
468+
469+
TESTS:
470+
471+
Check that the variable `x` can occur in the matrix::
472+
473+
sage: m = matrix([[x]])
474+
sage: m.minimal_polynomial('y')
475+
y - x
476+
477+
"""
478+
mp = self.fetch('minpoly')
479+
if mp is None:
480+
mp = self._maxima_lib_().jordan().minimalPoly().expand()
481+
d = mp.hipow('x')
482+
mp = [mp.coeff('x', i) for i in xrange(0, d + 1)]
483+
mp = PolynomialRing(self.base_ring(), 'x')(mp)
484+
self.cache('minpoly', mp)
485+
return mp.change_variable_name(var)
486+
454487
def fcp(self, var='x'):
455488
"""
456489
Return the factorization of the characteristic polynomial of self.

0 commit comments

Comments
 (0)