Rational functions are functions of the form f(x)=Q(x)P(x), where P(x) and Q(x) are polynomials. Their sums often yield curious results and are very commonly used in mathematics. Today, I will be explaining what was essentially a product of my curiosity turning into a very elegant solution for evaluating them.
We know that for an infinite sum of a rational function to be convergent, degP(x)−degQ(x)<−1 must hold. This is trivially proven using a combination of the p-test and the comparison test. For example, the sum
n=1∑∞n21
is clearly convergent, since deg1−degn2=0−2=−2<−1. On the other hand,
n=1∑∞n1
is divergent, since deg1−degn=0−1=−1≮−1.
Consider the sum
k=1∑∞k2−a1
where a is a constant. The following equalities hold:
Every infinite sum of a rational function, the denominator of which does not contain roots of multiplicity ≥ 2, can be meaningfully expressed as a finite sum of the terms in form f⋅(ψ∘g) where f and g are functions of x.
The following part of the post focuses on sheding light on this theorem from multiple angles and using it to derive a method for efficiently evaluating infinite sums of rational functions. While it is possible to special-case the general result for certain functions (cubic and quadratic), it will not be done in the example code for the sake of simplicity.
The algorithm for convergent series is as follows. Denote the roots of the polynomial Q(x+1) as R0…Rm. The following equality holds if P(x)=1:
n=1∑∞Q(n)1=−ω∈R∑Q’(ω+1)ψ(−ω)
If P(x)=1 (i.e. the rational function is not an inverse of some polynomial), the formula is as follows:
Computing the partial sums yields the sum −0.323477+0.392877i−0.323477−0.392877i+0.806386+0.0784787=0.2379107, and this value negated is the approximate value of the sum when computed by iteration until convergence.
A KamilaLisp implementation follows. Define a few helper methods: one to substitute x+1 into some polynomial P(x), compute P’(x) and evaluate a polynomial at a given point.