Skip to main content

Lagrange Polynomials

Module to generate Lagrange polynomials over integers for 1-dimensional data. This is generally useful for interpolation.

Installation

Install with pip.

Usage

Example

from lagrange_polynomial import LagrangePolynomial

xs = range(100)
ys = [f(x) for x in xs]          # For some function f

lp = LagrangePolynomial(xs, ys)  # Instantiate a polynomial with sequences of
                                 # x- and y-coordinates.

for x in xs:
    assert ys[x] == lp(x)        # Polynomial will intersect original points
    coefficient = lp.basis[0](x) # Get the 0th basis vector at x

Interface

The LagrangePolynomial class takes two equally-sized sequences and an optional integer p. The instance is a Lagrange polynomial L: x -> L(x) over GF(p). If p is not provided, it defaults to the 8th Mersenne prime M31.

It has a basis property, a LagrangeBasis object subclassing Sequence. Each element ℓⱼ indexed by integers j in range(len(xs)) is a function taking x to its jth basis vector ℓⱼ(x).

Test

Test with make test.

Release files for lagrange-polynomial 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lagrange-polynomial 0.0.1
File Size Uploaded
lagrange_polynomial-0.0.1.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lagrange-polynomial 0.0.1
File Interpreter ABI Platform
lagrange_polynomial-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size:7.1 kB

Release files / lagrange_polynomial-0.0.1.tar.gz

Download URL lagrange_polynomial-0.0.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
35d851dcc3e67f978e2a3827a93810632c73f3eef90b8bff656956974e7b78b7
BLAKE2b-256 checksum
How to use checksums
d5f9e42033444b363d3911ccd9c560c39c3a0d528cc709518cbb44c8886731f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release files / lagrange_polynomial-0.0.1-py3-none-any.whl

Download URL lagrange_polynomial-0.0.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
850b702ea1aabcfc0d6f82dd4a64387b8cff7c386d2198f3fac8176ea31bea32
BLAKE2b-256 checksum
How to use checksums
a88a24d409ecb2d1b1a4985371571c8281ff85addd0b71b4954ad85fcbc52475
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page