Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to find the sum $$S=f\left(\dfrac{1}{2012} \right) +f\left(\dfrac{2}{2012} \right) +\cdots + f\left(\dfrac{2011}{2012} \right), $$ where $$f(x) = \dfrac{4^x}{4^x + 2}.$$ I tried

f[x_] := 4^x/(4^x + 2)
Sum[f[i/2012], {i, 1, 2011}]

But I can't get the answer. How do I tell Mathematica to do that?

I know, $$f(x) + f(1 - x) =1.$$

I used

Simplify[f[x] + f[1 - x]]
share|improve this question
Another way will be NSum[f[i/2012], {i, 1, 2011}] – PlatoManiac Dec 20 '12 at 15:32
Thank you very much. – minthao_2011 Dec 20 '12 at 15:33
up vote 12 down vote accepted

The Simplify idea is on the right track, but you have to tell Mathematica about the relationship between f and Plus in a slightly different way:

ClearAll[f]; Plus[f[x_], f[y_]] /; x + y == 1 ^:= 1

The Upset symbol ^:= means this is a definition for f rather than Plus. This approach is inefficient--there is going to be a lot of blind checking to find pairs of arguments x and y that sum to unity--but it works.

With[{n = 2012}, Sum[f[i/n], {i, 1, n - 1}]]


Ah, yes: we do have to remember to give a definition of f in order to handle any leftover terms from the sum that do not simplify:

Block[{x}, %  /. f[x_] -> 4^x/(4^x + 2)]


Despite the inefficiency, this approach clearly and suggestively captures the point of the problem: to use that sum-to-unity identity for $f$ to simplify the sum, leaving only the middle term $f(\frac{1}{2})$ to be evaluated.

share|improve this answer
There is a story, well known to mathematicians, about a very young Karl Gauss being set the problem of summing $1+2+\cdots+100$. He obtained the solution almost immediately by observing that by taking the sum from both ends, it "folds" into $(1+100)+(2+99)+\cdots+(49+52)+(50+51)$ = $101+101+\cdots+101$ = $50\times 101$. Summing $f(i/n)$ is accomplished with the same idea. – whuber Dec 20 '12 at 20:16

I like FindSequenceFunction it can be pretty awesome.

Here I give it the sequence (your case is when k=2012):

$$ \left\{ \sum_{n=1}^{k-1} f \left( \frac{i}{n} \right) \right\}_{k=1}^{25} $$

(* 1/2 (-1+#1)& *)

g[10000] == Rationalize@NSum[f[i/10000],{i,1,9999}]
(* True *)

Bonus toy rule replacement that works for small numbers

(* 15 *)

(* 14+ff[1/2] *)
(* 29/2 *)

(* {15,29/2} *)

The neat thing about this is that it hints of an obvious extension to other functions as long as they satisfy f[x]+f[1-x]==1

share|improve this answer

You could also use the knowledge that $f(x) + f(1-x) = 1$ as follows:

f[x_] := 4^x/(4^x + 2)
Sum[Simplify[f[i/2012] + f[(2012 - i)/2012]], {i, 1, 2011}]/2


Here I just did the sum twice - once forward and once backward. Then I divided by two. The assumption about $f$ actually never has to be explained to Mathematica here, I just helped it along by arranging the terms so that Simplify can recognize them inside the sum.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.