Z

Struct Z 

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

Z is an arbitrary integer value.

Attributes:

§Implicit Typecasting

Most of our functions take as input values of type Into<Z>. These capture all types that can be turned into a Z value. The types are Z,Modulus, i8, i16,i32,i64,u8,u16,u32,u64 and the references of all of these types. These types are then implicitly casted to a Z before the desired action is performed.

§Examples

use qfall_math::integer::Z;
use std::str::FromStr;

// instantiations
let a = Z::from_str("-876543")?;
let b = Z::from(i64::MIN);
let zero = Z::default();

// arithmetics
let _ = &a * b.clone();
let _ = &b - zero;

// comparison
assert_ne!(b, a);

// to_string incl. (de-)serialization
assert_eq!("-876543", &a.to_string());
assert_eq!(
    "{\"value\":\"-876543\"}",
    serde_json::to_string(&a).unwrap()
);

Implementations§

Source§

impl Z

Source

pub fn div_floor(&self, other: impl Into<Z>) -> Self

Divides self by other and the result is rounded down.

Parameters:

  • other: specifies the value to divide self by

Returns the quotient of both numbers as a Z floored.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(42);
let b: Z = Z::from(20);

let c = a.div_floor(&b);
let d = a.div_floor(20);

assert_eq!(Z::from(2), c);
assert_eq!(Z::from(2), d);
§Panics …
  • if the divisor is 0.
Source

pub fn div_ceil(&self, other: impl Into<Z>) -> Self

Divides self by other and the result is rounded up.

Parameters:

  • other: specifies the value to divide self by

Returns the quotient of both numbers as a Z ceiled.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(42);
let b: Z = Z::from(20);

let c = a.div_ceil(&b);
let d = a.div_ceil(20);

assert_eq!(Z::from(3), c);
assert_eq!(Z::from(3), d);
§Panics …
  • if the divisor is 0.
Source

pub fn div_exact(&self, other: impl Into<Z>) -> Option<Self>

Divides self by other and returns a result if it is integer.

Parameters:

  • other: specifies the value to divide self by

Returns the quotient of both numbers as a Z or None if the quotient is not integer.

§Examples
use qfall_math::integer::Z;

let a_0: Z = Z::from(40);
let a_1: Z = Z::from(42);
let b: Z = Z::from(20);

let c_0 = a_0.div_exact(&b).unwrap();
let c_1 = a_1.div_exact(&b);

assert_eq!(Z::from(2), c_0);
assert!(c_1.is_none());
§Panics …
  • if the divisor is 0.
Source§

impl Z

Source

pub fn exp_taylor(&self, length_taylor_polynomial: impl Into<u32>) -> Q

Computes e^self using taylor series approximation of the exponential function.

Parameters:

  • length_taylor_polynomial: the length of the taylor series approximation of the exponential function

Returns e^self.

§Examples
use qfall_math::integer::Z;

// sum_{k=0}^999 17^k/k!
let evaluation = Z::from(17).exp_taylor(1000_u32);
Source§

impl Z

Source

pub fn log_ceil(&self, base: impl Into<Z>) -> Result<Z, MathError>

Computes the logarithm of a natural number (i.e. an integer greater than 0) with a base greater than 1 rounded up.

Warning: It assumes that the return value fits in an i64.

Parameters:

  • base: the base of the logarithm

Returns $\lceil log_base(self) \rceil$ as a Z instance or a MathError, if at least one of the conditions base > 1 and self > 0 isn’t met.

§Examples
use qfall_math::integer::Z;

let value = Z::from(15);
let log = value.log_ceil(4).unwrap();

assert_eq!(Z::from(2), log);
§Errors and Failures
Source

pub fn log_floor(&self, base: impl Into<Z>) -> Result<Z, MathError>

Computes the logarithm of a natural number (i.e. an integer greater than 0) with a base greater than 1 rounded down.

Warning: It assumes that the return value fits in an i64.

Parameters:

  • base: the base of the logarithm

Returns $\lfloor log_base(self) \rfloor$ as a Z instance or a MathError, if at least one of the conditions base > 1 and self > 0 isn’t met.

§Examples
use qfall_math::integer::Z;

let value = Z::from(15);
let log = value.log_floor(4).unwrap();

assert_eq!(Z::from(1), log);
§Errors and Failures
Source

pub fn ln(&self) -> Result<Q, MathError>

Computes the natural logarithm of a natural number (i.e. an integer greater than 0) approximated as an f64 and returned as a Q.

Warning: It assumes that the return value does not overflow an f64.

Returns the double precision approximation of the natural logarithm of self or a MathError, if self is smaller than 1.

§Examples
use qfall_math::integer::Z;
use qfall_math::rational::Q;

let value = Z::from(1);
let log = value.ln().unwrap();

assert_eq!(Q::ZERO, log);
§Errors and Failures
Source

pub fn log(&self, base: impl Into<Z>) -> Result<Q, MathError>

Computes the logarithm of a natural number (i.e. an integer greater than 0) with an integer base greater than 1 approximated as an f64 and returned as a Q.

Warning: It assumes that the return value does not overflow an f64.

Parameters:

  • base: the base of the logarithm

Returns log_base(self) as a Q instance or a MathError, if at least one of the conditions base > 1 and self > 0 isn’t met.

§Examples
use qfall_math::integer::Z;
use qfall_math::rational::Q;

let value = Z::from(2);
let log = value.log(2).unwrap();

assert_eq!(Q::ONE, log);
§Errors and Failures
Source§

impl Z

Source

pub fn sqrt(&self) -> Q

Calculate the square root with a fixed precision.

The error of the result is smaller than ±10⁻⁹. The actual result may be more accurate and is the best approximation for the resulting denominator.

Returns the square root with a precision of ±10⁻⁹.

§Examples
use qfall_math::integer::Z;

let value = Z::from(2);
let root = value.sqrt();
§Panics …
  • if the provided value is negative.
Source

pub fn sqrt_precision(&self, precision: &Z) -> Result<Q, MathError>

Calculate the square root with a specified minimum precision.

The actual result may be more accurate and is the best approximation for the resulting denominator. The continued fractions expansion is used to approximate the square root.

