Open In App

Python | sympy.partition() method

Last Updated : 26 Jul, 2019
Improve
Improve
Like Article
Like
Save
Share
Report
With the help of sympy.partition() method, we can find Partition number in SymPy.

partition(n) -

The Partition numbers are a sequence of integers pn that represent the number of distinct ways of representing n as a sum of natural numbers (with order irrelevant). The generating function for pn is given by – \sum_{n=0}^\infty p_n x^n = \prod_{k=1}^\infty (1 - x^k)^{-1}.
Syntax: partition(n) Parameter: n – It denotes the number upto which partition number is to be calculated. Returns: Returns the nth partition number.
Example #1:
# import sympy 
from sympy import * 
  
n = 7
print("Value of n = {}".format(n))
   
# Use sympy.partition() method 
nth_partition = partition(n)  
      
print("Value of nth partition number : {}".format(nth_partition))  

                    
Output:
Value of n = 7
Value of nth partition number : 15
Example #2:
# import sympy 
from sympy import * 
  
n = 10
print("Value of n = {}".format(n))
   
# Use sympy.partition() method 
n_partition = [partition(x) for x in range(1, 11)]  
      
print("N partition number are : {}".format(n_partition))  

                    
Output:
Value of n = 10
N partition number are : [1, 2, 3, 5, 7, 11, 15, 22, 30, 42]


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads