I need to compute a recursive sequence of numbers. In the formula, I need to compute B(r) where B(x) is a polynomial with rational coefficients (i.e fractions) and r is a rational number. My code is
def B(x):
return x**2-x+1/6
However, when I plug r in, I get a floating number, not a rational number. This is expected.
I have several polynomials like this and my formula involves addition/subtraction with these numbers. How can I return the final result as a rational number?
Thanks!