Compressibility factor: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Rjwilmsi
 
Line 1: Line 1:
'''[[Fermat]]'s [[Integer factorization|factorization]] method''', named after [[Pierre de Fermat]], is based on the representation of an [[even and odd numbers|odd]] [[integer]] as the [[difference of two squares]]:
Glen Wendler is the title individuals use to contact me and my wife doesn't like it at all. Some time in the past she selected to live in Delaware but her spouse desires them to move. Dispatching has been my occupation for some time. Going to [http://Www.Dict.cc/?s=karaoke karaoke] is some thing that [http://www.Answers.com/topic/I%27ve+carried I've carried] out for many years. Go to my web site to discover out much more: http://www.socialairforce.com/groups/warning-nya-internet-svenska-casinon/<br><br>
:<math>N = a^2 - b^2.</math>
That difference is [[algebra]]ically factorable as <math>(a+b)(a-b)</math>; if neither factor equals one, it is a proper factorization of ''N''.


Each odd number has such a representation. Indeed, if <math>N=cd</math> is a factorization of ''N'', then
My homepage ... [http://www.socialairforce.com/groups/warning-nya-internet-svenska-casinon/ nya online casino]
:<math>N = [(c+d)/2]^2 - [(c-d)/2]^2.</math>
 
Since ''N'' is odd, then ''c'' and ''d'' are also odd, so those halves are integers. (A multiple of four is also a difference of squares: let ''c'' and ''d'' be even.)
 
In its simplest form, Fermat's method might be even slower than trial division (worst case). Nonetheless, the combination of trial division and Fermat's is more effective than either.
 
==The basic method==
One tries various values of ''a'', hoping that <math>a^2-N = b^2</math>, a square.
 
<code>
:FermatFactor(N): // N should be odd
:: a ← ceil(sqrt(N))
:: b2 ← a*a - N
:: while b2 isn't a square:
:::: a ← a + 1    // equivalently: b2 ← b2 + 2*a + 1
:::: b2 ← a*a - N //              a ← a + 1
:: endwhile
:: return a - sqrt(b2) // or a + sqrt(b2)
</code>
 
For example, to factor <math>N = 5959</math>, our first try for ''a'' is the square root of <math>5959</math> rounded up to the next integer which is <math>78</math>.  Then, <math>b^2 = 78^2-5959</math>.  Since ''b'' is not an integer, a second try is made by increasing the value of ''a'' by 1.  The second attempt again fails because ''b'' is not an integer.
{| class="wikitable"
! Try:
|    1 ||    2 ||  3
|-
! ''a''
|    78 ||    79 ||  80
|-
! ''b''<sup>2</sup>
|  125 ||  282 || 441
|-
! ''b''
| 11.18 || 16.79 ||  21
|}
 
The third try produces a perfect square so ''b'' is an integer. So, <math>a = 80</math>, <math>b = 21</math>, and the factors of <math>5959</math> are <math>a - b = 59</math>, and <math>a + b = 101</math>.
 
Suppose N has more than two prime factors. That procedure first finds the factorization with the least values of ''a'' and ''b''. That is, <math>a + b</math> is the smallest factor &ge; the square-root of ''N''. And so <math>a - b = N/(a + b)</math> is the largest factor &le; root-''N''. If the procedure finds <math>N=1 \cdot N</math>, that shows that ''N'' is prime.
 
For <math>N = cd</math>, let ''c'' be the largest subroot factor. <math>a = (c+d)/2</math>, so the number of steps is approximately <math>(c + d)/2 - \sqrt N = (\sqrt d - \sqrt c)^2 / 2 = (\sqrt N - c)^2 / 2c</math>.
 
If ''N'' is prime (so that <math>c = 1</math>), one needs <math>O(N)</math> steps! This is a bad way to prove primality. But if ''N'' has a factor close to its square-root, the method works quickly. More precisely, if c differs less than <math>{\left(4N\right)}^{1/4}</math> from <math>\sqrt N</math> the method requires only one step. Note, that this is independent of the size of N.
 
==Fermat's and trial division==
Consider trying to factor the prime number {{nowrap|1=''N'' = 2345678917}}, but also compute ''b'' and {{nowrap|''a'' − ''b''}} throughout.  Going up from <math>\sqrt{N}</math>, we can tabulate:
{| class="wikitable"
|-
! ''a''
|  48,433 ||  48,434 ||  48,435 ||  48,436
|-
! ''b''<sup>2</sup>
|  76,572 ||  173,439 ||  270,308 ||  367,179
|-
! ''b''
|    276.7 ||    416.5 ||    519.9 ||    605.9
|-
! ''a'' − ''b''
| 48,156.3 || 48,017.5 || 479,15.1 || 47,830.1
|}
 
In practice, one wouldn't bother with that last row, until ''b'' is an integer. But observe that if ''N'' had a subroot factor above <math>a-b=47830.1</math>, Fermat's method would have found it already.
 
Trial division would normally try up to 48,432; but after only four Fermat steps, we need only divide up to 47830, to find a factor or prove primality.
 
This all suggests a combined factoring method. Choose some bound <math>c > \sqrt{N}</math>; use Fermat for factors between <math>\sqrt{N}</math> and <math>c</math>.  This gives a bound for trial division which is <math>c - \sqrt{c^2 - N}</math>. In the above example, with <math>c = 48436</math> the bound for trial division is 47830. A reasonable choice could be <math>c = 55000</math> giving a bound of 28937.
 
In this regard, Fermat's method gives diminishing returns. One would surely stop before this point:
{| class="wikitable"
|-
! ''a''
|        60,001 ||        60,002
|-
! ''b''<sup>2</sup>
| 1,254,441,084 || 1,254,561,087
|-
! ''b''
|      35,418.1 ||      35,419.8
|-
! ''a'' − ''b''
|      24,582.9 ||      24,582.2
|}
 
==Sieve improvement==
 
It is not necessary to compute all the square-roots of <math>a^2-N</math>, nor even examine all the values for <math>a</math>. Examine the table for <math>N=2345678917</math>:
{| class="wikitable"
|-
! ''a''
| 48,433 ||  48,434 ||  48,435 ||  48,436
|-
! ''b''<sup>2</sup>
| 76,572 || 173,439 || 270,308 || 367,179
|-
! ''b''
|  276.7 ||  416.5 ||  519.9 ||  605.9
|}
 
One can quickly tell that none of these values of b2 are squares. Squares end with 0, 1, 4, 5, 9, or 16 [[Modular arithmetic|modulo]] 20. The values repeat with each increase of <math>a</math> by 10.  For this example, adding '-17' mod 20 (or 3), <math>a^2-N</math> produces 3, 4, 7, 8, 12, and 19 modulo 20 for these values.  It is apparent that only the 4 from this list can be a square.  Thus, <math>a^2</math> must be 1 mod 20, which means that <math>a</math> is 1 or 9 mod 10; it will produce a b2 which ends in 4 mod 20 and, if  square, <math>b</math> will end in 2 or 8 mod 10.
 
This can be performed with any modulus. Using the same <math>N=2345678917</math>,
{|
|-
|modulo 16:||Squares are ||0, 1, 4, or 9
|-
|          ||N mod 16 is||5
|-
|          ||so <math>a^2</math> can only be||9
|-
|          ||and <math>a</math> must be||3 or 5 or 11 or 13 modulo 16
|-
|modulo 9: ||Squares are ||0, 1, 4, or 7
|-
|          ||N mod 9 is||7
|-
|          ||so <math>a^2</math> can only be||7
|-
|          ||and <math>a</math> must be||4 or 5 modulo 9
|}
One generally chooses a power of a different prime for each modulus.
 
Given a sequence of ''a''-values (start, end, and step) and a modulus, one can proceed thus:
<code>
:FermatSieve(N, astart, aend, astep, modulus)
::a ← astart
::do modulus times:
:::b2 ← a*a - N
:::if b2 is a square, modulo modulus:
::::FermatSieve(N, a, aend, astep * modulus, NextModulus)
:::endif
:::a ← a + astep
::enddo
</code>
But the [[Recursion (computer science)|recursion]] is stopped when few ''a''-values remain; that is, when (aend-astart)/astep is small. Also, because ''a'''s step-size is constant, one can compute successive b2's with additions.
 
==Multiplier improvement==
 
Fermat's method works best when there is a factor near the square-root of ''N''.
 
If the approximate ratio of two factors (<math>d/c</math>) is known, then the [[rational number]] <math>v/u</math> can picked near that value. <math>Nuv = cv \cdot 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, if the ratio is not known, various <math>u/v</math> values can be tried, 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.<ref>{{cite journal |author=Lehman, R. Sherman|title=Factoring Large Integers |journal=[[Mathematics of Computation]] |year=1974 |volume=28 |issue=126 |pages=637-646 |doi=10.2307/2005940}}</ref>
 
==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 large [[semiprimes]], which are the "worst-case". The primary improvement that quadratic sieve makes over Fermat's factorization method is that instead of simply finding a square in the sequence of <math>a^2 - n</math>, it finds a subset of elements of this sequence whose ''product'' is a square, and it does this in a highly efficient manner. The end result is the same: a difference of square mod ''n'' that, if nontrivial, can be used to factor ''n''.
 
==See also==
*[[Completing the square]]
*[[Factorization of polynomials]]
*[[Factor theorem]]
*[[FOIL rule]]
*[[Monoid factorisation]]
*[[Pascal's triangle]]
*[[Prime factor]]
*[[Factorization]]
*[[Euler's factorization method]]
*[[Integer factorization]]
*[[Program synthesis]]
*[[Table of Gaussian integer factorizations]]
*[[Unique factorization domain|Unique factorization]]
 
==References==
{{reflist}}
*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).
 
==External links==
* [http://kadinumberprops.blogspot.in/2012/11/fermats-factorization-running-time.html Fermat's factorization running time], at blogspot.in
 
[[Category:Integer factorization algorithms]]
 
{{number theoretic algorithms}}

Latest revision as of 14:23, 8 December 2014

Glen Wendler is the title individuals use to contact me and my wife doesn't like it at all. Some time in the past she selected to live in Delaware but her spouse desires them to move. Dispatching has been my occupation for some time. Going to karaoke is some thing that I've carried out for many years. Go to my web site to discover out much more: http://www.socialairforce.com/groups/warning-nya-internet-svenska-casinon/

My homepage ... nya online casino