qfall_math/integer/
mat_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//! [`MatPolyOverZ`] is a type of matrix with entries of [`PolyOverZ`](crate::integer::PolyOverZ).
10//! This implementation uses the [FLINT](https://flintlib.org/) library.
11
12use crate::utils::parse::partial_string;
13use flint_sys::fmpz_poly_mat::fmpz_poly_mat_struct;
14use std::fmt;
15
16mod arithmetic;
17mod cmp;
18mod coefficient_embedding;
19mod concat;
20mod default;
21mod evaluate;
22mod from;
23mod get;
24mod norm;
25mod ownership;
26mod properties;
27mod reduce;
28mod sample;
29mod serialize;
30mod set;
31mod sort;
32mod tensor;
33mod to_string;
34mod trace;
35mod transpose;
36mod unsafe_functions;
37mod vector;
38
39/// [`MatPolyOverZ`] is a matrix with entries of type [`PolyOverZ`](crate::integer::PolyOverZ).
40///
41/// Attributes:
42/// - `matrix`: holds [FLINT](https://flintlib.org/)'s [struct](fmpz_poly_mat_struct)
43///   of the [`PolyOverZ`](crate::integer::PolyOverZ) matrix
44///
45/// # Examples
46/// ## Matrix usage
47/// ```
48/// use qfall_math::{
49///     integer::{PolyOverZ, MatPolyOverZ},
50///     traits::{MatrixGetEntry, MatrixSetEntry},
51/// };
52/// use std::str::FromStr;
53///
54/// // instantiate new matrix
55/// let id_mat = MatPolyOverZ::from_str("[[1  1, 0],[0, 1  1]]").unwrap();
56///
57/// // clone object, set and get entry
58/// let mut clone = id_mat.clone();
59/// clone.set_entry(0, 0, PolyOverZ::from(2));
60/// assert_eq!(
61///     clone.get_entry(1, 1).unwrap(),
62///     PolyOverZ::from_str("1  1").unwrap(),
63/// );
64///
65/// // to_string
66/// assert_eq!("[[1  1, 0],[0, 1  1]]", &id_mat.to_string());
67/// ```
68///
69/// ## Vector usage
70/// ```
71/// use qfall_math::{
72///     integer::{PolyOverZ, MatPolyOverZ},
73/// };
74/// use std::str::FromStr;
75///
76/// let row_vec = MatPolyOverZ::from_str("[[1  1, 0, 1  1]]").unwrap();
77/// let col_vec = MatPolyOverZ::from_str("[[1  -5],[1  -1],[0]]").unwrap();
78///
79/// // check if matrix instance is vector
80/// assert!(row_vec.is_row_vector());
81/// assert!(col_vec.is_column_vector());
82/// ```
83pub struct MatPolyOverZ {
84    pub(crate) matrix: fmpz_poly_mat_struct,
85}
86
87impl fmt::Debug for MatPolyOverZ {
88    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89        write!(
90            f,
91            "MatPolyOverZ: {{matrix: {}, storage: {:?}}}",
92            // printing the entire matrix is not meaningful for large matrices
93            partial_string(self, 3, 3),
94            self.matrix
95        )
96    }
97}