Skip to content

Commit 3e11973

Browse files
committed
chg: faster computation of resultants
1 parent 79110ab commit 3e11973

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

factory/cfModResultant.cc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
**/
1111
/*****************************************************************************/
1212

13+
#include <config.h>
1314

1415
#include "assert.h"
16+
#include "timing.h"
1517

1618
#include "cfModResultant.h"
1719
#include "cf_primes.h"
@@ -28,6 +30,8 @@
2830
#include "FLINTconvert.h"
2931
#endif
3032

33+
TIMING_DEFINE_PRINT(fac_resultant_p)
34+
3135
//TODO arrange by bound= deg (F,xlevel)*deg (G,i)+deg (G,xlevel)*deg (F, i)
3236
static inline
3337
void myCompress (const CanonicalForm& F, const CanonicalForm& G, CFMap & M,
@@ -325,6 +329,9 @@ resultantFp (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
325329
else if (degBx == 0)
326330
return power (B, degAx);
327331

332+
if (A.isUnivariate() && B.isUnivariate() && A.level() == B.level())
333+
return uniResultant (A, B);
334+
328335
CanonicalForm F= A;
329336
CanonicalForm G= B;
330337

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

337344
Variable y= Variable (2);
338345

339-
if (F.isUnivariate() && G.isUnivariate() && F.level() == G.level())
340-
return N(uniResultant (F, G));
341-
342346
int i= -1;
343347
CanonicalForm GEval, FEval, recResult, H;
344348
CanonicalForm newtonPoly= 1;
@@ -361,6 +365,8 @@ resultantFp (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
361365

362366
if (H == modResult)
363367
equalCount++;
368+
else
369+
equalCount= 0;
364370

365371
count++;
366372
if (count > bound || (prob && equalCount == 2))
@@ -471,6 +477,9 @@ resultantZ (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
471477
CanonicalForm l= lc (F)*lc(G);
472478
CanonicalForm resultModP, q (0), newResult, newQ;
473479
CanonicalForm result;
480+
int equalCount= 0;
481+
CanonicalForm test, newTest;
482+
int count= 0;
474483
do
475484
{
476485
p = cf_getBigPrime( i );
@@ -485,10 +494,13 @@ resultantZ (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
485494

486495
setCharacteristic (p);
487496

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

490501
setCharacteristic (0);
491502

503+
count++;
492504
if ( q.isZero() )
493505
{
494506
result= mapinto(resultModP);
@@ -499,9 +511,17 @@ resultantZ (const CanonicalForm& A, const CanonicalForm& B, const Variable& x,
499511
chineseRemainder( result, q, mapinto (resultModP), p, newResult, newQ );
500512
q= newQ;
501513
result= newResult;
502-
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))
503523
{
504-
result= symmetricRemainder (result, q);
524+
result= test;
505525
break;
506526
}
507527
}

0 commit comments

Comments
 (0)