poly

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package poly implements polynomial and its operations.

Index

Constants

View Source
const (
	// MinDegree is the minimum degree of polynomial that Evaluator can handle.
	// Currently, this is set to 2^4, because AVX2 implementation of FFT and inverse FFT
	// handles first/last two loops separately.
	MinDegree = 1 << 4

	// ShortLogBound is a maximum bound for the coefficients of "short" polynomials
	// used in [*Evaluator.ShortFourierPolyMulPoly] functions.
	// Currently, this is set to 8 bits.
	ShortLogBound = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluator

type Evaluator[T num.Integer] struct {
	// contains filtered or unexported fields
}

Evaluator computes polynomial operations over the N-th cyclotomic ring.

Operations usually take two forms: for example,

  • Op(p0, p1) adds p0, p1, allocates a new polynomial to store the result and returns it.
  • OpAssign(p0, p1, pOut) adds p0, p1 and writes the result to pre-allocated pOut without returning.

Note that in most cases, p0, p1, and fpOut can overlap. However, for operations that cannot, InPlace methods are implemented separately.

For performance reasons, most methods in this package don't implement bound checks. If length mismatch happens, it may panic or produce wrong results.

Evaluator is not safe for concurrent use. Use *Evaluator.ShallowCopy to get a safe copy.

func NewEvaluator

func NewEvaluator[T num.Integer](N int) *Evaluator[T]

NewEvaluator creates a new Evaluator with degree N.

Panics when N is not a power of two, or when N is smaller than MinDegree or larger than MaxDegree.

func (*Evaluator[T]) AddFourierPoly added in v0.4.0

func (e *Evaluator[T]) AddFourierPoly(fp0, fp1 FourierPoly) FourierPoly

AddFourierPoly returns fp0 + fp1.

func (*Evaluator[T]) AddFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) AddFourierPolyAssign(fp0, fp1, fpOut FourierPoly)

AddFourierPolyAssign computes fpOut = fp0 + fp1.

func (*Evaluator[T]) AddPoly added in v0.4.0

func (e *Evaluator[T]) AddPoly(p0, p1 Poly[T]) Poly[T]

AddPoly returns p0 + p1.

func (*Evaluator[T]) AddPolyAssign added in v0.4.0

func (e *Evaluator[T]) AddPolyAssign(p0, p1, pOut Poly[T])

AddPolyAssign computes pOut = p0 + p1.

func (*Evaluator[T]) CmplxMulAddFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) CmplxMulAddFourierPolyAssign(fp0 FourierPoly, c complex128, fpOut FourierPoly)

CmplxMulAddFourierPolyAssign computes fpOut += c * fp0.

func (*Evaluator[T]) CmplxMulFourierPoly added in v0.4.0

func (e *Evaluator[T]) CmplxMulFourierPoly(fp0 FourierPoly, c complex128) FourierPoly

CmplxMulFourierPoly returns c * fp0.

func (*Evaluator[T]) CmplxMulFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) CmplxMulFourierPolyAssign(fp0 FourierPoly, c complex128, fpOut FourierPoly)

CmplxMulFourierPolyAssign computes fpOut = c * fp0.

func (*Evaluator[T]) CmplxMulSubFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) CmplxMulSubFourierPolyAssign(fp0 FourierPoly, c complex128, fpOut FourierPoly)

CmplxMulSubFourierPolyAssign computes fpOut -= c * fp0.

func (*Evaluator[T]) Degree

func (e *Evaluator[T]) Degree() int

Degree returns the degree of polynomial that the evaluator can handle.

func (*Evaluator[T]) FloatMulAddFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) FloatMulAddFourierPolyAssign(fp0 FourierPoly, c float64, fpOut FourierPoly)

FloatMulAddFourierPolyAssign computes fpOut += c * fp0.

func (*Evaluator[T]) FloatMulFourierPoly added in v0.4.0

func (e *Evaluator[T]) FloatMulFourierPoly(fp0 FourierPoly, c float64) FourierPoly

FloatMulFourierPoly returns c * fp0.

func (*Evaluator[T]) FloatMulFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) FloatMulFourierPolyAssign(fp0 FourierPoly, c float64, fpOut FourierPoly)

FloatMulFourierPolyAssign computes fpOut = c * fp0.

