qfall_math/integer_mod_q/modulus_polynomial_ring_zq.rs
1// Copyright © 2023 Marvin Beckmann
2//
3// This file is part of qFALL-math.
4//
5// qFALL-math is free software: you can redistribute it and/or modify it under
6// the terms of the Mozilla Public License Version 2.0 as published by the
7// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
8
9//! [`ModulusPolynomialRingZq`] is the context object for
10//! [`PolynomialRingZq`](super::PolynomialRingZq).
11//! This implementation uses the [FLINT](https://flintlib.org/) library.
12
13use super::ntt_basis_polynomial_ring_zq::NTTBasisPolynomialRingZq;
14use crate::integer_mod_q::PolyOverZq;
15use std::{fmt, rc::Rc};
16
17mod cmp;
18mod coefficient_embedding;
19mod from;
20mod get;
21mod norm;
22mod ntt_basis;
23mod ownership;
24mod serialize;
25mod to_string;
26
27/// [`ModulusPolynomialRingZq`] represents the modulus object for
28/// [`PolynomialRingZq`](crate::integer_mod_q::PolynomialRingZq)
29///
30/// Attributes
31/// - `modulus`: holds the specific content, i.e. the modulus `q` and f(X)
32///
33/// # Examples
34/// ```
35/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
36/// use qfall_math::integer_mod_q::PolyOverZq;
37/// use std::str::FromStr;
38///
39/// // initialize X^2 + 1 mod 17, i.e. a polynomial with modulus
40/// let poly_mod = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
41/// let modulus = ModulusPolynomialRingZq::from(poly_mod);
42/// ```
43pub struct ModulusPolynomialRingZq {
44 pub(crate) modulus: Rc<PolyOverZq>,
45 pub(crate) ntt_basis: Rc<Option<NTTBasisPolynomialRingZq>>,
46 pub(crate) non_zero: Vec<usize>,
47}
48
49impl fmt::Debug for ModulusPolynomialRingZq {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 write!(
52 f,
53 "ModulusPolynomialRingZq {{ modulus: {}, storage: {{modulus: {:?}}}}}",
54 self, self.modulus
55 )
56 }
57}