# Inverses of matrices of Laurent polynomials

This question is rather similar in spirit to my previous question in that it's about figuring out how to "correctly" manipulate matrices of polynomials, ensuring that everything stays in the right rings.

In this case, I have a matrix, all of whose elements are of the form Univariate Laurent Polynomial Ring in t over Integer Ring. The matrix has an inverse over this ring, yet sage insists that the entries of the inverse belong to Fraction Field of Univariate Polynomial Ring in t over Integer Ring. Here's a minimal example:

sage: R.<t> = LaurentPolynomialRing(ZZ)
sage: f = t^2
sage: mat = matrix([[f]])
sage: mat[0,0].parent()
Univariate Laurent Polynomial Ring in t over Integer Ring
sage: mat.inverse()
[1/t^2]
sage: mat.inverse()[0,0].parent()
Fraction Field of Univariate Polynomial Ring in t over Integer Ring


Desired output:

sage: mat.inverse()
[t^-2]
sage: mat.inverse()[0,0].parent()
Univariate Laurent Polynomial Ring in t over Integer Ring


What would have been the correct way to obtain what I want?

Using apply_map to force each entry back into the right ring does not immediately do the job:

sage: R(1/f)
t^-2
sage: mat.inverse().apply_map(lambda f: R(f))
...
TypeError: denominator must be a unit
sage: mat.inverse().apply_map(R)
...
TypeError: denominator must be a unit

edit retag close merge delete

Sort by » oldest newest most voted

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 in t.

The following function 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: m = 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]

more

This is defined behaviour of the general inverse, as far as I understand from the code. For example,

 sage: parent(~1)
Rational Field


The definition of Matrix_generic_dense.__invert__() explicitly states

Return this inverse of this matrix, as a matrix over the fraction field.

sage: R.fraction_field()
Fraction Field of Univariate Polynomial Ring in t over Integer Ring


I'm not an algebraist so no comment on that but, with symbolics you would stay in the ring, so symbolics seems to be good for something, contrary to many a belief.

sage: mat = matrix([[x^2]])
sage: mati = mat.inverse(); mati
[x^(-2)]
sage: mati[0,0].parent()
Symbolic Ring

more

Thanks for the answer. I don't think it entirely answers my question. In my case, there is a way to obtain a matrix over the desired ring as one could try to coerce all entries (even though apply_map doesn't work for whatever reason). Clearly though, that's a very inelegant way of doing it, and so I was looking for the "correct" way to do it.

( 2015-08-27 08:40:13 -0500 )edit