Skip to main content

Lagrange polynomials over finite fields

Project description

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.

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

lagrange_polynomial-0.0.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

lagrange_polynomial-0.0.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

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