33const int max_fp_fac = 3;
38#define DEBOUTHPRINT(stream, msg, hg) \
39{std::stream << deb_level_msg << msg, std::stream.flush(); hprint( hg ); std::stream << std::endl;}
45 std::cerr <<
"( " << n <<
": ";
49 std::cerr <<
i <<
" ";
55#define DEBOUTHPRINT(stream, msg, hg)
63 for (
i = 1;
i < n;
i++ )
65 for (
j = 1;
j <=
i;
j++ )
67 for (
k =
i;
k < n;
k +=
j )
72hintersect(
int * a,
const int *
const b )
74 int i, n, na = a[0], nb =
b[0];
79 for (
i = 1;
i < n;
i++ )
97initHG (
int * a,
const CFFList & F )
102 for (
int j = 1;
j < n;
j++ ) a[
j] = 0;
103 for (
i = F;
i.hasItem();
i++ )
104 if ( (
k =
i.getItem().factor().degree()) < n )
107 STICKYWARN(
k == -1,
"there occured an error. factory was not able to factorize\n"
108 "correctly mod p. Please send the example which caused\n"
109 "this error to the authors. Nonetheless we will go on with the\n"
110 "calculations hoping the result will be correct. Thank you." );
120 int i, n = a[0],
m = F.
size(),
k;
121 for (
i = 1;
i < n;
i++ ) a[
i] = 0;
122 for (
i = 1;
i <
m;
i++ )
127 STICKYWARN(
k == -1,
"there occured an error. factory was not able to factorize\n"
128 "correctly mod p. Please send the example which caused\n"
129 "this error to the authors. Nonetheless we will go on with the\n"
130 "calculations hoping the result will be correct. Thank you." );
191 if (
i >= theFactors.
size() )
195 DEBOUTLN( cerr,
"ldfr (g) = " << theFactors[
i] );
197 DEBOUTLN( cerr,
"ldfr (pk(f*g)) = " <<
g );
208 return liftDegreeFactRec( theFactors, F, recip_lf,
f, pk,
i+1, d, ZF,
exp );
214 bool ok = liftDegreeFactRec( theFactors, F, recip_lf, pk( recip_lf *
f * theFactors[
i] ), pk,
i+1, d, ZF,
exp );
218 ok = liftDegreeFactRec( theFactors, F, recip_lf,
f, pk,
i+1, d, ZF,
exp );
225 return gcd(
f,
f.deriv() ).degree() == 0;
238 return isSqrFreeZ(
f );
240 return isSqrFreeFp(
f );
251 while ( ptr < maxp &&
i < max_fp_fac )
254 if (
mod(
lc(
f ), prime ) != 0 )
266 return (
i == max_fp_fac );
274 CanonicalForm a,
b, aa, bb, c,
g,
h, g1, h1, e, modulus, tmp, q, r;
278 int * kvals =
new int[no_iter];
280 DEBOUTLN( cerr,
"quadratic lift called with p = " <<
p <<
" and k = " <<
k );
281 for (
j = 0,
i =
k;
i > 1;
i = (
i+1 ) / 2,
j++ ) kvals[
j] =
i;
302 while ( ! e.
isZero() &&
j > 0 ) {
307 DEBOUTLN( cerr,
"lifting from p^" << kvals[
j+1] <<
" to p^" << kvals[
j] );
316 a += ( ( 1 - a * g1 ) * a ) % h1;
317 b += ( ( 1 -
b * h1 ) *
b ) % g1;
320 divrem( a * c, h1, q, r );
321 tmp =
b * c + q * g1;
330 if (
mod(
f -
g *
h, modulus ) != 0 ) {
331 DEBOUTLN( cerr,
"error at lift stage " <<
i );
337 gk =
g / tmp; hk =
h / ( lf / tmp );
340 gk = pk(
g); hk = pk(
h);
351 CanonicalForm a,
b, c,
g,
h, g1, h1, e, modulus, tmp, q, r;
376 divrem( a * c, h1, q, r );
377 tmp =
b * c + q * g1;
385 ASSERT(
mod(
f -
g *
h, modulus ) == 0,
"error at lift stage" );
390 gk =
g / tmp; hk =
h / ( lf / tmp );
393 gk = pk(
g); hk = pk(
h);
397 return (F-gk*hk).isZero();
411 int *
p =
new int [max_fp_fac];
430 if (
f.inCoeffDomain() )
continue;
431 n =
f.degree() / 2 + 1;
434 D =
new int [n];
D[0] = n;
435 Dh =
new int [n]; Dh[0] = n;
440 ok = choosePrimes(
p,
f );
443 DEBOUTLN( cerr,
"warning: no good prime found to factorize " <<
f );
444 STICKYWARN( ok,
"there occured an error. We went out of primes p\n"
445 "to factorize mod p. Please send the example which caused\n"
446 "this error to the authors. Nonetheless we will go on with the\n"
447 "calculations hoping the result will be correct. Thank you.");
454 for (
i = 0;
i < max_fp_fac;
i++ ) {
462 DEBOUTLN( cerr,
"F[i] = " << F[
i] <<
", p = " <<
p[
i] );
470 DEBOUTHPRINT( cerr,
"D = ",
D );
471 for (
i = 1;
i < max_fp_fac;
i++ ) {
474 DEBOUTHPRINT( cerr,
"Dh = ", Dh );
476 DEBOUTHPRINT( cerr,
"D = ",
D );
483 for (
i = 1;
i < max_fp_fac;
i++ ) {
488 k = kBound(
f,
p[
j] );
497 F[
j].
sort( cmpFactor );
503 ok = UnivariateQuadraticLift(
f, I.
getItem().factor(),
fp / I.
getItem().factor(), pk,
lc(
f ), dummy1, dummy2 );
505 ok = UnivariateLinearLift(
f, I.
getItem().factor(),
fp / I.
getItem().factor(), pk,
lc(
f ), dummy1, dummy2 );
508 DEBOUTLN( cerr,
"dummy1 = " << dummy1 );
509 DEBOUTLN( cerr,
"dummy2 = " << dummy2 );
520 DEBOUTLN( cerr,
"dummy1 = " << dummy1 );
523 theFactors[
i] = pk( dummy1 );
531 initHG( Dh, theFactors );
533 DEBOUTHPRINT( cerr,
"Dh = ", Dh );
538 DEBOUTLN( cerr,
"theFactors = " << theFactors );
541 DEBOUTHPRINT( cerr,
"D = ",
D );
544 DEBOUTLN( cerr,
"recip_lf = " << recip_lf );
546 for (
i = 1;
i <
D[0];
i++ )
548 while ( liftDegreeFactRec( theFactors,
f, recip_lf, lf, pk, 0,
i, ZF,
exp ) );
555 if ( ZF.
getFirst().factor().inCoeffDomain() )
557 if (
lc( ff ).
sign() < 0 )
This file defines functions for conversion to FLINT (www.flintlib.org) and back.
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
univariate Gcd over finite fields and Z, extended GCD over finite fields and Q
CanonicalForm euclideanNorm(const CanonicalForm &f)
CanonicalForm euclideanNorm ( const CanonicalForm & f )
declarations of higher level algorithms.
CFFList FACTORY_PUBLIC sqrFree(const CanonicalForm &f, bool sort=false)
squarefree factorization
#define STICKYWARN(expression, message)
#define ASSERT(expression, message)
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
static const int SW_FAC_QUADRATICLIFT
Iterators for CanonicalForm's.
void remove(int moveright)
void sort(int(*)(const T &, const T &))
factory's class for variables
class to do operations mod p^k for int's p and k
CanonicalForm getpk() const
functions to print debug output
#define DEBINCLEVEL(stream, msg)
#define DEBOUTLN(stream, objects)
#define DEBDECLEVEL(stream, msg)
CFFList FpFactorizeUnivariateCZ(const CanonicalForm &f, bool issqrfree, int numext, const Variable alpha, const Variable beta)
squarefree part and factorization over Q, Q(a)
CFFList sqrFreeFp(const CanonicalForm &f)
bool isSqrFree(const CanonicalForm &f)
CFFList ZFactorizeUnivariate(const CanonicalForm &ff, bool issqrfree=false)
CanonicalForm replaceLc(const CanonicalForm &f, const CanonicalForm &c)
operations mod p^k and some other useful functions for factorization
static int min(int a, int b)
static BOOLEAN length(leftv result, leftv arg)
gmp_float exp(const gmp_float &a)
static int SI_LOG2(int v)
#define TIMING_DEFINE_PRINT(t)
#define TIMING_END_AND_PRINT(t, msg)