Zq

Struct Zq 

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

Zq is an arbitrary integer value in a residue class.

Attributes:

  • value: holds a Z value for an integer value
  • modulus: holds a Modulus above which the value is reduced

§Examples

use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;

// instantiation
let a = Zq::from((5, 10));
let b = Zq::from_str("93 mod 10")?;
let _ = a.clone();

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

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

Implementations§

Source§

impl Zq

Source

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

Implements addition for two Zq values.

Parameters:

  • other: specifies the value to add to self

Returns the sum of both numbers as a Zq or an error if the modulus does mismatch.

§Examples
use qfall_math::integer_mod_q::Zq;

let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));

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

impl Zq

Source

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

Implements multiplication for two Zq values.

Parameters:

  • other: specifies the value to multiply with self

Returns the product of both numbers as a Zq or an error if the moduli mismatch.

§Examples
use qfall_math::integer_mod_q::Zq;

let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));

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

impl Zq

Source

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

Implements subtraction for two Zq values.

Parameters:

  • other: specifies the value to subtract from self

Returns the result of the subtraction of both numbers as a Zq or an error if the moduli mismatch.

§Examples
use qfall_math::integer_mod_q::Zq;

let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));

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

impl Zq

Source

pub fn from_utf8( message: &str, modulus: impl Into<Modulus>, ) -> Result<Zq, MathError>

Create a Zq integer from a String, i.e. its UTF8-Encoding. The inverse of this function is Zq::to_utf8.

Parameters:

  • message: specifies the message that is transformed via its UTF8-Encoding to a new Zq instance.
  • modulus: Defines the modulus by which value is reduced.

Returns value defined by message mod modulus as Zq or a MathError if the provided modulus is smaller than the UTF8-Encoding of the message.

§Examples
use qfall_math::integer_mod_q::Zq;
let message = "hello!";
  
let value = Zq::from_utf8(&message, i64::MAX).unwrap();
assert_eq!(Zq::from((36762444129640u64, i64::MAX)), value);
§Errors and Failures
  • Returns a ConversionError if the provided modulus is smaller than the UTF8-Encoding of the message.
§Panics …
  • if modulus is smaller than 2.
Source§

impl Zq

Source

pub fn get_representative_least_nonnegative_residue(&self) -> Z

Returns the Z value of the Zq element.

The representation in the range [0, modulus) is returned. Use Zq::get_representative_least_absolute_residue if they should be in the range [-modulus/2, modulus/2].

§Examples
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer::Z;
let zq_value = Zq::from((4, 7));

let z_value = zq_value.get_representative_least_nonnegative_residue();

assert_eq!(Z::from(4), z_value);
Source

pub fn get_representative_least_absolute_residue(&self) -> Z

Returns the Z value of the Zq element with the representatives close to 0.

The output value is in the range of [-modulus/2, modulus/2]. For even moduli, the positive representative is chosen for the element modulus / 2. Use Zq::get_representative_least_nonnegative_residue if they should be in the range [0, modulus).

§Examples
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer::Z;
let zq_value = Zq::from((5, 7));

let z_value = zq_value.get_representative_least_absolute_residue();

assert_eq!(Z::from(2), z_value);
Source

pub fn get_mod(&self) -> Modulus

Returns the Modulus of the Zq element.

§Examples
use qfall_math::integer_mod_q::{Zq, Modulus};
use std::str::FromStr;
let value = Zq::from((4, 7));
let cmp = Modulus::from(7);

let modulus = value.get_mod();

assert_eq!(cmp, modulus);
Source§

impl Zq

Source

pub fn inverse(&self) -> Option<Zq>

Returns the inverse of self as a fresh Zq instance. It returns None if no inverse for self mod q exists.

§Examples
use qfall_math::integer_mod_q::Zq;
let value = Zq::from((4, 7));

let inverse = value.inverse().unwrap();

assert_eq!(Zq::from((2, 7)), inverse);
Source

pub fn is_zero(&self) -> bool

Checks if a Zq is 0.

Returns true if the value is 0.

§Examples
use qfall_math::integer_mod_q::Zq;

let value = Zq::from((0, 7));
assert!(value.is_zero());
Source

pub fn is_one(&self) -> bool

Checks if a Zq is 1.

Returns true if the value is 1.

§Examples
use qfall_math::integer_mod_q::Zq;

