I think this is how you can get close to the actual solution. This is by no means a theoritical solution, but it would narrow down your search range by a huge amount. First, some concepts:
- The value of the sum of the above series is given by the harmonic number and its value can be approximated to
ln(n+1
wheren+1
is your iteration number (notn
). For example, if you run10^8
iterations, the sum would be ~log(10^8-1)=18.420680733952366
and the actual value (i.e. by code) is18.997896413852555
. I know this is a huge difference, but lets take it (At least I don't know any other method).
UPDATE: see the comment on this answer, you can actually add Euler-Mascheroni constant constant for a better approximation).
As the value of
sum
increases, your precision becomes shorter, the value of the smallest precision can be obtained byeps(sum)
i.e. after10^8
iterations, the value ofeps(sum)=3.552713678800501e-15
.The increment at each iteration needs to be calculated and is very simple. At
10^8
iteration, the increment from previous iteration is1/10^8
.So, what we want is that the number obtained in (3) should be greater than (2). How to obtain the value of sum in (2), either run the code or use method in (1) (I did the latter).
I observed that
eps(8)>1e-15
. The increment at iteration10^15 = 10^-15 < eps(8)
. Therefore, its already impossible to reach 10^15 iterations. Lets try10^14
iterations. The increment at iteration10^14 = 10^-14 < eps(64)
. That means your sum at 10^14 iterations should be less than 64. Is it? Lets check from formula in (1). It is= log(10^14-1) = 32.236191301916627
.So I concluded that at 10^14 iterations, the precision is still big enough, but at 10^15 is not. So the exact iteration number lies in the range 10^14 to 10^15. Well, you can still narrow it down and possibly with some more effort find the exact iteration number. I have shown you the way.
I actually found out the number of iterations when your condition would be satisfied. I calculated it as follows:
eps(33)= 7.105427357601002e-015
(since eps
takes the same value from 32 to 63 and your sum will never reach 64, so this is the value of eps
you should be dealing with). So you need your increment to be just above this number. Therefore, I decided to have the increment to be 7.1055e-15
. We already know that number of iterations lie between 10^14 and 10^15. Therefore, desired number of iterations must be k*10^14
where k is a constant between 1 to 10 (since when k = 10
, it essentially becomes 10^15
). Solve (1/(k*10^14))=7.1055e-15
(you can go even finer, I decided to stick with 7.1055e-15
. I got k=1.407360495390895
. Therefore, number of iterations = 1.407360495390895*10^14
.
P.S. I could be wrong. Please cross-check. Also, I suggest you to post this in math.stackoverflow. Before that reframe the question such that you are asking for a theoretical solution and you can get much better answers.