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
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)
Metadata
Release files for InfSumPy 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| infsumpy-1.1.0.tar.gz | 18.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| infsumpy-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.2 kB
Release files / infsumpy-1.1.0.tar.gz
| Download URL | infsumpy-1.1.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a972421bdd4f96707e6bbbeff7f310c984ed3235f91ad6155b6f1550f0808fcd
|
|
BLAKE2b-256 checksum How to use checksums |
1af8e4a3d4637f8df7abf9463e85648e92bb71b22493462a89550e4e1e42a0a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / infsumpy-1.1.0-py3-none-any.whl
| Download URL | infsumpy-1.1.0-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e6b3f51bb8666b61086239b1f668f93f82b21e36456ea727b6e6b8c26a9f97c
|
|
BLAKE2b-256 checksum How to use checksums |
4d996e69c81fdc3adc761bfaa2eabf1ad34f08fa0061b1373844776753a8b378
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|