0

$\sum_{i=0}^n \frac{\sum_{i=0}^n n}{n!} $

Is it possible to convert this series to the form $ \frac{ n(n+1)}{2} $

I've tried my best to convert the code below to math notation but can't seem to get the same answer.

Python version:

vars1=1
vars2=0
for x in (range(1,n+1)):
  vars1*=x
  vars2+=x
  ans+=vars2/vars1
  • I think in it's current form the sum you are referring to has a notational mistake - since in the second sum, ${i}$ is redefined but is not a free variable – Riemann'sPointyNose Jul 22 '20 at 16:48
  • If you have any insights on what would be the correct formula please feel free to let me know, I've literally already filled up a notebook trying to get to the same answer. I just know it as the sum of the fractions of sum(n)/n! – JJ-Pysquared Jul 22 '20 at 16:51
  • @JJ-Pysquared Shoudn't be something like $\sum_{k=0}^n \frac{\sum_{i=0}^k i}{k!}$? – mwt Jul 22 '20 at 16:57
  • @mwt Does that formula equal to the code which is the sum of the fractions of (SUM(n)/n!), that is also what I am mostly confused about – JJ-Pysquared Jul 22 '20 at 17:00
  • Are you running Python 2 or Python 3? In Python 2, vars2/vars1 rounds down to an integer, unless one quantity is a float, so you could try vars1=1. or ans+=float(vars2)/vars1 or ans+=vars2/float(vars1). – J.G. Jul 22 '20 at 17:05
  • @J.G. python3_____ – JJ-Pysquared Jul 22 '20 at 17:06
  • In that case, could you edit your question to show an example that calculates an incorrect result? You haven't included here an initialization of n or ans, or a unit test. – J.G. Jul 22 '20 at 17:11
  • Sorry, ans =0, n=5, what I need to know is can i convert this to a=x(x+1)/2x! , (a(a+1)/2) or SUM(x(x+1)) / SUM(2x!) – JJ-Pysquared Jul 22 '20 at 17:13

1 Answers1

1

You have the right idea thinking that var1 is representing the factorial. And it goes ${1!,2!,3!,...,n!}$. And indeed var2 is the sum of the first ${x}$ integers, and we are taking their ratio. So

$${S(n) = \sum_{x=1}^{n}\frac{\sum_{i=0}^{x}i}{x!}}$$

Now using the fact that

$${\sum_{i=0}^{x}i = \frac{x(x+1)}{2}}$$

We can get

$${S(n) = \sum_{x=1}^{n}\frac{x(x+1)}{2x!}}$$

I don't think a nice partial sum formula will exist. If you take a look at WolframAlpha, it's a long expression involving the Gamma function and all sorts: https://www.wolframalpha.com/input/?i=sum+from+k%3D1+to+n+%28k*%28%28k%2B1%29%2F2%29%29%2F%28k%21%29

What you can do, however, is take a limit as ${n\rightarrow\infty}$. This will tell you, as $n$ get's bigger, what the sum is approaching. I imagine that it converges quite quickly, so for large $n$ this will be a good approximation anyways. I am going to change the variable ${x}$ into the variable ${i}$, since otherwise things are going to get very confusing. Notice

$${S(n) = \frac{1}{2}\sum_{i=1}^{n}\left[\frac{i^2}{i!} + \frac{i}{i!}\right]=\frac{1}{2}\left(\sum_{i=1}^{n}\frac{i}{(i-1)!} + \sum_{i=1}^{n}\frac{1}{(i-1)!}\right)}$$

So we have two sums to calculate. Using

$${e^{x} = \sum_{i=0}^{\infty}\frac{x^i}{i!}}$$

you see the right sum

$${\sum_{i=1}^{n}\frac{1}{(i-1)!}\rightarrow \sum_{i=0}^{\infty}\frac{1}{i!}=e}$$

as ${n\rightarrow \infty}$. Differentiating the Taylor Series for ${e^{x}}$, multiplying by $x$ and differentiating once again and setting ${x=1}$ also yields that

$${\sum_{i=1}^{n}\frac{i}{(i-1)!}\rightarrow 2e}$$

as ${n\rightarrow\infty}$. And hence we get overall that

$${\lim_{n\rightarrow\infty}S(n)=\frac{1}{2}\left(2e+e\right)=\frac{3e}{2}\approx 4.07742274}$$

This is what your sum "approaches" as ${n\rightarrow\infty}$.

  • @Riemann'sPointNose awesome, my main question is can i convert this to a=x(x+1)/2x! , (a(a+1)/2) – JJ-Pysquared Jul 22 '20 at 17:05
  • Or is valid to spread the sum ie SUM(x(x+1)) / SUM(2x!) – JJ-Pysquared Jul 22 '20 at 17:11
  • @JJ-Pysquared No. This works only for arithmetic sequences. It is not a general summation formula. – mwt Jul 22 '20 at 17:13
  • @JJ-Pysquared Given an $n$, the "closed form" for your sum is not actually a trivial one, as you can see from the WolframAlpha link I have given you. However, I editted the answer and have shown you how to calculate the limit as the sum goes to infinity – Riemann'sPointyNose Jul 22 '20 at 17:17
  • @RiemannPointyNose Thank you, I was actually trying to use the fact that S(n)*2/3=e to solve for n! https://github.com/JJpysquared/Gen_e/blob/master/Approx line 58, sorry for wasting your time but thank you so much for the insight – JJ-Pysquared Jul 22 '20 at 17:22
  • @JJ-Pysquared no problem at all! I also just ran the code for ${n=30}$ and it indeed even only after ${30}$ iterations the answer was already so close to what it's approaching, so it converges very very quickly – Riemann'sPointyNose Jul 22 '20 at 17:24
  • Back to the drawing board and just want to say thank you for everyone's help, I tried voting up but I don't have enough reputation points :/ – JJ-Pysquared Jul 22 '20 at 17:31