• Aucun résultat trouvé

Exercises for Chapter 1

N/A
N/A
Protected

Academic year: 2022

Partager "Exercises for Chapter 1"

Copied!
5
0
0

Texte intégral

(1)

Bordeaux 1 University MHT 933 - master 2

Mathematics 2009-2010

Exercises for Chapter 1

Exercise 1– [modular inversion]

1. Write an algorithm to compute nk modm (n, m, k integers, n, m > 0, k ≥0) with the square and multiply method (recursive or iterative version).

2. Letpbe a prime number. Using Fermat’s little theorem and the previous algorithm, write an algorithm of inversion mod p, i.e. which gives n−1 mod p if 0< n < p.

3. Compute the arithmetic complexity of this algorithm.

Exercise 2– [Fast Fibonacci]

We recall that the Fibonacci’s sequence is defined by

F0 = 0, F1 = 1, etFn+2 =Fn+1+Fn for every n≥0.

1. Design an algorithm which computes Fn inO(n) additions in Z≥0. 2. Give an estimation of the word complexity of this algorithm1. 3. Show that for everyk, n∈Z≥0, we have

Fn+k+1 =FnFk+Fn+1Fk+1.

4. Deduce from this an algorithm 2 which computes Fn in O(logn) opera- tions in Z≥0.

5. Give an estimation of the word complexity of this new algorithm.

Exercise 3– [Strassen]

Let A and B be two matrices n×n. We want to compute C = AB in an

1We recall that Fn = 1

5

Φn(−Φ)−n

where Φ = (1 +

5)/2 1.618 is the gold number.

2You can search for a procedure which computes (Fn, Fn+1) from (Fn/2, Fn/2+1) if n is even and (F(n−1)/2, F(n+1)/2) ifnis odd, procedure which will be used recursively.

(2)

economic way. We suppose first that n is a power of 2. We divide A, B and C in 4 matricesn/2×n/2.

A=

A1 A2 A3 A4

, B =

B1 B2 B3 B4

and C=

C1 C2 C3 C4

.

We put

















P1 = A1(B2−B4) P2 = (A1+A2)B4

P3 = (A3+A4)B1 P4 = A4(B3−B1)

P5 = (A1+A4)(B1+B4) P6 = (A2−A4)(B3+B4) P7 = (A1−A3)(B1+B2)

1. Write C2 in function of P1 and P2, C3 in function of P3 and P4, C1 in function of P4+P5 and P2−P6 and C4 in function of P1+P5 and P3+P7. 2. Compute the number of additions and of multiplications of matrices n/2×n/2 which are sufficient to obtain C with this approach.

3. Compute the total number of mutiplications that we are led to make with the algorithm defined by iteration of the process.

4. Find an induction formula forcn wherecn is the arithmetic complexity of the algorithm for matrices n×n (total number of operations).

5. Suppose now that n is not necessarily a power of 2. Generalize the previous algorithm to this general case and prove that the algorithm that is obtained has a complexity in

O

nlog 7/log 2 .

6. Compare with the complexity of the naive algorithm making use of the formulae

cij =

n

X

k=1

aikbkj.

Exercise 4– [Toom-Cook]

Here we study a generalization of Karatsuba’s algorithm. Karatsuba’s idea is to reduce the computation of the product of two polynomials of degree(s)

(3)

< 2N to the computation of 3 products of polynomials of degree(s) < N. But if instead of cutting in two, we cut in three and more generally in k parts, what can we obtain ?

Let us begin with cutting in three parts and suppose that we want to multiply two polynomials P and Q of degree(s) < n = 3N. Decompose them in the following way:

P = P2X2N +P1XN +P0 Q = Q2X2N +Q1XN +Q0

where thePi andQi are polynomials of degree(s)< N. Let Π be the product of P and Q and put









Π0 = P0Q0

Π1 = (P2+P1 +P0)(Q2+Q1+Q0) Π−1 = P2−P1+P0

Q2−Q1+Q0

Π2 = 4P2+ 2P1+P0

4Q2+ 2Q1+Q0 Π = P2Q2

1. Show that there exists 5 polynomials of degree(s) < 2N −1 denoted by Ri (0≤i≤4) such that













Π =

4

P

i=0

RiXiN Πα =

4

P

i=0

Riαi if α∈ {0,1,−1,2}

Π = R4

2. Write the Ri (0≤i≤4) as functions of the Πα (α ∈ {0,1,−1,2,∞}).

3. Deduce from above questions that the computation of Π can be reduced to the computation of 5 products of 2 polynomials of degree < N.

4. Compute the arithmetic complexity (in terms of number of multiplications as a function of n) of the algorithm obtained by using this method (suppose first that n is a power of 3) and compare with Karatsuba.

5. See in what the idea is the same as in Karatsuba (evaluation-interpolation) and generalize.

Exercise 5– [Mergesort]

We want to sort n numbers in increasing order using only comparisons. We denote by f(n) the number of comparisons required. The main idea is the

(4)

following one : first, sort the “first half”, then sort the “second half” and finally merge. Show that f(n) = O(nlogn).

Exercise 6– [p-adic inversion by Newton’s method]

Let p, l ∈ Z>0 and f, g0 ∈ Z such that f g0 ≡ 1 mod p. In particular f is inversible modulo p. We want to construct from g0 an element g ∈ Z such that f g ≡ 1 mod pl. We consider the sequence defined by the induction formula

gi+1 = 2gi−f g2i mod p2i+1.

1. Show that for everyiwe havef gi ≡1 mod p2iand that ifr=dlogl/log 2e, the number gr is an answer to our problem.

2. Analyze in detail the differents steps of the algorithm. Compute its arith- metic and its word complexities.

Exercise 7– [Fast Euclidean division by Newton’s method]

Let S, T ∈ A[X] where A is a commutative ring with unity 1, and where deg(S) = n, deg(T) =m,n ≥m and T is monic.

1. Show that the classical Euclidean division algorithm ofS byT has O(n2) arithmetic complexity.

2. If P ∈ A[X] and k ≥ deg(P), we put Reck(P(X)) = XkP(1/X). Show that

Recn−m(Q) =Recn(S).Recm(T)−1 modXn−m+1, where Q is the quotient in the Euclidean division of S byT.

3. Let F ∈ A[X] with F(0) = 1 and let l ≥ 1. Let define a sequence of polynomials Gi ∈A[X] by G0 = 1 and

Gi+1 = 2Gi −F.G2i mod X2i+1 for i≥0. Show that for every i≥0 we have

F.Gi ≡1 modX2i.

4. Deduce from previous questions an algorithm to compute Qand the rest R of the Euclidean division ofS byT.

5. Show that the arithmetic complexity of this new algorithm applied to Euclidean division of polynomials of degree < n is in O(M(n)) where M(n)

(5)

is the arithmetic complexity for the computation of the product of 2 polyno- mials with degree < n.

6. Show that we can compute the Euclidean division of 2 integers of length

< n with O(nlognlog logn) word complexity.

Exercise 8– [Around FFT]

Let n = 2k where k ∈ Z≥0. Let R be a commutative ring having as an element a primitive n-th root of unity ω, and in which 2 is invertible (we shall denote its inverse by 1/2). Let P and Q be two polynomials in R[X]

with degrees < n. We have seen an algorithm (FFT) which computes P ? Q = P Qmod (Xn−1) and thus P Q if degP + degQ < n, which uses the evaluation of P and Q at the ωi, 0 ≤ i ≤ n−1. Here we want to study a variant of this algorithm.

Algorithm 1. Fast Convolution

Require: P, Q ∈ R[X] with degrees < n = 2k and the powers ω, ω2, . . . , ωn/2−1 of a n-th primitive root of unity.

Ensure: P ? Q=P Qmod (Xn−1).

1: if k= 0 then

2: ReturnP Q

3: P0 ←P mod (Xn/2−1), P1 ←P mod (Xn/2+ 1), Q0 ←Qmod (Xn/2 −1), Q1 ←Qmod (Xn/2+ 1).

4: Call the algorithm recursivelyto computeR0, R1 ∈R[X] with degrees

< n/2 such that

R0 ≡P0Q0 mod (Xn/2−1), R1(ωX)≡P1(ωX)Q1(ωX) mod (Xn/2−1).

5: Return

1 2

(R0−R1)Xn/2+R0+R1 .

1. Show thatR0 ≡P Qmod (Xn/2−1) andR1 ≡P Qmod (Xn/2+ 1).

2. Deduce from this that the algorithm works correctly.

3. What is its algebraic complexity (number of operations inR)?

Références

Documents relatifs

[r]

Please attach a cover sheet with a declaration http://tcd-ie.libguides.com/plagiarism/declaration confirming that you know and understand College rules on plagiarism.. Please put

In this article, we developed a symbolic method to compute the distribution associated to the number of pattern occurrences in random texts generated by stochastic 0L-systems.. In

- Though the rotation lattice of binary trees is not a modular lattice^ we show that its Möbius fonction jx can be computed as f or distributive lattices.. - Bien que le treillis

The reason why conflict resolution by FOLLOW set does not work nearly as well as one might wish is that it replaces the look-ahead of single item of rule N in a given LR state

Other interesting fields related to AVT are automatic sign language translation and signing avatars (Wolfe et al. Still, very often this type of image-related research is

In this note, we establish such a connection between finite W -superalgebras and super Yangians of type A where the nilpotent element e is rectangular (cf. §3 for the

The numerical solution of the temperature for the radiative heat transfer model (4.2) at steady state, with a buffer inside the fluid zone (top) and a buffer partially outside the