PolynomialRingZq

Struct PolynomialRingZq 

Source
pub struct PolynomialRingZq { /* private fields */ }
Expand description

PolynomialRingZq represents polynomials over the finite field PolyOverZq/f(X) where f(X) is a polynomial over Zq.

Attributes

  • poly: holds the value
  • modulus: holds the modulus q and f(X)

§Examples

use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;

let poly_mod = PolyOverZq::from_str("3  1 0 1 mod 17").unwrap();
let modulus = ModulusPolynomialRingZq::from(poly_mod);

// instantiation
let a = PolynomialRingZq::from((PolyOverZ::from(5), &modulus));
let b = PolynomialRingZq::from((PolyOverZ::from_str("2  1 5").unwrap(), &modulus));
let _ = a.clone();

// arithmetics
let _ = &a + &b;
let _ = &a * &b;

// to_string incl. (de-)serialization
assert_eq!("1  5 / 3  1 0 1 mod 17", &a.to_string());
let _ = serde_json::to_string(&a).unwrap();

Implementations§

Source§

impl PolynomialRingZq

Source

pub fn add_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>

Implements addition for two PolynomialRingZq values.

Parameters:

  • other: specifies the polynomial to add to self

Returns the sum of both polynomials as a PolynomialRingZq or an error if the moduli mismatch.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));

let c: PolynomialRingZq = a.add_safe(&b).unwrap();
§Errors and Failures
Source§

impl PolynomialRingZq

Source

pub fn mul_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>

Implements multiplication for two PolynomialRingZq values.

Parameters:

  • other: specifies the polynomial to multiply to self

Returns the product of both polynomials as a PolynomialRingZq or an error if the moduli mismatch.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));

let c: PolynomialRingZq = a.mul_safe(&b).unwrap();
§Errors and Failures
Source§

impl PolynomialRingZq

Source

pub fn mul_scalar_zq_safe(&self, scalar: &Zq) -> Result<Self, MathError>

Implements multiplication for a PolynomialRingZq with a Zq.

Parameters:

  • scalar: Specifies the scalar by which the polynomial is multiplied.

Returns the product of self and scalar as a PolynomialRingZq or an error if the moduli mismatch.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;

let poly_1 = PolynomialRingZq::from_str("3  1 2 3 / 4  1 2 3 4 mod 17").unwrap();
let integer = Zq::from((3,17));

let poly_2 = poly_1.mul_scalar_zq_safe(&integer).unwrap();
§Errors and Failures
Source§

impl PolynomialRingZq

Source

pub fn sub_safe(&self, other: &Self) -> Result<PolynomialRingZq, MathError>

Implements subtraction for two PolynomialRingZq values.

Parameters:

  • other: specifies the polynomial to subtract from self

Returns the result of subtraction of both polynomials as a PolynomialRingZq or an error if the moduli mismatch.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));

let c: PolynomialRingZq = a.sub_safe(&b).unwrap();
§Errors and Failures
Source§

impl PolynomialRingZq

Source

pub fn get_mod(&self) -> ModulusPolynomialRingZq

Returns the modulus object of the PolynomialRingZq element.

§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));

let poly_ring_mod = poly_ring.get_mod();

assert_eq!(modulus, poly_ring_mod);
Source

pub fn get_representative_least_nonnegative_residue(&self) -> PolyOverZ

Returns a representative polynomial of the PolynomialRingZq element.

The representation of the coefficients is in the range [0, modulus) and the representation of the polynomial is in the range [0, modulus_polynomial).

§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));

let poly_z = poly_ring.get_representative_least_nonnegative_residue();

let cmp_poly = PolyOverZ::from_str("3  15 0 1").unwrap();
assert_eq!(cmp_poly, poly_z);
Source

pub fn get_degree(&self) -> i64

Returns the degree of a PolynomialRingZq as a i64. The zero polynomial has degree -1.

§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3  0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));

let degree = poly_ring.get_degree();

assert_eq!(2, degree);
Source§

impl PolynomialRingZq

Source

pub fn norm_eucl_sqrd(&self) -> Z

Returns the squared Euclidean norm or squared 2-norm of the given polynomial. The squared Euclidean norm for a polynomial is obtained by treating the coefficients of the polynomial as a vector and then applying the standard squared Euclidean norm.

Each length of an entry in this vector is defined as the shortest distance to the next zero representative modulo q.

§Examples
use qfall_math::{integer::Z, integer_mod_q::PolynomialRingZq};
use std::str::FromStr;

let poly = PolynomialRingZq::from_str("3  1 2 3 / 4  1 2 3 4 mod 11").unwrap();

let sqrd_2_norm = poly.norm_eucl_sqrd();

// 1*1 + 2*2 + 3*3 = 14
assert_eq!(Z::from(14), sqrd_2_norm);
Source

pub fn norm_infty(&self) -> Z

Returns the infinity norm or the maximal absolute value of a coefficient of the given polynomial. The infinity norm for a polynomial is obtained by treating the coefficients of the polynomial as a vector and then applying the standard infinity norm.

Each length of an entry in this vector is defined as the shortest distance to the next zero representative modulo q.

§Examples
use qfall_math::{integer::Z, integer_mod_q::PolynomialRingZq};
use std::str::FromStr;

let poly = PolynomialRingZq::from_str("3  1 2 4 / 4  1 2 3 4 mod 7").unwrap();

let infty_norm = poly.norm_infty();

// max coefficient is 4 = -3
assert_eq!(Z::from(3), infty_norm);
Source§

impl PolynomialRingZq

Source

pub fn is_irreducible(&self) -> bool

Checks if a PolynomialRingZq is irreducible.

Returns true if the polynomial is irreducible and false otherwise.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;

let poly_irr = PolynomialRingZq::from_str("2  1 1 / 3  1 2 3 mod 17").unwrap();
// returns true, since X + 1 is irreducible
assert!(poly_irr.is_irreducible());
Source

pub fn is_one(&self) -> bool

Checks if a PolynomialRingZq is the constant polynomial with coefficient 1.

Returns true if there is only one coefficient, which is 1.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;

