Skip to main content

Poly64

Struct Poly64 

Source
pub struct Poly64 {
    pub data: Vec<u64>,
    pub is_ntt: bool,
}
Expand description

Polynomial in R_q = Z_q[X]/(X^N + 1) with 64-bit coefficients.

Tracks whether the data is in coefficient domain or NTT (evaluation) domain. In NTT domain, multiplication is pointwise (O(N) instead of O(N²)).

Fields§

§data: Vec<u64>

Coefficients (coefficient domain) or evaluations (NTT domain).

§is_ntt: bool

true if the polynomial is in NTT (evaluation) domain.

Implementations§

Source§

impl Poly64

Source

pub fn new_zero(n: usize) -> Self

Creates the zero polynomial with N coefficients.

Source

pub fn forward_ntt(&mut self, ntt_ctx: &Ntt64Context)

Converts from coefficient domain to NTT domain (in-place).

§Panics

Panics if the polynomial is already in NTT domain.

Source

pub fn inverse_ntt(&mut self, ntt_ctx: &Ntt64Context)

Converts from NTT domain to coefficient domain (in-place).

§Panics

Panics if the polynomial is not in NTT domain.

Source

pub fn add_assign(&mut self, other: &Poly64, arith: &Ntt64Arith)

Pointwise addition: self += other (mod q).

Both polynomials must be in the same domain (NTT or coefficient).

§Panics

Panics if domains or sizes don’t match.

Source

pub fn sub_assign(&mut self, other: &Poly64, arith: &Ntt64Arith)

Pointwise subtraction: self -= other (mod q).

Both polynomials must be in the same domain.

§Panics

Panics if domains or sizes don’t match.

Source

pub fn mul_assign(&mut self, other: &Poly64, arith: &Ntt64Arith)

Pointwise multiplication: self *= other (mod q).

Both polynomials must be in NTT domain so that pointwise multiplication corresponds to negacyclic convolution in coefficient domain.

§Panics

Panics if polynomials are not in NTT domain or have different sizes.

Source

pub fn scalar_mul(&mut self, scalar: u64, arith: &Ntt64Arith)

Scalar multiplication: self *= scalar (mod q).

Source

pub fn negate(&mut self, arith: &Ntt64Arith)

Negation: self = −self (mod q), i.e. self[i] = q − self[i].

Source

pub fn len(&self) -> usize

Number of coefficients (= max degree + 1).

Source

pub fn is_empty(&self) -> bool

Whether the polynomial has zero length.

Trait Implementations§

Source§

impl Clone for Poly64

Source§

fn clone(&self) -> Poly64

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Poly64

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.