Function Repository Resource:

FactorGraph

Source Notebook

Get a graph representation for the factorization of an integer

Contributed by: Emmanuel Garcés

ResourceFunction["FactorGraph"][n]

gives a graph representing the factorization of the integer n.

ResourceFunction["FactorGraph"][n,pos]

gives the graph for n with the largest factor with position pos.

Details and Options

Let m and n be distinct integers such that m divides n. Then the vertices of a polygon with n vertices can be connected to a polygon with m vertices from m/n equally spaced vertices on the first polygon. This procedure can be applied repeatedly to the prime factors of a number in order to get visualizations of the factorizations of the numbers.
The vertices of a polygon with vertices can be connected to a polygon with vertices from equally spaced vertices on the first polygon. This procedure can be applied repeatedly to the prime factors of a number in order to get visualizations of the factorizations of the numbers.
In ResourceFunction["FactorGraph"][n,pos], pos can be "Inside" or "Outside".

Examples

Basic Examples (5) 

Get the rules representing the graph:

In[1]:=
ResourceFunction["FactorGraph"][6]
Out[1]=
In[2]:=
ResourceFunction["FactorGraph"][5, "Outside"]
Out[2]=

Get the graph:

In[3]:=
GraphPlot[First@ResourceFunction["FactorGraph"][72]]
Out[3]=

Factor graphs from a list of the first 10 integers:

In[4]:=
GraphicsGrid[{Table[
   GraphPlot[First[ResourceFunction["FactorGraph"][n, "Inside"]], Method -> (n /. {4 -> "RadialDrawing", 6 | 8 | 16 -> "HighDimensionalEmbedding", _ -> "SpringElectricalEmbedding"})], {n, 2, 10}]}, ImageSize -> {800, 100}]
Out[4]=

With a different method:

In[5]:=
GraphPlot[First[ResourceFunction["FactorGraph"][20, "Outside"]], Method -> "LinearEmbedding"]
Out[5]=

For a larger integer:

In[6]:=
GraphPlot[First[ResourceFunction["FactorGraph"][2000, "Outside"]]]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 11 March 2019

License Information