Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Factor an integer using Hart's one line factoring algorithm
ResourceFunction["FactorIntegerHart"][n] returns a pair of factors of the integer n, using Hart’s algorithm. |
Original example given by Hart:
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
Hart's algorithm will work when the base is rational, in this case the base is 101/11:
| In[3]:= | ![]() |
| Out[3]= |
| In[4]:= |
| Out[4]= |
The coefficients may also be (distinct) rational numbers:
| In[5]:= | ![]() |
| Out[5]= |
| In[6]:= |
| Out[6]= |
The exponents of the base can be distinct, providing they are sufficiently close:
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
By default, the maximum number of iterations is 216:
| In[9]:= | ![]() |
| Out[9]= |
Increasing MaxIterations allows us to factor this integer:
| In[10]:= |
| Out[10]= |
For the applicable class of semiprimes, FactorIntegerHart will usually be much faster than FactorInteger:
| In[11]:= | ![]() |
| Out[11]= |
| In[12]:= |
| Out[12]= |
Unlike FactorInteger, the factors returned by FactorIntegerHart may not be prime:
| In[13]:= |
| Out[13]= |
| In[14]:= |
| Out[14]= |
Factoring an enormous semiprime:
| In[15]:= | ![]() |
| Out[15]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License