pub struct MatPolynomialRingZq { /* private fields */ }Expand description
MatPolynomialRingZq is a matrix with entries of type PolynomialRingZq.
Attributes:
matrix: holds theMatPolyOverZmatrixmodulus: holds theModulusPolynomialRingZqmodulus of the matrix
§Examples
§Matrix usage
use qfall_math::{
integer::{PolyOverZ, MatPolyOverZ},
integer_mod_q::{MatPolynomialRingZq, PolyOverZq},
traits::{MatrixGetEntry, MatrixSetEntry},
};
use std::str::FromStr;
// instantiate new matrix
let id_mat = MatPolyOverZ::identity(2, 2);
// instantiate modulus_object
let modulus = PolyOverZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let poly_mat = MatPolynomialRingZq::from((id_mat, modulus));
// clone object, set and get entry
let mut clone = poly_mat.clone();
clone.set_entry(0, 0, PolyOverZ::from(-16));
let entry: PolyOverZ = clone.get_entry(0,0).unwrap();
assert_eq!(
entry,
PolyOverZ::from(1),
);
// to_string
assert_eq!("[[1 1, 0],[0, 1 1]] / 5 1 0 0 0 1 mod 17", &poly_mat.to_string());§Vector usage
use qfall_math::{
integer::{PolyOverZ, MatPolyOverZ},
integer_mod_q::{MatPolynomialRingZq, PolyOverZq},
};
use std::str::FromStr;
let row_vec = MatPolyOverZ::from_str("[[1 1, 0, 1 1]]").unwrap();
let col_vec = MatPolyOverZ::from_str("[[1 -5],[1 -1],[0]]").unwrap();
let modulus = PolyOverZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let row_vec = MatPolynomialRingZq::from((row_vec, modulus));
let col_vec = MatPolynomialRingZq::from((col_vec, row_vec.get_mod()));
// check if matrix instance is vector
assert!(row_vec.is_row_vector());
assert!(col_vec.is_column_vector());Implementations§
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn add_safe(&self, other: &Self) -> Result<MatPolynomialRingZq, MathError>
pub fn add_safe(&self, other: &Self) -> Result<MatPolynomialRingZq, MathError>
Implements addition for two MatPolynomialRingZq values.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a MatPolynomialRingZq or an error if the moduli
mismatch, or the dimensions of the matrices mismatch.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat_1 = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let poly_mat_2 = MatPolyOverZ::from_str("[[3 3 0 1, 1 42],[0, 1 17]]").unwrap();
let poly_ring_mat_2 = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
let poly_ring_mat_3: MatPolynomialRingZq = poly_ring_mat_1.add_safe(&poly_ring_mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothMatPolynomialRingZqmismatch. - Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the dimensions of bothMatPolynomialRingZqmismatch.
Sourcepub fn add_mat_poly_over_z_safe(
&self,
other: &MatPolyOverZ,
) -> Result<Self, MathError>
pub fn add_mat_poly_over_z_safe( &self, other: &MatPolyOverZ, ) -> Result<Self, MathError>
Implements addition for a MatPolynomialRingZq matrix with a MatPolyOverZ matrix.
Parameters:
other: specifies the value to add withself
Returns the addition of self and other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_3 = &mat_1.add_mat_poly_over_z_safe(&mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the dimensions ofselfandotherdo not match for multiplication.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn mul_safe(&self, other: &Self) -> Result<Self, MathError>
pub fn mul_safe(&self, other: &Self) -> Result<Self, MathError>
Implements multiplication for two MatPolynomialRingZq values.
Parameters:
other: specifies the value to multiply withself
Returns the product of self and other as a MatPolynomialRingZq
or an error if the dimensions of self and other do not match for multiplication
or the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat_1 = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let poly_mat_2 = MatPolyOverZ::from_str("[[3 3 0 1, 1 42],[0, 1 17]]").unwrap();
let poly_ring_mat_2 = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
let poly_ring_mat_3: MatPolynomialRingZq = poly_ring_mat_1.mul_safe(&poly_ring_mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the dimensions ofselfandotherdo not match for multiplication. - Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli mismatch.
Sourcepub fn mul_mat_poly_over_z_safe(
&self,
other: &MatPolyOverZ,
) -> Result<Self, MathError>
pub fn mul_mat_poly_over_z_safe( &self, other: &MatPolyOverZ, ) -> Result<Self, MathError>
Implements multiplication for a MatPolynomialRingZq matrix with a MatPolyOverZ matrix.
Parameters:
other: specifies the value to multiply withself
Returns the product of self and other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_3 = &mat_1.mul_mat_poly_over_z_safe(&mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the dimensions ofselfandotherdo not match for multiplication.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn mul_scalar_zq_safe(&self, scalar: &Zq) -> Result<Self, MathError>
pub fn mul_scalar_zq_safe(&self, scalar: &Zq) -> Result<Self, MathError>
Implements multiplication for a MatPolynomialRingZq matrix with a Zq.
Parameters:
scalar: specifies the scalar by which the matrix is multiplied
Returns the product of self and scalar as a MatPolynomialRingZq or
an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, Zq};
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[1 42, 1 17],[2 1 8, 1 6]] / 3 1 2 3 mod 61").unwrap();
let integer = Zq::from((2, 61));
let mat_2 = &mat_1.mul_scalar_zq_safe(&integer).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMismatchingModulusif the moduli mismatch.
Sourcepub fn mul_scalar_poly_over_zq_safe(
&self,
scalar: &PolyOverZq,
) -> Result<Self, MathError>
pub fn mul_scalar_poly_over_zq_safe( &self, scalar: &PolyOverZq, ) -> Result<Self, MathError>
Implements multiplication for a MatPolynomialRingZq matrix with a PolyOverZq.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq
or an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq, PolyOverZq};
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 poly = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
let poly_ring_mat2 = &poly_ring_mat1.mul_scalar_poly_over_zq_safe(&poly);§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli mismatch.
Sourcepub fn mul_scalar_poly_ring_zq_safe(
&self,
scalar: &PolynomialRingZq,
) -> Result<Self, MathError>
pub fn mul_scalar_poly_ring_zq_safe( &self, scalar: &PolynomialRingZq, ) -> Result<Self, MathError>
Implements multiplication for a MatPolynomialRingZq matrix with a PolynomialRingZq.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq
or an error if the moduli mismatch.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ, Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat1 = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly = PolyOverZ::from_str("3 1 0 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_mat2 = &poly_ring_mat1.mul_scalar_poly_ring_zq_safe(&poly_ring);§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli mismatch.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn sub_safe(&self, other: &Self) -> Result<MatPolynomialRingZq, MathError>
pub fn sub_safe(&self, other: &Self) -> Result<MatPolynomialRingZq, MathError>
Implements subtraction for two MatPolynomialRingZq matrices.
Parameters:
other: specifies the value to subtract fromself
Returns the result of the subtraction as a MatPolynomialRingZq or an
error if the matrix dimensions or moduli mismatch.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 3],[0, 2 1 2]]").unwrap();
let poly_ring_mat_1 = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let poly_mat_2 = MatPolyOverZ::from_str("[[3 3 0 1, 1 7],[0, 1 16]]").unwrap();
let poly_ring_mat_2 = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
let poly_ring_mat_3 = poly_ring_mat_1.sub_safe(&poly_ring_mat_2);§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingModulusif the moduli of bothMatPolynomialRingZqmismatch. - Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the dimensions of bothMatPolynomialRingZqmismatch.
Sourcepub fn sub_mat_poly_over_z_safe(
&self,
other: &MatPolyOverZ,
) -> Result<Self, MathError>
pub fn sub_mat_poly_over_z_safe( &self, other: &MatPolyOverZ, ) -> Result<Self, MathError>
Implements subtraction for a MatPolynomialRingZq matrix with a MatPolyOverZ matrix.
Parameters:
other: specifies the value to subtract fromself
Returns the subtraction of self by other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_3 = &mat_1.sub_mat_poly_over_z_safe(&mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the dimensions ofselfandotherdo not match for multiplication.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn new(
num_rows: impl TryInto<i64> + Display,
num_cols: impl TryInto<i64> + Display,
modulus: impl Into<ModulusPolynomialRingZq>,
) -> Self
pub fn new( num_rows: impl TryInto<i64> + Display, num_cols: impl TryInto<i64> + Display, modulus: impl Into<ModulusPolynomialRingZq>, ) -> Self
Creates a new matrix with num_rows rows, num_cols columns,
zeros as entries and modulus as the modulus.
Parameters:
num_rows: number of rows the new matrix should havenum_cols: number of columns the new matrix should havemodulus: the common modulus of the matrix entries
Returns a new MatPolynomialRingZq instance of the provided dimensions.
§Examples
use qfall_math::integer_mod_q::PolyOverZq;
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use std::str::FromStr;
let poly_mod = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
let modulus = ModulusPolynomialRingZq::try_from(&poly_mod).unwrap();
let matrix = MatPolynomialRingZq::new(5, 10, &modulus);§Panics …
- if the number of rows or columns is negative,
0, or does not fit into ani64.
Sourcepub fn identity(
num_rows: impl TryInto<i64> + Display,
num_cols: impl TryInto<i64> + Display,
modulus: impl Into<ModulusPolynomialRingZq>,
) -> Self
pub fn identity( num_rows: impl TryInto<i64> + Display, num_cols: impl TryInto<i64> + Display, modulus: impl Into<ModulusPolynomialRingZq>, ) -> Self
Generate a num_rows times num_columns matrix with 1 on the
diagonal and 0 anywhere else with a given modulus.
Parameters:
rum_rows: the number of rows of the identity matrixnum_columns: the number of columns of the identity matrixmodulus: the polynomial mod q which serves as the modulus of the matrix
Returns a matrix with 1 across the diagonal and 0 anywhere else.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap();
let matrix = MatPolynomialRingZq::identity(2, 3, &modulus);
let identity = MatPolynomialRingZq::identity(10, 10, &modulus);§Panics …
- if the provided number of rows and columns are not suited to create a matrix.
For further information see
MatPolyOverZ::new.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn get_mod(&self) -> ModulusPolynomialRingZq
pub fn get_mod(&self) -> ModulusPolynomialRingZq
Returns the modulus of the matrix as a ModulusPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let modulus = poly_ring_mat.get_mod();Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn get_representative_least_nonnegative_residue(&self) -> MatPolyOverZ
pub fn get_representative_least_nonnegative_residue(&self) -> MatPolyOverZ
Creates a MatPolyOverZ where each entry is a representative of the
equivalence class of each entry from a MatPolynomialRingZq.
The representation of the coefficients is in the range [0, modulus) and
the representation of the polynomials is in the range [0, modulus_polynomial).
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let matrix = poly_ring_mat.get_representative_least_nonnegative_residue();
let cmp_poly_mat = MatPolyOverZ::from_str("[[3 15 0 1, 1 8],[0, 2 1 2]]").unwrap();
assert_eq!(cmp_poly_mat, matrix);Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn norm_l_2_infty_sqrd(&self) -> Z
pub fn norm_l_2_infty_sqrd(&self) -> Z
Outputs the squared l_{2, ∞}-norm, i.e. it computes the squared Euclidean norm of each column of the matrix and returns the largest one.
§Examples
use qfall_math::{integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq}, integer::{Z, MatPolyOverZ}};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 7").unwrap();
let mat = MatPolyOverZ::from_str("[[1 2, 1 3],[1 2, 0]]").unwrap();
let mat = MatPolynomialRingZq::from((&mat, &modulus));
let eucl_norm = mat.norm_l_2_infty_sqrd();
// 3^2 + 0^2 = 9
assert_eq!(Z::from(9), eucl_norm);Sourcepub fn norm_l_2_infty(&self) -> Q
pub fn norm_l_2_infty(&self) -> Q
Outputs the l_{2, ∞}-norm, i.e. it computes the Euclidean norm of each column of the matrix and returns the largest one.
§Examples
use qfall_math::{integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq}, integer::{Z, MatPolyOverZ}};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 5").unwrap();
let mat = MatPolyOverZ::from_str("[[1 2, 1 3],[1 2, 1 0],[1 3, 1 4],[1 3, 1 4]]").unwrap();
let mat = MatPolynomialRingZq::from((&mat, &modulus));
let eucl_norm = mat.norm_l_2_infty();
// sqrt(4 * 2^2) = 4
assert_eq!(Q::from(4), eucl_norm);Sourcepub fn norm_l_infty_infty(&self) -> Z
pub fn norm_l_infty_infty(&self) -> Z
Outputs the l_{∞, ∞}-norm, i.e. it computes the ∞-norm of each column of the matrix and returns the largest one.
§Examples
use qfall_math::{integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq}, integer::{Z, MatPolyOverZ}};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 7").unwrap();
let mat = MatPolyOverZ::from_str("[[1 2, 1 4],[1 2, 0]]").unwrap();
let mat = MatPolynomialRingZq::from((&mat, &modulus));
let eucl_norm = mat.norm_l_infty_infty();
// max{2, 3} = 3
assert_eq!(Z::from(3), eucl_norm);Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Checks if a MatPolynomialRingZq is the identity matrix.
Returns true if every diagonal entry of the matrix is
the constant polynomial 1 and all other entries are 0.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, PolyOverZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = PolyOverZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let id_mat = MatPolyOverZ::identity(2, 2);
let poly_ring_mat = MatPolynomialRingZq::from((id_mat, modulus));
assert!(poly_ring_mat.is_identity());use qfall_math::integer_mod_q::{MatPolynomialRingZq, PolyOverZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = PolyOverZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let id_mat = MatPolyOverZ::from_str("[[1 1, 0],[0, 1 1],[0, 0]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((id_mat, modulus));
assert!(poly_ring_mat.is_identity());Sourcepub fn is_square(&self) -> bool
pub fn is_square(&self) -> bool
Checks if a MatPolynomialRingZq is a square matrix.
Returns true if the number of rows and columns is identical.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, PolyOverZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = PolyOverZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[1 13, 0],[2 1 1, 1 1]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((poly_mat, modulus));
assert!(poly_ring_mat.is_square());Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Checks if every entry of a MatPolynomialRingZq is 0.
Returns true if every entry is 0.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, PolyOverZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = PolyOverZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::new(2,2);
let poly_ring_mat = MatPolynomialRingZq::from((poly_mat, modulus));
assert!(poly_ring_mat.is_zero());Sourcepub fn is_symmetric(&self) -> bool
pub fn is_symmetric(&self) -> bool
Checks if a MatPolynomialRingZq is symmetric.
Returns true if we have a_ij == a_ji for all i,j.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("2 2 1 mod 17").unwrap();
let value = MatPolynomialRingZq::identity(2,2, modulus);
assert!(value.is_symmetric());Sourcepub fn ntt(&self) -> MatNTTPolynomialRingZq
pub fn ntt(&self) -> MatNTTPolynomialRingZq
Returns the NTT representation of self.
§Examples
use qfall_math::integer_mod_q::{MatNTTPolynomialRingZq, MatPolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use crate::qfall_math::traits::SetCoefficient;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let mat_poly_ring = MatPolynomialRingZq::sample_uniform(2, 3, &polynomial_modulus);
let mat_ntt_poly_ring = mat_poly_ring.ntt();§Panics …
- if the
NTTBasisPolynomialRingZq, which is part of theModulusPolynomialRingZqinselfis not set.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn sample_binomial(
num_rows: impl TryInto<i64> + Display,
num_cols: impl TryInto<i64> + Display,
modulus: impl Into<ModulusPolynomialRingZq>,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial( num_rows: impl TryInto<i64> + Display, num_cols: impl TryInto<i64> + Display, modulus: impl Into<ModulusPolynomialRingZq>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Outputs a MatPolynomialRingZq instance with entries chosen according to the binomial
distribution parameterized by n and p.
Parameters:
num_rows: specifies the number of rows the new matrix should havenum_cols: specifies the number of columns the new matrix should havemodulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is definedn: specifies the number of trialsp: specifies the probability of success
Returns a new MatPolynomialRingZq instance with entries chosen
according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), n does not fit into an i64,
or the dimensions of the matrix were chosen too small.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let sample = MatPolynomialRingZq::sample_binomial(2, 2, &modulus, 2, 0.5).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifn < 0orp ∉ (0,1). - Returns a
MathErrorof typeConversionErrorifndoes not fit into ani64.
§Panics …
- if the provided number of rows and columns are not suited to create a matrix.
For further information see
MatPolynomialRingZq::new. - if the provided
ModulusPolynomialRingZqhas degree0or smaller.
Sourcepub fn sample_binomial_with_offset(
num_rows: impl TryInto<i64> + Display,
num_cols: impl TryInto<i64> + Display,
modulus: impl Into<ModulusPolynomialRingZq>,
offset: impl Into<Z>,
n: impl Into<Z>,
p: impl Into<Q>,
) -> Result<Self, MathError>
pub fn sample_binomial_with_offset( num_rows: impl TryInto<i64> + Display, num_cols: impl TryInto<i64> + Display, modulus: impl Into<ModulusPolynomialRingZq>, offset: impl Into<Z>, n: impl Into<Z>, p: impl Into<Q>, ) -> Result<Self, MathError>
Outputs a MatPolynomialRingZq instance with entries chosen according to the binomial
distribution parameterized by n and p with given offset.
Parameters:
num_rows: specifies the number of rows the new matrix should havenum_cols: specifies the number of columns the new matrix should havemodulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is definedoffset: specifies an offset applied to each sample collected from the binomial distributionn: specifies the number of trialsp: specifies the probability of success
Returns a new MatPolynomialRingZq instance with entries chosen
according to the binomial distribution or a MathError
if n < 0, p ∉ (0,1), n does not fit into an i64,
or the dimensions of the matrix were chosen too small.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let sample = MatPolynomialRingZq::sample_binomial_with_offset(2, 2, &modulus, -1, 2, 0.5).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifn < 0orp ∉ (0,1). - Returns a
MathErrorof typeConversionErrorifndoes not fit into ani64.
§Panics …
- if the provided number of rows and columns are not suited to create a matrix.
For further information see
MatPolynomialRingZq::new. - if the provided
ModulusPolynomialRingZqhas degree0.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn sample_discrete_gauss(
num_rows: impl TryInto<i64> + Display,
num_cols: impl TryInto<i64> + Display,
modulus: impl Into<ModulusPolynomialRingZq>,
center: impl Into<Q>,
s: impl Into<Q>,
) -> Result<MatPolynomialRingZq, MathError>
pub fn sample_discrete_gauss( num_rows: impl TryInto<i64> + Display, num_cols: impl TryInto<i64> + Display, modulus: impl Into<ModulusPolynomialRingZq>, center: impl Into<Q>, s: impl Into<Q>, ) -> Result<MatPolynomialRingZq, MathError>
Initializes a new matrix with dimensions num_rows x num_columns and with each entry
sampled independently according to the discrete Gaussian distribution,
using PolynomialRingZq::sample_discrete_gauss.
Parameters:
num_rows: specifies the number of rows the new matrix should havenum_cols: specifies the number of columns the new matrix should havemodulus: specifies the Modulus for the matrix and the maximum degree any discrete Gaussian polynomial can haven: specifies the range from whichZ::sample_discrete_gausssamplescenter: specifies the positions of the center with peak probabilitys: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = s
Returns a MatPolynomialRingZq with each entry sampled independently from the
specified discrete Gaussian distribution or an error if s < 0.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap();
let matrix = MatPolynomialRingZq::sample_discrete_gauss(3, 1, &modulus, 0, 1.25f32).unwrap();§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputifs < 0.
§Panics …
- if the provided number of rows and columns are not suited to create a matrix.
For further information see
MatPolynomialRingZq::new. - if
modulusis not a valid choice for aModulusPolynomialRingZq, seeModulusPolynomialRingZq::fromfor further information.
Sourcepub fn sample_d(
basis: &Self,
k: impl Into<i64>,
center: &[PolyOverQ],
s: impl Into<Q>,
) -> Result<MatPolynomialRingZq, MathError>
pub fn sample_d( basis: &Self, k: impl Into<i64>, center: &[PolyOverQ], s: impl Into<Q>, ) -> Result<MatPolynomialRingZq, MathError>
SampleD samples a discrete Gaussian from the lattice with a provided basis.
We do not check whether basis is actually a basis. Hence, the callee is
responsible for making sure that basis provides a suitable basis.
Parameters:
basis: specifies a basis for the lattice from which is sampledk: the maximal length the polynomial can haven: specifies the range from whichZ::sample_discrete_gausssamplescenter: specifies the positions of the center with peak probabilitys: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = s
Returns a vector of polynomials sampled according to the
discrete Gaussian distribution or an error if the basis is not a row vector,
s < 0, or the number of rows of the basis and center differ.
§Example
use qfall_math::{
integer::{MatPolyOverZ, Z},
integer_mod_q::{
MatPolynomialRingZq,
ModulusPolynomialRingZq,
},
rational::{PolyOverQ, Q},
};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[1 1, 3 0 0 1, 2 0 1]]").unwrap();
let basis = MatPolynomialRingZq::from((&poly_mat, &modulus));
let center = vec![PolyOverQ::default()];
let s = Q::from(8);
let sample = MatPolynomialRingZq::sample_d(&basis, 3, ¢er, s);§Errors and Failures
- Returns a
MathErrorof typeVectorFunctionCalledOnNonVector, if the basis is not a row vector - Returns a
MathErrorof typeInvalidIntegerInputifs < 0. - Returns a
MathErrorof typeMismatchingMatrixDimensionif the number of rows of thebasisandcenterdiffer.
This function implements SampleD 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
§Panics …
- if the polynomials have higher length than the provided upper bound
k
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn sample_uniform(
num_rows: impl TryInto<i64> + Display,
num_cols: impl TryInto<i64> + Display,
modulus: impl Into<ModulusPolynomialRingZq>,
) -> Self
pub fn sample_uniform( num_rows: impl TryInto<i64> + Display, num_cols: impl TryInto<i64> + Display, modulus: impl Into<ModulusPolynomialRingZq>, ) -> Self
Outputs a MatPolynomialRingZq instance with polynomials as entries,
whose coefficients were chosen uniform at random in [0, modulus.get_q()).
The internally used uniform at random chosen bytes are generated
by ThreadRng, which uses ChaCha12 and
is considered cryptographically secure.
Parameters:
num_rows: specifies the number of rows the new matrix should havenum_cols: specifies the number of columns the new matrix should havemodulus: specifies theModulusPolynomialRingZqover which the ring of polynomials modulomodulus.get_q()is defined
Returns a fresh MatPolynomialRingZq instance of length modulus.get_degree() - 1
with coefficients chosen uniform at random in [0, modulus.get_q()).
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let matrix = MatPolynomialRingZq::sample_uniform(2, 2, &modulus);§Panics …
- if the provided number of rows and columns are not suited to create a matrix.
For further information see
MatPolynomialRingZq::new. - if the provided
ModulusPolynomialRingZqhas degree0.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn reverse_columns(&mut self)
pub fn reverse_columns(&mut self)
Swaps the i-th column with the n-i-th column for all i <= n/2
of the specified matrix with n columns.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut matrix = MatPolynomialRingZq::new(4, 3, ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap());
matrix.reverse_columns();Sourcepub fn reverse_rows(&mut self)
pub fn reverse_rows(&mut self)
Swaps the i-th row with the n-i-th row for all i <= n/2
of the specified matrix with n rows.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut matrix = MatPolynomialRingZq::new(4, 3, ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap());
matrix.reverse_rows();Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn sort_by_column<T: Ord>(
&self,
cond_func: fn(&Self) -> Result<T, MathError>,
) -> Result<Self, MathError>
pub fn sort_by_column<T: Ord>( &self, cond_func: fn(&Self) -> Result<T, MathError>, ) -> Result<Self, MathError>
Sorts the columns of the matrix based on some condition defined by cond_func in an ascending order.
This condition is usually a norm with the described input-output behaviour.
Parameters:
cond_func: computes values implementingOrdover the columns of the specified matrix. These values are then used to re-order / sort the rows of the matrix.
Returns an empty Ok if the action could be performed successfully.
A MathError is returned if the execution of cond_func returned an error.
§Examples
§Use a build-in function as condition
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let mat = MatPolynomialRingZq::from_str("[[2 3 4, 1 2, 1 1]] / 3 1 2 3 mod 17").unwrap();
let cmp = MatPolynomialRingZq::from_str("[[1 1, 1 2, 2 3 4]] / 3 1 2 3 mod 17").unwrap();
let sorted = mat.sort_by_column(MatPolynomialRingZq::norm_eucl_sqrd).unwrap();
assert_eq!(cmp, sorted);§Use a custom function as condition
This function needs to take a column vector as input and output a type implementing PartialOrd
use qfall_math::{integer_mod_q::MatPolynomialRingZq, integer::{PolyOverZ, Z}, error::MathError, traits::{MatrixDimensions, MatrixGetEntry}};
use crate::qfall_math::traits::GetCoefficient;
use std::str::FromStr;
let mat = MatPolynomialRingZq::from_str("[[2 0 4, 1 2, 1 1]] / 3 1 2 3 mod 17").unwrap();
let cmp = MatPolynomialRingZq::from_str("[[2 0 4, 1 1, 1 2]] / 3 1 2 3 mod 17").unwrap();
fn custom_cond_func(matrix: &MatPolynomialRingZq) -> Result<Z, MathError> {
let mut sum = Z::ZERO;
for entry in matrix.get_entries_rowwise() {
sum += PolyOverZ::get_coeff(&entry, 0)?;
}
Ok(sum)
}
let sorted = mat.sort_by_column(custom_cond_func).unwrap();
assert_eq!(cmp, sorted);§Errors and Failures
- Returns a
MathErrorof the same type ascond_funcif the execution ofcond_funcfails.
Sourcepub fn sort_by_row<T: Ord>(
&self,
cond_func: fn(&Self) -> Result<T, MathError>,
) -> Result<Self, MathError>
pub fn sort_by_row<T: Ord>( &self, cond_func: fn(&Self) -> Result<T, MathError>, ) -> Result<Self, MathError>
Sorts the rows of the matrix based on some condition defined by cond_func in an ascending order.
This condition is usually a norm with the described input-output behaviour.
Parameters:
cond_func: computes values implementingOrdover the columns of the specified matrix. These values are then used to re-order / sort the columns of the matrix.
Returns an empty Ok if the action could be performed successfully.
A MathError is returned if the execution of cond_func returned an error.
§Examples
§Use a build-in function as condition
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let mat = MatPolynomialRingZq::from_str("[[2 3 4],[1 2],[1 1]] / 3 1 2 3 mod 17").unwrap();
let cmp = MatPolynomialRingZq::from_str("[[1 1],[1 2],[2 3 4]] / 3 1 2 3 mod 17").unwrap();
let sorted = mat.sort_by_row(MatPolynomialRingZq::norm_infty).unwrap();
assert_eq!(cmp, sorted);§Use a custom function as condition
This function needs to take a row vector as input and output a type implementing PartialOrd
use qfall_math::{integer_mod_q::MatPolynomialRingZq, integer::{PolyOverZ, Z}, error::MathError, traits::{MatrixDimensions, MatrixGetEntry}};
use crate::qfall_math::traits::GetCoefficient;
use std::str::FromStr;
let mat = MatPolynomialRingZq::from_str("[[2 0 4],[1 2],[1 1]] / 3 1 2 3 mod 17").unwrap();
let cmp = MatPolynomialRingZq::from_str("[[2 0 4],[1 1],[1 2]] / 3 1 2 3 mod 17").unwrap();
fn custom_cond_func(matrix: &MatPolynomialRingZq) -> Result<Z, MathError> {
let mut sum = Z::ZERO;
for entry in matrix.get_entries_columnwise() {
sum += PolyOverZ::get_coeff(&entry, 0)?;
}
Ok(sum)
}
let sorted = mat.sort_by_row(custom_cond_func).unwrap();
assert_eq!(cmp, sorted);§Errors and Failures
- Returns a
MathErrorof the same type ascond_funcif the execution ofcond_funcfails.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn tensor_product_safe(&self, other: &Self) -> Result<Self, MathError>
pub fn tensor_product_safe(&self, other: &Self) -> Result<Self, MathError>
Computes the tensor product of self with other.
Parameters:
other: the value with which the tensor product is computed.
Returns the tensor product of self with other or an error if the
moduli of the provided matrices mismatch.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[1 1, 2 1 1]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolynomialRingZq::from_str("[[1 1, 1 2]] / 3 1 2 3 mod 17").unwrap();
let mat_ab = mat_1.tensor_product_safe(&mat_2).unwrap();
let mat_ba = mat_2.tensor_product_safe(&mat_1).unwrap();
let res_ab = "[[1 1, 1 2, 2 1 1, 2 2 2]] / 3 1 2 3 mod 17";
let res_ba = "[[1 1, 2 1 1, 1 2, 2 2 2]] / 3 1 2 3 mod 17";
assert_eq!(mat_ab, MatPolynomialRingZq::from_str(res_ab).unwrap());
assert_eq!(mat_ba, MatPolynomialRingZq::from_str(res_ba).unwrap());§Errors and Failures
- Returns a
MathErrorof typeMismatchingModulusif the moduli of the provided matrices mismatch.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn pretty_string(
&self,
nr_printed_rows: u64,
nr_printed_columns: u64,
) -> String
pub fn pretty_string( &self, nr_printed_rows: u64, nr_printed_columns: u64, ) -> String
Outputs the matrix as a String, where the upper leftmost nr_printed_rows x nr_printed_columns
submatrix is output entirely as well as the corresponding entries in the last column and row of the matrix.
Parameters:
nr_printed_rows: defines the number of rows of the upper leftmost matrix that are printed entirelynr_printed_columns: defines the number of columns of the upper leftmost matrix that are printed entirely
Returns a String representing the abbreviated matrix.
§Example
use qfall_math::integer::MatZ;
let matrix = MatZ::identity(10, 10);
println!("Matrix: {}", matrix.pretty_string(2, 2));
// outputs the following:
// Matrix: [
// [1, 0, , ..., 0],
// [0, 1, , ..., 0],
// [...],
// [0, 0, , ..., 1]
// ]Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn transpose(&self) -> Self
pub fn transpose(&self) -> Self
Returns the transposed form of the given matrix, i.e. rows get transformed to columns and vice versa.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[1 42],[2 1 2],[1 17]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let transpose = poly_ring_mat.transpose();Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub unsafe fn get_fmpz_poly_mat_struct(&mut self) -> &mut fmpz_poly_mat_struct
pub unsafe fn get_fmpz_poly_mat_struct(&mut self) -> &mut fmpz_poly_mat_struct
Returns a mutable reference to the underlying fmpz_poly_mat_struct by calling get_fmpz_poly_mat_struct on matrix.
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 MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub unsafe fn get_fq_ctx_struct(&mut self) -> &mut fq_ctx_struct
pub unsafe fn get_fq_ctx_struct(&mut self) -> &mut fq_ctx_struct
Returns a mutable reference to the underlying fq_ctx_struct by calling get_fq_ctx_struct 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 MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub unsafe fn set_fmpz_poly_mat_struct(
&mut self,
flint_struct: fmpz_poly_mat_struct,
)
pub unsafe fn set_fmpz_poly_mat_struct( &mut self, flint_struct: fmpz_poly_mat_struct, )
Sets the field fmpz_poly_mat_struct to flint_struct by calling set_fmpz_poly_mat_struct on matrix.
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 MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub unsafe fn set_fq_ctx_struct(&mut self, flint_struct: fq_ctx_struct)
pub unsafe fn set_fq_ctx_struct(&mut self, flint_struct: fq_ctx_struct)
Sets the field fq_ctx_struct to flint_struct by calling set_fq_ctx_struct 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.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn dot_product(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
pub fn dot_product(&self, other: &Self) -> Result<PolynomialRingZq, MathError>
Returns the dot product of two vectors of type MatPolynomialRingZq.
Note that the dimensions of the two vectors are irrelevant for the dot product.
Parameters:
other: specifies the other vector the dot product is calculated over
Returns the resulting dot_product as a PolynomialRingZq or an error
if the given MatPolynomialRingZq instances aren’t vectors or have different
numbers of entries.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_vec_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1],[2 1 2]]").unwrap();
let poly_ring_vec_1 = MatPolynomialRingZq::from((&poly_vec_1, &modulus));
let poly_vec_2 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42]]").unwrap();
let poly_ring_vec_2 = MatPolynomialRingZq::from((&poly_vec_2, &modulus));
let dot_prod = poly_ring_vec_1.dot_product(&poly_ring_vec_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::VectorFunctionCalledOnNonVectorif the givenMatPolynomialRingZqinstance is not a (row or column) vector. - Returns a
MathErrorof typeMathError::MismatchingMatrixDimensionif the given vectors have different lengths.
Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn is_row_vector(&self) -> bool
pub fn is_row_vector(&self) -> bool
Returns true if the provided MatPolynomialRingZq has only one row,
i.e. is a row vector. Otherwise, returns false.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42]]").unwrap();
let poly_mat_2 = MatPolyOverZ::from_str("[[4 -1 0 1 1],[2 1 2]]").unwrap();
let row_vec = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let col_vec = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
assert!(row_vec.is_row_vector());
assert!(!col_vec.is_row_vector());Sourcepub fn is_column_vector(&self) -> bool
pub fn is_column_vector(&self) -> bool
Returns true if the provided MatPolynomialRingZq has only one column,
i.e. is a column vector. Otherwise, returns false.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42]]").unwrap();
let poly_mat_2 = MatPolyOverZ::from_str("[[4 -1 0 1 1],[2 1 2]]").unwrap();
let row_vec = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let col_vec = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
assert!(col_vec.is_column_vector());
assert!(!row_vec.is_column_vector());Sourcepub fn is_vector(&self) -> bool
pub fn is_vector(&self) -> bool
Returns true if the provided MatPolynomialRingZq has only one column or one row,
i.e. is a vector. Otherwise, returns false.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42]]").unwrap();
let poly_mat_2 = MatPolyOverZ::from_str("[[4 -1 0 1 1],[2 1 2]]").unwrap();
let row_vec = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let col_vec = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
assert!(row_vec.is_vector());
assert!(col_vec.is_vector());Sourcepub fn has_single_entry(&self) -> bool
pub fn has_single_entry(&self) -> bool
Returns true if the provided MatPolynomialRingZq has only one entry,
i.e. is a 1x1 matrix. Otherwise, returns false.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[1 42]]").unwrap();
let vec = MatPolynomialRingZq::from((&poly_mat, &modulus));
assert!(vec.has_single_entry());Source§impl MatPolynomialRingZq
impl MatPolynomialRingZq
Sourcepub fn norm_eucl_sqrd(&self) -> Result<Z, MathError>
pub fn norm_eucl_sqrd(&self) -> Result<Z, MathError>
Returns the squared Euclidean norm or 2-norm of the given (row or column) vector
or an error if the given MatPolynomialRingZq instance is not a (row or column) vector.
The squared Euclidean norm for a polynomial vector is obtained by
computing the sum of the squared Euclidean norms of the individual polynomials.
The squared Euclidean norm for a polynomial is obtained by treating the coefficients
of the polynomial as a vector and then applying the standard squared Euclidean norm.
Each length of an entry in this vector is defined as the shortest distance to the next zero representative modulo q.
§Examples
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let vec = MatPolynomialRingZq::from_str("[[1 1],[2 2 2],[1 3]] / 3 1 2 3 mod 11").unwrap();
let sqrd_2_norm = vec.norm_eucl_sqrd().unwrap();
assert_eq!(Z::from(18), sqrd_2_norm);§Errors and Failures
- Returns a
MathErrorof typeMathError::VectorFunctionCalledOnNonVectorif the givenMatPolynomialRingZqinstance is not a (row or column) vector.
Sourcepub fn norm_eucl(&self) -> Result<Q, MathError>
pub fn norm_eucl(&self) -> Result<Q, MathError>
Returns the Euclidean norm or 2-norm of the given (row or column) vector
or an error if the given MatPolynomialRingZq instance is not a (row or column) vector.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let vec = MatPolynomialRingZq::from_str("[[1 2],[2 2 2],[1 2]] / 3 1 2 3 mod 11").unwrap();
let sqrd_2_norm = vec.norm_eucl().unwrap();
assert_eq!(4, sqrd_2_norm);§Errors and Failures
- Returns a
MathErrorof typeMathError::VectorFunctionCalledOnNonVectorif the givenMatPolynomialRingZqinstance is not a (row or column) vector.
Sourcepub fn norm_infty(&self) -> Result<Z, MathError>
pub fn norm_infty(&self) -> Result<Z, MathError>
Returns the infinity norm or ∞-norm of the given (row or column) vector
or an error if the given MatPolynomialRingZq instance is not a (row or column) vector.
The infinity norm for a polynomial vector is obtained by computing the
infinity norm on the vector consisting of the infinity norms of the individual polynomials.
The infinity norm for a polynomial is obtained by treating the coefficients
of the polynomial as a vector and then applying the standard infinity norm.
Each length of an entry in this vector is defined as the shortest distance to the next zero representative modulo q.
§Examples
use qfall_math::integer::Z;
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let vec = MatPolynomialRingZq::from_str("[[1 1],[2 2 4],[1 3]] / 3 1 2 3 mod 11").unwrap();
let infty_norm = vec.norm_infty().unwrap();
assert_eq!(Z::from(4), infty_norm);§Errors and Failures
- Returns a
MathErrorof typeMathError::VectorFunctionCalledOnNonVectorif the givenMatPolynomialRingZqinstance is not a (row or column) vector.
Trait Implementations§
Source§impl Add<&MatPolyOverZ> for &MatPolynomialRingZq
impl Add<&MatPolyOverZ> for &MatPolynomialRingZq
Source§fn add(self, other: &MatPolyOverZ) -> Self::Output
fn add(self, other: &MatPolyOverZ) -> Self::Output
Implements the Add trait for a MatPolynomialRingZq matrix with a MatPolyOverZ matrix.
Add is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the value to add withself
Returns the addition of self and other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_3 = &mat_1 + &mat_2;§Panics …
- if the dimensions of
selfandotherdo not match for multiplication.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
+ operator.Source§impl Add for &MatPolynomialRingZq
impl Add for &MatPolynomialRingZq
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Implements the Add trait for two MatPolynomialRingZq values.
Add is implemented for any combination of MatPolynomialRingZq and borrowed MatPolynomialRingZq.
Parameters:
other: specifies the polynomial to add toself
Returns the sum of both polynomials as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat_1 = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let poly_mat_2 = MatPolyOverZ::from_str("[[3 3 0 1, 1 42],[0, 1 17]]").unwrap();
let poly_ring_mat_2 = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
let poly_ring_mat_3: MatPolynomialRingZq = &poly_ring_mat_1 + &poly_ring_mat_2;
let poly_ring_mat_4: MatPolynomialRingZq = poly_ring_mat_1 + poly_ring_mat_2;
let poly_ring_mat_5: MatPolynomialRingZq = &poly_ring_mat_3 + poly_ring_mat_4;
let poly_ring_mat_6: MatPolynomialRingZq = poly_ring_mat_3 + &poly_ring_mat_5;§Panics …
- if the moduli of both
MatPolynomialRingZqmismatch. - if the dimensions of both
MatPolynomialRingZqmismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
+ operator.Source§impl AddAssign<&MatPolyOverZ> for MatPolynomialRingZq
impl AddAssign<&MatPolyOverZ> for MatPolynomialRingZq
Source§fn add_assign(&mut self, other: &MatPolyOverZ)
fn add_assign(&mut self, other: &MatPolyOverZ)
Documentation at MatPolynomialRingZq::add_assign.
Source§impl AddAssign<&MatPolynomialRingZq> for MatPolynomialRingZq
impl AddAssign<&MatPolynomialRingZq> for MatPolynomialRingZq
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 MatPolynomialRingZq in combination with
MatPolynomialRingZq and MatPolyOverZ.
Parameters:
other: specifies the value to add toself
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 0 1 mod 7").unwrap();
let mut a = MatPolynomialRingZq::identity(2, 2, &modulus);
let b = MatPolynomialRingZq::new(2, 2, &modulus);
let c = MatPolyOverZ::new(2, 2);
a += &b;
a += b;
a += &c;
a += c;§Panics …
- if the matrix dimensions mismatch.
- if the moduli of the matrices mismatch.
Source§impl AddAssign<MatPolyOverZ> for MatPolynomialRingZq
impl AddAssign<MatPolyOverZ> for MatPolynomialRingZq
Source§fn add_assign(&mut self, other: MatPolyOverZ)
fn add_assign(&mut self, other: MatPolyOverZ)
Documentation at MatPolynomialRingZq::add_assign.
Source§impl AddAssign for MatPolynomialRingZq
impl AddAssign for MatPolynomialRingZq
Source§fn add_assign(&mut self, other: MatPolynomialRingZq)
fn add_assign(&mut self, other: MatPolynomialRingZq)
Documentation at MatPolynomialRingZq::add_assign.
Source§impl Clone for MatPolynomialRingZq
impl Clone for MatPolynomialRingZq
Source§fn clone(&self) -> MatPolynomialRingZq
fn clone(&self) -> MatPolynomialRingZq
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CompareBase<&MatPolyOverZ> for MatPolynomialRingZq
impl CompareBase<&MatPolyOverZ> for MatPolynomialRingZq
Source§impl CompareBase<&MatPolynomialRingZq> for MatNTTPolynomialRingZq
impl CompareBase<&MatPolynomialRingZq> for MatNTTPolynomialRingZq
Source§fn compare_base(&self, other: &&MatPolynomialRingZq) -> bool
fn compare_base(&self, other: &&MatPolynomialRingZq) -> 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: &&MatPolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&MatPolynomialRingZq, ) -> 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<&MatPolynomialRingZq> for MatPolynomialRingZq
impl CompareBase<&MatPolynomialRingZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &&MatPolynomialRingZq) -> bool
fn compare_base(&self, other: &&MatPolynomialRingZq) -> 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: &&MatPolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&MatPolynomialRingZq, ) -> 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<&MatZ> for MatPolynomialRingZq
impl CompareBase<&MatZ> for MatPolynomialRingZq
Source§impl CompareBase<&MatZq> for MatPolynomialRingZq
impl CompareBase<&MatZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &&MatZq) -> bool
fn compare_base(&self, other: &&MatZq) -> 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: &&MatZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&MatZq) -> 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<&PolyOverZ> for MatPolynomialRingZq
impl CompareBase<&PolyOverZ> for MatPolynomialRingZq
Source§impl CompareBase<&PolyOverZq> for MatPolynomialRingZq
impl CompareBase<&PolyOverZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &&PolyOverZq) -> bool
fn compare_base(&self, other: &&PolyOverZq) -> 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: &&PolyOverZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&PolyOverZq) -> 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<&PolynomialRingZq> for MatPolynomialRingZq
impl CompareBase<&PolynomialRingZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &&PolynomialRingZq) -> bool
fn compare_base(&self, other: &&PolynomialRingZq) -> 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: &&PolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> 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<Integer: Into<Z>> CompareBase<Integer> for MatPolynomialRingZq
impl<Integer: Into<Z>> CompareBase<Integer> for MatPolynomialRingZq
Source§impl CompareBase<MatPolyOverZ> for MatPolynomialRingZq
impl CompareBase<MatPolyOverZ> for MatPolynomialRingZq
Source§impl CompareBase<MatPolynomialRingZq> for MatNTTPolynomialRingZq
impl CompareBase<MatPolynomialRingZq> for MatNTTPolynomialRingZq
Source§fn compare_base(&self, other: &MatPolynomialRingZq) -> bool
fn compare_base(&self, other: &MatPolynomialRingZq) -> 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: &MatPolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &MatPolynomialRingZq, ) -> 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<MatZ> for MatPolynomialRingZq
impl CompareBase<MatZ> for MatPolynomialRingZq
Source§impl CompareBase<MatZq> for MatPolynomialRingZq
impl CompareBase<MatZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &MatZq) -> bool
fn compare_base(&self, other: &MatZq) -> 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: &MatZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &MatZq) -> 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<PolyOverZ> for MatPolynomialRingZq
impl CompareBase<PolyOverZ> for MatPolynomialRingZq
Source§impl CompareBase<PolyOverZq> for MatPolynomialRingZq
impl CompareBase<PolyOverZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &PolyOverZq) -> bool
fn compare_base(&self, other: &PolyOverZq) -> 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: &PolyOverZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolyOverZq) -> 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<PolynomialRingZq> for MatPolynomialRingZq
impl CompareBase<PolynomialRingZq> for MatPolynomialRingZq
Source§fn compare_base(&self, other: &PolynomialRingZq) -> bool
fn compare_base(&self, other: &PolynomialRingZq) -> 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: &PolynomialRingZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolynomialRingZq) -> 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 for MatPolynomialRingZq
impl CompareBase for MatPolynomialRingZq
Source§fn compare_base(&self, other: &MatPolynomialRingZq) -> bool
fn compare_base(&self, other: &MatPolynomialRingZq) -> 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: &MatPolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &MatPolynomialRingZq, ) -> 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 Concatenate for &MatPolynomialRingZq
impl Concatenate for &MatPolynomialRingZq
Source§fn concat_vertical(self, other: Self) -> Result<Self::Output, MathError>
fn concat_vertical(self, other: Self) -> Result<Self::Output, MathError>
Concatenates self with other vertically, i.e. other is added below.
Parameters:
other: the other matrix to concatenate withself
Returns a vertical concatenation of the two matrices or a an error, if the matrices can not be concatenated vertically.
§Examples
use crate::qfall_math::traits::*;
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus_str = "3 1 0 1 mod 17";
let modulus = ModulusPolynomialRingZq::from_str(modulus_str).unwrap();
let mat_1 = MatPolynomialRingZq::new(13, 5, &modulus);
let mat_2 = MatPolynomialRingZq::new(17, 5, &modulus);
let mat_vert = mat_1.concat_vertical(&mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMismatchingMatrixDimensionif the matrices can not be concatenated due to mismatching dimensions. - Returns a
MathErrorof typeMismatchingModulusif the matrices can not be concatenated due to mismatching moduli.
Source§fn concat_horizontal(self, other: Self) -> Result<Self::Output, MathError>
fn concat_horizontal(self, other: Self) -> Result<Self::Output, MathError>
Concatenates self with other horizontally, i.e. other is added on the right.
Parameters:
other: the other matrix to concatenate withself
Returns a horizontal concatenation of the two matrices or a an error, if the matrices can not be concatenated horizontally.
§Examples
use crate::qfall_math::traits::*;
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus_str = "3 1 17 1 mod 17";
let modulus = ModulusPolynomialRingZq::from_str(&modulus_str).unwrap();
let mat_1 = MatPolynomialRingZq::new(17, 5, &modulus);
let mat_2 = MatPolynomialRingZq::new(17, 7, &modulus);
let mat_vert = mat_1.concat_horizontal(&mat_2).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMismatchingMatrixDimensionif the matrices can not be concatenated due to mismatching dimensions. - Returns a
MathErrorof typeMismatchingModulusif the matrices can not be concatenated due to mismatching moduli.
type Output = MatPolynomialRingZq
Source§impl Debug for MatPolynomialRingZq
impl Debug for MatPolynomialRingZq
Source§impl<'de> Deserialize<'de> for MatPolynomialRingZq
impl<'de> Deserialize<'de> for MatPolynomialRingZq
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 MatPolynomialRingZq
impl Display for MatPolynomialRingZq
Source§impl From<&MatPolynomialRingZq> for MatNTTPolynomialRingZq
impl From<&MatPolynomialRingZq> for MatNTTPolynomialRingZq
Source§fn from(matrix: &MatPolynomialRingZq) -> Self
fn from(matrix: &MatPolynomialRingZq) -> Self
Computes the NTT representation of matrix.
Parameters:
matrix: the matrix that’s going to be represented in NTT format.
Returns the NTT representation as a MatNTTPolynomialRingZq of matrix.
§Examples
use qfall_math::integer_mod_q::{MatNTTPolynomialRingZq, MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let mat_poly_ring = MatPolynomialRingZq::sample_uniform(2, 3, &modulus);
let mat_ntt_poly_ring = MatNTTPolynomialRingZq::from(&mat_poly_ring);§Panics …
- if the
NTTBasisPolynomialRingZq, which is part of theModulusPolynomialRingZqinmatrixis not set.
Source§impl From<&MatPolynomialRingZq> for MatPolynomialRingZq
impl From<&MatPolynomialRingZq> for MatPolynomialRingZq
Source§fn from(value: &MatPolynomialRingZq) -> Self
fn from(value: &MatPolynomialRingZq) -> Self
Alias for MatPolynomialRingZq::clone.
Source§impl From<&MatPolynomialRingZq> for String
impl From<&MatPolynomialRingZq> for String
Source§fn from(value: &MatPolynomialRingZq) -> Self
fn from(value: &MatPolynomialRingZq) -> Self
Converts a MatPolynomialRingZq into its String representation.
Parameters:
value: specifies the matrix that will be represented as aString
Returns a String of the form "[[poly_1, poly_2, poly_3],[poly_4, poly_5, poly_6]] / poly_7 mod q".
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let matrix = MatPolynomialRingZq::from_str("[[2 2 2, 1 2],[0, 1 3]] / 2 4 4 mod 3").unwrap();
let string: String = matrix.into();Source§impl<Matrix: Into<MatPolyOverZ>, Mod: Into<ModulusPolynomialRingZq>> From<(Matrix, Mod)> for MatPolynomialRingZq
impl<Matrix: Into<MatPolyOverZ>, Mod: Into<ModulusPolynomialRingZq>> From<(Matrix, Mod)> for MatPolynomialRingZq
Source§fn from((matrix, modulus): (Matrix, Mod)) -> Self
fn from((matrix, modulus): (Matrix, Mod)) -> Self
Creates a polynomial ring matrix of type MatPolynomialRingZq from
a value that implements Into<MatPolyOverZ> and a value that
implements Into<ModulusPolynomialRingZq>.
Parameters:
matrix: the polynomial matrix defining each entry.modulus: the modulus that is applied to each polynomial.
Returns a new MatPolynomialRingZq with the entries from matrix
under the modulus modulus.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((poly_mat, modulus));Source§impl From<MatNTTPolynomialRingZq> for MatPolynomialRingZq
impl From<MatNTTPolynomialRingZq> for MatPolynomialRingZq
Source§fn from(matrix: MatNTTPolynomialRingZq) -> Self
fn from(matrix: MatNTTPolynomialRingZq) -> Self
Creates a polynomial ring matrix of type MatPolynomialRingZq from
the corresponding MatNTTPolynomialRingZq.
Parameters:
matrix: the polynomial matrix defining each entry.
Returns a new MatPolynomialRingZq with the entries from matrix.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, MatNTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let ntt_mat = MatNTTPolynomialRingZq::sample_uniform(1, 1, &modulus);
let poly_ring_mat = MatPolynomialRingZq::from(ntt_mat);§Panics …
- if the
NTTBasisPolynomialRingZqinmodulusis not set.
Source§impl From<MatPolynomialRingZq> for String
impl From<MatPolynomialRingZq> for String
Source§fn from(value: MatPolynomialRingZq) -> Self
fn from(value: MatPolynomialRingZq) -> Self
Documentation can be found at String::from for &MatPolynomialRingZq.
Source§impl FromCoefficientEmbedding<(&MatZq, &ModulusPolynomialRingZq, i64)> for MatPolynomialRingZq
impl FromCoefficientEmbedding<(&MatZq, &ModulusPolynomialRingZq, i64)> for MatPolynomialRingZq
Source§fn from_coefficient_embedding(
embedding: (&MatZq, &ModulusPolynomialRingZq, i64),
) -> Self
fn from_coefficient_embedding( embedding: (&MatZq, &ModulusPolynomialRingZq, i64), ) -> Self
Computes a MatPolynomialRingZq from a coefficient embedding.
Interprets the first degree + 1 many rows of the matrix as the
coefficients of the first row of polynomials. The first one containing
their coefficients of degree 0, and the last one their coefficients
of degree degree. It inverts the operation of
MatPolynomialRingZq::into_coefficient_embedding.
Parameters:
embedding: the coefficient matrix, the modulus, and the maximal degree of the polynomials (defines how the matrix is split)
Returns a row vector of polynomials that corresponds to the embedding.
§Examples
use std::str::FromStr;
use qfall_math::{
integer_mod_q::{MatZq, MatPolynomialRingZq, ModulusPolynomialRingZq},
traits::FromCoefficientEmbedding,
};
let matrix = MatZq::from_str("[[17, 1],[3, 2],[-5, 3],[1, 2]] mod 19").unwrap();
let modulus = ModulusPolynomialRingZq::from_str("4 1 2 3 4 mod 19").unwrap();
let mat = MatPolynomialRingZq::from_coefficient_embedding((&matrix, &modulus, 1));
let cmp_mat = MatPolynomialRingZq::from_str("[[2 17 3, 2 1 2],[2 -5 1, 2 3 2]] / 4 1 2 3 4 mod 19").unwrap();
assert_eq!(cmp_mat, mat);§Panics …
- if
degree+1 does not divide the number of rows of the embedding. - if the moduli mismatch.
Source§impl FromStr for MatPolynomialRingZq
impl FromStr for MatPolynomialRingZq
Source§fn from_str(string: &str) -> Result<Self, MathError>
fn from_str(string: &str) -> Result<Self, MathError>
Creates a MatPolynomialRingZq matrix from a String.
Warning: Each entry is parsed as a PolyOverZ object.
If an entry string starts with a correctly formatted PolyOverZ object,
the rest of this entry string is ignored. This means that the entry input
string "4 0 1 2 3" is the same as "4 0 1 2 3 4 5 6 7".
Parameters:
string: the matrix of form:"[[poly_1, poly_2, poly_3],[poly_4, poly_5, poly_6]] / poly_7 mod 11"for a 2x3 matrix where the first three polynomials are in the first row, the second three are in the second row, and the seventh polynomial and 11 form the modulus.
Note that the strings for entries, the polynomial modulus and the integer modulus are trimmed, i.e. all whitespaces around all values are ignored.
Returns a MatPolynomialRingZq or an error if the matrix is not formatted in a suitable way,
the number of rows or columns is too large (must fit into i64),
the number of entries in rows is unequal, or if an entry is not formatted correctly.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let matrix = MatPolynomialRingZq::from_str("[[2 2 2, 1 2],[0, 1 3]] / 2 3 3 mod 24").unwrap();use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let str_1 = "[[2 2 2, 1 2],[0, 1 3]] / 2 3 3 mod 24";
let matrix = MatPolynomialRingZq::from_str(str_1).unwrap();use qfall_math::integer_mod_q::MatPolynomialRingZq;
use std::str::FromStr;
let string = String::from("[[2 2 2, 1 2],[0, 1 3]] / 2 3 3 mod 24");
let matrix = MatPolynomialRingZq::from_str(&string).unwrap();§Errors and Failures
- Returns a
MathErrorof typeMathError::StringConversionError,- if the matrix is not formatted in a suitable way,
- if the number of rows or columns is too large (must fit into i64),
- if the number of entries in rows is unequal,
- if the delimiter
/andmodcould not be found, - if the modulus is not formatted correctly,
for further information see
PolyOverZq::from_str, or - if an entry is not formatted correctly.
For further information see
PolyOverZ::from_str.
- Returns a MathError of type InvalidModulus
- if modulus is smaller than 2, or
- if the modulus polynomial is 0.
§Panics …
- if the provided number of rows and columns are not suited to create a matrix.
For further information see
MatPolyOverZ::new.
Source§impl IntoCoefficientEmbedding<(MatZq, ModulusPolynomialRingZq)> for &MatPolynomialRingZq
impl IntoCoefficientEmbedding<(MatZq, ModulusPolynomialRingZq)> for &MatPolynomialRingZq
Source§fn into_coefficient_embedding(
self,
size: impl Into<i64>,
) -> (MatZq, ModulusPolynomialRingZq)
fn into_coefficient_embedding( self, size: impl Into<i64>, ) -> (MatZq, ModulusPolynomialRingZq)
Computes the coefficient embedding of a matrix of polynomials
in a MatZq and a ModulusPolynomialRingZq.
Each column vector of polynomials is embedded into size many
row vectors of coefficients. The first one containing their
coefficients of degree 0, and the last one their coefficients
of degree size - 1.
It inverts the operation of MatPolynomialRingZq::from_coefficient_embedding.
The representation of the polynomials in the embedding is in the range [0, modulus_polynomial).
Parameters:
size: determines the number of rows each polynomial is embedded in. It has to be larger than the degree of all polynomials.
Returns a coefficient embedding as a matrix if size is large enough.
§Examples
use std::str::FromStr;
use qfall_math::{
integer_mod_q::{MatZq, MatPolynomialRingZq},
traits::IntoCoefficientEmbedding,
};
let poly = MatPolynomialRingZq::from_str("[[1 1, 2 1 2],[1 -1, 2 -1 -2]] / 3 1 2 3 mod 17").unwrap();
let embedding = poly.into_coefficient_embedding(2);
let cmp_mat = MatZq::from_str("[[1, 1],[0, 2],[-1, -1],[0, -2]] mod 17").unwrap();
assert_eq!((cmp_mat, poly.get_mod()), embedding);§Panics …
- if
sizeis not larger than the degree of the polynomial, i.e. not all coefficients can be embedded.
Source§impl MatrixDimensions for MatPolynomialRingZq
impl MatrixDimensions for MatPolynomialRingZq
Source§fn get_num_rows(&self) -> i64
fn get_num_rows(&self) -> i64
Returns the number of rows of the matrix as an i64.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let rows = poly_ring_mat.get_num_rows();Source§fn get_num_columns(&self) -> i64
fn get_num_columns(&self) -> i64
Returns the number of columns of the matrix as an i64.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let rows = poly_ring_mat.get_num_columns();Source§impl MatrixGetEntry<PolyOverZ> for MatPolynomialRingZq
impl MatrixGetEntry<PolyOverZ> for MatPolynomialRingZq
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolyOverZ
unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolyOverZ
Outputs the PolyOverZ value of a specific matrix entry
without checking whether it’s part of the matrix.
Parameters:
row: specifies the row in which the entry is locatedcolumn: specifies the column in which the entry is located
Returns the PolyOverZ value of the matrix at the position of the given
row and column.
§Safety
To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 50").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let entry_1: PolyOverZ = unsafe { poly_ring_mat.get_entry_unchecked(1, 0) };
let entry_2: PolyOverZ = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
assert_eq!(entry_1, PolyOverZ::from(0));
assert_eq!(entry_2, PolyOverZ::from(42));Source§fn get_entry(
&self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
) -> Result<T, MathError>
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<PolynomialRingZq> for MatPolynomialRingZq
impl MatrixGetEntry<PolynomialRingZq> for MatPolynomialRingZq
Source§unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolynomialRingZq
unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> PolynomialRingZq
Outputs the PolynomialRingZq 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 PolynomialRingZq value of the matrix at the position of the given
row and column.
§Safety
To use this function safely, make sure that the selected entry is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 50").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let entry_1: PolynomialRingZq = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
let entry_2: PolynomialRingZq = unsafe { poly_ring_mat.get_entry_unchecked(0, 1) };
let value_cmp = PolynomialRingZq::from((&PolyOverZ::from(42), &modulus));
assert_eq!(entry_1, value_cmp);
assert_eq!(entry_1, entry_2);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 MatrixGetSubmatrix for MatPolynomialRingZq
impl MatrixGetSubmatrix for MatPolynomialRingZq
Source§unsafe fn get_submatrix_unchecked(
&self,
row_1: i64,
row_2: i64,
col_1: i64,
col_2: i64,
) -> Self
unsafe fn get_submatrix_unchecked( &self, row_1: i64, row_2: i64, col_1: i64, col_2: i64, ) -> Self
Returns a deep copy of the submatrix defined by the given parameters and does not check the provided dimensions. There is also a safe version of this function that checks the input.
Parameters:
row_1: the starting row of the submatrix
row_2: the ending row of the submatrix
col_1: the starting column of the submatrix
col_2: the ending column of the submatrix
Returns the submatrix from (row_1, col_1) to (row_2, col_2)(exclusively).
§Examples
use qfall_math::{integer::MatPolyOverZ, traits::MatrixGetSubmatrix};
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();();
let mat = MatPolyOverZ::identity(3, 3);
let poly_ring_mat = MatPolynomialRingZq::from((&mat, &modulus));
let sub_mat_1 = poly_ring_mat.get_submatrix(0, 2, 1, 1).unwrap();
let sub_mat_2 = poly_ring_mat.get_submatrix(0, -1, 1, -2).unwrap();
let sub_mat_3 = unsafe{poly_ring_mat.get_submatrix_unchecked(0, 3, 1, 2)};
let e_2 = MatPolyOverZ::from_str("[[0],[1 1],[0]]").unwrap();
let e_2 = MatPolynomialRingZq::from((&e_2, &modulus));
assert_eq!(e_2, sub_mat_1);
assert_eq!(e_2, sub_mat_2);
assert_eq!(e_2, sub_mat_3);§Safety
To use this function safely, make sure that the selected submatrix is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.
Source§fn get_row(
&self,
row: impl TryInto<i64> + Display + Clone,
) -> Result<Self, MathError>
fn get_row( &self, row: impl TryInto<i64> + Display + Clone, ) -> Result<Self, MathError>
Source§unsafe fn get_row_unchecked(&self, row: i64) -> Self
unsafe fn get_row_unchecked(&self, row: i64) -> Self
Source§fn get_column(
&self,
column: impl TryInto<i64> + Display + Clone,
) -> Result<Self, MathError>
fn get_column( &self, column: impl TryInto<i64> + Display + Clone, ) -> Result<Self, MathError>
Source§unsafe fn get_column_unchecked(&self, column: i64) -> Self
unsafe fn get_column_unchecked(&self, column: i64) -> Self
Source§fn get_submatrix(
&self,
row_1: impl TryInto<i64> + Display,
row_2: impl TryInto<i64> + Display,
col_1: impl TryInto<i64> + Display,
col_2: impl TryInto<i64> + Display,
) -> Result<Self, MathError>
fn get_submatrix( &self, row_1: impl TryInto<i64> + Display, row_2: impl TryInto<i64> + Display, col_1: impl TryInto<i64> + Display, col_2: impl TryInto<i64> + Display, ) -> Result<Self, MathError>
(row_1, col_1) to (row_2, col_2)(inclusively) are collected in
a new matrix.
Note that row_1 >= row_2 and col_1 >= col_2 must hold after converting negative indices.
Otherwise the function will panic. Read moreSource§impl MatrixSetEntry<&PolyOverZ> for MatPolynomialRingZq
impl MatrixSetEntry<&PolyOverZ> for MatPolynomialRingZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: &PolyOverZ,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: &PolyOverZ, ) -> Result<(), MathError>
Sets the value of a specific matrix entry according to a given value of type PolyOverZ.
Parameters:
row: specifies the row in which the entry is locatedcolumn: specifies the column in which the entry is locatedvalue: specifies the value to which the entry is set
Negative indices can be used to index from the back, e.g., -1 for
the last element.
Returns an empty Ok if the action could be performed successfully.
Otherwise, a MathError is returned if the specified entry is
not part of the matrix.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use crate::qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[0, 1 42],[0, 2 1 2]]").unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let value = PolyOverZ::default();
poly_ring_mat.set_entry(0, 1, &value).unwrap();
poly_ring_mat.set_entry(-1, -1, &value).unwrap();
let mat_cmp = MatPolynomialRingZq::from((&MatPolyOverZ::new(2, 2), &modulus));
assert_eq!(poly_ring_mat, mat_cmp);§Errors and Failures
- Returns a
MathErrorof typeMathError::OutOfBoundsifroworcolumnare greater than the matrix size.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: &PolyOverZ,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: &PolyOverZ, )
Sets the value of a specific matrix entry according to a given value of type PolyOverZ
without checking whether the coordinate is part of the matrix, if the moduli match
or if the entry is reduced.
Parameters:
row: specifies the row in which the entry is 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::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use crate::qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[0, 1 42],[0, 2 1 2]]").unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let value = PolyOverZ::default();
unsafe {
poly_ring_mat.set_entry_unchecked(0, 1, &value);
poly_ring_mat.set_entry_unchecked(1, 1, &value);
}
let mat_cmp = MatPolynomialRingZq::from((&MatPolyOverZ::new(2, 2), &modulus));
assert_eq!(poly_ring_mat, mat_cmp);Source§impl MatrixSetEntry<&PolynomialRingZq> for MatPolynomialRingZq
impl MatrixSetEntry<&PolynomialRingZq> for MatPolynomialRingZq
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: &PolynomialRingZq,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: &PolynomialRingZq, )
Sets the value of a specific matrix entry according to a given value of type PolynomialRingZq
without checking whether the coordinate is part of the matrix or if the moduli match.
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::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ};
use crate::qfall_math::traits::*;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat = MatPolyOverZ::from_str("[[0, 1 42],[0, 2 1 2]]").unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
let value = PolynomialRingZq::from((&PolyOverZ::default(), &modulus));
unsafe {
poly_ring_mat.set_entry_unchecked(0, 1, &value);
poly_ring_mat.set_entry_unchecked(1, 1, &value);
}
let mat_cmp = MatPolynomialRingZq::from((&MatPolyOverZ::new(2, 2), &modulus));
assert_eq!(poly_ring_mat, mat_cmp);Source§impl MatrixSetEntry<PolyOverZ> for MatPolynomialRingZq
impl MatrixSetEntry<PolyOverZ> for MatPolynomialRingZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: PolyOverZ,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: PolyOverZ, ) -> Result<(), MathError>
Documentation can be found at MatPolynomialRingZq::set_entry for &PolyOverZ.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: PolyOverZ,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: PolyOverZ, )
Documentation can be found at MatPolynomialRingZq::set_entry for &PolyOverZ.
Source§impl MatrixSetEntry<PolynomialRingZq> for MatPolynomialRingZq
impl MatrixSetEntry<PolynomialRingZq> for MatPolynomialRingZq
Source§fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: PolynomialRingZq,
) -> Result<(), MathError>
fn set_entry( &mut self, row: impl TryInto<i64> + Display, column: impl TryInto<i64> + Display, value: PolynomialRingZq, ) -> Result<(), MathError>
Documentation can be found at MatPolynomialRingZq::set_entry for &PolynomialRingZq.
Source§unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: PolynomialRingZq,
)
unsafe fn set_entry_unchecked( &mut self, row: i64, column: i64, value: PolynomialRingZq, )
Documentation can be found at MatPolynomialRingZq::set_entry for &PolynomialRingZq.
Source§impl MatrixSetSubmatrix for MatPolynomialRingZq
impl MatrixSetSubmatrix for MatPolynomialRingZq
Source§unsafe fn set_submatrix_unchecked(
&mut self,
row_self_start: i64,
col_self_start: i64,
row_self_end: i64,
col_self_end: i64,
other: &Self,
row_other_start: i64,
col_other_start: i64,
row_other_end: i64,
col_other_end: i64,
)
unsafe fn set_submatrix_unchecked( &mut self, row_self_start: i64, col_self_start: i64, row_self_end: i64, col_self_end: i64, other: &Self, row_other_start: i64, col_other_start: i64, row_other_end: i64, col_other_end: i64, )
Sets the matrix entries in self to entries defined in other.
The entries in self starting from (row_self_start, col_self_start) up to
(row_self_end, col_self_end)are set to be
the entries from the submatrix from other defined by (row_other_start, col_other_start)
to (row_other_end, col_other_end) (exclusively).
Parameters:
row_self_start: the starting row of the matrix in which to set a submatrix
col_self_start: the starting column of the matrix in which to set a submatrix
other: the matrix from where to take the submatrix to set
row_other_start: the starting row of the specified submatrix
col_other_start: the starting column of the specified submatrix
row_other_end: the ending row of the specified submatrix
col_other_end:the ending column of the specified submatrix
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::integer::MatPolyOverZ;
use qfall_math::traits::MatrixSetSubmatrix;
use std::str::FromStr;
let mat = MatPolyOverZ::identity(3, 3);
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let mut mat = MatPolynomialRingZq::from((&mat, &modulus));
mat.set_submatrix(0, 1, &mat.clone(), 0, 0, 1, 1).unwrap();
// [[1,1,0],[0,0,1],[0,0,1]]
let mat_cmp = MatPolyOverZ::from_str("[[1 1, 1 1, 0],[0, 0, 1 1],[0, 0, 1 1]]").unwrap();
assert_eq!(mat, MatPolynomialRingZq::from((&mat_cmp, &modulus)));
unsafe{ mat.set_submatrix_unchecked(2, 0, 3, 2, &mat.clone(), 0, 0, 1, 2) };
let mat_cmp = MatPolyOverZ::from_str("[[1 1, 1 1, 0],[0, 0, 1 1],[1 1, 1 1, 1 1]]").unwrap();
assert_eq!(mat, MatPolynomialRingZq::from((&mat_cmp, &modulus)));§Safety
To use this function safely, make sure that the selected submatrices are part of the matrices, the submatrices are of the same dimensions and the base types are the same. If not, memory leaks, unexpected panics, etc. might occur.
Source§fn set_row(
&mut self,
row_0: impl TryInto<i64> + Display,
other: &Self,
row_1: impl TryInto<i64> + Display,
) -> Result<(), MathError>
fn set_row( &mut self, row_0: impl TryInto<i64> + Display, other: &Self, row_1: impl TryInto<i64> + Display, ) -> Result<(), MathError>
other. Read moreSource§unsafe fn set_row_unchecked(&mut self, row_0: i64, other: &Self, row_1: i64)
unsafe fn set_row_unchecked(&mut self, row_0: i64, other: &Self, row_1: i64)
other. Read moreSource§fn set_column(
&mut self,
col_0: impl TryInto<i64> + Display,
other: &Self,
col_1: impl TryInto<i64> + Display,
) -> Result<(), MathError>
fn set_column( &mut self, col_0: impl TryInto<i64> + Display, other: &Self, col_1: impl TryInto<i64> + Display, ) -> Result<(), MathError>
other. Read moreSource§unsafe fn set_column_unchecked(&mut self, col_0: i64, other: &Self, col_1: i64)
unsafe fn set_column_unchecked(&mut self, col_0: i64, other: &Self, col_1: i64)
other. Read moreSource§fn set_submatrix(
&mut self,
row_self_start: impl TryInto<i64> + Display,
col_self_start: impl TryInto<i64> + Display,
other: &Self,
row_other_start: impl TryInto<i64> + Display,
col_other_start: impl TryInto<i64> + Display,
row_other_end: impl TryInto<i64> + Display,
col_other_end: impl TryInto<i64> + Display,
) -> Result<(), MathError>
fn set_submatrix( &mut self, row_self_start: impl TryInto<i64> + Display, col_self_start: impl TryInto<i64> + Display, other: &Self, row_other_start: impl TryInto<i64> + Display, col_other_start: impl TryInto<i64> + Display, row_other_end: impl TryInto<i64> + Display, col_other_end: impl TryInto<i64> + Display, ) -> Result<(), MathError>
self to entries defined in other.
The entries in self starting from (row_self_start, col_self_start) are set to be
the entries from the submatrix from other defined by (row_other_start, col_other_start)
to (row_other_end, col_other_end) (inclusively).
The original matrix must have sufficiently many entries to contain the defined submatrix. Read moreSource§impl MatrixSwaps for MatPolynomialRingZq
impl MatrixSwaps for MatPolynomialRingZq
Source§fn swap_entries(
&mut self,
row_0: impl TryInto<i64> + Display,
col_0: impl TryInto<i64> + Display,
row_1: impl TryInto<i64> + Display,
col_1: impl TryInto<i64> + Display,
) -> Result<(), MathError>
fn swap_entries( &mut self, row_0: impl TryInto<i64> + Display, col_0: impl TryInto<i64> + Display, row_1: impl TryInto<i64> + Display, col_1: impl TryInto<i64> + Display, ) -> Result<(), MathError>
Swaps two entries of the specified matrix.
Parameters:
row_0: specifies the row, in which the first entry is locatedcol_0: specifies the column, in which the first entry is locatedrow_1: specifies the row, in which the second entry is locatedcol_1: specifies the column, in which the second entry is located
Negative indices can be used to index from the back, e.g., -1 for
the last element.
Returns an empty Ok if the action could be performed successfully.
Otherwise, a MathError is returned if one of the specified entries is not part of the matrix.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::traits::MatrixSwaps;
use std::str::FromStr;
let mut matrix = MatPolynomialRingZq::new(4, 3, ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap());
matrix.swap_entries(0, 0, 2, 1);§Errors and Failures
- Returns a
MathErrorof typeMathError::OutOfBoundsif row or column are greater than the matrix size.
Source§fn swap_columns(
&mut self,
col_0: impl TryInto<i64> + Display,
col_1: impl TryInto<i64> + Display,
) -> Result<(), MathError>
fn swap_columns( &mut self, col_0: impl TryInto<i64> + Display, col_1: impl TryInto<i64> + Display, ) -> Result<(), MathError>
Swaps two columns of the specified matrix.
Parameters:
col_0: specifies the first column which is swapped with the second onecol_1: specifies the second column which is swapped with the first one
Negative indices can be used to index from the back, e.g., -1 for
the last element.
Returns an empty Ok if the action could be performed successfully.
Otherwise, a MathError is returned if one of the specified columns is not part of the matrix.
§Examples
use qfall_math::traits::MatrixSwaps;
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut matrix = MatPolynomialRingZq::new(4, 3, ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap());
matrix.swap_columns(0, 2);§Errors and Failures
- Returns a
MathErrorof typeOutOfBoundsif one of the given columns is not in the matrix.
Source§fn swap_rows(
&mut self,
row_0: impl TryInto<i64> + Display,
row_1: impl TryInto<i64> + Display,
) -> Result<(), MathError>
fn swap_rows( &mut self, row_0: impl TryInto<i64> + Display, row_1: impl TryInto<i64> + Display, ) -> Result<(), MathError>
Swaps two rows of the specified matrix.
Parameters:
row_0: specifies the first row which is swapped with the second onerow_1: specifies the second row which is swapped with the first one
Negative indices can be used to index from the back, e.g., -1 for
the last element.
Returns an empty Ok if the action could be performed successfully.
Otherwise, a MathError is returned if one of the specified rows is not part of the matrix.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq};
use qfall_math::traits::MatrixSwaps;
use std::str::FromStr;
let mut matrix = MatPolynomialRingZq::new(4, 3, ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap());
matrix.swap_rows(0, 2);§Errors and Failures
- Returns a
MathErrorof typeOutOfBoundsif one of the given rows is not in the matrix.
Source§impl Mul<&MatPolyOverZ> for &MatPolynomialRingZq
impl Mul<&MatPolyOverZ> for &MatPolynomialRingZq
Source§fn mul(self, other: &MatPolyOverZ) -> Self::Output
fn mul(self, other: &MatPolyOverZ) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a MatPolyOverZ matrix.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the value to multiply withself
Returns the product of self and other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_3 = &mat_1 * &mat_2;§Panics …
- if the dimensions of
selfandotherdo not match for multiplication.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&MatPolynomialRingZq> for &MatPolyOverZ
impl Mul<&MatPolynomialRingZq> for &MatPolyOverZ
Source§fn mul(self, other: &MatPolynomialRingZq) -> Self::Output
fn mul(self, other: &MatPolynomialRingZq) -> Self::Output
Implements the Mul trait for a MatPolyOverZ matrix with a MatPolynomialRingZq matrix.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the value to multiply withself
Returns the product of self and other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_2 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_3 = &mat_1 * &mat_2;§Panics …
- if the dimensions of
selfandotherdo not match for multiplication.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&PolyOverZ> for &MatPolynomialRingZq
impl Mul<&PolyOverZ> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &PolyOverZ) -> Self::Output
fn mul(self, scalar: &PolyOverZ) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a PolyOverZ.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ, Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat1 = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly = PolyOverZ::from_str("3 1 0 1").unwrap();
let poly_ring_mat2 = &poly_ring_mat1 * &poly;Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&PolyOverZq> for &MatPolynomialRingZq
impl Mul<&PolyOverZq> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &PolyOverZq) -> Self::Output
fn mul(self, scalar: &PolyOverZq) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a PolyOverZq.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq, PolyOverZq};
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 poly = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
let poly_ring_mat2 = &poly_ring_mat1 * &poly;§Panics …
- if the moduli mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl Mul<&PolynomialRingZq> for &MatPolynomialRingZq
impl Mul<&PolynomialRingZq> for &MatPolynomialRingZq
Source§fn mul(self, scalar: &PolynomialRingZq) -> Self::Output
fn mul(self, scalar: &PolynomialRingZq) -> Self::Output
Implements the Mul trait for a MatPolynomialRingZq matrix with a PolynomialRingZq.
Mul is implemented for any combination of owned and borrowed values.
Parameters:
scalar: Specifies the scalar by which the matrix is multiplied.
Returns the product of self and scalar as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq, PolynomialRingZq};
use qfall_math::integer::{MatPolyOverZ, PolyOverZ, Z};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat1 = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly = PolyOverZ::from_str("3 1 0 1").unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_mat2 = &poly_ring_mat1 * &poly_ring;§Panics …
- if the moduli mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* 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<&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 for &MatPolynomialRingZq
impl Mul for &MatPolynomialRingZq
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Implements the Mul trait for two MatPolynomialRingZq values.
Mul is implemented for any combination of owned and borrowed MatPolynomialRingZq.
Parameters:
other: specifies the value to multiply withself
Returns the product of self and other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
let poly_ring_mat_1 = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let poly_mat_2 = MatPolyOverZ::from_str("[[3 3 0 1, 1 42],[0, 1 17]]").unwrap();
let poly_ring_mat_2 = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
let poly_ring_mat_3: MatPolynomialRingZq = &poly_ring_mat_1 * &poly_ring_mat_2;
let poly_ring_mat_4: MatPolynomialRingZq = poly_ring_mat_1 * poly_ring_mat_2;
let poly_ring_mat_5: MatPolynomialRingZq = &poly_ring_mat_3 * poly_ring_mat_4;
let poly_ring_mat_6: MatPolynomialRingZq = poly_ring_mat_3 * &poly_ring_mat_5;§Panics …
- if the dimensions of
selfandotherdo not match for multiplication. - if the moduli mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
* operator.Source§impl MulAssign<&PolyOverZq> for MatPolynomialRingZq
impl MulAssign<&PolyOverZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, scalar: &PolyOverZq)
fn mul_assign(&mut self, scalar: &PolyOverZq)
Documentation at MatPolynomialRingZq::mul_assign.
Performs underlying scalar multiplication as PolyOverZ and then applies the reduction.
§Panics …
- if the moduli are different.
Source§impl MulAssign<&PolynomialRingZq> for MatPolynomialRingZq
impl MulAssign<&PolynomialRingZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, scalar: &PolynomialRingZq)
fn mul_assign(&mut self, scalar: &PolynomialRingZq)
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 MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{MatPolynomialRingZq,ModulusPolynomialRingZq,PolynomialRingZq,Zq};
use qfall_math::integer::{MatZ,PolyOverZ,Z,MatPolyOverZ};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {}", u64::MAX - 1)).unwrap();
let poly_mat1 = MatPolyOverZ::from_str(&format!("[[1 1],[1 {}],[1 4]]", i64::MAX)).unwrap();
let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat1, &modulus));
let poly_z = PolyOverZ::from_str("2 3 1").unwrap();
let polynomial_ring_zq = PolynomialRingZq::from((&poly_z, &modulus));
poly_ring_mat *= &polynomial_ring_zq;
poly_ring_mat *= &poly_z;
poly_ring_mat *= 2;
poly_ring_mat *= -2;
poly_ring_mat *= &Z::from(5);
poly_ring_mat *= &Zq::from((5, u64::MAX -1));§Panics …
- if the moduli are different.
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<PolyOverZq> for MatPolynomialRingZq
impl MulAssign<PolyOverZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, other: PolyOverZq)
fn mul_assign(&mut self, other: PolyOverZq)
Documentation at MatPolynomialRingZq::mul_assign.
Source§impl MulAssign<PolynomialRingZq> for MatPolynomialRingZq
impl MulAssign<PolynomialRingZq> for MatPolynomialRingZq
Source§fn mul_assign(&mut self, other: PolynomialRingZq)
fn mul_assign(&mut self, other: PolynomialRingZq)
Documentation at MatPolynomialRingZq::mul_assign.
Source§impl<T> MulAssign<T> for MatPolynomialRingZqwhere
MatPolyOverZ: MulAssign<T>,
impl<T> MulAssign<T> for MatPolynomialRingZqwhere
MatPolyOverZ: MulAssign<T>,
Source§fn mul_assign(&mut self, scalar: T)
fn mul_assign(&mut self, scalar: T)
Documentation at MatPolynomialRingZq::mul_assign.
Performs underlying scalar multiplication as PolyOverZ and then applies the reduction.
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 PartialEq for MatPolynomialRingZq
impl PartialEq for MatPolynomialRingZq
Source§impl Serialize for MatPolynomialRingZq
impl Serialize for MatPolynomialRingZq
Source§impl Sub<&MatPolyOverZ> for &MatPolynomialRingZq
impl Sub<&MatPolyOverZ> for &MatPolynomialRingZq
Source§fn sub(self, other: &MatPolyOverZ) -> Self::Output
fn sub(self, other: &MatPolyOverZ) -> Self::Output
Implements the Sub trait for a MatPolynomialRingZq matrix with a MatPolyOverZ matrix.
Sub is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the value to subtract fromself
Returns the subtraction of self by other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_3 = &mat_1 - &mat_2;§Panics …
- if the dimensions of
selfandotherdo not match for multiplication.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
- operator.Source§impl Sub<&MatPolynomialRingZq> for &MatPolyOverZ
impl Sub<&MatPolynomialRingZq> for &MatPolyOverZ
Source§fn sub(self, other: &MatPolynomialRingZq) -> Self::Output
fn sub(self, other: &MatPolynomialRingZq) -> Self::Output
Implements the Sub trait for a MatPolyOverZ matrix with a MatPolynomialRingZq matrix.
Sub is implemented for any combination of owned and borrowed values.
Parameters:
other: specifies the value to subtract fromself
Returns the subtraction of self by other as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let mat_1 = MatPolyOverZ::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]]").unwrap();
let mat_2 = MatPolynomialRingZq::from_str("[[2 1 42, 1 17],[1 8, 2 5 6]] / 3 1 2 3 mod 17").unwrap();
let mat_3 = &mat_1 - &mat_2;§Panics …
- if the dimensions of
selfandotherdo not match for multiplication.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
- operator.Source§impl Sub for &MatPolynomialRingZq
impl Sub for &MatPolynomialRingZq
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Implements the Sub trait for two MatPolynomialRingZq values.
Sub is implemented for any combination of MatPolynomialRingZq
and borrowed MatPolynomialRingZq.
Parameters:
other: specifies the value to subtract fromself
Returns the result of the subtraction as a MatPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_mat_1 = MatPolyOverZ::from_str("[[3 0 1 1, 1 3],[0, 2 1 2]]").unwrap();
let poly_ring_mat_1 = MatPolynomialRingZq::from((&poly_mat_1, &modulus));
let poly_mat_2 = MatPolyOverZ::from_str("[[3 3 0 1, 1 7],[0, 1 16]]").unwrap();
let poly_ring_mat_2 = MatPolynomialRingZq::from((&poly_mat_2, &modulus));
let poly_ring_mat_3: MatPolynomialRingZq = &poly_ring_mat_1 - &poly_ring_mat_2;
let poly_ring_mat_4: MatPolynomialRingZq = poly_ring_mat_1 - poly_ring_mat_2;
let poly_ring_mat_5: MatPolynomialRingZq = &poly_ring_mat_3 - poly_ring_mat_4;
let poly_ring_mat_6: MatPolynomialRingZq = poly_ring_mat_3 - &poly_ring_mat_5;§Panics …
- if the dimensions of both matrices mismatch.
- if the moduli of both matrices mismatch.
Source§type Output = MatPolynomialRingZq
type Output = MatPolynomialRingZq
- operator.Source§impl SubAssign<&MatPolyOverZ> for MatPolynomialRingZq
impl SubAssign<&MatPolyOverZ> for MatPolynomialRingZq
Source§fn sub_assign(&mut self, other: &MatPolyOverZ)
fn sub_assign(&mut self, other: &MatPolyOverZ)
Documentation at MatPolynomialRingZq::sub_assign.
Source§impl SubAssign<&MatPolynomialRingZq> for MatPolynomialRingZq
impl SubAssign<&MatPolynomialRingZq> for MatPolynomialRingZq
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 MatPolynomialRingZq in combination with
MatPolynomialRingZq and MatPolyOverZ.
Parameters:
other: specifies the value to subtract fromself
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
use qfall_math::integer::MatPolyOverZ;
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("3 1 0 1 mod 7").unwrap();
let mut a = MatPolynomialRingZq::identity(2, 2, &modulus);
let b = MatPolynomialRingZq::new(2, 2, &modulus);
let c = MatPolyOverZ::new(2, 2);
a -= &b;
a -= b;
a -= &c;
a -= c;§Panics …
- if the matrix dimensions mismatch.
- if the moduli of the matrices mismatch.
Source§impl SubAssign<MatPolyOverZ> for MatPolynomialRingZq
impl SubAssign<MatPolyOverZ> for MatPolynomialRingZq
Source§fn sub_assign(&mut self, other: MatPolyOverZ)
fn sub_assign(&mut self, other: MatPolyOverZ)
Documentation at MatPolynomialRingZq::sub_assign.
Source§impl SubAssign for MatPolynomialRingZq
impl SubAssign for MatPolynomialRingZq
Source§fn sub_assign(&mut self, other: MatPolynomialRingZq)
fn sub_assign(&mut self, other: MatPolynomialRingZq)
Documentation at MatPolynomialRingZq::sub_assign.
Source§impl Tensor for MatPolynomialRingZq
impl Tensor for MatPolynomialRingZq
Source§fn tensor_product(&self, other: &Self) -> Self
fn tensor_product(&self, other: &Self) -> Self
Computes the tensor product of self with other.
Parameters:
other: the value with which the tensor product is computed.
Returns the tensor product of self with other.
§Examples
use qfall_math::integer_mod_q::MatPolynomialRingZq;
use qfall_math::traits::Tensor;
use std::str::FromStr;
let mat_1 = MatPolynomialRingZq::from_str("[[1 1, 2 1 1]] / 3 1 2 3 mod 17").unwrap();
let mat_2 = MatPolynomialRingZq::from_str("[[1 1, 1 2]] / 3 1 2 3 mod 17").unwrap();
let mat_ab = mat_1.tensor_product(&mat_2);
let mat_ba = mat_2.tensor_product(&mat_1);
let res_ab = "[[1 1, 1 2, 2 1 1, 2 2 2]] / 3 1 2 3 mod 17";
let res_ba = "[[1 1, 2 1 1, 1 2, 2 2 2]] / 3 1 2 3 mod 17";
assert_eq!(mat_ab, MatPolynomialRingZq::from_str(res_ab).unwrap());
assert_eq!(mat_ba, MatPolynomialRingZq::from_str(res_ba).unwrap());§Panics …
- if the moduli of both matrices mismatch.
Use
tensor_product_safeto get an error instead.