Extrapolation Methods
Let be $S_n = {\sum}^{n}_{i=1} a_i$ a sequence of partial sums. This repository contains implementations of the following series transformations, which generate a new sequence $T_n$:
-
Aitken's transformation (or delta-squared process):
- In
esum: O($2n\log n$) - In
acelsum: O($n$)
$$T_n = \frac{S_{n-1} S_{n+1} - S_n^2}{S_{n+1} - 2 S_n + S_{n-1}}.$$
- In
-
Richardson's transformation (modify, with given p):
- In
esum: O($2(\log n)^2$) - In
acelsum: O($\log n$)
$$T_n = S_{2n} + \frac{S_{2n} - S_n}{2^p - 1}.$$
Here, we use $p = 1$ for simplicity.
- In
-
- In
esum: O($2n\log n$) - In
acelsum: O($n$)
Let be the auxiliary sequence $\varepsilon_n^j$ defined by:
$$\varepsilon_{-1}^{j} = 0\ \text{and}\ \varepsilon_{0}^{j} = S_j,$$
and inductively:
$$\varepsilon_{k+1}^{j} = \varepsilon_{k-1}^{j+1} + [\varepsilon_{k}^{j+1} - \varepsilon_{k}^{j}]^{-1}.$$
Then, $T_n = \varepsilon_{n-1}^{2}$ (because the odd steps are only partial steps).
- In
-
- In
esum: O($4n\log n$) - In
acelsum: O($2n$)
Let be two auxiliary sequences $s_j^{(n)}$ and $r_j^{(n)}$ defined by:
$$s^{(n)}_0 = 1,\ r^{(n)}_1 = x_n,\ n=0,1,\ldots,$$
inductively:
$$s^{(n)}_{k+1} = s^{(n+1)}_{k} \left( \frac{r^{(n+1)}_{k+1}}{r^{(n)}_{k+1}} - 1 \right),\ k,n = 0,1,\ldots$$
and
$$r^{(n)}_{k+1} = r^{(n+1)}_{k} \left( \frac{s^{(n+1)}_{k}}{s^{(n)}_{k}} - 1 \right),\ k=1,2,\ldots;\ n=0,1,\ldots$$
Then, $T_n = S_n - \frac{S_{n+1} - S_{n}}{r^{(n+1)}_{1} - r^{(n)}_{1}} r^{(n)}_{1}$.
- In
-
- In
esum: O($4n\log n$) - In
acelsum: O($2n$)
This method is defined by
$$W_n^{(k)} = \frac{M_n^{(k)}}{N_n^{(k)}}$$
where
$$M_n^{(0)} = \frac{S_n}{g(n)},$$
$$M_{n}^{(k+1)} = \frac{M_{n+1}^{(k)} - M_{n}^{(k)}}{a_{n + k}^{-1} - a_{n + 1}^{-1}},$$
and
$$N_n^{(0)} = \frac{1}{g(n)},$$
$$N_{n}^{(k+1)} = \frac{N_{n+1}^{(k)} - N_{n}^{(k)}}{a_{n + k}^{-1} - a_{n + 1}^{-1}}.$$
For the function $g(n)$, we have some classic choices for this function:
- t-variant: $g(n) = a_{n+1}$;
- u-variant: $g(n) = n a_n$;
- v-variant: $g(n) = a_n a_{n+1} / (a_{n+1} - a_n)$.
Then, $T_n = \frac{M_n^{(1)}}{N_n^{(1)}}$.
- In
Installation
Make sure you have the mpmath library installed:
pip install mpmath
To install the package, run the following command:
pip install extrapolation
Usage
We have the transformations implemented above, and for use have the esum and acelsum function.
esum
The esum receives on input:
- A series: In the form of a function $f: \mathbb{N} \to \mathbb{R}$ returning the terms to be summed.
- The Transformation: "Aitken", "Richardson", "Epsilon", "G", "Levin-t", "Levin-u", "Levin-v" and "None", the latter being using the initial series without any transformation.
- The stopping criterion: In case the difference of the last two values of the series are smaller than a given error.
- Return in logarithm scale: True if you want to receive the return in logarithm scale with the sign and False if you want to receive in normal scale.
- Precision: If precision is 53 we use the default python precision, otherwise the given bits precision.
This function determines the minimum value of n for which, the difference between the last partial sums becomes less than the specified error when applying the transformation. And returns the series applied to the transformation. The following is an example:
from extrapolation import esum
import math
# Test with no_transform (without transformation) and with Richardson transformation the basel problem
n0, no_accelerated = esum(lambda x: 1/x**2, 'None', error=1e-12, logarithm=False, precision=100)
n1, accelerated = esum(lambda x: 1/x**2, 'Richardson', error=1e-12, logarithm=False, precision=100)
# Comparison
print(f"True value: {math.pi ** 2 / 6}")
print(f"Without acceleration: {no_accelerated[-1]}, with {n0} iterations")
print(f"With acceleration: {accelerated[-1]}, with {n1} iterations")
Out:
True value: 1.6449340668482264
Without acceleration: 1.6449330668487264267523920296, with 1000000 iterations
With acceleration: 1.6449340611255960068665838135, with 22896 iterations
acelsum
We have also the acelsum function, that receives on input:
- A series: In the form of a function $f: \mathbb{N} \to \mathbb{R}$ returning the terms to be summed.
- The Transformation: "Aitken", "Richardson", "Epsilon", "G", "Levin-t", "Levin-u", "Levin-v" and "None", the latter being using the initial series without any transformation.
- Natural n: Number of values to be summed.
- Return in logarithm scale: True if you want to receive the return in logarithm scale with the sign and False if you want to receive in normal scale.
- Precision: If precision is 53 we use the default python precision, otherwise the given bits precision.
This function calculates partial sums up to a given natural value, returning the result in log-scale or normal by applying a chosen transformation. The following is an example:
from extrapolation import acelsum
import math
# Test with no_transform (without transformation) and with Richardson transformation the basel problem
no_accelerated = acelsum(lambda x: 1/x**2, 'None', n=1000, logarithm=False, precision=100)
accelerated = acelsum(lambda x: 1/x**2, 'Richardson', n=1000, logarithm=False, precision=100)
# Comparison
print(f"True value: {math.pi ** 2 / 6}")
print(f"Without acceleration: {no_accelerated[-1]}")
print(f"With acceleration: {accelerated[-1]}")
Out:
True value: 1.6449340668482264
Without acceleration: 1.6439345666815597935850701245
With acceleration: 1.6449310678482254269248263997
Metadata
Release files for extrapolation 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| extrapolation-2.1.1.tar.gz | 6.8 kB | Without provenance | Details for extrapolation-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| extrapolation-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for extrapolation-2.1.1-py3-none-any.whl |
Total release size: 14.0 kB
Release files / extrapolation-2.1.1.tar.gz
| Download URL | extrapolation-2.1.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9721cc52c2a195256268c2aa09c7cdfd4426fb9e5f678733e4556b9ef9fdf31d
|
|
BLAKE2b-256 checksum How to use checksums |
fcdcfa6ef73f99e5098632be8e64b47e7e7b100b9282c7f2e628b829cfaec9f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / extrapolation-2.1.1-py3-none-any.whl
| Download URL | extrapolation-2.1.1-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db36011deca2a531e54f208d4210e1b27b3c511d5b6f7130f1ea69cdac31fa7c
|
|
BLAKE2b-256 checksum How to use checksums |
04307118a86f6861b3b9baa06121b16b9b988c8728f03066d6b722f0e2312eef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for extrapolation 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.