pub struct Zq { /* private fields */ }Expand description
Zq is an arbitrary integer value in a residue class.
Attributes:
value: holds aZvalue for an integer valuemodulus: holds aModulusabove which the value is reduced
§Examples
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
// instantiation
let a = Zq::from((5, 10));
let b = Zq::from_str("93 mod 10")?;
let _ = a.clone();
// arithmetics
let _ = &a + &b;
let _ = &a * &b;
// to_string incl. (de-)serialization
assert_eq!("5 mod 10", &a.to_string());
let _ = serde_json::to_string(&a).unwrap();
Implementations§
Source§impl Zq
impl Zq
Sourcepub fn add_safe(&self, other: &Self) -> Result<Zq, MathError>
pub fn add_safe(&self, other: &Self) -> Result<Zq, MathError>
Implements addition for two Zq values.
Parameters:
other: specifies the value to add toself
Returns the sum of both numbers as a Zq or an error if the modulus
does mismatch.
§Examples
use qfall_math::integer_mod_q::Zq;
let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Zq = a.add_safe(&b).unwrap();§Errors
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothZqmismatch.
Source§impl Zq
impl Zq
Sourcepub fn mul_safe(&self, other: &Self) -> Result<Zq, MathError>
pub fn mul_safe(&self, other: &Self) -> Result<Zq, MathError>
Implements multiplication for two Zq values.
Parameters:
other: specifies the value to multiply withself
Returns the product of both numbers as a Zq or an error if the moduli
mismatch.
§Examples
use qfall_math::integer_mod_q::Zq;
let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Zq = a.mul_safe(&b).unwrap();§Errors
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothZqmismatch.
Source§impl Zq
impl Zq
Sourcepub fn sub_safe(&self, other: &Self) -> Result<Zq, MathError>
pub fn sub_safe(&self, other: &Self) -> Result<Zq, MathError>
Implements subtraction for two Zq values.
Parameters:
other: specifies the value to subtract fromself
Returns the result of the subtraction of both numbers as a Zq
or an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::Zq;
let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Zq = a.sub_safe(&b).unwrap();§Errors
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothZqmismatch.
Source§impl Zq
impl Zq
Sourcepub fn from_utf8(
message: &str,
modulus: impl Into<Modulus>,
) -> Result<Zq, MathError>
pub fn from_utf8( message: &str, modulus: impl Into<Modulus>, ) -> Result<Zq, MathError>
Create a Zq integer from a String, i.e. its UTF8-Encoding.
The inverse of this function is Zq::to_utf8.
Parameters:
message: specifies the message that is transformed via its UTF8-Encoding to a newZqinstance.modulus: Defines the modulus by whichvalueis reduced.
Returns value defined by message mod modulus as Zq or a MathError
if the provided modulus is smaller than the UTF8-Encoding of the message.
§Examples
use qfall_math::integer_mod_q::Zq;
let message = "hello!";
let value = Zq::from_utf8(&message, i64::MAX).unwrap();
assert_eq!(Zq::from((36762444129640u64, i64::MAX)), value);§Errors and Failures
- Returns a
ConversionErrorif the provided modulus is smaller than the UTF8-Encoding of the message.
§Panics …
- if
modulusis smaller than2.
Source§impl Zq
impl Zq
Sourcepub fn get_representative_least_nonnegative_residue(&self) -> Z
pub fn get_representative_least_nonnegative_residue(&self) -> Z
Returns the Z value of the Zq element.
The representation in the range [0, modulus) is returned.
Use Zq::get_representative_least_absolute_residue if they should be
in the range [-modulus/2, modulus/2].
§Examples
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer::Z;
let zq_value = Zq::from((4, 7));
let z_value = zq_value.get_representative_least_nonnegative_residue();
assert_eq!(Z::from(4), z_value);Sourcepub fn get_representative_least_absolute_residue(&self) -> Z
pub fn get_representative_least_absolute_residue(&self) -> Z
Returns the Z value of the Zq element with the representatives close to 0.
The output value is in the range of [-modulus/2, modulus/2].
For even moduli, the positive representative is chosen for the element modulus / 2.
Use Zq::get_representative_least_nonnegative_residue if they should be
in the range [0, modulus).
§Examples
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer::Z;
let zq_value = Zq::from((5, 7));
let z_value = zq_value.get_representative_least_absolute_residue();
assert_eq!(Z::from(2), z_value);Source§impl Zq
impl Zq
Sourcepub fn sample_binomial(
modulus: impl Into<Modulus>,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial( modulus: impl Into<Modulus>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Chooses a Zq instance according to the binomial distribution
parameterized by n and p.
Parameters:
modulus: specifies theModulusof the newZqinstancen: specifies the number of trialsp: specifies the probability of success
Returns a fresh Zq instance with a value sampled
according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), or n does not fit into an i64.
§Examples
use qfall_math::integer_mod_q::Zq;
let sample = Zq::sample_binomial(7, 2, 0.5).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifn < 0. - Returns a
MathErrorof typeInvalidIntervalifp ∉ (0,1). - Returns a
MathErrorof typeConversionErrorifndoes not fit into ani64.
§Panics …
- if
modulusis smaller than2.
Source§impl Zq
impl Zq
Sourcepub fn sample_discrete_gauss(
modulus: impl Into<Modulus>,
center: impl Into<Q>,
s: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_discrete_gauss( modulus: impl Into<Modulus>, center: impl Into<Q>, s: impl Into<Q>, ) -> Result<Self, MathError>
Chooses a Zq instance chosen according to the discrete Gaussian distribution
in [center - ⌈6 * s⌉ , center + ⌊ 6 * s⌋ ].
This function samples discrete Gaussians according to the definition of SampleZ in GPV08.
Parameters:
modulus: specifies the modulus of the newZqelementcenter: 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 Zq sample chosen according to the specified discrete Gaussian
distribution or a MathError if the specified parameters were not chosen
appropriately, i.e. s < 0.
§Examples
use qfall_math::integer_mod_q::Zq;
let sample = Zq::sample_discrete_gauss(17, 0, 1).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifs < 0.
§Panics …
- if
modulusis smaller than2.
This function implements SampleZ according to:
- [1] Gentry, Craig and Peikert, Chris and Vaikuntanathan, Vinod (2008). Trapdoors for hard lattices and new cryptographic constructions. In: Proceedings of the fortieth annual ACM symposium on Theory of computing. https://dl.acm.org/doi/pdf/10.1145/1374376.1374407
Source§impl Zq
impl Zq
Sourcepub fn sample_uniform(modulus: impl Into<Z>) -> Self
pub fn sample_uniform(modulus: impl Into<Z>) -> Self
Chooses a Zq instance uniformly at random in [0, modulus).
The internally used uniform at random chosen bytes are generated
by ThreadRng, which uses ChaCha12 and
is considered cryptographically secure.
Parameters:
modulus: specifies theModulusof the newZqinstance and thus the size of the interval over which is sampled
Returns a new Zq instance with a value chosen
uniformly at random in [0, modulus).
§Examples
use qfall_math::integer_mod_q::Zq;
let sample = Zq::sample_uniform(17);§Panics
- if the given modulus is smaller than or equal to
1.
Source§impl Zq
impl Zq
Sourcepub fn to_utf8(&self) -> Result<String, FromUtf8Error>
pub fn to_utf8(&self) -> Result<String, FromUtf8Error>
Enables conversion to a UTF8-Encoded String for Zq values.
The inverse to this function is Zq::from_utf8 for valid UTF8-Encodings.
Warning: Not every byte-sequence forms a valid UTF8-character.
If this is the case, a FromUtf8Error will be returned.
Returns the corresponding UTF8-encoded String or a
FromUtf8Error if the byte sequence contains an invalid UTF8-character.
§Examples
use qfall_math::integer_mod_q::Zq;
let value = Zq::from((10, 63));
let text: String = value.to_utf8().unwrap();§Errors and Failures
- Returns a
FromUtf8Errorif the integer’s byte sequence contains valid UTF8-characters.
Source§impl Zq
impl Zq
Sourcepub unsafe fn get_fmpz(&mut self) -> &mut fmpz
pub unsafe fn get_fmpz(&mut self) -> &mut fmpz
Returns a mutable reference to the underlying fmpz by calling get_fmpz on value.
WARNING: The returned struct is part of flint_sys.
Any changes to this object are unsafe and may introduce memory leaks.
In case you are calling this function to a modulus struct,
please be aware that most moduli are shared across multiple instances and all
modifications of this struct will affect any other instance with a reference to this object.
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Source§impl Zq
impl Zq
Sourcepub unsafe fn get_fmpz_mod_ctx(&mut self) -> &mut fmpz_mod_ctx
pub unsafe fn get_fmpz_mod_ctx(&mut self) -> &mut fmpz_mod_ctx
Returns a mutable reference to the underlying fmpz_mod_ctx by calling get_fmpz_mod_ctx on modulus.
WARNING: The returned struct is part of flint_sys.
Any changes to this object are unsafe and may introduce memory leaks.
In case you are calling this function to a modulus struct,
please be aware that most moduli are shared across multiple instances and all
modifications of this struct will affect any other instance with a reference to this object.
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Source§impl Zq
impl Zq
Sourcepub unsafe fn set_fmpz(&mut self, flint_struct: fmpz)
pub unsafe fn set_fmpz(&mut self, flint_struct: fmpz)
Sets the field fmpz to flint_struct by calling set_fmpz on value.
Parameters:
flint_struct: value to set the attribute to
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Ensure that the old struct does not share any memory with any other structs that might be used in the future. The memory of the old struct is freed using this function.
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Source§impl Zq
impl Zq
Sourcepub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx)
pub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx)
Sets the field fmpz_mod_ctx to flint_struct by calling set_fmpz_mod_ctx on modulus.
Parameters:
flint_struct: value to set the attribute to
This function is a passthrough to enable users of this library to use flint_sys
and with that FLINT functions that might not be covered in our library yet.
If this is the case, please consider contributing to this open-source project
by opening a Pull Request at qfall_math
to provide this feature in the future.
§Safety
Ensure that the old struct does not share any memory with any other structs that might be used in the future. The memory of the old struct is freed using this function.
Any flint_sys struct and function is part of a FFI to the C-library FLINT.
As FLINT is a C-library, it does not provide all memory safety features
that Rust and our Wrapper provide.
Thus, using functions of flint_sys can introduce memory leaks.
Trait Implementations§
Source§impl Add<&Z> for &Zq
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 &Zq
impl Add for &Zq
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Implements the Add trait for two Zq values.
Add is implemented for any combination of Zq and borrowed Zq.
Parameters:
other: specifies the value to add toself
Returns the sum of both numbers as a Zq.
§Examples
use qfall_math::integer_mod_q::Zq;
let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Zq = &a + &b;
let d: Zq = a + b;
let e: Zq = &c + d;
let f: Zq = c + &e;§Panics …
- if the moduli of both
Zqmismatch.
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<&Zq> for Zq
impl AddAssign<&Zq> for Zq
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 Zq in combination with
Zq, Z, i64, i32, i16, i8, u64, u32, u16 and u8.
Parameters:
other: specifies the value to add toself
Returns the sum of both numbers modulo q as a Zq.
§Examples
use qfall_math::{integer_mod_q::Zq, integer::Z};
let mut a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Z = Z::from(5);
a += &b;
a += b;
a += 5;
a += c;§Panics …
- if the moduli of both
Zqmismatch.
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 Zq
impl AddAssign<i16> for Zq
Source§fn add_assign(&mut self, other: i16)
fn add_assign(&mut self, other: i16)
Documentation at Zq::add_assign.
Source§impl AddAssign<i32> for Zq
impl AddAssign<i32> for Zq
Source§fn add_assign(&mut self, other: i32)
fn add_assign(&mut self, other: i32)
Documentation at Zq::add_assign.
Source§impl AddAssign<i64> for Zq
impl AddAssign<i64> for Zq
Source§fn add_assign(&mut self, other: i64)
fn add_assign(&mut self, other: i64)
Documentation at Zq::add_assign.
Source§impl AddAssign<i8> for Zq
impl AddAssign<i8> for Zq
Source§fn add_assign(&mut self, other: i8)
fn add_assign(&mut self, other: i8)
Documentation at Zq::add_assign.
Source§impl AddAssign<u16> for Zq
impl AddAssign<u16> for Zq
Source§fn add_assign(&mut self, other: u16)
fn add_assign(&mut self, other: u16)
Documentation at Zq::add_assign.
Source§impl AddAssign<u32> for Zq
impl AddAssign<u32> for Zq
Source§fn add_assign(&mut self, other: u32)
fn add_assign(&mut self, other: u32)
Documentation at Zq::add_assign.
Source§impl AddAssign<u64> for Zq
impl AddAssign<u64> for Zq
Source§fn add_assign(&mut self, other: u64)
fn add_assign(&mut self, other: u64)
Documentation at Zq::add_assign.
Source§impl AddAssign<u8> for Zq
impl AddAssign<u8> for Zq
Source§fn add_assign(&mut self, other: u8)
fn add_assign(&mut self, other: u8)
Documentation at Zq::add_assign.
Source§impl AddAssign for Zq
impl AddAssign for Zq
Source§fn add_assign(&mut self, other: Zq)
fn add_assign(&mut self, other: Zq)
Documentation at Zq::add_assign.
Source§impl CompareBase<&Zq> for MatNTTPolynomialRingZq
impl CompareBase<&Zq> for MatNTTPolynomialRingZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for MatPolynomialRingZq
impl CompareBase<&Zq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for MatZq
impl CompareBase<&Zq> for MatZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for NTTPolynomialRingZq
impl CompareBase<&Zq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for PolyOverZq
impl CompareBase<&Zq> for PolyOverZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for PolynomialRingZq
impl CompareBase<&Zq> for PolynomialRingZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for Zq
impl CompareBase<&Zq> for Zq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl<Integer: Into<Z>> CompareBase<Integer> for Zq
impl<Integer: Into<Z>> CompareBase<Integer> for Zq
Source§impl CompareBase<Zq> for MatNTTPolynomialRingZq
impl CompareBase<Zq> for MatNTTPolynomialRingZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for MatPolynomialRingZq
impl CompareBase<Zq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for MatZq
impl CompareBase<Zq> for MatZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for NTTPolynomialRingZq
impl CompareBase<Zq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for PolyOverZq
impl CompareBase<Zq> for PolyOverZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for PolynomialRingZq
impl CompareBase<Zq> for PolynomialRingZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase for Zq
impl CompareBase for Zq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl<'de> Deserialize<'de> for Zq
impl<'de> Deserialize<'de> for Zq
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>,
Source§impl Display for Zq
impl Display for Zq
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Allows to convert an integer of type Zq into a String.
Returns the integer in form of a String. For integer 2 mod 4
the String looks like this 2 mod 4.
§Examples
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
use core::fmt;
let integer_mod_q = Zq::from((42, 3));
println!("{integer_mod_q}");use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
use core::fmt;
let integer_mod_q = Zq::from((42, 3));
let integer_string = integer_mod_q.to_string();Source§impl Evaluate<&Zq, Zq> for PolyOverZq
impl Evaluate<&Zq, Zq> for PolyOverZq
Source§fn evaluate(&self, value: &Zq) -> Zq
fn evaluate(&self, value: &Zq) -> Zq
Evaluates a PolyOverZq on a given input of Zq. Note that the
Zq in this case is only a reference. Note that this function will panic if
the modulus of the input and the polynomial mismatch.
Use PolyOverZq::evaluate_safe if a panic has to be avoided.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Zq.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("5 0 1 2 -3 1 mod 17").unwrap();
let value = Zq::from((3, 17));
let res = poly.evaluate(&value);§Panics …
- if the moduli of the polynomial and the input mismatch.
Source§impl<Integer: Into<Z>> Evaluate<Integer, Zq> for PolyOverZq
impl<Integer: Into<Z>> Evaluate<Integer, Zq> for PolyOverZq
Source§fn evaluate(&self, value: Integer) -> Zq
fn evaluate(&self, value: Integer) -> Zq
Evaluates a PolyOverZq on a given input that implements Into<Z>.
Parameters:
value: the value with which to evaluate the polynomial.
Returns the evaluation of the polynomial as a Zq.
§Examples
use qfall_math::traits::*;
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::PolyOverZq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("5 0 1 2 -3 1 mod 17").unwrap();
let value = Z::from(3);
let res = poly.evaluate(&value);
let res_2 = poly.evaluate(3);Source§impl From<&Zq> for PolyOverZq
impl From<&Zq> for PolyOverZq
Source§fn from(value: &Zq) -> Self
fn from(value: &Zq) -> Self
Creates a constant PolyOverZq, i.e. the polynomial x mod q,
where x is the value of the given Zq value and q its modulus.
Parameters:
value: the constant value the polynomial will have.
Returns a new constant PolyOverZq with the specified value and modulus of the Zq value.
§Examples
use qfall_math::{integer_mod_q::*, traits::*};
let poly = PolyOverZq::from(&Zq::from((1, 10)));
let poly_cmp = PolyOverZq::from((1, 10));
assert_eq!(poly, poly_cmp);
assert_eq!(poly.get_degree(), 0);Source§impl From<&Zq> for String
impl From<&Zq> for String
Source§fn from(value: &Zq) -> Self
fn from(value: &Zq) -> Self
Converts a Zq into its String representation.
Parameters:
value: specifies the integer and modulus that will be represented as aString
Returns a String of the form "x mod q".
§Examples
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let zq = Zq::from_str("3 mod 5").unwrap();
let string: String = zq.into();Source§impl<IntegerValue: Into<Z>, IntegerModulus: Into<Modulus>> From<(IntegerValue, IntegerModulus)> for Zq
impl<IntegerValue: Into<Z>, IntegerModulus: Into<Modulus>> From<(IntegerValue, IntegerModulus)> for Zq
Source§fn from((value, modulus): (IntegerValue, IntegerModulus)) -> Self
fn from((value, modulus): (IntegerValue, IntegerModulus)) -> Self
Creates a Zq from a tuple with the integer and the modulus.
Parameters:
value: Defines the value of the residue class.modulus: Defines the modulus by whichvalueis reduced.
Note that the strings for integer and modulus are trimmed, i.e. all whitespaces around all values are ignored.
Returns the value mod modulus as a Zq.
§Examples
use qfall_math::integer_mod_q::Zq;
use qfall_math::integer::Z;
let answer_1 = Zq::from((1337 + 42, 1337));
let answer_2 = Zq::from((Z::from(42), 1337));
assert_eq!(answer_1, answer_2);§Panics …
- if
modulusis smaller than2.
Source§impl<Mod: Into<Modulus>> From<Mod> for Zq
impl<Mod: Into<Modulus>> From<Mod> for Zq
Source§fn from(modulus: Mod) -> Self
fn from(modulus: Mod) -> Self
Creates a zero integer with a given Modulus.
Parameters:
modulus: of the newZq
Returns a new constant Zq with the specified Modulus.
§Examples
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let zq = Zq::from(100);
let zq_cmp = Zq::from_str("0 mod 100").unwrap();
assert_eq!(zq, zq_cmp);§Panics …
- if
modulusis smaller than2.
Source§impl From<Zq> for PolyOverZq
impl From<Zq> for PolyOverZq
Source§impl FromStr for Zq
impl FromStr for Zq
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a Zq integer from a String.
Parameters:
s: the integer and modulus value of form:"12 mod 25"for the number 12 under the modulus 25.
Returns a Zq or an error if the provided string was not formatted
correctly.
§Examples
use std::str::FromStr;
use qfall_math::integer_mod_q::Zq;
let a: Zq = "100 mod 3".parse().unwrap();
let b: Zq = Zq::from_str("100 mod 3").unwrap();§Errors and Failures
- Returns a
MathErrorof typeStringConversionError- if the provided string contains a
Nullbyte, - if the provided string was not formatted correctly,
- if the provided modulus was not formatted correctly to create a
Z, or - if the delimiter
modcould not be found.
- if the provided string contains a
- Returns a
MathErrorof typeInvalidModulusif the provided value is smaller than2. - Returns a
MathErrorof type
Source§impl GetCoefficient<Zq> for ModulusPolynomialRingZq
impl GetCoefficient<Zq> for ModulusPolynomialRingZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
Returns the coefficient of a polynomial ModulusPolynomialRingZq as a Zq.
If an index is provided which exceeds the highest set coefficient, 0 is returned.
Parameters:
index: the index of the coefficient to get (has to be positive)
Returns the coefficient as a Zq.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::{Zq, ModulusPolynomialRingZq};
use std::str::FromStr;
let poly = ModulusPolynomialRingZq::from_str("4 0 1 2 3 mod 17").unwrap();
let coeff_0: Zq = poly.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4: Zq = poly.get_coeff(4).unwrap();
assert_eq!(Zq::from((0, 17)), coeff_0);
assert_eq!(Zq::from((1, 17)), coeff_1);
assert_eq!(Zq::from((0, 17)), coeff_4);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl GetCoefficient<Zq> for PolyOverZq
impl GetCoefficient<Zq> for PolyOverZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
Returns the coefficient of a polynomial PolyOverZq as a Zq.
If an index is provided which exceeds the highest set coefficient, 0 is returned.
Parameters:
index: the index of the coefficient to get (has to be positive)
Returns the coefficient as a Zq, or a MathError if the provided index
is negative and therefore invalid, or it does not fit into an i64.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let poly = PolyOverZq::from_str("4 0 1 2 3 mod 17").unwrap();
let coeff_0: Zq = poly.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly.get_coeff_unchecked(1) };
let coeff_4: Zq = poly.get_coeff(4).unwrap();
assert_eq!(Zq::from((0, 17)), coeff_0);
assert_eq!(Zq::from((1, 17)), coeff_1);
assert_eq!(Zq::from((0, 17)), coeff_4);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl GetCoefficient<Zq> for PolynomialRingZq
impl GetCoefficient<Zq> for PolynomialRingZq
Source§unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
unsafe fn get_coeff_unchecked(&self, index: i64) -> Zq
Returns the coefficient of a PolynomialRingZq as a Zq.
If an index is provided which exceeds the highest set coefficient, 0 is returned.
Parameters:
index: the index of the coefficient to get (has to be positive)
Returns the coefficient as a Zq, or a MathError if the provided index
is negative and therefore invalid, or it does not fit into an i64.
§Examples
use qfall_math::traits::*;
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;
let poly_ring = PolynomialRingZq::from_str("3 0 1 1 / 4 1 0 0 1 mod 17").unwrap();
let coeff_0: Zq = poly_ring.get_coeff(0).unwrap();
let coeff_1: Zq = unsafe{ poly_ring.get_coeff_unchecked(1) };
let coeff_3: Zq = poly_ring.get_coeff(3).unwrap();
assert_eq!(Zq::from((0, 17)), coeff_0);
assert_eq!(Zq::from((1, 17)), coeff_1);
assert_eq!(Zq::from((0, 17)), coeff_3);§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0.
Source§impl MatrixGetEntry<Zq> for MatZq
impl MatrixGetEntry<Zq> for MatZq
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> Zq
unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> Zq
Outputs the Zq value of a specific matrix entry
without checking whether it’s part of the matrix.
Parameters:
row: specifies the row in which the entry is locatedcolumn: specifies the column in which the entry is located
Returns the Zq value of the matrix at the position of the given
row and column.
§Safety
To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
§Examples
use qfall_math::integer_mod_q::{MatZq, Zq};
use qfall_math::traits::MatrixGetEntry;
use std::str::FromStr;
let matrix = MatZq::from_str("[[1, 2, 3],[4, 5, 6],[7, 8, 9]] mod 10").unwrap();
assert_eq!(Zq::from((3, 10)), unsafe { matrix.get_entry_unchecked(0, 2) } );
assert_eq!(Zq::from((8, 10)), unsafe { matrix.get_entry_unchecked(2, 1) } );
assert_eq!(Zq::from((8, 10)), unsafe { matrix.get_entry_unchecked(2, 1) } );Source§fn get_entry(
&self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
) -> Result<T, MathError>
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 MatrixSetEntry<&Zq> for MatZq
impl MatrixSetEntry<&Zq> for MatZq
Source§unsafe fn set_entry_unchecked(&mut self, row: i64, column: i64, value: &Zq)
unsafe fn set_entry_unchecked(&mut self, row: i64, column: i64, value: &Zq)
Sets the value of a specific matrix entry according to a given value of type Zq
without checking whether the coordinate is part of the matrix,
if the moduli match or the entry is reduced.
Parameters:
row: specifies the row in which the entry is locatedcolumn: specifies the column in which the entry is locatedvalue: specifies the value to which the entry is set
§Safety
To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
§Examples
use qfall_math::integer_mod_q::{MatZq, Zq};
use qfall_math::traits::*;
let mut matrix = MatZq::new(3, 3, 10);
let value = Zq::from((5, 10));
unsafe {
matrix.set_entry_unchecked(0, 1, &value);
matrix.set_entry_unchecked(2, 2, Zq::from((19, 10)));
}
assert_eq!("[[0, 5, 0],[0, 0, 0],[0, 0, 9]] mod 10", matrix.to_string());Source§impl MatrixSetEntry<Zq> for MatZq
impl MatrixSetEntry<Zq> for MatZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: Zq,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: Zq, ) -> Result<(), MathError>
Documentation can be found at MatZq::set_entry for &Zq.
Source§unsafe fn set_entry_unchecked(&mut self, row: i64, column: i64, value: Zq)
unsafe fn set_entry_unchecked(&mut self, row: i64, column: i64, value: Zq)
Documentation can be found at MatZq::set_entry for &Zq.
Source§impl Mul<&Z> for &Zq
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 &MatPolynomialRingZq
impl Mul<&Zq> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &Zq) -> Self::Output
fn mul(self, scalar: &Zq) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a Zq integer.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, Zq};
use qfall_math::integer::{MatPolyOverZ, Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat1 = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let integer = Zq::from((3, 17));
let poly_ring_mat2 = &poly_ring_mat1 * &integer;§Panics …
- if the moduli mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&Zq> for &MatZ
impl Mul<&Zq> for &MatZ
Source§fn mul(self, scalar: &Zq) -> Self::Output
fn mul(self, scalar: &Zq) -> Self::Output
Implements the Mul trait for a MatZ matrix with a Zq representative of a residue class.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a MatZq.
§Examples
use qfall_math::integer::MatZ;
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let mat_1 = MatZ::from_str("[[2, 1],[1, 2]]").unwrap();
let zq = Zq::from((1,3));
let mat_2 = &mat_1 * &zq;Source§impl Mul<&Zq> for &MatZq
impl Mul<&Zq> for &MatZq
Source§fn mul(self, scalar: &Zq) -> Self::Output
fn mul(self, scalar: &Zq) -> Self::Output
Implements the Mul trait for a MatZq matrix with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a MatZq.
§Examples
use qfall_math::integer_mod_q::{MatZq, Zq};
use std::str::FromStr;
let mat_1 = MatZq::from_str("[[42, 17],[8, 6]] mod 61").unwrap();
let integer = Zq::from((2, 61));
let mat_2 = &mat_1 * &integer;§Panics …
- if the moduli mismatch.
Source§impl Mul<&Zq> for &PolyOverZ
impl Mul<&Zq> for &PolyOverZ
Source§fn mul(self, scalar: &Zq) -> PolyOverZq
fn mul(self, scalar: &Zq) -> PolyOverZq
Implements the Mul trait for a PolyOverZ with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Zq using PolyOverZ.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a PolyOverZq.
§Examples
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolyOverZq, Zq};
use std::str::FromStr;
let poly_1 = PolyOverZ::from_str("4 1 2 3 4").unwrap();
let integer = Zq::from((3,17));
let poly_2 = &poly_1 * &integer;Source§type Output = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl Mul<&Zq> for &PolyOverZq
impl Mul<&Zq> for &PolyOverZq
Source§fn mul(self, scalar: &Zq) -> PolyOverZq
fn mul(self, scalar: &Zq) -> PolyOverZq
Implements the Mul trait for a PolyOverZq with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Zq using PolyOverZq.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a PolyOverZq.
§Examples
use qfall_math::integer_mod_q::{PolyOverZq, Zq};
use std::str::FromStr;
let poly_1 = PolyOverZq::from_str("4 1 2 3 4 mod 17").unwrap();
let integer = Zq::from((3,17));
let poly_2 = &poly_1 * &integer;§Panics …
- if the moduli mismatch.
Source§type Output = PolyOverZq
type Output = PolyOverZq
* operator.Source§impl Mul<&Zq> for &PolynomialRingZq
impl Mul<&Zq> for &PolynomialRingZq
Source§fn mul(self, scalar: &Zq) -> PolynomialRingZq
fn mul(self, scalar: &Zq) -> PolynomialRingZq
Implements the Mul trait for a PolynomialRingZq with a Zq.
Mul is implemented for any combination of owned and borrowed values.
Mul is also implemented for Zq using PolynomialRingZq.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, Zq};
use std::str::FromStr;
let poly_1 = PolynomialRingZq::from_str("3 1 2 3 / 4 1 2 3 4 mod 17").unwrap();
let integer = Zq::from((3,17));
let poly_2 = &poly_1 * &integer;§Panics …
- if the moduli mismatch.
Source§type Output = PolynomialRingZq
type Output = PolynomialRingZq
* operator.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 &Zq
impl Mul for &Zq
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Implements the Mul trait for two Zq values.
Mul is implemented for any combination of Zq and borrowed Zq.
Parameters:
other: specifies the value to multiply withself
Returns the product of both numbers as a Zq.
§Examples
use qfall_math::integer_mod_q::Zq;
let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Zq = &a * &b;
let d: Zq = a * b;
let e: Zq = &c * d;
let f: Zq = c * &e;§Panics …
- if the moduli of both
Zqmismatch.
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<&Zq> for MatPolynomialRingZq
impl MulAssign<&Zq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, scalar: &Zq)
fn mul_assign(&mut self, scalar: &Zq)
Source§impl MulAssign<&Zq> for PolyOverZq
impl MulAssign<&Zq> for PolyOverZq
Source§fn mul_assign(&mut self, scalar: &Zq)
fn mul_assign(&mut self, scalar: &Zq)
Source§impl MulAssign<&Zq> for PolynomialRingZq
impl MulAssign<&Zq> for PolynomialRingZq
Source§fn mul_assign(&mut self, rhs: &Zq)
fn mul_assign(&mut self, rhs: &Zq)
Computes the scalar multiplication of self and other reusing
the memory of self.
Parameters:
other: specifies the value to multiply toself
Returns the scalar of the matrix as a PolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{ModulusPolynomialRingZq,PolynomialRingZq,Zq};
use qfall_math::integer::{MatZ,PolyOverZ,Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {}", u64::MAX - 1)).unwrap();
let poly_z = PolyOverZ::from_str("2 3 1").unwrap();
let mut polynomial_ring_zq = PolynomialRingZq::from((&poly_z, &modulus));
let zq = Zq::from((17, u64::MAX -1 ));
let z = Z::from(5);
polynomial_ring_zq *= &zq;
polynomial_ring_zq *= zq;
polynomial_ring_zq *= &z;
polynomial_ring_zq *= z;
polynomial_ring_zq *= 2;
polynomial_ring_zq *= -2;§Panics …
- if the moduli are different.
Source§impl MulAssign<&Zq> for Zq
impl MulAssign<&Zq> for Zq
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 Zq in combination with
Zq, Z, i64, i32, i16, i8, u64, u32, u16 and u8.
Parameters:
other: specifies the value to multiply toself
Returns the product of both numbers modulo q as a Zq.
§Examples
use qfall_math::{integer_mod_q::Zq, integer::Z};
let mut a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Z = Z::from(5);
a *= &b;
a *= b;
a *= 5;
a *= c;§Panics …
- if the moduli of both
Zqmismatch.
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<Zq> for MatPolynomialRingZq
impl MulAssign<Zq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at MatPolynomialRingZq::mul_assign.
Source§impl MulAssign<Zq> for MatZq
impl MulAssign<Zq> for MatZq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at MatZq::mul_assign.
Source§impl MulAssign<Zq> for PolyOverZq
impl MulAssign<Zq> for PolyOverZq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at PolyOverZq::mul_assign.
Source§impl MulAssign<Zq> for PolynomialRingZq
impl MulAssign<Zq> for PolynomialRingZq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at PolynomialRingZq::mul_assign.
Source§impl MulAssign<i16> for Zq
impl MulAssign<i16> for Zq
Source§fn mul_assign(&mut self, other: i16)
fn mul_assign(&mut self, other: i16)
Documentation at Zq::mul_assign.
Source§impl MulAssign<i32> for Zq
impl MulAssign<i32> for Zq
Source§fn mul_assign(&mut self, other: i32)
fn mul_assign(&mut self, other: i32)
Documentation at Zq::mul_assign.
Source§impl MulAssign<i64> for Zq
impl MulAssign<i64> for Zq
Source§fn mul_assign(&mut self, other: i64)
fn mul_assign(&mut self, other: i64)
Documentation at Zq::mul_assign.
Source§impl MulAssign<i8> for Zq
impl MulAssign<i8> for Zq
Source§fn mul_assign(&mut self, other: i8)
fn mul_assign(&mut self, other: i8)
Documentation at Zq::mul_assign.
Source§impl MulAssign<u16> for Zq
impl MulAssign<u16> for Zq
Source§fn mul_assign(&mut self, other: u16)
fn mul_assign(&mut self, other: u16)
Documentation at Zq::mul_assign.
Source§impl MulAssign<u32> for Zq
impl MulAssign<u32> for Zq
Source§fn mul_assign(&mut self, other: u32)
fn mul_assign(&mut self, other: u32)
Documentation at Zq::mul_assign.
Source§impl MulAssign<u64> for Zq
impl MulAssign<u64> for Zq
Source§fn mul_assign(&mut self, other: u64)
fn mul_assign(&mut self, other: u64)
Documentation at Zq::mul_assign.
Source§impl MulAssign<u8> for Zq
impl MulAssign<u8> for Zq
Source§fn mul_assign(&mut self, other: u8)
fn mul_assign(&mut self, other: u8)
Documentation at Zq::mul_assign.
Source§impl MulAssign for Zq
impl MulAssign for Zq
Source§fn mul_assign(&mut self, other: Zq)
fn mul_assign(&mut self, other: Zq)
Documentation at Zq::mul_assign.
Source§impl<Integer: Into<Z>> Pow<Integer> for Zq
impl<Integer: Into<Z>> Pow<Integer> for Zq
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 Output instance
or an error if the exponent is negative and the base value of self is not invertible.
§Examples
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::Zq;
use qfall_math::traits::*;
let base = Zq::from((2, 9));
let powered_value = base.pow(4).unwrap();
let cmp = Zq::from((7, 9));
assert_eq!(cmp, powered_value);§Errors and Failures
- Returns a
MathErrorof typeInvalidExponentif the provided exponent is negative and the base value ofselfis not invertible.
type Output = Zq
Source§impl SetCoefficient<&Zq> for PolyOverZq
impl SetCoefficient<&Zq> for PolyOverZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)
Sets the coefficient of a polynomial PolyOverZq.
We advise to use small coefficients, since already 2^32 coefficients take space
of roughly 34 GB. If not careful, be prepared that memory problems can occur, if
the index is very high.
This function does not check if the modulus of the polynomial and the value match.
Parameters:
index: the index of the coefficient to set (has to be positive)value: the new value the index should have from a borrowedZq.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::Zq;
use qfall_math::traits::*;
use std::str::FromStr;
let mut poly = PolyOverZq::from_str("4 0 1 2 3 mod 17").unwrap();
let value = Zq::from((1000, 17));
assert!(poly.set_coeff(4, &value).is_ok());
unsafe{ poly.set_coeff_unchecked(5, &value) };§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0 and that the provided value has
the same base so that they have a matching base.
Source§impl SetCoefficient<&Zq> for PolynomialRingZq
impl SetCoefficient<&Zq> for PolynomialRingZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: &Zq)
Sets the coefficient of a PolynomialRingZq element.
We advise to use small coefficients, since already 2^32 coefficients take space
of roughly 34 GB. If not careful, be prepared that memory problems can occur, if
the index is very high.
This function does not check if the modulus of the polynomial and the value match.
Parameters:
index: the index of the coefficient to set (has to be positive)value: the new value the index should have
§Examples
use crate::qfall_math::traits::SetCoefficient;
use qfall_math::integer::PolyOverZ;
use qfall_math::integer_mod_q::{PolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer_mod_q::Zq;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZ::from_str("3 0 1 1").unwrap();
let mut poly_ring = PolynomialRingZq::from((&poly, &modulus));
let value = Zq::from((1000, 17));
poly_ring.set_coeff(2, &value).unwrap();
unsafe{ poly_ring.set_coeff_unchecked(5, &value) };§Safety
To use this function safely, make sure that the selected index
is greater or equal than 0 and that the provided value has
the same base so that they have a matching base.
Source§impl SetCoefficient<Zq> for PolyOverZq
impl SetCoefficient<Zq> for PolyOverZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)
Documentation can be found at PolyOverZq::set_coeff for &Zq.
Source§impl SetCoefficient<Zq> for PolynomialRingZq
impl SetCoefficient<Zq> for PolynomialRingZq
Source§unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)
unsafe fn set_coeff_unchecked(&mut self, index: i64, value: Zq)
Documentation can be found at PolynomialRingZq::set_coeff for &Zq.
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 &Zq
impl Sub for &Zq
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Implements the Sub trait for two Zq values.
Sub is implemented for any combination of Zq and borrowed Zq.
Parameters:
other: specifies the value to subtract fromself
Returns the result of the subtraction of both numbers as a Zq.
§Examples
use qfall_math::integer_mod_q::Zq;
let a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Zq = &a - &b;
let d: Zq = a - b;
let e: Zq = &c - d;
let f: Zq = c - &e;§Panics …
- if the moduli of both
Zqmismatch.
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<&Zq> for Zq
impl SubAssign<&Zq> for Zq
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 Zq in combination with
Zq, Z, i64, i32, i16, i8, u64, u32, u16 and u8.
Parameters:
other: specifies the value to subtract fromself
Returns the difference of both numbers modulo q as a Zq.
§Examples
use qfall_math::{integer_mod_q::Zq, integer::Z};
let mut a: Zq = Zq::from((23, 42));
let b: Zq = Zq::from((1, 42));
let c: Z = Z::from(5);
a -= &b;
a -= b;
a -= 5;
a -= c;§Panics …
- if the moduli of both
Zqmismatch.
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 Zq
impl SubAssign<i16> for Zq
Source§fn sub_assign(&mut self, other: i16)
fn sub_assign(&mut self, other: i16)
Documentation at Zq::sub_assign.
Source§impl SubAssign<i32> for Zq
impl SubAssign<i32> for Zq
Source§fn sub_assign(&mut self, other: i32)
fn sub_assign(&mut self, other: i32)
Documentation at Zq::sub_assign.
Source§impl SubAssign<i64> for Zq
impl SubAssign<i64> for Zq
Source§fn sub_assign(&mut self, other: i64)
fn sub_assign(&mut self, other: i64)
Documentation at Zq::sub_assign.
Source§impl SubAssign<i8> for Zq
impl SubAssign<i8> for Zq
Source§fn sub_assign(&mut self, other: i8)
fn sub_assign(&mut self, other: i8)
Documentation at Zq::sub_assign.
Source§impl SubAssign<u16> for Zq
impl SubAssign<u16> for Zq
Source§fn sub_assign(&mut self, other: u16)
fn sub_assign(&mut self, other: u16)
Documentation at Zq::sub_assign.
Source§impl SubAssign<u32> for Zq
impl SubAssign<u32> for Zq
Source§fn sub_assign(&mut self, other: u32)
fn sub_assign(&mut self, other: u32)
Documentation at Zq::sub_assign.
Source§impl SubAssign<u64> for Zq
impl SubAssign<u64> for Zq
Source§fn sub_assign(&mut self, other: u64)
fn sub_assign(&mut self, other: u64)
Documentation at Zq::sub_assign.
Source§impl SubAssign<u8> for Zq
impl SubAssign<u8> for Zq
Source§fn sub_assign(&mut self, other: u8)
fn sub_assign(&mut self, other: u8)
Documentation at Zq::sub_assign.
Source§impl SubAssign for Zq
impl SubAssign for Zq
Source§fn sub_assign(&mut self, other: Zq)
fn sub_assign(&mut self, other: Zq)
Documentation at Zq::sub_assign.