assignment 1

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 2 gcd(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((a - b)/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 figure 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 field, 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 field 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 ).

Upload: karthikvs88

Post on 20-Jul-2016

213 views

Category:

Documents


0 download

DESCRIPTION

introduction to Symbolic computation

TRANSCRIPT

Page 1: Assignment 1

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) ∈ N0. 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((a−b)/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 figure out on what to base theinduction).

(c) Find a “good” upper bound on the recursion depth of the algorithm, and show that ittakes 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 field, and f1, . . . , f` ∈ K. Then

f1 +1

f2 +1

· · ·f`−1 +

1f`

is a continued fraction, denoted by C( f1, . . . , f`). Now assume R is a Euclidean Domain andK its field of fractions. For (a0,a1) ∈ R2, let ai,qi ∈ R, for 1 ≤ i ≤ `, be the entries in theextended Euclidean scheme for (a0,a1).

(a) Show thata0

a1=C(q1, . . . ,q`).

Page 2: Assignment 1

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

Define polynomials c` ∈ K[x1, . . . ,x`] for ` ∈ N, inductively by

c` =

1 if `= 0,x1 if `= 1,x1c`−1(x2, . . . ,x`)+ c`−2(x3, . . . ,x`) if `≥ 2.

(b) Prove by induction that for `≥ 1

C( f1, . . . , f`) =c`( f1, . . . , f`)

c`−1( f2, . . . , f`).

(c) Write a Maple program that computes the EES and all continuants ci(q`−i+1, . . . ,q`).Test your algorithm thoroughly and run it on a0 = x40 and a1 = x38+2x36+x2 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 variablesx and y). Assume that f and g have degrees less than m in y and n in x. Let h = f · g (theproduct 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 coefficients in R[y]), bound the number of operations in R tocompute h.

(ii) Using Karatsuba’s 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 field andf = ∑0≤i≤n aixi ∈ F[x] have degree n. Let A ∈ Fm×m be an m×m matrix over F. We define

f (A) = ∑0≤i≤n

aiAi ∈ Fm×m

(i) Given two matrices A,B ∈ Fm×m, how many operations in F does it take to compute thematrix product C = AB ∈ Fm×m, using the standard “school” method.

(ii) Given a polynomial f ∈ F[x] of degree n, and A∈ Fm×m, describe the obvious algorithmfor 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,Karatsuba’s method or a combination of the two.

(iv) Write two Maple procedures, one using the naı̈ve algorithm and one using for your newalgorithm, to evaluate a polynomial at a matrix, where all coefficients of the polynomialand entries of the matrix are in Zp. The arguments to your procedures should be thepolynomial f ∈ Zp[x], the matrix A ∈ Zm×m

p , and the prime p. Compare the timingsof the algorithms on a few examples to show the practical benefit of the asymptoticspeedup you obtained.