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
impl Z
Sourcepub fn div_floor(&self, other: impl Into<Z>) -> Self
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 divideselfby
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.
Sourcepub fn div_ceil(&self, other: impl Into<Z>) -> Self
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 divideselfby
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.
Sourcepub fn div_exact(&self, other: impl Into<Z>) -> Option<Self>
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 divideselfby
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
impl Z
Sourcepub fn exp_taylor(&self, length_taylor_polynomial: impl Into<u32>) -> Q
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
impl Z
Sourcepub fn log_ceil(&self, base: impl Into<Z>) -> Result<Z, MathError>
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
- Returns a
MathErrorof typeInvalidIntegerInputif thebaseis smaller than2. - Returns a
MathErrorof typeNonPositiveifselfis not greater than0.
Sourcepub fn log_floor(&self, base: impl Into<Z>) -> Result<Z, MathError>
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
- Returns a
MathErrorof typeInvalidIntegerInputif thebaseis smaller than2. - Returns a
MathErrorof typeNonPositiveifselfis not greater than0.
Sourcepub fn ln(&self) -> Result<Q, MathError>
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
- Returns a
MathErrorof typeNonPositiveifselfis not greater than0.
Sourcepub fn log(&self, base: impl Into<Z>) -> Result<Q, MathError>
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
- Returns a
MathErrorof typeInvalidIntegerInputif thebaseis smaller than2. - Returns a
MathErrorof typeNonPositiveifselfis not greater than0.
Source§impl Z
impl Z
Sourcepub fn sqrt(&self) -> Q
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.
Sourcepub fn sqrt_precision(&self, precision: &Z) -> Result<Q, MathError>
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:
precisionspecifies the upper limit of the error as1/(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
- Returns a
MathErrorof typeMathError::NonPositiveif the precision is not larger than zero. - Returns a
MathErrorof typeMathError::NonPositiveif the parameter of the square root is negative.
Source§impl Z
impl Z
Sourcepub fn from_str_b(s: &str, base: i32) -> Result<Self, MathError>
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 stringbase: 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
- Returns a
MathErrorof typeOutOfBoundsif the base is not between2and62. - Returns a
MathErrorof typeStringConversionError- if the provided string contains a
Nullbyte, or - if the provided string was not formatted correctly.
- if the provided string contains a
Sourcepub fn from_bytes(bytes: &[u8]) -> Self
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 newZinstance. 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);Sourcepub fn from_bits(bits: &[bool]) -> Z
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 newZinstance. 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);Sourcepub fn from_utf8(message: &str) -> Z
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 newZinstance.
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
impl Z
Sourcepub fn bit_complement(&self) -> Self
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
impl Z
Sourcepub fn bits(&self) -> u64
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);Sourcepub fn is_perfect_power(&self) -> Option<(Self, i32)>
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
impl Z
Sourcepub fn sample_binomial(
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
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 trialsp: 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
- Returns a
MathErrorof typeInvalidIntegerInputifn < 0. - Returns a
MathErrorof typeInvalidIntervalifp ∉ (0,1). - Returns a
MathErrorof typeConversionErrorifndoes not fit into ani64.
Source§impl Z
impl Z
Sourcepub fn sample_discrete_gauss(
center: impl Into<Q>,
s: impl Into<Q>,
) -> Result<Self, MathError>
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 sampledcenter: specifies the position of the center with peak probabilitys: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * 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
- Returns a
MathErrorof typeInvalidIntegerInputifs < 0.
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
impl Z
Sourcepub fn sample_uniform(
lower_bound: impl Into<Z>,
upper_bound: impl Into<Z>,
) -> Result<Self, MathError>
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 sampledupper_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
- Returns a
MathErrorof typeInvalidIntervalif the givenupper_boundisn’t at least larger thanlower_bound.
Sourcepub fn sample_prime_uniform(
lower_bound: impl Into<Z>,
upper_bound: impl Into<Z>,
) -> Result<Self, MathError>
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 sampledupper_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
MathErrorof typeInvalidIntervalif the givenupper_boundisn’t at least larger thanlower_bound, or if no prime could be found in the specified interval. - Returns a
MathErrorof typeInvalidIntegerInputiflower_boundis negative as primes are always positive.
Source§impl Z
impl Z
Sourcepub fn to_string_b(&self, base: i32) -> Result<String, MathError>
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 between2and62which specifies the base of the returnedString.
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
- Returns a
MathErrorof typeOutOfBoundsif the base is not between2and62.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
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);Sourcepub fn to_utf8(&self) -> Result<String, FromUtf8Error>
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
FromUtf8Errorif the integer’s byte sequence contains invalid UTF8-characters.
Source§impl Z
impl Z
Sourcepub unsafe fn get_fmpz(&mut self) -> &mut fmpz
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
impl Z
Sourcepub unsafe fn set_fmpz(&mut self, flint_struct: fmpz)
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
impl Add<&PolyOverZ> for &Z
Source§fn add(self, other: &PolyOverZ) -> Self::Output
fn add(self, other: &PolyOverZ) -> Self::Output
Implements the Add trait for Z and PolyOverZ values.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;
let a: Z = Z::from(42);
let b: PolyOverZ = PolyOverZ::from_str("4 5 1 2 3").unwrap();
let c: PolyOverZ = &a + &b;
let d: PolyOverZ = a + b;
let e: PolyOverZ = &Z::from(42) + d;
let f: PolyOverZ = Z::from(42) + &e;Source§impl Add<&Q> for &Z
impl Add<&Q> for &Z
Source§fn add(self, other: &Q) -> Self::Output
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 toself
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§impl Add<&Z> for &PolyOverZ
impl Add<&Z> for &PolyOverZ
Source§fn add(self, other: &Z) -> Self::Output
fn add(self, other: &Z) -> Self::Output
Implements the Add trait for PolyOverZ and Z values.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies theZto add toself
Returns the sum of both as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;
let b: PolyOverZ = PolyOverZ::from_str("4 5 1 2 3").unwrap();
let a: Z = Z::from(42);
let c: PolyOverZ = &a + &b;
let d: PolyOverZ = a + b;
let e: PolyOverZ = d + &Z::from(42);
let f: PolyOverZ = &e + Z::from(42);Source§impl Add<&Z> for &Q
impl Add<&Z> for &Q
Source§fn add(self, other: &Z) -> Self::Output
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 toself
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§impl Add<&Z> for &Zq
impl Add<&Z> for &Zq
Source§fn add(self, other: &Z) -> Self::Output
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 toself
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§impl Add<&Zq> for &Z
impl Add<&Zq> for &Z
Source§fn add(self, other: &Zq) -> Self::Output
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 toself
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§impl Add for &Z
impl Add for &Z
Source§fn add(self, other: Self) -> Self::Output
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 toself
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§impl AddAssign<&Z> for Q
impl AddAssign<&Z> for Q
Source§fn add_assign(&mut self, other: &Z)
fn add_assign(&mut self, other: &Z)
Documentation at Q::add_assign.
Source§impl AddAssign<&Z> for Z
impl AddAssign<&Z> for Z
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
Computes the addition of self and other reusing
the memory of self.
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 toself
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
impl AddAssign<&Z> for Zq
Source§fn add_assign(&mut self, other: &Z)
fn add_assign(&mut self, other: &Z)
Documentation at Zq::add_assign.
Source§impl AddAssign<Z> for Q
impl AddAssign<Z> for Q
Source§fn add_assign(&mut self, other: Z)
fn add_assign(&mut self, other: Z)
Documentation at Q::add_assign.
Source§impl AddAssign<Z> for Zq
impl AddAssign<Z> for Zq
Source§fn add_assign(&mut self, other: Z)
fn add_assign(&mut self, other: Z)
Documentation at Zq::add_assign.
Source§impl AddAssign<i16> for Z
impl AddAssign<i16> for Z
Source§fn add_assign(&mut self, other: i16)
fn add_assign(&mut self, other: i16)
Documentation at Z::add_assign.
Source§impl AddAssign<i32> for Z
impl AddAssign<i32> for Z
Source§fn add_assign(&mut self, other: i32)
fn add_assign(&mut self, other: i32)
Documentation at Z::add_assign.
Source§impl AddAssign<i64> for Z
impl AddAssign<i64> for Z
Source§fn add_assign(&mut self, other: i64)
fn add_assign(&mut self, other: i64)
Documentation at Z::add_assign.
Source§impl AddAssign<i8> for Z
impl AddAssign<i8> for Z
Source§fn add_assign(&mut self, other: i8)
fn add_assign(&mut self, other: i8)
Documentation at Z::add_assign.
Source§impl AddAssign<u16> for Z
impl AddAssign<u16> for Z
Source§fn add_assign(&mut self, other: u16)
fn add_assign(&mut self, other: u16)
Documentation at Z::add_assign.
Source§impl AddAssign<u32> for Z
impl AddAssign<u32> for Z
Source§fn add_assign(&mut self, other: u32)
fn add_assign(&mut self, other: u32)
Documentation at Z::add_assign.
Source§impl AddAssign<u64> for Z
impl AddAssign<u64> for Z
Source§fn add_assign(&mut self, other: u64)
fn add_assign(&mut self, other: u64)
Documentation at Z::add_assign.
Source§impl AddAssign<u8> for Z
impl AddAssign<u8> for Z
Source§fn add_assign(&mut self, other: u8)
fn add_assign(&mut self, other: u8)
Documentation at Z::add_assign.
Source§impl AddAssign for Z
impl AddAssign for Z
Source§fn add_assign(&mut self, other: Z)
fn add_assign(&mut self, other: Z)
Documentation at Z::add_assign.
Source§impl BitAnd for &Z
impl BitAnd for &Z
Source§fn bitand(self, other: Self) -> Self::Output
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 logicalandaction to apart fromself
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§impl BitOr for &Z
impl BitOr for &Z
Source§fn bitor(self, other: Self) -> Self::Output
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 logicaloraction to apart fromself
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§impl BitXor for &Z
impl BitXor for &Z
Source§fn bitxor(self, other: Self) -> Self::Output
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 logicalxoraction to apart fromself
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§impl<'de> Deserialize<'de> for Z
impl<'de> Deserialize<'de> for Z
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Implements the deserialize option. This allows to create a Z from a given Json-object.
Source§impl Display for Z
impl Display for Z
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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
impl<Integer: Into<Z>> Distance<Integer> for Z
Source§fn distance(&self, other: Integer) -> Self::Output
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 theZvalue whose distance is calculated toself
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);
type Output = Z
Source§impl Div<&Q> for &Z
impl Div<&Q> for &Z
Source§fn div(self, other: &Q) -> Self::Output
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 divideselfby
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§impl Div<&Z> for &MatQ
impl Div<&Z> for &MatQ
Source§fn div(self, scalar: &Z) -> Self::Output
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§impl Div<&Z> for &MatZ
impl Div<&Z> for &MatZ
Source§fn div(self, divisor: &Z) -> Self::Output
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§impl Div<&Z> for &PolyOverQ
impl Div<&Z> for &PolyOverQ
Source§fn div(self, scalar: &Z) -> Self::Output
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
scalaris0.
Source§impl Div<&Z> for &Q
impl Div<&Z> for &Q
Source§fn div(self, other: &Z) -> Self::Output
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 divideselfby
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§impl Div for &Z
impl Div for &Z
Source§fn div(self, other: Self) -> Self::Output
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 divideselfby
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§impl DivAssign<&Z> for MatQ
impl DivAssign<&Z> for MatQ
Source§fn div_assign(&mut self, scalar: &Z)
fn div_assign(&mut self, scalar: &Z)
Documentation at MatQ::div_assign.
Source§impl DivAssign<&Z> for PolyOverQ
impl DivAssign<&Z> for PolyOverQ
Source§fn div_assign(&mut self, scalar: &Z)
fn div_assign(&mut self, scalar: &Z)
Documentation at PolyOverQ::div_assign.
Source§impl DivAssign<&Z> for Q
impl DivAssign<&Z> for Q
Source§fn div_assign(&mut self, other: &Z)
fn div_assign(&mut self, other: &Z)
Documentation at Q::div_assign.
Source§impl DivAssign<Z> for MatQ
impl DivAssign<Z> for MatQ
Source§fn div_assign(&mut self, other: Z)
fn div_assign(&mut self, other: Z)
Documentation at MatQ::div_assign.
Source§impl DivAssign<Z> for PolyOverQ
impl DivAssign<Z> for PolyOverQ
Source§fn div_assign(&mut self, other: Z)
fn div_assign(&mut self, other: Z)
Documentation at PolyOverQ::div_assign.
Source§impl DivAssign<Z> for Q
impl DivAssign<Z> for Q
Source§fn div_assign(&mut self, other: Z)
fn div_assign(&mut self, other: Z)
Documentation at Q::div_assign.
Source§impl<Integer: Into<Z>> Evaluate<Integer, Z> for PolyOverZ
impl<Integer: Into<Z>> Evaluate<Integer, Z> for PolyOverZ
Source§fn evaluate(&self, value: Integer) -> Z
fn evaluate(&self, value: Integer) -> Z
Evaluates a PolyOverZ on a given input.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Z.
§Examples
use qfall_math::traits::*;
use qfall_math::integer::Z;
use qfall_math::integer::PolyOverZ;
use std::str::FromStr;
let poly = PolyOverZ::from_str("5 0 1 2 -3 1").unwrap();
let res: Z = poly.evaluate(3);Source§impl FromStr for Z
impl FromStr for Z
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
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
MathErrorof typeStringConversionError- if the provided string contains a
Nullbyte, or - if the provided string was not formatted correctly.
- if the provided string contains a
Source§impl<Integer: Into<Z>> Gcd<Integer> for Z
impl<Integer: Into<Z>> Gcd<Integer> for Z
Source§fn gcd(&self, other: Integer) -> Self::Output
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);type Output = Z
Source§impl GetCoefficient<Z> for ModulusPolynomialRingZq
impl GetCoefficient<Z> for ModulusPolynomialRingZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
Returns the coefficient of a polynomial 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§impl GetCoefficient<Z> for PolyOverZ
impl GetCoefficient<Z> for PolyOverZ
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
Returns the coefficient of a polynomial PolyOverZ as a Z.
If an index is provided which exceeds the highest set coefficient, 0 is returned.
Parameters:
index: the index of the coefficient to get (has to be positive)
Returns the coefficient as a Z, or a MathError if the provided index
is negative and therefore invalid, or it does not fit into an i64.
§Examples
use qfall_math::integer::{Z, PolyOverZ};
use std::str::FromStr;
use qfall_math::traits::*;
let poly = PolyOverZ::from_str("4 0 1 2 3").unwrap();
let coeff_0 = poly.get_coeff(0).unwrap();
let coeff_1 = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4 = poly.get_coeff(4).unwrap();
assert_eq!(Z::ZERO, coeff_0);
assert_eq!(Z::ONE, coeff_1);
assert_eq!(Z::ZERO, coeff_4);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl GetCoefficient<Z> for PolyOverZq
impl GetCoefficient<Z> for PolyOverZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
Returns the coefficient of a polynomial 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§impl GetCoefficient<Z> for PolynomialRingZq
impl GetCoefficient<Z> for PolynomialRingZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Z
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§impl<Integer: Into<Z>> Lcm<Integer> for Z
impl<Integer: Into<Z>> Lcm<Integer> for Z
Source§fn lcm(&self, other: Integer) -> Self::Output
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 thelcmis 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);type Output = Z
Source§impl MatrixGetEntry<Z> for MatZ
impl MatrixGetEntry<Z> for MatZ
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> Z
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 locatedcolumn: 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>
fn get_entry( &self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, ) -> Result<T, MathError>
Source§fn get_entries(&self) -> Vec<Vec<T>>
fn get_entries(&self) -> Vec<Vec<T>>
Vec<Vec<T>> containing all entries of the matrix s.t.
any entry in row i and column j can be accessed via entries[i][j]
if entries = matrix.get_entries. Read moreSource§fn get_entries_rowwise(&self) -> Vec<T>
fn get_entries_rowwise(&self) -> Vec<T>
Source§impl MatrixGetEntry<Z> for MatZq
impl MatrixGetEntry<Z> for MatZq
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> Z
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 locatedcolumn: 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>
fn get_entry( &self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, ) -> Result<T, MathError>
Source§fn get_entries(&self) -> Vec<Vec<T>>
fn get_entries(&self) -> Vec<Vec<T>>
Vec<Vec<T>> containing all entries of the matrix s.t.
any entry in row i and column j can be accessed via entries[i][j]
if entries = matrix.get_entries. Read moreSource§fn get_entries_rowwise(&self) -> Vec<T>
fn get_entries_rowwise(&self) -> Vec<T>
Source§impl Mul<&Q> for &Z
impl Mul<&Q> for &Z
Source§fn mul(self, other: &Q) -> Self::Output
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 withself
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§impl Mul<&Z> for &MatPolyOverZ
impl Mul<&Z> for &MatPolyOverZ
Source§fn mul(self, scalar: &Z) -> Self::Output
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
type Output = MatPolyOverZ
* operator.Source§impl Mul<&Z> for &MatPolynomialRingZq
impl Mul<&Z> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &Z) -> Self::Output
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
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&Z> for &MatQ
impl Mul<&Z> for &MatQ
Source§fn mul(self, scalar: &Z) -> Self::Output
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§impl Mul<&Z> for &MatZ
impl Mul<&Z> for &MatZ
Source§fn mul(self, scalar: &Z) -> Self::Output
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§impl Mul<&Z> for &MatZq
impl Mul<&Z> for &MatZq
Source§fn mul(self, scalar: &Z) -> Self::Output
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§impl Mul<&Z> for &PolyOverQ
impl Mul<&Z> for &PolyOverQ
Source§fn mul(self, scalar: &Z) -> Self::Output
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§impl Mul<&Z> for &PolyOverZ
impl Mul<&Z> for &PolyOverZ
Source§fn mul(self, scalar: &Z) -> Self::Output
fn mul(self, scalar: &Z) -> Self::Output
Implements the Mul trait for a PolyOverZ with a Z integer.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Z using PolyOverZ.
Parameters:
scalar: specifies the scalar by which the polynomial is multiplied
Returns the product of self and scalar as a PolyOverZ.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer::Z;
use std::str::FromStr;
let poly_1 = PolyOverZ::from_str("4 1 2 3 4").unwrap();
let integer = Z::from(3);
let poly_2 = &poly_1 * &integer;Source§impl Mul<&Z> for &PolyOverZq
impl Mul<&Z> for &PolyOverZq
Source§fn mul(self, scalar: &Z) -> Self::Output
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
type Output = PolyOverZq
* operator.Source§impl Mul<&Z> for &PolynomialRingZq
impl Mul<&Z> for &PolynomialRingZq
Source§fn mul(self, scalar: &Z) -> Self::Output
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
type Output = PolynomialRingZq
* operator.Source§impl Mul<&Z> for &Q
impl Mul<&Z> for &Q
Source§fn mul(self, other: &Z) -> Self::Output
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 withself
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§impl Mul<&Z> for &Zq
impl Mul<&Z> for &Zq
Source§fn mul(self, other: &Z) -> Self::Output
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 withself
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§impl Mul<&Zq> for &Z
impl Mul<&Zq> for &Z
Source§fn mul(self, other: &Zq) -> Self::Output
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 withself
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§impl Mul for &Z
impl Mul for &Z
Source§fn mul(self, other: Self) -> Self::Output
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 withself
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§impl MulAssign<&Z> for MatPolyOverZ
impl MulAssign<&Z> for MatPolyOverZ
Source§fn mul_assign(&mut self, scalar: &Z)
fn mul_assign(&mut self, scalar: &Z)
Computes the scalar multiplication of self and scalar reusing
the memory of self.
Parameters:
scalar: specifies the value to multiply toself
Returns the scalar of the 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
impl MulAssign<&Z> for MatQ
Source§fn mul_assign(&mut self, other: &Z)
fn mul_assign(&mut self, other: &Z)
Documentation at MatQ::mul_assign.
Source§impl MulAssign<&Z> for MatZ
impl MulAssign<&Z> for MatZ
Source§fn mul_assign(&mut self, scalar: &Z)
fn mul_assign(&mut self, scalar: &Z)
Computes the scalar multiplication of self and scalar reusing
the memory of self.
Parameters:
scalar: specifies the value to multiply toself
Returns the scalar of the 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
impl MulAssign<&Z> for MatZq
Source§fn mul_assign(&mut self, scalar: &Z)
fn mul_assign(&mut self, scalar: &Z)
Computes the scalar multiplication of self and scalar reusing
the memory of self.
Parameters:
scalar: specifies the value to multiply toself
Returns the scalar of the 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
impl MulAssign<&Z> for PolyOverQ
Source§fn mul_assign(&mut self, other: &Z)
fn mul_assign(&mut self, other: &Z)
Documentation at PolyOverQ::mul_assign.
Source§impl MulAssign<&Z> for PolyOverZ
impl MulAssign<&Z> for PolyOverZ
Source§fn mul_assign(&mut self, scalar: &Z)
fn mul_assign(&mut self, scalar: &Z)
Computes the scalar multiplication of self and scalar reusing
the memory of self.
Parameters:
scalar: specifies the value to multiply toself
Returns the scalar of the polynomial as a PolyOverZ.
§Examples
use qfall_math::integer::{Z,PolyOverZ};
use std::str::FromStr;
let mut a = PolyOverZ::from_str("3 1 2 -3").unwrap();
let b = Z::from(2);
a *= &b;
a *= b;
a *= 2;
a *= -2;Source§impl MulAssign<&Z> for PolyOverZq
impl MulAssign<&Z> for PolyOverZq
Source§fn mul_assign(&mut self, scalar: &Z)
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 toself
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
impl MulAssign<&Z> for Q
Source§fn mul_assign(&mut self, other: &Z)
fn mul_assign(&mut self, other: &Z)
Documentation at Q::mul_assign.
Source§impl MulAssign<&Z> for Z
impl MulAssign<&Z> for Z
Source§fn mul_assign(&mut self, other: &Self)
fn mul_assign(&mut self, other: &Self)
Computes the multiplication of self and other reusing
the memory of self.
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 toself
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
impl MulAssign<&Z> for Zq
Source§fn mul_assign(&mut self, other: &Z)
fn mul_assign(&mut self, other: &Z)
Documentation at Zq::mul_assign.
Source§impl MulAssign<Z> for MatPolyOverZ
impl MulAssign<Z> for MatPolyOverZ
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at MatPolyOverZ::mul_assign.
Source§impl MulAssign<Z> for MatQ
impl MulAssign<Z> for MatQ
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at MatQ::mul_assign.
Source§impl MulAssign<Z> for MatZ
impl MulAssign<Z> for MatZ
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at MatZ::mul_assign.
Source§impl MulAssign<Z> for MatZq
impl MulAssign<Z> for MatZq
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at MatZq::mul_assign.
Source§impl MulAssign<Z> for PolyOverQ
impl MulAssign<Z> for PolyOverQ
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at PolyOverQ::mul_assign.
Source§impl MulAssign<Z> for PolyOverZ
impl MulAssign<Z> for PolyOverZ
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at PolyOverZ::mul_assign.
Source§impl MulAssign<Z> for PolyOverZq
impl MulAssign<Z> for PolyOverZq
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<Z> for Q
impl MulAssign<Z> for Q
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at Q::mul_assign.
Source§impl MulAssign<Z> for Zq
impl MulAssign<Z> for Zq
Source§fn mul_assign(&mut self, other: Z)
fn mul_assign(&mut self, other: Z)
Documentation at Zq::mul_assign.
Source§impl MulAssign<i16> for Z
impl MulAssign<i16> for Z
Source§fn mul_assign(&mut self, other: i16)
fn mul_assign(&mut self, other: i16)
Documentation at Z::mul_assign.
Source§impl MulAssign<i32> for Z
impl MulAssign<i32> for Z
Source§fn mul_assign(&mut self, other: i32)
fn mul_assign(&mut self, other: i32)
Documentation at Z::mul_assign.
Source§impl MulAssign<i64> for Z
impl MulAssign<i64> for Z
Source§fn mul_assign(&mut self, other: i64)
fn mul_assign(&mut self, other: i64)
Documentation at Z::mul_assign.
Source§impl MulAssign<i8> for Z
impl MulAssign<i8> for Z
Source§fn mul_assign(&mut self, other: i8)
fn mul_assign(&mut self, other: i8)
Documentation at Z::mul_assign.
Source§impl MulAssign<u16> for Z
impl MulAssign<u16> for Z
Source§fn mul_assign(&mut self, other: u16)
fn mul_assign(&mut self, other: u16)
Documentation at Z::mul_assign.
Source§impl MulAssign<u32> for Z
impl MulAssign<u32> for Z
Source§fn mul_assign(&mut self, other: u32)
fn mul_assign(&mut self, other: u32)
Documentation at Z::mul_assign.
Source§impl MulAssign<u64> for Z
impl MulAssign<u64> for Z
Source§fn mul_assign(&mut self, other: u64)
fn mul_assign(&mut self, other: u64)
Documentation at Z::mul_assign.
Source§impl MulAssign<u8> for Z
impl MulAssign<u8> for Z
Source§fn mul_assign(&mut self, other: u8)
fn mul_assign(&mut self, other: u8)
Documentation at Z::mul_assign.
Source§impl MulAssign for Z
impl MulAssign for Z
Source§fn mul_assign(&mut self, other: Z)
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.
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
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) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq<Z> for Modulus
impl PartialEq<Z> for Modulus
Source§fn eq(&self, other: &Z) -> bool
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));Source§impl PartialEq<Z> for Q
impl PartialEq<Z> for Q
Source§fn eq(&self, other: &Z) -> bool
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));Source§impl PartialEq for Z
impl PartialEq for Z
Source§fn eq(&self, other: &Self) -> bool
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));Source§impl PartialOrd<Modulus> for Z
impl PartialOrd<Modulus> for Z
Source§fn partial_cmp(&self, other: &Modulus) -> Option<Ordering>
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);Source§impl PartialOrd<Z> for Modulus
impl PartialOrd<Z> for Modulus
Source§fn partial_cmp(&self, other: &Z) -> Option<Ordering>
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);Source§impl PartialOrd for Z
impl PartialOrd for Z
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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);Source§impl<Integer: Into<Z>> Pow<Integer> for Z
impl<Integer: Into<Z>> Pow<Integer> for Z
Source§fn pow(&self, exp: Integer) -> Result<Self::Output, MathError>
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
MathErrorof typeInvalidExponentif the provided exponent is negative and the base value ofselfis not invertible.
type Output = Z
Source§impl Rem<&Modulus> for &Z
impl Rem<&Modulus> for &Z
Source§fn rem(self, modulus: &Modulus) -> Self::Output
fn rem(self, modulus: &Modulus) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative values of self, the smallest positive representative is returned.
Parameters:
modulus: specifies a non-zero integer over which the positive remainder is computed
Returns self mod modulus as a 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§impl Rem<&Z> for &MatPolyOverZ
impl Rem<&Z> for &MatPolyOverZ
Source§fn rem(self, modulus: &Z) -> Self::Output
fn rem(self, modulus: &Z) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative 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
modulusis smaller than2.
Source§type Output = MatPolyOverZ
type Output = MatPolyOverZ
% operator.Source§impl Rem<&Z> for &MatZ
impl Rem<&Z> for &MatZ
Source§fn rem(self, modulus: &Z) -> Self::Output
fn rem(self, modulus: &Z) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative 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
modulusis smaller than2.
Source§impl Rem<&Z> for &PolyOverZ
impl Rem<&Z> for &PolyOverZ
Source§fn rem(self, modulus: &Z) -> Self::Output
fn rem(self, modulus: &Z) -> Self::Output
Computes self mod modulus as long as modulus is greater than 1.
For negative coefficients in self, the smallest positive representative is returned.
Parameters:
modulus: specifies a non-zero integer over which the positive remainders are computed
Returns self mod modulus as a PolyOverZ instance.
§Examples
use qfall_math::integer::{PolyOverZ, Z};
use std::str::FromStr;
let a: PolyOverZ = PolyOverZ::from_str("2 -2 42").unwrap();
let b: Z = Z::from(24);
let c: PolyOverZ = a % b;§Panics …
- if
modulusis smaller than2.
Source§impl Rem for &Z
impl Rem for &Z
Source§fn rem(self, modulus: Self) -> Self::Output
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
modulusis smaller than2.
Source§impl Sub<&Q> for &Z
impl Sub<&Q> for &Z
Source§fn sub(self, other: &Q) -> Self::Output
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 fromself
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§impl Sub<&Z> for &Q
impl Sub<&Z> for &Q
Source§fn sub(self, other: &Z) -> Self::Output
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 fromself
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§impl Sub<&Z> for &Zq
impl Sub<&Z> for &Zq
Source§fn sub(self, other: &Z) -> Self::Output
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 fromself
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§impl Sub<&Zq> for &Z
impl Sub<&Zq> for &Z
Source§fn sub(self, other: &Zq) -> Self::Output
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 fromself
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§impl Sub for &Z
impl Sub for &Z
Source§fn sub(self, other: Self) -> Self::Output
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 fromself
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§impl SubAssign<&Z> for Q
impl SubAssign<&Z> for Q
Source§fn sub_assign(&mut self, other: &Z)
fn sub_assign(&mut self, other: &Z)
Documentation at Q::sub_assign.
Source§impl SubAssign<&Z> for Z
impl SubAssign<&Z> for Z
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
Computes the subtraction of self and other reusing
the memory of self.
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 fromself
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
impl SubAssign<&Z> for Zq
Source§fn sub_assign(&mut self, other: &Z)
fn sub_assign(&mut self, other: &Z)
Documentation at Zq::sub_assign.
Source§impl SubAssign<Z> for Q
impl SubAssign<Z> for Q
Source§fn sub_assign(&mut self, other: Z)
fn sub_assign(&mut self, other: Z)
Documentation at Q::sub_assign.
Source§impl SubAssign<Z> for Zq
impl SubAssign<Z> for Zq
Source§fn sub_assign(&mut self, other: Z)
fn sub_assign(&mut self, other: Z)
Documentation at Zq::sub_assign.
Source§impl SubAssign<i16> for Z
impl SubAssign<i16> for Z
Source§fn sub_assign(&mut self, other: i16)
fn sub_assign(&mut self, other: i16)
Documentation at Z::sub_assign.
Source§impl SubAssign<i32> for Z
impl SubAssign<i32> for Z
Source§fn sub_assign(&mut self, other: i32)
fn sub_assign(&mut self, other: i32)
Documentation at Z::sub_assign.
Source§impl SubAssign<i64> for Z
impl SubAssign<i64> for Z
Source§fn sub_assign(&mut self, other: i64)
fn sub_assign(&mut self, other: i64)
Documentation at Z::sub_assign.
Source§impl SubAssign<i8> for Z
impl SubAssign<i8> for Z
Source§fn sub_assign(&mut self, other: i8)
fn sub_assign(&mut self, other: i8)
Documentation at Z::sub_assign.
Source§impl SubAssign<u16> for Z
impl SubAssign<u16> for Z
Source§fn sub_assign(&mut self, other: u16)
fn sub_assign(&mut self, other: u16)
Documentation at Z::sub_assign.
Source§impl SubAssign<u32> for Z
impl SubAssign<u32> for Z
Source§fn sub_assign(&mut self, other: u32)
fn sub_assign(&mut self, other: u32)
Documentation at Z::sub_assign.
Source§impl SubAssign<u64> for Z
impl SubAssign<u64> for Z
Source§fn sub_assign(&mut self, other: u64)
fn sub_assign(&mut self, other: u64)
Documentation at Z::sub_assign.
Source§impl SubAssign<u8> for Z
impl SubAssign<u8> for Z
Source§fn sub_assign(&mut self, other: u8)
fn sub_assign(&mut self, other: u8)
Documentation at Z::sub_assign.
Source§impl SubAssign for Z
impl SubAssign for Z
Source§fn sub_assign(&mut self, other: Z)
fn sub_assign(&mut self, other: Z)
Documentation at Z::sub_assign.
Source§impl TryFrom<&Z> for i64
impl TryFrom<&Z> for i64
Source§fn try_from(value: &Z) -> Result<Self, Self::Error>
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 ani64
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
- Returns a
MathErrorof typeConversionErrorif the value does not fit into ani64
Source§impl TryFrom<&Z> for u64
impl TryFrom<&Z> for u64
Source§fn try_from(value: &Z) -> Result<Self, Self::Error>
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 anu64
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
- Returns a
MathErrorof typeConversionErrorif the value does not fit into anu64
Source§impl TryFrom<Z> for i64
impl TryFrom<Z> for i64
Source§fn try_from(value: Z) -> Result<Self, Self::Error>
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 ani64
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
- Returns a
MathErrorof typeConversionErrorif the value does not fit into ani64
Source§impl TryFrom<Z> for u64
impl TryFrom<Z> for u64
Source§fn try_from(value: Z) -> Result<Self, Self::Error>
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 anu64
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
- Returns a
MathErrorof typeConversionErrorif the value does not fit into anu64
Source§impl<Integer: Into<Z>> Xgcd<Integer> for Z
impl<Integer: Into<Z>> Xgcd<Integer> for Z
Source§fn xgcd(&self, other: Integer) -> Self::Output
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);