let value = Zq::from((1, 7));
assert!(value.is_one());
Source§

impl Zq

Source

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

Chooses a Zq instance according to the binomial distribution parameterized by n and p.

Parameters:

  • modulus: specifies the Modulus of the new Zq instance
  • n: specifies the number of trials
  • p: specifies the probability of success

Returns a fresh Zq instance with a value sampled according to the binomial distribution or a MathError if n < 0, p ∉ (0,1), or n does not fit into an i64.

§Examples
use qfall_math::integer_mod_q::Zq;

let sample = Zq::sample_binomial(7, 2, 0.5).unwrap();
§Errors and Failures
§Panics …
  • if modulus is smaller than 2.
Source§

impl Zq

Source

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

Chooses a Zq instance chosen according to the discrete Gaussian distribution in [center - ⌈6 * s⌉ , center + ⌊ 6 * s⌋ ].

This function samples discrete Gaussians according to the definition of SampleZ in GPV08.

Parameters:

  • modulus: specifies the modulus of the new Zq element
  • center: specifies the position of the center with peak probability
  • s: specifies the Gaussian parameter, which is proportional to the standard deviation sigma * sqrt(2 * pi) = s

Returns new Zq sample chosen according to the specified discrete Gaussian distribution or a MathError if the specified parameters were not chosen appropriately, i.e. s < 0.

§Examples
use qfall_math::integer_mod_q::Zq;

let sample = Zq::sample_discrete_gauss(17, 0, 1).unwrap();
§Errors and Failures
§Panics …
  • if modulus is smaller than 2.

This function implements SampleZ according to:

  • [1] Gentry, Craig and Peikert, Chris and Vaikuntanathan, Vinod (2008). Trapdoors for hard lattices and new cryptographic constructions. In: Proceedings of the fortieth annual ACM symposium on Theory of computing. https://dl.acm.org/doi/pdf/10.1145/1374376.1374407
Source§

impl Zq

Source

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

Chooses a Zq instance uniformly at random in [0, modulus).

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

Parameters:

  • modulus: specifies the Modulus of the new Zq instance and thus the size of the interval over which is sampled

Returns a new Zq instance with a value chosen uniformly at random in [0, modulus).

§Examples
use qfall_math::integer_mod_q::Zq;

let sample = Zq::sample_uniform(17);
§Panics
  • if the given modulus is smaller than or equal to 1.
Source§

impl Zq

Source

pub fn to_utf8(&self) -> Result<String, FromUtf8Error>

Enables conversion to a UTF8-Encoded String for Zq values. The inverse to this function is Zq::from_utf8 for valid UTF8-Encodings.

Warning: Not every byte-sequence forms a valid UTF8-character. If this is the case, a FromUtf8Error will be returned.

Returns the corresponding UTF8-encoded String or a FromUtf8Error if the byte sequence contains an invalid UTF8-character.

§Examples
use qfall_math::integer_mod_q::Zq;
let value = Zq::from((10, 63));

let text: String = value.to_utf8().unwrap();
§Errors and Failures
  • Returns a FromUtf8Error if the integer’s byte sequence contains valid UTF8-characters.
Source§

impl Zq

Source

pub unsafe fn get_fmpz(&mut self) -> &mut fmpz

Returns a mutable reference to the underlying fmpz by calling get_fmpz on value.

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 Zq

Source

pub unsafe fn get_fmpz_mod_ctx(&mut self) -> &mut fmpz_mod_ctx

Returns a mutable reference to the underlying fmpz_mod_ctx by calling get_fmpz_mod_ctx on modulus.

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

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

§Safety

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

Source§

impl Zq

Source

pub unsafe fn set_fmpz(&mut self, flint_struct: fmpz)

Sets the field fmpz to flint_struct by calling set_fmpz on value.

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 Zq

Source

pub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx)

Sets the field fmpz_mod_ctx to flint_struct by calling set_fmpz_mod_ctx on modulus.

Parameters:

  • flint_struct: value to set the attribute to

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

§Safety

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

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

Trait Implementations§

Source§

impl Add<&Z> for &Zq

Source§

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

Implements the Add trait for Zq and Z values. Add is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to add to self

Returns the sum of both numbers as a Zq.

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

let a: Zq = Zq::from((42, 19));
let b: Z = Z::from(42);

