Inverse Powers

Let’s consider the inverse powers mathematical sequence of a given number \(n\) which is defined as:

\[p_i = \frac{1}{n^i}, i \geq 0\]

Implement the following Python function in the invpow module (file invpow.py):

invpow(n, eps)
takes n, eps float numbers where n is any number and eps represents a tolerance
returns a float with the sum of all those terms of this sequence until the difference between two consecutive terms is negligible under an epsilon tolerance, i.e. \(abs(t_i - t_{i+1}) < eps\).

For exemple:


>>> round(invpow(1.1, 1e-2), 4)
9.9847
>>> round(invpow(1.1, 1e-4), 4)
10.9895
>>> round(invpow(2, 1e-1), 4)
1.875
>>> round(invpow(2, 1e-3), 4)
1.998
>>> round(invpow(3.3, 1e-2), 4)
1.4311
>>> round(invpow(3.3, 1e-10), 4)
1.4348

Doctests are available at the invpow-test.txt file.