Content deleted Content added
m →The basic method: use consistent case |
mNo edit summary |
||
Line 10:
==The basic method==
One tries various values of ''a'', hoping that <math>a^2-N = b^2</math> is a square (note that variable b2 represents <math>b^2</math>).
:FermatFactor(N): // N should be odd
Line 43:
==Fermat's and trial division==
Let's try to factor the prime number N=2345678917, but also compute
<table>
<tr><td>
<tr><td>
<tr><td>
<tr><td>
</table>
In practice, one wouldn't bother with that last row, until ''
Trial division would normally try up to 48432; but after only four Fermat steps, we need only divide up to 47830, to find a factor or prove primality.
Line 60:
In this regard, Fermat's method gives diminishing returns. One would surely stop before this point:
<table>
<tr><td>
<tr><td>
<tr><td>
<tr><td>
</table>
Line 70:
One needn't compute all the square-roots of <math>a^2-N</math>, nor even examine all the values for <math>a</math>. Examine the tableau for <math>N=2345678917</math>:
<table>
<tr><td>
<tr><td>
<tr><td>
</table>
One can quickly tell that none of these values of
This can be performed with any modulus. Using the same <math>N=2345678917</math>,
Line 92:
Given a sequence of ''a''-values (start, end, and step) and a modulus, one can proceed thus:
:FermatSieve(N,
::
::do
:::
:::if
::::FermatSieve(N,
:::endif
:::
::enddo
But one stops the recursion, when few ''a''-values remain; that is, when (
==Multiplier improvement==
Line 108:
Fermat's method works best when there is a factor near the square-root of ''N''. Perhaps one can arrange for that to happen.
If one knows the approximate ratio of two factors (<math>d/c</math>), then one can pick a rational number <math>v/u</math> near that value. <math>Nuv = cv * du</math>, and the factors are roughly equal: Fermat's, applied to ''Nuv'', will find them quickly. Then <math>\gcd(N,cv)=c</math> and <math>\gcd(N,du)=d</math>. (Unless ''c'' divides ''u'' or ''d'' divides ''v''.)
Generally, one does not know the ratio, but one can try various <math>u/v</math> values, and try to factor each resulting ''Nuv''. R. Lehman devised a systematic way to do this, so that Fermat's plus trial-division can factor N in <math>O(N^{1/3})</math> time.
Line 115:
==Other improvements==
The fundamental ideas of Fermat's factorization method are the basis of the [[quadratic sieve]] and [[general number field sieve]], the best-known algorithms for factoring "worst-case" large [[semiprimes]]. The primary improvement that quadratic sieve makes over Fermat's factorization method is that instead of simply finding a square in the sequence of
See also J. McKee, "[http://www.ams.org/mcom/1999-68-228/S0025-5718-99-01133-3/home.html Speeding Fermat's factoring method]", ''Mathematics of Computation'', 68:1729-1737 (1999).
|