let c: Zq = &a + &b;
let d: Zq = a + b;
let e: Zq = &c + Z::from(42);
let f: Zq = c + &Z::from(42);
Source§

type Output = Zq

The resulting type after applying the + operator.
Source§

impl Add<&Zq> for &Z

Source§

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

Implements the Add trait for Z and Zq values. Add is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to add to self

Returns the sum of both numbers as a Zq.

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

let a: Z = Z::from(42);
let b: Zq = Zq::from((42, 19));

let c: Zq = &a + &b;
let d: Zq = a + b;
let e: Zq = &Z::from(42) + d;
let f: Zq = Z::from(42) + &e;
Source§

type Output = Zq

The resulting type after applying the + operator.
Source§

impl Add for &Zq

Source§

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

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

Parameters:

  • other: specifies the value to add to self

Returns the sum of both numbers as a Zq.

§Examples
use qfall_math::integer_mod_q::Zq;

let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));

let c: Zq = &a + &b;
let d: Zq = a + b;
let e: Zq = &c + d;
let f: Zq = c + &e;
§Panics …
  • if the moduli of both Zq mismatch.
Source§

type Output = Zq

The resulting type after applying the + operator.
Source§

impl AddAssign<&Z> for Zq

Source§

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

Documentation at Zq::add_assign.

Source§

impl AddAssign<&Zq> for Zq

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 Zq in combination with Zq, Z, i64, i32, i16, i8, u64, u32, u16 and u8.

Parameters:

  • other: specifies the value to add to self

Returns the sum of both numbers modulo q as a Zq.

§Examples
use qfall_math::{integer_mod_q::Zq, integer::Z};

let mut a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Z = Z::from(5);

a += &b;
a += b;
a += 5;
a += c;
§Panics …
  • if the moduli of both Zq mismatch.
Source§

impl AddAssign<Z> for Zq

Source§

fn add_assign(&mut self, other: Z)

Documentation at Zq::add_assign.

Source§

impl AddAssign<i16> for Zq

Source§

fn add_assign(&mut self, other: i16)

Documentation at Zq::add_assign.

Source§

impl AddAssign<i32> for Zq

Source§

fn add_assign(&mut self, other: i32)

Documentation at Zq::add_assign.

Source§

impl AddAssign<i64> for Zq

Source§

fn add_assign(&mut self, other: i64)

Documentation at Zq::add_assign.

Source§

impl AddAssign<i8> for Zq

Source§

fn add_assign(&mut self, other: i8)

Documentation at Zq::add_assign.

Source§

impl AddAssign<u16> for Zq

Source§

fn add_assign(&mut self, other: u16)

Documentation at Zq::add_assign.

Source§

impl AddAssign<u32> for Zq

Source§

fn add_assign(&mut self, other: u32)

Documentation at Zq::add_assign.

Source§

impl AddAssign<u64> for Zq

Source§

fn add_assign(&mut self, other: u64)

Documentation at Zq::add_assign.

Source§

impl AddAssign<u8> for Zq

Source§

fn add_assign(&mut self, other: u8)

Documentation at Zq::add_assign.

Source§

impl AddAssign for Zq

Source§

fn add_assign(&mut self, other: Zq)

Documentation at Zq::add_assign.

Source§

impl Clone for Zq

Source§

fn clone(&self) -> Zq

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<&Zq> for MatNTTPolynomialRingZq

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

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<&Zq> for MatZq

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<&Zq> for NTTPolynomialRingZq

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<&Zq> for PolyOverZq

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

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 Zq

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<Zq> for MatNTTPolynomialRingZq

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<Zq> for MatPolynomialRingZq

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<Zq> for MatZq

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<Zq> for NTTPolynomialRingZq

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<Zq> for PolyOverZq

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

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

Source§

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

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

impl<'de> Deserialize<'de> for Zq

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 Zq

Source§

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

Allows to convert an integer of type Zq into a String.

Returns the integer in form of a String. For integer 2 mod 4 the String looks like this 2 mod 4.

§Examples
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
use core::fmt;

let integer_mod_q = Zq::from((42, 3));
println!("{integer_mod_q}");
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
use core::fmt;

let integer_mod_q = Zq::from((42, 3));
let integer_string = integer_mod_q.to_string();
Source§

impl Evaluate<&Zq, Zq> for PolyOverZq

Source§

fn evaluate(&self, value: &Zq) -> Zq

