Ask Your Question

Revision history [back]

The problem is that Sage is unable to convert 1/t^2, seen as an element in the fraction field of the univariate polynomial ring in t, to the ring of Laurent polynomials.

You could define an inverse function as follows for your needs.

def inv(m):
    r"""
    Return the inverse of this matrix over a ring of Laurent polynomials

    Raises ``ZeroDivisionError`` if matrix has zero determinant,
    and ``ArithmeticError`` if matrix is nonsquare.

    Uses the meth:`__invert__` method in `src/sage/matrix/matrix0.pyx`,
    which returns a matrix over the fraction field. This is then
    converted back to the ring of Laurent polynomials, with the trick
    that the fraction field of a ring of Laurent polynomials is really
    the fraction field of the corresponding ring of polynomials.

    EXAMPLE::

        sage: R.<t> = LaurentPolynomialRing(ZZ)
        sage: f = t^2
        sage: m = matrix([[f]])
        sage: m.parent()
        Full MatrixSpace of 1 by 1 dense matrices over
        Univariate Laurent Polynomial Ring in t over Integer Ring
        sage: mi = inv(m)
        sage: mi
        [1/t^2]
        sage: mi.parent()
        Full MatrixSpace of 1 by 1 dense matrices over
        Univariate Laurent Polynomial Ring in t over Integer Ring
    """
    M = m.parent()
    R = m.base_ring()
    l = m.inverse().list()
    return M([R(x.numerator()) * R(x.denominator()).inverse_of_unit() for x in l])

The problem is that Sage is unable to convert 1/t^2, seen as an element in the fraction field of the univariate polynomial ring in t, to the ring of Laurent polynomials.polynomials in t.

You could define an inverse The following function as follows for should fit your needs.

def inv(m):
    r"""
    Return the inverse of this matrix over a ring of Laurent polynomials

    Raises ``ZeroDivisionError`` if matrix has zero determinant,
    and ``ArithmeticError`` if matrix is nonsquare.

    Uses the meth:`__invert__` method in `src/sage/matrix/matrix0.pyx`,
    which returns a matrix over the fraction field. This is then
    converted back to the ring of Laurent polynomials, with the trick
    that the fraction field of a ring of Laurent polynomials is really
    the fraction field of the corresponding ring of polynomials.

    EXAMPLE::

        sage: R.<t> = LaurentPolynomialRing(ZZ)
        sage: f = t^2
        sage: m = matrix([[f]])
matrix([[t^2]])
        sage: m.parent()
        Full MatrixSpace of 1 by 1 dense matrices over
        Univariate Laurent Polynomial Ring in t over Integer Ring
        sage: mi = inv(m)
        sage: mi
        [1/t^2]
        sage: mi.parent()
        Full MatrixSpace of 1 by 1 dense matrices over
        Univariate Laurent Polynomial Ring in t over Integer Ring
    """
    M = m.parent()
    R = m.base_ring()
    l = m.inverse().list()
    return M([R(x.numerator()) * R(x.denominator()).inverse_of_unit() for x in l])

Then, as in the example,

sage: R.<t> = LaurentPolynomialRing(ZZ)
sage: m = matrix([[t^2]])
sage: inv(m)
[1/t^2]