Ask Your Question
1

Multiplying matrices with different parents?

asked 2015-06-24 18:39:06 +0100

Acanti gravatar image

updated 2023-01-09 23:59:37 +0100

tmonteil gravatar image

I want to conjugate a symbolic matrix, Sigma, by a matrix, garbage, over Z/9Z. If I define both matrices as symbolic matrices, I get the right answer. If I define garbage over Z/9Z, I get confusing answers. Can anyone explain my results?

Sigma=matrix(SR,2,[[1+3*A,3*B],[3*C,1+3*D]])
garbage=matrix(SR,2,[[2,1],[2,6]]);garbageinverse=matrix(SR,2,[[6,8],[7,2]])
expand(garbage*Sigma*garbageinverse);(Sigma*garbageinverse)[0,0]*garbage[1,0]+(Sigma*garbageinverse)[1,0]*garbage[1,1]
R=Integers(9)
garbage=matrix(R,2,[[2,1],[2,6]]);garbageinverse=matrix(R,2,[[6,8],[7,2]])
expand(garbage*Sigma*garbageinverse);(Sigma*garbageinverse)[0,0]*garbage[1,0]+(Sigma*garbageinverse)[1,0]*garbage[1,1]

[  36*A + 42*B + 18*C + 21*D + 19    48*A + 12*B + 24*C + 6*D + 18]
[36*A + 42*B + 108*C + 126*D + 54  48*A + 12*B + 144*C + 36*D + 28]
36*A + 42*B + 108*C + 126*D + 54
[        6*B + 3*D + 1 3*A + 3*B + 6*C + 6*D]
[            0*A + 0*D         3*A + 0*D + 1]
6*B + 0*D
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-06-24 22:47:35 +0100

tmonteil gravatar image

updated 2015-06-25 14:25:44 +0100

There is indeed something wrong with how the Symbolic Ring deals with integer modulo 9.

Here is the actual issue:

sage: _ = var('A,B')
sage: (A + 3*B)*Zmod(9)(6)
0*B

while the result should be 6*A. Thanks for pointing this issue, i opened trac ticket 18787.

What is even more weird is that i found some non-determinism, since i once get the following result without being able to reproduce (on Sage 6.8.beta5):

sage: var('A,B,C,D')
(A, B, C, D)
sage: Sigma=matrix(SR,2,[[1+3*A,3*B],[3*C,1+3*D]])
sage: garbage=matrix(SR,2,[[2,1],[2,6]]);garbageinverse=matrix(SR,2,[[6,8],[7,2]])
sage: expand(garbage*Sigma*garbageinverse);(Sigma*garbageinverse)[0,0]*garbage[1,0]+(Sigma*garbageinverse)[1,0]*garbage[1,1]
[  36*A + 42*B + 18*C + 21*D + 19    48*A + 12*B + 24*C + 6*D + 18]
[36*A + 42*B + 108*C + 126*D + 54  48*A + 12*B + 144*C + 36*D + 28]
36*A + 42*B + 108*C + 126*D + 54
sage: R=Integers(9)
sage: garbage=matrix(R,2,[[2,1],[2,6]]);garbageinverse=matrix(R,2,[[6,8],[7,2]])
sage: expand(garbage*Sigma*garbageinverse);(Sigma*garbageinverse)[0,0]*garbage[1,0]+(Sigma*garbageinverse)[1,0]*garbage[1,1]
[        6*B + 3*D + 1 3*A + 3*B + 6*C + 6*D]
[            0*A + 6*B         3*A + 3*B + 1]
6*B + 0*D

That said, for such algebraic questions, i would recommend to work on well defined rings:

sage: R.<a,b,c,d> = PolynomialRing(Integers(9),4)
sage: R
Multivariate Polynomial Ring in a, b, c, d over Ring of integers modulo 9
sage: Sigma = matrix(R,2,[[1+3*a,3*b],[3*c,1+3*d]])
sage: garbage = matrix(R,2,[[2,1],[2,6]])
sage: garbageinverse=matrix(R,2,[[6,8],[7,2]])
sage: garbage*Sigma*garbageinverse
[        6*b + 3*d + 1 3*a + 3*b + 6*c + 6*d]
[                  6*b         3*a + 3*b + 1]
sage: (Sigma*garbageinverse)[0,0]*garbage[1,0]+(Sigma*garbageinverse)[1,0]*garbage[1,1]
6*b
edit flag offensive delete link more

Comments

1

Thank you for looking into this for me! As a new user, I'm glad to know it wasn't something ridiculous on my part. Also, thanks for the suggestion to use the polynomial ring. That will get me through what I need to do.

Acanti gravatar imageAcanti ( 2015-06-24 23:16:15 +0100 )edit

Thierry, if you can get any smaller examples of this please do open a ticket. But I agree that in general SR is ill-equipped to handle modular stuff, because SR sort of implicitly assumes characteristic zero I think.

kcrisman gravatar imagekcrisman ( 2015-06-25 05:41:02 +0100 )edit

Pynac has some code that takes the characteristic into account but I have no idea how complete it is.

rws gravatar imagerws ( 2015-06-25 07:47:57 +0100 )edit

I could not find a smaller example since the direct computation of the coefficients is OK, so there is something with matrices.

tmonteil gravatar imagetmonteil ( 2015-06-25 13:09:17 +0100 )edit

But Jeroen did !

tmonteil gravatar imagetmonteil ( 2015-06-25 14:21:44 +0100 )edit
1

answered 2015-06-25 10:19:28 +0100

slelievre gravatar image

@tmonteil's answer says it all. What I have to add is more a comment than an answer.

For a question on ask-sage, why not use simpler names and provide readable code?

sage: Z9 = Zmod(9)
sage: R.<a,b,c,d> = PolynomialRing(Z9)
sage: m = matrix(R, 2, [[1+3*a,3*b],[3*c,1+3*d]])
sage: g = matrix(R, 2,[[2,1],[2,6]])
sage: gi = matrix(R, 2,[[6,8],[7,2]]) # this is g inverse
sage: g * gi
[1 0]
[0 1]
sage: g * m * gi
[        6*b + 3*d + 1 3*a + 3*b + 6*c + 6*d]
[                  6*b         3*a + 3*b + 1]
sage: (m * gi)[0,0] * g[1,0] + (m * gi)[1,0] * g[1,1]
6*b
edit flag offensive delete link more

Comments

I think the answer to that is that new users of this (or any) Q&A site may not yet be accustomed to the local customs.

kcrisman gravatar imagekcrisman ( 2015-06-25 15:20:00 +0100 )edit

Ignore that, you are talking about the answer. Agreed, but perhaps T was just trying to match the OP's names as much as possible - but yours is undoubtedly clearer :)

kcrisman gravatar imagekcrisman ( 2015-06-25 15:22:40 +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

1 follower

Stats

Asked: 2015-06-24 18:39:06 +0100

Seen: 561 times

Last updated: Jun 25 '15