Evaluates a PolyOverZq on a given input of Zq. Note that the Zq in this case is only a reference. Note that this function will panic if the modulus of the input and the polynomial mismatch. Use PolyOverZq::evaluate_safe if a panic has to be avoided.

Parameters:

  • value: the value with which to evaluate the polynomial.

Returns the evaluation of the polynomial as a Zq.

§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;

let poly = PolyOverZq::from_str("5  0 1 2 -3 1 mod 17").unwrap();
let value = Zq::from((3, 17));
let res = poly.evaluate(&value);
§Panics …
  • if the moduli of the polynomial and the input mismatch.
Source§

impl<Integer: Into<Z>> Evaluate<Integer, Zq> for PolyOverZq

Source§

fn evaluate(&self, value: Integer) -> Zq

Evaluates a PolyOverZq on a given input that implements Into<Z>.

Parameters:

  • value: the value with which to evaluate the polynomial.

Returns the evaluation of the polynomial as a Zq.

§Examples
use qfall_math::traits::*;
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;

let poly = PolyOverZq::from_str("5  0 1 2 -3 1 mod 17").unwrap();
let value = Z::from(3);

let res = poly.evaluate(&value);
let res_2 = poly.evaluate(3);
Source§

impl Evaluate<Zq, Zq> for PolyOverZq

Source§

fn evaluate(&self, value: Zq) -> Zq

Documentation can be found at PolyOverZq::evaluate for &Zq.

Source§

impl From<&Zq> for PolyOverZq

Source§

fn from(value: &Zq) -> Self

Creates a constant PolyOverZq, i.e. the polynomial x mod q, where x is the value of the given Zq value and q its modulus.

Parameters:

  • value: the constant value the polynomial will have.

Returns a new constant PolyOverZq with the specified value and modulus of the Zq value.

§Examples
use qfall_math::{integer_mod_q::*, traits::*};

let poly = PolyOverZq::from(&Zq::from((1, 10)));

let poly_cmp = PolyOverZq::from((1, 10));
assert_eq!(poly, poly_cmp);
assert_eq!(poly.get_degree(), 0);
Source§

impl From<&Zq> for String

Source§

fn from(value: &Zq) -> Self

Converts a Zq into its String representation.

Parameters:

  • value: specifies the integer and modulus that will be represented as a String

Returns a String of the form "x mod q".

§Examples
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let zq = Zq::from_str("3 mod 5").unwrap();

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

impl From<&Zq> for Zq

Source§

fn from(value: &Zq) -> Self

An alias for Zq::clone. It makes the use of generic Into<Zq> types easier.

Source§

impl<IntegerValue: Into<Z>, IntegerModulus: Into<Modulus>> From<(IntegerValue, IntegerModulus)> for Zq

Source§

fn from((value, modulus): (IntegerValue, IntegerModulus)) -> Self

Creates a Zq from a tuple with the integer and the modulus.

Parameters:

  • value: Defines the value of the residue class.
  • modulus: Defines the modulus by which value is reduced.

Note that the strings for integer and modulus are trimmed, i.e. all whitespaces around all values are ignored.

Returns the value mod modulus as a Zq.

§Examples
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer::Z;

let answer_1 = Zq::from((1337 + 42, 1337));
let answer_2 = Zq::from((Z::from(42), 1337));

assert_eq!(answer_1, answer_2);
§Panics …
  • if modulus is smaller than 2.
Source§

impl<Mod: Into<Modulus>> From<Mod> for Zq

Source§

fn from(modulus: Mod) -> Self

Creates a zero integer with a given Modulus.

Parameters:

  • modulus: of the new Zq

Returns a new constant Zq with the specified Modulus.

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

let zq = Zq::from(100);

let zq_cmp = Zq::from_str("0 mod 100").unwrap();
assert_eq!(zq, zq_cmp);
§Panics …
  • if modulus is smaller than 2.
Source§

impl From<Zq> for PolyOverZq

Source§

fn from(value: Zq) -> Self

Documentation can be found at PolyOverZq::from for &Zq.

Source§

impl From<Zq> for String

Source§

fn from(value: Zq) -> Self

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

Source§

impl FromStr for Zq

Source§

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

Creates a Zq integer from a String.

Parameters:

  • s: the integer and modulus value of form: "12 mod 25" for the number 12 under the modulus 25.

Returns a Zq or an error if the provided string was not formatted correctly.

