package polynomial
import "github.com/cloudflare/circl/math/polynomial"
Package polynomial provides representations of polynomials over the scalars of a group.
Index ¶
- func LagrangeBase(jth uint, xi []group.Scalar, x group.Scalar) group.Scalar
- type LagrangePolynomial
- func NewLagrangePolynomial(x, y []group.Scalar) (l LagrangePolynomial)
- func (l LagrangePolynomial) Degree() int
- func (l LagrangePolynomial) Evaluate(x group.Scalar) group.Scalar
- type Polynomial
Functions ¶
func LagrangeBase ¶
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.
Types ¶
type LagrangePolynomial ¶
type LagrangePolynomial struct {
// contains filtered or unexported fields
}
LagrangePolynomial stores a Lagrange polynomial over the set of scalars of a group.
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 ¶
type Polynomial struct {
// contains filtered or unexported fields
}
Polynomial stores a polynomial over the set of scalars of a group.
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) Coefficient ¶
func (p Polynomial) Coefficient(n uint) group.Scalar
Coefficient returns a deep-copy of the n-th polynomial's coefficient. Note coefficients are sorted in ascending order with respect to the degree.
func (Polynomial) Degree ¶
func (p Polynomial) Degree() int
Degree returns the degree of the polynomial. The zero polynomial has degree equal to -1.
func (Polynomial) Evaluate ¶
func (p Polynomial) Evaluate(x group.Scalar) group.Scalar
Evaluate returns the evaluation of p on x.
Source Files ¶
- Version
- v1.6.1 (latest)
- Published
- Apr 9, 2025
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 2 days ago –
Tools for package owners.