Skip to main content

Approximate infinite sums with a guaranteed error.

Project description

InfSumPy Logo


InfSumPy is a Python package that evaluates infinite positive sums with a 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 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, threshold or fixed.
  • Max terms: The maximum number of terms.
  • Start terms: The index of the first term of the series.
  • Epsilon (optional): The espected error tolerance (if method is ratio, integral or threshold).
  • L (optional): Limit of the ratio of terms (if method is ratio).
  • Integral of series (optional): The function of g(n) = ∫_n^∞ f(x) dx for the inetegral test (if method is integral).
  • Precision (optional): The precision for the mpmath library (default value if 53).

The function return 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

infsumpy-1.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

InfSumPy-1.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file infsumpy-1.0.1.tar.gz.

File metadata

  • Download URL: infsumpy-1.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for infsumpy-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b9e181c7cb58edaef9d0011ee6ecd6ed406c64f4407fd6b8456c6c468d5ad417
MD5 391474721c0edaf7aa3b79ae72d527c6
BLAKE2b-256 52425fd8fa4be7e58c2ac5dd9209d69cc25a2f15b14f5007302a6e2c3c5061d4

See more details on using hashes here.

File details

Details for the file InfSumPy-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: InfSumPy-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for InfSumPy-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 56c445c8a51fefdbfa7c7b582e05f6d3cdf22e0112ef180be1b16285b77ea921
MD5 b63fe95ce86fab74544ac2e999e19f7f
BLAKE2b-256 9c6f61eb4045db02aa5e7bc8dac36658cd9b4cfb1f2ab80100f72c93ba595a9c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page