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 />

•stabilize - if pro<strong>of</strong> is False, require det to be the same for this many CRT primes in a row. Ignored<br />

if pro<strong>of</strong> is True.<br />

ALGORITHM: The p-adic algorithm works by first finding a r<strong>and</strong>om vector v, then solving A*x = v <strong>and</strong><br />

taking the denominator d. This gives a divisor <strong>of</strong> the determinant. Then we compute det(A)/d using a<br />

multimodular algorithm <strong>and</strong> the Hadamard bound, skipping primes that divide d.<br />

TIMINGS: This is perhaps the fastest implementation <strong>of</strong> determinants in the world. E.g., for a 500x500<br />

r<strong>and</strong>om matrix with 32-bit entries on a core2 duo 2.6Ghz running OS X, <strong>Sage</strong> takes 4.12 seconds, whereas<br />

Magma takes 62.87 seconds (both with pro<strong>of</strong> False). With pro<strong>of</strong>=True on the same problem <strong>Sage</strong> takes<br />

5.73 seconds. For another example, a 200x200 r<strong>and</strong>om matrix with 1-digit entries takes 4.18 seconds in<br />

pari, 0.18 in <strong>Sage</strong> with pro<strong>of</strong> True, 0.11 in <strong>Sage</strong> with pro<strong>of</strong> False, <strong>and</strong> 0.21 seconds in Magma with pro<strong>of</strong><br />

True <strong>and</strong> 0.18 in Magma with pro<strong>of</strong> False.<br />

EXAMPLES:<br />

sage: A = matrix(ZZ,8,8,[3..66])<br />

sage: A.determinant()<br />

0<br />

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

sage: D1 = A.determinant()<br />

sage: A._clear_cache()<br />

sage: D2 = A.determinant(algorithm=’ntl’)<br />

sage: D1 == D2<br />

True<br />

We have a special-case algorithm for 4 x 4 determinants:<br />

sage: A = matrix(ZZ,4,[1,2,3,4,4,3,2,1,0,5,0,1,9,1,2,3])<br />

sage: A.determinant()<br />

270<br />

Next we try the Linbox det. Note that we must have pro<strong>of</strong>=False.<br />

sage: A = matrix(ZZ,5,[1,2,3,4,5,4,6,3,2,1,7,9,7,5,2,1,4,6,7,8,3,2,4,6,7])<br />

sage: A.determinant(algorithm=’linbox’)<br />

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

...<br />

RuntimeError: you must pass the pro<strong>of</strong>=False option to the determinant comm<strong>and</strong> to use LinBox’<br />

sage: A.determinant(algorithm=’linbox’,pro<strong>of</strong>=False)<br />

-21<br />

sage: A._clear_cache()<br />

sage: A.determinant()<br />

-21<br />

A bigger example:<br />

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

sage: d = A.determinant()<br />

sage: A._clear_cache()<br />

sage: A.determinant(algorithm=’linbox’,pro<strong>of</strong>=False) == d<br />

True<br />

TESTS:<br />

This shows that we can compute determinants for all sizes up to 80. The check that the determinant <strong>of</strong> a<br />

squared matrix is a square is a sanity check that the result is probably correct:<br />

sage: for s in [1..80]: # long time (6s on sage.math, 2013)<br />

... M = r<strong>and</strong>om_matrix(ZZ, s)<br />

320 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!