diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index 308a7525c70..d367a11ef82 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -5356,6 +5356,33 @@ cdef class Matrix(sage.structure.element.Matrix): sage: N = ~M sage: (N*M).norm() 0.9999999999999999 + + Check that :trac:`28402` is fixed:: + + sage: B = matrix(RR, [[1/6, -1/24, -1/30, 1/120,1/12, 0, 0, 0, 0], + ....: [-1/24,1/60,1/60, 1/420, -1/24, 0, 0, 0, 0], + ....: [-1/30,1/60, 2/105, 1/140, -1/20, 0, 0, 0, 0], + ....: [1/120, 1/420, 1/140, 13/1260, -1/40, 0, 0, 0, 0], + ....: [1/12, -1/24, -1/20, -1/40, 1/3, -1/24, -1/30, 1/120,1/12], + ....: [0, 0, 0, 0, -1/24,1/60,1/60, 1/420, -1/24], + ....: [0, 0, 0, 0, -1/30,1/60, 2/105, 1/140, -1/20], + ....: [0, 0, 0, 0, 1/120, 1/420, 1/140, 13/1260, -1/40], + ....: [0, 0, 0, 0,1/12, -1/24, -1/20, -1/40, 1/6]], + ....: sparse=True) + sage: (B.inverse()*B).norm(1) # rel tol 2e-12 + 1.0 + sage: B = matrix(QQ, [[1/6, -1/24, -1/30, 1/120,1/12, 0, 0, 0, 0], + ....: [-1/24,1/60,1/60, 1/420, -1/24, 0, 0, 0, 0], + ....: [-1/30,1/60, 2/105, 1/140, -1/20, 0, 0, 0, 0], + ....: [1/120, 1/420, 1/140, 13/1260, -1/40, 0, 0, 0, 0], + ....: [1/12, -1/24, -1/20, -1/40, 1/3, -1/24, -1/30, 1/120,1/12], + ....: [0, 0, 0, 0, -1/24,1/60,1/60, 1/420, -1/24], + ....: [0, 0, 0, 0, -1/30,1/60, 2/105, 1/140, -1/20], + ....: [0, 0, 0, 0, 1/120, 1/420, 1/140, 13/1260, -1/40], + ....: [0, 0, 0, 0,1/12, -1/24, -1/20, -1/40, 1/6]], + ....: sparse=True) + sage: (B.inverse()*B).norm(1) + 1.0 """ if not self.base_ring().is_field(): try: @@ -5403,13 +5430,12 @@ cdef class Matrix(sage.structure.element.Matrix): if self.base_ring().is_exact(): if A[self._nrows-1, self._ncols-1] != 1: raise ZeroDivisionError("input matrix must be nonsingular") + if self.is_sparse(): + return self.build_inverse_from_augmented_sparse(A) else: if not A[self._nrows-1, self._ncols-1]: raise ZeroDivisionError("input matrix must be nonsingular") - if self.is_sparse(): - return self.build_inverse_from_augmented_sparse(A) - return A.matrix_from_columns(list(xrange(self._ncols, 2 * self._ncols))) cdef build_inverse_from_augmented_sparse(self, A):