# Formula for calculating the sum of a series of function results over a specific range of inputs?

Let's say I have a simple function, something like this:

$f(x) = 5x + 30$

And I want to know the sum of the results of $f(x)$ for all consecutive integers $x$ from $Y$ to $Z$, where $Y$ and $Z$ are arbitrary values greater than $1$.

For example, if $Y$ was $19$ and $Z$ was $22$, the result would be $f(19) + f(20) + f(21) + f(22)$.

Is there any good way to work out a formula for this based on the definition of $f(x)$, such that the sum over a large range of inputs can be calculated without having to iterate over every value individually and sum them?

-
For a general function or of a specific type? – cmmndy Feb 6 '13 at 18:25
For various kinds of $f(x)$, like $x$, $x^2$, $x^3$, $c^x$, $\sin x$, $x^2 2^x$, there is, and then for their linear combinations like $2x+3^x$, and so on. But for general $f(x)$ can't really say anything. – André Nicolas Feb 6 '13 at 18:26
I agree with @AndréNicolas, without any further assumptions, you need to evaluate the function at each value. Which also makes sense intuitively. – cmmndy Feb 6 '13 at 18:28

For your particular example, or more generally $ax+b$ where $a$ and $b$ are constants, there is a nice formula. The sum of $ax+b$ from $x=m$ to $x=n$ is equal to $$a\left(\frac{(n+m)(n-m+1)}{2} \right) +b(n-m+1).$$

There are also known formulas when $f(x)=x^2$, $f(x)=x^3$, $f(x)=x^4$, and so on.

One can find formulas for $f(x)=c^x$, where $c$ is a constant. Also for $f(x)=xc^x$, $x^2c^x$, and so on. One can also deal with $f(x)=\sin x$ and $f(x=\cos x$. There is a large number of other $f(x)$ for which "summatory" formulas of the kind you asked about are known.

You might for fun want to find a simple expression for $\frac{1}{1\cdot 2}+\frac{1}{2\cdot 3}+\frac{1}{3\cdot 4}+\cdots+\frac{1}{99\cdot 100}$.

Whenever we have a formula for $g(x)$ and for $h(x)$, we can easily obtain a formula for $f(x)=ag(x)+bh(x)$, where $a$ and $b$ are any constants.

But there is no simplifying formula for general $f(x)$.

Remark: Let's see intuitively what happens with your $f(x)=5x+30$, as $x$ goes from say $44$ to $98$, inclusive.

So we will be adding together $98-44+1=55$ numbers. When we add up the $55$ $30$'s, we will get $(30)(55)$.

What about the sum of the $55$ terms of the shape $5x$? This will be $5$ times the sum $$44+45+46+\cdots +96+97+98.$$ Npte that the end terms $44$ and $98$ average to $\frac{44+98}{2}$, which is $71$. You can see that $45$ and $97$ also average to $71$, as do $46$ and $96$, and so on. This is because as we go inwards, the bottom number goes up by $1$ but the top number goes down by $1$, so the sum of the two doesn't change. Thus the average of all our numbers is $71$. There are $55$ numbers in the list, so their sum is $(71)(55)$.

The sum of all the $5x$ is therefore $(5)(71)(55)$, and therefore the sum of all the $5x+30$ is $(5)(71)(55)+(30)(55)$. The same idea gives the general formula quoted above.

-

As an example you gave a linear function, and for every linear function $f(a+b)=f(a)+f(b)$

Since there is a formula for $\sum_{i=k}^n i=[n(n+1)-k(k+1)]/2=S$, you could compute it just by evaluating $f(S)$.

This trick can't be expected to extend outside additive functions, obviously.

-