func (*Evaluator[T]) FloatMulSubFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) FloatMulSubFourierPolyAssign(fp0 FourierPoly, c float64, fpOut FourierPoly)

FloatMulSubFourierPolyAssign computes fpOut -= c * fp0.

func (*Evaluator[T]) FourierPolyMulAddPolyAssign added in v0.4.0

func (e *Evaluator[T]) FourierPolyMulAddPolyAssign(p0 Poly[T], fp FourierPoly, pOut Poly[T])

FourierPolyMulAddPolyAssign computes pOut += p0 * fp.

func (*Evaluator[T]) FourierPolyMulPoly added in v0.4.0

func (e *Evaluator[T]) FourierPolyMulPoly(p0 Poly[T], fp FourierPoly) Poly[T]

FourierPolyMulPoly returns p0 * fp.

func (*Evaluator[T]) FourierPolyMulPolyAssign added in v0.4.0

func (e *Evaluator[T]) FourierPolyMulPolyAssign(p0 Poly[T], fp FourierPoly, pOut Poly[T])

FourierPolyMulPolyAssign computes pOut = p0 * fp.

func (*Evaluator[T]) FourierPolyMulSubPolyAssign added in v0.4.0

func (e *Evaluator[T]) FourierPolyMulSubPolyAssign(p0 Poly[T], fp FourierPoly, pOut Poly[T])

FourierPolyMulSubPolyAssign computes pOut -= p0 * fp.

func (*Evaluator[T]) MonomialMulAddPolyAssign added in v0.4.0

func (e *Evaluator[T]) MonomialMulAddPolyAssign(p0 Poly[T], d int, pOut Poly[T])

MonomialMulAddPolyAssign computes pOut += X^d * p0.

p0 and pOut should not overlap.

func (*Evaluator[T]) MonomialMulPoly added in v0.4.0

func (e *Evaluator[T]) MonomialMulPoly(p0 Poly[T], d int) Poly[T]

MonomialMulPoly returns X^d * p0.

func (*Evaluator[T]) MonomialMulPolyAssign added in v0.4.0

func (e *Evaluator[T]) MonomialMulPolyAssign(p0 Poly[T], d int, pOut Poly[T])

MonomialMulPolyAssign computes pOut = X^d * p0.

p0 and pOut should not overlap. For inplace multiplication, use *Evaluator.MonomialMulPolyInPlace.

func (*Evaluator[T]) MonomialMulPolyInPlace added in v0.4.0

func (e *Evaluator[T]) MonomialMulPolyInPlace(p0 Poly[T], d int)

MonomialMulPolyInPlace computes p0 = X^d * p0.

func (*Evaluator[T]) MonomialMulSubPolyAssign added in v0.4.0

func (e *Evaluator[T]) MonomialMulSubPolyAssign(p0 Poly[T], d int, pOut Poly[T])

MonomialMulSubPolyAssign computes pOut -= X^d * p0.

p0 and pOut should not overlap.

func (*Evaluator[T]) MonomialSubOneToFourierPoly added in v0.4.0

func (e *Evaluator[T]) MonomialSubOneToFourierPoly(d int) FourierPoly

MonomialSubOneToFourierPoly transforms X^d-1 to FourierPoly.

d should be positive.

func (*Evaluator[T]) MonomialSubOneToFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) MonomialSubOneToFourierPolyAssign(d int, fpOut FourierPoly)

MonomialSubOneToFourierPolyAssign transforms X^d-1 to FourierPoly and writes it to fpOut.

func (*Evaluator[T]) MonomialToFourierPoly added in v0.4.0

func (e *Evaluator[T]) MonomialToFourierPoly(d int) FourierPoly

MonomialToFourierPoly transforms X^d to FourierPoly.

func (*Evaluator[T]) MonomialToFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) MonomialToFourierPolyAssign(d int, fpOut FourierPoly)

MonomialToFourierPolyAssign transforms X^d to FourierPoly and writes it to fpOut.

func (*Evaluator[T]) MulAddFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) MulAddFourierPolyAssign(fp0, fp1, fpOut FourierPoly)

MulAddFourierPolyAssign computes fpOut += fp0 * fp1.

func (*Evaluator[T]) MulAddPolyAssign added in v0.4.0

func (e *Evaluator[T]) MulAddPolyAssign(p0, p1, pOut Poly[T])

MulAddPolyAssign computes pOut += p0 * p1.

func (*Evaluator[T]) MulFourierPoly added in v0.4.0

func (e *Evaluator[T]) MulFourierPoly(fp0, fp1 FourierPoly) FourierPoly

MulFourierPoly returns fp0 * fp1.

func (*Evaluator[T]) MulFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) MulFourierPolyAssign(fp0, fp1, fpOut FourierPoly)

MulFourierPolyAssign computes fpOut = fp0 * fp1.

func (*Evaluator[T]) MulPoly added in v0.4.0

func (e *Evaluator[T]) MulPoly(p0, p1 Poly[T]) Poly[T]

MulPoly returns p0 * p1.

func (*Evaluator[T]) MulPolyAssign added in v0.4.0

func (e *Evaluator[T]) MulPolyAssign(p0, p1, pOut Poly[T])

MulPolyAssign computes pOut = p0 * p1.

func (*Evaluator[T]) MulSubFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) MulSubFourierPolyAssign(fp0, fp1, fpOut FourierPoly)

MulSubFourierPolyAssign computes fpOut -= fp0 * fp1.

func (*Evaluator[T]) MulSubPolyAssign added in v0.4.0

func (e *Evaluator[T]) MulSubPolyAssign(p0, p1, pOut Poly[T])

MulSubPolyAssign computes pOut -= p0 * p1.

func (*Evaluator[T]) NegFourierPoly added in v0.4.0

func (e *Evaluator[T]) NegFourierPoly(fp0 FourierPoly) FourierPoly

NegFourierPoly returns -fp0.

func (*Evaluator[T]) NegFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) NegFourierPolyAssign(fp0, fpOut FourierPoly)

NegFourierPolyAssign computes fpOut = -fp0.

func (*Evaluator[T]) NegPoly added in v0.4.0

func (e *Evaluator[T]) NegPoly(p0 Poly[T]) Poly[T]

NegPoly returns pOut = -p0.

func (*Evaluator[T]) NegPolyAssign added in v0.4.0

func (e *Evaluator[T]) NegPolyAssign(p0, pOut Poly[T])

NegPolyAssign computes pOut = -p0.

func (*Evaluator[T]) NewFourierPoly added in v0.3.0

func (e *Evaluator[T]) NewFourierPoly() FourierPoly

NewFourierPoly creates a new fourier polynomial with the same degree as the evaluator.

func (*Evaluator[T]) NewPoly added in v0.1.3

func (e *Evaluator[T]) NewPoly() Poly[T]

NewPoly creates a new polynomial with the same degree as the evaluator.

func (*Evaluator[T]) PermuteAddFourierPolyAssign added in v0.5.0

func (e *Evaluator[T]) PermuteAddFourierPolyAssign(fp0 FourierPoly, d int, fpOut FourierPoly)

PermuteAddFourierPolyAssign computes fpOut += fp0(X^d).

fp0 and fpOut should not overlap.

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermuteAddPolyAssign added in v0.4.0

func (e *Evaluator[T]) PermuteAddPolyAssign(p0 Poly[T], d int, pOut Poly[T])

PermuteAddPolyAssign computes pOut += p0(X^d).

p0 and pOut should not overlap.

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermuteFourierPoly added in v0.5.0

func (e *Evaluator[T]) PermuteFourierPoly(fp0 FourierPoly, d int) FourierPoly

PermuteFourierPoly returns fp0(X^d).

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermuteFourierPolyAssign added in v0.5.0

func (e *Evaluator[T]) PermuteFourierPolyAssign(fp0 FourierPoly, d int, fpOut FourierPoly)

PermuteFourierPolyAssign computes fpOut = fp0(X^d).

fp0 and fpOut should not overlap. For inplace permutation, use *Evaluator.PermuteFourierPolyInPlace.

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermuteFourierPolyInPlace added in v0.5.0

func (e *Evaluator[T]) PermuteFourierPolyInPlace(fp0 FourierPoly, d int)

PermuteFourierPolyInPlace computes fp0 = fp0(X^d).

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermutePoly added in v0.4.0

func (e *Evaluator[T]) PermutePoly(p0 Poly[T], d int) Poly[T]

PermutePoly returns p0(X^d).

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermutePolyAssign added in v0.4.0

func (e *Evaluator[T]) PermutePolyAssign(p0 Poly[T], d int, pOut Poly[T])

PermutePolyAssign computes pOut = p0(X^d).

p0 and pOut should not overlap. For inplace permutation, use *Evaluator.PermutePolyInPlace.

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermutePolyInPlace added in v0.4.0

func (e *Evaluator[T]) PermutePolyInPlace(p0 Poly[T], d int)

PermutePolyInPlace computes p0 = p0(X^d).

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermuteSubFourierPolyAssign added in v0.5.0

func (e *Evaluator[T]) PermuteSubFourierPolyAssign(fp0 FourierPoly, d int, fpOut FourierPoly)

PermuteSubFourierPolyAssign computes fpOut -= fp0(X^d).

fp0 and fpOut should not overlap.

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PermuteSubPolyAssign added in v0.4.0

func (e *Evaluator[T]) PermuteSubPolyAssign(p0 Poly[T], d int, pOut Poly[T])

PermuteSubPolyAssign computes pOut -= p0(X^d).

p0 and pOut should not overlap.

Panics when d is not odd. This is because the permutation is not bijective when d is even.

func (*Evaluator[T]) PolyMulAddFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) PolyMulAddFourierPolyAssign(fp0 FourierPoly, p Poly[T], fpOut FourierPoly)

PolyMulAddFourierPolyAssign computes fpOut += p * fp0.

func (*Evaluator[T]) PolyMulFourierPoly added in v0.4.0

func (e *Evaluator[T]) PolyMulFourierPoly(fp0 FourierPoly, p Poly[T]) FourierPoly

PolyMulFourierPoly returns p * fp0 as FourierPoly.

func (*Evaluator[T]) PolyMulFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) PolyMulFourierPolyAssign(fp0 FourierPoly, p Poly[T], fpOut FourierPoly)

PolyMulFourierPolyAssign computes fpOut = p * fp0.

func (*Evaluator[T]) PolyMulSubFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) PolyMulSubFourierPolyAssign(fp0 FourierPoly, p Poly[T], fpOut FourierPoly)

PolyMulSubFourierPolyAssign computes fpOut -= p * fp0.

func (*Evaluator[T]) ScalarMulAddPolyAssign added in v0.4.0

func (e *Evaluator[T]) ScalarMulAddPolyAssign(p0 Poly[T], c T, pOut Poly[T])

ScalarMulAddPolyAssign computes pOut += c * p0.

func (*Evaluator[T]) ScalarMulPoly added in v0.4.0

func (e *Evaluator[T]) ScalarMulPoly(p0 Poly[T], c T) Poly[T]

ScalarMulPoly returns c * p0.

func (*Evaluator[T]) ScalarMulPolyAssign added in v0.4.0

func (e *Evaluator[T]) ScalarMulPolyAssign(p0 Poly[T], c T, pOut Poly[T])

ScalarMulPolyAssign computes pOut = c * p0.

func (*Evaluator[T]) ScalarMulSubPolyAssign added in v0.4.0

func (e *Evaluator[T]) ScalarMulSubPolyAssign(p0 Poly[T], c T, pOut Poly[T])

ScalarMulSubPolyAssign computes pOut -= c * p0.

func (*Evaluator[T]) ShallowCopy

func (e *Evaluator[T]) ShallowCopy() *Evaluator[T]

ShallowCopy returns a shallow copy of this Evaluator. Returned Evaluator is safe for concurrent use.

func (*Evaluator[T]) ShortFourierPolyMulAddPolyAssign added in v0.5.0

func (e *Evaluator[T]) ShortFourierPolyMulAddPolyAssign(p0 Poly[T], fpShort FourierPoly, pOut Poly[T])

ShortFourierPolyMulAddPolyAssign computes pOut += p0 * fpShort, under the assumption that fpShort is a short polynomial. (i.e., all coefficients are bounded by ShortLogBound bits.) This is faster than *Evaluator.MulAddPolyAssign, and the result is exact unlike *Evaluator.FourierPolyMulAddPolyAssign.

func (*Evaluator[T]) ShortFourierPolyMulPoly added in v0.5.0

func (e *Evaluator[T]) ShortFourierPolyMulPoly(p0 Poly[T], fpShort FourierPoly) Poly[T]

ShortFourierPolyMulPoly returns p0 * fpShort, under the assumption that fpShort is a short polynomial. (i.e., all coefficients are bounded by ShortLogBound bits.) This is faster than *Evaluator.MulPoly, and the result is exact unlike *Evaluator.FourierPolyMulPoly.

func (*Evaluator[T]) ShortFourierPolyMulPolyAssign added in v0.5.0

func (e *Evaluator[T]) ShortFourierPolyMulPolyAssign(p0 Poly[T], fpShort FourierPoly, pOut Poly[T])

ShortFourierPolyMulPolyAssign computes pOut = p0 * fpShort, under the assumption that fpShort is a short polynomial. (i.e., all coefficients are bounded by ShortLogBound bits.) This is faster than *Evaluator.MulPolyAssign, and the result is exact unlike *Evaluator.FourierPolyMulPolyAssign.

func (*Evaluator[T]) ShortFourierPolyMulSubPolyAssign added in v0.5.0

func (e *Evaluator[T]) ShortFourierPolyMulSubPolyAssign(p0 Poly[T], fpShort FourierPoly, pOut Poly[T])

ShortFourierPolyMulSubPolyAssign computes pOut -= p0 * fpShort, under the assumption that fpShort is a short polynomial. (i.e., all coefficients are bounded by ShortLogBound bits.) This is faster than *Evaluator.MulSubPolyAssign, and the result is exact unlike *Evaluator.FourierPolyMulSubPolyAssign.

func (*Evaluator[T]) SubFourierPoly added in v0.4.0

func (e *Evaluator[T]) SubFourierPoly(fp0, fp1 FourierPoly) FourierPoly

SubFourierPoly returns fp0 - fp1.

func (*Evaluator[T]) SubFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) SubFourierPolyAssign(fp0, fp1, fpOut FourierPoly)

SubFourierPolyAssign computes fpOut = fp0 - fp1.

func (*Evaluator[T]) SubPoly added in v0.4.0

func (e *Evaluator[T]) SubPoly(p0, p1 Poly[T]) Poly[T]

SubPoly returns p0 - p1.

func (*Evaluator[T]) SubPolyAssign added in v0.4.0

func (e *Evaluator[T]) SubPolyAssign(p0, p1, pOut Poly[T])

SubPolyAssign computes pOut = p0 - p1.

func (*Evaluator[T]) ToFourierPoly added in v0.4.0

func (e *Evaluator[T]) ToFourierPoly(p Poly[T]) FourierPoly

ToFourierPoly transforms Poly to FourierPoly.

func (*Evaluator[T]) ToFourierPolyAddAssign added in v0.4.0

func (e *Evaluator[T]) ToFourierPolyAddAssign(p Poly[T], fpOut FourierPoly)

ToFourierPolyAddAssign transforms Poly to FourierPoly and adds it to fpOut.

func (*Evaluator[T]) ToFourierPolyAssign added in v0.4.0

func (e *Evaluator[T]) ToFourierPolyAssign(p Poly[T], fpOut FourierPoly)

ToFourierPolyAssign transforms Poly to FourierPoly and writes it to fpOut.

func (*Evaluator[T]) ToFourierPolySubAssign added in v0.4.0

func (e *Evaluator[T]) ToFourierPolySubAssign(p Poly[T], fpOut FourierPoly)

ToFourierPolySubAssign transforms Poly to FourierPoly and subtracts it from fpOut.

func (*Evaluator[T]) ToPoly added in v0.4.0

func (e *Evaluator[T]) ToPoly(fp FourierPoly) Poly[T]

ToPoly transforms FourierPoly to Poly.

func (*Evaluator[T]) ToPolyAddAssign added in v0.4.0

func (e *Evaluator[T]) ToPolyAddAssign(fp FourierPoly, pOut Poly[T])

ToPolyAddAssign transforms FourierPoly to Poly and adds it to pOut.

func (*Evaluator[T]) ToPolyAddAssignUnsafe added in v0.4.0

func (e *Evaluator[T]) ToPolyAddAssignUnsafe(fp FourierPoly, pOut Poly[T])

ToPolyAddAssignUnsafe transforms FourierPoly to Poly and adds it to pOut.

This method is slightly faster than *Evaluator.ToPolyAddAssign, but it modifies fp directly. Use it only if you don't need fp after this method (e.g. fp is a buffer).

func (*Evaluator[T]) ToPolyAssign added in v0.4.0