Parameters:

  • precision specifies the upper limit of the error as 1/(2*precision). The precision must be larger than zero.

Returns the square root with a specified minimum precision or an error if the precision is not larger than zero or the parameter of the square root is negative.

§Examples
use qfall_math::integer::Z;
use qfall_math::rational::Q;

let value = Z::from(42);
let precision = Z::from(1000);

let root = value.sqrt_precision(&precision);
§Errors and Failures
Source§

impl Z

Source

pub const ONE: Z

Returns an instantiation of Z with value 1.

§Examples
use qfall_math::integer::Z;
  
let a: Z = Z::ONE;
Source

pub const ZERO: Z

Returns an instantiation of Z with value 0.

§Examples
use qfall_math::integer::Z;
  
let a: Z = Z::ZERO;
Source

pub const MINUS_ONE: Z

Returns an instantiation of Z with value -1.

§Examples
use qfall_math::integer::Z;
  
let a: Z = Z::MINUS_ONE;
Source§

impl Z

Source

pub fn from_str_b(s: &str, base: i32) -> Result<Self, MathError>

Creates a Z integer from a String. This function takes a base between 2 and 62 in which the number is represented.

Parameters:

  • s: the integer value as a string
  • base: the base in which the integer is represented

Returns a Z or an error if the provided string was not formatted correctly, the provided string contains a Null byte or the base is out of bounds.

§Examples
use qfall_math::integer::Z;
  
let a: Z = Z::from_str_b("100", 2).unwrap();
assert_eq!(Z::from(4), a);
§Errors and Failures
Source

pub fn from_bytes(bytes: &[u8]) -> Self

Creates a Z integer from an iterable of u8s, i.e. a vector of bytes. This function can only construct positive or zero integers, but not negative ones. The inverse function to Z::from_bytes is Z::to_bytes for positive numbers including 0.

Parameters:

  • bytes: specifies an iterable of bytes that should be set in the new Z instance. The first byte should be the least significant byte, i.e. its first bit the least significant bit.

Returns a Z with the value provided by the byte iterable.

§Examples
use qfall_math::integer::Z;
// instantiate a byte-vector corresponding to "100000001"
// vec![0x01, 0x01] would also be sufficient
let bytes: Vec<u8> = vec![1, 1];
  
let a: Z = Z::from_bytes(&bytes);
assert_eq!(Z::from(257), a);
Source

pub fn from_bits(bits: &[bool]) -> Z

Creates a Z integer from an iterable of bools, i.e. a vector of bits. This function can only construct positive or zero integers, but not negative ones.

Parameters:

  • bits: specifies an iterable of bits that should be set in the new Z instance. The first bit should be the least significant bit.

Returns a Z with the value provided by the bit iterable.

§Examples
use qfall_math::integer::Z;
// instantiate a bit-vector corresponding to "101"
let bits: Vec<bool> = vec![true, false, true];
  
let a: Z = Z::from_bits(&bits);
assert_eq!(Z::from(5), a);
Source

pub fn from_utf8(message: &str) -> Z

Create a Z integer from a String, i.e. its UTF8-Encoding. This function can only construct positive or zero integers, but not negative ones. The inverse of this function is Z::to_utf8.

Parameters:

  • message: specifies the message that is transformed via its UTF8-Encoding to a new Z instance.

Returns a Z with corresponding value to the message’s UTF8-Encoding.

§Examples
use qfall_math::integer::Z;
let message = "hello!";
  
let value = Z::from_utf8(&message);
assert_eq!(Z::from(36762444129640u64), value);
Source§

impl Z

Source

pub fn bit_complement(&self) -> Self

Outputs the bit-wise complement of self.

§Examples
use qfall_math::integer::Z;
let value = Z::from(4);

let complement = value.bit_complement();
let complement_twice = complement.bit_complement();

assert_eq!(Z::from(-5), complement);
assert_eq!(value, complement_twice);
Source§

impl Z

Source

pub fn is_zero(&self) -> bool

Checks if a Z is 0.

Returns true if the value is 0.

§Examples
use qfall_math::integer::Z;

let value = Z::ZERO;
assert!(value.is_zero());
Source

pub fn is_one(&self) -> bool

Checks if a Z is 1.

Returns true if the value is 1.

§Examples
use qfall_math::integer::Z;

let value = Z::ONE;
assert!(value.is_one());
Source

pub fn is_prime(&self) -> bool

Checks if a Z is prime.

Returns true if the value is prime.

§Examples
use qfall_math::integer::Z;

let value = Z::from(17);
assert!(value.is_prime());
Source

pub fn abs(self) -> Self

Returns the given Z instance with its absolute value.

§Examples
use qfall_math::integer::Z;
let mut value = Z::from(-1);

let value = value.abs();

assert_eq!(Z::ONE, value);
Source

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

Returns the inverse of self as a fresh Q instance.

As the inverse of 0 is undefined, it returns None in case self == 0.

§Examples
use qfall_math::{integer::Z, rational::Q};
let value = Z::from(4);

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

assert_eq!(Q::from((1, 4)), inverse);
Source

pub fn bits(&self) -> u64

Computes the number of bits needed to store the absolute value of self.

The number of bits needs to fit into an u64, i.e. the size should not exceed 2^(2^64). Otherwise, the result is undefined.

§Examples
use qfall_math::integer::Z;
let value = Z::from(4);

let nr_bits = value.bits();

assert_eq!(3, nr_bits);
Source

pub fn to_bits(&self) -> Vec<bool>

Computes the Vec of bool bits corresponding to the bits of the absolute value of self.

The first bit is the least significant bit.

§Examples
use qfall_math::integer::Z;
let value = Z::from(4);

let vec_bits = value.to_bits();

assert_eq!(vec![false, false, true], vec_bits);
Source

pub fn is_perfect_power(&self) -> Option<(Self, i32)>

Computes a pair (root, exp) s.t. root^exp = self if self is a perfect power and can be represented via root.pow(exp).

This algorithm tries to find the smallest perfect root, but there is no formal guarantee to find it.

