<Section Label="sec:Factors">
<Heading>The method for <C>Factors</C></Heading>
The &FactInt; package provides a better method for the operation
<C>Factors</C> for integer arguments, which supersedes the one included in
the &GAP; Library:
<ManSection>
<Meth Name="Factors" Arg="n" Label="FactInt's method, for integers"/>
<Returns>
a sorted list of the prime factors of <A>n</A>.
</Returns>
<Description>
<Index Key="primality of the factors">primality of the factors</Index>
The returned factors pass the built-in probabilistic primality test of
&GAP; (<C>IsProbablyPrimeInt</C>, Baillie-PSW Primality Test; see the
&GAP; Reference Manual).
If the method fails to compute the prime factorization of <A>n</A>,
an error is signalled.
The same holds for all other factorization routines provided by this
package.
It follows a rough description how the factorization method works: <P/>
First of all, the method checks whether <M>n = b^k \pm 1</M> for some
<M>b</M>, <M>k</M> and looks for factors corresponding to polynomial
factors of <M>x^k \pm 1</M>.
Provided that <M>b</M> and <M>k</M> are not too large, the factors that
do not correspond to polynomial factors are taken from Richard P. Brent's
Factor Tables <Cite Key="Brent04"/>.
The code for accessing these tables has been contributed by Frank Lübeck.
<P/>
Then the method uses trial division and a number of cheap methods for
various common special cases.
After the small and other <Q>easy</Q> factors have been found this way,
&FactInt;'s method searches for medium-sized factors using
Pollard's Rho (by the library function FactorsRho, see the &GAP;
Reference Manual), Pollard's p-1
(see <Ref Func="FactorsPminus1" Label="Pollard's p-1"/>),
Williams' p+1
(see <Ref Func="FactorsPplus1" Label="Williams' p+1"/>)
and the Elliptic Curves Method (ECM,
see <Ref Func="FactorsECM" Label="Elliptic Curves Method, ECM"/>)
in this order. <P/>
If there is still an unfactored part remaining after that,
it is factored using the Multiple Polynomial Quadratic Sieve (MPQS,
see <Ref Func="FactorsMPQS"
Label="Multiple Polynomial Quadratic Sieve, MPQS"/>).
<P/>
The following options are interpreted:
<List>
<Mark><A>TDHints</A></Mark>
<Item>
A list of additional trial divisors.
This is useful only if certain primes <M>p</M> are expected to
divide <M>n</M> with probability significantly larger than
<M>\frac{1}{p}</M>.
</Item>
<Mark><A>RhoSteps</A></Mark>
<Item>
The number of steps for Pollard's Rho.
</Item>
<Mark><A>RhoCluster</A></Mark>
<Item>
The number of steps between two gcd computations in Pollard's Rho.
</Item>
<Mark><A>Pminus1Limit1</A> / <A>Pminus1Limit2</A></Mark>
<Item>
The first- / second stage limit for Pollard's p-1
(see <Ref Func="FactorsPminus1" Label="Pollard's p-1"/>).
</Item>
<Mark><A>Pplus1Residues</A></Mark>
<Item>
The number of residues to be tried by Williams' p+1
(see <Ref Func="FactorsPplus1" Label="Williams' p+1"/>).
</Item>
<Mark><A>Pplus1Limit1</A> / <A>Pplus1Limit2</A></Mark>
<Item>
The first- / second stage limit for Williams' p+1
(see <Ref Func="FactorsPplus1" Label="Williams' p+1"/>).
</Item>
<Mark><A>ECMCurves</A></Mark>
<Item>
The number of elliptic curves to be tried by the
Elliptic Curves Method (ECM)
(see <Ref Func="FactorsECM"
Label="Elliptic Curves Method, ECM"/>).
Also admissible: a function that takes the number <M>n</M> to be
factored as an argument and returns the desired number
of curves to be tried.
</Item>
<Mark><A>ECMLimit1</A> / <A>ECMLimit2</A></Mark>
<Item>
The initial first- / second stage limit for ECM
(see <Ref Func="FactorsECM"
Label="Elliptic Curves Method, ECM"/>).
</Item>
<Mark><A>ECMDelta</A></Mark>
<Item>
The increment per curve for the first
stage limit in ECM. The second stage limit is adjusted appropriately
(see <Ref Func="FactorsECM"
Label="Elliptic Curves Method, ECM"/>).
</Item>
<Mark><A>ECMDeterministic</A></Mark>
<Item>
If true, ECM chooses its curves deterministically, i.e. repeatable
(see <Ref Func="FactorsECM"
Label="Elliptic Curves Method, ECM"/>).
</Item>
<Mark><A>FBMethod</A></Mark>
<Item>
Specifies which of the factor base methods should be
used to do the <Q>hard work</Q>. Currently implemented:
<C>"CFRAC"</C> and <C>"MPQS"</C>
(see <Ref Func="FactorsCFRAC"
Label="Continued Fraction Algorithm, CFRAC"/>
and <Ref Func="FactorsMPQS"
Label="Multiple Polynomial Quadratic Sieve, MPQS"/>,
respectively).
Default: <C>"MPQS"</C>.
</Item>
</List>
For the use of the &GAP; Options Stack, see Chapter <E>Options Stack</E>
in the &GAP; Reference Manual. <P/>
Setting <A>RhoSteps</A>, <A>Pminus1Limit1</A>, <A>Pplus1Residues</A>,
<A>Pplus1Limit1</A>, <A>ECMCurves</A> or <A>ECMLimit1</A> equal to zero
switches the respective method off. The method chooses defaults for all
option values that are not explicitly set by the user. The option values
are also interpreted by the routines for the particular factorization
methods described in the next chapter.
<Example>
<![CDATA[
gap> Factors( Factorial(44) + 1 );
[ 694763, 9245226412016162109253, 413852053257739876455072359 ]
gap> Factors( 2^997 - 1 );
[ 167560816514084819488737767976263150405095191554732902607,
79934306053602222928609369601238840619880168466272137576868879760059\
3002563860297371289151859287894468775962208410650878341385577817736702\
2158878920741413700868182301410439178049533828082651513160945607018874\
830040978453228378816647358334681553 ]
]]>
</Example>
</Description>
</ManSection>
The above method for <C>Factors</C> calls the following function,
which is the actual <Q>working horse</Q> of this package:
<ManSection>
<Func Name="FactInt" Arg="n" Label="factorization of an integer"/>
<Returns>
a list of two lists, where the first list contains the determined
prime factors of <A>n</A> and the second list contains the
remaining unfactored parts of <A>n</A>, if there are any.
</Returns>
<Description>
This function interprets all options which are interpreted by the
method for <C>Factors</C> described above. In addition, it interprets
the options <A>cheap</A> and <A>FactIntPartial</A>.
If the option <A>cheap</A> is set, only usually
cheap factorization attempts are made.
If the option <A>FactIntPartial</A> is set, the factorization process
is stopped before invoking the (usually time-consuming) MPQS or CFRAC,
if the number of digits of the remaining unfactored part exceeds the
bound passed as option value <A>MPQSLimit</A> or <A>CFRACLimit</A>,
respectively. <P/>
<Section Label="sec:Info">
<Heading>Getting information about the factoring process</Heading>
<Index Key="information about factoring process">
information about factoring process
</Index>
Optionally, the &FactInt; package prints information on the progress of
the factorization process:
<ManSection>
<InfoClass Name="InfoFactInt"
Label="FactInt's Info class"/>
<Func Name="FactIntInfo" Arg="level"
Label="setting the InfoLevel of InfoFactInt"/>
<Description>
This Info class allows to monitor what happens during the factoring
process. <P/>
If <C>InfoLevel(InfoFactInt) = 1</C>, then basic information
about the factoring techniques used is displayed. If this InfoLevel has
value 2, then additionally all <Q>relevant</Q> steps in the
factoring algorithms are mentioned. If it is set equal to 3, then
large amounts of details of the progress of the factoring process are
shown. <P/>
Enter <C>FactIntInfo(<A>level</A>)</C> to set the
<C>InfoLevel</C> of <C>InfoFactInt</C> to the positive
integer <A>level</A>. The call <C>FactIntInfo(<A>level</A>);</C>
is equivalent to <C>SetInfoLevel(InfoFactInt,<A>level</A>);</C>. <P/>
The informational output is usually not literally the same in
each factorization attempt to a given integer with given parameters.
For a description of the Info mechanism, see Section
<E>Info Functions</E> in the &GAP; Reference Manual.
</Description>
</ManSection>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.