qfall_math/integer_mod_q/
poly_over_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//! [`PolyOverZq`] is a type of polynomial with arbitrarily many coefficients of type
10//! [`Zq`](crate::integer_mod_q::Zq).
11//! This implementation uses the [FLINT](https://flintlib.org/) library.
12
13// For **DEVELOPERS**: Many functions assume that the [`PolyOverZq`] instances are reduced.
14// To avoid unnecessary checks and reductions, always return canonical/reduced
15// values. The end-user should be unable to obtain a non-reduced value.
16
17use super::modulus::Modulus;
18use flint_sys::fmpz_mod_poly::fmpz_mod_poly_struct;
19use std::fmt;
20
21mod arithmetic;
22mod cmp;
23mod coefficient_embedding;
24mod dot_product;
25mod evaluate;
26mod from;
27mod get;
28mod norm;
29mod ownership;
30mod properties;
31mod sample;
32mod serialize;
33mod set;
34mod to_string;
35mod unsafe_functions;
36
37/// [`PolyOverZq`] is a type of polynomial with arbitrarily many coefficients of type
38/// [`Zq`](crate::integer_mod_q::Zq).
39///
40// Attributes:
41// - `poly`: holds the content of the polynomial
42// - `modulus`: holds the value of the modulus
43//
44/// # Examples
45/// ```
46/// use qfall_math::integer::Z;
47/// use qfall_math::integer_mod_q::PolyOverZq;
48/// use qfall_math::traits::*;
49/// use std::str::FromStr;
50///
51/// // instantiations
52/// let poly_1 = PolyOverZq::from_str("4  0 1 2 3 mod 42").unwrap();
53/// let poly_2 = poly_1.clone();
54///
55/// // evaluate function
56/// let value = Z::from(3);
57/// let res = poly_1.evaluate(&value);
58///
59/// // properties
60/// let reducibility: bool = poly_1.is_irreducible();
61///
62/// // comparison
63/// assert_eq!(poly_1, poly_2);
64/// ```
65pub struct PolyOverZq {
66    pub(crate) poly: fmpz_mod_poly_struct,
67    pub(crate) modulus: Modulus,
68}
69
70impl fmt::Debug for PolyOverZq {
71    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72        write!(
73            f,
74            "PolyOverZq {{poly: {}\
75            storage: {{poly: {:?}, modulus: {:?}}}}}",
76            self, self.poly, self.modulus
77        )
78    }
79}