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
// 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/>.
//! [`NTTPolynomialRingZq`] containts the NTT representations of polynomials.
use crate::;
use Display;
use ;
use fmt;
/// [`NTTPolynomialRingZq`] contains the NTT representation of some polynomial with respect to
/// a [`NTTBasisPolynomialRingZq`](super::NTTBasisPolynomialRingZq) that itself isn't aware of.
///
/// Attributes
/// - `poly`: holds the coefficients
/// - `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, PolynomialRingZq, NTTPolynomialRingZq, ModulusPolynomialRingZq};
/// use std::str::FromStr;
/// // Setup modulus with capability to perform NTT transform
/// let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
/// modulus.set_ntt_unchecked(64);
///
/// // sample random polynomial
/// let rnd = NTTPolynomialRingZq::sample_uniform(&modulus);
/// // or instantiate polynomial from PolynomialRingZq (or PolyOverZq)
///
/// let poly_ring = PolynomialRingZq::sample_uniform(&modulus);
/// let ntt_poly_ring = NTTPolynomialRingZq::from(&poly_ring);
///
/// // multiply, add and subtract objects
/// let mod_q = Modulus::from(modulus.get_q());
/// let mut tmp_ntt = ntt_poly_ring * &rnd;
/// tmp_ntt += &rnd;
/// tmp_ntt -= &rnd;
///
/// // Return to PolynomialRingZq
/// let res = tmp_ntt.inv_ntt();
/// ```