Exercice 1: la méthode de Pollard pour factoriser un entier de grande taille

 > Pollard:=proc(B,a,n) local d,Q,l,q; d:=gcd(a,n); if d>= 2 then return d; fi; Q:=3; for q from 2 to B do if isprime(q) then l:=floor(ln(n)/ln(q)); Q:=power(Q,q**l) mod n; fi; od; d:=gcd(Q-1,n); return d; end;

 > isprime(2);

 > debug(Pollard);Pollard(19,3,19048567);

{--> enter , Pollard, , args = , 19, , , 3, , , 19048567

<-- exit , Pollard,  (now at top level, ) = , 5281, }

 > 19048567/5281;

 > Pollard(31,3,19048564);

{--> enter , Pollard, , args = , 31, , , 3, , , 19048564

<-- exit , Pollard,  (now at top level, ) = , 72428, }

Exercice 2 : Interpolation pour le calcul de zéros d'une fonction

 > f:=x->2*cos(x)-3*x;diff(f(x),x);X:=[0.1,0.3,0.5,0.7,0.9];Y:=map(f,X);

 > P:=simplify(collect(interp(Y,X,t),t));

 > simplify(eval(P, t=0));

 > map(f,%);

 > plot(f);

Exercice 3 : calcul de puissance de matrice

 > with(linalg);A:=matrix(5,5,1): for i to 5 do A[i,i]:=3 od: evalm(A);

Warning, the protected names norm and trace have been redefined and unprotected

 > latex(matrix([[2, 1, 1, 1, 1], [1, 2, 1, 1, 1], [1, 1, 2, 1, 1], [1, 1, 1, 2, 1], [1, 1, 1, 1, 2]]));

\left[ \begin {array}{ccccc} 2&1&1&1&1\\\noalign{\medskip}1&2&1&1&1
\\\noalign{\medskip}1&1&2&1&1\\\noalign{\medskip}1&1&1&2&1

\\\noalign{\medskip}1&1&1&1&2\end {array} \right]

 > for i from 2 to 4 do evalm(A^i) od;

 > I5:=diag(1,1,1,1,1);

 > An:=evalm(matrix(5,5,(i,j)->an-2**n)+2**n*I5);

 > evalm(An&*A);

 > calculA:=proc(n) local t; if n=1 then return 3 else return  7*calculA(n-1)-2**(n+1); fi; end;

 >

 > calculA(3);calculA(4);calculA(5);

 > MonExo:=proc(A,n) local I5,An,an; I5:=diag(1,1,1,1,1); if n=1 then return eval(A); fi; an:=calculA(n); An:=evalm(matrix(5,5,(i,j)->an-2**n)+2**n*I5); return eval(An); end;

 > MonExo(A,3);MonExo(A,5);

 >