In particular, if we let A be the 2x2 matrix
then F(n) is the second component of An-1.[0 1]T where
[0 1]T is just a column vector with first row 0 and second row 1
and An-1 is n-1 copies of matrix A multiplied together.
Use this fact with divide and conquer to design an algorithm that uses
only O(log n) multiplications and additions of integers to compute F(n).
Programming plus write-up portion
You may work on this portion in groups of two or three. The write-up
should have the names of everyone working together on it. Each person can be
the member of only one group. It should be handed
in separately from the previous portion.
In describing and analyzing Strassen's algorithm we assumed that we
used divide and conquer all the way down to tiny matrices. However,
on small matrices the ordinary matrix multiplication algorithm will be faster
because of lower overhead.
This is a common issue with divide and conquer algorithms.
The best way to run these algorithms is to test the input size n
at the start to see if it is big enough to make using divide and conquer
worthwhile; if n is larger than some threshold then the algorithm would
do a level of recursion, if n is below that threshold then it
would do the non-recursive algorithm.
Your job is to figure out the best choice for that threshold value for a
version of Strassen's algorithm based on your implementation.
(See the class slides for the description of the recursion used in
Strassen's algorithm and for the code for the basic non-recursive algorithm
for matrix multiplication.)
Steps:
-
First, write a program that implements the ordinary n3
algorithm for matrix multiplication over the integers (see the slides).
-
Next, write a recursive program that the implements a pure version of
Strassen's algorithm for matrix multiplication over the integers
(see the slides).
To keep the recursion simple you can assume that the input matrices are
nxn matrices where n that is a perfect power of 2.
-
Now modify your recursive program so that it uses an
extra number s and tests the input size n of the matrices first.
If n is at most s then it skips out of the recursion and
calls the simple version from part a above.
-
Your job now is to figure out which value of s is best to use with
your algorithm. To do so, you will need to figure out how long your
code takes to work and you will need sample inputs of various sizes.
Code for generating test matrices is available here.
For information about
how to time your code see Timing Instructions.
Try out various values of s, which you can also assume is a power of 2
since we are only working with sizes n that are powers of 2.
Your write-up should include
- your code
- the timings that you found
- and the choice of s you found works best
The Math Sciences Computing Center is available for your programming project.
(Bonus) Generalize your code so that it works with matrices of any dimension,
not just powers of 2. Figure out the best value of s to use in this
case.