40#define SM_MIN_LENGTH_BUCKET MIN_LENGTH_BUCKET - 5
42#define SM_MIN_LENGTH_BUCKET MAX_INT_VAL
45typedef struct smprec sm_prec;
60static void sm_ExpMultDiv(poly,
const poly,
const poly,
const ring);
61static void sm_PolyDivN(poly,
const number,
const ring);
64static void sm_FindRef(poly *, poly *, poly,
const ring);
86 p =
currRing->p_Procs->pp_Mult_Coeff_mm_DivSelectMult(
p,
m, a,
b,
196 al = di*
sizeof(long);
198 bl = ra*
sizeof(long);
200 for (
i=di-1;
i>=0;
i--)
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);
315 number diag,
h=n_Init(1,
R->cf);
337 if (!n_Equal(diag,
h,
R->cf))
339 p_Mult_nn(
res,diag,
R);
342 n_Delete(&diag,
R->cf);
367 *iv=
new intvec(1,rVar(tmpR));
468 for (
i=
v->rows()-1;
i>=0;
i--)
660 if ((wr<0.25) || (wc<0.25))
701 float wc, wp,
w, hp =
piv->f;
739 float wopt = 1.0e30, hp =
piv->f;
742 int i, copt, ropt,
f, e =
crd;
761 if ((wr<0.25) || (wc<0.25))
826 res->m = pp_Mult_qq(
b->m,
w,
_R);
838 else if (a->pos >
b->pos)
841 res->m = pp_Mult_qq(
b->m,
w,
_R);
848 ha = pp_Mult_qq(a->m,
p,
_R);
850 hb = pp_Mult_qq(
b->m,
w,
_R);
851 ha = p_Add_q(ha, hb,
_R);
925 else if (a->pos >
b->pos)
970 if (
y != hp) p_Delete(&
y,
_R);
983 ha = p_Add_q(
x,
y,
_R);
1008 }
while (r !=
NULL);
1037 }
while (a->pos <
rpiv);
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);
1142 if (
i >
act)
return;
1172 if (
i >
act)
return;
1217 }
while ((a !=
NULL) && (a->pos <=
tored));
1233 if ((a ==
NULL) || (a->pos >
tored))
break;
1236 if ((
k >
i) && (a->pos <=
tored))
1243 }
while ((a !=
NULL) && (a->pos <=
tored));
1253 while ((a !=
NULL) && (a->pos <=
tored))
1406 }
while (a !=
NULL);
1425 }
while (a !=
NULL);
1446 }
while (a !=
NULL);
1486 }
while (a !=
NULL);
1560void sm_PolyDiv(poly a, poly
b,
const ring
R)
1562 const number
x = pGetCoeff(
b);
1571 if (!p_LmIsConstantComp(
b,
R))
1573 for (
i=rVar(
R);
i;
i--)
1574 p_SubExp(a,
i,p_GetExp(
b,
i,
R),
R);
1577 y = n_Div(pGetCoeff(a),
x,
R->cf);
1578 n_Normalize(
y,
R->cf);
1581 }
while (a !=
NULL);
1587 for (
i=rVar(
R);
i;
i--)
1588 p_SubExp(a,
i,p_GetExp(
b,
i,
R),
R);
1590 y = n_Div(pGetCoeff(a),
x,
R->cf);
1591 n_Normalize(
y,
R->cf);
1593 yn = n_InpNeg(n_Copy(
y,
R->cf),
R->cf);
1600 for (
i=rVar(
R);
i;
i--)
1601 p_SetExp(
h,
i,p_GetExp(a,
i,
R)+p_GetExp(t,
i,
R),
R);
1605 }
while (t !=
NULL);
1606 n_Delete(&yn,
R->cf);
1620poly 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);
1764 if ((c ==
NULL) || p_LmIsConstantComp(c,
R))
1766 return pp_Mult_qq(a,
b,
R);
1782 lead = p_LmDivisibleByNoComp(e, a,
R);
1788 r = pp_Mult_mm(a, e,
R);
1818 if (p_LmDivisibleByNoComp(e, a,
R))
1821 pa = p_Add_q(pa,r,
R);
1825 r = pp_Mult_mm(a, e,
R);
1829 }
while (
b !=
NULL);
1853 const number
x = pGetCoeff(
b);
1854 poly tail =
pNext(
b), e = p_Init(
R);
1857 int lt = pLength(tail);
1866 y = n_Div(pGetCoeff(a),
x,
R->cf);
1867 n_Normalize(
y,
R->cf);
1869 yn = n_InpNeg(n_Copy(
y,
R->cf),
R->cf);
1877 h = pp_Mult_mm(tail, e,
R);
1878 n_Delete(&yn,
R->cf);
1889 y = n_Div(pGetCoeff(a),
x,
R->cf);
1890 n_Normalize(
y,
R->cf);
1892 yn = n_InpNeg(n_Copy(
y,
R->cf),
R->cf);
1897 h = pp_Mult_mm(tail, e,
R);
1898 n_Delete(&yn,
R->cf);
1908 if (p_LmDivisibleByNoComp(c,
b,
R))
1910 p_ExpVectorDiff(a,
b, c,
R);
1918 for (
i=rVar(
R);
i>0;
i--)
1920 if(p_GetExp(c,
i,
R) > p_GetExp(
b,
i,
R))
1921 p_SetExp(a,
i,p_GetExp(c,
i,
R)-p_GetExp(
b,
i,
R),
R);
1938 p_ExpVectorDiff(bc,
b, c,
R);
1942 p_ExpVectorAdd(t, bc,
R);
1955 y = n_Div(pGetCoeff(a),
x,
R->cf);
1956 n_Normalize(
y,
R->cf);
1959 }
while (a !=
NULL);
1987 i = p_LmCmp(pb, r,
R);
1994 x = n_Add(pGetCoeff(pb), pGetCoeff(r),
R->cf);
1996 if (n_IsZero(
x,
R->cf))
1999 pNext(pa) = p_Add_q(pb,r,
R);
2024 poly pa = *px,
pp =
NULL;
2028 i = p_LmCmp(pa, r,
R);
2043 x = n_Add(pGetCoeff(pa), pGetCoeff(r),
R->cf);
2045 if (n_IsZero(
x,
R->cf))
2051 *px = p_Add_q(pa,r,
R);
2088 memcpy(r, a,
sizeof(
smprec));
2179 float res = (float)n_Size(pGetCoeff(
p),
R->cf);
2183 for(
i=rVar(
R);
i>0;
i--)
2185 if (p_GetExp(
p,
i,
R) != 0)
return res+1.0;
2196 res += (float)n_Size(pGetCoeff(
p),
R->cf);
2200 return res+(float)
i;
2211 x = n_GetDenom(pGetCoeff(a),
R->cf);
2212 sw = n_IsOne(
x,
R->cf);
2226 number
x,
y,
res=n_Init(1,
R->cf);
2235 if (!sw)
return res;
2241 x = n_Copy(pGetCoeff(a),
R->cf);
2243 y = n_Div(
x,pGetCoeff(a),
R->cf);
2246 n_Normalize(
x,
R->cf);
2247 n_Delete(&
res,
R->cf);
2256typedef struct smnrec sm_nrec;
2324 WerrorS(
"symbol in equation");
2340 WerrorS(
"singular problem for linsolv");
2402 if (
sing != 0)
return;
2413 if (
sing != 0)
return;
2449 n_Delete(&
x,
_R->cf);
2462 z = n_Mult(
sol[
j],
s->m,
_R->cf);
2466 x = n_Sub(
y, z,
_R->cf);
2467 n_Delete(&
y,
_R->cf);
2468 n_Delete(&z,
_R->cf);
2471 x = n_InpNeg(z,
_R->cf);
2480 n_Delete(&
x,
_R->cf);
2481 if (n_IsZero(
y,
_R->cf))
2483 n_Delete(&
sol[
i],
_R->cf);
2495 sol[
i] = n_Div(
x, d->m,
_R->cf);
2496 n_Delete(&
x,
_R->cf);
2531 xo=n_Init(0,
_R->cf);
2538 if (n_GreaterZero(
x,
_R->cf))
2540 if (n_Greater(
x,xo,
_R->cf))
2542 n_Delete(&xo,
_R->cf);
2543 xo = n_Copy(
x,
_R->cf);
2550 xo = n_InpNeg(xo,
_R->cf);
2551 if (n_Greater(xo,
x,
_R->cf))
2553 n_Delete(&xo,
_R->cf);
2554 xo = n_Copy(
x,
_R->cf);
2558 xo = n_InpNeg(xo,
_R->cf);
2570 n_Delete(&xo,
_R->cf);
2578 number
p = n_Invers(
piv->m,
_R->cf);
2595 w = n_Mult(r->m,
p,
_R->cf);
2596 n_Delete(&r->m,
_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);
2625 n_Delete(&hb,
_R->cf);
2626 n_Delete(&a->m,
_R->cf);
2627 if (n_IsZero(ha,
_R->cf))
2647 }
while (r !=
NULL);
2648 n_Delete(&
p,
_R->cf);
2676 }
while (a->pos <
rpiv);
2692 if ((a ==
NULL) || (a->pos >
rpiv))
2697 a->m = n_InpNeg(a->m,
_R->cf);
2704 else if (a->pos ==
rpiv)
2707 a->m = n_InpNeg(a->m,
_R->cf);
2829 n_Delete(&a->m,
R->cf);
2837 memcpy(r, a,
sizeof(
smnrec));
2854 a->m = pGetCoeff(
p);
2867 a->m = pGetCoeff(
p);
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");
sparse_mat(ideal, const ring)
void smToIntvec(intvec *)
void smNewBareiss(int, int)
sparse_number_mat(ideal, const ring)
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
void WerrorS(const char *s)
void kBucketDestroy(kBucket_pt *bucket_pt)
void kBucketInit(kBucket_pt bucket, poly lm, int length)
poly kBucketExtractLm(kBucket_pt bucket)
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
#define omFreeSize(addr, size)
#define omFreeBin(addr, bin)
#define omGetSpecBin(size)
#define TEST_OPT_NOT_BUCKETS
void p_Normalize(poly p, const ring r)
poly p_Cleardenom(poly p, const ring r)
static poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
poly prMoveR(poly &p, ring src_r, ring dest_r)
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
void PrintS(const char *s)
void Werror(const char *fmt,...)
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...
void rKillModifiedRing(ring r)
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
static BOOLEAN rOrd_is_Comp_dp(const ring r)
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
BOOLEAN id_IsConstant(ideal id, const ring r)
test if the ideal has only constant polynomials NOTE: zero ideal/module is also constant
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
STATIC_VAR omBin smnrec_bin
static void sm_ElemDelete(smpoly *, const ring)
static smnumber sm_Poly2Smnumber(poly, const ring)
static void smMinSelect(long *, int, int)
poly sm_MultDiv(poly a, poly b, const poly c, const ring R)
static BOOLEAN sm_HaveDenom(poly, const ring)
#define SM_MIN_LENGTH_BUCKET
long sm_ExpBound(ideal m, int di, int ra, int t, const ring currRing)
static void sm_CombineChain(poly *, poly, const ring)
poly sm_CallDet(ideal I, const ring R)
static poly pp_Mult_Coeff_mm_DivSelect_MultDiv(poly p, int &lp, poly m, poly a, poly b, const ring currRing)
static void sm_NumberDelete(smnumber *, const ring R)
void sm_CallBareiss(ideal I, int x, int y, ideal &M, intvec **iv, const ring R)
static float sm_PolyWeight(smpoly, const ring)
static BOOLEAN smSmaller(poly, poly)
ideal sm_CallSolv(ideal I, const ring R)
static smnumber smNumberCopy(smnumber)
static poly sm_Smpoly2Poly(smpoly, const ring)
static smpoly smElemCopy(smpoly)
static number sm_Cleardenom(ideal, const ring)
static poly sm_SelectCopy_ExpMultDiv(poly p, poly m, poly a, poly b, const ring currRing)
static void sm_ExpMultDiv(poly, const poly, const poly, const ring)
ring sm_RingChange(const ring origR, long bound)
static BOOLEAN smCheckSolv(ideal)
void sm_SpecialPolyDiv(poly a, poly b, const ring R)
static BOOLEAN sm_IsNegQuot(poly, const poly, const poly, const ring)
static void sm_ExactPolyDiv(poly, poly, const ring)
static void sm_FindRef(poly *, poly *, poly, const ring)
void sm_KillModifiedRing(ring r)
static smpoly sm_Poly2Smpoly(poly, const ring)
static void sm_PolyDivN(poly, const number, const ring)
static poly sm_Smnumber2Poly(number, const ring)