Friday, November 14, 2025
HomeLanguagesPython | sympy.tribonacci() method

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:




# 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))  


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:




# 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))  


Output:

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

Example #3:




# 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))  


Output:

Value of n = 6 and k = 3
The nth tribonacci polynomial value : 68289
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7142 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS