Poly

Struct Poly 

Source
pub struct Poly<K> { /* private fields */ }
Expand description

A polynomial, with coefficients in K.

Implementations§

Source§

impl<K> Poly<K>

Source

pub fn degree(&self) -> u32

The degree of this polynomial.

Technically, this is only an upper bound on the degree, because this method does not inspect the coefficients of a polynomial to check if they’re non-zero.

Because of this, it’s possible that two polynomials considered equal have different degrees.

For that behavior, see Self::degree_exact.

Source

pub fn required(&self) -> NonZeroU32

Return the number of evaluation points required to recover this polynomial.

In other words, Self::degree + 1.

Source

pub fn constant(&self) -> &K

Return the constant value of this polynomial.

I.e. the first coefficient.

Source

pub fn translate<L>(&self, f: impl Fn(&K) -> L) -> Poly<L>

Translate the coefficients of this polynomial.

This applies some kind of map to each coefficient, creating a new polynomial.

Source

pub fn eval<R>(&self, r: &R) -> K
where K: Space<R>,

Evaluate a polynomial at a particular point.

For

p(X) := a_0 + a_1 X + a_2 X^2 + ...

this returns:

a_0 + a_1 r + a_2 r^2 + ...

This can work for any type which can multiply the coefficients of this polynomial.

For example, if you have a polynomial consistent of elements of a group, you can evaluate it using a scalar over that group.

Source

pub fn eval_msm<R: Ring>(&self, r: &R) -> K
where K: Space<R>,

Like Self::eval, but using Space::msm.

This method uses more scratch space, and requires cloning values of type R more, but should be better if Space::msm has a better algorithm for K.

Source§

impl<K: Random> Poly<K>

Source

pub fn new(rng: impl CryptoRngCore, degree: u32) -> Self

Source

pub fn new_with_constant( rng: impl CryptoRngCore, degree: u32, constant: K, ) -> Self

Returns a new scalar polynomial with a particular value for the constant coefficient.

This does the same thing as Poly::new otherwise.

Source§

impl<K: Additive> Poly<K>

Source

pub fn degree_exact(&self) -> u32

Like Self::degree, but checking for zero coefficients.

This method is slower, but reports exact results in case there are zeros.

This will return 0 for a polynomial with no coefficients.

Source§

impl<G: CryptoGroup> Poly<G>

Source

pub fn commit(p: Poly<G::Scalar>) -> Self

Commit to a polynomial of scalars, producing a polynomial of group elements.

Trait Implementations§

Source§

impl<'a, K: Additive> Add<&'a Poly<K>> for Poly<K>

Source§

type Output = Poly<K>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a Poly<K>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, K: Additive> AddAssign<&'a Poly<K>> for Poly<K>

Source§

fn add_assign(&mut self, rhs: &'a Poly<K>)

Performs the += operation. Read more
Source§

impl<K: Additive> Additive for Poly<K>

Source§

fn zero() -> Self

The neutral element for addition.
Source§

fn double(&mut self)

Add an element to itself. Read more
Source§

fn scale(&self, bits_le: &[u64]) -> Self

Scale this number by a positive integer. Read more
Source§

impl<K: Clone> Clone for Poly<K>

Source§

fn clone(&self) -> Poly<K>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug> Debug for Poly<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: EncodeSize> EncodeSize for Poly<K>

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

impl<'a, R, K: Space<R>> Mul<&'a R> for Poly<K>

Source§

type Output = Poly<K>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'a R) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, R, K: Space<R>> MulAssign<&'a R> for Poly<K>

Source§

fn mul_assign(&mut self, rhs: &'a R)

Performs the *= operation. Read more
Source§

impl<K: Additive> Neg for Poly<K>

Source§

type Output = Poly<K>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<K: Additive> PartialEq for Poly<K>

An equality test taking into account high 0 coefficients.

Without this behavior, the additive test suite does not past, because x - x may result in a polynomial with extra 0 coefficients.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K: Read> Read for Poly<K>

Source§

type Cfg = (RangeCfg<NonZero<u32>>, <K as Read>::Cfg)

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings. Read more
Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl<R: Sync, K: Space<R>> Space<R> for Poly<K>

Available on crate feature std only.
Source§

fn msm(polys: &[Self], scalars: &[R], concurrency: usize) -> Self

Calculate sum_i points[i] * scalars[i]. Read more
Source§

impl<'a, K: Additive> Sub<&'a Poly<K>> for Poly<K>

Source§

type Output = Poly<K>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a Poly<K>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, K: Additive> SubAssign<&'a Poly<K>> for Poly<K>

Source§

fn sub_assign(&mut self, rhs: &'a Poly<K>)

Performs the -= operation. Read more
Source§

impl<K: Write> Write for Poly<K>

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

impl<K: Additive> Eq for Poly<K>

Source§

impl<K: Additive> Object for Poly<K>

Auto Trait Implementations§

§

impl<K> Freeze for Poly<K>

§

impl<K> RefUnwindSafe for Poly<K>
where K: RefUnwindSafe,

§

impl<K> Send for Poly<K>
where K: Send,

§

impl<K> Sync for Poly<K>
where K: Sync,

§

impl<K> Unpin for Poly<K>
where K: Unpin,

§

impl<K> UnwindSafe for Poly<K>
where K: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Codec for T
where T: Encode + Decode,