Returns a pair (root, exp) if root.pow(exp) = self exists. Otherwise, None is returned.

§Examples
use qfall_math::integer::Z;
let value = Z::from(16);

let (root, exp) = value.is_perfect_power().unwrap();

assert_eq!(root, Z::from(2));
assert_eq!(exp, 4);
Source§

impl Z

Source

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

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

Parameters:

  • n: specifies the number of trials
  • p: specifies the probability of success

Returns a fresh Z 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::Z;

let sample = Z::sample_binomial(2, 0.5).unwrap();
§Errors and Failures
Source§

impl Z

Source

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

Chooses a Z instance 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:

  • n: specifies the range from which is sampled
  • 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 Z 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::Z;

let sample = Z::sample_discrete_gauss(0, 1).unwrap();
§Errors and Failures

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 Z

Source

pub fn sample_uniform( lower_bound: impl Into<Z>, upper_bound: impl Into<Z>, ) -> Result<Self, MathError>

Chooses a Z instance uniformly 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:

  • 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 Z instance with a uniform random value in [lower_bound, upper_bound) or a MathError if the provided interval was chosen too small.

§Examples
use qfall_math::integer::Z;

let sample = Z::sample_uniform(&17, &26).unwrap();
§Errors and Failures
Source

pub fn sample_prime_uniform( lower_bound: impl Into<Z>, upper_bound: impl Into<Z>, ) -> Result<Self, MathError>

Chooses a prime Z instance uniformly at random in [lower_bound, upper_bound). If after 2 * n steps, where n denotes the size of the interval, no suitable prime was found, the algorithm aborts.

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

Parameters:

  • 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 Z instance with a uniform random value in [lower_bound, upper_bound). Otherwise, a MathError if the provided interval was chosen too small, no prime could be found in the interval, or the provided lower_bound was negative.

§Examples
use qfall_math::integer::Z;

let prime = Z::sample_prime_uniform(1, 100).unwrap();
§Errors and Failures
  • Returns a MathError of type InvalidInterval if the given upper_bound isn’t at least larger than lower_bound , or if no prime could be found in the specified interval.
  • Returns a MathError of type InvalidIntegerInput if lower_bound is negative as primes are always positive.
Source§

impl Z

Source

pub fn to_string_b(&self, base: i32) -> Result<String, MathError>

Allows to convert an integer of type Z into a String with a configurable base b between 2 and 62.

Parameters:

  • b: specifies any base between 2 and 62 which specifies the base of the returned String.

Returns the integer in form of a String with regards to the base b or an error, if the base is out of bounds.

§Examples
use qfall_math::integer::Z;
use core::fmt;

let integer = Z::from(42);
println!("{integer}");
use qfall_math::integer::Z;
use core::fmt;

let integer = Z::from(42);
let integer_string = integer.to_string();
§Errors and Failures
Source

pub fn to_bytes(&self) -> Vec<u8>

Outputs the integer as a Vec of bytes. The inverse function to Z::to_bytes is Z::from_bytes for positive numbers including 0.

Warning: The bits are returned as they are stored in the memory. For negative numbers, this means that -1 is output as [255]. For these values, Z::from_bytes is not inverse to Z::to_bytes, as this function can only instantiate positive values.

Returns a Vec<u8> of bytes representing the integer as it is stored in memory.

§Examples
use qfall_math::integer::Z;

let integer = Z::from(257);

let byte_string = integer.to_bytes();

assert_eq!(vec![1, 1], byte_string);
Source

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

Enables conversion to a UTF8-Encoded String for Z values. The inverse to this function is Z::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::Z;
let integer = Z::from(10);

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

impl Z

Source

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

Returns a mutable reference to the field value of type fmpz.

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 Z

Source

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

Sets the field value of type fmpz 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 &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<&Q> for &Z

Source§

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

Implements the Add trait for Z and Q 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 Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

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

Source§

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

Implements the Add trait for Q 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 Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

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

Source§

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

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

Parameters:

  • other: specifies the value to add to self

Returns the sum of both numbers as a Z.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(42);
let b: Z = Z::from(24);

let c: Z = &a + &b;
let d: Z = a + b;
let e: Z = &c + d;
let f: Z = c + &e;
Source§

type Output = Z

The resulting type after applying the + operator.
Source§

impl AddAssign<&Z> for Q

Source§

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

Documentation at Q::add_assign.

Source§

impl AddAssign<&Z> for Z

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 Z in combination with 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 as a Z.

§Examples
use qfall_math::integer::Z;

let mut a: Z = Z::from(42);
let b: Z = Z::from(24);

a += &b;
a += b;
a += 5;
Source§

impl AddAssign<&Z> for Zq

Source§

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

Documentation at Zq::add_assign.

Source§

impl AddAssign<Z> for Q

Source§

fn add_assign(&mut self, other: Z)

Documentation at Q::add_assign.

Source§

impl AddAssign<Z> for Zq

Source§

fn add_assign(&mut self, other: Z)

Documentation at Zq::add_assign.

Source§

impl AddAssign<i16> for Z

Source§

fn add_assign(&mut self, other: i16)

Documentation at Z::add_assign.

Source§

impl AddAssign<i32> for Z

Source§

fn add_assign(&mut self, other: i32)

Documentation at Z::add_assign.

Source§

impl AddAssign<i64> for Z

Source§

fn add_assign(&mut self, other: i64)

Documentation at Z::add_assign.

Source§

impl AddAssign<i8> for Z

Source§

fn add_assign(&mut self, other: i8)

Documentation at Z::add_assign.

Source§

impl AddAssign<u16> for Z

Source§

fn add_assign(&mut self, other: u16)

Documentation at Z::add_assign.

Source§

impl AddAssign<u32> for Z

Source§

fn add_assign(&mut self, other: u32)

Documentation at Z::add_assign.

Source§

impl AddAssign<u64> for Z

Source§

fn add_assign(&mut self, other: u64)

Documentation at Z::add_assign.

Source§

impl AddAssign<u8> for Z

Source§

fn add_assign(&mut self, other: u8)

Documentation at Z::add_assign.

Source§

impl AddAssign for Z

Source§

fn add_assign(&mut self, other: Z)