let value = PolynomialRingZq::from_str("1  1 / 3  1 0 1 mod 4").unwrap();
assert!(value.is_one());
Source

pub fn is_zero(&self) -> bool

Checks if every entry of a PolynomialRingZq is 0.

Returns true if PolynomialRingZq has no coefficients.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;

let value = PolynomialRingZq::from_str("0 / 2  1 1 mod 7").unwrap();
assert!(value.is_zero());
Source

pub fn ntt(&self) -> NTTPolynomialRingZq

Computes the NTT representation of self.

§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use crate::qfall_math::traits::SetCoefficient;
use std::str::FromStr;

let n = 4;
let modulus = 7681;

let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();

let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);

let poly_ring = PolynomialRingZq::sample_uniform(&polynomial_modulus);

let ntt_poly_ring = poly_ring.ntt();
§Panics …
Source§

impl PolynomialRingZq

Source

pub fn sample_binomial( modulus: &ModulusPolynomialRingZq, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>

Generates a PolynomialRingZq instance of maximum degree modulus.get_degree() - 1 and coefficients chosen according to the binomial distribution parameterized by n and p.

Parameters:

  • modulus: specifies the ModulusPolynomialRingZq over which the ring of polynomials modulo modulus.get_q() is defined
  • n: specifies the number of trials
  • p: specifies the probability of success

Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1 with coefficients chosen according to the binomial distribution or a MathError if n < 0, p ∉ (0,1), n does not fit into an i64.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3  1 2 3 mod 17").unwrap();

let sample = PolynomialRingZq::sample_binomial(&modulus, 2, 0.5).unwrap();
§Errors and Failures
§Panics …
Source

pub fn sample_binomial_with_offset( modulus: &ModulusPolynomialRingZq, offset: impl Into<Z>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>

Generates a PolynomialRingZq instance of maximum degree modulus.get_degree() - 1 and coefficients chosen according to the binomial distribution parameterized by n and p with given offset.

Parameters:

  • modulus: specifies the ModulusPolynomialRingZq over which the ring of polynomials modulo modulus.get_q() is defined
  • offset: specifies an offset applied to each sample collected from the binomial distribution
  • n: specifies the number of trials
  • p: specifies the probability of success

Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1 with coefficients chosen according to the binomial distribution or a MathError if n < 0, p ∉ (0,1), n does not fit into an i64.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3  1 2 3 mod 17").unwrap();

let sample = PolynomialRingZq::sample_binomial_with_offset(&modulus, -1, 2, 0.5).unwrap();
§Errors and Failures
§Panics …
Source§

impl PolynomialRingZq

Source

pub fn sample_discrete_gauss( modulus: impl Into<ModulusPolynomialRingZq>, center: impl Into<Q>, s: impl Into<Q>, ) -> Result<Self, MathError>

Initializes a new PolynomialRingZq with maximum degree modulus.get_degree() - 1 and with each entry sampled independently according to the discrete Gaussian distribution.

Parameters:

  • modulus: specifies the ModulusPolynomialRingZq over which the ring of polynomials modulo modulus.get_q() is defined
  • center: specifies the positions of the center with peak probability
  • s: specifies the Gaussian parameter, which is proportional to the standard deviation sigma * sqrt(2 * pi) = s

Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1 with coefficients chosen independently according the discrete Gaussian distribution or a MathError if s < 0.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3  1 2 3 mod 17").unwrap();

let sample = PolynomialRingZq::sample_discrete_gauss(&modulus, 0, 1).unwrap();
§Errors and Failures
§Panics …
Source§

impl PolynomialRingZq

Source

pub fn sample_uniform(modulus: impl Into<ModulusPolynomialRingZq>) -> Self

Generates a PolynomialRingZq instance with maximum degree modulus.get_degree() - 1 and coefficients chosen uniform at random in [0, modulus.get_q()).

The internally used uniform at random chosen bytes are generated by ThreadRng, which uses ChaCha12 and is considered cryptographically secure.

Parameters:

  • modulus: specifies the ModulusPolynomialRingZq over which the ring of polynomials modulo modulus.get_q() is defined

Returns a fresh PolynomialRingZq instance of length modulus.get_degree() - 1 with coefficients chosen uniform at random in [0, modulus.get_q()).

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3  1 2 3 mod 17").unwrap();

let sample = PolynomialRingZq::sample_uniform(&modulus);
§Panics …
Source§

impl PolynomialRingZq

Source

pub unsafe fn get_fmpz_poly_struct(&mut self) -> &mut fmpz_poly_struct

Returns a mutable reference to the underlying fmpz_poly_struct by calling get_fmpz_poly_struct on poly.

WARNING: The returned struct is part of flint_sys. Any changes to this object are unsafe and may introduce memory leaks. In case you are calling this function to a modulus struct, please be aware that most moduli are shared across multiple instances and all modifications of this struct will affect any other instance with a reference to this object.

This function is a passthrough to enable users of this library to use flint_sys and with that FLINT functions that might not be covered in our library yet. If this is the case, please consider contributing to this open-source project by opening a Pull Request at qfall_math to provide this feature in the future.

§Safety

Any flint_sys struct and function is part of a FFI to the C-library FLINT. As FLINT is a C-library, it does not provide all memory safety features that Rust and our Wrapper provide. Thus, using functions of flint_sys can introduce memory leaks.

Source§

impl PolynomialRingZq

Source

pub unsafe fn get_fq_ctx_struct(&mut self) -> &mut fq_ctx_struct

Returns a mutable reference to the underlying fq_ctx_struct by calling get_fq_ctx_struct on modulus.

WARNING: The returned struct is part of flint_sys. Any changes to this object are unsafe and may introduce memory leaks. In case you are calling this function to a modulus struct, please be aware that most moduli are shared across multiple instances and all modifications of this struct will affect any other instance with a reference to this object.

This function is a passthrough to enable users of this library to use flint_sys and with that FLINT functions that might not be covered in our library yet. If this is the case, please consider contributing to this open-source project by opening a Pull Request at qfall_math to provide this feature in the future.

§Safety

Any flint_sys struct and function is part of a FFI to the C-library FLINT. As FLINT is a C-library, it does not provide all memory safety features that Rust and our Wrapper provide. Thus, using functions of flint_sys can introduce memory leaks.

Source§

impl PolynomialRingZq

Source

pub unsafe fn set_fmpz_poly_struct(&mut self, flint_struct: fmpz_poly_struct)

Sets the field fmpz_poly_struct to flint_struct by calling set_fmpz_poly_struct on poly.

Parameters:

  • flint_struct: value to set the attribute to

This function is a passthrough to enable users of this library to use flint_sys and with that FLINT functions that might not be covered in our library yet. If this is the case, please consider contributing to this open-source project by opening a Pull Request at qfall_math to provide this feature in the future.

§Safety

Ensure that the old struct does not share any memory with any other structs that might be used in the future. The memory of the old struct is freed using this function.

Any flint_sys struct and function is part of a FFI to the C-library FLINT. As FLINT is a C-library, it does not provide all memory safety features that Rust and our Wrapper provide. Thus, using functions of flint_sys can introduce memory leaks.

Source§

impl PolynomialRingZq

Source

pub unsafe fn set_fq_ctx_struct(&mut self, flint_struct: fq_ctx_struct)

Sets the field fq_ctx_struct to flint_struct by calling set_fq_ctx_struct on modulus.

Parameters:

  • flint_struct: value to set the attribute to

This function is a passthrough to enable users of this library to use flint_sys and with that FLINT functions that might not be covered in our library yet. If this is the case, please consider contributing to this open-source project by opening a Pull Request at qfall_math to provide this feature in the future.

§Safety

Ensure that the old struct does not share any memory with any other structs that might be used in the future. The memory of the old struct is freed using this function.

Any flint_sys struct and function is part of a FFI to the C-library FLINT. As FLINT is a C-library, it does not provide all memory safety features that Rust and our Wrapper provide. Thus, using functions of flint_sys can introduce memory leaks.

Trait Implementations§

Source§

impl Add<&PolyOverZ> for &PolynomialRingZq

Source§

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 to self

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

The resulting type after applying the + operator.
Source§

impl Add<&PolyOverZq> for &PolynomialRingZq

Source§

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 to self

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

The resulting type after applying the + operator.
Source§

impl Add for &PolynomialRingZq

Source§

fn add(self, other: Self) -> Self::Output

Implements the Add trait for two PolynomialRingZq values. Add is implemented for any combination of PolynomialRingZq and borrowed PolynomialRingZq.

Parameters:

  • other: specifies the polynomial to add to self

Returns the sum of both polynomials as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));

