Ask Your Question
1

Using polynomial over matrices

asked 2012-04-11 14:05:12 +0100

Pierre L gravatar image

Things goes wrong when I try to define polynomial ring over a matrix algebra. When I type

A = MatrixSpace(QQ, 2)
PA.<x> = PolynomialRing(A)
x

I obtain the following error :

AttributeError: 'MatrixSpace_generic' object has no attribute 'is_atomic_repr'

Of course, I could use matrices over polynomial rings, but I would loss generality of the code... Do you have any idea ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-04-11 15:00:02 +0100

niles gravatar image

The problem is just with printing elements of the ring; the function is_atomic_repr is just used to determine whether or not to write parentheses around the coefficients of a polynomial (e.g. the elements of ZZ are atomic, but elements of a polynomial ring are not).

Matrix_space doesn't have one, but you can give it one easily:

sage: A = MatrixSpace(QQ, 2)
sage: PA.<x> = PolynomialRing(A)
sage: def iar():
...    return True
...
sage: A.is_atomic_repr = iar
sage: x
[1 0]
[0 1]*x

Note that things will still print in silly ways, because matrices always print a linebreak after printing the top row:

sage: f = PA.random_element()
sage: f
[   1    1]
[-1/2    0]*x^2 + [1/2 1/2]
[  0  -2]*x + [-1/2    0]
[  -1    0]
sage: f[0]
[-1/2    0]
[  -1    0]
sage: f[1]
[1/2 1/2]
[  0  -2]

You can still work with polynomials and print their coefficients without defining is_atomic_repr:

sage: B = MatrixSpace(ZZ, 2)
sage: PB.<x> = PolynomialRing(B)
sage: f = x - 1
sage: (f^2).coeffs()
[
[1 0]  [-2  0]  [1 0]
[0 1], [ 0 -2], [0 1]
]
sage: (f^2+1).dict()
{0: [2 0]
[0 2], 1: [-2  0]
[ 0 -2], 2: [1 0]
[0 1]}

sage: ((x^2 + 1)^2).padded_list()
[
[1 0]  [0 0]  [2 0]  [0 0]  [1 0]
[0 1], [0 0], [0 2], [0 0], [0 1]
]

sage: ((f^2 - f)^3)[0]
[8 0]
[0 8]
sage: ((f^2 - f)^3)[4]
[33  0]
[ 0 33]
edit flag offensive delete link more

Comments

Thanks ! That was quite tricky...

Pierre L gravatar imagePierre L ( 2012-04-11 15:49:47 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-04-11 14:05:12 +0100

Seen: 616 times

Last updated: Apr 11 '12