qfall_math/integer/poly_over_z.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//! [`PolyOverZ`] is a type of polynomial with arbitrarily many coefficients of type
10//! [`Z`](crate::integer::Z)
11//! This implementation uses the [FLINT](https://flintlib.org/) library.
12
13use flint_sys::fmpz_poly::fmpz_poly_struct;
14use std::fmt;
15
16mod arithmetic;
17mod cmp;
18mod coefficient_embedding;
19mod default;
20mod dot_product;
21mod evaluate;
22pub(crate) mod fmpz_poly_helpers;
23mod from;
24mod get;
25mod norm;
26mod ownership;
27mod properties;
28mod reduce;
29mod sample;
30mod serialize;
31mod set;
32mod to_string;
33mod unsafe_functions;
34
35/// [`PolyOverZ`] is a type of polynomial with arbitrarily many coefficients of type
36/// [`Z`](crate::integer::Z).
37///
38// Attributes:
39// - `poly`: holds the content of the polynomial
40//
41/// # Examples
42/// ```
43/// use qfall_math::integer::{PolyOverZ, Z};
44/// use qfall_math::traits::*;
45/// use std::str::FromStr;
46///
47/// // instantiations
48/// let poly_1 = PolyOverZ::from_str("4 0 1 2 3").unwrap();
49/// let poly_2 = PolyOverZ::default();
50///
51/// // arithmetic operations
52/// let _ = &poly_1 + &poly_2;
53/// let _ = &poly_1 * &poly_2;
54///
55/// // evaluate function
56/// let value = Z::from(3);
57/// let res: Z = poly_1.evaluate(&value);
58///
59/// // comparison
60/// assert_ne!(poly_1, poly_2);
61/// ```
62pub struct PolyOverZ {
63 pub(crate) poly: fmpz_poly_struct,
64}
65
66impl fmt::Debug for PolyOverZ {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 write!(
69 f,
70 "PolyOverZ {{poly: {}, storage: {{poly: {:?}}}}}",
71 self, self.poly
72 )
73 }
74}