pub struct RnsPoly {
pub components: Vec<Poly64>,
pub level: usize,
}Expand description
Polynomial in RNS representation: one component per modulus.
Each component components[i] is a polynomial in Z_{q_i}[X]/(X^N+1),
stored in NTT domain by default for performance.
The level indicates the number of active moduli. CKKS rescaling reduces
the level by removing the last modulus.
Fields§
§components: Vec<Poly64>components[i] = polynomial modulo moduli[i].
level: usizeCurrent level (number of active moduli).
Implementations§
Source§impl RnsPoly
impl RnsPoly
Sourcepub fn from_coefficients(coeffs: &[i64], ctx: &RnsContext) -> Self
pub fn from_coefficients(coeffs: &[i64], ctx: &RnsContext) -> Self
Encodes a signed-integer polynomial into RNS representation.
For each modulus q_i:
- Reduces each coefficient mod q_i (handles negatives)
- Converts to NTT domain
§Arguments
coeffs— polynomial coefficients in Z (signed, coefficient domain)ctx— RNS context
Sourcepub fn add(&self, other: &RnsPoly, ctx: &RnsContext) -> RnsPoly
pub fn add(&self, other: &RnsPoly, ctx: &RnsContext) -> RnsPoly
Component-wise addition in RNS.
Both polynomials must have the same level.
Sourcepub fn sub(&self, other: &RnsPoly, ctx: &RnsContext) -> RnsPoly
pub fn sub(&self, other: &RnsPoly, ctx: &RnsContext) -> RnsPoly
Component-wise subtraction in RNS.
Sourcepub fn mul(&self, other: &RnsPoly, ctx: &RnsContext) -> RnsPoly
pub fn mul(&self, other: &RnsPoly, ctx: &RnsContext) -> RnsPoly
Component-wise multiplication in RNS (NTT domain).
All components must be in NTT domain.
Sourcepub fn drop_last_modulus(&mut self)
pub fn drop_last_modulus(&mut self)
Drops the last modulus (CKKS rescaling).
After this operation, the level decreases by 1 and the last component is removed. The scale factor Δ is implicitly divided by q_L.
§Panics
Panics if the level is already 1.
Sourcepub fn forward_all(&mut self, ctx: &RnsContext)
pub fn forward_all(&mut self, ctx: &RnsContext)
Converts all components from NTT domain to coefficient domain.
Sourcepub fn inverse_all(&mut self, ctx: &RnsContext)
pub fn inverse_all(&mut self, ctx: &RnsContext)
Converts all components from NTT domain to coefficient domain.