52 int n=
tmax (F.level(), G.level());
56 for (
int i = 0;
i <= n;
i++)
57 degsf[
i]= degsg[
i]= 0;
66 for (
int i= 1;
i <= n;
i++)
68 if (degsf[
i] != 0 && degsg[
i] != 0)
73 if (degsf[
i] == 0 && degsg[
i] != 0 &&
i <= G.level())
78 if (degsg[
i] == 0 && degsf[
i] &&
i <= F.level())
85 if (both_non_zero == 0)
95 for (
int i= 1;
i <= n;
i++)
97 if (degsf[
i] != 0 && degsg[
i] == 0 &&
i <= F.level())
99 if (k + both_non_zero !=
i)
106 if (degsf[
i] == 0 && degsg[
i] != 0 &&
i <= G.level())
108 if (l + g_zero + both_non_zero !=
i)
126 max_min_deg=
tmin (degsf[i], degsg[i]);
127 while (max_min_deg == 0)
130 max_min_deg=
tmin (degsf[i], degsg[i]);
132 for (
int j= i + 1;
j <=
m;
j++)
134 if ((
tmin (degsf[
j],degsg[j]) < max_min_deg) &&
135 (
tmin (degsf[j], degsg[j]) != 0))
137 max_min_deg=
tmin (degsf[j], degsg[j]);
196 for (k= evaluation.
length() + 1; k > 2; k--)
207 int l= evaluation.
length() + 1;
210 for (
int i= 2; i < l + 1; i++, j++)
224 int * degsf=
new int [n + 1];
226 for (
int i = 0; i <= n; i++)
232 ASSERT (A.
min() == 2,
"expected A.min() == 2");
247 for (
int j= i + 1;
j <= n;
j++)
249 if (degsf[
j] > max_deg)
265 if (k == 2 && n == 3)
302 LCs [1]= MM (LeadCoeffs [1]);
303 LCs [2]= MM (LeadCoeffs [2]);
306 long termEstimate=
size (U);
307 for (
int i= A.
min(); i <= A.
max(); i++)
312 termEstimate *=
degree (U,i)*2;
315 evaluation.
append (A [i]);
326 CFList shiftedLCsEval1, shiftedLCsEval2;
327 shiftedLCs[0]=
myShift2Zero (LCs[1], shiftedLCsEval1, evaluation);
328 shiftedLCs[1]=
myShift2Zero (LCs[2], shiftedLCsEval2, evaluation);
335 lcs [0]= shiftedLCsEval1.
getFirst();
336 lcs [1]= shiftedLCsEval2.
getFirst();
347 bool noOneToOne=
false;
350 liftBounds=
new int [U.
level() - 1];
351 liftBounds[0]= liftBound;
352 for (
int i= 1; i < U.
level() - 1; i++)
355 false, shiftedLCsEval1, shiftedLCsEval2, Pi,
356 diophant, noOneToOne);
357 delete [] liftBounds;
376 if( count == 0 && delta != 0)
378 if( count++ > maxeval )
395 if (count++ > maxeval)
401 if(
degree( Fb, 1 ) == degF )
404 if(
degree( Gb, 1 ) == degG )
409 if(
degree( Db, 1 ) <= delta )
431 if( count++ > maxeval )
444 int sizeF=
size (FF);
445 int sizeG=
size (GG);
450 if (sizeF/maxNumVars > 500 && sizeG/maxNumVars > 500)
463 CanonicalForm F,
G,
f,
g, d, Fb, Gb, Db, Fbt, Gbt, Dbt, B0,
B, D0, lcF, lcG,
465 CFArray DD( 1, 2 ), lcDD( 1, 2 );
486 int best_level= compress4EZGCD (F, G, M, N, smallestDegLev);
519 return N(d*
gcd(F,g));
524 return N(d*
gcd(G,f));
533 if (sizeF/maxNumVars > 500 && sizeG/maxNumVars > 500)
553 lcF =
LC( F, x ); lcG =
LC( G, x );
554 lcD =
gcd( lcF, lcG );
563 DEBOUTLN( cerr,
"search for evaluation, delta = " << delta );
567 if (!
findeval( F, G, Fb, Gb, Db, b, delta, degF, degG, maxeval, count,
580 DEBOUTLN( cerr,
"found evaluation b = " << b );
588 if (degF <= degG &&
fdivides (F, G))
598 else if (delta == degG)
600 if (degG <= degF &&
fdivides( G, F ))
623 if (!
findeval( F, G, Fbt, Gbt, Dbt, bt, delta, degF, degG, maxeval, count,
646 else if ( dd < delta )
650 Db = Dbt; Fb = Fbt; Gb = Gbt;
652 DEBOUTLN( cerr,
"now after A4, delta = " << delta );
656 if (degF <= degG &&
fdivides (F, G))
666 else if (delta == degG)
668 if (degG <= degF &&
fdivides( G, F ))
686 if ( delta != degF && delta != degG )
694 xxx1 =
gcd( DD[1], Db );
695 xxx2 =
gcd( buf, Db );
730 DD[2] = DD[2] * (
b( lcDD[2] ) /
lc( DD[2] ) );
731 DD[1] = DD[1] * (
b( lcDD[1] ) /
lc( DD[1] ) );
732 DEBOUTLN( cerr,
"(hensel) B = " << B );
734 DEBOUTLN( cerr,
"(hensel) b(B) = " <<
b(B) );
735 DEBOUTLN( cerr,
"(hensel) DD = " << DD );
736 DEBOUTLN( cerr,
"(hensel) lcDD = " << lcDD );
738 gcdfound=
Hensel (B*lcD, DD, b, lcDD);
740 DEBOUTLN( cerr,
"(hensel finished) DD = " << DD );
758 cand = DD[2] / contcand;
760 gcdfound =
fdivides( cand, G ) && cand*(DD[1]/(lcD/contcand)) == F;
762 gcdfound =
fdivides( cand, F ) && cand*(DD[1]/(lcD/contcand)) ==
G;
764 "time for termination test in EZ: ")
787 return ezgcd( FF, GG, b,
false );
810 if (FF == GG)
return FF/
Lc(FF);
814 int sizeF=
size (FF);
815 int sizeG=
size (GG);
817 if (sizeF/maxNumVars > sizePerVars1 && sizeG/maxNumVars > sizePerVars1)
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();
870 return N(d*
gcd(F,g));
875 return N(d*
gcd(G,f));
882 if (sizeF/maxNumVars > sizePerVars1 && sizeG/maxNumVars > sizePerVars1)
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);
static CanonicalForm myReverseShift(const CanonicalForm &F, const CFList &evaluation)
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 ...
static CanonicalForm ezgcd(const CanonicalForm &FF, const CanonicalForm &GG, REvaluation &b, bool internal)
real implementation of EZGCD over Z
generate random elements in GF
Conversion to and from NTL.
This file defines functions for Hensel lifting.
static CanonicalForm bound(const CFMatrix &M)
void prune1(const Variable &alpha)
const CanonicalForm CFMap & M
some useful template functions.
functions to print debug output
template CanonicalForm tmax(const CanonicalForm &, const CanonicalForm &)
#define TIMING_END_AND_PRINT(t, msg)
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 ...
#define DEBINCLEVEL(stream, msg)
factory's class for variables
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
generate random evaluation points
static Evaluation optimize4Lift(const CanonicalForm &F, CFMap &M, CFMap &N, const Evaluation &A)
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...
const CanonicalForm int const CFList & evaluation
#define DEBDECLEVEL(stream, msg)
static const double log2exp
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Extended Zassenhaus GCD over finite fields and Z.
bool delta(X x, Y y, D d)
void prune(Variable &alpha)
This file implements functions to map between extensions of finite fields.
CFList nonMonicHenselLift2(const CFList &F, const CFList &factors, const CFList &MOD, CFList &diophant, CFArray &Pi, CFMatrix &M, int lOld, int &lNew, const CFList &LCs1, const CFList &LCs2, bool &bad)
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)
CanonicalForm GFMapDown(const CanonicalForm &F, int k)
maps a polynomial over to a polynomial over , d needs to be a multiple of k
Variable rootOf(const CanonicalForm &, char name= '@')
returns a symbolic root of polynomial with name name Use it to define algebraic variables ...
void setValue(int i, const CanonicalForm &f)
static const int SW_RATIONAL
set to 1 for computations over Q
generate random elements in F_p
generate random integers, random elements of finite fields
declarations of higher level algorithms.
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
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...
CanonicalForm EZGCD_P(const CanonicalForm &FF, const CanonicalForm &GG)
Extended Zassenhaus GCD for finite fields. In case things become too dense we switch to a modular alg...
bool fdivides(const CanonicalForm &f, const CanonicalForm &g)
bool fdivides ( const CanonicalForm & f, const CanonicalForm & g )
void newpair(const Variable &v, const CanonicalForm &s)
void CFMap::newpair ( const Variable & v, const CanonicalForm & s )
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 )
class to evaluate a polynomial at points
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)
static const int SW_USE_EZGCD
set to 1 to use EZGCD over Z
#define GaloisFieldDomain
bool isZero(const CFArray &A)
checks if entries of A are zero
modular and sparse modular GCD algorithms over finite fields and Z.
static int Hensel(const CanonicalForm &UU, CFArray &G, const Evaluation &AA, const CFArray &LeadCoeffs)
const CanonicalForm CFMap CFMap int & both_non_zero
TIMING_DEFINE_PRINT(ez_eval) TIMING_DEFINE_PRINT(ez_compress) TIMING_DEFINE_PRINT(ez_hensel_lift) TIMING_DEFINE_PRINT(ez_content) TIMING_DEFINE_PRINT(ez_termination) static int compress4EZGCD(const CanonicalForm &F
#define ASSERT(expression, message)
#define DEBOUTLN(stream, objects)
CanonicalForm mapPrimElem(const CanonicalForm &primElem, const Variable &alpha, const Variable &beta)
compute the image of a primitive element of in . We assume .
void nonMonicHenselLift12(const CanonicalForm &F, CFList &factors, int l, CFArray &Pi, CFList &diophant, CFMatrix &M, const CFArray &LCs, bool sort)
Hensel lifting from univariate to bivariate, factors need not to be monic.
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
template CanonicalForm tmin(const CanonicalForm &, const CanonicalForm &)
static CanonicalForm myShift2Zero(const CanonicalForm &F, CFList &Feval, const CFList &evaluation)