Skip to content

Commit f6237dd

Browse files
committed
chg: faster computation of resultants
Conflicts: factory/cfModResultant.cc
1 parent 1e5c50f commit f6237dd

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

factory/cfModResultant.cc

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "config.h"
1414

1515
#include "cf_assert.h"
16+
#include "timing.h"
1617

1718
#include "cfModResultant.h"
1819
#include "cf_primes.h"
@@ -29,6 +30,8 @@
2930
#include "FLINTconvert.h"
3031
#endif
3132

33+
TIMING_DEFINE_PRINT(fac_resultant_p)
34+
3235
//TODO arrange by bound= deg (F,xlevel)*deg (G,i)+deg (G,xlevel)*deg (F, i)
3336
static inline
3437
void myCompress (const CanonicalForm& F, const CanonicalForm& G, CFMap & M,
@@ -326,6 +329,9 @@ resultantFp (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
326329
else if (degBx == 0)
327330
return power (B, degAx);
328331

332+
if (A.isUnivariate() && B.isUnivariate() && A.level() == B.level())
333+
return uniResultant (A, B);
334+
329335
CanonicalForm F= A;
330336
CanonicalForm G= B;
331337

@@ -337,9 +343,6 @@ resultantFp (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
337343

338344
Variable y= Variable (2);
339345

340-
if (F.isUnivariate() && G.isUnivariate() && F.level() == G.level())
341-
return N(uniResultant (F, G));
342-
343346
int i= -1;
344347
CanonicalForm GEval, FEval, recResult, H;
345348
CanonicalForm newtonPoly= 1;
@@ -362,6 +365,8 @@ resultantFp (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
362365

363366
if (H == modResult)
364367
equalCount++;
368+
else
369+
equalCount= 0;
365370

366371
count++;
367372
if (count > bound || (prob && equalCount == 2))
@@ -472,6 +477,9 @@ resultantZ (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
472477
CanonicalForm l= lc (F)*lc(G);
473478
CanonicalForm resultModP, q (0), newResult, newQ;
474479
CanonicalForm result;
480+
int equalCount= 0;
481+
CanonicalForm test, newTest;
482+
int count= 0;
475483
do
476484
{
477485
p = cf_getBigPrime( i );
@@ -486,10 +494,13 @@ resultantZ (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
486494

487495
setCharacteristic (p);
488496

497+
TIMING_START (fac_resultant_p);
489498
resultModP= resultantFp (mapinto (F), mapinto (G), X, prob);
499+
TIMING_END_AND_PRINT (fac_resultant_p, "time to compute resultant mod p: ");
490500

491501
setCharacteristic (0);
492502

503+
count++;
493504
if ( q.isZero() )
494505
{
495506
result= mapinto(resultModP);
@@ -500,9 +511,17 @@ resultantZ (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
500511
chineseRemainder( result, q, mapinto (resultModP), p, newResult, newQ );
501512
q= newQ;
502513
result= newResult;
503-
if (newQ > bound)
514+
test= symmetricRemainder (result,q);
515+
if (test != newTest)
516+
{
517+
newTest= test;
518+
equalCount= 0;
519+
}
520+
else
521+
equalCount++;
522+
if (newQ > bound || (prob && equalCount == 2))
504523
{
505-
result= symmetricRemainder (result, q);
524+
result= test;
506525
break;
507526
}
508527
}

0 commit comments

Comments
 (0)