I just worked on implementing the sage-combinat generic testing framework for matrices, with a test function for minpoly. I got some interesting results. Is there something wrong in these tests below?
************************************************************************** Over GF(5), I get lots of different results: sage: A = Matrix(GF(5),3,3,srange(9)) sage: A.minpoly() x^3 + 3*x^2 + 2*x sage: A.minpoly() x^2 + 2*x sage: A.minpoly() x^2 + 3*x + 2 sage: A.minpoly() x^3 + 3*x^2 + 2*x sage: A.minpoly() x^3 + 3*x^2 + 2*x sage: A.minpoly() x^2 + x sage: A.minpoly() x^2 + x sage: A.minpoly() x^2 + 2*x sage: A.minpoly() x^2 + x sage: A.minpoly() x^3 + 3*x^2 + 2*x ************************************************************************** Over QQ[a,b], I get an error: sage: R.<a,b> = QQ[] sage: m = matrix(R,2,[0,a,b,b^2]) sage: m.minpoly() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/jason/.sage/temp/littleone/16177/_home_jason__sage_init_sage_0.py in <module>() /home/jason/sage/local/lib/python2.6/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.minpoly (sage/matrix/matrix2.c:8014)() /home/jason/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.is_squarefree (sage/rings/polynomial/polynomial_element.c:32924)() AttributeError: 'sage.rings.polynomial.polynomial_element.Polynomia' object has no attribute 'gcd' ************************************************************************** Over Integers(25)['x'], I get an error: sage: A = random_matrix(Integers(25)['x'],2); A [7*x^2 + 20*x + 23 2*x^2 + 2*x + 18] [ x^2 + 12*x + 22 6*x^2 + 16*x + 15] sage: A.minpoly() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/jason/.sage/temp/littleone/16177/_home_jason__sage_init_sage_0.py in <module>() /home/jason/sage/local/lib/python2.6/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.minpoly (sage/matrix/matrix2.c:7997)() /home/jason/sage/local/lib/python2.6/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.charpoly (sage/matrix/matrix2.c:8742)() /home/jason/sage/local/lib/python2.6/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix._charpoly_hessenberg (sage/matrix/matrix2.c:10491)() /home/jason/sage/local/lib/python2.6/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.hessenberg_form (sage/matrix/matrix2.c:9779)() TypeError: self must be an integral domain. Hessenberg form only possible for matrices over a field ************************************************************************** This funny behavior with the is_zero function on 2x2 integer matrices showed up: sage: m=sage.matrix.matrix_integer_2x2.MatrixSpace_ZZ_2x2()(0) sage: m [0 0] [0 0] sage: m.is_zero() True sage: (m-m).is_zero() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/jason/.sage/temp/littleone/16177/_home_jason__sage_init_sage_0.py in <module>() /home/jason/sage/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element.is_zero (sage/structure/element.c:4811)() /home/jason/sage/local/lib/python2.6/site-packages/sage/matrix/matrix0.so in sage.matrix.matrix0.Matrix.__nonzero__ (sage/matrix/matrix0.c:21577)() TypeError: 'NoneType' object is not callable ************************************************************************** Okay, so I'm now sold on the generic testing framework in #6343 (which has been merged into 4.1.2.alpha2). For the curious, all I did was define a function: def _test_minpoly(self, **options): """ Checks that :meth:`minpoly` works. EXAMPLES:: sage: a=matrix([[1,2],[3,4]]) sage: a._test_minpoly() """ if self.nrows()==self.ncols(): tester = self._tester(**options) # At least we'll check that the minimal polynomial kills the # matrix. tester.assert_(self.minpoly().subs(x=self).is_zero()) Then in every matrix class, right under the calls to load(dumps..., I just put a call to TestSuite().run(), like so: sage: m = matrix(ZZ['x'], 2, 3, [1..6]) sage: loads(dumps(m)) == m True sage: TestSuite(m).run() Then I ran the doctests in the matrix directory and all the above errors were failures in the doctests. (I also had to change an existing method called "_test_pickle" to conform to the new generic doctesting framework) Jason -- Jason Grout --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---