Python | sympy.bell() method

With the help of sympy.bell() method, we can find Bell number and Bell polynomials in SymPy.

bell(n) -



Syntax: bell(n)

Parameter:
n – It denotes the order of the bell number.

Returns: Returns the nth bell number.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import * n = 5
print("Value of n = {}".format(n))
   
# Use sympy.bell() method 
nth_bell = bell(n)  
      
print("Value of nth bell number : {}".format(nth_bell))  

chevron_right


Output:

Value of n = 5
Value of nth bell number : 52

bell(n, k) –

Syntax: bell(n, k)

Parameter:
n – It denotes the order of the bell polynomial.
k – It denotes the variable in the bell polynomial.

Returns: Returns the expression of the bell polynomial or its value.

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import * n = 5
k = symbols('x')
print("Value of n = {} and k = {}".format(n, k))
   
# Use sympy.bell() method 
nth_bell_poly = bell(n, k)  
      
print("The nth bell polynomial : {}".format(nth_bell_poly))  

chevron_right


Output:


Value of n = 5 and k = x
The nth bell polynomial : x**5 + 10*x**4 + 25*x**3 + 15*x**2 + x

Example #3:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import * n = 5
k = 3
print("Value of n = {} and k = {}".format(n, k))
   
# Use sympy.bell() method 
nth_bell_poly = bell(n, k)  
      
print("The nth bell polynomial value : {}".format(nth_bell_poly))  

chevron_right


Output:

Value of n = 5 and k = 3
The nth bell polynomial value : 1866

bell(n, k, (x1, x2, x3, …)) –

Syntax: bell(n, k, (x1, x2, x3, …))

Parameter:
n – It denotes the order of the bell polynomial of second kind.
k – It is a parameter in the bell polynomial of second kind.
(x1, x2, x3, …) – It denotes the tuple of variable symbols.

Returns: Returns the Bell polynomials of the second kind.

Example #4:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import * n = 5
k = 3
variables = symbols('x:6')[1:]
print("Value of n = {}, k = {} and variables = {}".format(n, k, variables))
   
# Use sympy.bell() method 
nth_bell_poly = bell(n, k, variables)  
      
print("The nth bell polynomial of second kind : {}".format(nth_bell_poly))  

chevron_right


Output:

Value of n = 5, k = 3 and variables = (x1, x2, x3, x4, x5)
The nth bell polynomial of second kind : 10*x1**2*x3 + 15*x1*x2**2


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.