Approximate infinite sums with guaranteed error.
Project description
InfSumPy is a Python package that evaluates infinite positive sums with guaranteed error. Using ratio and integral tests we evaluate series that pass these tests with controlled error.
Instalation
Make sure you have the mpmath library installed:
pip install mpmath
To install the package, run the following command:
pip install infsumpy
Usage
We have the transformations implemented above, and for use, we have the infsum function.
Which receives from input:
- A series: In the form of a function f: $\mathbb{N} \to \mathbb{R}$.
- Method: Can be
ratio,integral,thresholdorfixed. - Max terms: The maximum number of terms.
- Start terms: The index of the first term of the series.
- Epsilon (optional): The expected error tolerance (if the method is
ratio,integralorthreshold). - L (optional): Limit of the ratio of terms (if the method is
ratio). - Integral of series (optional): The function of g(n) = ∫_n^∞ f(x) dx for the integral test (if the method is
integral). - Precision (optional): The precision for the
mpmathlibrary (default value is 53).
The function returns the number of terms used in the sum and the approximation.
Ratio test
from infsumpy import infsum
# the infinity sum of n/(2**n) pass in the ratio test with limit L = 1/2,
# then we can evaluate with controled error
print(infsum(lambda n: n/(2**n), 'ratio', max_terms=10**4, initial=1, eps=2**(-52), L=1/2))
> (56, 2.0)
Integral test
from infsumpy import infsum
# the infinity sum of 1/n**2 pass in the integral test with integral
# g(n) = ∫_n^∞ 1/x**2 dx = 1/n, then we can evaluate with controled error
print(infsum(lambda n: 1/(n**2), 'integral', max_terms=10**4, initial=1, eps=10**(-3), g=lambda n: 1/n))
> (499, 1.64493406229104)
Threshold (not guaranteed)
from infsumpy import infsum
# we can also use a stoping criterio such that sum until the n-th are less
# than the epsilon, here for the infinity sum of 2/(2**n)
print(infsum(lambda n: n/(2**n), 'threshold', max_terms=10**4, initial=1, eps=2**(-52)))
> (57, 2.0)
Fixed (not guaranteed)
from infsumpy import infsum
# we can just sum a fixed number of terms of the infinite sum of 2/(2**n)
print(infsum(lambda n: n/(2**n), 'fixed', max_terms=10**4, initial=1))
> (10000, 2.0)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infsumpy-1.0.5.tar.gz.
File metadata
- Download URL: infsumpy-1.0.5.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66fdf52db7dd74af15cb75e7b33bf7f4183d08d694d4fd832c9c9ba2858803da
|
|
| MD5 |
a37d9dad09badeaa1de74bffdf3d3eeb
|
|
| BLAKE2b-256 |
16b97612ad15e5138f4fb4799511a1294466c2c40b0567ef4f432bb1adf885d2
|
File details
Details for the file infsumpy-1.0.5-py3-none-any.whl.
File metadata
- Download URL: infsumpy-1.0.5-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b11f97e94f665216b10028c4467af114f9c91c69250fe0e68169e7d940d78f2b
|
|
| MD5 |
1467b3c9b1007a96cac6281bd1a5bb9d
|
|
| BLAKE2b-256 |
7cee1fe7d43e49a92f0aba76fced87607463b8758e54bbde4ad7decbfb75fb29
|