> |
Exercice 4
Question a
> | partition:=proc(n,k) options remember;
local gauche,droite,parti,i; if n=1 then if k<>1 then parti:={} else parti:={[1]}; fi: else Dans le cas général on va construtire les partitions, à partir de celles obtenues sur les n-1 dernièrs élements, en choissisant celle qui contiendra le premièr élément (notons le 0) gauche:=partition(n-1,k-1); gauche contient les (k-1)-partitions de l'ensemble E privé de 0 (notons E' cet ensemble) parti:=map2(colle,k,gauche); rajoute à gauche une k-ième partie qui est le singleton: 0 droite:=partition(n-1,k); droite contient les k-partitions de l'ensemble E' for i from 1 to k do on distribue sur chaque partie (numérotée i allant de 1 à k) , l'ément 0 gauche:=map2(colle,i,droite); gauche modifie les k-partitions de droite on ajoutant à chacune l'élément i parti:={op(gauche),op(parti)}; on fusionne les k-partitions de E jusqu'ici obtenues dans parti od; fi; parti; end: |
> | partition(4,3); |
> |
> | Question b |
> | p_classes:=proc(E,k)
local i,j,p,n,Np,sol; n:=nops(E); p:=partition(n,k); Np:=nops(p); sol:=array(1..Np,1..k); for i from 1 to Np do for j from 1 to k do sol[i,j]:=ens3(E,p[i],j); sol est un tableau dont chaque ligne contient une des k k-partitions de E od; od; evalm(sol); end: |
> |
> | p_classes([a,b,c,d,e,f],3); |
> |
> | Question c |
> | Stirling:=proc(n,k) options remember;
local s; if n<1 then s:=0; else if n=1 then if k<>1 then s:=0 else s:=1 fi; else s:=Stirling(n-1,k-1)+k*Stirling(n-1,k); fi; fi; s; end: |
> |
> | Stirling(17,5); |
> |
> | Triangle_Stirling:=proc(m)
local i,j,T; T:=array(1..m+1,1..m+1); for i from 0 to m do for j from 0 to m do if i=0 or j=0 then T[i+1,j+1]:=0 elif i=1 and j<>1 then T[i+1,j+1]:=0; elif i=1 and j=1 then T[2,2]:=1; else T[i+1,j+1]:=T[i,j]+j*T[i,j+1]; fi; od;od; for i from 0 to m do T[1,i+1]:='k'=i;T[i+1,1]:='n'=i; od;T[1,1]:='k/n'; evalm(T); end: |
> |
> |
> | T:=Triangle_Stirling(8); |
> |