§Examples
use std::str::FromStr;
use qfall_math::integer_mod_q::Zq;
  
let a: Zq = "100 mod 3".parse().unwrap();
let b: Zq = Zq::from_str("100 mod 3").unwrap();
§Errors and Failures
  • Returns a MathError of type StringConversionError
    • if the provided string contains a Null byte,
    • if the provided string was not formatted correctly,
    • if the provided modulus was not formatted correctly to create a Z, or
    • if the delimiter mod could not be found.
  • Returns a MathError of type InvalidModulus if the provided value is smaller than 2.
  • Returns a MathError of type
Source§

type Err = MathError

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

impl GetCoefficient<Zq> for ModulusPolynomialRingZq

Source§

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

Returns the coefficient of a polynomial ModulusPolynomialRingZq 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.

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

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

let coeff_0: Zq = poly.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4: Zq = poly.get_coeff(4).unwrap();

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

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

Source§

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 PolyOverZq

Source§

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

Returns the coefficient of a polynomial PolyOverZq as a Zq.

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

Parameters:

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

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

§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;

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

let coeff_0: Zq = poly.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4: Zq = poly.get_coeff(4).unwrap();

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

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

Source§

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 MatrixGetEntry<Zq> for MatZq

Source§

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

Outputs the Zq 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 Zq 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::{MatZq, Zq};
use qfall_math::traits::MatrixGetEntry;
use std::str::FromStr;

let matrix = MatZq::from_str("[[1, 2, 3],[4, 5, 6],[7, 8, 9]] mod 10").unwrap();