let c: PolynomialRingZq = &a + &b;
let d: PolynomialRingZq = a + b;
let e: PolynomialRingZq = &c + d;
let f: PolynomialRingZq = c + &e;
§Panics …
Source§

type Output = PolynomialRingZq

The resulting type after applying the + operator.
Source§

impl AddAssign<&PolyOverZ> for PolynomialRingZq

Source§

fn add_assign(&mut self, other: &PolyOverZ)

Documentation at PolynomialRingZq::add_assign.

Source§

impl AddAssign<&PolyOverZq> for PolynomialRingZq

Source§

fn add_assign(&mut self, other: &PolyOverZq)

Documentation at PolynomialRingZq::add_assign.

§Panics …
  • if the moduli are different.
Source§

impl AddAssign<&PolynomialRingZq> for PolynomialRingZq

Source§

fn add_assign(&mut self, other: &Self)

Computes the addition of self and other reusing the memory of self. AddAssign can be used on PolynomialRingZq in combination with PolynomialRingZq, PolyOverZ and PolyOverZq.

Parameters:

  • other: specifies the polynomial to add to self

Returns the sum of both polynomials modulo Z_q[X] as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let mut a = PolynomialRingZq::from((&poly_1, &modulus));
let c = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&c, &modulus));
let d = PolyOverZq::from((&c, 17));

a += &b;
a += b;
a += &c;
a += c;
a += &d;
a += d;
§Panics …
Source§

impl AddAssign<PolyOverZ> for PolynomialRingZq

Source§

fn add_assign(&mut self, other: PolyOverZ)

Documentation at PolynomialRingZq::add_assign.

Source§

impl AddAssign<PolyOverZq> for PolynomialRingZq

Source§

fn add_assign(&mut self, other: PolyOverZq)

Documentation at PolynomialRingZq::add_assign.

Source§

impl AddAssign for PolynomialRingZq

Source§

fn add_assign(&mut self, other: PolynomialRingZq)

Documentation at PolynomialRingZq::add_assign.

Source§

impl Clone for PolynomialRingZq

Source§

fn clone(&self) -> PolynomialRingZq

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl CompareBase<&PolyOverZ> for PolynomialRingZq

Source§

fn compare_base(&self, other: &T) -> bool

Compares the base elements of the objects and returns true if they match and an operation between the two provided types is possible. Read more
Source§

fn call_compare_base_error(&self, other: &T) -> Option<MathError>

Calls an error that gives small explanation how the base elements differ. This function only calls the error and does not check if the two actually differ. Read more
Source§

impl CompareBase<&PolyOverZq> for PolynomialRingZq

Source§

