https://github.com/fionn/lagrange-polynomial
Numerical Lagrange polynomials over 𝔽ₚ
https://github.com/fionn/lagrange-polynomial
cryptography lagrange-polynomial-interpolation numerical-methods
Last synced: 11 months ago
JSON representation
Numerical Lagrange polynomials over 𝔽ₚ
- Host: GitHub
- URL: https://github.com/fionn/lagrange-polynomial
- Owner: fionn
- Created: 2020-03-19T14:57:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-08T14:48:15.000Z (over 3 years ago)
- Last Synced: 2025-02-28T20:12:30.218Z (11 months ago)
- Topics: cryptography, lagrange-polynomial-interpolation, numerical-methods
- Language: Python
- Homepage: https://pypi.org/project/lagrange-polynomial/
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```python
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 _M_31.
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 _j_th basis vector _ℓⱼ_(_x_).
## Test
Test with `make test`.