Docsity

Homework 3 with Solution | Computer Algebra | MA 522, Assignments of Mathematics

Toggle sidebar
bg1
Homework 3
MA 522 Fall 2008
1. (20 points) Write a pseudo-code for the division with remainder algorithm over Z
Solution: DIVISION-WITH-REMAINDER
INPUT:a=Pn
i=0 ai264i, and b=Pm
i=0 bi264i
OUTPUT:q, r ∈Zsuch that a=qb +r,0≤r < b.
1r←a
2for i=n−m, n −m−1, . . . 0do
3if rm+i6= 0 then
4qi←quo(rm+i, bm) %Use single precision division with remainder
5if qi= 0 then qi←quo(rm+i264 +rm+i−1, bm)
6while r−qi264ib < 0do
7qi←qi−1
8r←r−qi264ib
9else qi←0
10 return q=Pn−m
i=0 qi264iand r.
2. Textbook, page 40/ 2.10 (i) and (iii)
Let Rbe a ring (commutative, with 1) and a=Pn
i=0 aixi∈R[x]of degree n, all ai∈R. The
weight w(a)of ais the number of nonzero coefficients of abesides the leading coefficient:
w(a) := #{0≤i<n :ai6= 0}.
Thus w(a)≤deg(a), with equality if and only if all coefficients of aare nonzero. The
sparse representation of ais a list (i, ai)i∈I, with each ai∈Rand a=Pi∈Iaixi. Then we
can choose #I=w(a)+1.
(i) Show that two polynomials a, b ∈R[x]of weight w(a) = nand w(b) = mcan be
multiplied in the sparse representation using at most 2nm +n+m+ 1 arithmetic opera-
tions in R.
Proof: The polynomial multiplication algorithm (ALGORITHM 2.3) requires (n+1)(m+ 1)
multiplications in Rand the resulting (n+1)(m+ 1) products are summed up in n+m+1.
Since the summing of sitems costs s−1additions, the total number of additions in Ris
(n+1)(m+1)−(n+m+1) = nm. Thus we have at most (n+1)(m+1)+nm = 2nm+n+m+1
operations in R.
(iii) Let n≥m. Show that quotient and remainder on division of a polynomial a∈R[x]
of degree less than nby b∈R[x]of degree m, with lc(b)a unit, can be computed using
n−mdivisions in Rans w(b)·(n−m)multiplications and subtractions in Reach.
Proof: The polynomial division algorithm (ALGORITHM 2.5) requires n−mdivisions in
R, and n−mconstant multiplication and abstraction of the polynomial b. Since the lead-
ing term is always 0after the subtraction of the constant multiple of b, we do not need to
1
pf2

Partial preview of the text

Download Homework 3 with Solution | Computer Algebra | MA 522 and more Assignments Mathematics in PDF only on Docsity!

Homework 3

MA 522 Fall 2008

  1. (20 points) Write a pseudo-code for the division with remainder algorithm over Z

Solution: DIVISION-WITH-REMAINDER INPUT: a =

∑n i=0 ai^2

64 i, and b = ∑m i=0 bi^2

64 i

OUTPUT: q, r ∈ Z such that a = qb + r, 0 ≤ r < b. 1 r ← a 2 for i = n − m, n − m − 1 ,... 0 do 3 if rm+i 6 = 0 then 4 qi ← quo(rm+i, bm) %Use single precision division with remainder 5 if qi = 0 then qi ← quo(rm+i 264 + rm+i− 1 , bm) 6 while r − qi 264 ib < 0 do 7 qi ← qi − 1 8 r ← r − qi 264 ib 9 else qi ← 0 10 return q =

∑n−m i=0 qi^2

64 i (^) and r.

  1. Textbook, page 40/ 2.10 (i) and (iii) Let R be a ring (commutative, with 1) and a =

∑n i=0 aix i (^) ∈ R[x] of degree n, all ai ∈ R. The

weight w(a) of a is the number of nonzero coefficients of a besides the leading coefficient:

w(a) := #{ 0 ≤ i < n : ai 6 = 0}.

Thus w(a) ≤ deg(a), with equality if and only if all coefficients of a are nonzero. The sparse representation of a is a list (i, ai)i∈I , with each ai ∈ R and a =

i∈I aix

i. Then we

can choose #I = w(a) + 1.

(i) Show that two polynomials a, b ∈ R[x] of weight w(a) = n and w(b) = m can be multiplied in the sparse representation using at most 2 nm + n + m + 1 arithmetic opera- tions in R. Proof: The polynomial multiplication algorithm (ALGORITHM 2.3) requires (n + 1)(m + 1) multiplications in R and the resulting (n+1)(m+1) products are summed up in n+m+1. Since the summing of s items costs s − 1 additions, the total number of additions in R is (n+1)(m+1)−(n+m+1) = nm. Thus we have at most (n+1)(m+1)+nm = 2nm+n+m+ operations in R.

(iii) Let n ≥ m. Show that quotient and remainder on division of a polynomial a ∈ R[x] of degree less than n by b ∈ R[x] of degree m, with lc(b) a unit, can be computed using n − m divisions in R ans w(b) · (n − m) multiplications and subtractions in R each. Proof: The polynomial division algorithm (ALGORITHM 2.5) requires n − m divisions in R, and n − m constant multiplication and abstraction of the polynomial b. Since the lead- ing term is always 0 after the subtraction of the constant multiple of b, we do not need to

compute that term. Therefore each of these polynomial subtractions and multiplications only need w(b) operations over R, even though b has w(b) + 1 terms. Therefore the algo- rithm uses w(b)(n − m) subtractions and multiplications over R.

  1. See separate MAPLE sheet for solutions
  2. Textbook, page 60/ 3.25 (ii) Proof of correctness: Let a, b ∈ N such that a ≥ b > 0. We will consider the following four cases, corresponding to each line of the algorithm
    1. If a = b then gcd(a, b) = a.
    2. If both a and b are even then 2 divides the gcd and clearly gcd(a, b) = 2 gcd(a/ 2 , b/2).
    3. Assume that exactly one among a and b are even, say a. Then 2 does not divide the gcd and clearly gcd(a, b) = gcd(a/ 2 , b).
    4. Assume that neither a nor b are even. Let d := gcd(a, b) and d′^ = gcd((a − b)/ 2 , b). Since d divides a and b, it also divides a − b. But since d is odd and a − b is even, d must divide (a − b)/ 2. This implies that d divides d′. On the other hand, d′^ divides b and (a − b)/ 2 , thus it also divides a − b. This implies that d′^ divides both a and b, so it also divides their gcd d. Thus d and d′^ must be equal.

Since this four cases cover all possibilities, the algorithm returns the correct answer.

(iii) An upper bound for the depth of the recursion depth is

dlog 2 (ab)e = dlog 2 (a) + log 2 (b)e.

Assume that a and b has binary length n and m, respectively. Then running time satisfies the following recursion equation:

T (n + m) = max(T (n + m − 2), T (n + m − 1)) + n + m− = T (n + m − 1) + n + m.

The solution for this equation is

n∑+m

i=

i =

(n + m)(n + m + 1) 2

∈ O(n^2 ).