assert_eq!(Zq::from((3, 10)), unsafe { matrix.get_entry_unchecked(0, 2) } );
assert_eq!(Zq::from((8, 10)), unsafe { matrix.get_entry_unchecked(2, 1) } );
assert_eq!(Zq::from((8, 10)), unsafe { matrix.get_entry_unchecked(2, 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 MatrixSetEntry<&Zq> for MatZq

Source§

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

Sets the value of a specific matrix entry according to a given value of type Zq without checking whether the coordinate is part of the matrix, if the moduli match or 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::{MatZq, Zq};
use qfall_math::traits::*;

let mut matrix = MatZq::new(3, 3, 10);
let value = Zq::from((5, 10));

unsafe {
    matrix.set_entry_unchecked(0, 1, &value);
    matrix.set_entry_unchecked(2, 2, Zq::from((19, 10)));
}

assert_eq!("[[0, 5, 0],[0, 0, 0],[0, 0, 9]] mod 10", 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<Zq> for MatZq

Source§

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

Documentation can be found at MatZq::set_entry for &Zq.

Source§

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

Documentation can be found at MatZq::set_entry for &Zq.

Source§

impl Mul<&Z> for &Zq

Source§

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

Implements the Mul trait for Zq and Z values. Mul is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to multiply with self

Returns the product of both numbers as a Zq.

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

let a: Zq = Zq::from((42, 19));
let b: Z = Z::from(42);

let c: Zq = &a * &b;
let d: Zq = a * b;
let e: Zq = &c * Z::from(42);
let f: Zq = c * &Z::from(42);
Source§

type Output = Zq

The resulting type after applying the * operator.
Source§

impl Mul<&Zq> for &MatPolynomialRingZq

Source§

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

Implements the Mul trait for a MatPolynomialRingZq matrix with a Zq integer. 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, Zq};
use qfall_math::integer::{MatPolyOverZ, Z};
use std::str::FromStr;

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

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

type Output = MatPolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul<&Zq> for &MatZ

Source§

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

Implements the Mul trait for a MatZ matrix with a Zq representative of a residue class. 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 MatZq.

§Examples
use qfall_math::integer::MatZ;
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;

let mat_1 = MatZ::from_str("[[2, 1],[1, 2]]").unwrap();
let zq = Zq::from((1,3));

let mat_2 = &mat_1 * &zq;
Source§

type Output = MatZq

The resulting type after applying the * operator.
Source§

impl Mul<&Zq> for &MatZq

Source§

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

Implements the Mul trait for a MatZq matrix with a Zq. 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 MatZq.

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

let mat_1 = MatZq::from_str("[[42, 17],[8, 6]] mod 61").unwrap();
let integer = Zq::from((2, 61));

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

type Output = MatZq

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<&Zq> for &PolyOverZq

Source§

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

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

Parameters:

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

Returns the product of self and scalar as a PolyOverZq.

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

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

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

type Output = PolyOverZq

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<&Zq> for &Z

Source§

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

Implements the Mul trait for Z and Zq values. Mul is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to multiply with self

Returns the product of both numbers as a Zq.

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

let a: Z = Z::from(42);
let b: Zq = Zq::from((42, 9));

let c: Zq = &a * &b;
let d: Zq = a * b;
let e: Zq = &Z::from(42) * d;
let f: Zq = Z::from(42) * &e;
Source§

type Output = Zq

The resulting type after applying the * operator.
Source§

impl Mul for &Zq

Source§

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

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

Parameters:

  • other: specifies the value to multiply with self

Returns the product of both numbers as a Zq.

§Examples
use qfall_math::integer_mod_q::Zq;

let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));

let c: Zq = &a * &b;
let d: Zq = a * b;
let e: Zq = &c * d;
let f: Zq = c * &e;
§Panics …
  • if the moduli of both Zq mismatch.
Source§

type Output = Zq

The resulting type after applying the * operator.
Source§

impl MulAssign<&Z> for Zq

Source§

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

Documentation at Zq::mul_assign.

Source§

impl MulAssign<&Zq> for MatPolynomialRingZq

Source§

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

Documentation at MatPolynomialRingZq::mul_assign.

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

impl MulAssign<&Zq> for MatZq

Source§

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

Documentation at MatZq::mul_assign

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

impl MulAssign<&Zq> for PolyOverZq

Source§

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

Documentation at PolyOverZq::mul_assign

§Panics …
  • if the moduli are different.
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<&Zq> for Zq

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 Zq in combination with Zq, Z, i64, i32, i16, i8, u64, u32, u16 and u8.

Parameters:

  • other: specifies the value to multiply to self

Returns the product of both numbers modulo q as a Zq.

§Examples
use qfall_math::{integer_mod_q::Zq, integer::Z};

let mut a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Z = Z::from(5);

a *= &b;
a *= b;
a *= 5;
a *= c;
§Panics …
  • if the moduli of both Zq mismatch.
Source§

impl MulAssign<Z> for Zq

Source§

fn mul_assign(&mut self, other: Z)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<Zq> for MatPolynomialRingZq

Source§

fn mul_assign(&mut self, other: Zq)

Source§

impl MulAssign<Zq> for MatZq

Source§

fn mul_assign(&mut self, other: Zq)

Documentation at MatZq::mul_assign.

Source§

impl MulAssign<Zq> for PolyOverZq

Source§

fn mul_assign(&mut self, other: Zq)

Documentation at PolyOverZq::mul_assign.

Source§

impl MulAssign<Zq> for PolynomialRingZq

Source§

fn mul_assign(&mut self, other: Zq)

Documentation at PolynomialRingZq::mul_assign.

Source§

impl MulAssign<i16> for Zq

Source§

fn mul_assign(&mut self, other: i16)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<i32> for Zq

Source§

fn mul_assign(&mut self, other: i32)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<i64> for Zq

Source§

fn mul_assign(&mut self, other: i64)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<i8> for Zq

Source§

fn mul_assign(&mut self, other: i8)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<u16> for Zq

Source§

fn mul_assign(&mut self, other: u16)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<u32> for Zq

Source§

fn mul_assign(&mut self, other: u32)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<u64> for Zq

Source§

fn mul_assign(&mut self, other: u64)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<u8> for Zq

Source§

fn mul_assign(&mut self, other: u8)

Documentation at Zq::mul_assign.

Source§

impl MulAssign for Zq

Source§

fn mul_assign(&mut self, other: Zq)

Documentation at Zq::mul_assign.

Source§

impl PartialEq for Zq

Source§

fn eq(&self, other: &Zq) -> 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<Integer: Into<Z>> Pow<Integer> for Zq

Source§

fn pow(&self, exp: Integer) -> Result<Self::Output, MathError>

Raises the value of self to the power of an integer exp.

Parameters:

  • exp: specifies the exponent to which the value is raised

Returns the value of self powered by exp as a new Output instance or an error if the exponent is negative and the base value of self is not invertible.

§Examples
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::Zq;
use qfall_math::traits::*;

let base = Zq::from((2, 9));

let powered_value = base.pow(4).unwrap();

let cmp = Zq::from((7, 9));
assert_eq!(cmp, powered_value);
§Errors and Failures
  • Returns a MathError of type InvalidExponent if the provided exponent is negative and the base value of self is not invertible.
Source§

type Output = Zq

Source§

impl Serialize for Zq

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 PolyOverZq

Source§

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

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

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

Parameters:

  • index: the index of the coefficient to set (has to be positive)
  • value: the new value the index should have from a borrowed Zq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::Zq;
use qfall_math::traits::*;
use std::str::FromStr;

let mut poly = PolyOverZq::from_str("4  0 1 2 3 mod 17").unwrap();
let value = Zq::from((1000, 17));

assert!(poly.set_coeff(4, &value).is_ok());
unsafe{ poly.set_coeff_unchecked(5, &value) };
§Safety

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

Source§

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)

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 SetCoefficient<Zq> for PolyOverZq

