Square form factorization: Difference between revisions

m
Tightened the intro
m (→‎{{header|Wren}}: Added a word to the preamble.)
m (Tightened the intro)
Line 1:
{{draft task|mathematicsMathematics}}
 
 
Line 6:
[[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.&#8217;''
 
An integral [[wp:Binary_quadratic_form|binary quadratic form]] is a polynomial
{{math|''f''(''x,y'') &#61; ''ax<sup>2</sup>'' + ''bxy'' + ''cy<sup>2</sup>''}}
with integer coefficients and discriminant {{math|''D'' &#61; ''b<sup>2</sup>'' &#8211; ''4ac''}}.
For each positive discriminant there are nearly always multiple forms {{math|(''a, b, c'')}}.
 
The next form in a periodic sequence (cycle) of adjacent forms is found by applying a reduction operator ''rho''.
It''rho'', isessentially a variant of Euclid's algorithm for finding the continued fraction of a square root. Using
Using {{math|floor(''&#8730;N'')}}, rho constructs a ''principal form''
{{math|(''1, b, c'')}} with {{math|''D'' &#61; ''4N''}}.
 
SquFoF worksis becausebased thereon arethe 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'')}}, easycalled tosymmetry spot and obviously calledpoints.
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>'' &#8211; ''4ac'' &#61; ''a''(''a&#183;k<sup>2</sup>'' &#8211; ''4c'') &#61; ''4N''}}
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 aany form onin an ambiguous cycle
is squared, that square form will always land in the principal cycle. Conversely, the square root of aany
form onin 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
Line 39 ⟶ 36:
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 a proper square formsform. 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.
(A short trial division loop acts as sentry). If N is prime or the cube of a prime, there are only trivialimproper squares only
and the program will duly report failure.
 
Line 69 ⟶ 66:
 
type arg
'SquFoFsqufof arguments
as ulong m, f
as integer vb
Line 100 ⟶ 97:
dim shared N as ulongint
'the number to split
 
dim shared flag as integer
'signal to end all threads
Line 398 ⟶ 396:
</lang>
 
{{out|(No need to replicate all)Examples}}
<pre>
N = 2501