08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

Note: The rank is cached.<br />

ALGORITHM: First check if the matrix has maxim possible rank by working modulo one r<strong>and</strong>om prime.<br />

If not call LinBox’s rank function.<br />

EXAMPLES:<br />

sage: a = matrix(ZZ,2,3,[1..6]); a<br />

[1 2 3]<br />

[4 5 6]<br />

sage: a.rank()<br />

2<br />

sage: a = matrix(ZZ,3,3,[1..9]); a<br />

[1 2 3]<br />

[4 5 6]<br />

[7 8 9]<br />

sage: a.rank()<br />

2<br />

Here’s a bigger example - the rank is <strong>of</strong> course still 2:<br />

sage: a = matrix(ZZ,100,[1..100^2]); a.rank()<br />

2<br />

rational_reconstruction(N)<br />

Use rational reconstruction to lift self to a matrix over the rational numbers (if possible), where we view<br />

self as a matrix modulo N.<br />

INPUT:<br />

•N - an integer<br />

OUTPUT:<br />

•matrix - over QQ or raise a ValueError<br />

EXAMPLES: We create a r<strong>and</strong>om 4x4 matrix over ZZ.<br />

sage: A = matrix(ZZ, 4, [4, -4, 7, 1, -1, 1, -1, -12, -1, -1, 1, -1, -3, 1, 5, -1])<br />

There isn’t a unique rational reconstruction <strong>of</strong> it:<br />

sage: A.rational_reconstruction(11)<br />

Traceback (most recent call last):<br />

...<br />

ValueError: Rational reconstruction <strong>of</strong> 4 (mod 11) does not exist.<br />

We throw in a denominator <strong>and</strong> reduce the matrix modulo 389 - it does rationally reconstruct.<br />

sage: B = (A/3 % 389).change_ring(ZZ)<br />

sage: B.rational_reconstruction(389) == A/3<br />

True<br />

TEST:<br />

Check that ticket #9345 is fixed:<br />

sage: A = r<strong>and</strong>om_matrix(ZZ, 3, 3)<br />

sage: A.rational_reconstruction(0)<br />

Traceback (most recent call last):<br />

332 Chapter 17. Dense matrices over the integer ring

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!