switch := proc(n, x, maxsub)
    local vs, i, j, k, pg, bk, nsw, pe, bki, pn, allpoly,
          mon, nlist, dg, vres, colist, pnum, part, pgel,
          jnum, vt, pct, multiplicity, m;
    vs := linalg[vector](n, 0);
    vt := linalg[vector](n, 0);
    nsw := 2^n;
    multiplicity := proc(y, j)
        j[y] := j[y] + 1;
    end:
    allpoly := 0;
    nlist := {};
    pg := []:
    colist := []:
    for pnum from 1 to combinat[numbpart](n) do
        for i from 1 to n do
            j[i] := 0:
        od:
        if pnum = 1 then
           part := combinat[firstpart](n);
        else
           part := combinat[nextpart](part);
        fi:
        map(multiplicity, part, 'j'):
        pgel := [];
        pct := 0;
        for i from 2 to n do
            for jnum from 1 to j[i] do
                pgel := [op(pgel),
                [seq(pct + (jnum-1)*i + k, k = 1..i)]];
            od:
            pct := pct + i*j[i];
        od:
        pg := [op(pg), pgel];
        colist := [op(colist),
        product(1/('k'^j['k']*j['k']!), 'k' = 1..n)];
    od:
    m := 1;
    for i from 1 to nops(pg) do
        pe := pg[i];
        nlist := {};
        mon := 1;
        dg := 0;
        for j from 0 to nsw-1 do
            bk := convert(j, base, 2);
            bki := linalg[vectdim](bk);
            for k from 1 to n do
                vs[k] := 0;
            od:
            for k from 1 to bki do
                vs[k] := bk[k];
            od:
            for k from 1 to linalg[vectdim](vs) do
                vt[linalg[vectdim](vs)-k+1] := vs[k];
            od:
            vres := ppoly(pe, vs, n, x, nlist, m);
            pn := vres[1];
            nlist := nlist union vres[2];
            dg := dg + vres[3];
            m := vres[4];
            mon := simplify(mon*pn);
        od:
        mon := colist[i] * mon * x[1]^(2^n-dg);
        allpoly := simplify(allpoly + mon);
    od:
    maxsub := m;
    RETURN(allpoly);
end: