Factorization module

class factodiagrams.preprocess.Factorisation.Factorization

Bases: object

Graph_description(graph_description: list) → str

Generate a factorization graph description in dot format

Parameters

graph_description (list) – list describing the nodes and the connections between different stages.

Returns

the dot file descriibng the generale graph

Return type

str

createedge(x: str, y: str, t: int) → str

Function to create a connection between the nodes and stages

Parameters
  • x (str) – nodes 1

  • y (str) – nodes 2

  • t (int) –

    nodes type

    • t=0 : last stage of the tree

    • t=1 : all other stages

Returns

return the connection description between the nodes

Return type

str

createnode(x: int) → str

Function to add new node to the graph

Parameters

x (int) –

type of nodes

  • x=0 : the node will be in the last stage of the tree (Black nodes)

  • x=1 : the node will be in the other stages of the tree

Returns

node description

Return type

str

draw_factor(n: int, fact_method: str, save: bool, show: bool) → bool

Create a default factorization diagram for the given integer n , by factoring it and calling factorization method

Warning

  • In case of a large image, the function uses svg format and show it in the default browser

  • This functions requires the command circo from graphviz

Parameters
  • n (int) – Number to which we draw the diagram

  • fact_method (str) –

    Factorization function name used to get the factors

    • prime_factors : To use the prime factors algorithme implementaion

    • pollardrho : To use the pollard rho algorithme implementaion

  • save (bool) –

    Variable to keep or delete the generated diagram

    • True : to save automatically the diagram

    • False : to delete the diagram after show it

  • show (bool) –

    Variable to show or hide the generated diagram - True : to show automatically the diagram

    • False : to hide automatically the diagram

Returns

operation state

Return type

(bool)

draw_factor_poster(numbers: list, fact_method: str, col: int = 2, poster_name: str = 'poster') → None

Create a default Matrix of factorization diagram for the given list of numbers

Parameters
  • numbers (list) – List of numbers

  • fact_method (str) –

    Factorization function name used to get the factors

    • prime_factors : To use the prime factors algorithme implementaion

    • pollardrho : To use the pollard rho algorithme implementaion

  • col (int, optional) – Number of column in the poster. Defaults to 2.

  • poster_name (str, optional) – The poster output file name. Defaults to “poster”.

factorization(n: int, function_name: str) → dict

Function to generate a number factorization based on the function_name algorithm

Parameters
  • n (int) – number to factorize

  • function_name (str) –

    Factorization function name used to get the factors

    • prime_factors : To use the prime factors algorithme implementaion

    • pollardrho : To use the pollard rho algorithme implementaion

Returns

dictionary of each factor’s multiplicity

Return type

dict

get_concat_v(k: int, poster_name: str = 'poster')

Concatenation vertically all the diagrams

Parameters
  • k (int) – number of columns

  • poster_name (str, optional) – output image name. Defaults to “poster”.

get_graph(n: int, name: str) → list
Create a default graph description for the given integer n ,

by factorizing it and calling factorization method

Parameters
  • n (int) – Number to factorize

  • name (str) –

    Factorization methode name used to get the factors

    • prime_factors : To use the prime factors algorithme implementaion

    • pollardrho : To use the pollard rho algorithme implementaion

Returns

List describing the nodes and the edges of graph

Return type

list

pgcd(a: int, b: int) → int

the Greatest Common Divisor (GCD) of two integers A and B based on the Euclidean Algorithm

Parameters
  • a (int) – The first number

  • b (int) – The second number

Returns

Greatest common divisor

Return type

int

pollardrho(n: int) → list

This function provides an implementation of the Pollard Rho algorithm.

Parameters

n (int) – Number to factorize

Returns

[d (int): non-trivial factor, n//d]

Return type

list

prime_factors(n: int) → list

This function returns a list of prime factors of a number n > 1.

Note

in case of n=1 or n=0 , the function returns an empty list

Parameters

n (int) – the number to be factored

Returns

list of prime factors

Return type

list

>>> factorisation=Factorization()
>>> factorisation.prime_factors(50)
[2,5,10]
to_string(factors: list) → str

Function to format the primes factors output

Parameters

factors (list) – list of prime factors

Returns

formated output

Return type

str

factodiagrams.preprocess.decomposition.fours(n)

Returns the formatted list of prime factors of n.

If two numbers 2 follow each other in the prime number decomposition, this function returns an array where the 2x2 have been transformed into 4. Useful for a better representation.

Parameters

n (int) – number to decompose.

Example

prime_factors(12) [2, 2, 3] become [4, 3]

factodiagrams.preprocess.decomposition.radius(n)

Returns the radius of circles according to n.

Parameters

n (int) – number to decompose.

factodiagrams.preprocess.facto_f_W.fermat(n)
factodiagrams.preprocess.facto_f_W.wilson_factor(n)
factodiagrams.preprocess.facto_methode.factorization(self, n: int, function_name: str) → dict

[function to generate a number factorization based on function name]

Parameters
  • n (int) – [number to factorize]

  • function_name (str) – [Factorization function name used to get the factors]

Returns

[dictionary of each factor’s multiplicity]

Return type

dict