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