Extended Zassenhaus GCD for finite fields. In case things become too dense we switch to a modular algorithm.
808 if (FF.isUnivariate() &&
fdivides(FF,
GG))
return FF/
Lc(FF);
810 if (FF ==
GG)
return FF/
Lc(FF);
814 int sizeF=
size (FF);
827 CanonicalForm F,
G,
f,
g, d, Fb, Gb, Db, Fbt, Gbt, Dbt, B0,
B, D0, lcF, lcG,
829 CFArray DD( 1, 2 ), lcDD( 1, 2 );
845 int best_level= compress4EZGCD (F, G, M, N, smallestDegLev);
847 if (best_level == 0)
return G.genOne();
859 if( F.isUnivariate() && G.isUnivariate() )
861 if( F.mvar() == G.mvar() )
867 if ( F.isUnivariate())
870 return N(d*
gcd(F,g));
872 if ( G.isUnivariate())
875 return N(d*
gcd(G,f));
898 bool passToGF=
false;
899 bool extOfExt=
false;
911 else if (p == 5 || p == 7)
944 bool primFail=
false;
947 ASSERT (!primFail,
"failure in integer factorizer");
951 BuildIrred (NTLIrredpoly, d*3);
958 BuildIrred (NTLIrredpoly, d*2);
965 else if ((p == 3 && d < 4) || ((p == 5 || p == 7) && d < 3))
972 bool primFail=
false;
975 ASSERT (!primFail,
"failure in integer factorizer");
977 BuildIrred (NTLIrredpoly, d*2);
986 F=
mapUp (F, a, v2, primElem, imPrimElem, source, dest);
987 G=
mapUp (G, a, v2, primElem, imPrimElem, source, dest);
992 lcF =
LC( F, x ); lcG =
LC( G, x );
993 lcD =
gcd( lcF, lcG );
1013 int goodPointCount= 0;
1017 if( !
findeval( F, G, Fb, Gb, Db, b, delta, degF, degG, maxeval, count, o,
1018 maxeval/maxNumVars, t ))
1038 result=
mapDown (result, primElem, imPrimElem, oldA, dest, source);
1041 return N (d*result);
1047 if (degF <= degG &&
fdivides (F, G))
1064 F=
mapDown (F, primElem, imPrimElem, oldA, dest, source);
1072 else if (delta == degG)
1074 if (degG <= degF &&
fdivides (G, F))
1091 G=
mapDown (G, primElem, imPrimElem, oldA, dest, source);
1111 if( !
findeval(F,G,Fbt,Gbt,Dbt, bt, delta, degF, degG, maxeval, count, o,
1112 maxeval/maxNumVars, t ))
1132 result=
mapDown (result, primElem, imPrimElem, oldA, dest, source);
1135 return N (d*result);
1150 if (goodPointCount == 5)
1158 Db = Dbt; Fb = Fbt; Gb = Gbt;
1162 if (degF <= degG &&
fdivides (F, G))
1179 F=
mapDown (F, primElem, imPrimElem, oldA, dest, source);
1187 else if (delta == degG)
1189 if (degG <= degF &&
fdivides (G, F))
1206 G=
mapDown (G, primElem, imPrimElem, oldA, dest, source);
1223 if( delta != degF && delta != degG )
1230 xxx1 =
gcd( DD[1], Db );
1231 xxx2 =
gcd( buf, Db );
1273 result=
mapDown (result, primElem, imPrimElem, oldA, dest, source);
1276 return N (d*result);
1278 DD[2] = DD[2] * (
b( lcDD[2] ) /
lc( DD[2] ) );
1279 DD[1] = DD[1] * (
b( lcDD[1] ) /
lc( DD[1] ) );
1288 result=
mapDown (result, primElem, imPrimElem, oldA, dest, source);
1291 return N (d*result);
1309 return N (d*result);
1316 gcdfound=
Hensel (B*lcD, DD, b, lcDD);
1326 result=
mapDown (result, primElem, imPrimElem, oldA, dest, source);
1329 return N (d*result);
1347 return N (d*result);
1362 cand = DD[2] / contcand;
1364 gcdfound =
fdivides( cand, G ) && cand*(DD[1]/(lcD/contcand)) == F;
1366 gcdfound =
fdivides( cand, F ) && cand*(DD[1]/(lcD/contcand)) ==
G;
1368 "time for termination test EZ_P: ");
1370 if (passToGF && gcdfound)
1378 if (k > 1 && gcdfound)
1383 if (extOfExt && gcdfound)
1385 cand=
mapDown (cand, primElem, imPrimElem, oldA, dest, source);
TIMING_END_AND_PRINT(fac_alg_resultant, "time to compute resultant0: ")
int status int void size_t count
static CanonicalForm mapDown(const CanonicalForm &F, const Variable &alpha, const CanonicalForm &G, CFList &source, CFList &dest)
the CanonicalForm G is the output of map_up, returns F considered as an element over ...
generate random elements in GF
void prune1(const Variable &alpha)
const CanonicalForm CFMap & M
template CanonicalForm tmax(const CanonicalForm &, const CanonicalForm &)
TIMING_START(fac_alg_resultant)
CanonicalForm primitiveElement(const Variable &alpha, Variable &beta, bool &fail)
determine a primitive element of , is a primitive element of a field which is isomorphic to ...
factory's class for variables
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
static bool findeval(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Fb, CanonicalForm &Gb, CanonicalForm &Db, REvaluation &b, int delta, int degF, int degG, int maxeval, int &count, int &k, int bound, int &l)
CanonicalForm sparseGCDFp(const CanonicalForm &F, const CanonicalForm &G, bool &topLevel, CFList &l)
class to generate random evaluation points
CanonicalForm convertNTLzzpX2CF(const zz_pX &poly, const Variable &x)
CanonicalForm modGCDGF(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &coF, CanonicalForm &coG, CFList &l, bool &topLevel)
GCD of F and G over GF, based on Alg. 7.2. as described in "Algorithms for Computer Algebra" by Gedde...
static const double log2exp
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
bool delta(X x, Y y, D d)
void prune(Variable &alpha)
Variable rootOf(const CanonicalForm &, char name='@')
returns a symbolic root of polynomial with name name Use it to define algebraic variables ...
bool gcd_test_one(const CanonicalForm &f, const CanonicalForm &g, bool swap, int &d)
Coprimality Check. f and g are assumed to have the same level. If swap is true, the main variables of...
static CanonicalForm mapUp(const Variable &alpha, const Variable &beta)
and is a primitive element, returns the image of
const CanonicalForm CFMap CFMap & N
int status int void * buf
CanonicalForm modGCDFp(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &coF, CanonicalForm &coG, bool &topLevel, CFList &l)
for(int i=0;i<=n;i++) degsf[i]
CanonicalForm GFMapDown(const CanonicalForm &F, int k)
maps a polynomial over to a polynomial over , d needs to be a multiple of k
generate random elements in F_p
CanonicalForm modGCDFq(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &coF, CanonicalForm &coG, Variable &alpha, CFList &l, bool &topLevel)
GCD of F and G over , l and topLevel are only used internally, output is monic based on Alg...
bool fdivides(const CanonicalForm &f, const CanonicalForm &g)
bool fdivides ( const CanonicalForm & f, const CanonicalForm & g )
CanonicalForm GF2FalphaRep(const CanonicalForm &F, const Variable &alpha)
changes representation by primitive element to representation by residue classes modulo a Conway poly...
generate random elements in F_p(alpha)
int ipower(int b, int m)
int ipower ( int b, int m )
CanonicalForm GFMapUp(const CanonicalForm &F, int k)
maps a polynomial over to a polynomial over , d needs to be a multiple of k
int cf_getBigPrime(int i)
#define GaloisFieldDomain
static int Hensel(const CanonicalForm &UU, CFArray &G, const Evaluation &AA, const CFArray &LeadCoeffs)
#define ASSERT(expression, message)
CanonicalForm mapPrimElem(const CanonicalForm &primElem, const Variable &alpha, const Variable &beta)
compute the image of a primitive element of in . We assume .
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
template CanonicalForm tmin(const CanonicalForm &, const CanonicalForm &)