pub struct PolyOverZq { /* private fields */ }Expand description
PolyOverZq is a type of polynomial with arbitrarily many coefficients of type
Zq.
§Examples
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::traits::*;
use std::str::FromStr;
// instantiations
let poly_1 = PolyOverZq::from_str("4 0 1 2 3 mod 42").unwrap();
let poly_2 = poly_1.clone();
// evaluate function
let value = Z::from(3);
let res = poly_1.evaluate(&value);
// properties
let reducibility: bool = poly_1.is_irreducible();
// comparison
assert_eq!(poly_1, poly_2);Implementations§
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn add_safe(&self, other: &Self) -> Result<PolyOverZq, MathError>
pub fn add_safe(&self, other: &Self) -> Result<PolyOverZq, MathError>
Implements addition for two PolyOverZq values.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a PolyOverZq or an error if the moduli
mismatch.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("3 2 4 1 mod 7").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 5 1 1 mod 7").unwrap();
let c: PolyOverZq = a.add_safe(&b).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothPolyOverZqmismatch.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn mul_safe(&self, other: &Self) -> Result<PolyOverZq, MathError>
pub fn mul_safe(&self, other: &Self) -> Result<PolyOverZq, MathError>
Implements multiplication for two PolyOverZq values.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials as a PolyOverZq or an error if the moduli
mismatch.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("3 2 4 1 mod 7").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 5 1 1 mod 7").unwrap();
let c: PolyOverZq = a.mul_safe(&b).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothPolyOverZqmismatch.
Source§impl PolyOverZq
impl PolyOverZq
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 PolyOverZq with a Zq.
Parameters:
scalar: Specifies the scalar by which the polynomial is multiplied.
Returns the product of self and scalar as a PolyOverZq
or an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, Zq};
use std::str::FromStr;
let poly_1 = PolyOverZq::from_str("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 PolyOverZq
impl PolyOverZq
Sourcepub fn sub_safe(&self, other: &Self) -> Result<PolyOverZq, MathError>
pub fn sub_safe(&self, other: &Self) -> Result<PolyOverZq, MathError>
Implements subtraction for two PolyOverZq values.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the result of the subtraction of both polynomials as a PolyOverZq or an error if the moduli
mismatch.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("3 2 4 1 mod 7").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 5 1 1 mod 7").unwrap();
let c: PolyOverZq = a.sub_safe(&b).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothPolyOverZqmismatch.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn dot_product(&self, other: &Self) -> Result<Zq, MathError>
pub fn dot_product(&self, other: &Self) -> Result<Zq, MathError>
Returns the dot product of two polynomials of type PolyOverZq.
The dot product for polynomials is obtained by treating the coefficients
of the polynomials as vectors and then applying the standard dot product operation.
Parameters:
other: specifies the other polynomial the dot product is calculated over
Returns the resulting dot_product as a PolyOverZq or an error
if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly_1 = PolyOverZq::from_str("4 1 0 2 1 mod 11").unwrap();
let poly_2 = PolyOverZq::from_str("1 9 mod 11").unwrap();
let dot_prod = poly_1.dot_product(&poly_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli mismatch.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn evaluate_safe(&self, value: &Zq) -> Result<Zq, MathError>
pub fn evaluate_safe(&self, value: &Zq) -> Result<Zq, MathError>
Evaluates a PolyOverZq on a given input of Zq. Note that the
Zq in this case is only a reference.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Zq or an error
if the moduli mismatch.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("5 0 1 2 -3 1 mod 17").unwrap();
let value = Zq::from((3, 17));
let res = poly.evaluate(&value);§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of the polynomial and the input mismatch.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn get_degree(&self) -> i64
pub fn get_degree(&self) -> i64
Returns the degree of a polynomial PolyOverZq as a i64.
The zero polynomial has degree -1.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("4 0 1 2 3 mod 7").unwrap();
let degree = poly.get_degree(); // This would only return 3Sourcepub fn get_representative_least_nonnegative_residue(&self) -> PolyOverZ
pub fn get_representative_least_nonnegative_residue(&self) -> PolyOverZ
Returns a representative polynomial of the PolyOverZq element.
The representation of the coefficients is in the range [0, modulus).
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly_zq = PolyOverZq::from_str("4 -3 0 31 1 mod 17").unwrap();
let poly_z = poly_zq.get_representative_least_nonnegative_residue();
let cmp_poly = PolyOverZ::from_str("4 14 0 14 1").unwrap();
assert_eq!(cmp_poly, poly_z);Source§impl PolyOverZq
impl PolyOverZq
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::PolyOverZq};
use std::str::FromStr;
let poly = PolyOverZq::from_str("3 1 2 3 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::PolyOverZq};
use std::str::FromStr;
let poly = PolyOverZq::from_str("3 1 2 4 mod 7").unwrap();
let infty_norm = poly.norm_infty();
// max coefficient is 4 = -3
assert_eq!(Z::from(3), infty_norm);Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn is_irreducible(&self) -> bool
pub fn is_irreducible(&self) -> bool
Checks if a PolyOverZq is irreducible.
Returns true if the polynomial is irreducible and false otherwise.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly_irr = PolyOverZq::from_str("2 1 1 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 PolyOverZq 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::PolyOverZq;
use std::str::FromStr;
let value = PolyOverZq::from_str("1 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 PolyOverZq is 0.
Returns true if PolyOverZq has no coefficients.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let value = PolyOverZq::from_str("0 mod 7").unwrap();
assert!(value.is_zero());Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn sample_binomial(
max_degree: impl TryInto<i64> + Display,
modulus: impl Into<Modulus>,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial( max_degree: impl TryInto<i64> + Display, modulus: impl Into<Modulus>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Generates a PolyOverZq instance of maximum degree max_degree and
coefficients chosen according to the binomial distribution
parameterized by n and p.
Parameters:
max_degree: specifies the length of the polynomial, i.e. the number of coefficientsmodulus: specifies theModulusof the newPolyOverZqinstancen: specifies the number of trialsp: specifies the probability of success
Returns a fresh PolyOverZq instance with each value sampled
according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), n does not fit into an i64,
or max_degree is negative or does not into an i64.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
let sample = PolyOverZq::sample_binomial(2, 7, 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. - Returns a
MathErrorof typeOutOfBoundsif themax_degreeis negative or it does not fit into ani64.
Sourcepub fn sample_binomial_with_offset(
max_degree: impl TryInto<i64> + Display,
offset: impl Into<Z>,
modulus: impl Into<Modulus>,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial_with_offset( max_degree: impl TryInto<i64> + Display, offset: impl Into<Z>, modulus: impl Into<Modulus>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Generates a PolyOverZq instance of maximum degree max_degree and
coefficients chosen according to the binomial distribution
parameterized by n and p with given offset.
Parameters:
max_degree: specifies the length of the polynomial, i.e. the number of coefficientsoffset: specifies an offset applied to each sample collected from the binomial distributionmodulus: specifies theModulusof the newPolyOverZqinstancen: specifies the number of trialsp: specifies the probability of success
Returns a fresh PolyOverZq instance with each value sampled
according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), n does not fit into an i64,
or max_degree is negative or does not into an i64.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
let sample = PolyOverZq::sample_binomial_with_offset(2, -1, 7, 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. - Returns a
MathErrorof typeOutOfBoundsif themax_degreeis negative or it does not fit into ani64.
§Panics …
- if
modulusis smaller than2.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn sample_discrete_gauss(
max_degree: impl TryInto<i64> + Display,
modulus: impl Into<Modulus>,
center: impl Into<Q>,
s: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_discrete_gauss( max_degree: impl TryInto<i64> + Display, modulus: impl Into<Modulus>, center: impl Into<Q>, s: impl Into<Q>, ) -> Result<Self, MathError>
Initializes a new PolyOverZq with maximum degree max_degree
and with each entry sampled independently according to the
discrete Gaussian distribution, using Z::sample_discrete_gauss.
Parameters:
max_degree: specifies the included maximal degree the createdPolyOverZqshould havemodulus: specififes theModulusover which the ring of integer coefficients 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 PolyOverZq instance of maximum degree max_degree
with coefficients chosen independently according the discrete Gaussian distribution or
a MathError if s < 0.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
let sample = PolyOverZq::sample_discrete_gauss(2, 17, 0, 1).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifs < 0.
§Panics …
- if
max_degreeis negative, or does not fit into ani64. - if
modulusis smaller than2.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub fn sample_uniform(
max_degree: impl TryInto<i64> + Display + Copy,
modulus: impl Into<Z>,
) -> Result<Self, MathError>
pub fn sample_uniform( max_degree: impl TryInto<i64> + Display + Copy, modulus: impl Into<Z>, ) -> Result<Self, MathError>
Generates a PolyOverZq instance with maximum degree max_degree
and coefficients chosen uniform at random in [0, modulus).
The internally used uniform at random chosen bytes are generated
by ThreadRng, which uses ChaCha12 and
is considered cryptographically secure.
Parameters:
max_degree: specifies the length of the polynomial, i.e. the number of coefficientsmodulus: specifies the modulus of the coefficients and thus, the interval size over which is sampled
Returns a fresh PolyOverZq instance of length max_degree with coefficients
chosen uniform at random in [0, modulus) or a MathError
if the max_degree was smaller than 0 or the provided modulus was chosen too small.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
let sample = PolyOverZq::sample_uniform(3, 17).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntervalif the givenmodulusisn’t larger than1, i.e. the interval size is at most1. - Returns a
MathErrorof typeOutOfBoundsif themax_degreeis negative or it does not fit into ani64.
§Panics …
- if
modulusis smaller than2.
Source§impl PolyOverZq
impl PolyOverZq
Sourcepub unsafe fn get_fmpz_mod_poly_struct(&mut self) -> &mut fmpz_mod_poly_struct
pub unsafe fn get_fmpz_mod_poly_struct(&mut self) -> &mut fmpz_mod_poly_struct
Returns a mutable reference to the field poly of type fmpz_mod_poly_struct.
WARNING: The returned struct is part of flint_sys.
Any changes to this object are unsafe and may introduce memory leaks.
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 PolyOverZq
impl PolyOverZq
Sourcepub unsafe fn get_fmpz_mod_ctx(&mut self) -> &mut fmpz_mod_ctx
pub unsafe fn get_fmpz_mod_ctx(&mut self) -> &mut fmpz_mod_ctx
Returns a mutable reference to the underlying fmpz_mod_ctx by calling get_fmpz_mod_ctx 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 PolyOverZq
impl PolyOverZq
Sourcepub unsafe fn set_fmpz_mod_poly_struct(
&mut self,
flint_struct: fmpz_mod_poly_struct,
)
pub unsafe fn set_fmpz_mod_poly_struct( &mut self, flint_struct: fmpz_mod_poly_struct, )
Sets the field poly of type PolyOverZq to flint_struct.
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 PolyOverZq
impl PolyOverZq
Sourcepub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx)
pub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx)
Sets the field fmpz_mod_ctx to flint_struct by calling set_fmpz_mod_ctx 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 &PolyOverZq
impl Add<&PolyOverZ> for &PolyOverZq
Source§fn add(self, other: &PolyOverZ) -> Self::Output
fn add(self, other: &PolyOverZ) -> Self::Output
Implements the Add trait for PolyOverZq 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 PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolyOverZq = &a + &b;Source§type Output = PolyOverZq
type Output = PolyOverZq
+ 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 &PolyOverZq
impl Add for &PolyOverZq
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Implements the Add trait for two PolyOverZq values.
Add is implemented for any combination of PolyOverZq and borrowed PolyOverZq.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("3 2 4 1 mod 7").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 5 1 1 mod 7").unwrap();
let c: PolyOverZq = &a + &b;
let d: PolyOverZq = a + b;
let e: PolyOverZq = &c + d;
let f: PolyOverZq = c + &e;§Panics …
- if the moduli of both
PolyOverZqmismatch.
Source§type Output = PolyOverZq
type Output = PolyOverZq
+ operator.Source§impl AddAssign<&PolyOverZ> for PolyOverZq
impl AddAssign<&PolyOverZ> for PolyOverZq
Source§fn add_assign(&mut self, other: &PolyOverZ)
fn add_assign(&mut self, other: &PolyOverZ)
Documentation at PolyOverZq::add_assign.
Source§impl AddAssign<&PolyOverZq> for PolyOverZq
impl AddAssign<&PolyOverZq> for PolyOverZq
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 PolyOverZq in combination with
PolyOverZq and PolyOverZ.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials modulo q as a PolyOverZq.
§Examples
use qfall_math::{integer_mod_q::PolyOverZq, integer::PolyOverZ};
use std::str::FromStr;
let mut a = PolyOverZq::from_str("3 1 2 3 mod 7").unwrap();
let b = PolyOverZq::from_str("5 1 2 -3 0 4 mod 7").unwrap();
let c = PolyOverZ::from_str("4 -1 2 5 3").unwrap();
a += &b;
a += b;
a += &c;
a += c;§Panics …
- if the moduli of both
PolyOverZqmismatch.
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<PolyOverZ> for PolyOverZq
impl AddAssign<PolyOverZ> for PolyOverZq
Source§fn add_assign(&mut self, other: PolyOverZ)
fn add_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverZq::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 PolyOverZq
impl AddAssign for PolyOverZq
Source§fn add_assign(&mut self, other: PolyOverZq)
fn add_assign(&mut self, other: PolyOverZq)
Documentation at PolyOverZq::add_assign.
Source§impl Clone for PolyOverZq
impl Clone for PolyOverZq
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clones the given PolyOverZq element by returning a deep clone,
storing the actual value separately and including
a reference to the Modulus element.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a = PolyOverZq::from_str("4 0 1 -2 3 mod 13").unwrap();
let b = a.clone();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 PolyOverZq
impl CompareBase<&PolyOverZ> for PolyOverZq
Source§impl CompareBase<&PolyOverZq> for MatNTTPolynomialRingZq
impl CompareBase<&PolyOverZq> for MatNTTPolynomialRingZq
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<&PolyOverZq> for MatPolynomialRingZq
impl CompareBase<&PolyOverZq> for MatPolynomialRingZq
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<&PolyOverZq> for NTTPolynomialRingZq
impl CompareBase<&PolyOverZq> for NTTPolynomialRingZq
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<&PolyOverZq> for PolyOverZq
impl CompareBase<&PolyOverZq> for PolyOverZq
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<&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<&Zq> for PolyOverZq
impl CompareBase<&Zq> for PolyOverZq
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 PolyOverZq
impl<Integer: Into<Z>> CompareBase<Integer> for PolyOverZq
Source§impl CompareBase<PolyOverZ> for PolyOverZq
impl CompareBase<PolyOverZ> for PolyOverZq
Source§impl CompareBase<PolyOverZq> for MatNTTPolynomialRingZq
impl CompareBase<PolyOverZq> for MatNTTPolynomialRingZq
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<PolyOverZq> for MatPolynomialRingZq
impl CompareBase<PolyOverZq> for MatPolynomialRingZq
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<PolyOverZq> for NTTPolynomialRingZq
impl CompareBase<PolyOverZq> for NTTPolynomialRingZq
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<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<Zq> for PolyOverZq
impl CompareBase<Zq> for PolyOverZq
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 PolyOverZq
impl CompareBase for PolyOverZq
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 Debug for PolyOverZq
impl Debug for PolyOverZq
Source§impl<'de> Deserialize<'de> for PolyOverZq
impl<'de> Deserialize<'de> for PolyOverZq
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>,
Implements the deserialize option. This allows to create a PolyOverZq from a given Json-object.
Source§impl Display for PolyOverZq
impl Display for PolyOverZq
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Allows to convert a PolyOverZq into a String.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
use core::fmt;
let poly = PolyOverZq::from_str("4 0 1 2 3 mod 5").unwrap();
println!("{poly}");use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("4 0 1 2 3 mod 5").unwrap();
let poly_string = poly.to_string();Source§impl Drop for PolyOverZq
impl Drop for PolyOverZq
Source§fn drop(&mut self)
fn drop(&mut self)
Drops the given memory allocated for the underlying value
and frees the allocated memory of the corresponding
Modulus if no other references are left.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
{
let a = PolyOverZq::from_str("4 0 1 -2 3 mod 13").unwrap();
} // as a's scope ends here, it get's droppeduse qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a = PolyOverZq::from_str("4 0 1 -2 3 mod 13").unwrap();
drop(a); // explicitly drops a's valueSource§impl Evaluate<&Zq, Zq> for PolyOverZq
impl Evaluate<&Zq, Zq> for PolyOverZq
Source§fn evaluate(&self, value: &Zq) -> Zq
fn evaluate(&self, value: &Zq) -> Zq
Evaluates a PolyOverZq on a given input of Zq. Note that the
Zq in this case is only a reference. Note that this function will panic if
the modulus of the input and the polynomial mismatch.
Use PolyOverZq::evaluate_safe if a panic has to be avoided.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Zq.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("5 0 1 2 -3 1 mod 17").unwrap();
let value = Zq::from((3, 17));
let res = poly.evaluate(&value);§Panics …
- if the moduli of the polynomial and the input mismatch.
Source§impl<Integer: Into<Z>> Evaluate<Integer, Zq> for PolyOverZq
impl<Integer: Into<Z>> Evaluate<Integer, Zq> for PolyOverZq
Source§fn evaluate(&self, value: Integer) -> Zq
fn evaluate(&self, value: Integer) -> Zq
Evaluates a PolyOverZq on a given input that implements Into<Z>.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Zq.
§Examples
use qfall_math::traits::*;
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("5 0 1 2 -3 1 mod 17").unwrap();
let value = Z::from(3);
let res = poly.evaluate(&value);
let res_2 = poly.evaluate(3);Source§impl From<&ModulusPolynomialRingZq> for PolyOverZq
impl From<&ModulusPolynomialRingZq> for PolyOverZq
Source§fn from(modulus: &ModulusPolynomialRingZq) -> Self
fn from(modulus: &ModulusPolynomialRingZq) -> Self
Creates a PolyOverZq from a ModulusPolynomialRingZq.
Parameters:
modulus: the context polynomial from which the coefficients are copied.
§Examples
Returns a new PolyOverZq representing the modulus object.
use qfall_math::integer_mod_q::{ModulusPolynomialRingZq, PolyOverZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_zq = PolyOverZq::from(&modulus);
let poly_cmp = PolyOverZq::from_str("4 1 0 0 1 mod 17").unwrap();
assert_eq!(poly_cmp, poly_zq);Source§impl From<&PolyOverZq> for ModulusPolynomialRingZq
impl From<&PolyOverZq> for ModulusPolynomialRingZq
Source§fn from(poly: &PolyOverZq) -> Self
fn from(poly: &PolyOverZq) -> Self
Creates a Modulus object of type ModulusPolynomialRingZq
for PolynomialRingZq
Parameters:
poly: the polynomial which is used as the modulus.
Returns a new ModulusPolynomialRingZq object with the coefficients
and modulus from the PolyOverZq instance.
§Examples
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
let mod_poly = ModulusPolynomialRingZq::try_from(&poly).unwrap();§Panics …
- if
modulusis smaller than2, or - if the modulus polynomial is of degree smaller than
1.
Source§impl From<&PolyOverZq> for PolyOverZq
impl From<&PolyOverZq> for PolyOverZq
Source§fn from(value: &PolyOverZq) -> Self
fn from(value: &PolyOverZq) -> Self
Alias for PolyOverZq::clone.
Source§impl From<&PolyOverZq> for String
impl From<&PolyOverZq> for String
Source§fn from(value: &PolyOverZq) -> Self
fn from(value: &PolyOverZq) -> Self
Converts a PolyOverZq into its String representation.
Parameters:
value: specifies the polynommial that will be represented as aString
Returns a String of the form "[#number of coefficients]⌴⌴[0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[q]".
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("2 2 1 mod 3").unwrap();
let string: String = poly.into();Source§impl From<&Zq> for PolyOverZq
impl From<&Zq> for PolyOverZq
Source§fn from(value: &Zq) -> Self
fn from(value: &Zq) -> Self
Creates a constant PolyOverZq, i.e. the polynomial x mod q,
where x is the value of the given Zq value and q its modulus.
Parameters:
value: the constant value the polynomial will have.
Returns a new constant PolyOverZq with the specified value and modulus of the Zq value.
§Examples
use qfall_math::{integer_mod_q::*, traits::*};
let poly = PolyOverZq::from(&Zq::from((1, 10)));
let poly_cmp = PolyOverZq::from((1, 10));
assert_eq!(poly, poly_cmp);
assert_eq!(poly.get_degree(), 0);Source§impl<Mod: Into<Modulus>> From<(&PolyOverZ, Mod)> for PolyOverZq
impl<Mod: Into<Modulus>> From<(&PolyOverZ, Mod)> for PolyOverZq
Source§fn from((poly, modulus): (&PolyOverZ, Mod)) -> Self
fn from((poly, modulus): (&PolyOverZ, Mod)) -> Self
Creates a PolyOverZq from a PolyOverZ and a value that implements Into<Modulus>.
Parameters:
poly: the coefficients of the polynomial.modulus: the modulus by which each entry is reduced.
Returns a new PolyOverZq with the coefficients from the
PolyOverZ instance under the specified Modulus value.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, Modulus};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("4 0 1 102 3").unwrap();
let modulus = Modulus::from(100);
let mod_poly = PolyOverZq::from((&poly, &modulus));
§Panics …
- if
modulusis smaller than2.
Source§impl<Integer: Into<Z>, Mod: Into<Modulus>> From<(Integer, Mod)> for PolyOverZq
impl<Integer: Into<Z>, Mod: Into<Modulus>> From<(Integer, Mod)> for PolyOverZq
Source§fn from((z, modulus): (Integer, Mod)) -> Self
fn from((z, modulus): (Integer, Mod)) -> Self
Creates a PolyOverZq from any values that implement Into<Z> and Into<Modulus>,
where the second value must be larger than 1.
Parameters:
z: the single, constant coefficient of the polynomial.modulus: the modulus by which each entry is reduced.
Returns a new constant PolyOverZq with the specified z and modulus value.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let mod_poly = PolyOverZq::from((5, 42));
§Panics …
- if
modulusis smaller than2.
Source§impl<Mod: Into<Modulus>> From<(PolyOverZ, Mod)> for PolyOverZq
impl<Mod: Into<Modulus>> From<(PolyOverZ, Mod)> for PolyOverZq
Source§fn from((poly, modulus): (PolyOverZ, Mod)) -> Self
fn from((poly, modulus): (PolyOverZ, Mod)) -> Self
Creates a PolyOverZq from a PolyOverZ and a value that implements Into<Modulus>.
Parameters:
poly: the coefficients of the polynomial.modulus: the modulus by which each entry is reduced.
Returns a new PolyOverZq with the coefficients from the
PolyOverZ instance under the specified Modulus value.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("4 0 1 102 3").unwrap();
let mod_poly = PolyOverZq::from((poly, 100));
§Panics …
- if
modulusis smaller than2.
Source§impl<Mod: Into<Modulus>> From<Mod> for PolyOverZq
impl<Mod: Into<Modulus>> From<Mod> for PolyOverZq
Source§fn from(modulus: Mod) -> Self
fn from(modulus: Mod) -> Self
Creates a zero polynomial with a given Modulus.
Parameters:
modulus: of the newPolyOverZq
Returns a new constant PolyOverZq with the specified Modulus.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from(100);
let poly_cmp = PolyOverZq::from_str("0 mod 100").unwrap();
assert_eq!(poly, poly_cmp);§Panics …
- if
modulusis smaller than2.
Source§impl From<ModulusPolynomialRingZq> for PolyOverZq
impl From<ModulusPolynomialRingZq> for PolyOverZq
Source§fn from(value: ModulusPolynomialRingZq) -> Self
fn from(value: ModulusPolynomialRingZq) -> Self
Documentation can be found at PolyOverZq::from for &ModulusPolynomialRingZq.
Source§impl From<PolyOverZq> for ModulusPolynomialRingZq
impl From<PolyOverZq> for ModulusPolynomialRingZq
Source§fn from(value: PolyOverZq) -> Self
fn from(value: PolyOverZq) -> Self
Documentation can be found at ModulusPolynomialRingZq::from for &PolyOverZq.
Source§impl From<PolyOverZq> for String
impl From<PolyOverZq> for String
Source§fn from(value: PolyOverZq) -> Self
fn from(value: PolyOverZq) -> Self
Documentation can be found at String::from for &PolyOverZq.
Source§impl From<Zq> for PolyOverZq
impl From<Zq> for PolyOverZq
Source§impl FromCoefficientEmbedding<&MatZq> for PolyOverZq
impl FromCoefficientEmbedding<&MatZq> for PolyOverZq
Source§fn from_coefficient_embedding(embedding: &MatZq) -> Self
fn from_coefficient_embedding(embedding: &MatZq) -> Self
Computes a polynomial from a vector.
The first i-th entry of the column vector is taken
as the coefficient of the polynomial.
It inverts the operation of
PolyOverZq::into_coefficient_embedding.
Parameters:
embedding: the column vector that encodes the embedding
Returns a polynomial that corresponds to the embedding.
§Examples
use std::str::FromStr;
use qfall_math::{
integer_mod_q::{MatZq, PolyOverZq},
traits::FromCoefficientEmbedding,
};
let vector = MatZq::from_str("[[17],[3],[-5]] mod 19").unwrap();
let poly = PolyOverZq::from_coefficient_embedding(&vector);
let cmp_poly = PolyOverZq::from_str("3 17 3 -5 mod 19").unwrap();
assert_eq!(cmp_poly, poly);§Panics …
- if the provided embedding is not a column vector.
Source§impl FromStr for PolyOverZq
impl FromStr for PolyOverZq
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a polynomial with arbitrarily many coefficients of type Zq.
Warning: If the input string starts with a correctly formatted PolyOverZ object,
the rest of the string until the "mod" is ignored. This means that the input string
"4 0 1 2 3 mod 13" is the same as "4 0 1 2 3 4 5 6 7 mod 13".
Parameters:
s: the polynomial of form:"[#number of coefficients]⌴⌴[0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[modulus]".
Note that the [#number of coefficients] and [0th coefficient]
are divided by two spaces and the string for the polynomial is trimmed,
i.e. all whitespaces before around the polynomial and the modulus are ignored.
Returns a PolyOverZq or an error if the provided string was not
formatted correctly, the number of coefficients was smaller than the number provided
at the start of the provided string, or the modulus was smaller than 2.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("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
Modulus, - if the number of coefficients was smaller than the number provided at the start of the provided string,
- if the provided value did not contain two whitespaces, or
- if the delimiter
modcould not be found.
- if the provided first half of the string was not formatted correctly to
create a
- Returns a
MathErrorof typeInvalidModulusifmodulusis smaller than2.
Source§impl GetCoefficient<Z> for PolyOverZq
impl GetCoefficient<Z> for PolyOverZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
Returns the coefficient of a polynomial PolyOverZq 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_mod_q::PolyOverZq;
use qfall_math::integer::Z;
use std::str::FromStr;
let poly = PolyOverZq::from_str("4 0 1 2 3 mod 17").unwrap();
let coeff_0: Z = poly.get_coeff(0).unwrap();
let coeff_1: Z = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4: Z = poly.get_coeff(4).unwrap();
assert_eq!(Z::ZERO, coeff_0);
assert_eq!(Z::ONE, coeff_1);
assert_eq!(Z::ZERO, coeff_4);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl GetCoefficient<Zq> for PolyOverZq
impl GetCoefficient<Zq> for PolyOverZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
Returns the coefficient of a polynomial PolyOverZq 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::PolyOverZq;
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("4 0 1 2 3 mod 17").unwrap();
let coeff_0: Zq = poly.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4: Zq = poly.get_coeff(4).unwrap();
assert_eq!(Zq::from((0, 17)), coeff_0);
assert_eq!(Zq::from((1, 17)), coeff_1);
assert_eq!(Zq::from((0, 17)), coeff_4);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl IntoCoefficientEmbedding<MatZq> for &PolyOverZq
impl IntoCoefficientEmbedding<MatZq> for &PolyOverZq
Source§fn into_coefficient_embedding(self, size: impl Into<i64>) -> MatZq
fn into_coefficient_embedding(self, size: impl Into<i64>) -> MatZq
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.
It inverts the operation of PolyOverZq::from_coefficient_embedding.
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, PolyOverZq},
traits::IntoCoefficientEmbedding,
};
let poly = PolyOverZq::from_str("3 17 3 -5 mod 19").unwrap();
let vector = poly.into_coefficient_embedding(4);
let cmp_vector = MatZq::from_str("[[17],[3],[-5],[0]] mod 19").unwrap();
assert_eq!(cmp_vector, vector);§Panics …
- if
sizeis not larger than the degree of the polynomial, i.e. not all coefficients can be embedded.
Source§impl Mul<&PolyOverZ> for &PolyOverZq
impl Mul<&PolyOverZ> for &PolyOverZq
Source§fn mul(self, other: &PolyOverZ) -> Self::Output
fn mul(self, other: &PolyOverZ) -> Self::Output
Implements the Mul trait for PolyOverZq 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 PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolyOverZq = &a * &b;Source§type Output = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl Mul<&PolyOverZq> for &MatPolynomialRingZq
impl Mul<&PolyOverZq> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &PolyOverZq) -> Self::Output
fn mul(self, scalar: &PolyOverZq) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a PolyOverZq.
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, PolyOverZq};
use qfall_math::integer::{MatPolyOverZ, 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 = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
let poly_ring_mat2 = &poly_ring_mat1 * &poly;§Panics …
- if the moduli mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* 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<&Z> for &PolyOverZq
impl Mul<&Z> for &PolyOverZq
Source§fn mul(self, scalar: &Z) -> Self::Output
fn mul(self, scalar: &Z) -> Self::Output
Implements the Mul trait for a PolyOverZq with a Z integer.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Z using PolyOverZq.
Parameters:
scalar: specifies the scalar by which the polynomial is multiplied
Returns the product of self and scalar as a PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::Z;
use std::str::FromStr;
let poly_1 = PolyOverZq::from_str("4 1 2 3 4 mod 17").unwrap();
let integer = Z::from(3);
let poly_2 = &poly_1 * &integer;Source§type Output = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl Mul<&Zq> for &PolyOverZq
impl Mul<&Zq> for &PolyOverZq
Source§fn mul(self, scalar: &Zq) -> PolyOverZq
fn mul(self, scalar: &Zq) -> PolyOverZq
Implements the Mul trait for a PolyOverZq with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Zq using PolyOverZq.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a PolyOverZq.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, Zq};
use std::str::FromStr;
let poly_1 = PolyOverZq::from_str("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 = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl Mul for &PolyOverZq
impl Mul for &PolyOverZq
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Implements the Mul trait for two PolyOverZq values.
Mul is implemented for any combination of PolyOverZq and borrowed PolyOverZq.
Parameters:
other: specifies the polynomial to multiply withself
Returns the product of both polynomials as a PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("3 2 4 1 mod 7").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 5 1 1 mod 7").unwrap();
let c: PolyOverZq = &a * &b;
let d: PolyOverZq = a * b;
let e: PolyOverZq = &c * d;
let f: PolyOverZq = c * &e;§Panics …
- if the moduli of both
PolyOverZqmismatch.
Source§type Output = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl MulAssign<&PolyOverZ> for PolyOverZq
impl MulAssign<&PolyOverZ> for PolyOverZq
Source§fn mul_assign(&mut self, other: &PolyOverZ)
fn mul_assign(&mut self, other: &PolyOverZ)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<&PolyOverZq> for MatPolynomialRingZq
impl MulAssign<&PolyOverZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, scalar: &PolyOverZq)
fn mul_assign(&mut self, scalar: &PolyOverZq)
Documentation at MatPolynomialRingZq::mul_assign.
Performs underlying scalar multiplication as PolyOverZ and then applies the reduction.
§Panics …
- if the moduli are different.
Source§impl MulAssign<&PolyOverZq> for PolyOverZq
impl MulAssign<&PolyOverZq> for PolyOverZq
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 PolyOverZq in combination with
PolyOverZq and PolyOverZ.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials modulo q as a PolyOverZq.
§Examples
use qfall_math::{integer_mod_q::PolyOverZq, integer::PolyOverZ};
use std::str::FromStr;
let mut a = PolyOverZq::from_str("3 1 2 3 mod 7").unwrap();
let b = PolyOverZq::from_str("5 1 2 -3 0 4 mod 7").unwrap();
let c = PolyOverZ::from_str("4 -1 2 5 3").unwrap();
a *= &b;
a *= b;
a *= &c;
a *= c;§Panics …
- if the moduli of both
PolyOverZqmismatch.
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<&Z> for PolyOverZq
impl MulAssign<&Z> for PolyOverZq
Source§fn mul_assign(&mut self, scalar: &Z)
fn mul_assign(&mut self, scalar: &Z)
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 polynomial as a PolyOverZq.
§Examples
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::{PolyOverZq, Zq};
use std::str::FromStr;
let mut a = PolyOverZq::from_str("3 1 2 -3 mod 5").unwrap();
let b = Z::from(2);
let c = Zq::from((17, 5));
a *= &b;
a *= &c;
a *= b;
a *= c;
a *= 2;
a *= -2;Source§impl MulAssign<&Zq> for PolyOverZq
impl MulAssign<&Zq> for PolyOverZq
Source§fn mul_assign(&mut self, scalar: &Zq)
fn mul_assign(&mut self, scalar: &Zq)
Source§impl MulAssign<PolyOverZ> for PolyOverZq
impl MulAssign<PolyOverZ> for PolyOverZq
Source§fn mul_assign(&mut self, other: PolyOverZ)
fn mul_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<PolyOverZq> for MatPolynomialRingZq
impl MulAssign<PolyOverZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, other: PolyOverZq)
fn mul_assign(&mut self, other: PolyOverZq)
Documentation at MatPolynomialRingZq::mul_assign.
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<Z> for PolyOverZq
impl MulAssign<Z> for PolyOverZq
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<Zq> for PolyOverZq
impl MulAssign<Zq> for PolyOverZq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<i16> for PolyOverZq
impl MulAssign<i16> for PolyOverZq
Source§fn mul_assign(&mut self, other: i16)
fn mul_assign(&mut self, other: i16)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<i32> for PolyOverZq
impl MulAssign<i32> for PolyOverZq
Source§fn mul_assign(&mut self, other: i32)
fn mul_assign(&mut self, other: i32)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<i64> for PolyOverZq
impl MulAssign<i64> for PolyOverZq
Source§fn mul_assign(&mut self, other: i64)
fn mul_assign(&mut self, other: i64)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<i8> for PolyOverZq
impl MulAssign<i8> for PolyOverZq
Source§fn mul_assign(&mut self, other: i8)
fn mul_assign(&mut self, other: i8)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<u16> for PolyOverZq
impl MulAssign<u16> for PolyOverZq
Source§fn mul_assign(&mut self, other: u16)
fn mul_assign(&mut self, other: u16)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<u32> for PolyOverZq
impl MulAssign<u32> for PolyOverZq
Source§fn mul_assign(&mut self, other: u32)
fn mul_assign(&mut self, other: u32)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<u64> for PolyOverZq
impl MulAssign<u64> for PolyOverZq
Source§fn mul_assign(&mut self, other: u64)
fn mul_assign(&mut self, other: u64)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<u8> for PolyOverZq
impl MulAssign<u8> for PolyOverZq
Source§fn mul_assign(&mut self, other: u8)
fn mul_assign(&mut self, other: u8)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign for PolyOverZq
impl MulAssign for PolyOverZq
Source§fn mul_assign(&mut self, other: PolyOverZq)
fn mul_assign(&mut self, other: PolyOverZq)
Documentation at PolyOverZq::mul_assign.
Source§impl PartialEq<PolyOverZq> for ModulusPolynomialRingZq
impl PartialEq<PolyOverZq> for ModulusPolynomialRingZq
Source§fn eq(&self, other: &PolyOverZq) -> bool
fn eq(&self, other: &PolyOverZq) -> bool
Checks if an integer matrix and a rational matrix are equal. Used by the == and != operators.
PartialEq is also implemented for PolyOverZq using ModulusPolynomialRingZq.
Parameters:
other: the other value that is used to compare the elements
Returns true if the elements are equal, otherwise false.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let a: ModulusPolynomialRingZq = ModulusPolynomialRingZq::from_str("3 1 2 3 mod 17").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 1 2 3 mod 17").unwrap();
// These are all equivalent and return true.
let compared: bool = (a == b);
let compared: bool = (b == a);
let compared: bool = (&a == &b);
let compared: bool = (&b == &a);
let compared: bool = (a.eq(&b));
let compared: bool = (b.eq(&a));
let compared: bool = (ModulusPolynomialRingZq::eq(&a, &b));
let compared: bool = (PolyOverZq::eq(&b, &a));Source§impl PartialEq for PolyOverZq
impl PartialEq for PolyOverZq
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Checks if two polynomials over Zq are equal.
Two PolyOverZq are considered equal if their modulus is equal and
all coefficients are equal modulus q.
Used by the == and != operators.
Parameters:
other: the other value that is used to compare the elements
Returns true if the elements are equal, otherwise false.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("2 42 1 mod 17").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("2 24 1 mod 19").unwrap();
// These are all equivalent and return false.
let compared: bool = (a == b);
let compared: bool = (&a == &b);
let compared: bool = (a.eq(&b));
let compared: bool = (PolyOverZq::eq(&a, &b));Source§impl Serialize for PolyOverZq
impl Serialize for PolyOverZq
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Implements the serialize option. This allows to create a Json-object from a given PolyOverZq.
Source§impl SetCoefficient<&Zq> for PolyOverZq
impl SetCoefficient<&Zq> for PolyOverZq
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 polynomial PolyOverZq.
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 from a borrowedZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::Zq;
use qfall_math::traits::*;
use std::str::FromStr;
let mut poly = PolyOverZq::from_str("4 0 1 2 3 mod 17").unwrap();
let value = Zq::from((1000, 17));
assert!(poly.set_coeff(4, &value).is_ok());
unsafe{ poly.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 PolyOverZq
impl<Integer: Into<Z>> SetCoefficient<Integer> for PolyOverZq
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 polynomial PolyOverZq.
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 coefficient will be set to.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::Z;
use qfall_math::traits::*;
use std::str::FromStr;
let mut poly = PolyOverZq::from_str("4 0 1 2 3 mod 17").unwrap();
assert!(poly.set_coeff(4, 1000).is_ok());
unsafe{ poly.set_coeff_unchecked(5, 75) };§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 PolyOverZq
impl SetCoefficient<Zq> for PolyOverZq
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 PolyOverZq::set_coeff for &Zq.
Source§impl Sub<&PolyOverZ> for &PolyOverZq
impl Sub<&PolyOverZ> for &PolyOverZq
Source§fn sub(self, other: &PolyOverZ) -> Self::Output
fn sub(self, other: &PolyOverZ) -> Self::Output
Implements the Sub trait for PolyOverZq 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 PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolyOverZq = &a - &b;Source§type Output = PolyOverZq
type Output = PolyOverZq
- operator.Source§impl Sub<&PolyOverZq> for &PolyOverZ
impl Sub<&PolyOverZq> for &PolyOverZ
Source§fn sub(self, other: &PolyOverZq) -> Self::Output
fn sub(self, other: &PolyOverZq) -> Self::Output
Implements the Sub trait for PolyOverZ 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 PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
let c: PolyOverZq = &a - &b;Source§type Output = PolyOverZq
type Output = PolyOverZq
- 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 &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 &PolyOverZq
impl Sub for &PolyOverZq
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Implements the Sub trait for two PolyOverZq values.
Sub is implemented for any combination of PolyOverZq and borrowed PolyOverZq.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the result of the subtraction of both polynomials as a PolyOverZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let a: PolyOverZq = PolyOverZq::from_str("3 2 4 1 mod 7").unwrap();
let b: PolyOverZq = PolyOverZq::from_str("3 5 1 1 mod 7").unwrap();
let c: PolyOverZq = &a - &b;
let d: PolyOverZq = a - b;
let e: PolyOverZq = &c - d;
let f: PolyOverZq = c - &e;§Panics …
- if the moduli of both
PolyOverZqmismatch.
Source§type Output = PolyOverZq
type Output = PolyOverZq
- operator.Source§impl SubAssign<&PolyOverZ> for PolyOverZq
impl SubAssign<&PolyOverZ> for PolyOverZq
Source§fn sub_assign(&mut self, other: &PolyOverZ)
fn sub_assign(&mut self, other: &PolyOverZ)
Documentation at PolyOverZq::sub_assign.
Source§impl SubAssign<&PolyOverZq> for PolyOverZq
impl SubAssign<&PolyOverZq> for PolyOverZq
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 PolyOverZq in combination with
PolyOverZq and PolyOverZ.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the difference of both polynomials modulo q as a PolyOverZq.
§Examples
use qfall_math::{integer_mod_q::PolyOverZq, integer::PolyOverZ};
use std::str::FromStr;
let mut a = PolyOverZq::from_str("3 1 2 3 mod 7").unwrap();
let b = PolyOverZq::from_str("5 1 2 -3 0 4 mod 7").unwrap();
let c = PolyOverZ::from_str("4 -1 2 5 3").unwrap();
a -= &b;
a -= b;
a -= &c;
a -= c;§Panics …
- if the moduli of both
PolyOverZqmismatch.
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<PolyOverZ> for PolyOverZq
impl SubAssign<PolyOverZ> for PolyOverZq
Source§fn sub_assign(&mut self, other: PolyOverZ)
fn sub_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverZq::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 PolyOverZq
impl SubAssign for PolyOverZq
Source§fn sub_assign(&mut self, other: PolyOverZq)
fn sub_assign(&mut self, other: PolyOverZq)
Documentation at PolyOverZq::sub_assign.