Comment #19 on issue 3501 by smi...@gmail.com: Missing partitions in sympy.utilities.iterables.multiset_partitions
http://code.google.com/p/sympy/issues/detail?id=3501

btw, the old multiset code didn't look at the values of the multiset. Unless a routine does, I don't know how anything could be faster than the replacement code that I put it when you consider the simple output that it is generating. Here is the output of _set_partitions for n=5


(1, [0, 0, 0, 0, 0])
(2, [0, 0, 0, 0, 1])
(2, [0, 0, 0, 1, 0])
(2, [0, 0, 0, 1, 1])
(3, [0, 0, 0, 1, 2])
(2, [0, 0, 1, 0, 0])
(2, [0, 0, 1, 0, 1])
(3, [0, 0, 1, 0, 2])
(2, [0, 0, 1, 1, 0])
(2, [0, 0, 1, 1, 1])
(3, [0, 0, 1, 1, 2])
(3, [0, 0, 1, 2, 0])
(3, [0, 0, 1, 2, 1])
(3, [0, 0, 1, 2, 2])
(4, [0, 0, 1, 2, 3])
(2, [0, 1, 0, 0, 0])
(2, [0, 1, 0, 0, 1])
(3, [0, 1, 0, 0, 2])
(2, [0, 1, 0, 1, 0])
(2, [0, 1, 0, 1, 1])
(3, [0, 1, 0, 1, 2])
(3, [0, 1, 0, 2, 0])
(3, [0, 1, 0, 2, 1])
(3, [0, 1, 0, 2, 2])
(4, [0, 1, 0, 2, 3])
(2, [0, 1, 1, 0, 0])
(2, [0, 1, 1, 0, 1])
(3, [0, 1, 1, 0, 2])
(2, [0, 1, 1, 1, 0])
(2, [0, 1, 1, 1, 1])
(3, [0, 1, 1, 1, 2])
(3, [0, 1, 1, 2, 0])
(3, [0, 1, 1, 2, 1])
(3, [0, 1, 1, 2, 2])
(4, [0, 1, 1, 2, 3])
(3, [0, 1, 2, 0, 0])
(3, [0, 1, 2, 0, 1])
(3, [0, 1, 2, 0, 2])
(4, [0, 1, 2, 0, 3])
(3, [0, 1, 2, 1, 0])
(3, [0, 1, 2, 1, 1])
(3, [0, 1, 2, 1, 2])
(4, [0, 1, 2, 1, 3])
(3, [0, 1, 2, 2, 0])
(3, [0, 1, 2, 2, 1])
(3, [0, 1, 2, 2, 2])
(4, [0, 1, 2, 2, 3])
(4, [0, 1, 2, 3, 0])
(4, [0, 1, 2, 3, 1])
(4, [0, 1, 2, 3, 2])
(4, [0, 1, 2, 3, 3])
(5, [0, 1, 2, 3, 4])

It's all very orderly and I suspect the 20+ lines of code that are generating it are about as compact as you can get. So, again, unless any replacement code actually considers the multiplicity of the elements I think this is as good as we can get. The challenge for any code that considers the multiplicity is to produce a pattern like the following:

L=[1,1,1,2,2]
s=set()
for n, p in _set_partitions(len(L)):
...      t = canon(p, L)
...      if t not in s:
...       print p
...       s.add(t)
...
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 1]
[0, 0, 0, 1, 1]
[0, 0, 0, 1, 2]
[0, 0, 1, 0, 0]
[0, 0, 1, 0, 1]
[0, 0, 1, 0, 2]
[0, 0, 1, 1, 1]
[0, 0, 1, 1, 2]
[0, 0, 1, 2, 2]
[0, 0, 1, 2, 3]
[0, 1, 2, 0, 0]
[0, 1, 2, 0, 1]
[0, 1, 2, 0, 3]
[0, 1, 2, 3, 3]
[0, 1, 2, 3, 4]

where


def canon(q, m):
    rv = [[] for i in range(max(q) + 1)]
    for i, qi in enumerate(q):
        rv[qi].append(m[i])
    return tuple(sorted([tuple(i) for i in rv]))


--
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to