Multiplications Rapides
3 d´ ecembre 2012
R´esum´e
Il s’agit d’implanter les algorithmes du cours concernant la multipli- cation des polynˆomes `a coeffficients complexes.
1 Complexe
Le typecomplexa fait son apparition dans C99, il est maintenant disponible sousgcc. Le programme (1) est une nouvelle fa¸con d’imprimer z´ero. Expliquer pourquoi !
COMPLEX( 7 ) Linux Programmer ’ s Manual
NAME
complex − b a s i c s o f complex m a t h e m a ti c s SYNOPSIS
#i n c l u d e <complex . h>
DESCRIPTION
Complex numbers a r e numbers o f t h e form z = a+b∗i , where a and b a r e r e a l numbers and i = s q r t (−1) , s o t h a t i∗i = −1.
There a r e o t h e r ways t o r e p r e s e n t t h a t number . The p a i r ( a , b ) o f r e a l numbers may be v i e w e d a s a p o i n t i n t h e p l a n e , g i v e n by X and Y−c o o r d i n a t e s . T h i s same p o i n t may a l s o be d e s c r i b e d by g i v i n g t h e p a i r o f r e a l numbers ( r , p h i ) , where r i s t h e
d i s t a n c e t o t h e o r i g i n O, and p h i t h e a n g l e between t h e X−a x i s and t h e l i n e Oz . Now z=r∗exp ( i∗p h i )= r∗( c o s ( p h i )+ i∗s i n ( p h i ) ) . The b a s i c . . .
SEE ALSO
cabs , c a r g , cexp , cpow , c r e a l , c s q r t , cimg
2 Karatsuba
On repr´esente les polynˆomes par des pointeurs sur des complex:
typedef double complex s c a l a r ; typedef s c a l a r ∗ p o l y ;
1
#include <complex . h>
#include <math . h>
#include <s t d l i b . h>
#include <s t d i o . h>
i n t main ( i n t a r g c , char ∗a r g v [ ] ) {
double complex x , z e t a , s ; i n t i , n = a t o i ( a r g v [ 1 ] ) ;
z e t a = cexp ( 2 ∗ I ∗ M PI / n ) ; s = 0 ;
x = 1 ;
f o r( i = 0 ; i < n ; i ++){
s = s + x ; x = x ∗ z e t a ; }
p r i n t f ( ”%f + %f ∗ i\n” , c r e a l ( s ) , cimag ( s ) ) ; return 0 ;
}
Fig.1 – Le type complexe en C
1. implantez l’algorithme de multiplication de Anatolii Alexevich Karatsuba pour ´ecrire une fonction poly kara( a, b, n)qui calcule le produit de deux polynˆomes de taillen.
2. Assurez vous du bon fonctionnement de votre multiplication au moyen d’un test efficace.
3. Pr´ecisez le temps de calcul en fonction den.
3 Fourier
1. ImplanterFourier( p, n )qui calcule la transform´ee de Fourier depsur place.
2. Implanter l’inversion de Fourier.
3. V´erifier la correction.
4. Pr´eciser le temps de calcul.
4 Multiplication
1. Implantertfrmul( r, p, n)qui calculer:=rp (mod Xn−1) le pro- duit de 2 polynomes moduloXn−1.
2. Prouver le bon fonctionnement de votre multiplication.
3. Pr´eciser le temps de calcul en fonction de n.
2
5 FFT
Reprendre les questions de la section pr´ec´edente avec la transformation de Fourier Rapide.
3