Package Exports
- lagrange
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lagrange) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-lagrange
Implements Lagrange polynomial interpolation for both the numbers you are used to as well as finite fields. Given a list of x values and a list of y values, it will attempt to solve f(x) for a given x value.
All finite field arithmetic uses the
galois NPM module (npm show galois).
Functions
base10(x, xValues, yValues)- Assumes the standard decimal system.galois(x, xValues, yValues, gfW)- ThegfWparameter is passed to thegaloismodule functions, which uses it as the exponent to define the field size (2^w).splitCoords(coords)- The above math functions take two separate arrays, one for x values and one for y values, but your application is likely to use an array of tuples to define coordinates. This utility function splits them out, giving you a tuple of x and y values ([xValues, yValues]).
Examples
See ./tests/lagrange.js for examples using different equations.
var lagrange = require('lagrange');
var GF_W = 8;
//f(x)=2x, for GF(256)
var coords = [[5, 10], [244, 245]]; //app stores tuples
coords = lagrange.splitCoords(coords); //make them lagrange friendly
assert.equal(lagrange.galois(0, coords[0], coords[1], GF_W), 0);
assert.equal(lagrange.galois(255, coords[0], coords[1], GF_W), 227);
console.log('success');