On Mar 30, 10:14 am, Eric Gourgoulhon <egourgoul...@gmail.com> wrote: > Hello, > > I've noticed this strange behavior (bug ?) on the following elementary > computation: > > sage: a = matrix([[sqrt(x),0,0,0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, > 1]]) > sage: det(a) > ... > TypeError: no conversion of this rational to integer
Good catch! The problem seems to be that `det` punts to `charpoly` for 4x4 matrices and larger, and that has some issues: sage: a=matrix([[x,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) sage: charpoly(a) 0 this is due to the use of "x" as a variable: sage: var('y') y sage: a=matrix([[y,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) sage: charpoly(a) x^4 + (-y - 3)*x^3 + (3*y + 3)*x^2 + (-3*y - 1)*x + y which is correct. That is not the (only) issue you are running into, however. Unwrapping the code for a.charpoly: sage: a=matrix([[y^(1/2),0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) sage: self=a sage: var='x' sage: cp = self._maxima_(maxima).charpoly(var)._sage_() Up to here everything is fine: sage: cp (x - 1)^3*(x - sqrt(y)) sage: cp.expand() x^4 - x^3*sqrt(y) - 3*x^3 + 3*x^2*sqrt(y) + 3*x^2 - 3*x*sqrt(y) - x + sqrt(y) It's in the following step that things go wrong: sage: cp.expand().polynomial(None, ring=SR[var]) TypeError so the problem is sage.symbolic.expression_conversions.polynomial It's silly that such a generic, dodgy routine is used here. You know which variable you want to isolate (and we should NOT make that 'x' but some 'custom_variable_you_never_use_somewhere_else') and you also know the degree. So the conversion should be something like V=SR('crazy_varname') cp=self._maxima_(maxima).charpoly('crazy_varname')._sage_().expand() SR[var](list(cp.coefficient(V,i) for i in range(self.nrows()+1))) Of course, even in this you're at the mercy of maxima's expand doing what you'd hope it does, but given that the result really should just be a polynomial in 'crazy_varname', so we can have good hopes 'expand' does the proper (expensive) thing here. (You really don't want to let 'crazy_varname' leak out of charpoly, otherwise you'll have trouble if someone decides to make a matrix of characteristic polynomials and determine the charpoly of that. You also don't want to generate a fresh variable every time, since the management of variables in maxima/our interface would create a memory leak) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.