Does WL PartitionsP[] exist in sympy?

57 views
Skip to first unread message

Rocky Bernstein

unread,
Mar 19, 2021, 7:43:55 PM3/19/21
to sympy
A little background first... 

I have been working on Mathics, a open-source implementation of the Wolfram Language.

Mathics relies heavily on sympy.  

For a little while I have been working on ensuring that Steve Skiena's Combinatorica  works on Mathics. In doing this, I was looking for a sympy equivalent to PartitionsP[] 

I couldn't find anything so initially I was generating all of the partitions using sympy.utilities.iterables.partitions and then taking the length.

This is horribly inefficent. Therefore I thought, I'd use the algorition in Skiena's book which makes use of Euler's recurrence for the number of partitions.

It took a little bit of tweaking to get it to be reasonably efficient in Python. The current impelemtation  is here.

This might be of interest and use in sympy as well,  so I'd like to mention it here. 

And if there is already such a routine in sympy, I'd would be grateful to know about. 

Thanks.

Chris Smith

unread,
Mar 19, 2021, 8:07:07 PM3/19/21
to sympy
See `npartitions` in sympy/ntheory/partitions_.py

>>> npartitions(10**3)
24061467864032622473692149727991

/c

Chris Smith

unread,
Mar 19, 2021, 8:09:47 PM3/19/21
to sympy
There should really be a note in the `utilities.iterables.partitions` docstring that indicates that if one only wants to count the partitions that `npartitions` should be used. Now, it only shows a See Also to other related functions:
```

See Also

========



sympy.combinatorics.partitions.Partition

sympy.combinatorics.partitions.IntegerPartition


```

/c

Rocky Bernstein

unread,
Mar 19, 2021, 8:24:43 PM3/19/21
to sympy
Thanks! _ will use that.

Chris Smith

unread,
Mar 19, 2021, 8:33:24 PM3/19/21
to sympy
see also `nP` in sympy/sympy/functions/combinatorial/numbers.py

/c
Reply all
Reply to author
Forward
0 new messages