fn compare_base(&self, other: &&PolyOverZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

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 to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<&PolynomialRingZq> for MatNTTPolynomialRingZq

Source§

fn compare_base(&self, other: &&PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<&PolynomialRingZq> for MatPolynomialRingZq

Source§

fn compare_base(&self, other: &&PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<&PolynomialRingZq> for NTTPolynomialRingZq

Source§

fn compare_base(&self, other: &&PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<&PolynomialRingZq> for PolynomialRingZq

Source§

fn compare_base(&self, other: &&PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<&Zq> for PolynomialRingZq

Source§

fn compare_base(&self, other: &&Zq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

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 to self

Returns a MathError of type MismatchingModulus.

Source§

impl<Integer: Into<Z>> CompareBase<Integer> for PolynomialRingZq

Source§

fn compare_base(&self, other: &T) -> bool

Compares the base elements of the objects and returns true if they match and an operation between the two provided types is possible. Read more
Source§

fn call_compare_base_error(&self, other: &T) -> Option<MathError>

Calls an error that gives small explanation how the base elements differ. This function only calls the error and does not check if the two actually differ. Read more
Source§

impl CompareBase<PolyOverZ> for PolynomialRingZq

Source§

fn compare_base(&self, other: &T) -> bool

Compares the base elements of the objects and returns true if they match and an operation between the two provided types is possible. Read more
Source§

fn call_compare_base_error(&self, other: &T) -> Option<MathError>

Calls an error that gives small explanation how the base elements differ. This function only calls the error and does not check if the two actually differ. Read more
Source§

impl CompareBase<PolyOverZq> for PolynomialRingZq

Source§

fn compare_base(&self, other: &PolyOverZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

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 to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<PolynomialRingZq> for MatNTTPolynomialRingZq

Source§

fn compare_base(&self, other: &PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<PolynomialRingZq> for MatPolynomialRingZq

Source§

fn compare_base(&self, other: &PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<PolynomialRingZq> for NTTPolynomialRingZq

Source§

fn compare_base(&self, other: &PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase<Zq> for PolynomialRingZq

Source§

fn compare_base(&self, other: &Zq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

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 to self

Returns a MathError of type MismatchingModulus.

Source§

impl CompareBase for PolynomialRingZq

Source§

fn compare_base(&self, other: &PolynomialRingZq) -> bool

Compares the moduli of the two elements.

Parameters:

  • other: The other object whose base is compared to self

Returns true if the moduli match and false otherwise.

Source§

fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>

Returns an error that gives a small explanation of how the moduli are incomparable.

Parameters:

  • other: The other object whose base is compared to self

Returns a MathError of type MismatchingModulus.

Source§

impl Debug for PolynomialRingZq

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PolynomialRingZq

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for PolynomialRingZq

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<&ModulusPolynomialRingZq> for PolynomialRingZq

Source§

fn from(modulus: &ModulusPolynomialRingZq) -> Self

Creates a zero polynomial with a given ModulusPolynomialRingZq.

Parameters:

  • modulus: the modulus that is applied to the polynomial ring element.

Returns a new constant PolynomialRingZq with the specified ModulusPolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4  -1 0 1 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from((poly, &modulus));
§Panics …
  • if the moduli mismatch.
Source§

impl From<&PolynomialRingZq> for NTTPolynomialRingZq

Source§

fn from(poly: &PolynomialRingZq) -> Self

Computes the NTT representation of poly.

Parameters:

  • poly: the polynomial that’s going to be represented in NTT form.

Returns the NTT representation as a NTTPolynomialRingZq of poly.

§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use crate::qfall_math::traits::SetCoefficient;
use std::str::FromStr;

let n = 4;
let modulus = 7681;

let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();

let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);

let poly_ring = PolynomialRingZq::sample_uniform(&polynomial_modulus);

let ntt_poly_ring = NTTPolynomialRingZq::from(&poly_ring);
§Panics …
Source§

impl From<&PolynomialRingZq> for String

Source§

fn from(value: &PolynomialRingZq) -> Self

Converts a PolynomialRingZq into its String representation.

Parameters:

  • value: specifies the polynomial that will be represented as a String

Returns a String of the form "[#number of coefficients of element]⌴⌴[0th coefficient]⌴ [1st coefficient]⌴...⌴/⌴[#number of coefficients of polynomial modulus]⌴⌴ [0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[q]".

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
let poly = PolynomialRingZq::from_str("2  2 1 / 3  2 2 2 mod 3").unwrap();

let string: String = poly.into();
Source§

impl<Mod: Into<ModulusPolynomialRingZq>> From<(&PolyOverZq, Mod)> for PolynomialRingZq

Source§

fn from((poly, modulus): (&PolyOverZq, Mod)) -> Self

Creates a new polynomial ring element of type PolynomialRingZq.

Parameters:

  • poly: the coefficients of the polynomial.
  • modulus: the modulus that is applied to the polynomial ring element.

Returns a new element inside the polynomial ring, if the moduli of the polynomial and the modulus match.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4  -1 0 1 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
§Panics …
  • if the moduli mismatch.
Source§

impl<Poly: Into<PolyOverZ>, Mod: Into<ModulusPolynomialRingZq>> From<(Poly, Mod)> for PolynomialRingZq

Source§

fn from((poly, modulus): (Poly, Mod)) -> Self

Creates a new polynomial ring element of type PolynomialRingZq.

Parameters:

  • poly: the coefficients of the polynomial.
  • modulus: the modulus that is applied to the polynomial ring element.

Returns a new element inside the polynomial ring.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
Source§

impl<Mod: Into<ModulusPolynomialRingZq>> From<(PolyOverZq, Mod)> for PolynomialRingZq

Source§

fn from((poly, modulus): (PolyOverZq, Mod)) -> Self

Creates a new polynomial ring element of type PolynomialRingZq.

Parameters:

  • poly: the coefficients of the polynomial.
  • modulus: the modulus that is applied to the polynomial ring element.

Returns a new element inside the polynomial ring, if the moduli of the polynomial and the modulus match.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4  -1 0 1 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from((poly, &modulus));
§Panics …
  • if the moduli mismatch.
Source§

impl From<ModulusPolynomialRingZq> for PolynomialRingZq

Source§

fn from(value: ModulusPolynomialRingZq) -> Self

Documentation can be found at PolynomialRingZq::from for &ModulusPolynomialRingZq.

Source§

impl From<NTTPolynomialRingZq> for PolynomialRingZq

Source§

fn from(ntt: NTTPolynomialRingZq) -> Self

Creates a polynomial from NTTPolynomialRingZq generated with respect to the NTTBasisPolynomialRingZq as part of ModulusPolynomialRingZq.

Parameters:

  • ntt: the NTT representation of the polynomial.
  • modulus: the modulus that is applied to the polynomial ring element.

Returns a new PolynomialRingZq with the specified ModulusPolynomialRingZq and values as defined in ntt.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, PolyOverZq, ModulusPolynomialRingZq, NTTPolynomialRingZq};
use qfall_math::traits::SetCoefficient;

let n = 4;
let modulus = 7681;

let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();

let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);

let ntt = NTTPolynomialRingZq::sample_uniform(&polynomial_modulus);

let res = PolynomialRingZq::from(ntt);
§Panics …
Source§

impl From<PolynomialRingZq> for String

Source§

fn from(value: PolynomialRingZq) -> Self

Documentation can be found at String::from for &PolynomialRingZq.

Source§

impl FromCoefficientEmbedding<(&MatZq, &ModulusPolynomialRingZq)> for PolynomialRingZq

Source§

fn from_coefficient_embedding( embedding: (&MatZq, &ModulusPolynomialRingZq), ) -> Self

Computes a polynomial of degree n-1 from a column vector of size n and a modulus. The i-th entry of the column vector is taken as the i-th coefficient of the polynomial. It inverts the operation of PolynomialRingZq::into_coefficient_embedding.

Parameters:

  • embedding: the column vector that encodes the embedding and the modulus of the resulting polynomial

Returns a polynomial that corresponds to the embedding.

§Examples
use std::str::FromStr;
use qfall_math::{
    integer_mod_q::{MatZq, PolynomialRingZq, ModulusPolynomialRingZq},
    traits::FromCoefficientEmbedding,
};

let vector = MatZq::from_str("[[17],[3],[-5]] mod 19").unwrap();
let modulus = ModulusPolynomialRingZq::from_str("4  1 2 3 4 mod 19").unwrap();
let poly = PolynomialRingZq::from_coefficient_embedding((&vector, &modulus));
let cmp_poly = PolynomialRingZq::from_str("3  17 3 -5 / 4  1 2 3 4 mod 19").unwrap();
assert_eq!(cmp_poly, poly);
§Panics …
  • if the provided embedding is not a column vector.
  • if the moduli mismatch.
Source§

impl FromStr for PolynomialRingZq

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Creates a polynomial ring element of type PolynomialRingZq.

Warning: If the polynomials start with a correctly formatted PolyOverZ object, the rest of the string until the "/" (for the first polynomial) or "mod" (for the second polynomial) is ignored. This means that the input string "4 0 1 2 3 / 2 1 1 mod 13" is the same as "4 0 1 2 3 4 5 6 7 / 2 1 1 mod 13".

Parameters:

  • s: the polynomial ring element of form: "[#number of coefficients of element]⌴⌴[0th coefficient]⌴ [1st coefficient]⌴...⌴/⌴[#number of coefficients of polynomial modulus]⌴⌴ [0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[q]".

Note that the [#number of coefficients] and [0th coefficient] are divided by two spaces and the strings for the polynomials are trimmed, i.e. all whitespaces around the polynomials and the modulus are ignored.

Returns a PolynomialRingZq or an error if the provided string was not formatted correctly, the numbers of coefficients were smaller than the numbers provided at the start of the provided string, or the modulus was smaller than 2.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;

let poly = PolynomialRingZq::from_str("4  -1 0 1 1 / 4  0 1 -2 3 mod 42").unwrap();
§Errors and Failures
  • Returns a MathError of type StringConversionError
    • if the provided first half of the string was not formatted correctly to create a PolyOverZ,
    • if the provided second half of the string was not formatted correctly to create a ModulusPolynomialRingZq,
    • if the numbers of coefficients were smaller than the numbers provided at the start of the provided string,
    • if the provided values did not contain two whitespaces, or
    • if the delimiter / and mod could not be found.
  • Returns a MathError of type InvalidModulus if the integer modulus q is smaller than 2.
Source§

type Err = MathError

The associated error which can be returned from parsing.
Source§

impl GetCoefficient<Z> for PolynomialRingZq

Source§

unsafe fn get_coeff_unchecked(&self, index: i64) -> Z

Returns the coefficient of a PolynomialRingZq as a Z.

If an index is provided which exceeds the highest set coefficient, 0 is returned.

Parameters:

  • index: the index of the coefficient to get (has to be positive)

Returns the coefficient as a Z, or a MathError if the provided index is negative and therefore invalid, or it does not fit into an i64.

§Examples
use qfall_math::traits::*;
use qfall_math::integer::{PolyOverZ, Z};
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3  0 1 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));

let coeff_0: Z = poly_ring.get_coeff(0).unwrap();
let coeff_1: Z = unsafe{ poly_ring.get_coeff_unchecked(1) };
let coeff_3: Z = poly_ring.get_coeff(3).unwrap();

assert_eq!(Z::ZERO, coeff_0);
assert_eq!(Z::ONE, coeff_1);
assert_eq!(Z::ZERO, coeff_3);
§Safety

To use this function safely, make sure that the selected index is greater or equal than 0.

Source§

fn get_coeff(&self, index: impl TryInto<i64> + Display) -> Result<T, MathError>

Returns a coefficient of the given object, e.g. a polynomial, for a given index. Read more
Source§

impl GetCoefficient<Zq> for PolynomialRingZq

Source§

unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq

Returns the coefficient of a PolynomialRingZq as a Zq.

If an index is provided which exceeds the highest set coefficient, 0 is returned.

Parameters:

  • index: the index of the coefficient to get (has to be positive)

Returns the coefficient as a Zq, or a MathError if the provided index is negative and therefore invalid, or it does not fit into an i64.

§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;

let poly_ring = PolynomialRingZq::from_str("3  0 1 1 / 4  1 0 0 1 mod 17").unwrap();

let coeff_0: Zq = poly_ring.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly_ring.get_coeff_unchecked(1) };
let coeff_3: Zq = poly_ring.get_coeff(3).unwrap();

assert_eq!(Zq::from((0, 17)), coeff_0);
assert_eq!(Zq::from((1, 17)), coeff_1);
assert_eq!(Zq::from((0, 17)), coeff_3);
§Safety

To use this function safely, make sure that the selected index is greater or equal than 0.

Source§

fn get_coeff(&self, index: impl TryInto<i64> + Display) -> Result<T, MathError>

Returns a coefficient of the given object, e.g. a polynomial, for a given index. Read more
Source§

impl IntoCoefficientEmbedding<(MatZq, ModulusPolynomialRingZq)> for &PolynomialRingZq

Source§

fn into_coefficient_embedding( self, size: impl Into<i64>, ) -> (MatZq, ModulusPolynomialRingZq)

Computes the coefficient embedding of the polynomial in a MatZq as a column vector, where the i-th entry of the vector corresponds to the i-th coefficient, and a ModulusPolynomialRingZq. It inverts the operation of PolynomialRingZq::from_coefficient_embedding.

The representation of the polynomials in the embedding is in the range [0, modulus_polynomial).

Parameters:

  • size: determines the number of rows of the embedding. It has to be larger than the degree of the polynomial.

Returns a coefficient embedding as a column vector if size is large enough.

§Examples
use std::str::FromStr;
use qfall_math::{
    integer_mod_q::{MatZq, PolynomialRingZq},
    traits::IntoCoefficientEmbedding,
};

let poly = PolynomialRingZq::from_str("2  1 -2 / 3  17 3 5 mod 19").unwrap();
let embedding = poly.into_coefficient_embedding(3);
let cmp_vector = MatZq::from_str("[[1],[-2],[0]] mod 19").unwrap();
assert_eq!((cmp_vector, poly.get_mod()), embedding);
§Panics …
  • if size is not larger than the degree of the polynomial, i.e. not all coefficients can be embedded.
Source§

impl MatrixGetEntry<PolynomialRingZq> for MatPolynomialRingZq

Source§

unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolynomialRingZq

Outputs the PolynomialRingZq value of a specific matrix entry without checking whether it’s part of the matrix.

Parameters:

  • row: specifies the row in which the entry is located
  • column: specifies the column in which the entry is located

Returns the PolynomialRingZq value of the matrix at the position of the given row and column.

§Safety

To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.

§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use qfall_math::traits::*;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 50").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4  -1 0 1 1, 1  42],[0, 2  1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));

let entry_1: PolynomialRingZq = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
let entry_2: PolynomialRingZq = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };

let value_cmp = PolynomialRingZq::from((&PolyOverZ::from(42), &modulus));
assert_eq!(entry_1, value_cmp);
assert_eq!(entry_1, entry_2);
Source§

fn get_entry( &self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, ) -> Result<T, MathError>

Returns the value of a specific matrix entry. Read more
Source§

fn get_entries(&self) -> Vec<Vec<T>>

Outputs a 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 more
Source§

fn get_entries_rowwise(&self) -> Vec<T>

Outputs a Vec<T> containing all entries of the matrix in a row-wise order, i.e. a matrix [[2, 3, 4],[5, 6, 7]] can be accessed via this function in this order [2, 3, 4, 5, 6, 7]. Read more
Source§

fn get_entries_columnwise(&self) -> Vec<T>

Outputs a Vec<T> containing all entries of the matrix in a column-wise order, i.e. a matrix [[2, 3, 4],[5, 6, 7]] can be accessed via this function in this order [2, 5, 3, 6, 4, 7]. Read more
Source§

impl MatrixSetEntry<&PolynomialRingZq> for MatPolynomialRingZq

Source§

unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: &PolynomialRingZq, )

Sets the value of a specific matrix entry according to a given value of type PolynomialRingZq without checking whether the coordinate is part of the matrix or if the moduli match.

Parameters:

  • row: specifies the row in which the entry is located
  • column: specifies the column in which the entry is located
  • value: specifies the value to which the entry is set
§Safety

To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.

§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use crate::qfall_math::traits::*;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[0, 1  42],[0, 2  1 2]]").unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let value = PolynomialRingZq::from((&PolyOverZ::default(), &modulus));

unsafe {
    poly_ring_mat.set_entry_unchecked(0, 1, &value);
    poly_ring_mat.set_entry_unchecked(1, 1, &value);
}

let mat_cmp = MatPolynomialRingZq::from((&MatPolyOverZ::new(2, 2), &modulus));
assert_eq!(poly_ring_mat, mat_cmp);
Source§

fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: T, ) -> Result<(), MathError>

Sets the value of a specific matrix entry according to a given value. Read more
Source§

impl MatrixSetEntry<PolynomialRingZq> for MatPolynomialRingZq

Source§

fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: PolynomialRingZq, ) -> Result<(), MathError>

Documentation can be found at MatPolynomialRingZq::set_entry for &PolynomialRingZq.

Source§

unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: PolynomialRingZq, )