Source§

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

Documentation can be found at PolyOverZq::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 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<&Z> for &Zq

Source§

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

Implements the Sub trait for Zq and Z values. Sub is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to subtract from self

Returns the result of the subtraction of both numbers as a Zq.

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

let a: Zq = Zq::from((42, 19));
let b: Z = Z::from(42);

let c: Zq = &a - &b;
let d: Zq = a - b;
let e: Zq = &c - Z::from(42);
let f: Zq = c - &Z::from(42);
Source§

type Output = Zq

The resulting type after applying the - operator.
Source§

impl Sub<&Zq> for &Z

Source§

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

Implements the Sub trait for Z and Zq values. Sub is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to subtract from self

Returns the result of subtraction of both numbers as a Zq.

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

let a: Z = Z::from(42);
let b: Zq = Zq::from((42, 19));

let c: Zq = &a - &b;
let d: Zq = a - b;
let e: Zq = &Z::from(42) - d;
let f: Zq = Z::from(42) - &e;
Source§

type Output = Zq

The resulting type after applying the - operator.
Source§

impl Sub for &Zq

Source§

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

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

Parameters:

  • other: specifies the value to subtract from self

Returns the result of the subtraction of both numbers as a Zq.

§Examples
use qfall_math::integer_mod_q::Zq;

let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));

let c: Zq = &a - &b;
let d: Zq = a - b;
let e: Zq = &c - d;
let f: Zq = c - &e;
§Panics …
  • if the moduli of both Zq mismatch.
Source§

type Output = Zq

The resulting type after applying the - operator.
Source§

impl SubAssign<&Z> for Zq

Source§

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

Documentation at Zq::sub_assign.

Source§

impl SubAssign<&Zq> for Zq

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 Zq in combination with Zq, Z, i64, i32, i16, i8, u64, u32, u16 and u8.

Parameters:

  • other: specifies the value to subtract from self

Returns the difference of both numbers modulo q as a Zq.

§Examples
use qfall_math::{integer_mod_q::Zq, integer::Z};

let mut a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Z = Z::from(5);

a -= &b;
a -= b;
a -= 5;
a -= c;
§Panics …
  • if the moduli of both Zq mismatch.
Source§

impl SubAssign<Z> for Zq

Source§

fn sub_assign(&mut self, other: Z)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<i16> for Zq

Source§

fn sub_assign(&mut self, other: i16)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<i32> for Zq

Source§

fn sub_assign(&mut self, other: i32)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<i64> for Zq

Source§

fn sub_assign(&mut self, other: i64)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<i8> for Zq

Source§

fn sub_assign(&mut self, other: i8)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<u16> for Zq

Source§

fn sub_assign(&mut self, other: u16)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<u32> for Zq

Source§

fn sub_assign(&mut self, other: u32)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<u64> for Zq

Source§

fn sub_assign(&mut self, other: u64)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<u8> for Zq

Source§

fn sub_assign(&mut self, other: u8)

Documentation at Zq::sub_assign.

Source§

impl SubAssign for Zq

Source§

fn sub_assign(&mut self, other: Zq)

Documentation at Zq::sub_assign.

Source§

impl Eq for Zq

Source§

impl StructuralPartialEq for Zq

Auto Trait Implementations§

§

impl Freeze for Zq

§

impl RefUnwindSafe for Zq

§

impl !Send for Zq

§

impl !Sync for Zq

§

impl Unpin for Zq

§

impl UnwindSafe for Zq

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