Exercice 1 - manipulations de base

 > Max:=proc(x,y) if x

 > Max(6,7);

 > Max(-1,2);

 > Max(-1.5,-1.6);

 > Max3:=proc(x,y,z) return Max(x,Max(y,z)); end proc;

 > Max3(1,2,3);

 > Max3(2,1,3);

 > Max3(3,2,1);

 > Min:=proc(x,y) if x=Max(x,y) then return y; else return x; end if; end proc;

 > Min(3,4);

 > Max(3,4);

 >

Exercice 2 - quelques boucles

 > TermeSuite:=proc(n::nonnegint) local a,b,c,i; if n=0 or n=1 then return 1; end if; a:=1; b:=1; for i from 2 to n do c := 3*a - b + 1; b := a; a := c; end do; end proc;

 > TermeSuite(1);

 > TermeSuite(3);

 > TermeSuite(4);

 > Fibo:=proc(n::nonnegint) local a,b,i; if n=0 then return 0;   elif n=1 then return 1; end if; a:=1; b:=0; for i from 2 to n do a := a + b; b := a - b; end do; return a; end proc;

 > Fibo(2);

 > Fibo(3);

 > Fibo(4);

 > Fibo(5);

 > Fibo:=proc(p::nonnegint, n::nonnegint) local a,b,i; if p=0 or n=p then return 1;   elif p=1 then return n; end if; return Fibo(p-1,n-1)+Fibo(p,n-1); end proc;

 > Fibo(1,5);

 > Fibo(3,5);

 > Fibo(12,22);

 > b:=Array(1..9,1..25);

 >

 > Fibo2:=proc(p::nonnegint, n::nonnegint) local a,i; global b; if p=0 or n=p then b[p,n]:=1; return 1; end if; if b[p,n]<>0 then return b[p,n]; end if; if p=1 then b[p,n]:=n;return n; end if; b[p-1,n-1]:=Fibo(p-1,n-1); b[p,n-1]:=Fibo(p,n-1); b[p,n]:= b[p-1,n-1]+b[p,n-1]; return b[p,n]; end proc;

 > Fibo2(9,24);

 > time(Fibo2(9,24));time(Fibo(9,24));

 > b;

Exercice 3 - Décomposition binaire

 > Puissance:=proc(x) local n,q; if (x <= 0) then printf("Valeur positive, svp..."); else n:=0; q:=1; while (x >= 2**n) do n:= n+1; end do; return n-1, 2**(n-1); end if; end proc;

 > Puissance(0);

Valeur positive, svp...

 > Puissance(1);

 > Puissance(4);

 > Puissance(9);

 > Puissance(35.5);

 > decomp:=proc(x) local i,t,r,b; t:=x; i:=0; while t>=1 do r := irem(t,2,'t'); b[i] := r; i:=i+1; end do; i:=i-1; while i >= 0 do printf("%d",b[i]); i:=i-1; end do; end proc;

 > decomp(2);

10

 > decomp(7);

111

 > decomp(13);

1101

 >