29#define PLURAL_INTERNAL_DECLARATIONS
58poly
sca_pp_Mult_mm(
const poly pPoly,
const poly pMonom,
const ring rRing, poly &);
61static poly
sca_pp_mm_Mult(
const poly pPoly,
const poly pMonom,
const ring rRing);
64poly
sca_p_Mult_mm(poly pPoly,
const poly pMonom,
const ring rRing);
67static poly
sca_p_mm_Mult(poly pPoly,
const poly pMonom,
const ring rRing);
71poly
sca_SPoly(
const poly p1,
const poly p2,
const ring r);
94 for(
REGISTER short j = iLastAltVar;
j >= iFirstAltVar;
j-- )
96 const unsigned int iExpM =
p_GetExp(pMonomM,
j, rRing);
97 const unsigned int iExpMM =
p_GetExp(pMonomMM,
j, rRing);
122 return(1 - (tpower << 1) );
132static inline poly
sca_m_Mult_mm( poly pMonomM,
const poly pMonomMM,
const ring rRing )
145 for(
REGISTER unsigned int j = iLastAltVar;
j >= iFirstAltVar;
j-- )
147 const unsigned int iExpM =
p_GetExp(pMonomM,
j, rRing);
148 const unsigned int iExpMM =
p_GetExp(pMonomMM,
j, rRing);
177 nCoeffM =
n_InpNeg(nCoeffM, rRing->cf);
179 const number nCoeffMM =
p_GetCoeff(pMonomMM, rRing);
181 number nCoeff =
n_Mult(nCoeffM, nCoeffMM, rRing->cf);
196static inline poly
sca_mm_Mult_m(
const poly pMonomMM, poly pMonomM,
const ring rRing )
209 for(
REGISTER unsigned int j = iLastAltVar;
j >= iFirstAltVar;
j-- )
211 const unsigned int iExpMM =
p_GetExp(pMonomMM,
j, rRing);
212 const unsigned int iExpM =
p_GetExp(pMonomM,
j, rRing);
241 nCoeffM =
n_InpNeg(nCoeffM, rRing->cf);
243 const number nCoeffMM =
p_GetCoeff(pMonomMM, rRing);
245 number nCoeff =
n_Mult(nCoeffM, nCoeffMM, rRing->cf);
261static inline poly
sca_mm_Mult_mm( poly pMonom1,
const poly pMonom2,
const ring rRing )
274 for(
REGISTER unsigned int j = iLastAltVar;
j >= iFirstAltVar;
j-- )
276 const unsigned int iExp1 =
p_GetExp(pMonom1,
j, rRing);
277 const unsigned int iExp2 =
p_GetExp(pMonom2,
j, rRing);
306 const number nCoeff1 =
p_GetCoeff(pMonom1, rRing);
307 const number nCoeff2 =
p_GetCoeff(pMonom2, rRing);
309 number nCoeff =
n_Mult(nCoeff1, nCoeff2, rRing->cf);
312 nCoeff =
n_InpNeg(nCoeff, rRing->cf);
349 poly pResult =
p_LmInit(pMonom, rRing);
357 nCoeff =
n_InpNeg(nCoeff, rRing->cf);
393 const int iComponentMonomM =
p_GetComp(pMonom, rRing);
395 poly
p = pPoly; poly* ppPrev = &pPoly;
406 if( iComponentMonomM!=0 )
409 Werror(
"sca_p_Mult_mm: exponent mismatch %d and %d\n", iComponent, iComponentMonomM);
416 if(iComponentMonomM==0 )
418 dReportError(
"sca_p_Mult_mm: Multiplication in the left module from the right");
471 const int iComponentMonomM =
p_GetComp(pMonom, rRing);
474 poly* ppPrev = &pResult;
485 if( iComponentMonomM!=0 )
488 Werror(
"sca_pp_Mult_mm: exponent mismatch %d and %d\n", iComponent, iComponentMonomM);
496 if(iComponentMonomM==0 )
498 dReportError(
"sca_pp_Mult_mm: Multiplication in the left module from the right");
538 poly* ppPrev = &pResult;
553 ppPrev = &
pNext(*ppPrev);
582 const int iComponentMonomM =
p_GetComp(pMonom, rRing);
585 poly* ppPrev = &pResult;
594 if( iComponentMonomM!=0 )
599 Werror(
"sca_pp_mm_Mult: exponent mismatch %d and %d\n", iComponent, iComponentMonomM);
608 dReportError(
"sca_pp_mm_Mult: Multiplication in the left module from the right!");
622 ppPrev = &
pNext(*ppPrev);
655 const int iComponentMonomM =
p_GetComp(pMonom, rRing);
657 poly
p = pPoly; poly* ppPrev = &pPoly;
671 if( iComponentMonomM!=0 )
676 Werror(
"sca_p_mm_Mult: exponent mismatch %d and %d\n", iComponent, iComponentMonomM);
685 dReportError(
"sca_p_mm_Mult: Multiplication in the left module from the right!");
718 if( !
p_Test(pPoly, rRing) )
720 PrintS(
"pPoly is wrong!");
744poly
sca_SPoly(
const poly p1,
const poly p2,
const ring r )
751 if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
754 dReportError(
"sca_SPoly: different non-zero components!\n");
759 poly pL =
p_Lcm(p1, p2, r);
785 number C =
n_Gcd(C1,C2,r->cf);
789 C1=
n_Div(C1, C, r->cf);
790 C2=
n_Div(C2, C, r->cf);
798 assume( (iSignSum*iSignSum == 0) || (iSignSum*iSignSum == 4) );
840 if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
843 dReportError(
"sca_ReduceSpoly: different non-zero components!");
859 number C =
n_Gcd(C1, C2, r->cf);
863 C1 =
n_Div(C1, C, r->cf);
864 C2 =
n_Div(C2, C, r->cf);
924#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
925 PrintS(
"sca_SetupQuotient(rGR, rG, bCopy)");
937 if(
rIsSCA(rG) && (rG != rGR))
955 PrintS(
"sca_SetupQuotient: qring?\n");
958 if(rGR->qideal ==
NULL)
962 PrintS(
"sca_SetupQuotient: qideal!!!\n");
970 int iAltVarStart =
N+1;
973 const ring rBase = rG;
978 PrintS(
"sca_SetupQuotient: AltVars?!\n");
981 for(
int i = 1;
i <
N;
i++)
983 for(
int j =
i + 1;
j <=
N;
j++)
987#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
988 Print(
"Nonzero D[%d, %d]\n",
i,
j);
999 if(
i < iAltVarStart)
1008#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1009 Print(
"Wrong Coeff at: [%d, %d]\n",
i,
j);
1017#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1018 Print(
"AltVars?1: [%d, %d]\n", iAltVarStart, iAltVarEnd);
1022 if( (iAltVarEnd == -1) || (iAltVarStart == (
N+1)) )
1026 for(
int i = 1;
i <
N;
i++)
1028 for(
int j =
i + 1;
j <=
N;
j++)
1033 if( (iAltVarStart <=
i) && (
j <= iAltVarEnd) )
1037#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1038 Print(
"Wrong Coeff at: [%d, %d]\n",
i,
j);
1047#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1048 Print(
"Wrong Coeff at: [%d, %d]\n",
i,
j);
1056#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1057 Print(
"AltVars!?: [%d, %d]\n", iAltVarStart, iAltVarEnd);
1060 assume( 1 <= iAltVarStart );
1061 assume( iAltVarStart < iAltVarEnd );
1072 const ideal idQuotient = rGR->qideal;
1075#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1076 PrintS(
"Analyzing quotient ideal:\n");
1093#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1094 Print(
"AltVars!?: [%d, %d]\n",
b, e);
1098 for (
int i = iAltVarStart; (
i <= iAltVarEnd);
i++ )
1099 if( (
i <
b) || (
i > e) )
1101 poly square =
p_One( rG);
1107 square =
nc_NF(idQuotient,
NULL, square, 0, 1, rG);
1109 if( square !=
NULL )
1116#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1117 Print(
"ScaVars!: [%d, %d]\n", iAltVarStart, iAltVarEnd);
1124 ideal tempQ =
id_KillSquares(idQuotient, iAltVarStart, iAltVarEnd, rG);
1127#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1130 PrintS(
"tempSCAQuotient: \n");
1142 rGR->GetNC()->SCAQuotient() =
NULL;
1144 rGR->GetNC()->SCAQuotient() =
idrMoveR(tempQ, rG, rGR);
1149#if ((defined(PDEBUG) && OUTPUT) || MYTEST)
1150 PrintS(
"SCAQuotient: \n");
1167 const int N = rGR->N;
1173 const ideal idQuotient = rGR->qideal;
1175 ideal tempQ = idQuotient;
1177 if( b <= N && e >= 1 )
1185 rGR->GetNC()->SCAQuotient() =
NULL;
1187 rGR->GetNC()->SCAQuotient() = tempQ;
1213 poly xi =
p_One( rRing);
1252 r->GetNC()->mmMultP() = sca_mm_Mult_p;
1253 r->GetNC()->mmMultPP() = sca_mm_Mult_pp;
1278 int& dx,
int& dy,
const ring r)
1280 const unsigned int N = r->N;
1296 for(
int i =
N;
i > 0;
i--)
1299 x += d * (*wx)[
i-1];
1300 y += d * (*wy)[
i-1];
1303 if( (wCx !=
NULL) && (wCy !=
NULL) )
1348 if ( (
x != ddx) || (
y != ddy) )
return false;
1364 if (
id ==
NULL)
return true;
1366 const int iSize =
IDELEMS(
id);
1368 if (iSize == 0)
return true;
1373 for(
int i = iSize - 1; (
i >= 0 ) &&
b;
i--)
1385 const unsigned int N = r->N;
1387 const int CommutativeVariable = 0;
1388 const int AntiCommutativeVariable = 0;
1392 if(AntiCommutativeVariable != CommutativeVariable)
1398 for (
unsigned int i = m_iFirstAltVar;
i<= m_iLastAltVar;
i++)
1400 (*w)[
i-1] = AntiCommutativeVariable;
1413 const unsigned int N = r->N;
1415 const int CommutativeVariable = 0;
1416 const int AntiCommutativeVariable = 1;
1420 if(AntiCommutativeVariable != CommutativeVariable)
1426 for (
unsigned int i = m_iFirstAltVar;
i<= m_iLastAltVar;
i++)
1428 (*w)[
i-1] = AntiCommutativeVariable;
1440 const short iFirstAltVar,
const short iLastAltVar,
1445 assume( (iFirstAltVar >= 1) && (iLastAltVar <=
rVar(r)) && (iFirstAltVar <= iLastAltVar) );
1448 PrintS(
"m_KillSquares, m = ");
1455 for(
short k = iFirstAltVar;
k <= iLastAltVar;
k++)
1466 const short iFirstAltVar,
const short iLastAltVar,
1472 assume( (iFirstAltVar >= 1) && (iLastAltVar <= r->
N) && (iFirstAltVar <= iLastAltVar) );
1475 PrintS(
"p_KillSquares, p = ");
1484 poly pResult =
NULL;
1485 poly* ppPrev = &pResult;
1507 PrintS(
"p_KillSquares => ");
1521 const short iFirstAltVar,
const short iLastAltVar,
1522 const ring r,
const bool bSkipZeroes)
1524 if (
id ==
NULL)
return id;
1526 assume( (iFirstAltVar >= 1) && (iLastAltVar <=
rVar(r)) && (iFirstAltVar <= iLastAltVar) );
1528 const int iSize =
IDELEMS(
id);
1530 if (iSize == 0)
return id;
1532 ideal temp =
idInit(iSize, id->rank);
1535 PrintS(
"<id_KillSquares>\n");
1538 for (
unsigned int i = 0;
i <
IDELEMS(
id);
i++)
1540 Print(
"; id[%d] = ",
i+1);
1549 for (
int j = 0;
j < iSize;
j++)
1556 PrintS(
"<id_KillSquares>\n");
1558 PrintS(
"ideal temp: \n");
1561 Print(
"; temp[%d] = ",
i+1);
1567 PrintS(
"</id_KillSquares>\n");
static int si_max(const int a, const int b)
void * cast_A_to_vptr(A a)
static int si_min(const int a, const int b)
const CanonicalForm CFMap CFMap & N
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff 'n' represents the additive inverse of the one element, i.e. -1.
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
const CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
EXTERN_VAR BBA_Proc sca_mora
EXTERN_VAR BBA_Proc sca_bba
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
static poly nc_mm_Mult_pp(const poly m, const poly p, const ring r)
static bool rIsSCA(const ring r)
void nc_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
static nc_type & ncRingType(nc_struct *p)
static poly sca_mm_Mult_m(const poly pMonomMM, poly pMonomM, const ring rRing)
void sca_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
bool sca_SetupQuotient(ring rGR, ring rG, bool bCopy)
static poly m_KillSquares(const poly m, const short iFirstAltVar, const short iLastAltVar, const ring r)
static poly sca_xi_Mult_pp(short i, const poly pPoly, const ring rRing)
static void m_GetBiDegree(const poly m, const intvec *wx, const intvec *wy, const intvec *wCx, const intvec *wCy, int &dx, int &dy, const ring r)
ideal id_KillSquares(const ideal id, const short iFirstAltVar, const short iLastAltVar, const ring r, const bool bSkipZeroes)
static poly sca_xi_Mult_mm(short i, const poly pMonom, const ring rRing)
static poly sca_p_mm_Mult(poly pPoly, const poly pMonom, const ring rRing)
poly p_KillSquares(const poly p, const short iFirstAltVar, const short iLastAltVar, const ring r)
poly sca_pp_Mult_mm(const poly pPoly, const poly pMonom, const ring rRing, poly &)
bool p_IsBiHomogeneous(const poly p, const intvec *wx, const intvec *wy, const intvec *wCx, const intvec *wCy, int &dx, int &dy, const ring r)
poly sca_p_Mult_mm(poly pPoly, const poly pMonom, const ring rRing)
intvec * ivGetSCAXVarWeights(const ring r)
static int sca_Sign_mm_Mult_mm(const poly pMonomM, const poly pMonomMM, const ring rRing)
poly sca_pp_Mult_xi_pp(short i, const poly pPoly, const ring rRing)
intvec * ivGetSCAYVarWeights(const ring r)
poly sca_ReduceSpoly(const poly p1, poly p2, const ring r)
static poly sca_mm_Mult_mm(poly pMonom1, const poly pMonom2, const ring rRing)
static poly sca_m_Mult_mm(poly pMonomM, const poly pMonomMM, const ring rRing)
bool sca_Force(ring rGR, int b, int e)
poly sca_SPoly(const poly p1, const poly p2, const ring r)
bool id_IsBiHomogeneous(const ideal id, const intvec *wx, const intvec *wy, const intvec *wCx, const intvec *wCy, const ring r)
static poly sca_pp_mm_Mult(const poly pPoly, const poly pMonom, const ring rRing)
void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
set spaces to zero by default
#define MATELEM(mat, i, j)
1-based access to matrix
int dReportError(const char *fmt,...)
#define p_SetCoeff0(p, n, r)
#define p_AllocBin(p, bin, r)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
STATIC_VAR p_Procs_s * _p_procs
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
poly p_Cleardenom(poly p, const ring r)
void p_Lcm(const poly a, const poly b, poly m, const ring r)
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
static poly p_Add_q(poly p, poly q, const ring r)
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
static poly p_LmInit(poly p, const ring r)
void p_Write(poly p, ring lmRing, ring tailRing)
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
static void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
static void p_Setm(poly p, const ring r)
static number p_SetCoeff(poly p, number n, ring r)
static poly p_Head(const poly p, const ring r)
copy the (leading) term of p
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
static poly p_Mult_nn(poly p, number n, const ring r)
static void p_Delete(poly *p, const ring r)
static poly pp_Mult_qq(poly p, poly q, const ring r)
static poly p_LmDeleteAndNext(poly p, const ring r)
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
void PrintS(const char *s)
void Werror(const char *fmt,...)
void rWrite(ring r, BOOLEAN details)
struct p_Procs_s p_Procs_s
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
static short rVar(const ring r)
#define rVar(r) (r->N)
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
static short scaLastAltVar(ring r)
static short scaFirstAltVar(ring r)
ideal idInit(int idsize, int rank)
initialise an ideal / module
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size