Documentation can be found at MatPolynomialRingZq::set_entry for &PolynomialRingZq.

Source§

impl Mul<&PolyOverZ> for &PolynomialRingZq

Source§

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 to self

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

The resulting type after applying the * operator.
Source§

impl Mul<&PolyOverZq> for &PolynomialRingZq

Source§

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 to self

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

The resulting type after applying the * operator.
Source§

impl Mul<&PolynomialRingZq> for &MatPolyOverZ

Source§

fn mul(self, scalar: &PolynomialRingZq) -> Self::Output

Implements the Mul trait for a MatPolyOverZ matrix with a PolynomialRingZq. Mul is implemented for any combination of owned and borrowed values.

Parameters:

  • scalar: Specifies the scalar by which the matrix is multiplied.

Returns the product of self and scalar as a MatPolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3  0 1 1, 1  42],[0, 2  1 2]]").unwrap();
let poly = PolyOverZ::from_str("3  1 0 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));

let poly_ring_mat1 = &poly_mat1 * &poly_ring;
Source§

type Output = MatPolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul<&PolynomialRingZq> for &MatPolynomialRingZq

Source§

fn mul(self, scalar: &PolynomialRingZq) -> Self::Output

Implements the Mul trait for a MatPolynomialRingZq matrix with a PolynomialRingZq. Mul is implemented for any combination of owned and borrowed values.

Parameters:

  • scalar: Specifies the scalar by which the matrix is multiplied.

Returns the product of self and scalar as a MatPolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ, Z};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3  0 1 1, 1  42],[0, 2  1 2]]").unwrap();
let poly_ring_mat1 = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly = PolyOverZ::from_str("3  1 0 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));

let poly_ring_mat2 = &poly_ring_mat1 * &poly_ring;
§Panics …
  • if the moduli mismatch.
Source§

type Output = MatPolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &PolynomialRingZq

Source§

fn mul(self, scalar: &Z) -> Self::Output

Implements the Mul trait for a PolynomialRingZq with a Z integer. Mul is implemented for any combination of owned and borrowed values. Mul is also implemented for Z using PolynomialRingZq.

Parameters:

  • scalar: specifies the scalar by which the polynomial is multiplied

Returns the product of self and scalar as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer::Z;
use std::str::FromStr;

let poly_1 = PolynomialRingZq::from_str("3  1 2 3 / 4  1 2 3 4 mod 17").unwrap();
let integer = Z::from(3);

let poly_2 = &poly_1 * &integer;
Source§

type Output = PolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul<&Zq> for &PolynomialRingZq

Source§

fn mul(self, scalar: &Zq) -> PolynomialRingZq

Implements the Mul trait for a PolynomialRingZq with a Zq. Mul is implemented for any combination of owned and borrowed values. Mul is also implemented for Zq using PolynomialRingZq.

Parameters:

  • scalar: specifies the scalar by which the matrix is multiplied

Returns the product of self and scalar as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;

let poly_1 = PolynomialRingZq::from_str("3  1 2 3 / 4  1 2 3 4 mod 17").unwrap();
let integer = Zq::from((3,17));

let poly_2 = &poly_1 * &integer;
§Panics …
  • if the moduli mismatch.
Source§

type Output = PolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul for &PolynomialRingZq

Source§

fn mul(self, other: Self) -> Self::Output

Implements the Mul trait for two PolynomialRingZq values. Mul is implemented for any combination of PolynomialRingZq and borrowed PolynomialRingZq.

Parameters:

  • other: specifies the polynomial to multiply to self

Returns the product of both polynomials as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));

