7
$\begingroup$

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]]
$\endgroup$
1
  • 1
    $\begingroup$ Another way will be NSum[f[i/2012], {i, 1, 2011}] $\endgroup$ Commented Dec 20, 2012 at 15:32

3 Answers 3

12
$\begingroup$

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}]]

$1005+f\left[\frac{1}{2}\right]$

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)]

$\frac{2011}{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.

$\endgroup$
1
  • 2
    $\begingroup$ 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. $\endgroup$
    – whuber
    Commented Dec 20, 2012 at 20:16
9
$\begingroup$

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} $$

partial=Rationalize@NSum[f[i/#],{i,1,#-1}]&/@Range[1,25]
g=FindSequenceFunction[partial]
(* 1/2 (-1+#1)& *)

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

Bonus toy rule replacement that works for small numbers

n=31;
Sum[ff[i/n],{i,1,n-1}]//.Plus[ff[i_],ff[j_]]/;(i==1-j):>1
(* 15 *)

n=30;
Sum[ff[i/n],{i,1,n-1}]//.Plus[ff[i_],ff[j_]]/;(i==1-j):>1
(* 14+ff[1/2] *)
%/.ff->f
(* 29/2 *)

g/@{31,30}
(* {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

$\endgroup$
5
$\begingroup$

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

$\frac{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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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