pub struct PolyOverZ { /* private fields */ }Expand description
PolyOverZ is a type of polynomial with arbitrarily many coefficients of type
Z.
§Examples
use qfall_math::integer::{PolyOverZ, Z};
use qfall_math::traits::*;
use std::str::FromStr;
// instantiations
let poly_1 = PolyOverZ::from_str("4 0 1 2 3").unwrap();
let poly_2 = PolyOverZ::default();
// arithmetic operations
let _ = &poly_1 + &poly_2;
let _ = &poly_1 * &poly_2;
// evaluate function
let value = Z::from(3);
let res: Z = poly_1.evaluate(&value);
// comparison
assert_ne!(poly_1, poly_2);Implementations§
Source§impl PolyOverZ
impl PolyOverZ
Sourcepub fn dot_product(&self, other: &Self) -> Result<Z, MathError>
pub fn dot_product(&self, other: &Self) -> Result<Z, MathError>
Returns the dot product of two polynomials of type PolyOverZ.
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 PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly_1 = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
let poly_2 = PolyOverZ::from(42);
let dot_prod = poly_1.dot_product(&poly_2).unwrap();Source§impl PolyOverZ
impl PolyOverZ
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.
§Examples
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let poly = PolyOverZ::from_str("3 1 2 3").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.
§Examples
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let poly = PolyOverZ::from_str("3 1 2 3").unwrap();
let infty_norm = poly.norm_infty();
// max coefficient is 3
assert_eq!(Z::from(3), infty_norm);Source§impl PolyOverZ
impl PolyOverZ
Sourcepub fn reduce_by_poly(&mut self, modulus: &PolyOverZ)
pub fn reduce_by_poly(&mut self, modulus: &PolyOverZ)
Reduces a polynomial by a polynomial modulus.
The modulus must have a leading coefficient of 1, else the function will panic.
Parameters:
modulus: Specifies the polynomial by whichselfis reduced
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let mut a = PolyOverZ::from_str("4 0 0 2 3").unwrap();
let modulus = PolyOverZ::from_str("3 0 1 1").unwrap();
a.reduce_by_poly(&modulus);
assert_eq!(PolyOverZ::from_str("2 0 1").unwrap(), a);§Panics …
- if the modulus does not have a leading coefficient of
1.
Source§impl PolyOverZ
impl PolyOverZ
Sourcepub fn sample_binomial(
max_degree: impl TryInto<i64> + Display,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial( max_degree: impl TryInto<i64> + Display, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Generates a PolyOverZ 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 coefficientsn: specifies the number of trialsp: specifies the probability of success
Returns a fresh PolyOverZ 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::PolyOverZ;
let sample = PolyOverZ::sample_binomial(2, 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>,
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>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Generates a PolyOverZ 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 distributionn: specifies the number of trialsp: specifies the probability of success
Returns a fresh PolyOverZ 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::PolyOverZ;
let sample = PolyOverZ::sample_binomial_with_offset(2, -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. - Returns a
MathErrorof typeOutOfBoundsif themax_degreeis negative or it does not fit into ani64.
Source§impl PolyOverZ
impl PolyOverZ
Sourcepub fn sample_discrete_gauss(
max_degree: impl TryInto<i64> + Display,
center: impl Into<Q>,
s: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_discrete_gauss( max_degree: impl TryInto<i64> + Display, center: impl Into<Q>, s: impl Into<Q>, ) -> Result<Self, MathError>
Initializes a new PolyOverZ 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 createdPolyOverZshould havecenter: 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 PolyOverZ 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::PolyOverZ;
let sample = PolyOverZ::sample_discrete_gauss(2, 0, 1).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifs < 0.
§Panics …
- if
max_degreeis negative, or does not fit into ani64.
Source§impl PolyOverZ
impl PolyOverZ
Sourcepub fn sample_uniform(
max_degree: impl TryInto<i64> + Display,
lower_bound: impl Into<Z>,
upper_bound: impl Into<Z>,
) -> Result<Self, MathError>
pub fn sample_uniform( max_degree: impl TryInto<i64> + Display, lower_bound: impl Into<Z>, upper_bound: impl Into<Z>, ) -> Result<Self, MathError>
Generates a PolyOverZ instance of maximum degree max_degree and coefficients
chosen uniform at random in [lower_bound, upper_bound).
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 coefficientslower_bound: specifies the included lower bound of the interval over which is sampledupper_bound: specifies the excluded upper bound of the interval over which is sampled
Returns a fresh PolyOverZ instance of length max_degree with coefficients
chosen uniform at random in [lower_bound, upper_bound) or a MathError
if the max_degree was smaller than 0 or the provided interval was chosen too small.
§Examples
use qfall_math::integer::{PolyOverZ, Z};
let sample = PolyOverZ::sample_uniform(3, 17, 26).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntervalif the givenupper_boundisn’t at least larger thanlower_bound. - Returns a
MathErrorof typeOutOfBoundsif themax_degreeis negative or it does not fit into ani64.
Source§impl PolyOverZ
impl PolyOverZ
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 field poly of type fmpz_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 PolyOverZ
impl PolyOverZ
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 poly of type fmpz_poly_struct 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.
Trait Implementations§
Source§impl Add<&PolyOverZ> for &PolyOverQ
impl Add<&PolyOverZ> for &PolyOverQ
Source§fn add(self, other: &PolyOverZ) -> Self::Output
fn add(self, other: &PolyOverZ) -> Self::Output
Implements the Add trait for PolyOverQ 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 PolyOverQ.
§Examples
use qfall_math::rational::PolyOverQ;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverQ::from_str("4 1/2 0 3/7 1").unwrap();
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolyOverQ = &a + &b;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<&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<&PolyOverZ> for &Z
impl Add<&PolyOverZ> for &Z
Source§fn add(self, other: &PolyOverZ) -> Self::Output
fn add(self, other: &PolyOverZ) -> Self::Output
Implements the Add trait for Z and PolyOverZ values.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;
let a: Z = Z::from(42);
let b: PolyOverZ = PolyOverZ::from_str("4 5 1 2 3").unwrap();
let c: PolyOverZ = &a + &b;
let d: PolyOverZ = a + b;
let e: PolyOverZ = &Z::from(42) + d;
let f: PolyOverZ = Z::from(42) + &e;Source§impl Add<&Z> for &PolyOverZ
impl Add<&Z> for &PolyOverZ
Source§fn add(self, other: &Z) -> Self::Output
fn add(self, other: &Z) -> Self::Output
Implements the Add trait for PolyOverZ and Z values.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies theZto add toself
Returns the sum of both as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;
let b: PolyOverZ = PolyOverZ::from_str("4 5 1 2 3").unwrap();
let a: Z = Z::from(42);
let c: PolyOverZ = &a + &b;
let d: PolyOverZ = a + b;
let e: PolyOverZ = d + &Z::from(42);
let f: PolyOverZ = &e + Z::from(42);Source§impl Add for &PolyOverZ
impl Add for &PolyOverZ
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Implements the Add trait for two PolyOverZ values.
Add is implemented for any combination of PolyOverZ and borrowed PolyOverZ.
Parameters:
other: specifies the value to add toself
Returns the sum of both polynomials as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b: PolyOverZ = PolyOverZ::from_str("5 1 2 -3 0 8").unwrap();
let c: PolyOverZ = &a + &b;
let d: PolyOverZ = a + b;
let e: PolyOverZ = &c + d;
let f: PolyOverZ = c + &e;Source§impl AddAssign<&PolyOverZ> for PolyOverQ
impl AddAssign<&PolyOverZ> for PolyOverQ
Source§fn add_assign(&mut self, other: &PolyOverZ)
fn add_assign(&mut self, other: &PolyOverZ)
Documentation at PolyOverQ::add_assign.
Source§impl AddAssign<&PolyOverZ> for PolyOverZ
impl AddAssign<&PolyOverZ> for PolyOverZ
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.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let mut a = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b = PolyOverZ::from_str("5 1 2 -3 0 8").unwrap();
a += &b;
a += b;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<&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<PolyOverZ> for PolyOverQ
impl AddAssign<PolyOverZ> for PolyOverQ
Source§fn add_assign(&mut self, other: PolyOverZ)
fn add_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverQ::add_assign.
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<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 for PolyOverZ
impl AddAssign for PolyOverZ
Source§fn add_assign(&mut self, other: PolyOverZ)
fn add_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverZ::add_assign.
Source§impl Clone for PolyOverZ
impl Clone for PolyOverZ
Source§impl CompareBase<&PolyOverZ> for MatNTTPolynomialRingZq
impl CompareBase<&PolyOverZ> for MatNTTPolynomialRingZq
Source§impl CompareBase<&PolyOverZ> for MatPolyOverZ
impl CompareBase<&PolyOverZ> for MatPolyOverZ
Source§impl CompareBase<&PolyOverZ> for MatPolynomialRingZq
impl CompareBase<&PolyOverZ> for MatPolynomialRingZq
Source§impl CompareBase<&PolyOverZ> for NTTPolynomialRingZq
impl CompareBase<&PolyOverZ> for NTTPolynomialRingZq
Source§impl CompareBase<&PolyOverZ> for PolyOverZq
impl CompareBase<&PolyOverZ> for PolyOverZq
Source§impl CompareBase<&PolyOverZ> for PolynomialRingZq
impl CompareBase<&PolyOverZ> for PolynomialRingZq
Source§impl<Integer: Into<Z>> CompareBase<Integer> for PolyOverZ
impl<Integer: Into<Z>> CompareBase<Integer> for PolyOverZ
Source§impl CompareBase<PolyOverZ> for MatNTTPolynomialRingZq
impl CompareBase<PolyOverZ> for MatNTTPolynomialRingZq
Source§impl CompareBase<PolyOverZ> for MatPolyOverZ
impl CompareBase<PolyOverZ> for MatPolyOverZ
Source§impl CompareBase<PolyOverZ> for MatPolynomialRingZq
impl CompareBase<PolyOverZ> for MatPolynomialRingZq
Source§impl CompareBase<PolyOverZ> for NTTPolynomialRingZq
impl CompareBase<PolyOverZ> for NTTPolynomialRingZq
Source§impl CompareBase<PolyOverZ> for PolyOverQ
impl CompareBase<PolyOverZ> for PolyOverQ
Source§impl CompareBase<PolyOverZ> for PolyOverZq
impl CompareBase<PolyOverZ> for PolyOverZq
Source§impl CompareBase<PolyOverZ> for PolynomialRingZq
impl CompareBase<PolyOverZ> for PolynomialRingZq
Source§impl CompareBase for PolyOverZ
impl CompareBase for PolyOverZ
Source§impl<'de> Deserialize<'de> for PolyOverZ
impl<'de> Deserialize<'de> for PolyOverZ
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 PolyOverZ from a given Json-object.
Source§impl Display for PolyOverZ
impl Display for PolyOverZ
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Allows to convert a polynomial of type PolyOverZ into a String.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
use core::fmt;
let poly = PolyOverZ::from_str("4 0 1 2 3").unwrap();
println!("{poly}");use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("4 0 1 2 3").unwrap();
let poly_string = poly.to_string();Source§impl Drop for PolyOverZ
impl Drop for PolyOverZ
Source§fn drop(&mut self)
fn drop(&mut self)
Drops the given PolyOverZ value and frees the allocated memory.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
{
let a = PolyOverZ::from_str("3 0 1 2").unwrap();
} // as a's scope ends here, it get's droppeduse qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverZ::from_str("3 0 1 2").unwrap();
drop(a); // explicitly drops a's valueSource§impl<Integer: Into<Z>> Evaluate<Integer, Z> for PolyOverZ
impl<Integer: Into<Z>> Evaluate<Integer, Z> for PolyOverZ
Source§fn evaluate(&self, value: Integer) -> Z
fn evaluate(&self, value: Integer) -> Z
Evaluates a PolyOverZ on a given input.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Z.
§Examples
use qfall_math::traits::*;
use qfall_math::integer::Z;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("5 0 1 2 -3 1").unwrap();
let res: Z = poly.evaluate(3);Source§impl<Rational: Into<Q>> Evaluate<Rational, Q> for PolyOverZ
impl<Rational: Into<Q>> Evaluate<Rational, Q> for PolyOverZ
Source§fn evaluate(&self, value: Rational) -> Q
fn evaluate(&self, value: Rational) -> Q
Evaluates a PolyOverZ on a given input.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Q.
§Examples
use qfall_math::traits::*;
use qfall_math::rational::Q;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("5 0 1 2 -3 1").unwrap();
let value = Q::from((3, 2));
let res: Q = poly.evaluate(&value);Source§impl From<&PolyOverZ> for PolyOverQ
impl From<&PolyOverZ> for PolyOverQ
Source§fn from(poly: &PolyOverZ) -> Self
fn from(poly: &PolyOverZ) -> Self
Creates a PolyOverQ from a PolyOverZ.
Parameters:
poly: the polynomial from which the coefficients are copied
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::rational::PolyOverQ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("4 0 1 102 3").unwrap();
let poly_q = PolyOverQ::from(&poly);
Source§impl From<&PolyOverZ> for PolyOverZ
impl From<&PolyOverZ> for PolyOverZ
Source§fn from(value: &PolyOverZ) -> Self
fn from(value: &PolyOverZ) -> Self
Alias for PolyOverZ::clone.
Source§impl From<&PolyOverZ> for String
impl From<&PolyOverZ> for String
Source§fn from(value: &PolyOverZ) -> Self
fn from(value: &PolyOverZ) -> Self
Converts a PolyOverZ into its String representation.
Parameters:
value: specifies the polynomial that will be represented as aString
Returns a String of the form "[#number of coefficients]⌴⌴[0th coefficient]⌴[1st coefficient]⌴...".
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("2 6 1").unwrap();
let string: String = poly.into();Source§impl<Integer: AsInteger + Into<Z>> From<Integer> for PolyOverZ
impl<Integer: AsInteger + Into<Z>> From<Integer> for PolyOverZ
Source§fn from(value: Integer) -> Self
fn from(value: Integer) -> Self
Creates a constant PolyOverZ with a specified integer constant.
Parameters:
value: an integer like Z, rust Integers or a reference to these values.
Returns a new constant polynomial with the specified value.
§Examples
use qfall_math::{integer::*, traits::*};
let one = PolyOverZ::from(1);
assert_eq!(one.get_coeff(0).unwrap(), Z::ONE);
assert_eq!(one.get_degree(), 0);Source§impl FromCoefficientEmbedding<&MatZ> for PolyOverZ
impl FromCoefficientEmbedding<&MatZ> for PolyOverZ
Source§fn from_coefficient_embedding(embedding: &MatZ) -> Self
fn from_coefficient_embedding(embedding: &MatZ) -> 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
PolyOverZ::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::{MatZ, PolyOverZ},
traits::FromCoefficientEmbedding,
};
let vector = MatZ::from_str("[[17],[3],[-5]]").unwrap();
let poly = PolyOverZ::from_coefficient_embedding(&vector);
let cmp_poly = PolyOverZ::from_str("3 17 3 -5").unwrap();
assert_eq!(cmp_poly, poly);§Panics …
- if the provided embedding is not a column vector.
Source§impl FromStr for PolyOverZ
impl FromStr for PolyOverZ
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 Z
from a String.
Warning: If the input string starts with a correctly formatted PolyOverZ object,
the rest of the string is ignored. This means that the input string
"4 0 1 2 3" is the same as "4 0 1 2 3 4 5 6 7".
Parameters:
s: the polynomial of form:"[#number of coefficients]⌴⌴[0th coefficient]⌴[1st coefficient]⌴...".
Note that the [#number of coefficients] and [0th coefficient]
are divided by two spaces and the input string is trimmed, i.e. all whitespaces
before and after are ignored.
Returns a PolyOverZ 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 provided string contains a Null Byte.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("4 0 1 2 3").unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::StringConversionError- if the provided string was not formatted correctly,
- 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 provided string contains a
NullByte.
Source§impl GetCoefficient<Z> for PolyOverZ
impl GetCoefficient<Z> for PolyOverZ
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 PolyOverZ 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::integer::{Z, PolyOverZ};
use std::str::FromStr;
use qfall_math::traits::*;
let poly = PolyOverZ::from_str("4 0 1 2 3").unwrap();
let coeff_0 = poly.get_coeff(0).unwrap();
let coeff_1 = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4 = 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 IntoCoefficientEmbedding<MatZ> for &PolyOverZ
impl IntoCoefficientEmbedding<MatZ> for &PolyOverZ
Source§fn into_coefficient_embedding(self, size: impl Into<i64>) -> MatZ
fn into_coefficient_embedding(self, size: impl Into<i64>) -> MatZ
Computes the coefficient embedding of the polynomial
in a MatZ as a column vector, where the i-th entry
of the vector corresponds to the i-th coefficient.
It inverts the operation of PolyOverZ::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::{MatZ, PolyOverZ},
traits::IntoCoefficientEmbedding,
};
let poly = PolyOverZ::from_str("3 17 3 -5").unwrap();
let vector = poly.into_coefficient_embedding(4);
let cmp_vector = MatZ::from_str("[[17],[3],[-5],[0]]").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 MatrixGetEntry<PolyOverZ> for MatPolyOverZ
impl MatrixGetEntry<PolyOverZ> for MatPolyOverZ
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolyOverZ
unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolyOverZ
Outputs the PolyOverZ 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 PolyOverZ 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::{MatPolyOverZ, PolyOverZ};
use qfall_math::traits::*;
use std::str::FromStr;
let matrix = MatPolyOverZ::from_str("[[1 1, 1 2],[1 3, 1 4],[0, 1 6]]").unwrap();
assert_eq!(PolyOverZ::from(2), unsafe { matrix.get_entry_unchecked(0, 1) });
assert_eq!(PolyOverZ::from(4), unsafe { matrix.get_entry_unchecked(1, 1) });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 MatrixGetEntry<PolyOverZ> for MatPolynomialRingZq
impl MatrixGetEntry<PolyOverZ> for MatPolynomialRingZq
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolyOverZ
unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolyOverZ
Outputs the PolyOverZ 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 PolyOverZ 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};
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: PolyOverZ = unsafe { poly_ring_mat.get_entry_unchecked(1, 0) };
let entry_2: PolyOverZ = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
assert_eq!(entry_1, PolyOverZ::from(0));
assert_eq!(entry_2, PolyOverZ::from(42));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<&PolyOverZ> for MatPolyOverZ
impl MatrixSetEntry<&PolyOverZ> for MatPolyOverZ
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: &PolyOverZ,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: &PolyOverZ, )
Sets the value of a specific matrix entry according to a given value of type PolyOverZ
without checking whether the coordinate is part of the matrix.
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::{MatPolyOverZ, PolyOverZ};
use qfall_math::traits::MatrixSetEntry;
use std::str::FromStr;
let mut matrix = MatPolyOverZ::new(2, 2);
let value = PolyOverZ::from_str("2 1 1").unwrap();
unsafe {
matrix.set_entry_unchecked(0, 1, &value);
matrix.set_entry_unchecked(1, 0, &PolyOverZ::from(2));
}
assert_eq!("[[0, 2 1 1],[1 2, 0]]", matrix.to_string());Source§impl MatrixSetEntry<&PolyOverZ> for MatPolynomialRingZq
impl MatrixSetEntry<&PolyOverZ> for MatPolynomialRingZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: &PolyOverZ,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: &PolyOverZ, ) -> Result<(), MathError>
Sets the value of a specific matrix entry according to a given value of type PolyOverZ.
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
Negative indices can be used to index from the back, e.g., -1 for
the last element.
Returns an empty Ok if the action could be performed successfully.
Otherwise, a MathError is returned if the specified entry is
not part of the matrix.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
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 = PolyOverZ::default();
poly_ring_mat.set_entry(0, 1, &value).unwrap();
poly_ring_mat.set_entry(-1, -1, &value).unwrap();
let mat_cmp = MatPolynomialRingZq::from((&MatPolyOverZ::new(2, 2), &modulus));
assert_eq!(poly_ring_mat, mat_cmp);§Errors and Failures
- Returns a
MathErrorof typeMathError::OutOfBoundsifroworcolumnare greater than the matrix size.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: &PolyOverZ,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: &PolyOverZ, )
Sets the value of a specific matrix entry according to a given value of type PolyOverZ
without checking whether the coordinate is part of the matrix, if the moduli match
or if the entry is reduced.
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};
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 = PolyOverZ::default();
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<PolyOverZ> for MatPolyOverZ
impl MatrixSetEntry<PolyOverZ> for MatPolyOverZ
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: PolyOverZ,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: PolyOverZ, ) -> Result<(), MathError>
Documentation can be found at MatPolyOverZ::set_entry for &PolyOverZ.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: PolyOverZ,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: PolyOverZ, )
Documentation can be found at MatPolyOverZ::set_entry for &PolyOverZ.
Source§impl MatrixSetEntry<PolyOverZ> for MatPolynomialRingZq
impl MatrixSetEntry<PolyOverZ> for MatPolynomialRingZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: PolyOverZ,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: PolyOverZ, ) -> Result<(), MathError>
Documentation can be found at MatPolynomialRingZq::set_entry for &PolyOverZ.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: PolyOverZ,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: PolyOverZ, )
Documentation can be found at MatPolynomialRingZq::set_entry for &PolyOverZ.
Source§impl Mul<&PolyOverZ> for &MatPolyOverZ
impl Mul<&PolyOverZ> for &MatPolyOverZ
Source§fn mul(self, scalar: &PolyOverZ) -> Self::Output
fn mul(self, scalar: &PolyOverZ) -> Self::Output
Implements the Mul trait for a MatPolyOverZ matrix with a PolyOverZ.
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 MatPolyOverZ.
§Examples
use qfall_math::integer::MatPolyOverZ;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let poly = PolyOverZ::from_str("3 1 2 3").unwrap();
let mat_2 = &mat_1 * &poly;Source§type Output = MatPolyOverZ
type Output = MatPolyOverZ
* operator.Source§impl Mul<&PolyOverZ> for &MatPolynomialRingZq
impl Mul<&PolyOverZ> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &PolyOverZ) -> Self::Output
fn mul(self, scalar: &PolyOverZ) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a PolyOverZ.
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_mat2 = &poly_ring_mat1 * &poly;Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&PolyOverZ> for &PolyOverQ
impl Mul<&PolyOverZ> for &PolyOverQ
Source§fn mul(self, other: &PolyOverZ) -> Self::Output
fn mul(self, other: &PolyOverZ) -> Self::Output
Implements the Mul trait for PolyOverQ 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 PolyOverQ.
§Examples
use qfall_math::rational::PolyOverQ;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverQ::from_str("4 1/2 0 3/7 1").unwrap();
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolyOverQ = &a * &b;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<&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<&Q> for &PolyOverZ
impl Mul<&Q> for &PolyOverZ
Source§fn mul(self, scalar: &Q) -> PolyOverQ
fn mul(self, scalar: &Q) -> PolyOverQ
Implements the Mul trait for a PolyOverZ with a Q.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Q using PolyOverZ.
Parameters:
scalar: specifies the scalar by which the polynomial is multiplied
Returns the product of self and scalar as a PolyOverQ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::rational::Q;
use std::str::FromStr;
let poly_1 = PolyOverZ::from_str("4 1 2 3 4").unwrap();
let rational = Q::from((3,2));
let poly_2 = &poly_1 * &rational;Source§impl Mul<&Z> for &PolyOverZ
impl Mul<&Z> for &PolyOverZ
Source§fn mul(self, scalar: &Z) -> Self::Output
fn mul(self, scalar: &Z) -> Self::Output
Implements the Mul trait for a PolyOverZ with a Z integer.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Z using PolyOverZ.
Parameters:
scalar: specifies the scalar by which the polynomial is multiplied
Returns the product of self and scalar as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;
let poly_1 = PolyOverZ::from_str("4 1 2 3 4").unwrap();
let integer = Z::from(3);
let poly_2 = &poly_1 * &integer;Source§impl Mul<&Zq> for &PolyOverZ
impl Mul<&Zq> for &PolyOverZ
Source§fn mul(self, scalar: &Zq) -> PolyOverZq
fn mul(self, scalar: &Zq) -> PolyOverZq
Implements the Mul trait for a PolyOverZ with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Zq using PolyOverZ.
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::PolyOverZ;
use qfall_math::integer_mod_q::{PolyOverZq, Zq};
use std::str::FromStr;
let poly_1 = PolyOverZ::from_str("4 1 2 3 4").unwrap();
let integer = Zq::from((3,17));
let poly_2 = &poly_1 * &integer;Source§type Output = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl Mul for &PolyOverZ
impl Mul for &PolyOverZ
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Implements the Mul trait for two PolyOverZ values.
Mul is implemented for any combination of PolyOverZ and borrowed PolyOverZ.
Parameters:
other: specifies the value to multiply withself
Returns the product of both polynomials as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b: PolyOverZ = PolyOverZ::from_str("5 1 2 -3 0 8").unwrap();
let c: PolyOverZ = &a * &b;
let d: PolyOverZ = a * b;
let e: PolyOverZ = &c * d;
let f: PolyOverZ = c * &e;Source§impl MulAssign<&PolyOverZ> for MatPolyOverZ
impl MulAssign<&PolyOverZ> for MatPolyOverZ
Source§fn mul_assign(&mut self, scalar: &PolyOverZ)
fn mul_assign(&mut self, scalar: &PolyOverZ)
Documentation at MatPolyOverZ::mul_assign.
Source§impl MulAssign<&PolyOverZ> for PolyOverQ
impl MulAssign<&PolyOverZ> for PolyOverQ
Source§fn mul_assign(&mut self, other: &PolyOverZ)
fn mul_assign(&mut self, other: &PolyOverZ)
Documentation at PolyOverQ::mul_assign.
Source§impl MulAssign<&PolyOverZ> for PolyOverZ
impl MulAssign<&PolyOverZ> for PolyOverZ
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.
Parameters:
other: specifies the polynomial to multiply toself
Returns the product of both polynomials as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let mut a = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b = PolyOverZ::from_str("5 1 2 -3 0 8").unwrap();
a *= &b;
a *= b;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<&Z> for PolyOverZ
impl MulAssign<&Z> for PolyOverZ
Source§fn mul_assign(&mut self, scalar: &Z)
fn mul_assign(&mut self, scalar: &Z)
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 polynomial as a PolyOverZ.
§Examples
use qfall_math::integer::{Z,PolyOverZ};
use std::str::FromStr;
let mut a = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b = Z::from(2);
a *= &b;
a *= b;
a *= 2;
a *= -2;Source§impl MulAssign<PolyOverZ> for MatPolyOverZ
impl MulAssign<PolyOverZ> for MatPolyOverZ
Source§fn mul_assign(&mut self, other: PolyOverZ)
fn mul_assign(&mut self, other: PolyOverZ)
Documentation at MatPolyOverZ::mul_assign.
Source§impl MulAssign<PolyOverZ> for PolyOverQ
impl MulAssign<PolyOverZ> for PolyOverQ
Source§fn mul_assign(&mut self, other: PolyOverZ)
fn mul_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverQ::mul_assign.
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<Z> for PolyOverZ
impl MulAssign<Z> for PolyOverZ
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<i16> for PolyOverZ
impl MulAssign<i16> for PolyOverZ
Source§fn mul_assign(&mut self, other: i16)
fn mul_assign(&mut self, other: i16)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<i32> for PolyOverZ
impl MulAssign<i32> for PolyOverZ
Source§fn mul_assign(&mut self, other: i32)
fn mul_assign(&mut self, other: i32)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<i64> for PolyOverZ
impl MulAssign<i64> for PolyOverZ
Source§fn mul_assign(&mut self, scalar: i64)
fn mul_assign(&mut self, scalar: i64)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<i8> for PolyOverZ
impl MulAssign<i8> for PolyOverZ
Source§fn mul_assign(&mut self, other: i8)
fn mul_assign(&mut self, other: i8)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<u16> for PolyOverZ
impl MulAssign<u16> for PolyOverZ
Source§fn mul_assign(&mut self, other: u16)
fn mul_assign(&mut self, other: u16)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<u32> for PolyOverZ
impl MulAssign<u32> for PolyOverZ
Source§fn mul_assign(&mut self, other: u32)
fn mul_assign(&mut self, other: u32)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<u64> for PolyOverZ
impl MulAssign<u64> for PolyOverZ
Source§fn mul_assign(&mut self, scalar: u64)
fn mul_assign(&mut self, scalar: u64)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<u8> for PolyOverZ
impl MulAssign<u8> for PolyOverZ
Source§fn mul_assign(&mut self, other: u8)
fn mul_assign(&mut self, other: u8)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign for PolyOverZ
impl MulAssign for PolyOverZ
Source§fn mul_assign(&mut self, other: PolyOverZ)
fn mul_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverZ::mul_assign.
Source§impl PartialEq<PolyOverZ> for PolyOverQ
impl PartialEq<PolyOverZ> for PolyOverQ
Source§fn eq(&self, other: &PolyOverZ) -> bool
fn eq(&self, other: &PolyOverZ) -> bool
Checks if an integer matrix and a rational matrix are equal. Used by the == and != operators.
PartialEq is also implemented for PolyOverZ using PolyOverQ.
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::PolyOverZ;
use qfall_math::rational::PolyOverQ;
use std::str::FromStr;
let a: PolyOverQ = PolyOverQ::from_str("3 1 2 3").unwrap();
let b: PolyOverZ = PolyOverZ::from_str("3 1 2 3").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 = (PolyOverQ::eq(&a, &b));
let compared: bool = (PolyOverZ::eq(&b, &a));Source§impl PartialEq for PolyOverZ
impl PartialEq for PolyOverZ
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Checks if two polynomials over Z are equal. 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::PolyOverZ;
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("2 42 1").unwrap();
let b: PolyOverZ = PolyOverZ::from_str("2 24 1").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 = (PolyOverZ::eq(&a, &b));Source§impl Rem<&Modulus> for &PolyOverZ
impl Rem<&Modulus> for &PolyOverZ
Source§fn rem(self, modulus: &Modulus) -> Self::Output
fn rem(self, modulus: &Modulus) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative values of self, the smallest positive representative is returned.
Parameters:
modulus: specifies a non-zero integer over which the positive remainder is computed
Returns self mod modulus as a PolyOverZ instance.
§Examples
use qfall_math::integer_mod_q::Modulus;
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("2 -2 42").unwrap();
let b = Modulus::from(24);
let c: PolyOverZ = a % b;Source§impl Rem<&Z> for &PolyOverZ
impl Rem<&Z> for &PolyOverZ
Source§fn rem(self, modulus: &Z) -> Self::Output
fn rem(self, modulus: &Z) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative coefficients in self, the smallest positive representative is returned.
Parameters:
modulus: specifies a non-zero integer over which the positive remainders are computed
Returns self mod modulus as a PolyOverZ instance.
§Examples
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("2 -2 42").unwrap();
let b: Z = Z::from(24);
let c: PolyOverZ = a % b;§Panics …
- if
modulusis smaller than2.
Source§impl<Mod: Into<ModulusPolynomialRingZq>> Rem<Mod> for &PolyOverZ
impl<Mod: Into<ModulusPolynomialRingZq>> Rem<Mod> for &PolyOverZ
Source§fn rem(self, modulus: Mod) -> Self::Output
fn rem(self, modulus: Mod) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative values of self, the smallest positive representative is returned.
Parameters:
modulus: specifies a non-zero integer over which the positive remainder is computed
Returns self mod modulus as a PolyOverZ instance.
§Examples
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("2 -2 42").unwrap();
let b = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 24").unwrap();
let c: PolyOverZ = &a % b;Source§impl<Mod: Into<ModulusPolynomialRingZq>> Rem<Mod> for PolyOverZ
impl<Mod: Into<ModulusPolynomialRingZq>> Rem<Mod> for PolyOverZ
Source§fn rem(self, modulus: Mod) -> Self::Output
fn rem(self, modulus: Mod) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative values of self, the smallest positive representative is returned.
Parameters:
modulus: specifies a non-zero integer over which the positive remainder is computed
Returns self mod modulus as a PolyOverZ instance.
§Examples
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("2 -2 42").unwrap();
let b = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 24").unwrap();
let c: PolyOverZ = a % b;Source§impl<Integer: Into<Z>> SetCoefficient<Integer> for PolyOverZ
impl<Integer: Into<Z>> SetCoefficient<Integer> for PolyOverZ
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 PolyOverZ.
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 qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use qfall_math::traits::*;
use std::str::FromStr;
let mut poly = PolyOverZ::from_str("4 0 1 2 3").unwrap();
assert!(poly.set_coeff(4, 1000).is_ok());
unsafe{ poly.set_coeff_unchecked(5, -1000) };§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 Sub<&PolyOverQ> for &PolyOverZ
impl Sub<&PolyOverQ> for &PolyOverZ
Source§fn sub(self, other: &PolyOverQ) -> Self::Output
fn sub(self, other: &PolyOverQ) -> Self::Output
Implements the Sub trait for PolyOverZ and PolyOverQ.
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 PolyOverQ.
§Examples
use qfall_math::rational::PolyOverQ;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let b = PolyOverQ::from_str("4 1/2 0 3/7 1").unwrap();
let c: PolyOverQ = &a - &b;Source§impl Sub<&PolyOverZ> for &PolyOverQ
impl Sub<&PolyOverZ> for &PolyOverQ
Source§fn sub(self, other: &PolyOverZ) -> Self::Output
fn sub(self, other: &PolyOverZ) -> Self::Output
Implements the Sub trait for PolyOverQ 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 PolyOverQ.
§Examples
use qfall_math::rational::PolyOverQ;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a = PolyOverQ::from_str("4 1/2 0 3/7 1").unwrap();
let b = PolyOverZ::from_str("4 2 0 3 1").unwrap();
let c: PolyOverQ = &a - &b;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<&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 &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<&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 for &PolyOverZ
impl Sub for &PolyOverZ
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Implements the Sub trait for two PolyOverZ values.
Sub is implemented for any combination of PolyOverZ and borrowed PolyOverZ.
Parameters:
other: specifies the value to subtract fromself
Returns the result of the subtraction of both polynomials as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b: PolyOverZ = PolyOverZ::from_str("5 1 2 -3 0 8").unwrap();
let c: PolyOverZ = &a - &b;
let d: PolyOverZ = a - b;
let e: PolyOverZ = &c - d;
let f: PolyOverZ = c - &e;Source§impl SubAssign<&PolyOverZ> for PolyOverQ
impl SubAssign<&PolyOverZ> for PolyOverQ
Source§fn sub_assign(&mut self, other: &PolyOverZ)
fn sub_assign(&mut self, other: &PolyOverZ)
Documentation at PolyOverQ::sub_assign.
Source§impl SubAssign<&PolyOverZ> for PolyOverZ
impl SubAssign<&PolyOverZ> for PolyOverZ
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.
Parameters:
other: specifies the polynomial to subtract fromself
Returns the difference of both polynomials as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let mut a = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b = PolyOverZ::from_str("5 1 2 -3 0 8").unwrap();
a -= &b;
a -= b;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<&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<PolyOverZ> for PolyOverQ
impl SubAssign<PolyOverZ> for PolyOverQ
Source§fn sub_assign(&mut self, other: PolyOverZ)
fn sub_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverQ::sub_assign.
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<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 for PolyOverZ
impl SubAssign for PolyOverZ
Source§fn sub_assign(&mut self, other: PolyOverZ)
fn sub_assign(&mut self, other: PolyOverZ)
Documentation at PolyOverZ::sub_assign.