PolyOverZ

Struct PolyOverZ 

Source
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

Source

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

Source

pub fn get_degree(&self) -> i64

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

§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let poly = PolyOverZ::from_str("4  0 1 2 3").unwrap();

let degree = poly.get_degree();

assert_eq!(3, degree);
Source§

impl PolyOverZ

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.

§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);
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.

§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

Source

pub fn is_one(&self) -> bool

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

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

§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let value = PolyOverZ::from(1);
assert!(value.is_one());
Source

pub fn is_zero(&self) -> bool

Checks if every entry of a PolyOverZ is 0.

Returns true if PolyOverZ has no coefficients.

§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let value = PolyOverZ::from(0);
assert!(value.is_zero());
Source§

impl PolyOverZ

Source

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 which self is 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

Source

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 coefficients
  • n: specifies the number of trials
  • p: 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
Source

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 coefficients
  • 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 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
Source§

impl PolyOverZ

Source

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 created PolyOverZ should have
  • 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 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
§Panics …
  • if max_degree is negative, or does not fit into an i64.
Source§

impl PolyOverZ

Source

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 coefficients
  • lower_bound: specifies the included lower bound of the interval over which is sampled
  • upper_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
Source§

impl PolyOverZ

Source

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

Source

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

Source§

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

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§

type Output = PolyOverQ

The resulting type after applying the + operator.
Source§

impl Add<&PolyOverZ> for &PolyOverZq

Source§

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

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

The resulting type after applying the + operator.
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<&PolyOverZ> for &Z

Source§

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

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§

type Output = PolyOverZ

The resulting type after applying the + operator.
Source§

impl Add<&Z> for &PolyOverZ

Source§

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 the Z to add to self

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§

type Output = PolyOverZ

The resulting type after applying the + operator.
Source§

impl Add for &PolyOverZ

Source§

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

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§

type Output = PolyOverZ

The resulting type after applying the + operator.
Source§

impl AddAssign<&PolyOverZ> for PolyOverQ

Source§

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

Documentation at PolyOverQ::add_assign.

Source§

impl AddAssign<&PolyOverZ> for PolyOverZ

Source§

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

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

Source§

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

Documentation at PolyOverZq::add_assign.

Source§

impl AddAssign<&PolyOverZ> for PolynomialRingZq

Source§

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

Documentation at PolynomialRingZq::add_assign.

Source§

impl AddAssign<PolyOverZ> for PolyOverQ

Source§

fn add_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverQ::add_assign.

Source§

impl AddAssign<PolyOverZ> for PolyOverZq

Source§

fn add_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverZq::add_assign.

Source§

impl AddAssign<PolyOverZ> for PolynomialRingZq

Source§

fn add_assign(&mut self, other: PolyOverZ)

Documentation at PolynomialRingZq::add_assign.

Source§

impl AddAssign for PolyOverZ

Source§

fn add_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverZ::add_assign.

Source§

impl Clone for PolyOverZ

Source§

fn clone(&self) -> Self

Clones the given element and returns a deep clone of the PolyOverZ element.

§Examples
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let a = PolyOverZ::from_str("3  0 1 2").unwrap();
let b = a.clone();
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl CompareBase<&PolyOverZ> for MatNTTPolynomialRingZq

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 MatPolyOverZ

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 MatPolynomialRingZq

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 NTTPolynomialRingZq

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 PolyOverZq

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<Integer: Into<Z>> CompareBase<Integer> for PolyOverZ

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 MatNTTPolynomialRingZq

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 MatPolyOverZ

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 MatPolynomialRingZq

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 NTTPolynomialRingZq

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 PolyOverQ

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 PolyOverZq

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 for PolyOverZ

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 Debug for PolyOverZ

Source§

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

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

impl Default for PolyOverZ

Source§

fn default() -> Self

Initializes a PolyOverZ with the zero polynomial.

§Examples
use qfall_math::integer::PolyOverZ;

let zero = PolyOverZ::default();
Source§

impl<'de> Deserialize<'de> for PolyOverZ

