Factorization

Struct Factorization 

Source
pub struct Factorization { /* private fields */ }
Expand description

Factorization represents any integer value as its factorization or partly factorization.

Attributes:

  • factors: holds FLINT’s struct for a factorization of an integer value

§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

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Factorization

Source§

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

Source§

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

Source§

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 dropped
use qfall_math::utils::Factorization;

let fac = Factorization::from((8, 3));
drop(fac); // explicitly drops fac's value
Source§

impl From<&Factorization> for Vec<(Z, u64)>

Source§

fn from(factors: &Factorization) -> Self

Convert a Factorization into a Vec<(Z, u64)>.

Parameters:

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

Source§

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:

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

Source§

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 the Factorization object.

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

Source§

fn from(factor: Integer) -> Self

Convert an integer into a Factorization.

Parameters:

Returns a new Factorization with factor as the only factor.

§Examples
use qfall_math::utils::Factorization;

let fac = Factorization::from(10);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V