func (e *Evaluator[T]) ToPolyAssign(fp FourierPoly, pOut Poly[T])

ToPolyAssign transforms FourierPoly to Poly and writes it to pOut.

func (*Evaluator[T]) ToPolyAssignUnsafe added in v0.4.0

func (e *Evaluator[T]) ToPolyAssignUnsafe(fp FourierPoly, pOut Poly[T])

ToPolyAssignUnsafe transforms FourierPoly to Poly and writes it to pOut.

This method is slightly faster than *Evaluator.ToPolyAssign, but it modifies fp directly. Use it only if you don't need fp after this method (e.g. fp is a buffer).

func (*Evaluator[T]) ToPolySubAssign added in v0.4.0

func (e *Evaluator[T]) ToPolySubAssign(fp FourierPoly, pOut Poly[T])

ToPolySubAssign transforms FourierPoly to Poly and subtracts it from pOut.

func (*Evaluator[T]) ToPolySubAssignUnsafe added in v0.4.0

func (e *Evaluator[T]) ToPolySubAssignUnsafe(fp FourierPoly, pOut Poly[T])

ToPolySubAssignUnsafe transforms FourierPoly to Poly and subtracts it from pOut.

This method is slightly faster than *Evaluator.ToPolySubAssign, but it modifies fp directly. Use it only if you don't need fp after this method (e.g. fp is a buffer).

type FourierPoly

type FourierPoly struct {
	// Coeffs is represented as float-4 complex vector
	// for efficient computation.
	//
	// Namely,
	//
	//	[(r0, i0), (r1, i1), (r2, i2), (r3, i3), ...]
	//
	// is represented as
	//
	//	[(r0, r1, r2, r3), (i0, i1, i2, i3), ...]
	//
	Coeffs []float64
}

FourierPoly is a fourier transformed polynomial over C[X]/(X^N/2 + 1). This corresponds to a polynomial over Z_Q[X]/(X^N + 1).

func NewFourierPoly

func NewFourierPoly(N int) FourierPoly

NewFourierPoly creates a fourier polynomial with degree N/2 with empty coefficients.

Panics when N is not a power of two, or when N is smaller than MinDegree.

func (FourierPoly) Approx added in v0.3.0

func (p FourierPoly) Approx(p0 FourierPoly, eps float64) bool

Approx checks if p0 is approximately equal with p, with a difference smaller than eps.

func (FourierPoly) Clear

func (p FourierPoly) Clear()

Clear clears all the coefficients to zero.

func (FourierPoly) Copy

func (p FourierPoly) Copy() FourierPoly

Copy returns a copy of the polynomial.

func (*FourierPoly) CopyFrom

func (p *FourierPoly) CopyFrom(p0 FourierPoly)

CopyFrom copies p0 to p.

func (FourierPoly) Degree

func (p FourierPoly) Degree() int

Degree returns the (doubled) degree of the polynomial.

func (FourierPoly) Equals

func (p FourierPoly) Equals(p0 FourierPoly) bool

Equals checks if p0 is equal with p. Note that due to floating point errors, this function may return false even if p0 and p are equal.

type Poly

type Poly[T num.Integer] struct {
	Coeffs []T
}

Poly is a polynomial over Z_Q[X]/(X^N + 1).

func From

func From[T num.Integer](coeffs []T, N int) Poly[T]

From creates a new polynomial from given coefficient slice. The given slice is copied, and extended to degree N.

func NewPoly added in v0.2.7

func NewPoly[T num.Integer](N int) Poly[T]

NewPoly creates a polynomial with degree N with empty coefficients.

Panics when N is not a power of two, or when N is smaller than MinDegree or larger than MaxDegree.

func (Poly[T]) Clear

func (p Poly[T]) Clear()

Clear clears all the coefficients to zero.

func (Poly[T]) Copy

func (p Poly[T]) Copy() Poly[T]

Copy returns a copy of the polynomial.

func (*Poly[T]) CopyFrom

func (p *Poly[T]) CopyFrom(p0 Poly[T])

CopyFrom copies p0 to p.

func (Poly[T]) Degree

func (p Poly[T]) Degree() int

Degree returns the degree of the polynomial. This is equivalent with length of coefficients.

func (Poly[T]) Equals

func (p Poly[T]) Equals(p0 Poly[T]) bool

Equals checks if p0 is equal with p.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL