1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright © 2025 Niklas Siemer
//
// This file is part of qFALL-math.
//
// qFALL-math is free software: you can redistribute it and/or modify it under
// the terms of the Mozilla Public License Version 2.0 as published by the
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
//! [`MatNTTPolynomialRingZq`] containts the NTT representations of matrices over polynomials.
use crate::;
use Display;
use ;
use fmt;
/// [`MatNTTPolynomialRingZq`] contains the NTT representation of a matrix over polynomials with respect to
/// a [`NTTBasisPolynomialRingZq`](super::NTTBasisPolynomialRingZq) that itself isn't aware of.
///
/// Any polynomial in NTT representation in row `i` and column `j` can be accessed via `matrix[j * nr_columns + i]`.
///
/// Attributes
/// - `matrix`: holds the matrix entries with its coefficients
/// - `nr_rows`: the number of rows of the matrix
/// - `nr_columns`: the number of columns of the matrix
/// - `modulus`: the [`ModulusPolynomialRingZq`] defining the modulus `q`, the ring `Z_q[X]/f(X)`, and
/// the NTT transform [`NTTBasisPolynomialRingZq`](crate::integer_mod_q::NTTBasisPolynomialRingZq)
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::{Modulus, MatPolynomialRingZq, MatNTTPolynomialRingZq, ModulusPolynomialRingZq};
/// use std::str::FromStr;
///
/// // setup modulus with ability to transform to NTT
/// let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
/// modulus.set_ntt_unchecked(64);
///
/// // sample random matrix
/// let mat_rnd = MatNTTPolynomialRingZq::sample_uniform(2, 2, &modulus);
/// // or instantiate matrix from MatPolynomialRingZq
/// let mat_poly_ring = MatPolynomialRingZq::identity(2, 2, &modulus);
/// let mat_ntt_poly_ring = MatNTTPolynomialRingZq::from(&mat_poly_ring);
///
/// // multiply, add and subtract objects
/// let mut tmp_mat_ntt = mat_ntt_poly_ring * &mat_rnd;
/// tmp_mat_ntt += &mat_rnd;
/// tmp_mat_ntt -= &mat_rnd;
///
/// // Return to MatPolynomialRingZq
/// let res = tmp_mat_ntt.inv_ntt();
/// ```
/// Quick solution to print a vector of [`Z`] values in the format `[1, 2, 3, 4, 5]`.
pub