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] | A | some poly
  [in] | B | some poly
  [in] | x | some polynomial variable
  [in] | prob | if true use probabilistic algorithm

Definition at line 349 of file cfModResultant.cc.

{
ASSERT (getCharacteristic() > 0, "characteristic > 0 expected");
if (A.isZero() || B.isZero())
return 0;
int degAx= degree (A, x);
int degBx= degree (B, x);
if (A.level() < x.level())
return power (A, degBx);
if (B.level() < x.level())
return power (B, degAx);
if (degAx == 0)
return power (A, degBx);
else if (degBx == 0)
return power (B, degAx);
if (A.isUnivariate() && B.isUnivariate() && A.level() == B.level())
return uniResultant (A, B);
CanonicalForm F= A;
CanonicalForm G= B;
CFMap M, N;
myCompress (F, G, M, N, x);
F= M (F);
G= M (G);
Variable y= Variable (2);
CanonicalForm GEval, FEval, recResult, H;
CanonicalForm newtonPoly= 1;
CanonicalForm modResult= 0;
Variable z= Variable (1);
int bound= degAx*degree (G, 2) + degree (F, 2)*degBx;
int p= getCharacteristic();
CanonicalForm minpoly;
Variable alpha= Variable (tmax (F.level(), G.level()) + 1);
bool algExt= hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha);
CFGenerator * gen;
bool extOfExt= false;
Variable v= alpha;
CanonicalForm primElemAlpha, imPrimElemAlpha;
CFList source,dest;
if (!algExt && (p < (1 << 28)))
{
// pass to an extension of size at least 2^29
// for very very large input that is maybe too small though
int deg= ceil (29.0*((double) log (2)/log (p)))+1;
minpoly= randomIrredpoly (deg, z);
alpha= rootOf (minpoly);
AlgExtGenerator AlgExtGen (alpha);
gen= AlgExtGen.clone();
for (int i= 0; i < p; i++) // skip values from the prime field
(*gen).next();
}
else if (!algExt)
{
FFGenerator FFGen;
gen= FFGen.clone();
}
else
{
int deg= ceil (29.0*((double) log (2)/log (p)));
if (degree (getMipo (alpha)) < deg)
{
mpz_t field_size;
mpz_init (field_size);
mpz_ui_pow_ui (field_size, p,
deg + degree (getMipo (alpha)) - deg%degree (getMipo (alpha)));
// field_size needs to fit in an int because of mapUp, mapDown, length of lists etc.
if (mpz_fits_sint_p (field_size))
{
minpoly= randomIrredpoly (deg + degree (getMipo (alpha))
- deg%degree (getMipo (alpha)), z);
v= rootOf (minpoly);
Variable V_buf2;
bool primFail= false;
extOfExt= true;
primElemAlpha= primitiveElement (alpha, V_buf2, primFail);
ASSERT (!primFail, "failure in integer factorizer");
if (primFail)
; //ERROR
else
imPrimElemAlpha= mapPrimElem (primElemAlpha, alpha, v);
F= mapUp (F, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
G= mapUp (G, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
}
else
{
deg= deg - deg % degree (getMipo (alpha));
mpz_ui_pow_ui (field_size, p, deg);
while (deg / degree (getMipo (alpha)) >= 2 && !mpz_fits_sint_p (field_size))
{
deg -= degree (getMipo (alpha));
mpz_ui_pow_ui (field_size, p, deg);
}
if (deg != degree (getMipo (alpha)))
{
minpoly= randomIrredpoly (deg, z);
v= rootOf (minpoly);
Variable V_buf2;
bool primFail= false;
extOfExt= true;
primElemAlpha= primitiveElement (alpha, V_buf2, primFail);
ASSERT (!primFail, "failure in integer factorizer");
if (primFail)
; //ERROR
else
imPrimElemAlpha= mapPrimElem (primElemAlpha, alpha, v);
F= mapUp (F, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
G= mapUp (G, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest);
}
}
mpz_clear (field_size);
}
AlgExtGenerator AlgExtGen (v);
gen= AlgExtGen.clone();
for (int i= 0; i < p; i++)
(*gen).next();
}
int count= 0;
int equalCount= 0;
CanonicalForm point;
do
{
evalPoint (F, G, FEval, GEval, *gen);
recResult= resultantFp (FEval, GEval, z, prob);
H= newtonInterp ((*gen).item(), recResult, newtonPoly, modResult, y);
if (H == modResult)
equalCount++;
else
equalCount= 0;
count++;
if (count > bound || (prob && equalCount == 2 && !H.inCoeffDomain()))
{
if (!algExt && degree (H, alpha) <= 0)
break;
else if (algExt)
{
if (extOfExt && !isInExtension (H, imPrimElemAlpha, 1, primElemAlpha,
dest, source))
{
H= mapDown (H, primElemAlpha, imPrimElemAlpha, alpha, dest, source);
prune (v);
break;
}
else if (!extOfExt)
break;
}
}
modResult= H;
newtonPoly *= (y - (*gen).item());
if ((*gen).hasItems())
(*gen).next();
else
STICKYASSERT (0, "out of evaluation points");
} while (1);
delete gen;
return N (H);
}
power
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
Definition canonicalform.cc:1896
degree
int degree(const CanonicalForm &f)
Definition canonicalform.h:316
hasFirstAlgVar
bool hasFirstAlgVar(const CanonicalForm &f, Variable &a)
check if poly f contains an algebraic variable a
Definition cf_ops.cc:679
CFList
List< CanonicalForm > CFList
Definition canonicalform.h:395
getCharacteristic
int FACTORY_PUBLIC getCharacteristic()
Definition cf_char.cc:70
N
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
i
int i
Definition cfEzgcd.cc:132
myCompress
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
x
Variable x
Definition cfModGcd.cc:4090
p
int p
Definition cfModGcd.cc:4086
N
const CanonicalForm CFMap CFMap & N
Definition cfModResultant.cc:47
resultantFp
CanonicalForm resultantFp(const CanonicalForm &A, const CanonicalForm &B, const Variable &x, bool prob)
modular resultant algorihtm over Fp
Definition cfModResultant.cc:349
uniResultant
static CanonicalForm uniResultant(const CanonicalForm &F, const CanonicalForm &G)
Definition cfModResultant.cc:256
evalPoint
static void evalPoint(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &FEval, CanonicalForm &GEval, CFGenerator &evalPoint)
Definition cfModResultant.cc:311
M
const CanonicalForm CFMap & M
Definition cfModResultant.cc:46
newtonInterp
static CanonicalForm newtonInterp(const CanonicalForm &alpha, const CanonicalForm &u, const CanonicalForm &newtonPoly, const CanonicalForm &oldInterPoly, const Variable &x)
Definition cfModResultant.cc:337
STICKYASSERT
#define STICKYASSERT(expression, message)
Definition cf_assert.h:64
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
randomIrredpoly
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
bound
static CanonicalForm bound(const CFMatrix &M)
Definition cf_linsys.cc:460
mapPrimElem
CanonicalForm mapPrimElem(const CanonicalForm &primElem, const Variable &alpha, const Variable &beta)
compute the image of a primitive element of in . We assume .
Definition cf_map_ext.cc:451
primitiveElement
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
Definition cf_map_ext.cc:343
mapDown
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 ,...
Definition cf_map_ext.cc:124
mapUp
static CanonicalForm mapUp(const Variable &alpha, const Variable &beta)
and is a primitive element, returns the image of
Definition cf_map_ext.cc:71
AlgExtGenerator
generate all elements in F_p(alpha) starting from 0
Definition cf_generator.h:94
CFGenerator
virtual class for generators
Definition cf_generator.h:22
CFGenerator::clone
virtual CFGenerator * clone() const
Definition cf_generator.h:30
CFGenerator::next
virtual void next()
Definition cf_generator.h:29
CFMap
class CFMap
Definition cf_map.h:85
CanonicalForm
factory's main class
Definition canonicalform.h:86
CanonicalForm::level
int level() const
level() returns the level of CO.
Definition canonicalform.cc:576
FFGenerator
generate all elements in F_p starting from 0
Definition cf_generator.h:56
FFGenerator::clone
CFGenerator * clone() const
Definition cf_generator.cc:52
Variable
factory's class for variables
Definition factory.h:127
alpha
Variable alpha
Definition facAbsBiFact.cc:52
y
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
H
CanonicalForm H
Definition facAbsFact.cc:60
B
b *CanonicalForm B
Definition facBivar.cc:52
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
isInExtension
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)
Definition facFqBivarUtil.cc:184
rootOf
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
getMipo
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition variable.cc:207
prune
void FACTORY_PUBLIC prune(Variable &alpha)
Definition variable.cc:261
tmax
template CanonicalForm tmax(const CanonicalForm &, const CanonicalForm &)
G
STATIC_VAR TreeM * G
Definition janet.cc:31
log
gmp_float log(const gmp_float &a)
Definition mpr_complex.cc:335
amp::ceil
const signed long ceil(const ampf< Precision > &x)
Definition amp.h:788
count
int status int void size_t count
Definition si_signals.h:69
A
#define A
Definition sirandom.c:24
M
#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] | A | some poly
  [in] | B | some poly
  [in] | x | some polynomial variable
  [in] | prob | if true use probabilistic algorithm

Definition at line 560 of file cfModResultant.cc.

{
ASSERT (getCharacteristic() == 0, "characteristic > 0 expected");
#ifndef NOASSERT
bool isRat= isOn (SW_RATIONAL);
On (SW_RATIONAL);
ASSERT (bCommonDen (A).isOne(), "input A is rational");
ASSERT (bCommonDen (B).isOne(), "input B is rational");
if (!isRat)
Off (SW_RATIONAL);
#endif
int degAx= degree (A, x);
int degBx= degree (B, x);
if (A.level() < x.level())
return power (A, degBx);
if (B.level() < x.level())
return power (B, degAx);
if (degAx == 0)
return power (A, degBx);
else if (degBx == 0)
return power (B, degAx);
CanonicalForm F= A;
CanonicalForm G= B;
Variable X= x;
if (F.level() != x.level() || G.level() != x.level())
{
if (F.level() > G.level())
X= F.mvar();
else
X= G.mvar();
F= swapvar (F, X, x);
G= swapvar (G, X, x);
}
// now X is the main variable
CanonicalForm d= 0;
CanonicalForm dd= 0;
CanonicalForm buf;
for (CFIterator i= F; i.hasTerms(); i++)
{
buf= oneNorm (i.coeff());
d= (buf > d) ? buf : d;
}
CanonicalForm e= 0, ee= 0;
for (CFIterator i= G; i.hasTerms(); i++)
{
buf= oneNorm (i.coeff());
e= (buf > e) ? buf : e;
}
d= power (d, degBx);
e= power (e, degAx);
CanonicalForm bound= 1;
for (int i= degBx + degAx; i > 1; i--)
bound *= i;
bound *= d*e;
bound *= 2;
bool onRational= isOn (SW_RATIONAL);
if (onRational)
Off (SW_RATIONAL);
int i = cf_getNumBigPrimes() - 1;
int p;
CanonicalForm l= lc (F)*lc(G);
CanonicalForm resultModP, q (0), newResult, newQ;
CanonicalForm result;
int equalCount= 0;
CanonicalForm test, newTest;
int count= 0;
do
{
p = cf_getBigPrime( i );
i--;
while ( i >= 0 && mod( l, p ) == 0)
{
p = cf_getBigPrime( i );
i--;
}
if (i <= 0)
return resultant (A, B, x);
setCharacteristic (p);
TIMING_START (fac_resultant_p);
resultModP= resultantFp (mapinto (F), mapinto (G), X, prob);
TIMING_END_AND_PRINT (fac_resultant_p, "time to compute resultant mod p: ");
setCharacteristic (0);
count++;
if ( q.isZero() )
{
result= mapinto(resultModP);
q= p;
}
else
{
chineseRemainder( result, q, mapinto (resultModP), p, newResult, newQ );
q= newQ;
result= newResult;
test= symmetricRemainder (result,q);
if (test != newTest)
{
newTest= test;
equalCount= 0;
}
else
equalCount++;
if (newQ > bound || (prob && equalCount == 2))
{
result= test;
break;
}
}
} while (1);
if (onRational)
On (SW_RATIONAL);
return swapvar (result, X, x);
}
isOn
bool isOn(int sw)
switches
Definition canonicalform.cc:1971
On
void On(int sw)
switches
Definition canonicalform.cc:1957
Off
void Off(int sw)
switches
Definition canonicalform.cc:1964
mapinto
CanonicalForm mapinto(const CanonicalForm &f)
Definition canonicalform.h:355
lc
CanonicalForm lc(const CanonicalForm &f)
Definition canonicalform.h:304
mod
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
setCharacteristic
void FACTORY_PUBLIC setCharacteristic(int c)
Definition cf_char.cc:28
swapvar
CanonicalForm FACTORY_PUBLIC swapvar(const CanonicalForm &, const Variable &, const Variable &)
swapvar() - swap variables x1 and x2 in f.
Definition cf_ops.cc:168
l
int l
Definition cfEzgcd.cc:100
test
CanonicalForm test
Definition cfModGcd.cc:4104
oneNorm
static CanonicalForm oneNorm(const CanonicalForm &F)
Definition cfModResultant.cc:243
symmetricRemainder
static CanonicalForm symmetricRemainder(const CanonicalForm &f, const CanonicalForm &q)
Definition cfModResultant.cc:545
bCommonDen
CanonicalForm bCommonDen(const CanonicalForm &f)
void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r,...
Definition cf_algorithm.cc:293
chineseRemainder
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
resultant
CanonicalForm FACTORY_PUBLIC resultant(const CanonicalForm &f, const CanonicalForm &g, const Variable &x)
CanonicalForm resultant ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ).
Definition cf_resultant.cc:173
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
cf_getBigPrime
int cf_getBigPrime(int i)
Definition cf_primes.cc:39
cf_getNumBigPrimes
int cf_getNumBigPrimes()
Definition cf_primes.cc:45
CFIterator
class to iterate through CanonicalForm's
Definition cf_iter.h:44
CanonicalForm::mvar
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
Definition canonicalform.cc:593
result
return result
Definition facAbsBiFact.cc:76
buf
int status int void * buf
Definition si_signals.h:69
TIMING_START
#define TIMING_START(t)
Definition timing.h:92
TIMING_END_AND_PRINT
#define TIMING_END_AND_PRINT(t, msg)
Definition timing.h:94