I'm trying to sum up a Taylor series of a transcendental function, but for each $n$, I need to tweak the number of terms to be summed up manually, on a trial and error basis.
I know that the result is always 0 or 1, so I want Mathematica to stop when the sum gets, say, lesser than $10^{-5}$ or close enough to 1. How do I do that?
Here's the formula I'm working with. This sum yields 1 if $k$ divides $n$, and 0 otherwise. If $n$ is small, summing up 55 terms is good enough, but if $n$ grows large, we may need many more terms. I don't know how many beforehand, so I'd like Mathematica to stop summing up when a certain precision is attained.
Is it possible to easily incorporate that into the below?
M = 55; k = 2; n = 4;
N[Sum[(-1)^i*(2*Pi*n)^(2*i)*Sum[BernoulliB[2*j]/(k^(2*j)*((2*j)!*(2*i - 2*j + 1)!)), {j, 0, i}], {i, 0, M}], 10]