My Project
Loading...
Searching...
No Matches
cfModResultant.h File Reference

modular resultant algorithm as described by G. More...

#include "canonicalform.h"

Go to the source code of this file.

Functions

CanonicalForm resultantFp (const CanonicalForm &A, const CanonicalForm &B, const Variable &x, bool prob=true)
 modular resultant algorihtm over Fp
 
CanonicalForm resultantZ (const CanonicalForm &A, const CanonicalForm &B, const Variable &x, bool prob=true)
 modular resultant algorihtm over Z
 

Detailed Description

modular resultant algorithm as described by G.

E. Collins in "The Calculation of multivariate polynomial resultants"

Author
Martin Lee

Definition in file cfModResultant.h.

Function Documentation

◆ resultantFp()

CanonicalForm resultantFp ( const CanonicalForm & A,
const CanonicalForm & B,
const Variable & x,
bool prob = true )

modular resultant algorihtm over Fp

Returns
resultantFp returns the resultant of A and B wrt. x
Parameters
[in]Asome poly
[in]Bsome poly
[in]xsome polynomial variable
[in]probif true use probabilistic algorithm

Definition at line 349 of file cfModResultant.cc.

351{
352 ASSERT (getCharacteristic() > 0, "characteristic > 0 expected");
353
354 if (A.isZero() || B.isZero())
355 return 0;
356
357 int degAx= degree (A, x);
358 int degBx= degree (B, x);
359 if (A.level() < x.level())
360 return power (A, degBx);
361 if (B.level() < x.level())
362 return power (B, degAx);
363
364 if (degAx == 0)
365 return power (A, degBx);
366 else if (degBx == 0)
367 return power (B, degAx);
368
369 if (A.isUnivariate() && B.isUnivariate() && A.level() == B.level())
370 return uniResultant (A, B);
371
372 CanonicalForm F= A;
374
375 CFMap M, N;
376 myCompress (F, G, M, N, x);
377
378 F= M (F);
379 G= M (G);
380
381 Variable y= Variable (2);
382
383 CanonicalForm GEval, FEval, recResult, H;
384 CanonicalForm newtonPoly= 1;
385 CanonicalForm modResult= 0;
386
387 Variable z= Variable (1);
388 int bound= degAx*degree (G, 2) + degree (F, 2)*degBx;
389
390 int p= getCharacteristic();
391 CanonicalForm minpoly;
392 Variable alpha= Variable (tmax (F.level(), G.level()) + 1);
393 bool algExt= hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha);
394 CFGenerator * gen;
395 bool extOfExt= false;
397 CanonicalForm primElemAlpha, imPrimElemAlpha;
398 CFList source,dest;
399 if (!algExt && (p < (1 << 28)))
400 {
401 // pass to an extension of size at least 2^29
402 // for very very large input that is maybe too small though
403 int deg= ceil (29.0*((double) log (2)/log (p)))+1;
404 minpoly= randomIrredpoly (deg, z);
405 alpha= rootOf (minpoly);
406 AlgExtGenerator AlgExtGen (alpha);
407 gen= AlgExtGen.clone();
408 for (int i= 0; i < p; i++) // skip values from the prime field
409 (*gen).next();
410 }
411 else if (!algExt)
412 {
413 FFGenerator FFGen;
414 gen= FFGen.clone();
415 }
416 else
417 {
418 int deg= ceil (29.0*((double) log (2)/log (p)));
419 if (degree (getMipo (alpha)) < deg)
420 {
421 mpz_t field_size;
422 mpz_init (field_size);
423 mpz_ui_pow_ui (field_size, p,
424 deg + degree (getMipo (alpha)) - deg%degree (getMipo (alpha)));
425
426 // field_size needs to fit in an int because of mapUp, mapDown, length of lists etc.
427 if (mpz_fits_sint_p (field_size))
428 {
429 minpoly= randomIrredpoly (deg + degree (getMipo (alpha))
430 - deg%degree (getMipo (alpha)), z);
431 v= rootOf (minpoly);
432 Variable V_buf2;
433 bool primFail= false;
434 extOfExt= true;
435 primElemAlpha= primitiveElement (alpha, V_buf2, primFail);
436 ASSERT (!primFail, "failure in integer factorizer");
437 if (primFail)
438 ; //ERROR
439 else
440 imPrimElemAlpha= mapPrimElem (primElemAlpha, alpha, v);
441 F= mapUp (F, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
442 G= mapUp (G, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
443 }
444 else
445 {
446 deg= deg - deg % degree (getMipo (alpha));
447 mpz_ui_pow_ui (field_size, p, deg);
448 while (deg / degree (getMipo (alpha)) >= 2 && !mpz_fits_sint_p (field_size))
449 {
450 deg -= degree (getMipo (alpha));
451 mpz_ui_pow_ui (field_size, p, deg);
452 }
453 if (deg != degree (getMipo (alpha)))
454 {
455 minpoly= randomIrredpoly (deg, z);
456 v= rootOf (minpoly);
457 Variable V_buf2;
458 bool primFail= false;
459 extOfExt= true;
460 primElemAlpha= primitiveElement (alpha, V_buf2, primFail);
461 ASSERT (!primFail, "failure in integer factorizer");
462 if (primFail)
463 ; //ERROR
464 else
465 imPrimElemAlpha= mapPrimElem (primElemAlpha, alpha, v);
466 F= mapUp (F, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
467 G= mapUp (G, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
468 }
469 }
470 mpz_clear (field_size);
471 }
472 AlgExtGenerator AlgExtGen (v);
473 gen= AlgExtGen.clone();
474 for (int i= 0; i < p; i++)
475 (*gen).next();
476 }
477 int count= 0;
478 int equalCount= 0;
479 CanonicalForm point;
480 do
481 {
482 evalPoint (F, G, FEval, GEval, *gen);
483
484 recResult= resultantFp (FEval, GEval, z, prob);
485
486 H= newtonInterp ((*gen).item(), recResult, newtonPoly, modResult, y);
487
488 if (H == modResult)
489 equalCount++;
490 else
491 equalCount= 0;
492
493 count++;
494 if (count > bound || (prob && equalCount == 2 && !H.inCoeffDomain()))
495 {
496 if (!algExt && degree (H, alpha) <= 0)
497 break;
498 else if (algExt)
499 {
500 if (extOfExt && !isInExtension (H, imPrimElemAlpha, 1, primElemAlpha,
501 dest, source))
502 {
503 H= mapDown (H, primElemAlpha, imPrimElemAlpha, alpha, dest, source);
504 prune (v);
505 break;
506 }
507 else if (!extOfExt)
508 break;
509 }
510 }
511
512 modResult= H;
513 newtonPoly *= (y - (*gen).item());
514 if ((*gen).hasItems())
515 (*gen).next();
516 else
517 STICKYASSERT (0, "out of evaluation points");
518 } while (1);
519
520 delete gen;
521
522 return N (H);
523}
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
int degree(const CanonicalForm &f)
bool hasFirstAlgVar(const CanonicalForm &f, Variable &a)
check if poly f contains an algebraic variable a
Definition cf_ops.cc:679
List< CanonicalForm > CFList
int FACTORY_PUBLIC getCharacteristic()
Definition cf_char.cc:70
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
int i
Definition cfEzgcd.cc:132
int myCompress(const CanonicalForm &F, const CanonicalForm &G, CFMap &M, CFMap &N, bool topLevel)
compressing two polynomials F and G, M is used for compressing, N to reverse the compression
Definition cfModGcd.cc:92
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
const CanonicalForm CFMap CFMap & N
CanonicalForm resultantFp(const CanonicalForm &A, const CanonicalForm &B, const Variable &x, bool prob)
modular resultant algorihtm over Fp
static CanonicalForm uniResultant(const CanonicalForm &F, const CanonicalForm &G)
static void evalPoint(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &FEval, CanonicalForm &GEval, CFGenerator &evalPoint)
const CanonicalForm CFMap & M
static CanonicalForm newtonInterp(const CanonicalForm &alpha, const CanonicalForm &u, const CanonicalForm &newtonPoly, const CanonicalForm &oldInterPoly, const Variable &x)
#define STICKYASSERT(expression, message)
Definition cf_assert.h:64
#define ASSERT(expression, message)
Definition cf_assert.h:99
CanonicalForm randomIrredpoly(int i, const Variable &x)
computes a random monic irreducible univariate polynomial in x over Fp of degree i via NTL/FLINT
Definition cf_irred.cc:26
static CanonicalForm bound(const CFMatrix &M)
Definition cf_linsys.cc:460
CanonicalForm mapPrimElem(const CanonicalForm &primElem, const Variable &alpha, const Variable &beta)
compute the image of a primitive element of in . We assume .
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
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 mapUp(const Variable &alpha, const Variable &beta)
and is a primitive element, returns the image of
Definition cf_map_ext.cc:71
generate all elements in F_p(alpha) starting from 0
virtual class for generators
virtual CFGenerator * clone() const
virtual void next()
class CFMap
Definition cf_map.h:85
factory's main class
int level() const
level() returns the level of CO.
generate all elements in F_p starting from 0
CFGenerator * clone() const
factory's class for variables
Definition factory.h:127
Variable alpha
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
CanonicalForm H
Definition facAbsFact.cc:60
b *CanonicalForm B
Definition facBivar.cc:52
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
bool isInExtension(const CanonicalForm &F, const CanonicalForm &gamma, const int k, const CanonicalForm &delta, CFList &source, CFList &dest)
tests if F is not contained in a subfield defined by gamma (Fq case) or k (GF case)
Variable FACTORY_PUBLIC rootOf(const CanonicalForm &, char name='@')
returns a symbolic root of polynomial with name name Use it to define algebraic variables
Definition variable.cc:162
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition variable.cc:207
void FACTORY_PUBLIC prune(Variable &alpha)
Definition variable.cc:261
template CanonicalForm tmax(const CanonicalForm &, const CanonicalForm &)
STATIC_VAR TreeM * G
Definition janet.cc:31
gmp_float log(const gmp_float &a)
const signed long ceil(const ampf< Precision > &x)
Definition amp.h:788
int status int void size_t count
Definition si_signals.h:69
#define A
Definition sirandom.c:24
#define M
Definition sirandom.c:25

◆ resultantZ()

CanonicalForm resultantZ ( const CanonicalForm & A,
const CanonicalForm & B,
const Variable & x,
bool prob = true )

modular resultant algorihtm over Z

Returns
resultantZ returns the resultant of A and B wrt. x
Parameters
[in]Asome poly
[in]Bsome poly
[in]xsome polynomial variable
[in]probif true use probabilistic algorithm

Definition at line 560 of file cfModResultant.cc.

562{
563 ASSERT (getCharacteristic() == 0, "characteristic > 0 expected");
564#ifndef NOASSERT
565 bool isRat= isOn (SW_RATIONAL);
566 On (SW_RATIONAL);
567 ASSERT (bCommonDen (A).isOne(), "input A is rational");
568 ASSERT (bCommonDen (B).isOne(), "input B is rational");
569 if (!isRat)
571#endif
572
573 int degAx= degree (A, x);
574 int degBx= degree (B, x);
575 if (A.level() < x.level())
576 return power (A, degBx);
577 if (B.level() < x.level())
578 return power (B, degAx);
579
580 if (degAx == 0)
581 return power (A, degBx);
582 else if (degBx == 0)
583 return power (B, degAx);
584
585 CanonicalForm F= A;
587
588 Variable X= x;
589 if (F.level() != x.level() || G.level() != x.level())
590 {
591 if (F.level() > G.level())
592 X= F.mvar();
593 else
594 X= G.mvar();
595 F= swapvar (F, X, x);
596 G= swapvar (G, X, x);
597 }
598
599 // now X is the main variable
600
601 CanonicalForm d= 0;
602 CanonicalForm dd= 0;
604 for (CFIterator i= F; i.hasTerms(); i++)
605 {
606 buf= oneNorm (i.coeff());
607 d= (buf > d) ? buf : d;
608 }
609 CanonicalForm e= 0, ee= 0;
610 for (CFIterator i= G; i.hasTerms(); i++)
611 {
612 buf= oneNorm (i.coeff());
613 e= (buf > e) ? buf : e;
614 }
615 d= power (d, degBx);
616 e= power (e, degAx);
618 for (int i= degBx + degAx; i > 1; i--)
619 bound *= i;
620 bound *= d*e;
621 bound *= 2;
622
623 bool onRational= isOn (SW_RATIONAL);
624 if (onRational)
626 int i = cf_getNumBigPrimes() - 1;
627 int p;
628 CanonicalForm l= lc (F)*lc(G);
629 CanonicalForm resultModP, q (0), newResult, newQ;
631 int equalCount= 0;
632 CanonicalForm test, newTest;
633 int count= 0;
634 do
635 {
636 p = cf_getBigPrime( i );
637 i--;
638 while ( i >= 0 && mod( l, p ) == 0)
639 {
640 p = cf_getBigPrime( i );
641 i--;
642 }
643
644 if (i <= 0)
645 return resultant (A, B, x);
646
648
649 TIMING_START (fac_resultant_p);
650 resultModP= resultantFp (mapinto (F), mapinto (G), X, prob);
651 TIMING_END_AND_PRINT (fac_resultant_p, "time to compute resultant mod p: ");
652
654
655 count++;
656 if ( q.isZero() )
657 {
658 result= mapinto(resultModP);
659 q= p;
660 }
661 else
662 {
663 chineseRemainder( result, q, mapinto (resultModP), p, newResult, newQ );
664 q= newQ;
665 result= newResult;
667 if (test != newTest)
668 {
669 newTest= test;
670 equalCount= 0;
671 }
672 else
673 equalCount++;
674 if (newQ > bound || (prob && equalCount == 2))
675 {
676 result= test;
677 break;
678 }
679 }
680 } while (1);
681
682 if (onRational)
683 On (SW_RATIONAL);
684 return swapvar (result, X, x);
685}
bool isOn(int sw)
switches
void On(int sw)
switches
void Off(int sw)
switches
CanonicalForm mapinto(const CanonicalForm &f)
CanonicalForm lc(const CanonicalForm &f)
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
void FACTORY_PUBLIC setCharacteristic(int c)
Definition cf_char.cc:28
CanonicalForm FACTORY_PUBLIC swapvar(const CanonicalForm &, const Variable &, const Variable &)
swapvar() - swap variables x1 and x2 in f.
Definition cf_ops.cc:168
int l
Definition cfEzgcd.cc:100
CanonicalForm test
Definition cfModGcd.cc:4104
static CanonicalForm oneNorm(const CanonicalForm &F)
static CanonicalForm symmetricRemainder(const CanonicalForm &f, const CanonicalForm &q)
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
void FACTORY_PUBLIC chineseRemainder(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew)
void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2,...
Definition cf_chinese.cc:57
CanonicalForm FACTORY_PUBLIC resultant(const CanonicalForm &f, const CanonicalForm &g, const Variable &x)
CanonicalForm resultant ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
int cf_getBigPrime(int i)
Definition cf_primes.cc:39
int cf_getNumBigPrimes()
Definition cf_primes.cc:45
class to iterate through CanonicalForm's
Definition cf_iter.h:44
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
return result
int status int void * buf
Definition si_signals.h:69
#define TIMING_START(t)
Definition timing.h:92
#define TIMING_END_AND_PRINT(t, msg)
Definition timing.h:94