Get permtutation count when using multiset_partitions

33 views
Skip to first unread message

Joan

unread,
Jun 17, 2019, 4:40:13 PM6/17/19
to sympy
I am using the multiset_partitions from sympy to get the possible permutations of a list of elements, it does work wonderfully, but depending on the case it will take a long time to generate the whole list.
Is there any way I can calculate the number of permutations prior generating them? It would help to discard some complex calculations to be made.

Thanks

Aaron Meurer

unread,
Jun 17, 2019, 4:48:39 PM6/17/19
to sympy
The docstring of multiset_partitions describes how to count
partitions. It mentions the nT function, but not where to get it. It's
in sympy.functions.combinatorial.numbers

>>> from sympy.functions.combinatorial.numbers import nT
>>> from sympy.utilities.iterables import multiset_partitions
>>> len(list(multiset_partitions([1, 1, 2, 3], 3)))
4
>>> nT([1, 1, 2, 3], 3)
4

Also the docstring creates its own version of the Stirling numbers of
the second kind, but there is a striling() function in the same
module. So the documentation of multiset_partitions() could be
improved. Also, some of these functions should probably be included in
the default namespace (sympy/__init__.py).

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/be1af050-ac6c-46a1-8107-e79a3d765feb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joan

unread,
Jun 26, 2019, 5:42:29 PM6/26/19
to sy...@googlegroups.com
Thanks Aaron,

I couldn't check on your suggestions until today, they worked great :D

Joan

Missatge de Aaron Meurer <asme...@gmail.com> del dia dl., 17 de juny 2019 a les 22:48:
Reply all
Reply to author
Forward
0 new messages