  \begin{Mexin}
domain setSpace(N: Type::PosInt, Rng = Dom::ExpressionField() : DOM_DOMAIN)
    inherits Dom::FreeModule(Rng,
                             combinat::subClass(combinat::subsets,
                                                Parameters = {$1..N}));
    category Cat::FreeModule(Rng);
       
    dimension := dom::basisIndices::count();       

    EiBasis   := proc(st : dom::basisIndices, i : Type::PosInt)
    begin
        if i > N then error("Invalid index") end_if;
        dom::term((st union {i}) minus {i-1, i+1})
    end_proc;
    Ei := operators::makeLinear(dom::EiBasis, Source=dom, ImageSet=dom);
end_domain:
  \end{Mexin}

  \begin{Mexin}
N := 3
  \end{Mexin}
  \begin{Mexout}
                               3
  \end{Mexout}

  \begin{Mexin}
space := setSpace(N)
  \end{Mexin}
  \begin{Mexout}
              setSpace(3, Dom::ExpressionField())
  \end{Mexout}

  \begin{Mexin}
gen := space::genericElement(z -> c[op(z)])
  \end{Mexin}
  \begin{Mexout}
c[1, 2, 3] B({1, 2, 3}) + c[2, 3] B({2, 3}) +

   c[1, 3] B({1, 3}) + c[1, 2] B({1, 2}) + c[3] B({3}) +

   c[2] B({2}) + c[1] B({1}) + c[] B({})
  \end{Mexout}

  \begin{Mexin}
oper := z -> (1/N)*_plus(space::Ei(z, i) $ i = 1..N):
  \end{Mexin}

  \begin{Mexin}
linsolve({coeff(oper(gen) - gen)})
  \end{Mexin}
  \begin{Mexout}
--                 c[1, 3]                         c[1, 3]
|  c[] = 0, c[1] = -------, c[2] = c[1, 3], c[3] = -------,
--                    2                               2

                                            --
   c[1, 2] = 0, c[2, 3] = 0, c[1, 2, 3] = 0  |
                                            --
  \end{Mexout}

  \begin{Mexin}
statistique := proc(N)
  local space, gen, oper, i, res;
begin
  space := setSpace(N); 
  gen := space::genericElement(z -> c[op(z)]); 
  oper := z -> (1/N)*_plus(space::Ei(z, i) $ i = 1..N); 
  res := op(solve({coeff(oper(gen) - gen), c[1] = 1}))
end_proc
  \end{Mexin}
  \begin{Mexout}
                  proc statistique(N) ... end
  \end{Mexout}

  \begin{Mexin}
statistique(3)
  \end{Mexin}
  \begin{Mexout}
[c[] = 0, c[1] = 1, c[2] = 2, c[3] = 1, c[1, 2] = 0,

   c[1, 3] = 2, c[2, 3] = 0, c[1, 2, 3] = 0]
  \end{Mexout}

  \begin{Mexin}
_plus(op(map(statistique(3), op, 2)))
  \end{Mexin}
  \begin{Mexout}
                               6
  \end{Mexout}
  \begin{Mexin}
_plus(op(map(statistique(4), op, 2)))
  \end{Mexin}
  \begin{Mexout}
                              24
  \end{Mexout}

  \begin{Mexin}
_plus(op(map(statistique(5), op, 2)))
  \end{Mexin}
  \begin{Mexout}
                              120
  \end{Mexout}

  \begin{Mexin}
_plus(op(map(statistique(6), op, 2)))
  \end{Mexin}
  \begin{Mexout}
                              720
  \end{Mexout}

  
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