let c: PolynomialRingZq = &a * &b;
let d: PolynomialRingZq = a * b;
let e: PolynomialRingZq = &c * d;
let f: PolynomialRingZq = c * &e;
§Panics …
Source§

type Output = PolynomialRingZq

The resulting type after applying the * operator.
Source§

impl MulAssign<&PolyOverZq> for PolynomialRingZq

Source§

fn mul_assign(&mut self, other: &PolyOverZq)

Documentation at PolynomialRingZq::mul_assign.

§Panics …
  • if the moduli are different.
Source§

impl MulAssign<&PolynomialRingZq> for MatPolynomialRingZq

Source§

fn mul_assign(&mut self, scalar: &PolynomialRingZq)

Computes the scalar multiplication of self and scalar reusing the memory of self.

Parameters:

  • scalar: specifies the value to multiply to self

Returns the scalar of the matrix as a MatPolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq,ModulusPolynomialRingZq,PolynomialRingZq,Zq};
use qfall_math::integer::{MatZ,PolyOverZ,Z,MatPolyOverZ};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str(&format!("4  1 0 0 1 mod {}", u64::MAX - 1)).unwrap();
let poly_mat1 = MatPolyOverZ::from_str(&format!("[[1  1],[1  {}],[1  4]]", i64::MAX)).unwrap();

