prof_simplet
Inscrit le: 12 Sep 2006 Messages: 86
|
Posté le: 20 Mai 2008 13:33 Sujet du message: Partitions d'un ensemble fini |
|
|
Bonjour, voici une procédure récursive calculant les partitions d'un ensemble fini X:
Code: |
partition:=proc(X::set)
local f,j,k,n,L,M;
n:=nops(X);
if n=1 then RETURN({{X}}) else
L:=NULL;
f:=partition(X minus {X[1]});
for j to nops(f) do
M:=f[j];
L:=L,{{X[1]},op(M)};
for k to nops(M) do
L:=L,(M minus {M[k]}) union {{X[1]} union M[k]}
end do;
end do;
end if;
{L}
end proc:
partition({a});
{{{a}}}
partition({a,b});
{{{b}, {a}}, {{a, b}}}
partition({a,b,c});
{{{a, c}, {b}}, {{c}, {b}, {a}}, {{a, c, b}}, {{c, b}, {a}}, {{c}, {a, b}}}
|
Je pense que cela peut servir à certains.
@ plus |
|