pub struct PolynomialRingZq { /* private fields */ }Expand description
PolynomialRingZq represents polynomials over the finite field
PolyOverZq/f(X) where f(X) is a polynomial over Zq.
Attributes
poly: holds the valuemodulus: holds the modulus q and f(X)
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let poly_mod = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
let modulus = ModulusPolynomialRingZq::from(poly_mod);
// instantiation
let a = PolynomialRingZq::from((PolyOverZ::from(5), &modulus));
let b = PolynomialRingZq::from((PolyOverZ::from_str("2 1 5").unwrap(), &modulus));
let _ = a.clone();
// arithmetics
let _ = &a + &b;
let _ = &a * &b;
// to_string incl. (de-)serialization
assert_eq!("1 5 / 3 1 0 1 mod 17", &a.to_string());
let _ = serde_json::to_string(&a).unwrap();
Implementations§
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn add_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
pub fn add_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
Implements addition for two PolynomialRingZq values.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a PolynomialRingZq or an error if the moduli
mismatch.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));
let c: PolynomialRingZq = a.add_safe(&b).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothPolynomialRingZqmismatch.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn mul_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
pub fn mul_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
Implements multiplication for two PolynomialRingZq values.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials as a PolynomialRingZq or an error if the moduli
mismatch.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));
let c: PolynomialRingZq = a.mul_safe(&b).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothPolynomialRingZqmismatch.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn mul_scalar_zq_safe(&self, scalar: &Zq) -> Result<Self, MathError>
pub fn mul_scalar_zq_safe(&self, scalar: &Zq) -> Result<Self, MathError>
Implements multiplication for a PolynomialRingZq with a Zq.
Parameters:
scalar: Specifies the scalar by which the polynomial is multiplied.
Returns the product of self and scalar as a PolynomialRingZq
or an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;
let poly_1 = PolynomialRingZq::from_str("3 1 2 3 / 4 1 2 3 4 mod 17").unwrap();
let integer = Zq::from((3,17));
let poly_2 = poly_1.mul_scalar_zq_safe(&integer).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli mismatch.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn sub_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
pub fn sub_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
Implements subtraction for two PolynomialRingZq values.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the result of subtraction of both polynomials as a
PolynomialRingZq or an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));
let c: PolynomialRingZq = a.sub_safe(&b).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothPolynomialRingZqmismatch.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn get_mod(&self) -> ModulusPolynomialRingZq
pub fn get_mod(&self) -> ModulusPolynomialRingZq
Returns the modulus object of the PolynomialRingZq element.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_mod = poly_ring.get_mod();
assert_eq!(modulus, poly_ring_mod);Sourcepub fn get_representative_least_nonnegative_residue(&self) -> PolyOverZ
pub fn get_representative_least_nonnegative_residue(&self) -> PolyOverZ
Returns a representative polynomial of the PolynomialRingZq element.
The representation of the coefficients is in the range [0, modulus) and
the representation of the polynomial is in the range [0, modulus_polynomial).
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let poly_z = poly_ring.get_representative_least_nonnegative_residue();
let cmp_poly = PolyOverZ::from_str("3 15 0 1").unwrap();
assert_eq!(cmp_poly, poly_z);Sourcepub fn get_degree(&self) -> i64
pub fn get_degree(&self) -> i64
Returns the degree of a PolynomialRingZq as a i64.
The zero polynomial has degree -1.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let degree = poly_ring.get_degree();
assert_eq!(2, degree);Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn norm_eucl_sqrd(&self) -> Z
pub fn norm_eucl_sqrd(&self) -> Z
Returns the squared Euclidean norm or squared 2-norm of the given polynomial. The squared Euclidean norm for a polynomial is obtained by treating the coefficients of the polynomial as a vector and then applying the standard squared Euclidean norm.
Each length of an entry in this vector is defined as the shortest distance to the next zero representative modulo q.
§Examples
use qfall_math::{integer::Z, integer_mod_q::PolynomialRingZq};
use std::str::FromStr;
let poly = PolynomialRingZq::from_str("3 1 2 3 / 4 1 2 3 4 mod 11").unwrap();
let sqrd_2_norm = poly.norm_eucl_sqrd();
// 1*1 + 2*2 + 3*3 = 14
assert_eq!(Z::from(14), sqrd_2_norm);Sourcepub fn norm_infty(&self) -> Z
pub fn norm_infty(&self) -> Z
Returns the infinity norm or the maximal absolute value of a coefficient of the given polynomial. The infinity norm for a polynomial is obtained by treating the coefficients of the polynomial as a vector and then applying the standard infinity norm.
Each length of an entry in this vector is defined as the shortest distance to the next zero representative modulo q.
§Examples
use qfall_math::{integer::Z, integer_mod_q::PolynomialRingZq};
use std::str::FromStr;
let poly = PolynomialRingZq::from_str("3 1 2 4 / 4 1 2 3 4 mod 7").unwrap();
let infty_norm = poly.norm_infty();
// max coefficient is 4 = -3
assert_eq!(Z::from(3), infty_norm);Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn is_irreducible(&self) -> bool
pub fn is_irreducible(&self) -> bool
Checks if a PolynomialRingZq is irreducible.
Returns true if the polynomial is irreducible and false otherwise.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let poly_irr = PolynomialRingZq::from_str("2 1 1 / 3 1 2 3 mod 17").unwrap();
// returns true, since X + 1 is irreducible
assert!(poly_irr.is_irreducible());Sourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
Checks if a PolynomialRingZq is the constant polynomial with coefficient 1.
Returns true if there is only one coefficient, which is 1.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let value = PolynomialRingZq::from_str("1 1 / 3 1 0 1 mod 4").unwrap();
assert!(value.is_one());Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Checks if every entry of a PolynomialRingZq is 0.
Returns true if PolynomialRingZq has no coefficients.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let value = PolynomialRingZq::from_str("0 / 2 1 1 mod 7").unwrap();
assert!(value.is_zero());Sourcepub fn ntt(&self) -> NTTPolynomialRingZq
pub fn ntt(&self) -> NTTPolynomialRingZq
Computes the NTT representation of self.
§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use crate::qfall_math::traits::SetCoefficient;
use std::str::FromStr;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let poly_ring = PolynomialRingZq::sample_uniform(&polynomial_modulus);
let ntt_poly_ring = poly_ring.ntt();§Panics …
- if the
NTTBasisPolynomialRingZq, which is part of theModulusPolynomialRingZqinselfis not set.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn sample_binomial(
modulus: &ModulusPolynomialRingZq,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial( modulus: &ModulusPolynomialRingZq, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Generates a PolynomialRingZq instance of maximum degree modulus.get_degree() - 1 and
coefficients chosen according to the binomial distribution
parameterized by n and p.
Parameters:
modulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is definedn: specifies the number of trialsp: specifies the probability of success
Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1
with coefficients chosen according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), n does not fit into an i64.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 2 3 mod 17").unwrap();
let sample = PolynomialRingZq::sample_binomial(&modulus, 2, 0.5).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifn < 0. - Returns a
MathErrorof typeInvalidIntervalifp ∉ (0,1). - Returns a
MathErrorof typeConversionErrorifndoes not fit into ani64.
§Panics …
- if the provided
ModulusPolynomialRingZqhas degree0or smaller.
Sourcepub fn sample_binomial_with_offset(
modulus: &ModulusPolynomialRingZq,
offset: impl Into<Z>,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial_with_offset( modulus: &ModulusPolynomialRingZq, offset: impl Into<Z>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Generates a PolynomialRingZq instance of maximum degree modulus.get_degree() - 1 and
coefficients chosen according to the binomial distribution
parameterized by n and p with given offset.
Parameters:
modulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is definedoffset: specifies an offset applied to each sample collected from the binomial distributionn: specifies the number of trialsp: specifies the probability of success
Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1
with coefficients chosen according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), n does not fit into an i64.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 2 3 mod 17").unwrap();
let sample = PolynomialRingZq::sample_binomial_with_offset(&modulus, -1, 2, 0.5).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifn < 0. - Returns a
MathErrorof typeInvalidIntervalifp ∉ (0,1). - Returns a
MathErrorof typeConversionErrorifndoes not fit into ani64.
§Panics …
- if the provided
ModulusPolynomialRingZqhas degree0or smaller.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn sample_discrete_gauss(
modulus: impl Into<ModulusPolynomialRingZq>,
center: impl Into<Q>,
s: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_discrete_gauss( modulus: impl Into<ModulusPolynomialRingZq>, center: impl Into<Q>, s: impl Into<Q>, ) -> Result<Self, MathError>
Initializes a new PolynomialRingZq with maximum degree modulus.get_degree() - 1
and with each entry sampled independently according to the
discrete Gaussian distribution.
Parameters:
modulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is definedcenter: specifies the positions of the center with peak probabilitys: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = s
Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1
with coefficients chosen independently according the discrete Gaussian distribution or
a MathError if s < 0.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 2 3 mod 17").unwrap();
let sample = PolynomialRingZq::sample_discrete_gauss(&modulus, 0, 1).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifs < 0.
§Panics …
- if the provided
ModulusPolynomialRingZqhas degree0or smaller.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub fn sample_uniform(modulus: impl Into<ModulusPolynomialRingZq>) -> Self
pub fn sample_uniform(modulus: impl Into<ModulusPolynomialRingZq>) -> Self
Generates a PolynomialRingZq instance with maximum degree modulus.get_degree() - 1
and coefficients chosen uniform at random in [0, modulus.get_q()).
The internally used uniform at random chosen bytes are generated
by ThreadRng, which uses ChaCha12 and
is considered cryptographically secure.
Parameters:
modulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is defined
Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1
with coefficients chosen uniform at random in [0, modulus.get_q()).
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 2 3 mod 17").unwrap();
let sample = PolynomialRingZq::sample_uniform(&modulus);§Panics …
- if the provided
ModulusPolynomialRingZqhas degree0or smaller.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub unsafe fn get_fmpz_poly_struct(&mut self) -> &mut fmpz_poly_struct
pub unsafe fn get_fmpz_poly_struct(&mut self) -> &mut fmpz_poly_struct
Returns a mutable reference to the underlying fmpz_poly_struct by calling get_fmpz_poly_struct on poly.
WARNING: The returned struct is part of flint_sys.
Any changes to this object are unsafe and may introduce memory leaks.
In case you are calling this function to a modulus struct,
please be aware that most moduli are shared across multiple instances and all
modifications of this struct will affect any other instance with a reference to this object.
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub unsafe fn get_fq_ctx_struct(&mut self) -> &mut fq_ctx_struct
pub unsafe fn get_fq_ctx_struct(&mut self) -> &mut fq_ctx_struct
Returns a mutable reference to the underlying fq_ctx_struct by calling get_fq_ctx_struct on modulus.
WARNING: The returned struct is part of flint_sys.
Any changes to this object are unsafe and may introduce memory leaks.
In case you are calling this function to a modulus struct,
please be aware that most moduli are shared across multiple instances and all
modifications of this struct will affect any other instance with a reference to this object.
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub unsafe fn set_fmpz_poly_struct(&mut self, flint_struct: fmpz_poly_struct)
pub unsafe fn set_fmpz_poly_struct(&mut self, flint_struct: fmpz_poly_struct)
Sets the field fmpz_poly_struct to flint_struct by calling set_fmpz_poly_struct on poly.
Parameters:
flint_struct: value to set the attribute to
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Ensure that the old struct does not share any memory with any other structs that might be used in the future. The memory of the old struct is freed using this function.
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Source§impl PolynomialRingZq
impl PolynomialRingZq
Sourcepub unsafe fn set_fq_ctx_struct(&mut self, flint_struct: fq_ctx_struct)
pub unsafe fn set_fq_ctx_struct(&mut self, flint_struct: fq_ctx_struct)
Sets the field fq_ctx_struct to flint_struct by calling set_fq_ctx_struct on modulus.
Parameters:
flint_struct: value to set the attribute to
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Ensure that the old struct does not share any memory with any other structs that might be used in the future. The memory of the old struct is freed using this function.
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Trait Implementations§
Source§impl Add<&PolyOverZ> for &PolynomialRingZq
impl Add<&PolyOverZ> for &PolynomialRingZq
Source§fn add(self, other: &PolyOverZ) -> Self::Output
fn add(self, other: &PolyOverZ) -> Self::Output
Implements the Add trait for PolynomialRingZq and PolyOverZ.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to add toself
Returns the addition of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolynomialRingZq = &a + &b;Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
+ operator.Source§impl Add<&PolyOverZq> for &PolynomialRingZq
impl Add<&PolyOverZq> for &PolynomialRingZq
Source§fn add(self, other: &PolyOverZq) -> Self::Output
fn add(self, other: &PolyOverZq) -> Self::Output
Implements the Add trait for PolynomialRingZq and PolyOverZq.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to add toself
Returns the addition of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, PolynomialRingZq};
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZq::from_str("4 2 0 3 1 mod 17").unwrap();
let c: PolynomialRingZq = &a + &b;§Panics …
- if the moduli mismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
+ operator.Source§impl Add for &PolynomialRingZq
impl Add for &PolynomialRingZq
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Implements the Add trait for two PolynomialRingZq values.
Add is implemented for any combination of PolynomialRingZq and borrowed PolynomialRingZq.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));
let c: PolynomialRingZq = &a + &b;
let d: PolynomialRingZq = a + b;
let e: PolynomialRingZq = &c + d;
let f: PolynomialRingZq = c + &e;§Panics …
- if the moduli of both
PolynomialRingZqmismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
+ operator.Source§impl AddAssign<&PolyOverZ> for PolynomialRingZq
impl AddAssign<&PolyOverZ> for PolynomialRingZq
Source§fn add_assign(&mut self, other: &PolyOverZ)
fn add_assign(&mut self, other: &PolyOverZ)
Documentation at PolynomialRingZq::add_assign.
Source§impl AddAssign<&PolyOverZq> for PolynomialRingZq
impl AddAssign<&PolyOverZq> for PolynomialRingZq
Source§fn add_assign(&mut self, other: &PolyOverZq)
fn add_assign(&mut self, other: &PolyOverZq)
Source§impl AddAssign<&PolynomialRingZq> for PolynomialRingZq
impl AddAssign<&PolynomialRingZq> for PolynomialRingZq
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
Computes the addition of self and other reusing
the memory of self.
AddAssign can be used on PolynomialRingZq in combination with
PolynomialRingZq, PolyOverZ and PolyOverZq.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials modulo Z_q[X] as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let mut a = PolynomialRingZq::from((&poly_1, &modulus));
let c = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&c, &modulus));
let d = PolyOverZq::from((&c, 17));
a += &b;
a += b;
a += &c;
a += c;
a += &d;
a += d;§Panics …
- if the moduli of both
PolynomialRingZqmismatch.
Source§impl AddAssign<PolyOverZ> for PolynomialRingZq
impl AddAssign<PolyOverZ> for PolynomialRingZq
Source§fn add_assign(&mut self, other: PolyOverZ)
fn add_assign(&mut self, other: PolyOverZ)
Documentation at PolynomialRingZq::add_assign.
Source§impl AddAssign<PolyOverZq> for PolynomialRingZq
impl AddAssign<PolyOverZq> for PolynomialRingZq
Source§fn add_assign(&mut self, other: PolyOverZq)
fn add_assign(&mut self, other: PolyOverZq)
Documentation at PolynomialRingZq::add_assign.
Source§impl AddAssign for PolynomialRingZq
impl AddAssign for PolynomialRingZq
Source§fn add_assign(&mut self, other: PolynomialRingZq)
fn add_assign(&mut self, other: PolynomialRingZq)
Documentation at PolynomialRingZq::add_assign.
Source§impl Clone for PolynomialRingZq
impl Clone for PolynomialRingZq
Source§fn clone(&self) -> PolynomialRingZq
fn clone(&self) -> PolynomialRingZq
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CompareBase<&PolyOverZ> for PolynomialRingZq
impl CompareBase<&PolyOverZ> for PolynomialRingZq
Source§impl CompareBase<&PolyOverZq> for PolynomialRingZq
impl CompareBase<&PolyOverZq> for PolynomialRingZq
Source§fn compare_base(&self, other: &&PolyOverZq) -> bool
fn compare_base(&self, other: &&PolyOverZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&PolyOverZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&PolyOverZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&PolynomialRingZq> for MatNTTPolynomialRingZq
impl CompareBase<&PolynomialRingZq> for MatNTTPolynomialRingZq
Source§fn compare_base(&self, other: &&PolynomialRingZq) -> bool
fn compare_base(&self, other: &&PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &&PolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&PolynomialRingZq> for MatPolynomialRingZq
impl CompareBase<&PolynomialRingZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &&PolynomialRingZq) -> bool
fn compare_base(&self, other: &&PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &&PolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&PolynomialRingZq> for NTTPolynomialRingZq
impl CompareBase<&PolynomialRingZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &&PolynomialRingZq) -> bool
fn compare_base(&self, other: &&PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &&PolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&PolynomialRingZq> for PolynomialRingZq
impl CompareBase<&PolynomialRingZq> for PolynomialRingZq
Source§fn compare_base(&self, other: &&PolynomialRingZq) -> bool
fn compare_base(&self, other: &&PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &&PolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for PolynomialRingZq
impl CompareBase<&Zq> for PolynomialRingZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl<Integer: Into<Z>> CompareBase<Integer> for PolynomialRingZq
impl<Integer: Into<Z>> CompareBase<Integer> for PolynomialRingZq
Source§impl CompareBase<PolyOverZ> for PolynomialRingZq
impl CompareBase<PolyOverZ> for PolynomialRingZq
Source§impl CompareBase<PolyOverZq> for PolynomialRingZq
impl CompareBase<PolyOverZq> for PolynomialRingZq
Source§fn compare_base(&self, other: &PolyOverZq) -> bool
fn compare_base(&self, other: &PolyOverZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolyOverZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolyOverZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<PolynomialRingZq> for MatNTTPolynomialRingZq
impl CompareBase<PolynomialRingZq> for MatNTTPolynomialRingZq
Source§fn compare_base(&self, other: &PolynomialRingZq) -> bool
fn compare_base(&self, other: &PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<PolynomialRingZq> for MatPolynomialRingZq
impl CompareBase<PolynomialRingZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &PolynomialRingZq) -> bool
fn compare_base(&self, other: &PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<PolynomialRingZq> for NTTPolynomialRingZq
impl CompareBase<PolynomialRingZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &PolynomialRingZq) -> bool
fn compare_base(&self, other: &PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for PolynomialRingZq
impl CompareBase<Zq> for PolynomialRingZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase for PolynomialRingZq
impl CompareBase for PolynomialRingZq
Source§fn compare_base(&self, other: &PolynomialRingZq) -> bool
fn compare_base(&self, other: &PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl Debug for PolynomialRingZq
impl Debug for PolynomialRingZq
Source§impl<'de> Deserialize<'de> for PolynomialRingZq
impl<'de> Deserialize<'de> for PolynomialRingZq
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for PolynomialRingZq
impl Display for PolynomialRingZq
Source§impl From<&ModulusPolynomialRingZq> for PolynomialRingZq
impl From<&ModulusPolynomialRingZq> for PolynomialRingZq
Source§fn from(modulus: &ModulusPolynomialRingZq) -> Self
fn from(modulus: &ModulusPolynomialRingZq) -> Self
Creates a zero polynomial with a given ModulusPolynomialRingZq.
Parameters:
modulus: the modulus that is applied to the polynomial ring element.
Returns a new constant PolynomialRingZq with the specified ModulusPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from((poly, &modulus));§Panics …
- if the moduli mismatch.
Source§impl From<&PolynomialRingZq> for NTTPolynomialRingZq
impl From<&PolynomialRingZq> for NTTPolynomialRingZq
Source§fn from(poly: &PolynomialRingZq) -> Self
fn from(poly: &PolynomialRingZq) -> Self
Computes the NTT representation of poly.
Parameters:
poly: the polynomial that’s going to be represented in NTT form.
Returns the NTT representation as a NTTPolynomialRingZq of poly.
§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use crate::qfall_math::traits::SetCoefficient;
use std::str::FromStr;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let poly_ring = PolynomialRingZq::sample_uniform(&polynomial_modulus);
let ntt_poly_ring = NTTPolynomialRingZq::from(&poly_ring);§Panics …
- if the
NTTBasisPolynomialRingZq, which is part of theModulusPolynomialRingZqinpolyis not set.
Source§impl From<&PolynomialRingZq> for String
impl From<&PolynomialRingZq> for String
Source§fn from(value: &PolynomialRingZq) -> Self
fn from(value: &PolynomialRingZq) -> Self
Converts a PolynomialRingZq into its String representation.
Parameters:
value: specifies the polynomial that will be represented as aString
Returns a String of the form "[#number of coefficients of element]⌴⌴[0th coefficient]⌴ [1st coefficient]⌴...⌴/⌴[#number of coefficients of polynomial modulus]⌴⌴ [0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[q]".
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let poly = PolynomialRingZq::from_str("2 2 1 / 3 2 2 2 mod 3").unwrap();
let string: String = poly.into();Source§impl<Mod: Into<ModulusPolynomialRingZq>> From<(&PolyOverZq, Mod)> for PolynomialRingZq
impl<Mod: Into<ModulusPolynomialRingZq>> From<(&PolyOverZq, Mod)> for PolynomialRingZq
Source§fn from((poly, modulus): (&PolyOverZq, Mod)) -> Self
fn from((poly, modulus): (&PolyOverZq, Mod)) -> Self
Creates a new polynomial ring element of type PolynomialRingZq.
Parameters:
poly: the coefficients of the polynomial.modulus: the modulus that is applied to the polynomial ring element.
Returns a new element inside the polynomial ring, if the moduli of the polynomial and the modulus match.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));§Panics …
- if the moduli mismatch.
Source§impl<Poly: Into<PolyOverZ>, Mod: Into<ModulusPolynomialRingZq>> From<(Poly, Mod)> for PolynomialRingZq
impl<Poly: Into<PolyOverZ>, Mod: Into<ModulusPolynomialRingZq>> From<(Poly, Mod)> for PolynomialRingZq
Source§fn from((poly, modulus): (Poly, Mod)) -> Self
fn from((poly, modulus): (Poly, Mod)) -> Self
Creates a new polynomial ring element of type PolynomialRingZq.
Parameters:
poly: the coefficients of the polynomial.modulus: the modulus that is applied to the polynomial ring element.
Returns a new element inside the polynomial ring.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));Source§impl<Mod: Into<ModulusPolynomialRingZq>> From<(PolyOverZq, Mod)> for PolynomialRingZq
impl<Mod: Into<ModulusPolynomialRingZq>> From<(PolyOverZq, Mod)> for PolynomialRingZq
Source§fn from((poly, modulus): (PolyOverZq, Mod)) -> Self
fn from((poly, modulus): (PolyOverZq, Mod)) -> Self
Creates a new polynomial ring element of type PolynomialRingZq.
Parameters:
poly: the coefficients of the polynomial.modulus: the modulus that is applied to the polynomial ring element.
Returns a new element inside the polynomial ring, if the moduli of the polynomial and the modulus match.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from((poly, &modulus));§Panics …
- if the moduli mismatch.
Source§impl From<ModulusPolynomialRingZq> for PolynomialRingZq
impl From<ModulusPolynomialRingZq> for PolynomialRingZq
Source§fn from(value: ModulusPolynomialRingZq) -> Self
fn from(value: ModulusPolynomialRingZq) -> Self
Documentation can be found at PolynomialRingZq::from for &ModulusPolynomialRingZq.
Source§impl From<NTTPolynomialRingZq> for PolynomialRingZq
impl From<NTTPolynomialRingZq> for PolynomialRingZq
Source§fn from(ntt: NTTPolynomialRingZq) -> Self
fn from(ntt: NTTPolynomialRingZq) -> Self
Creates a polynomial from NTTPolynomialRingZq generated with respect to the
NTTBasisPolynomialRingZq as part of
ModulusPolynomialRingZq.
Parameters:
ntt: the NTT representation of the polynomial.modulus: the modulus that is applied to the polynomial ring element.
Returns a new PolynomialRingZq with the specified ModulusPolynomialRingZq and
values as defined in ntt.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, PolyOverZq, ModulusPolynomialRingZq, NTTPolynomialRingZq};
use qfall_math::traits::SetCoefficient;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let ntt = NTTPolynomialRingZq::sample_uniform(&polynomial_modulus);
let res = PolynomialRingZq::from(ntt);§Panics …
- if the
NTTBasisPolynomialRingZqinmodulusis not set.
Source§impl From<PolynomialRingZq> for String
impl From<PolynomialRingZq> for String
Source§fn from(value: PolynomialRingZq) -> Self
fn from(value: PolynomialRingZq) -> Self
Documentation can be found at String::from for &PolynomialRingZq.
Source§impl FromCoefficientEmbedding<(&MatZq, &ModulusPolynomialRingZq)> for PolynomialRingZq
impl FromCoefficientEmbedding<(&MatZq, &ModulusPolynomialRingZq)> for PolynomialRingZq
Source§fn from_coefficient_embedding(
embedding: (&MatZq, &ModulusPolynomialRingZq),
) -> Self
fn from_coefficient_embedding( embedding: (&MatZq, &ModulusPolynomialRingZq), ) -> Self
Computes a polynomial of degree n-1 from a column vector of size n and a modulus.
The i-th entry of the column vector is taken
as the i-th coefficient of the polynomial.
It inverts the operation of
PolynomialRingZq::into_coefficient_embedding.
Parameters:
embedding: the column vector that encodes the embedding and the modulus of the resulting polynomial
Returns a polynomial that corresponds to the embedding.
§Examples
use std::str::FromStr;
use qfall_math::{
integer_mod_q::{MatZq, PolynomialRingZq, ModulusPolynomialRingZq},
traits::FromCoefficientEmbedding,
};
let vector = MatZq::from_str("[[17],[3],[-5]] mod 19").unwrap();
let modulus = ModulusPolynomialRingZq::from_str("4 1 2 3 4 mod 19").unwrap();
let poly = PolynomialRingZq::from_coefficient_embedding((&vector, &modulus));
let cmp_poly = PolynomialRingZq::from_str("3 17 3 -5 / 4 1 2 3 4 mod 19").unwrap();
assert_eq!(cmp_poly, poly);§Panics …
- if the provided embedding is not a column vector.
- if the moduli mismatch.
Source§impl FromStr for PolynomialRingZq
impl FromStr for PolynomialRingZq
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a polynomial ring element of type PolynomialRingZq.
Warning: If the polynomials start with a correctly formatted
PolyOverZ object, the rest of the string
until the "/" (for the first polynomial) or "mod" (for the second polynomial)
is ignored. This means that the input string "4 0 1 2 3 / 2 1 1 mod 13"
is the same as "4 0 1 2 3 4 5 6 7 / 2 1 1 mod 13".
Parameters:
s: the polynomial ring element of form:"[#number of coefficients of element]⌴⌴[0th coefficient]⌴ [1st coefficient]⌴...⌴/⌴[#number of coefficients of polynomial modulus]⌴⌴ [0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[q]".
Note that the [#number of coefficients] and [0th coefficient]
are divided by two spaces and the strings for the polynomials are trimmed,
i.e. all whitespaces around the polynomials and the modulus are ignored.
Returns a PolynomialRingZq or an error if the provided string was not
formatted correctly, the numbers of coefficients were smaller than the numbers
provided at the start of the provided string, or the modulus was smaller than 2.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let poly = PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 3 mod 42").unwrap();§Errors and Failures
- Returns a
MathErrorof typeStringConversionError- if the provided first half of the string was not formatted correctly to
create a
PolyOverZ, - if the provided second half of the
string was not formatted correctly to create a
ModulusPolynomialRingZq, - if the numbers of coefficients were smaller than the numbers provided at the start of the provided string,
- if the provided values did not contain two whitespaces, or
- if the delimiter
/andmodcould not be found.
- if the provided first half of the string was not formatted correctly to
create a
- Returns a
MathErrorof typeInvalidModulusif the integer modulusqis smaller than2.
Source§impl GetCoefficient<Z> for PolynomialRingZq
impl GetCoefficient<Z> for PolynomialRingZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
Returns the coefficient of a PolynomialRingZq as a Z.
If an index is provided which exceeds the highest set coefficient, 0 is returned.
Parameters:
index: the index of the coefficient to get (has to be positive)
Returns the coefficient as a Z, or a MathError if the provided index
is negative and therefore invalid, or it does not fit into an i64.
§Examples
use qfall_math::traits::*;
use qfall_math::integer::{PolyOverZ, Z};
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let coeff_0: Z = poly_ring.get_coeff(0).unwrap();
let coeff_1: Z = unsafe{ poly_ring.get_coeff_unchecked(1) };
let coeff_3: Z = poly_ring.get_coeff(3).unwrap();
assert_eq!(Z::ZERO, coeff_0);
assert_eq!(Z::ONE, coeff_1);
assert_eq!(Z::ZERO, coeff_3);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl GetCoefficient<Zq> for PolynomialRingZq
impl GetCoefficient<Zq> for PolynomialRingZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
Returns the coefficient of a PolynomialRingZq as a Zq.
If an index is provided which exceeds the highest set coefficient, 0 is returned.
Parameters:
index: the index of the coefficient to get (has to be positive)
Returns the coefficient as a Zq, or a MathError if the provided index
is negative and therefore invalid, or it does not fit into an i64.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;
let poly_ring = PolynomialRingZq::from_str("3 0 1 1 / 4 1 0 0 1 mod 17").unwrap();
let coeff_0: Zq = poly_ring.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly_ring.get_coeff_unchecked(1) };
let coeff_3: Zq = poly_ring.get_coeff(3).unwrap();
assert_eq!(Zq::from((0, 17)), coeff_0);
assert_eq!(Zq::from((1, 17)), coeff_1);
assert_eq!(Zq::from((0, 17)), coeff_3);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl IntoCoefficientEmbedding<(MatZq, ModulusPolynomialRingZq)> for &PolynomialRingZq
impl IntoCoefficientEmbedding<(MatZq, ModulusPolynomialRingZq)> for &PolynomialRingZq
Source§fn into_coefficient_embedding(
self,
size: impl Into<i64>,
) -> (MatZq, ModulusPolynomialRingZq)
fn into_coefficient_embedding( self, size: impl Into<i64>, ) -> (MatZq, ModulusPolynomialRingZq)
Computes the coefficient embedding of the polynomial
in a MatZq as a column vector, where the i-th entry
of the vector corresponds to the i-th coefficient, and a
ModulusPolynomialRingZq.
It inverts the operation of PolynomialRingZq::from_coefficient_embedding.
The representation of the polynomials in the embedding is in the range [0, modulus_polynomial).
Parameters:
size: determines the number of rows of the embedding. It has to be larger than the degree of the polynomial.
Returns a coefficient embedding as a column vector if size is large enough.
§Examples
use std::str::FromStr;
use qfall_math::{
integer_mod_q::{MatZq, PolynomialRingZq},
traits::IntoCoefficientEmbedding,
};
let poly = PolynomialRingZq::from_str("2 1 -2 / 3 17 3 5 mod 19").unwrap();
let embedding = poly.into_coefficient_embedding(3);
let cmp_vector = MatZq::from_str("[[1],[-2],[0]] mod 19").unwrap();
assert_eq!((cmp_vector, poly.get_mod()), embedding);§Panics …
- if
sizeis not larger than the degree of the polynomial, i.e. not all coefficients can be embedded.
Source§impl MatrixGetEntry<PolynomialRingZq> for MatPolynomialRingZq
impl MatrixGetEntry<PolynomialRingZq> for MatPolynomialRingZq
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolynomialRingZq
unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolynomialRingZq
Outputs the PolynomialRingZq value of a specific matrix entry
without checking whether it’s part of the matrix.
Parameters:
row: specifies the row in which the entry is locatedcolumn: specifies the column in which the entry is located
Returns the PolynomialRingZq value of the matrix at the position of the given
row and column.
§Safety
To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 50").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let entry_1: PolynomialRingZq = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
let entry_2: PolynomialRingZq = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
let value_cmp = PolynomialRingZq::from((&PolyOverZ::from(42), &modulus));
assert_eq!(entry_1, value_cmp);
assert_eq!(entry_1, entry_2);Source§fn get_entry(
&self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
) -> Result<T, MathError>
fn get_entry( &self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, ) -> Result<T, MathError>
Source§fn get_entries(&self) -> Vec<Vec<T>>
fn get_entries(&self) -> Vec<Vec<T>>
Vec<Vec<T>> containing all entries of the matrix s.t.
any entry in row i and column j can be accessed via entries[i][j]
if entries = matrix.get_entries. Read moreSource§fn get_entries_rowwise(&self) -> Vec<T>
fn get_entries_rowwise(&self) -> Vec<T>
Source§impl MatrixSetEntry<&PolynomialRingZq> for MatPolynomialRingZq
impl MatrixSetEntry<&PolynomialRingZq> for MatPolynomialRingZq
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: &PolynomialRingZq,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: &PolynomialRingZq, )
Sets the value of a specific matrix entry according to a given value of type PolynomialRingZq
without checking whether the coordinate is part of the matrix or if the moduli match.
Parameters:
row: specifies the row in which the entry is locatedcolumn: specifies the column in which the entry is locatedvalue: specifies the value to which the entry is set
§Safety
To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use crate::qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[0, 1 42],[0, 2 1 2]]").unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let value = PolynomialRingZq::from((&PolyOverZ::default(), &modulus));
unsafe {
poly_ring_mat.set_entry_unchecked(0, 1, &value);
poly_ring_mat.set_entry_unchecked(1, 1, &value);
}
let mat_cmp = MatPolynomialRingZq::from((&MatPolyOverZ::new(2, 2), &modulus));
assert_eq!(poly_ring_mat, mat_cmp);Source§impl MatrixSetEntry<PolynomialRingZq> for MatPolynomialRingZq
impl MatrixSetEntry<PolynomialRingZq> for MatPolynomialRingZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: PolynomialRingZq,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: PolynomialRingZq, ) -> Result<(), MathError>
Documentation can be found at MatPolynomialRingZq::set_entry for &PolynomialRingZq.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: PolynomialRingZq,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: PolynomialRingZq, )
Documentation can be found at MatPolynomialRingZq::set_entry for &PolynomialRingZq.
Source§impl Mul<&PolyOverZ> for &PolynomialRingZq
impl Mul<&PolyOverZ> for &PolynomialRingZq
Source§fn mul(self, other: &PolyOverZ) -> Self::Output
fn mul(self, other: &PolyOverZ) -> Self::Output
Implements the Mul trait for PolynomialRingZq and PolyOverZ.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolynomialRingZq = &a * &b;Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
* operator.Source§impl Mul<&PolyOverZq> for &PolynomialRingZq
impl Mul<&PolyOverZq> for &PolynomialRingZq
Source§fn mul(self, other: &PolyOverZq) -> Self::Output
fn mul(self, other: &PolyOverZq) -> Self::Output
Implements the Mul trait for PolynomialRingZq and PolyOverZq.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, PolynomialRingZq};
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZq::from_str("4 2 0 3 1 mod 17").unwrap();
let c: PolynomialRingZq = &a * &b;§Panics …
- if the moduli mismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
* operator.Source§impl Mul<&PolynomialRingZq> for &MatPolyOverZ
impl Mul<&PolynomialRingZq> for &MatPolyOverZ
Source§fn mul(self, scalar: &PolynomialRingZq) -> Self::Output
fn mul(self, scalar: &PolynomialRingZq) -> Self::Output
Implements the Mul trait for a MatPolyOverZ matrix with a PolynomialRingZq.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly = PolyOverZ::from_str("3 1 0 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_mat1 = &poly_mat1 * &poly_ring;Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&PolynomialRingZq> for &MatPolynomialRingZq
impl Mul<&PolynomialRingZq> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &PolynomialRingZq) -> Self::Output
fn mul(self, scalar: &PolynomialRingZq) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a PolynomialRingZq.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ, Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat1 = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly = PolyOverZ::from_str("3 1 0 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_mat2 = &poly_ring_mat1 * &poly_ring;§Panics …
- if the moduli mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&Z> for &PolynomialRingZq
impl Mul<&Z> for &PolynomialRingZq
Source§fn mul(self, scalar: &Z) -> Self::Output
fn mul(self, scalar: &Z) -> Self::Output
Implements the Mul trait for a PolynomialRingZq with a Z integer.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Z using PolynomialRingZq.
Parameters:
scalar: specifies the scalar by which the polynomial is multiplied
Returns the product of self and scalar as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer::Z;
use std::str::FromStr;
let poly_1 = PolynomialRingZq::from_str("3 1 2 3 / 4 1 2 3 4 mod 17").unwrap();
let integer = Z::from(3);
let poly_2 = &poly_1 * &integer;Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
* operator.Source§impl Mul<&Zq> for &PolynomialRingZq
impl Mul<&Zq> for &PolynomialRingZq
Source§fn mul(self, scalar: &Zq) -> PolynomialRingZq
fn mul(self, scalar: &Zq) -> PolynomialRingZq
Implements the Mul trait for a PolynomialRingZq with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Zq using PolynomialRingZq.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;
let poly_1 = PolynomialRingZq::from_str("3 1 2 3 / 4 1 2 3 4 mod 17").unwrap();
let integer = Zq::from((3,17));
let poly_2 = &poly_1 * &integer;§Panics …
- if the moduli mismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
* operator.Source§impl Mul for &PolynomialRingZq
impl Mul for &PolynomialRingZq
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Implements the Mul trait for two PolynomialRingZq values.
Mul is implemented for any combination of PolynomialRingZq and borrowed PolynomialRingZq.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));
let c: PolynomialRingZq = &a * &b;
let d: PolynomialRingZq = a * b;
let e: PolynomialRingZq = &c * d;
let f: PolynomialRingZq = c * &e;§Panics …
- if the moduli of both
PolynomialRingZqmismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
* operator.Source§impl MulAssign<&PolyOverZq> for PolynomialRingZq
impl MulAssign<&PolyOverZq> for PolynomialRingZq
Source§fn mul_assign(&mut self, other: &PolyOverZq)
fn mul_assign(&mut self, other: &PolyOverZq)
Source§impl MulAssign<&PolynomialRingZq> for MatPolynomialRingZq
impl MulAssign<&PolynomialRingZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, scalar: &PolynomialRingZq)
fn mul_assign(&mut self, scalar: &PolynomialRingZq)
Computes the scalar multiplication of self and scalar reusing
the memory of self.
Parameters:
scalar: specifies the value to multiply toself
Returns the scalar of the matrix as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq,ModulusPolynomialRingZq,PolynomialRingZq,Zq};
use qfall_math::integer::{MatZ,PolyOverZ,Z,MatPolyOverZ};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {}", u64::MAX - 1)).unwrap();
let poly_mat1 = MatPolyOverZ::from_str(&format!("[[1 1],[1 {}],[1 4]]", i64::MAX)).unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly_z = PolyOverZ::from_str("2 3 1").unwrap();
let polynomial_ring_zq = PolynomialRingZq::from((&poly_z, &modulus));
poly_ring_mat *= &polynomial_ring_zq;
poly_ring_mat *= &poly_z;
poly_ring_mat *= 2;
poly_ring_mat *= -2;
poly_ring_mat *= &Z::from(5);
poly_ring_mat *= &Zq::from((5, u64::MAX -1));§Panics …
- if the moduli are different.
Source§impl MulAssign<&PolynomialRingZq> for PolynomialRingZq
impl MulAssign<&PolynomialRingZq> for PolynomialRingZq
Source§fn mul_assign(&mut self, other: &Self)
fn mul_assign(&mut self, other: &Self)
Computes the multiplication of self and other reusing
the memory of self.
MulAssign can be used on PolynomialRingZq in combination with
PolynomialRingZq, PolyOverZ and PolyOverZq.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials modulo Z_q[X] as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let mut a = PolynomialRingZq::from((&poly_1, &modulus));
let c = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&c, &modulus));
let d = PolyOverZq::from((&c, 17));
a *= &b;
a *= b;
a *= &c;
a *= c;
a *= &d;
a *= d;§Panics …
- if the moduli of both
PolynomialRingZqmismatch.
Source§impl MulAssign<&Zq> for PolynomialRingZq
impl MulAssign<&Zq> for PolynomialRingZq
Source§fn mul_assign(&mut self, rhs: &Zq)
fn mul_assign(&mut self, rhs: &Zq)
Computes the scalar multiplication of self and other reusing
the memory of self.
Parameters:
other: specifies the value to multiply toself
Returns the scalar of the matrix as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{ModulusPolynomialRingZq,PolynomialRingZq,Zq};
use qfall_math::integer::{MatZ,PolyOverZ,Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {}", u64::MAX - 1)).unwrap();
let poly_z = PolyOverZ::from_str("2 3 1").unwrap();
let mut polynomial_ring_zq = PolynomialRingZq::from((&poly_z, &modulus));
let zq = Zq::from((17, u64::MAX -1 ));
let z = Z::from(5);
polynomial_ring_zq *= &zq;
polynomial_ring_zq *= zq;
polynomial_ring_zq *= &z;
polynomial_ring_zq *= z;
polynomial_ring_zq *= 2;
polynomial_ring_zq *= -2;§Panics …
- if the moduli are different.
Source§impl MulAssign<PolyOverZq> for PolynomialRingZq
impl MulAssign<PolyOverZq> for PolynomialRingZq
Source§fn mul_assign(&mut self, other: PolyOverZq)
fn mul_assign(&mut self, other: PolyOverZq)
Documentation at PolynomialRingZq::mul_assign.
Source§impl MulAssign<PolynomialRingZq> for MatPolynomialRingZq
impl MulAssign<PolynomialRingZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, other: PolynomialRingZq)
fn mul_assign(&mut self, other: PolynomialRingZq)
Documentation at MatPolynomialRingZq::mul_assign.
Source§impl<T> MulAssign<T> for PolynomialRingZq
impl<T> MulAssign<T> for PolynomialRingZq
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Documentation at PolynomialRingZq::mul_assign
This implicitly also implements scalar multiplication for all types that have a mul_assign with PolyOverZ`.
Source§impl MulAssign<Zq> for PolynomialRingZq
impl MulAssign<Zq> for PolynomialRingZq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at PolynomialRingZq::mul_assign.
Source§impl MulAssign for PolynomialRingZq
impl MulAssign for PolynomialRingZq
Source§fn mul_assign(&mut self, other: PolynomialRingZq)
fn mul_assign(&mut self, other: PolynomialRingZq)
Documentation at PolynomialRingZq::mul_assign.
Source§impl PartialEq for PolynomialRingZq
impl PartialEq for PolynomialRingZq
Source§impl Serialize for PolynomialRingZq
impl Serialize for PolynomialRingZq
Source§impl SetCoefficient<&Zq> for PolynomialRingZq
impl SetCoefficient<&Zq> for PolynomialRingZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)
Sets the coefficient of a PolynomialRingZq element.
We advise to use small coefficients, since already 2^32 coefficients take space
of roughly 34 GB. If not careful, be prepared that memory problems can occur, if
the index is very high.
This function does not check if the modulus of the polynomial and the value match.
Parameters:
index: the index of the coefficient to set (has to be positive)value: the new value the index should have
§Examples
use crate::qfall_math::traits::SetCoefficient;
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3 0 1 1").unwrap();
let mut poly_ring = PolynomialRingZq::from((&poly, &modulus));
let value = Zq::from((1000, 17));
poly_ring.set_coeff(2, &value).unwrap();
unsafe{ poly_ring.set_coeff_unchecked(5, &value) };§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0 and that the provided value has
the same base so that they have a matching base.
Source§impl<Integer: Into<Z>> SetCoefficient<Integer> for PolynomialRingZq
impl<Integer: Into<Z>> SetCoefficient<Integer> for PolynomialRingZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Integer)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Integer)
Sets the coefficient of a PolynomialRingZq element.
We advise to use small coefficients, since already 2^32 coefficients take space
of roughly 34 GB. If not careful, be prepared that memory problems can occur, if
the index is very high.
Parameters:
index: the index of the coefficient to set (has to be positive)value: the new value the index should have
§Examples
use crate::qfall_math::traits::SetCoefficient;
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3 0 1 1").unwrap();
let mut poly_ring = PolynomialRingZq::from((&poly, &modulus));
poly_ring.set_coeff(2, 16).unwrap();
unsafe{ poly_ring.set_coeff_unchecked(5, 5) };§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0 and that the provided value has
the same base so that they have a matching base.
Source§impl SetCoefficient<Zq> for PolynomialRingZq
impl SetCoefficient<Zq> for PolynomialRingZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)
Documentation can be found at PolynomialRingZq::set_coeff for &Zq.
Source§impl Sub<&PolyOverZ> for &PolynomialRingZq
impl Sub<&PolyOverZ> for &PolynomialRingZq
Source§fn sub(self, other: &PolyOverZ) -> Self::Output
fn sub(self, other: &PolyOverZ) -> Self::Output
Implements the Sub trait for PolynomialRingZq and PolyOverZ.
Sub is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the subtraction of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolynomialRingZq = &a - &b;Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
- operator.Source§impl Sub<&PolyOverZq> for &PolynomialRingZq
impl Sub<&PolyOverZq> for &PolynomialRingZq
Source§fn sub(self, other: &PolyOverZq) -> Self::Output
fn sub(self, other: &PolyOverZq) -> Self::Output
Implements the Sub trait for PolynomialRingZq and PolyOverZq.
Sub is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the subtraction of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, PolynomialRingZq};
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZq::from_str("4 2 0 3 1 mod 17").unwrap();
let c: PolynomialRingZq = &a - &b;§Panics …
- if the moduli mismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
- operator.Source§impl Sub<&PolynomialRingZq> for &PolyOverZ
impl Sub<&PolynomialRingZq> for &PolyOverZ
Source§fn sub(self, other: &PolynomialRingZq) -> Self::Output
fn sub(self, other: &PolynomialRingZq) -> Self::Output
Implements the Sub trait for PolyOverZ and PolynomialRingZq.
Sub is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the subtraction of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolynomialRingZq = &b - &a;Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
- operator.Source§impl Sub<&PolynomialRingZq> for &PolyOverZq
impl Sub<&PolynomialRingZq> for &PolyOverZq
Source§fn sub(self, other: &PolynomialRingZq) -> Self::Output
fn sub(self, other: &PolynomialRingZq) -> Self::Output
Implements the Sub trait for PolyOverZq and PolynomialRingZq.
Sub is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the subtraction of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, PolynomialRingZq};
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly, &modulus));
let b = PolyOverZq::from_str("4 2 0 3 1 mod 17").unwrap();
let c: PolynomialRingZq = &b - &a;§Panics …
- if the moduli mismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
- operator.Source§impl Sub for &PolynomialRingZq
impl Sub for &PolynomialRingZq
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Implements the Sub trait for two PolynomialRingZq values.
Sub is implemented for any combination of PolynomialRingZq and borrowed PolynomialRingZq.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the result of the subtraction of both polynomials as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));
let c: PolynomialRingZq = &a - &b;
let d: PolynomialRingZq = a - b;
let e: PolynomialRingZq = &c - d;
let f: PolynomialRingZq = c - &e;§Panics …
- if the moduli of both
PolynomialRingZqmismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
- operator.Source§impl SubAssign<&PolyOverZ> for PolynomialRingZq
impl SubAssign<&PolyOverZ> for PolynomialRingZq
Source§fn sub_assign(&mut self, other: &PolyOverZ)
fn sub_assign(&mut self, other: &PolyOverZ)
Documentation at PolynomialRingZq::sub_assign.
Source§impl SubAssign<&PolyOverZq> for PolynomialRingZq
impl SubAssign<&PolyOverZq> for PolynomialRingZq
Source§fn sub_assign(&mut self, other: &PolyOverZq)
fn sub_assign(&mut self, other: &PolyOverZq)
Source§impl SubAssign<&PolynomialRingZq> for PolynomialRingZq
impl SubAssign<&PolynomialRingZq> for PolynomialRingZq
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
Computes the subtraction of self and other reusing
the memory of self.
SubAssign can be used on PolynomialRingZq in combination with
PolynomialRingZq, PolyOverZ and PolyOverZq.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the difference of both polynomials modulo Z_q[X] as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let mut a = PolynomialRingZq::from((&poly_1, &modulus));
let c = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&c, &modulus));
let d = PolyOverZq::from((&c, 17));
a -= &b;
a -= b;
a -= &c;
a -= c;
a -= &d;
a -= d;§Panics …
- if the moduli of both
PolynomialRingZqmismatch.
Source§impl SubAssign<PolyOverZ> for PolynomialRingZq
impl SubAssign<PolyOverZ> for PolynomialRingZq
Source§fn sub_assign(&mut self, other: PolyOverZ)
fn sub_assign(&mut self, other: PolyOverZ)
Documentation at PolynomialRingZq::sub_assign.
Source§impl SubAssign<PolyOverZq> for PolynomialRingZq
impl SubAssign<PolyOverZq> for PolynomialRingZq
Source§fn sub_assign(&mut self, other: PolyOverZq)
fn sub_assign(&mut self, other: PolyOverZq)
Documentation at PolynomialRingZq::sub_assign.
Source§impl SubAssign for PolynomialRingZq
impl SubAssign for PolynomialRingZq
Source§fn sub_assign(&mut self, other: PolynomialRingZq)
fn sub_assign(&mut self, other: PolynomialRingZq)
Documentation at PolynomialRingZq::sub_assign.