Vous êtes sur la page 1sur 2

CS 487: Intro.

to Symbolic Computation Winter 2014: George Labahn Assignment 1 Page 1


CS 487: Assignment #1 Due: January 27, 2014 at 5:00pm
1. (The Binary Euclidean Algorithm).
Consider the following algorithm for the GCD of two integers.
Algorithm:
Input: a, b N; a, b > 0;
Output: gcd(a, b) N
0. if a < b then return gcd(b, a);
1. if a = b then return a;
2. if both a and b are even return 2gcd(a/2, b/2)
3. if exactly one of the two numbers, say a, is even, then return gcd(a/2, b)
4. if both a and b are odd then return gcd((ab)/2, b)
(a) Implement the above algorithm in Maple and demonstrate it on the pairs (54, 21),
(136, 51), (481, 325), (8771, 3206).
(b) Prove the algorithm works correctly. Use induction (you gure out on what to base the
induction).
(c) Find a good upper bound on the recursion depth of the algorithm, and show that it
takes O(
2
) bit operations on inputs of size (i.e., inputs with bits).
(d) Modify the algorithms so that it additionally computes s, t N such that sa +tb =
gcd(a, b).
(e) Develop a trinary variant which bases the recursion on a mod 3 and b mod 3. Imple-
ment it in Maple and provide a proof that it works.
2. (Continued fractions) Let K be a eld, and f
1
, . . . , f

K. Then
f
1
+
1
f
2
+
1

f
1
+
1
f

is a continued fraction, denoted by C( f


1
, . . . , f

). Now assume R is a Euclidean Domain and


K its eld of fractions. For (a
0
, a
1
) R
2
, let a
i
, q
i
R, for 1 i , be the entries in the
extended Euclidean scheme for (a
0
, a
1
).
(a) Show that
a
0
a
1
=C(q
1
, . . . , q

).
CS 487: Intro. to Symbolic Computation Winter 2014: George Labahn Assignment 1 Page 2
Dene polynomials c

K[x
1
, . . . , x

] for N, inductively by
c

1 if = 0,
x
1
if = 1,
x
1
c
1
(x
2
, . . . , x

) +c
2
(x
3
, . . . , x

) if 2.
(b) Prove by induction that for 1
C( f
1
, . . . , f

) =
c

( f
1
, . . . , f

)
c
1
( f
2
, . . . , f

)
.
(c) Write a Maple program that computes the EES and all continuants c
i
(q
i+1
, . . . , q

).
Test your algorithm thoroughly and run it on a
0
= x
40
and a
1
= x
38
+2x
36
+x
2
in Q[x].
(d) What is the relation between the continuants and the entries of the EES?
3. Let R be a ring (commutative, with 1) and f , g R[x, y] (i.e., polynomials in the two variables
x and y). Assume that f and g have degrees less than m in y and n in x. Let h = f g (the
product of f and g).
(i) Using classical univariate polynomial multiplication, and viewing R[x, y] as R[y][x] (i.e.,
polynomials in x with coefcients in R[y]), bound the number of operations in R to
compute h.
(ii) Using Karatsubas algorithm, bound the number of operations in R to compute h.
(iii) Generalize parts (i) and (ii) to polynomials in an arbitrary number of variables.
4. In linear algebra it is often useful to evaluate a polynomial at a matrix. Let F be a eld and
f =
0in
a
i
x
i
F[x] have degree n. Let A F
mm
be an mm matrix over F. We dene
f (A) =

0in
a
i
A
i
F
mm
(i) Given two matrices A, B F
mm
, how many operations in F does it take to compute the
matrix product C = AB F
mm
, using the standard school method.
(ii) Given a polynomial f F[x] of degree n, and A F
mm
, describe the obvious algorithm
for evaluating f (A). Analyse the cost of this algorithm in terms of operations in F,
depending on m and n.
(iii) Design an asymptotically faster algorithm for evaluating f (A). Try binary powering,
Karatsubas method or a combination of the two.
(iv) Write two Maple procedures, one using the nave algorithm and one using for your new
algorithm, to evaluate a polynomial at a matrix, where all coefcients of the polynomial
and entries of the matrix are in Z
p
. The arguments to your procedures should be the
polynomial f Z
p
[x], the matrix A Z
mm
p
, and the prime p. Compare the timings
of the algorithms on a few examples to show the practical benet of the asymptotic
speedup you obtained.

Vous aimerez peut-être aussi