Source§

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

Source§

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

Source§

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 dropped
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;

let a = PolyOverZ::from_str("3  0 1 2").unwrap();
drop(a); // explicitly drops a's value
Source§

impl<Integer: Into<Z>> Evaluate<Integer, Z> for PolyOverZ

Source§

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

Source§

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

Source§

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

Source§

fn from(value: &PolyOverZ) -> Self

Alias for PolyOverZ::clone.

Source§

impl From<&PolyOverZ> for String

Source§

fn from(value: &PolyOverZ) -> Self

Converts a PolyOverZ 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]⌴⌴[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

Source§

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 From<PolyOverZ> for PolyOverQ

Source§

fn from(value: PolyOverZ) -> Self

Documentation can be found at PolyOverQ::from for &PolyOverZ.

Source§

impl From<PolyOverZ> for String

Source§

fn from(value: PolyOverZ) -> Self

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

Source§

impl FromCoefficientEmbedding<&MatZ> for PolyOverZ

Source§

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

Source§

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 MathError of type MathError::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 Null Byte.
Source§

type Err = MathError

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

impl GetCoefficient<Z> for PolyOverZ

Source§

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§

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<MatZ> for &PolyOverZ

Source§

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 size is not larger than the degree of the polynomial, i.e. not all coefficients can be embedded.
Source§

impl MatrixGetEntry<PolyOverZ> for MatPolyOverZ

Source§

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 located
  • column: 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>

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 MatrixGetEntry<PolyOverZ> for MatPolynomialRingZq

Source§

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 located
  • column: 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>

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<&PolyOverZ> for MatPolyOverZ

Source§

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 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::{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§

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<&PolyOverZ> for MatPolynomialRingZq

Source§

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 located
  • column: specifies the column in which the entry is located
  • value: 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
Source§

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 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};
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

Source§

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, )

Documentation can be found at MatPolyOverZ::set_entry for &PolyOverZ.

Source§

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>

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

Source§

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

Source§

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

The resulting type after applying the * operator.
Source§

impl Mul<&PolyOverZ> for &MatPolynomialRingZq

Source§

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

The resulting type after applying the * operator.
Source§

impl Mul<&PolyOverZ> for &PolyOverQ

Source§

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

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§

type Output = PolyOverQ

The resulting type after applying the * operator.
Source§

impl Mul<&PolyOverZ> for &PolyOverZq

Source§

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

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

The resulting type after applying the * operator.
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<&Q> for &PolyOverZ

Source§

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§

type Output = PolyOverQ

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &PolyOverZ

Source§

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§

type Output = PolyOverZ

The resulting type after applying the * operator.
Source§

impl Mul<&Zq> for &PolyOverZ

Source§

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

The resulting type after applying the * operator.
Source§

impl Mul for &PolyOverZ

Source§

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

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§

type Output = PolyOverZ

The resulting type after applying the * operator.
Source§

impl MulAssign<&PolyOverZ> for MatPolyOverZ

Source§

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

Documentation at MatPolyOverZ::mul_assign.

Source§

impl MulAssign<&PolyOverZ> for PolyOverQ

Source§

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

Documentation at PolyOverQ::mul_assign.

Source§

impl MulAssign<&PolyOverZ> for PolyOverZ

Source§

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

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

Source§

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

Documentation at PolyOverZq::mul_assign.

Source§

impl MulAssign<&Z> for PolyOverZ

Source§

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

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

Source§

fn mul_assign(&mut self, other: PolyOverZ)

Documentation at MatPolyOverZ::mul_assign.

Source§

impl MulAssign<PolyOverZ> for PolyOverQ

Source§

fn mul_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverQ::mul_assign.

Source§

impl MulAssign<PolyOverZ> for PolyOverZq

Source§

fn mul_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverZq::mul_assign.

Source§

impl MulAssign<Z> for PolyOverZ

Source§

fn mul_assign(&mut self, other: Z)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<i16> for PolyOverZ

Source§

