I sent the following to John Cremona - he suggested I post it here. 

Dear John - 

  I was computing Smith normal forms (over ZZ) and I ran into an issue.  I 
boiled it down to this: 

sage: version()
'Sage Version 5.12, Release Date: 2013-10-07'
sage: M = matrix([[1,0],[0,1]])
sage: M
[1 0]
[0 1]
sage: M.parent()
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
sage: M.inverse()
[1 0]
[0 1]
sage: M.inverse().parent()
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

Note that the base ring has changed.  This caught me out: I was computing 
Smith normal forms in two ways and they were different.  Eventually I 
realized that (obviously) the Smith normal form is sensitive to the base 
ring!

Does the base ring have to change here?  I guess that there is a subtle 
algorithm to quickly compute inverses, that requires extending the ring.  
But once we've got the answer, couldn't we do a fast check to see if the 
answer is actually in the original base ring?

That is - if M is the original matrix and N is the computed inverse then 
add this to the very end: 

if N.parent() == M.parent(): 
    return N
try:
    R = M.parent().base_ring()
    P = N.change_ring(R)
    assert M*P == P*M == 1
    return P
except: 
    return N

all the best,

saul

[Edit]
John pointed me to the code for M.__invert__() so I suppose that I am 
suggesting placing some version of the above code after the try and before 
the return, around line 11. 

"try:
                        return (~self.lift()).change_ring(self.base_ring())"

Of course, in this particular place in the code the first two lines of my 
suggestion are pointless.  

best,

saul

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to