let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat1, &modulus));

let poly_z = PolyOverZ::from_str("2  3 1").unwrap();
let polynomial_ring_zq = PolynomialRingZq::from((&poly_z, &modulus));

poly_ring_mat *= &polynomial_ring_zq;
poly_ring_mat *= &poly_z;
poly_ring_mat *= 2;
poly_ring_mat *= -2;
poly_ring_mat *= &Z::from(5);
poly_ring_mat *= &Zq::from((5, u64::MAX -1));
§Panics …
  • if the moduli are different.
Source§

impl MulAssign<&PolynomialRingZq> for PolynomialRingZq

Source§

fn mul_assign(&mut self, other: &Self)

Computes the multiplication of self and other reusing the memory of self. MulAssign can be used on PolynomialRingZq in combination with PolynomialRingZq, PolyOverZ and PolyOverZq.

Parameters:

  • other: specifies the polynomial to multiply to self

Returns the product of both polynomials modulo Z_q[X] as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let mut a = PolynomialRingZq::from((&poly_1, &modulus));
let c = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&c, &modulus));
let d = PolyOverZq::from((&c, 17));

a *= &b;
a *= b;
a *= &c;
a *= c;
a *= &d;
a *= d;
§Panics …
Source§

impl MulAssign<&Zq> for PolynomialRingZq

Source§

fn mul_assign(&mut self, rhs: &Zq)

Computes the scalar multiplication of self and other reusing the memory of self.

Parameters:

  • other: specifies the value to multiply to self

Returns the scalar of the matrix as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{ModulusPolynomialRingZq,PolynomialRingZq,Zq};
use qfall_math::integer::{MatZ,PolyOverZ,Z};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str(&format!("4  1 0 0 1 mod {}", u64::MAX - 1)).unwrap();
let poly_z = PolyOverZ::from_str("2  3 1").unwrap();
let mut polynomial_ring_zq = PolynomialRingZq::from((&poly_z, &modulus));
let zq = Zq::from((17, u64::MAX -1 ));
let z = Z::from(5);

polynomial_ring_zq *= &zq;
polynomial_ring_zq *= zq;
polynomial_ring_zq *= &z;
polynomial_ring_zq *= z;
polynomial_ring_zq *= 2;
polynomial_ring_zq *= -2;
§Panics …
  • if the moduli are different.
Source§

impl MulAssign<PolyOverZq> for PolynomialRingZq

Source§

fn mul_assign(&mut self, other: PolyOverZq)

Documentation at PolynomialRingZq::mul_assign.

Source§

impl MulAssign<PolynomialRingZq> for MatPolynomialRingZq

Source§

impl<T> MulAssign<T> for PolynomialRingZq
where PolyOverZ: MulAssign<T>,

Source§

fn mul_assign(&mut self, rhs: T)

