InfSumPy


NameInfSumPy JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/wellington36/InfSumPy
SummaryApproximate infinite sums with guaranteed error.
upload_time2024-11-21 14:59:40
maintainerNone
docs_urlNone
authorWellington Silva
requires_pythonNone
licenseMIT
keywords python sum series infinite-series approximation guaranted-sum
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![InfSumPy Logo](https://github.com/wellington36/InfSumPy/raw/main/man/figures/logo_README.png)

--------------------------------------------------------------------------------
![PyPI](https://img.shields.io/pypi/v/InfSumPy?label=pypi%20package)
![versions](https://img.shields.io/pypi/pyversions/pybadges.svg)
![example workflow](https://github.com/wellington36/InfSumPy/actions/workflows/test_infsum.yml/badge.svg)

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:

```bash
pip install mpmath
```

To install the package, run the following command:

```bash
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`, `threshold` or `fixed`.
- _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`, `integral` or `threshold`).
- _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 `mpmath` library (default value is 53).

The function returns the number of terms used in the sum and the approximation.

### Ratio test
```py
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))
```

```bash
> (56, 2.0)
```

### Integral test
```py
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))
```

```bash
> (499, 1.64493406229104)
```

### Threshold (not guaranteed)
```py
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)))
```

```bash
> (57, 2.0)
```

### Fixed (not guaranteed)
```py
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))
```

```bash
> (10000, 2.0)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wellington36/InfSumPy",
    "name": "InfSumPy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, sum, series, infinite-series, approximation, guaranted-sum",
    "author": "Wellington Silva",
    "author_email": "<wellington.71319@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a0/61/dd1d4fe8dceeb58ffd86c4e3ff31d850e180ebbfc28f4130302115057ea8/infsumpy-1.0.3.tar.gz",
    "platform": null,
    "description": "![InfSumPy Logo](https://github.com/wellington36/InfSumPy/raw/main/man/figures/logo_README.png)\n\n--------------------------------------------------------------------------------\n![PyPI](https://img.shields.io/pypi/v/InfSumPy?label=pypi%20package)\n![versions](https://img.shields.io/pypi/pyversions/pybadges.svg)\n![example workflow](https://github.com/wellington36/InfSumPy/actions/workflows/test_infsum.yml/badge.svg)\n\nInfSumPy is a Python package that evaluates infinite positive sums with guaranteed error.\nUsing ratio and integral tests we evaluate series that pass these tests with controlled error.\n\n## Instalation\n\nMake sure you have the mpmath library installed:\n\n```bash\npip install mpmath\n```\n\nTo install the package, run the following command:\n\n```bash\npip install infsumpy\n```\n\n# Usage\nWe have the transformations implemented above, and for use, we have the `infsum` function.\nWhich receives from input:\n\n- _A series_: In the form of a function f: $\\mathbb{N} \\to \\mathbb{R}$.\n- _Method_: Can be `ratio`, `integral`, `threshold` or `fixed`.\n- _Max terms_: The maximum number of terms.\n- _Start terms_: The index of the first term of the series.\n- _Epsilon_ (optional): The expected error tolerance (if the method is `ratio`, `integral` or `threshold`).\n- _L_ (optional): Limit of the ratio of terms (if the method is `ratio`).\n- _Integral of series_ (optional): The function of g(n) = \u222b_n^\u221e f(x) dx for the integral test (if the method is `integral`).\n- _Precision_ (optional): The precision for the `mpmath` library (default value is 53).\n\nThe function returns the number of terms used in the sum and the approximation.\n\n### Ratio test\n```py\nfrom infsumpy import infsum\n\n# the infinity sum of n/(2**n) pass in the ratio test with limit L = 1/2,\n# then we can evaluate with controled error\nprint(infsum(lambda n: n/(2**n), 'ratio', max_terms=10**4, initial=1, eps=2**(-52), L=1/2))\n```\n\n```bash\n> (56, 2.0)\n```\n\n### Integral test\n```py\nfrom infsumpy import infsum\n\n# the infinity sum of 1/n**2 pass in the integral test with integral\n# g(n) = \u222b_n^\u221e 1/x**2 dx = 1/n, then we can evaluate with controled error\nprint(infsum(lambda n: 1/(n**2), 'integral', max_terms=10**4, initial=1, eps=10**(-3), g=lambda n: 1/n))\n```\n\n```bash\n> (499, 1.64493406229104)\n```\n\n### Threshold (not guaranteed)\n```py\nfrom infsumpy import infsum\n\n# we can also use a stoping criterio such that sum until the n-th are less\n# than the epsilon, here for the infinity sum of 2/(2**n)\nprint(infsum(lambda n: n/(2**n), 'threshold', max_terms=10**4, initial=1, eps=2**(-52)))\n```\n\n```bash\n> (57, 2.0)\n```\n\n### Fixed (not guaranteed)\n```py\nfrom infsumpy import infsum\n\n# we can just sum a fixed number of terms of the infinite sum of 2/(2**n)\nprint(infsum(lambda n: n/(2**n), 'fixed', max_terms=10**4, initial=1))\n```\n\n```bash\n> (10000, 2.0)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Approximate infinite sums with guaranteed error.",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/wellington36/InfSumPy"
    },
    "split_keywords": [
        "python",
        " sum",
        " series",
        " infinite-series",
        " approximation",
        " guaranted-sum"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3808c901b6ad92dcdf47f9d2a9c806457436399791ebcf9e532cc2d7bff0a985",
                "md5": "76de0044194f0ff254f02eefe8a8954e",
                "sha256": "d15ebd60e7de275428428ee61dc47d971fe418e0d00dd14d38d6090ad2275bc9"
            },
            "downloads": -1,
            "filename": "InfSumPy-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "76de0044194f0ff254f02eefe8a8954e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15806,
            "upload_time": "2024-11-21T14:59:35",
            "upload_time_iso_8601": "2024-11-21T14:59:35.422402Z",
            "url": "https://files.pythonhosted.org/packages/38/08/c901b6ad92dcdf47f9d2a9c806457436399791ebcf9e532cc2d7bff0a985/InfSumPy-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a061dd1d4fe8dceeb58ffd86c4e3ff31d850e180ebbfc28f4130302115057ea8",
                "md5": "2b19b8d22e91b330bdf5473fe2669faa",
                "sha256": "f633a88ab695db94dc48256b84ddaa1d43aa9f8513700dd8d2fdf6a5103045f1"
            },
            "downloads": -1,
            "filename": "infsumpy-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2b19b8d22e91b330bdf5473fe2669faa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16689,
            "upload_time": "2024-11-21T14:59:40",
            "upload_time_iso_8601": "2024-11-21T14:59:40.611657Z",
            "url": "https://files.pythonhosted.org/packages/a0/61/dd1d4fe8dceeb58ffd86c4e3ff31d850e180ebbfc28f4130302115057ea8/infsumpy-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-21 14:59:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wellington36",
    "github_project": "InfSumPy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "infsumpy"
}
        
Elapsed time: 0.66997s