Documentation at Z::add_assign.

Source§

impl BitAnd for &Z

Source§

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

Computes the bit-wise logical and of self and other.

Parameters:

  • other: specifies the value to apply the bit-wise logical and action to apart from self

Returns a new instance of Z containing the number resulting from the bit-wise logical and operation performed on self and other.

§Examples
use qfall_math::integer::Z;
let a = Z::from(5);
let b = Z::from(7);

let c: Z = &a & &b;
let d: Z = a & 1;
let e: Z = b & 15_u64;
Source§

type Output = Z

The resulting type after applying the & operator.
Source§

impl BitOr for &Z

Source§

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

Computes the bit-wise logical or of self and other.

Parameters:

  • other: specifies the value to apply the bit-wise logical or action to apart from self

Returns a new instance of Z containing the number resulting from the bit-wise logical or operation performed on self and other.

§Examples
use qfall_math::integer::Z;
let a = Z::from(5);
let b = Z::from(7);

let c: Z = &a | &b;
let d: Z = a | 1;
let e: Z = b | 15_u64;
Source§

type Output = Z

The resulting type after applying the | operator.
Source§

impl BitXor for &Z

Source§

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

Computes the bit-wise logical xor of self and other.

Parameters:

  • other: specifies the value to apply the bit-wise logical xor action to apart from self

Returns a new instance of Z containing the number resulting from the bit-wise logical xor operation performed on self and other.

§Examples
use qfall_math::integer::Z;
let a = Z::from(5);
let b = Z::from(7);

let c: Z = &a ^ &b;
let d: Z = a ^ 2;
let e: Z = b ^ 15_u64;
Source§

type Output = Z

The resulting type after applying the ^ operator.
Source§

impl Clone for Z

Source§

fn clone(&self) -> Self

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

§Examples
use qfall_math::integer::Z;

let a = Z::from(1);
let b = a.clone();
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Z

Source§

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

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

impl Default for Z

Source§

fn default() -> Self

Returns an instantiation of Z with value 0.

§Examples
use std::default::Default;
use qfall_math::integer::Z;
  
let a: Z = Z::default();
Source§

impl<'de> Deserialize<'de> for Z

Source§

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

Implements the deserialize option. This allows to create a Z from a given Json-object.

Source§

impl Display for Z

Source§

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

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

Returns the integer in form of a String. For integer 1 the String looks like this 1.

§Examples
use qfall_math::integer::Z;
use core::fmt;

let integer = Z::from(42);
println!("{integer}");
use qfall_math::integer::Z;
use core::fmt;

let integer = Z::from(42);
let integer_string = integer.to_string();
Source§

impl<Integer: Into<Z>> Distance<Integer> for Z

Source§

fn distance(&self, other: Integer) -> Self::Output

Computes the absolute distance between a Z instance and a value that implements Into<Z>.

Parameters:

  • other: specifies the Z value whose distance is calculated to self

Returns the absolute difference, i.e. distance between the Z instance and the value that implements Into<Z> as a new Z instance.

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

let a = Z::from(-1);

let distance_0 = a.distance(5);
let distance_1 = a.distance(10);
Source§

type Output = Z

Source§

impl Div<&Q> for &Z

Source§

fn div(self, other: &Q) -> Self::Output

Implements the Div trait for Z and Q values. Div is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to divide self by

Returns the ratio of both numbers as a Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

let c: Q = &a / &b;
let d: Q = a / b;
let e: Q = &Z::from(42) / d;
let f: Q = Z::from(42) / &e;
§Panics …
  • if the divisor is 0.
Source§

type Output = Q

The resulting type after applying the / operator.
Source§

impl Div<&Z> for &MatQ

Source§

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

Implements the Div trait for a MatQ by a Z integer. Div is implemented for any combination of owned and borrowed values.

Parameters:

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

Returns the division of self by scalar as a MatQ.

§Examples
use qfall_math::rational::{MatQ, Q};
use std::str::FromStr;

let matq_1 = MatQ::from_str("[[1, 2, 3],[4, 5/4, -1]]").unwrap();
let rational = Q::from((2,3));

let matq_2 = &matq_1 / &rational;
Source§

type Output = MatQ

The resulting type after applying the / operator.
Source§

impl Div<&Z> for &MatZ

Source§

fn div(self, divisor: &Z) -> Self::Output

Implements the Div trait for a MatZ matrix by a Z integer. Div is also implemented for borrowed values.

Parameters:

  • divisor: specifies the divisor by which the matrix is divided

Returns the quotient of self divided by divisor as a MatQ.

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

let mat = MatZ::from_str("[[3, 5],[9, 22]]").unwrap();
let divisor = Z::from(3);

let mat_q = &mat / &divisor;

assert_eq!("[[1, 5/3],[3, 22/3]]", mat_q.to_string());
§Panics …
  • if the divisor is 0.
Source§

type Output = MatQ

The resulting type after applying the / operator.
Source§

impl Div<&Z> for &PolyOverQ

Source§

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

Implements the Div trait for a PolyOverQ by a Z integer. Div is implemented for any combination of owned and borrowed values.

Parameters:

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

Returns the division of self by scalar as a PolyOverQ.

§Examples
use qfall_math::rational::{PolyOverQ, Q};
use qfall_math::integer::Z;
use std::str::FromStr;

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

&poly_1 / &integer;
&poly_1 / integer;
&poly_1 / 2;
&poly_1 / -2;
§Panics …
  • if scalar is 0.
Source§

type Output = PolyOverQ

The resulting type after applying the / operator.
Source§

impl Div<&Z> for &Q

Source§

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

Implements the Div trait for Q and Z values. Div is implemented for any combination of owned and borrowed values.

Parameters:

  • other: specifies the value to divide self by

Returns the ratio of both numbers as a Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

The resulting type after applying the / operator.
Source§

impl Div for &Z

Source§

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

Implements the Div trait for two Z values s.t. its value is rounded down. Div is implemented for any combination of Z and borrowed Z.

Parameters:

  • other: specifies the value to divide self by

Returns the quotient of both numbers as a Z floored.

§Examples
use qfall_math::integer::Z;
use qfall_math::rational::Q;

let a = Z::from(42);
let b = Z::from(20);

let c: Q = &a / &b;
let d: Q = a / b;

assert_eq!(Q::from((21, 10)), c);
assert_eq!(Q::from((21, 10)), d);
§Panics …
  • if the divisor is 0.
Source§

type Output = Q

The resulting type after applying the / operator.
Source§

impl DivAssign<&Z> for MatQ

Source§

fn div_assign(&mut self, scalar: &Z)

Documentation at MatQ::div_assign.

Source§

impl DivAssign<&Z> for PolyOverQ

Source§

fn div_assign(&mut self, scalar: &Z)

Documentation at PolyOverQ::div_assign.

Source§

impl DivAssign<&Z> for Q

Source§

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

Documentation at Q::div_assign.

Source§

impl DivAssign<Z> for MatQ

Source§

fn div_assign(&mut self, other: Z)

Documentation at MatQ::div_assign.

Source§

impl DivAssign<Z> for PolyOverQ

Source§

fn div_assign(&mut self, other: Z)

Documentation at PolyOverQ::div_assign.

Source§

impl DivAssign<Z> for Q

Source§

fn div_assign(&mut self, other: Z)

Documentation at Q::div_assign.

Source§

impl Drop for Z

Source§

fn drop(&mut self)

Drops the given Z value and frees the allocated memory.

§Examples
use qfall_math::integer::Z;
{
    let a = Z::from(3);
} // as a's scope ends here, it get's dropped
use qfall_math::integer::Z;

let a = Z::from(3);
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 From<&Vec<u8>> for Z

Source§

fn from(value: &Vec<u8>) -> Self

Converts a byte vector of type u8 to Z using Z::from_bytes.

Source§

impl From<&Z> for String

Source§

fn from(value: &Z) -> Self

Converts a Z into its String representation.

Parameters:

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

Returns a String.

§Examples
use qfall_math::integer::Z;
use std::str::FromStr;
let z = Z::from_str("6").unwrap();

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

impl<Integer: AsInteger + IntoZ> From<Integer> for Z

Source§

fn from(value: Integer) -> Self

Converts an integer to Z.

Parameters: value: must be a rust integer, Modulus, or a reference of these types.

Returns a Z with the value specified in the parameter.

§Examples
use qfall_math::integer::Z;

let a = Z::from(10);
let b = Z::from(i64::MAX);
let c = Z::from(&u64::MAX);
Source§

impl From<Vec<u8>> for Z

Source§

fn from(value: Vec<u8>) -> Self

Converts a byte vector of type u8 to Z using Z::from_bytes.

Source§

impl From<Z> for String

Source§

fn from(value: Z) -> Self

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

Source§

impl FromStr for Z

Source§

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

Creates a Z integer from a String.

Parameters:

  • s: the integer value of form: "12" for the number 12 and "-12" for -12.

Returns a Z or an error if the provided string was not formatted correctly, or the provided string contains a Null byte.

§Examples
use std::str::FromStr;
use qfall_math::integer::Z;
  
let a: Z = "100".parse().unwrap();
let b: Z = Z::from(100);
§Errors and Failures
  • Returns a MathError of type StringConversionError
    • if the provided string contains a Null byte, or
    • if the provided string was not formatted correctly.
Source§

type Err = MathError

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

impl<Integer: Into<Z>> Gcd<Integer> for Z

Source§

fn gcd(&self, other: Integer) -> Self::Output

Outputs the greatest common divisor (gcd) of the two given values with gcd(a, 0) = |a|.

Parameters:

  • other: specifies one of the values of which the gcd is computed

Returns the greatest common divisor of self and other as a Z instance.

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

let val_1 = Z::from(10);
let val_2 = Z::from(15);

let gcd = val_1.gcd(&val_2);

assert_eq!(Z::from(5), gcd);
Source§

type Output = Z

Source§

impl GetCoefficient<Z> for ModulusPolynomialRingZq

Source§

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

Returns the coefficient of a polynomial ModulusPolynomialRingZq as a Z.

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

Parameters:

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

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

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

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

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

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

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

Source§

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<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 GetCoefficient<Z> for PolyOverZq

Source§

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

Returns the coefficient of a polynomial PolyOverZq as a Z.

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

Parameters:

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

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

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

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

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

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

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

Source§

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<Z> for PolynomialRingZq

Source§

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

Returns the coefficient of a PolynomialRingZq as a Z.

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

Parameters:

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

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

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

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

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

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

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

Source§

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

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

impl Hash for Z

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Calculates the value of self mod 2^62 - 57 and then uses the inbuilt hash function for i64.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Integer: Into<Z>> Lcm<Integer> for Z

Source§

fn lcm(&self, other: Integer) -> Self::Output

Outputs the least common multiple (lcm) of the two given values with lcm(a, 0) = 0.

Parameters:

  • other: specifies one of the values of which the lcm is computed

Returns the least common multiple of self and other as a new Z instance.

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

let val_1 = Z::from(10);
let val_2 = Z::from(15);

let lcm = val_1.lcm(&val_2);

assert_eq!(Z::from(30), lcm);
Source§

type Output = Z

Source§

impl MatrixGetEntry<Z> for MatZ

Source§

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

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

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

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

Source§

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

Outputs the Z 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 Z 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;
use qfall_math::traits::MatrixGetEntry;
use qfall_math::integer::Z;
use std::str::FromStr;

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

let entry_1 :Z = unsafe { matrix.get_entry_unchecked(0, 2) };
let entry_2 :Z = unsafe { matrix.get_entry_unchecked(2, 1) };
let entry_3 :Z = unsafe { matrix.get_entry_unchecked(2, 1) };

assert_eq!(3, entry_1);
assert_eq!(8, entry_2);
assert_eq!(8, entry_3);
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 Mul<&Q> for &Z

Source§

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

Implements the Mul trait for Z and Q 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 Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &MatPolyOverZ

Source§

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

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

§Examples
use qfall_math::integer::MatPolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;

let mat_1 = MatPolyOverZ::from_str("[[2  1 42, 1  17],[1  8, 2  5 6]]").unwrap();
let integer = Z::from(3);

let mat_2 = &mat_1 * &integer;
Source§

type Output = MatPolyOverZ

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &MatPolynomialRingZq

Source§

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

Implements the Mul trait for a MatPolynomialRingZq matrix with a Z 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};
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 = Z::from(3);

let poly_ring_mat2 = &poly_ring_mat1 * &integer;
Source§

type Output = MatPolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &MatQ

Source§

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

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

§Examples
use qfall_math::rational::MatQ;
use qfall_math::integer::Z;
use std::str::FromStr;

let mat_1 = MatQ::from_str("[[2/3, 1],[1/2, 2]]").unwrap();
let integer = Z::from(3);

let mat_2 = &mat_1 * &integer;
Source§

type Output = MatQ

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &MatZ

Source§

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

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

§Examples
use qfall_math::integer::MatZ;
use qfall_math::integer::Z;
use std::str::FromStr;

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

let mat_2 = &mat_1 * &integer;
Source§

type Output = MatZ

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &MatZq

Source§

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

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

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

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

let mat_2 = &mat_1 * &integer;
Source§

type Output = MatZq

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &PolyOverQ

Source§

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

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

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::rational::{PolyOverQ, Q};
use qfall_math::integer::Z;
use std::str::FromStr;

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

let poly_2 = &poly_1 * &integer;
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<&Z> for &PolyOverZq

Source§

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

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

Parameters:

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

Returns the product of self and scalar as a PolyOverZq.

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

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

let poly_2 = &poly_1 * &integer;
Source§

type Output = PolyOverZq

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &PolynomialRingZq

Source§

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

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

Parameters:

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

Returns the product of self and scalar as a PolynomialRingZq.

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

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

let poly_2 = &poly_1 * &integer;
Source§

type Output = PolynomialRingZq

The resulting type after applying the * operator.
Source§

impl Mul<&Z> for &Q

Source§

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

Implements the Mul trait for Q 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 Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

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

Source§

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

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

Parameters:

  • other: specifies the value to multiply with self

Returns the product of both numbers as a Z.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(42);
let b: Z = Z::from(24);

let c: Z = &a * &b;
let d: Z = a * b;
let e: Z = &c * d;
let f: Z = c * &e;
Source§

type Output = Z

The resulting type after applying the * operator.
Source§

impl MulAssign<&Z> for MatPolyOverZ

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 matrix as a MatPolyOverZ.

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

let mut a = MatPolyOverZ::from_str("[[3  0 1 1, 1  42],[0, 2  1 2]]").unwrap();
let b = Z::from(2);
let c = PolyOverZ::from_str("2  1 -3").unwrap();

a *= &b;
a *= b;
a *= &c;
a *= c;
a *= 2;
a *= -2;
Source§

impl MulAssign<&Z> for MatQ

Source§

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

Documentation at MatQ::mul_assign.

Source§

impl MulAssign<&Z> for MatZ

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 matrix as a MatZ.

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

let mut a = MatZ::from_str("[[2, 1],[1, 2]]").unwrap();
let b = Z::from(2);

a *= &b;
a *= b;
a *= 2;
a *= -2;
Source§

impl MulAssign<&Z> for MatZq

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 matrix as a MatZq.

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

let mut a = MatZq::from_str("[[2, 1],[1, 2]] mod 61").unwrap();
let b = Z::from(2);
let c = Zq::from((17, 61));

a *= &b;
a *= b;
a *= 2;
a *= -2;
a *= &c;
a *= c;
Source§

impl MulAssign<&Z> for PolyOverQ

Source§

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

Documentation at PolyOverQ::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<&Z> for PolyOverZq

Source§

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

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

Parameters:

  • other: specifies the value to multiply to self

Returns the scalar of the polynomial as a PolyOverZq.

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

let mut a = PolyOverZq::from_str("3  1 2 -3 mod 5").unwrap();
let b = Z::from(2);
let c = Zq::from((17, 5));

a *= &b;
a *= &c;
a *= b;
a *= c;
a *= 2;
a *= -2;
Source§

impl MulAssign<&Z> for Q

Source§

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

Documentation at Q::mul_assign.

Source§

impl MulAssign<&Z> for Z

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 Z in combination with 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 as a Z.

§Examples
use qfall_math::integer::Z;

let mut a: Z = Z::from(42);
let b: Z = Z::from(24);

a *= &b;
a *= b;
a *= 5;
Source§

impl MulAssign<&Z> for Zq

Source§

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

Documentation at Zq::mul_assign.

Source§

impl MulAssign<Z> for MatPolyOverZ

Source§

fn mul_assign(&mut self, other: Z)

Documentation at MatPolyOverZ::mul_assign.

Source§

impl MulAssign<Z> for MatQ

Source§

fn mul_assign(&mut self, other: Z)

Documentation at MatQ::mul_assign.

Source§

impl MulAssign<Z> for MatZ

Source§

fn mul_assign(&mut self, other: Z)

Documentation at MatZ::mul_assign.

Source§

impl MulAssign<Z> for MatZq

Source§

fn mul_assign(&mut self, other: Z)

Documentation at MatZq::mul_assign.

Source§

impl MulAssign<Z> for PolyOverQ

Source§

fn mul_assign(&mut self, other: Z)

Documentation at PolyOverQ::mul_assign.

Source§

impl MulAssign<Z> for PolyOverZ

Source§

fn mul_assign(&mut self, other: Z)

Documentation at PolyOverZ::mul_assign.

Source§

impl MulAssign<Z> for PolyOverZq

Source§

fn mul_assign(&mut self, other: Z)

Documentation at PolyOverZq::mul_assign.

Source§

impl MulAssign<Z> for Q

Source§

fn mul_assign(&mut self, other: Z)

Documentation at Q::mul_assign.

Source§

impl MulAssign<Z> for Zq

Source§

fn mul_assign(&mut self, other: Z)

Documentation at Zq::mul_assign.

Source§

impl MulAssign<i16> for Z

Source§

fn mul_assign(&mut self, other: i16)

Documentation at Z::mul_assign.

Source§

impl MulAssign<i32> for Z

Source§

fn mul_assign(&mut self, other: i32)

Documentation at Z::mul_assign.

Source§

impl MulAssign<i64> for Z

Source§

fn mul_assign(&mut self, other: i64)

Documentation at Z::mul_assign.

Source§

impl MulAssign<i8> for Z

Source§

fn mul_assign(&mut self, other: i8)

Documentation at Z::mul_assign.

Source§

impl MulAssign<u16> for Z

Source§

fn mul_assign(&mut self, other: u16)

Documentation at Z::mul_assign.

Source§

impl MulAssign<u32> for Z

Source§

fn mul_assign(&mut self, other: u32)

Documentation at Z::mul_assign.

Source§

impl MulAssign<u64> for Z

Source§

fn mul_assign(&mut self, other: u64)

Documentation at Z::mul_assign.

Source§

impl MulAssign<u8> for Z

Source§

fn mul_assign(&mut self, other: u8)

Documentation at Z::mul_assign.

Source§

impl MulAssign for Z

Source§

fn mul_assign(&mut self, other: Z)

Documentation at Z::mul_assign.

Source§

impl Ord for Z

Enables the usage of max, min, and clamp.

§Examples

use qfall_math::integer::Z;
use std::cmp::{max, min};

let a: Z = Z::from(10);
let b: Z = Z::from(42);

assert_eq!(b, max(a.clone(), b.clone()));
assert_eq!(a, min(a.clone(), b.clone()));
assert_eq!(a, Z::ZERO.clamp(a.clone(), b.clone()));
Source§

fn cmp(&self, other: &Self) -> Ordering

Compares two Z values. Used by the <, <=, >, and >= operators.

Parameters:

  • other: the other value that is used to compare the elements

Returns the Ordering of the elements.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(10);
let b: Z = Z::from(42);

assert!(a < b);
assert!(a <= b);
assert!(b > a);
assert!(b >= a);
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<Z> for Modulus

Source§

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

Checks if an integer and a modulus are equal. Used by the == and != operators. PartialEq is also implemented for Z using Modulus.

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::Z;
use qfall_math::integer_mod_q::Modulus;
let a: Modulus = Modulus::from(42);
let b: Z = Z::from(42);

// 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 = (Z::eq(&b, &a));
let compared: bool = (Modulus::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 PartialEq<Z> for Q

Source§

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

Checks if an integer and a rational are equal. Used by the == and != operators. PartialEq is also implemented for Z using Q.

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::Z;
use qfall_math::rational::Q;
let a: Q = Q::from(42);
let b: Z = Z::from(42);

// 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 = (Q::eq(&a, &b));
let compared: bool = (Z::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 Z

Source§

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

Checks if two integers 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::Z;
let a: Z = Z::from(42);
let b: Z = Z::from(24);

// 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 = (Z::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 PartialOrd<Modulus> for Z

Source§

fn partial_cmp(&self, other: &Modulus) -> Option<Ordering>

Compares a Z value with a Modulus. Used by the <, <=, >, and >= operators. PartialOrd is also implemented for Z using Modulus.

Parameters:

  • other: the other value that is used to compare the elements

Returns the Ordering of the elements.

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

let a: Modulus = Modulus::from(10);
let b: Z = Z::from(42);

assert!(a < b);
assert!(a <= b);
assert!(b > a);
assert!(b >= a);
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<Z> for Modulus

Source§

fn partial_cmp(&self, other: &Z) -> Option<Ordering>

Compares a Z value with a Modulus. Used by the <, <=, >, and >= operators. PartialOrd is also implemented for Z using Modulus.

Parameters:

  • other: the other value that is used to compare the elements

Returns the Ordering of the elements.

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

let a: Modulus = Modulus::from(10);
let b: Z = Z::from(42);

assert!(a < b);
assert!(a <= b);
assert!(b > a);
assert!(b >= a);
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd for Z

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Compares two Z values. Used by the <, <=, >, and >= operators.

Parameters:

  • other: the other value that is used to compare the elements

Returns the Ordering of the elements.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(10);
let b: Z = Z::from(42);

assert!(a < b);
assert!(a <= b);
assert!(b > a);
assert!(b >= a);
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Integer: Into<Z>> Pow<Integer> for Z

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 Z instance or an error if the provided exponent is negative and the base value of self is not invertible.

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

let base = Z::from(9);

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

assert_eq!(Z::from(729), 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 = Z

Source§

impl Rem<&Modulus> for &Z

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 Z instance.

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

let a: Z = Z::from(42);
let b = Modulus::from(24);

let c: Z = a % &b;
Source§

type Output = Z

The resulting type after applying the % operator.
Source§

impl Rem<&Z> for &MatPolyOverZ

Source§

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

Computes self mod modulus as long as modulus is greater than 1. For negative entries 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 MatPolyOverZ instance.

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

let a: MatPolyOverZ = MatPolyOverZ::from_str("[[2  1 -2],[1  42]]").unwrap();
let b: Z = Z::from(24);

let c: MatPolyOverZ = a % b;
§Panics …
  • if modulus is smaller than 2.
Source§

type Output = MatPolyOverZ

The resulting type after applying the % operator.
Source§

impl Rem<&Z> for &MatZ

Source§

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

Computes self mod modulus as long as modulus is greater than 1. For negative entries 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 MatZ instance.

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

let a: MatZ = MatZ::from_str("[[-2],[42]]").unwrap();
let b: Z = Z::from(24);

let c: MatZ = a % b;
§Panics …
  • if modulus is smaller than 2.
Source§

type Output = MatZ

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

Source§

fn rem(self, modulus: Self) -> 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 Z instance.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(42);
let b: Z = Z::from(24);

let c: Z = a % b;
§Panics …
  • if modulus is smaller than 2.
Source§

type Output = Z

The resulting type after applying the % operator.
Source§

impl Serialize for Z

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 Z.

Source§

impl Sub<&Q> for &Z

Source§

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

Implements the Sub trait for Z and Q 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 as a Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

The resulting type after applying the - operator.
Source§

impl Sub<&Z> for &Q

Source§

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

Implements the Sub trait for Q 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 Q.

§Examples
use qfall_math::rational::Q;
use qfall_math::integer::Z;
use std::str::FromStr;

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

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

type Output = Q

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

Source§

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

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

Parameters:

  • other: specifies the value to subtract from self

Returns the result of the subtraction as a Z.

§Examples
use qfall_math::integer::Z;

let a: Z = Z::from(42);
let b: Z = Z::from(24);

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

type Output = Z

The resulting type after applying the - operator.
Source§

impl SubAssign<&Z> for Q

Source§

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

Documentation at Q::sub_assign.

Source§

impl SubAssign<&Z> for Z

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 Z in combination with 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 as a Z.

§Examples
use qfall_math::integer::Z;

let mut a: Z = Z::from(42);
let b: Z = Z::from(24);

a -= &b;
a -= b;
a -= 5;
Source§

impl SubAssign<&Z> for Zq

Source§

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

Documentation at Zq::sub_assign.

Source§

impl SubAssign<Z> for Q

Source§

fn sub_assign(&mut self, other: Z)

Documentation at Q::sub_assign.

Source§

impl SubAssign<Z> for Zq

Source§

fn sub_assign(&mut self, other: Z)

Documentation at Zq::sub_assign.

Source§

impl SubAssign<i16> for Z

Source§

fn sub_assign(&mut self, other: i16)

Documentation at Z::sub_assign.

Source§

impl SubAssign<i32> for Z

Source§

fn sub_assign(&mut self, other: i32)

Documentation at Z::sub_assign.

Source§

impl SubAssign<i64> for Z

Source§

fn sub_assign(&mut self, other: i64)

Documentation at Z::sub_assign.

Source§

impl SubAssign<i8> for Z

Source§

fn sub_assign(&mut self, other: i8)

Documentation at Z::sub_assign.

Source§

impl SubAssign<u16> for Z

Source§

fn sub_assign(&mut self, other: u16)

Documentation at Z::sub_assign.

Source§

impl SubAssign<u32> for Z

Source§

fn sub_assign(&mut self, other: u32)

Documentation at Z::sub_assign.

Source§

impl SubAssign<u64> for Z

Source§

fn sub_assign(&mut self, other: u64)

Documentation at Z::sub_assign.

Source§

impl SubAssign<u8> for Z

Source§

fn sub_assign(&mut self, other: u8)

Documentation at Z::sub_assign.

Source§

impl SubAssign for Z

Source§

fn sub_assign(&mut self, other: Z)

Documentation at Z::sub_assign.

Source§

impl TryFrom<&Z> for i64

Source§

fn try_from(value: &Z) -> Result<Self, Self::Error>

Converts a Z into an i64. If the value is either too large or too small an error is returned.

Parameters:

  • value: the value that will be converted into an i64

Returns the value as an i64 or an error if it does not fit into an i64.

§Examples
use qfall_math::integer::Z;

let max = Z::from(i64::MAX);
assert_eq!(i64::MAX, i64::try_from(&max).unwrap());

let max = Z::from(u64::MAX);
assert!(i64::try_from(&max).is_err());
§Errors and Failures
Source§

type Error = MathError

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

impl TryFrom<&Z> for u64

Source§

fn try_from(value: &Z) -> Result<Self, Self::Error>

Converts a Z into an u64. If the value is either too large or too small an error is returned.

Parameters:

  • value: the value that will be converted into an u64

Returns the value as an u64 or an error if it does not fit into an u64.

§Examples
use qfall_math::integer::Z;

let max = Z::from(u64::MAX);
assert_eq!(u64::MAX, u64::try_from(&max).unwrap());

let max = Z::from(u64::MAX) + 1;
assert!(u64::try_from(&max).is_err());
§Errors and Failures
Source§

type Error = MathError

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

impl TryFrom<Z> for i64

Source§

fn try_from(value: Z) -> Result<Self, Self::Error>

Converts a Z into an i64. If the value is either too large or too small an error is returned.

Parameters:

  • value: the value that will be converted into an i64

Returns the value as an i64 or an error if it does not fit into an i64

§Examples
use qfall_math::integer::Z;

let max = Z::from(i64::MAX);
assert_eq!(i64::MAX, i64::try_from(max).unwrap());

let max = Z::from(u64::MAX) + 1;
assert!(i64::try_from(max).is_err());
§Errors and Failures
Source§

type Error = MathError

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

impl TryFrom<Z> for u64

Source§

fn try_from(value: Z) -> Result<Self, Self::Error>

Converts a Z into an u64. If the value is either too large or too small an error is returned.

Parameters:

  • value: the value that will be converted into an u64

Returns the value as an u64 or an error if it does not fit into an u64.

§Examples
use qfall_math::integer::Z;

let max = Z::from(u64::MAX);
assert_eq!(u64::MAX, u64::try_from(max).unwrap());

let max = Z::from(u64::MAX) + 1;
assert!(u64::try_from(max).is_err());
§Errors and Failures
Source§

type Error = MathError

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

impl<Integer: Into<Z>> Xgcd<Integer> for Z

Source§

fn xgcd(&self, other: Integer) -> Self::Output

Outputs the extended greatest common divisor (xgcd) of the two given values, i.e. a triple (gcd(a, b), x, y), where a*x + b*y = gcd(a, b)*.

Parameters:

  • other: specifies one of the values of which the gcd is computed

Returns a triple (gcd(a, b), x, y) containing the greatest common divisor, x, and y s.t. gcd(a, b) = a*x + b*y.

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

let val_1 = Z::from(10);
let val_2 = Z::from(15);

let (gcd, x, y) = val_1.xgcd(&val_2);
let cmp_gcd = &val_1 * &x + &val_2 * &y;

assert_eq!(Z::from(5), gcd);
assert_eq!(gcd, cmp_gcd);
Source§

type Output = (Z, Z, Z)

Source§

impl Eq for Z

Auto Trait Implementations§

§

impl Freeze for Z

§

impl RefUnwindSafe for Z

§

impl Send for Z

§

impl Sync for Z

§

impl Unpin for Z

§

impl UnwindSafe for Z

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

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T, Base> RefNum<Base> for T
where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,