fn mul_assign(&mut self, other: i16)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<i32> for PolyOverZ

Source§

fn mul_assign(&mut self, other: i32)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<i64> for PolyOverZ

Source§

fn mul_assign(&mut self, scalar: i64)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<i8> for PolyOverZ

Source§

fn mul_assign(&mut self, other: i8)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<u16> for PolyOverZ

Source§

fn mul_assign(&mut self, other: u16)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<u32> for PolyOverZ

Source§

fn mul_assign(&mut self, other: u32)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<u64> for PolyOverZ

Source§

fn mul_assign(&mut self, scalar: u64)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<u8> for PolyOverZ

Source§

fn mul_assign(&mut self, other: u8)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign for PolyOverZ

Source§

fn mul_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverZ::mul_assign.

Source§

impl PartialEq<PolyOverZ> for PolyOverQ

Source§

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));
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 PartialEq for PolyOverZ

Source§

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));
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 Rem<&Modulus> for &PolyOverZ

Source§

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§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<&Z> for &PolyOverZ

Source§

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 modulus is smaller than 2.
Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl<Mod: Into<ModulusPolynomialRingZq>> Rem<Mod> for &PolyOverZ

Source§

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§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl<Mod: Into<ModulusPolynomialRingZq>> Rem<Mod> for PolyOverZ

Source§

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§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<i16> for PolyOverZ

Source§

fn rem(self, modulus: i16) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<i32> for PolyOverZ

Source§

fn rem(self, modulus: i32) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<i64> for PolyOverZ

Source§

fn rem(self, modulus: i64) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<i8> for PolyOverZ

Source§

fn rem(self, modulus: i8) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<u16> for PolyOverZ

Source§

fn rem(self, modulus: u16) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<u32> for PolyOverZ

Source§

fn rem(self, modulus: u32) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<u64> for PolyOverZ

Source§

fn rem(self, modulus: u64) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<u8> for PolyOverZ

Source§

fn rem(self, modulus: u8) -> Self::Output

Documentation can be found at PolyOverZ::rem.

Source§

type Output = PolyOverZ

The resulting type after applying the % operator.
Source§

impl Serialize for PolyOverZ

Source§

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

Implements the serialize option. This allows to create a Json-object from a given PolyOverZ.

Source§

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

Source§

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§

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<&PolyOverQ> for &PolyOverZ

Source§

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

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§

type Output = PolyOverQ

The resulting type after applying the - operator.
Source§

impl Sub<&PolyOverZ> for &PolyOverQ

Source§

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

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§

type Output = PolyOverQ

The resulting type after applying the - operator.
Source§

impl Sub<&PolyOverZ> for &PolyOverZq

Source§

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

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

The resulting type after applying the - operator.
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 &PolyOverZ

Source§

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

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

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 for &PolyOverZ

Source§

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

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§

type Output = PolyOverZ

The resulting type after applying the - operator.
Source§

impl SubAssign<&PolyOverZ> for PolyOverQ

Source§

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

Documentation at PolyOverQ::sub_assign.

Source§

impl SubAssign<&PolyOverZ> for PolyOverZ

Source§

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

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

Source§

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

Documentation at PolyOverZq::sub_assign.

Source§

impl SubAssign<&PolyOverZ> for PolynomialRingZq

Source§

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

Documentation at PolynomialRingZq::sub_assign.

Source§

impl SubAssign<PolyOverZ> for PolyOverQ

Source§

fn sub_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverQ::sub_assign.

Source§

impl SubAssign<PolyOverZ> for PolyOverZq

Source§

fn sub_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverZq::sub_assign.

Source§

impl SubAssign<PolyOverZ> for PolynomialRingZq

Source§

fn sub_assign(&mut self, other: PolyOverZ)

Documentation at PolynomialRingZq::sub_assign.

Source§

impl SubAssign for PolyOverZ

Source§

fn sub_assign(&mut self, other: PolyOverZ)

Documentation at PolyOverZ::sub_assign.

Source§

impl Eq for PolyOverZ

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>,