pub struct Factorization { /* private fields */ }Expand description
Factorization represents any integer value as its factorization or
partly factorization.
Attributes:
§Implicit Typecasting
Most of our functions take as input values of type Integer.
These capture all types that can be turned into a Z value.
The types are Z, Modulus, i8,
i16,i32,i64,u8,u16,u32,u64 and the
references of all of these types. These types are then implicitly casted to a
Z before the desired action is performed.
§Examples
use qfall_math::utils::Factorization;
use qfall_math::integer::Z;
use std::str::FromStr;
use core::fmt;
// instantiations
let a = Z::from(1200);
let b = Z::from(20);
let fac_1 = Factorization::from(&a);
let mut fac_2 = Factorization::from((&a, &b));
// refinement
fac_2.refine();
// to_string
assert_eq!("[(3, 1), (20, 3)]", &fac_2.to_string());Implementations§
Source§impl Factorization
impl Factorization
Sourcepub fn refine(&mut self)
pub fn refine(&mut self)
Allows to refine a partial factorization of type Factorization to a more
complete one whose bases are pairwise relatively prime.
The bases of the factors are then in ascending order.
For factorization [(2, 2), (40, 1), (9, 2)] the refinement looks like this
[(2, 5), (5, 1), (9, 2)].
§Examples
use qfall_math::utils::Factorization;
use core::fmt;
let mut fac = Factorization::from((1200, 20));
fac.refine();
println!("{}", fac);Trait Implementations§
Source§impl Debug for Factorization
impl Debug for Factorization
Source§impl Default for Factorization
impl Default for Factorization
Source§fn default() -> Self
fn default() -> Self
Returns an instantiation of Factorization with 1 as the only factor.
§Examples
use std::default::Default;
use qfall_math::utils::Factorization;
let fac = Factorization::default();Source§impl Display for Factorization
impl Display for Factorization
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Allows to convert a factorization of type Factorization into a String.
Returns the factorization in form of a String. For factorization 2^3 * 5 * 7^2
the String looks like this [(2, 3), (5, 1), (7, 2)].
§Examples
use qfall_math::utils::Factorization;
use core::fmt;
let mut fac = Factorization::from((1200, 20));
fac.refine();
println!("{}", fac);Source§impl Drop for Factorization
impl Drop for Factorization
Source§fn drop(&mut self)
fn drop(&mut self)
Drops the given Factorization value and frees the allocated memory.
§Examples
use qfall_math::utils::Factorization;
{
let fac = Factorization::from((8, 3));
} // as fac's scope ends here, it get's droppeduse qfall_math::utils::Factorization;
let fac = Factorization::from((8, 3));
drop(fac); // explicitly drops fac's valueSource§impl From<&Factorization> for Vec<(Z, u64)>
impl From<&Factorization> for Vec<(Z, u64)>
Source§fn from(factors: &Factorization) -> Self
fn from(factors: &Factorization) -> Self
Convert a Factorization into a Vec<(Z, u64)>.
Parameters:
factors: theFactorizationwe want as aVec<(Z, u64)>object.
Returns a new Vec<(Z, u64)> with the factors from Factorization
represented as tuples with bases as Z and exponents as u64 values.
§Examples
use qfall_math::utils::Factorization;
use qfall_math::integer::Z;
let fac = Factorization::from(10);
let vec = Vec::<(Z, u64)>::from(&fac);Source§impl From<&Vec<(Z, u64)>> for Factorization
impl From<&Vec<(Z, u64)>> for Factorization
Source§fn from(factors: &Vec<(Z, u64)>) -> Self
fn from(factors: &Vec<(Z, u64)>) -> Self
Convert a Vec<(Z, u64)> into a Factorization.
Note that the order and occurrences of the factors are not altered by this method and an empty vector results in a factorization of 1.
Parameters:
factors: theVec<(Z, u64)>we want as aFactorizationobject.
Returns a new Factorization with the factors from Vec<(Z, u64)>.
§Examples
use qfall_math::utils::Factorization;
use qfall_math::integer::Z;
let vec: Vec<(Z, u64)> = vec![(Z::from(3), 2), (Z::from(8), 2), (Z::from(4), 1)];
let fac = Factorization::from(&vec);Source§impl<Integer: Into<Z>> From<(Integer, Integer)> for Factorization
impl<Integer: Into<Z>> From<(Integer, Integer)> for Factorization
Source§fn from(factors: (Integer, Integer)) -> Self
fn from(factors: (Integer, Integer)) -> Self
Convert two integers into a Factorization.
Note that the order and occurrences of the factors are not altered by this method.
Parameters:
factors: a tuple with two integers we want in theFactorizationobject.
Returns a new Factorization with factors as the only factors.
§Examples
use qfall_math::utils::Factorization;
let fac = Factorization::from((10, 5));Source§impl<Integer: Into<Z>> From<Integer> for Factorization
impl<Integer: Into<Z>> From<Integer> for Factorization
Source§fn from(factor: Integer) -> Self
fn from(factor: Integer) -> Self
Convert an integer into a Factorization.
Parameters:
factor: the integer we want as aFactorizationobject.
Returns a new Factorization with factor as the only factor.
§Examples
use qfall_math::utils::Factorization;
let fac = Factorization::from(10);