Documentation at PolynomialRingZq::mul_assign This implicitly also implements scalar multiplication for all types that have a mul_assign with PolyOverZ`.

Source§

impl MulAssign<Zq> for PolynomialRingZq

Source§

fn mul_assign(&mut self, other: Zq)

Documentation at PolynomialRingZq::mul_assign.

Source§

impl MulAssign for PolynomialRingZq

Source§

fn mul_assign(&mut self, other: PolynomialRingZq)

Documentation at PolynomialRingZq::mul_assign.

Source§

impl PartialEq for PolynomialRingZq

Source§

fn eq(&self, other: &PolynomialRingZq) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PolynomialRingZq

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl SetCoefficient<&Zq> for PolynomialRingZq

Source§

unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)

Sets the coefficient of a PolynomialRingZq element. We advise to use small coefficients, since already 2^32 coefficients take space of roughly 34 GB. If not careful, be prepared that memory problems can occur, if the index is very high.

This function does not check if the modulus of the polynomial and the value match.

Parameters:

  • index: the index of the coefficient to set (has to be positive)
  • value: the new value the index should have
§Examples
use crate::qfall_math::traits::SetCoefficient;
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;    

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3  0 1 1").unwrap();
let mut poly_ring = PolynomialRingZq::from((&poly, &modulus));
let value = Zq::from((1000, 17));

poly_ring.set_coeff(2, &value).unwrap();
unsafe{ poly_ring.set_coeff_unchecked(5, &value) };
§Safety

To use this function safely, make sure that the selected index is greater or equal than 0 and that the provided value has the same base so that they have a matching base.

Source§

fn set_coeff( &mut self, index: impl TryInto<i64> + Display, value: T, ) -> Result<(), MathError>

Sets coefficient of the object, e.g. polynomial, for a given input value and a index. Read more
Source§

impl<Integer: Into<Z>> SetCoefficient<Integer> for PolynomialRingZq

Source§

unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Integer)

Sets the coefficient of a PolynomialRingZq element. We advise to use small coefficients, since already 2^32 coefficients take space of roughly 34 GB. If not careful, be prepared that memory problems can occur, if the index is very high.

Parameters:

  • index: the index of the coefficient to set (has to be positive)
  • value: the new value the index should have
§Examples
use crate::qfall_math::traits::SetCoefficient;
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3  0 1 1").unwrap();
let mut poly_ring = PolynomialRingZq::from((&poly, &modulus));

poly_ring.set_coeff(2, 16).unwrap();
unsafe{ poly_ring.set_coeff_unchecked(5, 5) };
§Safety

To use this function safely, make sure that the selected index is greater or equal than 0 and that the provided value has the same base so that they have a matching base.

Source§

fn set_coeff( &mut self, index: impl TryInto<i64> + Display, value: T, ) -> Result<(), MathError>

Sets coefficient of the object, e.g. polynomial, for a given input value and a index. Read more
Source§

impl SetCoefficient<Zq> for PolynomialRingZq

Source§

unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)

Documentation can be found at PolynomialRingZq::set_coeff for &Zq.

Source§

fn set_coeff( &mut self, index: impl TryInto<i64> + Display, value: T, ) -> Result<(), MathError>

Sets coefficient of the object, e.g. polynomial, for a given input value and a index. Read more
Source§

impl Sub<&PolyOverZ> for &PolynomialRingZq

Source§

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 from self

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

The resulting type after applying the - operator.
Source§

impl Sub<&PolyOverZq> for &PolynomialRingZq

Source§

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 from self

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

The resulting type after applying the - operator.
Source§

impl Sub<&PolynomialRingZq> for &PolyOverZ

Source§

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 from self

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

The resulting type after applying the - operator.
Source§

impl Sub<&PolynomialRingZq> for &PolyOverZq

Source§

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 from self

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

The resulting type after applying the - operator.
Source§

impl Sub for &PolynomialRingZq

Source§

fn sub(self, other: Self) -> Self::Output

Implements the Sub trait for two PolynomialRingZq values. Sub is implemented for any combination of PolynomialRingZq and borrowed PolynomialRingZq.

Parameters:

  • other: specifies the polynomial to subtract from self

Returns the result of the subtraction of both polynomials as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::PolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let a = PolynomialRingZq::from((&poly_1, &modulus));
let poly_2 = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&poly_2, &modulus));

let c: PolynomialRingZq = &a - &b;
let d: PolynomialRingZq = a - b;
let e: PolynomialRingZq = &c - d;
let f: PolynomialRingZq = c - &e;
§Panics …
Source§

type Output = PolynomialRingZq

The resulting type after applying the - operator.
Source§

impl SubAssign<&PolyOverZ> for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: &PolyOverZ)

Documentation at PolynomialRingZq::sub_assign.

Source§

impl SubAssign<&PolyOverZq> for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: &PolyOverZq)

Documentation at PolynomialRingZq::sub_assign.

§Panics …
  • if the moduli are different.
Source§

impl SubAssign<&PolynomialRingZq> for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: &Self)

Computes the subtraction of self and other reusing the memory of self. SubAssign can be used on PolynomialRingZq in combination with PolynomialRingZq, PolyOverZ and PolyOverZq.

Parameters:

  • other: specifies the polynomial to subtract from self

Returns the difference of both polynomials modulo Z_q[X] as a PolynomialRingZq.

§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let modulus = ModulusPolynomialRingZq::from_str("4  1 0 0 1 mod 17").unwrap();
let poly_1 = PolyOverZ::from_str("4  -1 0 1 1").unwrap();
let mut a = PolynomialRingZq::from((&poly_1, &modulus));
let c = PolyOverZ::from_str("4  2 0 3 1").unwrap();
let b = PolynomialRingZq::from((&c, &modulus));
let d = PolyOverZq::from((&c, 17));

a -= &b;
a -= b;
a -= &c;
a -= c;
a -= &d;
a -= d;
§Panics …
Source§

impl SubAssign<PolyOverZ> for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: PolyOverZ)

Documentation at PolynomialRingZq::sub_assign.

Source§

impl SubAssign<PolyOverZq> for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: PolyOverZq)

Documentation at PolynomialRingZq::sub_assign.

Source§

impl SubAssign for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: PolynomialRingZq)

Documentation at PolynomialRingZq::sub_assign.

Source§

impl Eq for PolynomialRingZq

Source§

impl StructuralPartialEq for PolynomialRingZq

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,