Square form factorization: Difference between revisions
Content deleted Content added
m →{{header|Wren}}: Added a word to the preamble. |
m Tightened the intro |
||
Line 1: | Line 1: | ||
{{ |
{{task|Mathematics}} |
||
Line 6: | Line 6: | ||
[[wp:Daniel_Shanks|Daniel Shanks]]'s Square Form Factorization [[wp:Shanks%27s_square_forms_factorization|(SquFoF)]]. |
[[wp:Daniel_Shanks|Daniel Shanks]]'s Square Form Factorization [[wp:Shanks%27s_square_forms_factorization|(SquFoF)]]. |
||
Invented around 1975, ''‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm'' |
|||
''for numbers between 10<sup>10</sup> and 10<sup>18</sup>, and will likely remain so.’'' |
|||
An integral [[wp:Binary_quadratic_form|binary quadratic form]] is a polynomial |
An integral [[wp:Binary_quadratic_form|binary quadratic form]] is a polynomial |
||
{{math|''f''(''x,y'') = ''ax<sup>2</sup>'' + ''bxy'' + ''cy<sup>2</sup>''}} |
{{math|''f''(''x,y'') = ''ax<sup>2</sup>'' + ''bxy'' + ''cy<sup>2</sup>''}} |
||
with integer coefficients and discriminant {{math|''D'' = ''b<sup>2</sup>'' – ''4ac''}}. |
with integer coefficients and discriminant {{math|''D'' = ''b<sup>2</sup>'' – ''4ac''}}. |
||
For each positive discriminant there are |
For each positive discriminant there are multiple forms {{math|(''a, b, c'')}}. |
||
The next form in a periodic sequence (cycle) of adjacent forms is found by applying a reduction operator |
The next form in a periodic sequence (cycle) of adjacent forms is found by applying a reduction operator |
||
''rho'', essentially a variant of Euclid's algorithm for finding the continued fraction of a square root. |
|||
{{math|floor(''√N'')}}, rho constructs a ''principal form'' |
Using {{math|floor(''√N'')}}, rho constructs a ''principal form'' |
||
{{math|(''1, b, c'')}} with {{math|''D'' = ''4N''}}. |
{{math|(''1, b, c'')}} with {{math|''D'' = ''4N''}}. |
||
SquFoF |
SquFoF is based on the existence of cycles containing ''ambiguous forms'', with the property that ''a'' divides ''b''. |
||
They come in pairs of associated forms {{math|(''a, b, c'') and (''c, b, a'')}} |
They come in pairs of associated forms {{math|(''a, b, c'') and (''c, b, a'')}} called symmetry points. |
||
If an ambiguous form is found (there is one for each divisor of D), write the discriminant as |
|||
{{math|(''ak'')''<sup>2</sup>'' – ''4ac'' = ''a''(''a·k<sup>2</sup>'' – ''4c'') = ''4N''}} |
{{math|(''ak'')''<sup>2</sup>'' – ''4ac'' = ''a''(''a·k<sup>2</sup>'' – ''4c'') = ''4N''}} |
||
and (if a is not equal to 1 or 2) N is split. |
and (if a is not equal to 1 or 2) N is split. |
||
Shanks used ''square forms'' to jump to a random ambiguous cycle. Fact: if |
Shanks used ''square forms'' to jump to a random ambiguous cycle. Fact: if any form in an ambiguous cycle |
||
is squared, that square form will always land in the principal cycle. Conversely, the square root of |
is squared, that square form will always land in the principal cycle. Conversely, the square root of any |
||
form |
form in the principal cycle lies in an ambiguous cycle. (Possibly the principal cycle itself). |
||
A square form is easy to find: the last coefficient ''c'' is a perfect square. This happens about once |
A square form is easy to find: the last coefficient ''c'' is a perfect square. This happens about once |
||
Line 39: | Line 36: | ||
no roots land in the principal cycle itself and cases a = 1 or a = 2 do not happen. |
no roots land in the principal cycle itself and cases a = 1 or a = 2 do not happen. |
||
Sometimes the cycle length is too short to find proper square |
Sometimes the cycle length is too short to find a proper square form. This is fixed by running five instances |
||
of SquFoF in parallel, with input N and 3, 5, 7, 11 times N; the discriminants then will have different periods. |
of SquFoF in parallel, with input N and 3, 5, 7, 11 times N; the discriminants then will have different periods. |
||
(A |
(A trial division loop acts as sentry). If N is prime or the cube of a prime, there are improper squares only |
||
and the program will duly report failure. |
and the program will duly report failure. |
||
Line 69: | Line 66: | ||
type arg |
type arg |
||
' |
'squfof arguments |
||
as ulong m, f |
as ulong m, f |
||
as integer vb |
as integer vb |
||
Line 100: | Line 97: | ||
dim shared N as ulongint |
dim shared N as ulongint |
||
'the number to split |
'the number to split |
||
dim shared flag as integer |
dim shared flag as integer |
||
'signal to end all threads |
'signal to end all threads |
||
Line 398: | Line 396: | ||
</lang> |
</lang> |
||
{{out| |
{{out|Examples}} |
||
<pre> |
<pre> |
||
N = 2501 |
N = 2501 |