Assignment 3
Integer Multiplication, Primality Testing, Interpolation
CS 300 Applied Symbolic Computation
Instructor: Jeremy Johnson
Due Tuesday May 20 by class time.
Problems to hand in
- [20 points] Count the number of multiplications used by the binary
powering algorithm, Powerrec (see below), presented in Lecture 5. Plot
the number of multiplications for exponent 0..128. Can you determine
a formula for the number of multiplications?
- > Powerrec := proc(M,e) if e = 0 then return 1; fi;
> if e = 1 then return M; fi;
> return Powerrec(M,floor(e/2))^2*M^(e mod 2);
> end;
- [30 points]
- Using Maple, implement and experiment with the primality test described
in the RSA paper. I.E. For an integer n, generate random integers
between 1 and n-1 and check to see if (i) gcd(a,n) = 1, and if (ii)
J(a,n) = a^((n-1)/2) mod n, where J(a,n) is the Jacobi symbol of a
and n. If n is prime these two conditions will always be true. If
n is composite, the condition will be false with atleast probability
1/2. Your procedure should allow the number of trials to be passed
as a parameter. You may use Maple's jacobi function in the numtheory
package. You may also want to use ifactor, and isprime for testing
purposes.
- Implement a Maple procedure to compute compute the Jacobi symbol
(as indicated on page 124 of the RSA paper. A discussion of the Jacobi
symbol is provided in chapter 3 of the Niven and Zuckerman handout.
- [30 points]
- Implement a Maple procedure that uses Karatsuba's algorithm to multiply
integers. Time your version of Karatsuba's algorithm for a range of
input sizes (i.e. number of digits) and empirically determine the asymptotic
computing time rate.
- Reimplement Karatsuba's algorithm using the internal representation
of integers. You must perform the extraction of the high and low order
digits and multiplication by powers of ten in linear time. You can get
the internal representation of a maple integer using the disassemble
instruction. Similarly you can reassemble an integer in the internal format
using Maple's assemble instruction. See internal.mws for an example of how
to use these functions. You should also refer to the online documentation.
- [20 points] Implement a Maple procedure that multiplies two polynomials
with coefficients in Z_p using the evaluation, pointwise product, interpolation
algorithm.