qfall_math/utils/
factorization.rs

1// Copyright © 2023 Marcel Luca Schmidt
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//! This module contains the type [`Factorization`], which is a factorized
10//! (or partly factorized) representation of integers with arbitrary length.
11
12use flint_sys::fmpz_factor::fmpz_factor_struct;
13
14mod default;
15mod from;
16mod ownership;
17mod refine;
18mod to_string;
19
20/// [`Factorization`] represents any integer value as its factorization or
21/// partly factorization.
22///
23/// Attributes:
24/// - `factors`: holds [FLINT](https://flintlib.org/)'s [struct](fmpz_factor_struct)
25///   for a factorization of an integer value
26///
27/// # Implicit Typecasting
28/// Most of our functions take as input values of type Integer.
29/// These capture all types that can be turned into a [`Z`](crate::integer::Z) value.
30/// The types are [`Z`](crate::integer::Z), [`Modulus`](crate::integer_mod_q::Modulus), [`i8`],
31/// [`i16`],[`i32`],[`i64`],[`u8`],[`u16`],[`u32`],[`u64`] and the
32/// references of all of these types. These types are then implicitly casted to a
33/// [`Z`](crate::integer::Z) before the desired action is performed.
34///
35/// # Examples
36/// ```
37/// use qfall_math::utils::Factorization;
38/// use qfall_math::integer::Z;
39/// use std::str::FromStr;
40/// use core::fmt;
41///
42/// // instantiations
43/// let a = Z::from(1200);
44/// let b = Z::from(20);
45///
46/// let fac_1 = Factorization::from(&a);
47/// let mut fac_2 = Factorization::from((&a, &b));
48///
49/// // refinement
50/// fac_2.refine();
51///
52/// // to_string
53/// assert_eq!("[(3, 1), (20, 3)]", &fac_2.to_string());
54/// ```
55#[derive(Debug)]
56pub struct Factorization {
57    factors: fmpz_factor_struct,
58}