def test_rational_algorithm(): f = 1 / ((x - 1)**2 * (x - 2)) assert rational_algorithm(f, x, k) == \ (-2**(-k - 1) + 1 - (factorial(k + 1) / factorial(k)), 0, 0) f = (1 + x + x**2 + x**3) / ((x - 1) * (x - 2)) assert rational_algorithm(f, x, k) == \ (-15*2**(-k - 1) + 4, x + 4, 0) f = z / (y * m - m * x - y * x + x**2) assert rational_algorithm(f, x, k) == \ (((-y**(-k - 1)*z) / (y - m)) + ((m**(-k - 1)*z) / (y - m)), 0, 0) f = x / (1 - x - x**2) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == \ (((-Rational(1, 2) + sqrt(5)/2)**(-k - 1) * (-sqrt(5)/10 + Rational(1, 2))) + ((-sqrt(5)/2 - Rational(1, 2))**(-k - 1) * (sqrt(5)/10 + Rational(1, 2))), 0, 0) f = 1 / (x**2 + 2 * x + 2) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == \ ((I*(-1 + I)**(-k - 1)) / 2 - (I*(-1 - I)**(-k - 1)) / 2, 0, 0) f = log(1 + x) assert rational_algorithm(f, x, k) == \ (-(-1)**(-k) / k, 0, 1) f = atan(x) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == \ (((I*I**(-k)) / 2 - (I*(-I)**(-k)) / 2) / k, 0, 1) f = x * atan(x) - log(1 + x**2) / 2 assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == \ (((I*I**(-k + 1)) / 2 - (I*(-I)**(-k + 1)) / 2) / (k*(k - 1)), 0, 2) f = log((1 + x) / (1 - x)) / 2 - atan(x) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == \ ((-(-1)**(-k) / 2 - (I*I**(-k)) / 2 + (I*(-I)**(-k)) / 2 + Rational(1, 2)) / k, 0, 1) assert rational_algorithm(cos(x), x, k) is None
def test_rational_algorithm(): f = 1 / ((x - 1) ** 2 * (x - 2)) assert rational_algorithm(f, x, k) == (-2 ** (-k - 1) + 1 - (factorial(k + 1) / factorial(k)), 0, 0) f = (1 + x + x ** 2 + x ** 3) / ((x - 1) * (x - 2)) assert rational_algorithm(f, x, k) == (-15 * 2 ** (-k - 1) + 4, x + 4, 0) f = z / (y * m - m * x - y * x + x ** 2) assert rational_algorithm(f, x, k) == (((-y ** (-k - 1) * z) / (y - m)) + ((m ** (-k - 1) * z) / (y - m)), 0, 0) f = x / (1 - x - x ** 2) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == ( ((-Rational(1, 2) + sqrt(5) / 2) ** (-k - 1) * (-sqrt(5) / 10 + Rational(1, 2))) + ((-sqrt(5) / 2 - Rational(1, 2)) ** (-k - 1) * (sqrt(5) / 10 + Rational(1, 2))), 0, 0, ) f = 1 / (x ** 2 + 2 * x + 2) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == ( (I * (-1 + I) ** (-k - 1)) / 2 - (I * (-1 - I) ** (-k - 1)) / 2, 0, 0, ) f = log(1 + x) assert rational_algorithm(f, x, k) == (-(-1) ** (-k) / k, 0, 1) f = atan(x) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == (((I * I ** (-k)) / 2 - (I * (-I) ** (-k)) / 2) / k, 0, 1) f = x * atan(x) - log(1 + x ** 2) / 2 assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == ( ((I * I ** (-k + 1)) / 2 - (I * (-I) ** (-k + 1)) / 2) / (k * (k - 1)), 0, 2, ) f = log((1 + x) / (1 - x)) / 2 - atan(x) assert rational_algorithm(f, x, k) is None assert rational_algorithm(f, x, k, full=True) == ( (-(-1) ** (-k) / 2 - (I * I ** (-k)) / 2 + (I * (-I) ** (-k)) / 2 + Rational(1, 2)) / k, 0, 1, ) assert rational_algorithm(cos(x), x, k) is None