...

Package polynomial

import "github.com/cloudflare/circl/math/polynomial"
Overview
Index

Overview ▾

Package polynomial provides representations of polynomials over the scalars of a group.

func LagrangeBase

func LagrangeBase(jth uint, xi []group.Scalar, x group.Scalar) group.Scalar

LagrangeBase returns the j-th Lagrange polynomial base evaluated at x. Thus, L_j(x) = \prod (x - x[i]) / (x[j] - x[i]) for 0 <= i < k, and i != j.

type LagrangePolynomial

LagrangePolynomial stores a Lagrange polynomial over the set of scalars of a group.

type LagrangePolynomial struct {
    // contains filtered or unexported fields
}

func NewLagrangePolynomial

func NewLagrangePolynomial(x, y []group.Scalar) (l LagrangePolynomial)

NewLagrangePolynomial creates a polynomial in Lagrange basis given a list of nodes (x) and values (y), such that:

p(x) = \sum_i^k y[i] L_j(x), where k is the degree of the polynomial,
L_j(x) = \prod_i^k (x-x[i])/(x[j]-x[i]),
y[i] = p(x[i]), and
all x[i] are different.

It panics if one of these conditions does not hold.

The zero polynomial has degree equal to -1 and can be instantiated passing (nil,nil) to NewLagrangePolynomial.

func (LagrangePolynomial) Degree

func (l LagrangePolynomial) Degree() int

func (LagrangePolynomial) Evaluate

func (l LagrangePolynomial) Evaluate(x group.Scalar) group.Scalar

type Polynomial

Polynomial stores a polynomial over the set of scalars of a group.

type Polynomial struct {
    // contains filtered or unexported fields
}

func New

func New(coeffs []group.Scalar) (p Polynomial)

New creates a new polynomial given its coefficients in ascending order. Thus,

p(x) = \sum_i^k c[i] x^i,

where k = len(c)-1 is the degree of the polynomial.

The zero polynomial has degree equal to -1 and can be instantiated passing nil to New.

func (Polynomial) Degree

func (p Polynomial) Degree() int

func (Polynomial) Evaluate

func (p Polynomial) Evaluate(x group.Scalar) group.Scalar