Python | sympy.tribonacci() method

With the help of sympy.tribonacci() method, we can find Tribonacci number and Tribonacci polynomial in SymPy.

tribonacci(n) -


The Tribonacci numbers are the integer sequence defined by the initial terms T_0 = 0, T_1 = 1, T_2 = 1 and the three-term recurrence relation T_n = T_{n-1} + T_{n-2} + T_{n-3}.



Syntax: tribonacci(n)

Parameter:
n – It denotes the number upto which Tribonacci number is to be calculated.

Returns: Returns the nth Tribonacci number.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import * 
  
n = 7
print("Value of n = {}".format(n))
   
# Use sympy.tribonacci() method 
nth_tribonacci = tribonacci(n)  
      
print("Value of nth tribonacci number : {}".format(nth_tribonacci))  

chevron_right


Output:

Value of n = 7
Value of nth tribonacci number : 24

tribonacci(n, k) -

The Tribonacci polynomials are defined by T_0(k) = 0, T_1(k) = 1, T_2(k) = k^2 and T_n(k) = k^2 T_{n-1}(k) + k T_{n-2}(k) + T_{n-3}(k) for n > 2. For all positive integers n, T_n(1) = T_n.

Syntax: tribonacci(n, k)

Parameter:
n – It denotes the nth Tribonacci polynomial.
k – It denotes the variable in the Tribonacci polynomial.


Returns: Returns the nth Tribonacci polynomial in k, Tn(k)

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.tribonacci() method 
nth_tribonacci_poly = tribonacci(n, k)  
      
print("The nth tribonacci polynomial : {}".format(nth_tribonacci_poly))  

chevron_right


Output:

Value of n = 5 and k = x
The nth tribonacci polynomial : x**8 + 3*x**5 + 3*x**2

Example #3:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Value of n = 6 and k = 3
The nth tribonacci polynomial value : 68289


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.