40 #define SM_MIN_LENGTH_BUCKET MIN_LENGTH_BUCKET - 5 42 #define SM_MIN_LENGTH_BUCKET MAX_INT_VAL 45 typedef struct smprec sm_prec;
60 static void sm_ExpMultDiv(poly,
const poly,
const poly,
const ring);
61 static void sm_PolyDivN(poly,
const number,
const ring);
64 static void sm_FindRef(poly *, poly *, poly,
const ring);
86 p = currRing->p_Procs->pp_Mult_Coeff_mm_DivSelectMult(p, m, a, b,
148 void smSparseHomog();
166 int smCheckNormalize();
176 void smNewBareiss(
int,
int);
177 void smToIntvec(
intvec *);
196 al = di*
sizeof(long);
198 bl = ra*
sizeof(long);
200 for (i=di-1;i>=0;i--)
208 for (j=currRing->N;j>0;j--)
253 for (i=pos;i<d;i++) c[i] = c[i+1];
263 int *block0=(
int*)
omAlloc0(3*
sizeof(
int));
264 int *block1=(
int*)
omAlloc0(3*
sizeof(
int));
273 tmpR->bitmask = 2*
bound;
274 tmpR->wvhdl = (
int **)
omAlloc0((3) *
sizeof(
int*));
280 if (origR->qideal!=
NULL)
285 Print(
"[%ld:%d]", (
long) tmpR->bitmask, tmpR->ExpL_Size);
292 for(
int i=r->N-1;
i>=0;
i--)
omFree(r->names[
i]);
304 if (I->ncols != I->rank)
306 Werror(
"det of %ld x %d module (matrix)",I->rank,I->ncols);
404 perm = (
int *)
omAlloc(
sizeof(
int)*(i+1));
407 wrw = (
float *)
omAlloc(
sizeof(
float)*
i);
409 wcl = (
float *)
omAlloc(
sizeof(
float)*
i);
431 if (m_act ==
NULL)
return;
468 for (i=v->
rows()-1; i>=0; i--)
486 if (
act != 0) res = m_act[1]->m;
510 if (
act != 0) res = m_act[1]->m;
537 if (
act != 0) res = m_act[1]->m;
551 if ((x > 0) && (x <
nrows))
617 for (i=tored;
i; i--) wrw[i] = 0.0;
660 if ((wr<0.25) || (wc<0.25))
671 wp = w*(wpoints-wcl[
i]-wr);
690 m_act[
act] = m_act[cpiv];
701 float wc, wp,
w, hp = piv->f;
706 for (i=tored;
i; i--) wrw[i] = 0.0;
720 if (f) w /= m_res[
f]->f;
739 float wopt = 1.0e30, hp = piv->f;
742 int i, copt, ropt,
f,
e = crd;
744 this->smNewWeights();
757 if (f) w /= m_res[
f]->f;
761 if ((wr<0.25) || (wc<0.25))
772 wp = w*(wpoints-wcl[
i]-wr);
791 m_act[
act] = m_act[cpiv];
838 else if (a->pos > b->pos)
872 m_act[r->pos] = dumm->n;
880 poly hp = this->smMultPoly(piv);
911 x =
SM_MULT(b->m, hr, m_res[ir]->m,_R);
913 if(ir)
SM_DIV(x, m_res[ir]->
m,_R);
925 else if (a->pos > b->pos)
928 x =
SM_MULT(b->m, hr, m_res[ir]->m,_R);
930 if(ir)
SM_DIV(x, m_res[ir]->
m,_R);
943 x =
SM_MULT(ha, m_res[ir]->
m, m_res[ia]->
m,_R);
946 if (ia)
SM_DIV(ha, m_res[ia]->
m,_R);
949 x =
SM_MULT(ha, gp, m_res[ia]->
m,_R);
951 y =
SM_MULT(b->m, hr, m_res[ia]->m,_R);
957 x =
SM_MULT(ha, m_res[crd]->
m, m_res[ia]->
m,_R);
965 y =
SM_MULT(y, m_res[ir]->
m, m_res[ip]->
m,_R);
966 if (ip)
SM_DIV(y, m_res[ip]->
m,_R);
969 x =
SM_MULT(ha, y, m_res[ia]->
m,_R);
972 y =
SM_MULT(b->m, hr, m_res[ia]->m,_R);
976 x =
SM_MULT(hr, m_res[ia]->
m, m_res[ir]->
m,_R);
977 if (ir)
SM_DIV(x, m_res[ir]->
m,_R);
978 y =
SM_MULT(b->m, x, m_res[ia]->m,_R);
980 x =
SM_MULT(ha, gp, m_res[ia]->
m,_R);
986 if (ia)
SM_DIV(ha, m_res[ia]->
m,_R);
1006 m_act[r->pos] = dumm->n;
1008 }
while (r !=
NULL);
1037 }
while (a->pos < rpiv);
1044 for (i=1; i<
act; i++)
1053 if ((a ==
NULL) || (a->pos > rpiv))
1058 a->m =
p_Neg(a->m,_R);
1065 else if (a->pos == rpiv)
1068 a->m =
p_Neg(a->m,_R);
1090 h->n = m_row[h->pos];
1142 if (i >
act)
return;
1143 if (m_act[i] ==
NULL)
break;
1150 if (m_act[j] !=
NULL)
1152 m_act[
i] = m_act[
j];
1172 if (i >
act)
return;
1173 if (m_act[i]->
pos > tored)
1175 m_res[inred] = m_act[
i];
1185 if (m_act[j]->
pos > tored)
1187 m_res[inred] = m_act[
j];
1192 m_act[
i] = m_act[
j];
1215 perm[crd+
i] = a->pos;
1217 }
while ((a !=
NULL) && (a->pos <= tored));
1224 if (perm[crd+k] >= a->pos)
1226 if (perm[crd+k] > a->pos)
1228 for (l=i;l>=
k;l--) perm[crd+l+1] = perm[crd+l];
1229 perm[crd+
k] = a->pos;
1233 if ((a ==
NULL) || (a->pos > tored))
break;
1236 if ((k > i) && (a->pos <= tored))
1241 perm[crd+
i] = a->pos;
1243 }
while ((a !=
NULL) && (a->pos <= tored));
1253 while ((a !=
NULL) && (a->pos <= tored))
1255 if (perm[crd+k] == a->pos)
1267 if (m_row[j] !=
NULL)
1293 m_res[crd] = m_act[
act];
1296 for (i=1;i<=tored;i++)
1298 if(m_row[i] !=
NULL)
1323 for (i=tored+1;i<=
nrows;i++)
1325 if(m_row[i] !=
NULL)
1348 while (inred <
ncols)
1352 m_res[crd] = m_res[inred];
1371 ha =
SM_MULT(a->m, m_res[e]->m, m_res[f]->m,_R);
1373 if (f)
SM_DIV(ha, m_res[f]->
m,_R);
1399 ha =
SM_MULT(a->m, m_res[e]->m, m_res[f]->m, _R);
1401 if (f)
SM_DIV(ha, m_res[f]->
m, _R);
1406 }
while (a !=
NULL);
1425 }
while (a !=
NULL);
1446 }
while (a !=
NULL);
1461 h =
SM_MULT(h, m_res[crd]->
m, m_res[f]->
m, _R);
1462 if (f)
SM_DIV(h, m_res[f]->
m, _R);
1486 }
while (a !=
NULL);
1551 for (i=
act;
i;i--) perm[i]=i;
1560 void sm_PolyDiv(poly a, poly
b,
const ring
R)
1573 for (i=
rVar(R);
i; i--)
1581 }
while (a !=
NULL);
1587 for (i=
rVar(R);
i; i--)
1600 for (i=
rVar(R);
i; i--)
1605 }
while (t !=
NULL);
1620 poly smMultDiv(poly a, poly b, const poly c)
1626 if ((c == NULL) || pLmIsConstantComp(c))
1628 return pp_Mult_qq(a, b);
1631 pqLength(a, b, la, lb, SM_MIN_LENGTH_BUCKET);
1633 // we iter over b, so, make sure b is the shortest
1634 // such that we minimize our iterations
1649 pSetCoeff0(e,pGetCoeff(b));
1650 if (smIsNegQuot(e, b, c))
1652 lead = pLmDivisibleByNoComp(e, a);
1653 r = smSelectCopy_ExpMultDiv(a, e, b, c);
1658 r = pp_Mult__mm(a, e);
1664 smFindRef(&pa, &res, r);
1674 res = p_Add_q(res, r);
1683 if (!TEST_OPT_NOT_BUCKETS && lb >= SM_MIN_LENGTH_BUCKET)
1685 // use buckets if minimum length is smaller than threshold
1688 // find the last monomial before pa
1692 pNext(append) = res;
1697 while (pNext(append) != pa)
1699 assume(pNext(append) != NULL);
1703 kBucket_pt bucket = kBucketCreate(currRing);
1704 kBucketInit(bucket, pNext(append), 0);
1707 pSetCoeff0(e,pGetCoeff(b));
1708 if (smIsNegQuot(e, b, c))
1711 r = pp_Mult_Coeff_mm_DivSelect_MultDiv(a, lr, e, b, c);
1712 if (pLmDivisibleByNoComp(e, a))
1713 append = kBucket_ExtractLarger_Add_q(bucket, append, r, &lr);
1715 kBucket_Add_q(bucket, r, &lr);
1719 r = pp_Mult__mm(a, e);
1720 append = kBucket_ExtractLarger_Add_q(bucket, append, r, &la);
1723 } while (b != NULL);
1724 pNext(append) = kBucketClear(bucket);
1725 kBucketDestroy(&bucket);
1733 pSetCoeff0(e,pGetCoeff(b));
1734 if (smIsNegQuot(e, b, c))
1736 r = smSelectCopy_ExpMultDiv(a, e, b, c);
1737 if (pLmDivisibleByNoComp(e, a))
1738 smCombineChain(&pa, r);
1744 r = pp_Mult__mm(a, e);
1745 smCombineChain(&pa, r);
1748 } while (b != NULL);
1829 }
while (b !=
NULL);
1918 for (i=
rVar(R); i>0; i--)
1959 }
while (a !=
NULL);
2020 static void sm_FindRef(poly *ref, poly *px, poly r,
const ring R)
2088 memcpy(r, a,
sizeof(
smprec));
2160 q =
pNext(pp) = a->m;
2183 for(i=
rVar(R); i>0; i--)
2185 if (
p_GetExp(p,i,R) != 0)
return res+1.0;
2200 return res+(float)i;
2235 if (!sw)
return res;
2256 typedef struct smnrec sm_nrec;
2297 void smZeroToredElim();
2304 void smTriangular();
2306 ideal smRes2Ideal();
2324 WerrorS(
"symbol in equation");
2340 WerrorS(
"singular problem for linsolv");
2359 tored =
nrows = smat->rank;
2361 perm = (
int *)
omAlloc(
sizeof(
int)*
i);
2362 m_row = (smnumber *)
omAlloc0(
sizeof(smnumber)*
i);
2363 wrw = (
int *)
omAlloc(
sizeof(
int)*
i);
2365 wcl = (
int *)
omAlloc(
sizeof(
int)*
i);
2366 m_act = (smnumber *)
omAlloc(
sizeof(smnumber)*
i);
2367 m_res = (smnumber *)
omAlloc0(
sizeof(smnumber)*
i);
2401 this->smZeroToredElim();
2402 if (sing != 0)
return;
2405 this->smRealPivot();
2412 this->smZeroToredElim();
2413 if (sing != 0)
return;
2433 smnumber
s, d, r = m_row[
nrows];
2436 sol = (number *)
omAlloc0(
sizeof(number)*(crd+1));
2448 sol[
i] =
n_Div(x, m_res[i]->
m,_R->cf);
2462 z =
n_Mult(sol[j], s->m,_R->cf);
2466 x =
n_Sub(y, z,_R->cf);
2479 y =
n_Add(x, sol[i],_R->cf);
2495 sol[
i] =
n_Div(x, d->m,_R->cf);
2535 while ((a!=
NULL) && (a->pos<=tored))
2567 m_act[
act] = m_act[copt];
2579 smnumber c = m_act[
act];
2595 w =
n_Mult(r->m, p,_R->cf);
2605 res->m =
n_Mult(b->m, w,_R->cf);
2607 }
while (b !=
NULL);
2610 if (a->pos < b->pos)
2615 else if (a->pos > b->pos)
2618 res->m =
n_Mult(b->m, w,_R->cf);
2623 hb =
n_Mult(b->m, w,_R->cf);
2624 ha =
n_Add(a->m, hb,_R->cf);
2645 m_act[r->pos] = dumm->n;
2647 }
while (r !=
NULL);
2676 }
while (a->pos < rpiv);
2683 for (i=1; i<
act; i++)
2692 if ((a ==
NULL) || (a->pos > rpiv))
2704 else if (a->pos == rpiv)
2722 smnumber c = m_act[
act];
2729 h->n = m_row[h->pos];
2742 smnumber r = m_row[rpiv];
2782 if ((a==
NULL) || (a->pos>tored))
2827 smnumber a = *r, b = a->n;
2837 memcpy(r, a,
sizeof(
smnrec));
2891 if ((i == 0) || (i != I->rank-1))
2893 WerrorS(
"wrong dimensions for linsolv");
2898 if(I->m[i-1] ==
NULL)
2900 WerrorS(
"singular input for linsolv");
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
static poly sm_Smpoly2Poly(smpoly, const ring)
static FORCE_INLINE BOOLEAN n_Greater(number a, number b, const coeffs r)
ordered fields: TRUE iff 'a' is larger than 'b'; in Z/pZ: TRUE iff la > lb, where la and lb are the l...
sparse_number_mat(ideal, const ring)
const CanonicalForm int s
ring sm_RingChange(const ring origR, long bound)
const CanonicalForm int const CFList const Variable & y
void sm_SpecialPolyDiv(poly a, poly b, const ring R)
static void sm_ExpMultDiv(poly, const poly, const poly, const ring)
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
void kBucketInit(kBucket_pt bucket, poly lm, int length)
static CanonicalForm bound(const CFMatrix &M)
static poly pp_Mult_Coeff_mm_DivSelect_MultDiv(poly p, int &lp, poly m, poly a, poly b, const ring currRing)
static BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r)
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
poly sm_CallDet(ideal I, const ring R)
poly prMoveR(poly &p, ring src_r, ring dest_r)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
#define omFreeSize(addr, size)
static short rVar(const ring r)
#define rVar(r) (r->N)
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
static BOOLEAN smSmaller(poly, poly)
BOOLEAN p_New(leftv res, leftv args)
static poly pp_Mult_mm(poly p, poly m, const ring r)
BOOLEAN id_IsConstant(ideal id, const ring r)
test if the ideal has only constant polynomials NOTE: zero ideal/module is also constant ...
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
void WerrorS(const char *s)
static number sm_Cleardenom(ideal, const ring)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
static void sm_NumberDelete(smnumber *, const ring R)
long sm_ExpBound(ideal m, int di, int ra, int t, const ring currRing)
static number p_SetCoeff(poly p, number n, ring r)
static void p_LmFree(poly p, ring)
poly kBucketExtractLm(kBucket_pt bucket)
BOOLEAN pb(leftv res, leftv args)
static long p_SubExp(poly p, int v, long ee, ring r)
#define TEST_OPT_NOT_BUCKETS
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
static poly sm_Smnumber2Poly(number, const ring)
void smNewBareiss(int, int)
void kBucketDestroy(kBucket_pt *bucket_pt)
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
static smnumber smNumberCopy(smnumber)
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
static void sm_FindRef(poly *, poly *, poly, const ring)
static smpoly sm_Poly2Smpoly(poly, const ring)
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
static BOOLEAN smCheckSolv(ideal)
static poly pp_Mult_qq(poly p, poly q, const ring r)
static BOOLEAN sm_HaveDenom(poly, const ring)
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
static int p_LmCmp(poly p, poly q, const ring r)
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible ...
#define SM_MIN_LENGTH_BUCKET
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 int si_max(const int a, const int b)
void PrintS(const char *s)
static poly p_Mult_nn(poly p, number n, const ring r)
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
static unsigned pLength(poly a)
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
static void sm_PolyDivN(poly, const number, const ring)
void p_Normalize(poly p, const ring r)
static void p_Delete(poly *p, const ring r)
#define omGetSpecBin(size)
ideal idInit(int idsize, int rank)
initialise an ideal / module
const Variable & v
< [in] a sqrfree bivariate poly
static void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
STATIC_VAR omBin smnrec_bin
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
void sm_KillModifiedRing(ring r)
ideal sm_CallSolv(ideal I, const ring R)
static void sm_CombineChain(poly *, poly, const ring)
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 smnumber sm_Poly2Smnumber(poly, const ring)
static smpoly smElemCopy(smpoly)
sparse_mat(ideal, const ring)
static FORCE_INLINE number n_GetDenom(number &n, const coeffs r)
return the denominator of n (if elements of r are by nature not fractional, result is 1) ...
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
void rKillModifiedRing(ring r)
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
static void p_Setm(poly p, const ring r)
poly sm_MultDiv(poly a, poly b, const poly c, const ring R)
static void smMinSelect(long *, int, int)
void sm_CallBareiss(ideal I, int x, int y, ideal &M, intvec **iv, const ring R)
static void sm_ExactPolyDiv(poly, poly, const ring)
static poly p_Neg(poly p, const ring r)
static void p_LmDelete(poly p, const ring r)
static float sm_PolyWeight(smpoly, const ring)
BOOLEAN pa(leftv res, leftv args)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/<p(a)>: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
static poly p_Add_q(poly p, poly q, const ring r)
static poly sm_SelectCopy_ExpMultDiv(poly p, poly m, poly a, poly b, const ring currRing)
#define omFreeBin(addr, bin)
static BOOLEAN rOrd_is_Comp_dp(const ring r)
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
static poly p_Init(const ring r, omBin bin)
poly p_Cleardenom(poly p, const ring r)
static void sm_ElemDelete(smpoly *, const ring)
ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
void smToIntvec(intvec *)
void Werror(const char *fmt,...)
static poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
static BOOLEAN sm_IsNegQuot(poly, const poly, const poly, const ring)