Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Math 480: Open Source Mathematical Software
2016-05-06
William Stein
Lectures 18: Linear algebra (part 3 of 3)
Today:
Reminder: homework and peer grading is due at 6pm tonight.
Start screencast (crossing fingers that projector works this time... if not, maybe I'll switch to this windows machine in front of me)
(20 minutes) How multimodular echelon form works
(5 minutes) Sync stress test
Multimodular echelon form
I told you before about one way Sage computes the determinant of a large integer (or rational) matrix by solving for a random , and considering the denominator of . Cramer's rule, turned on its head, is a powerful approach to computing determinants.
Here's another central idea in exact linear algebra: multimodular echelon form.
Imagine with me what it would be like to do Gaussian elimination to put the following matrix $$ into reduced row Echelon form:
Then clear the second column:
And it gets bad...
There is a better way, which seems way more complicated but:
avoids "coefficient explosion"
enables many other nice optimizations: parallelization, working mod p, asymptotically fast matrix multiplication, etc.
The basic idea:
Choose some random prime .
Reduce our matrix modulo a prime number to get .
Compute the reduced row echelon form of .
(*) Lift the result back to the rational numbers to get the right answer.
This is potentially better, since the numbers all stay small, instead of getting massive/painful.
Notice -- the numbers aren't exploding. (Please imagine doing all this with a 200x201 matrix, say!)
But... how do you get from B.rref() to A.rref()???
Obviously, there isn't enough information: but 236 mod 389 doesn't tell you ...
There is an algorithm called rational reconstruction, which is based on Euclidean GCD:
Still doesn't work. But if we replace 389 by a bigger prime, it works:
Multimodular!
But this sucks -- if the matrix is large, the entries are large, and we have to work modulo an enormous prime with thousands of digits. NO.
Instead, work modulo several small primes (possibly at once, in parallel). Small primes are easier and faster -- they fit in an int or long.
Use the Chinese Remainder Theorem to combine the rref modulo a bunch of small primes to get a matrix with entries modulo .
Use rational reconstruction on that (it works modulo for any integer ).
And... realize that echelon modulo can be done via several matrix multiplications! (Permute the matrix and work with blocks...)
And... that matrix multiplication is way faster that ... https://en.wikipedia.org/wiki/Strassen_algorithm
Sync stress test
Everybody do something here and see what happens (tmp/2016-05-06-stress.sagews
in the shared project):