15#define SHIFT_MULT_COMPAT_MODE
17#ifdef SHIFT_MULT_DEBUG
23#ifdef SHIFT_MULT_DEBUG
34 int lV = ri->isLPring;
36#ifdef SHIFT_MULT_COMPAT_MODE
50 number mCoeff = pGetCoeff(_m);
51 omBin bin = ri->PolyBin;
52 pAssume(!n_IsZero(mCoeff, ri->cf));
55 int *mExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
56 p_GetExpV(_m,mExpV,ri);
58 int *pExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
64 pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(
p), ri->cf));
66 p_GetExpV(
p, pExpV, ri);
69 p_SetExpV(q, pExpV, ri);
77#ifdef SHIFT_MULT_COMPAT_MODE
79 p_Delete(&pCopyHead, ri);
81#ifdef SHIFT_MULT_DEBUG
91#ifdef SHIFT_MULT_DEBUG
100 int lV = ri->isLPring;
102#ifdef SHIFT_MULT_COMPAT_MODE
113 number mCoeff = pGetCoeff(_m);
115 pAssume(!n_IsZero(mCoeff, ri->cf));
117 int *mExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
118 p_GetExpV(_m,mExpV,ri);
120 int *pExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
123 pCoeff = pGetCoeff(
p);
125 n_Delete(&pCoeff, ri->cf);
127 p_GetExpV(
p,pExpV,ri);
129 p_SetExpV(
p, pExpV, ri);
135#ifdef SHIFT_MULT_COMPAT_MODE
138#ifdef SHIFT_MULT_DEBUG
147#ifdef SHIFT_MULT_DEBUG
158 int lV = ri->isLPring;
160#ifdef SHIFT_MULT_COMPAT_MODE
174 number mCoeff = pGetCoeff(_m);
175 omBin bin = ri->PolyBin;
176 pAssume(!n_IsZero(mCoeff, ri->cf));
179 int *mExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
180 p_GetExpV(_m,mExpV,ri);
182 int *pExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
188 pSetCoeff0(q, n_Mult(mCoeff, pGetCoeff(
p), ri->cf));
190 p_GetExpV(
p, pExpV, ri);
193 p_SetExpV(q, pExpV, ri);
200#ifdef SHIFT_MULT_COMPAT_MODE
202 p_Delete(&pCopyHead, ri);
204#ifdef SHIFT_MULT_DEBUG
214#ifdef SHIFT_MULT_DEBUG
223 int lV = ri->isLPring;
225#ifdef SHIFT_MULT_COMPAT_MODE
236 number mCoeff = pGetCoeff(_m);
238 pAssume(!n_IsZero(mCoeff, ri->cf));
240 int *mExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
241 p_GetExpV(_m,mExpV,ri);
243 int *pExpV = (
int *)
omAlloc((ri->N+1)*
sizeof(
int));
246 pCoeff = pGetCoeff(
p);
248 n_Delete(&pCoeff, ri->cf);
250 p_GetExpV(
p,pExpV,ri);
252 p_SetExpV(
p, pExpV, ri);
258#ifdef SHIFT_MULT_COMPAT_MODE
261#ifdef SHIFT_MULT_DEBUG
270#ifdef SHIFT_MULT_DEBUG
274 Shorter = pLength(
p) + pLength(q);
276 poly tmp = p_Neg(p_Copy(
m, ri), ri);
280#ifdef SHIFT_MULT_DEBUG
283 Shorter -= pLength(qq);
290 WarnS(
"\n** pp_Mult_mm_Noether is not supported yet by Letterplace. Ignoring spNoether and using pp_Mult_mm. This might lead to unexpected behavior.");
302 ll = pLen - pLength(
p);
315 WarnS(
"\n** pp_Mult_Coeff_mm_DivSelectMult is not supported yet by Letterplace. This might lead to unexpected behavior.");
320 WarnS(
"\n** pp_Mult_Coeff_mm_DivSelect is not supported yet by Letterplace. This might lead to unexpected behavior.");
329 if (
m ==
NULL || p_LmIsConstantComp(
m,ri))
return;
331 int lV = ri->isLPring;
335 if (shift == 0)
return;
337 int *e=(
int *)
omAlloc((ri->N+1)*
sizeof(
int));
338 int *
s=(
int *)
omAlloc0((ri->N+1)*
sizeof(
int));
341 int expVoffset = shift*lV;
342 for (
int i = 1 + expVoffset;
i <= ri->N;
i++)
345 s[
i - expVoffset] = e[
i];
364 if (sh == 0 ||
m ==
NULL || p_LmIsConstantComp(
m,ri))
return;
366 int lV = ri->isLPring;
371 int *e=(
int *)
omAlloc((ri->N+1)*
sizeof(
int));
372 int *
s=(
int *)
omAlloc0((ri->N+1)*
sizeof(
int));
377 Werror(
"degree bound of Letterplace ring is %d, but at least %d is needed for this shift", ri->N/lV,
p_mLastVblock(
m, e, ri) + sh);
379 for (
int i = ri->N - sh*lV;
i > 0;
i--)
384 s[
i + (sh*lV)] = e[
i];
413 ans = si_max(ans,ansnew);
423 if (
p ==
NULL || p_LmIsConstantComp(
p,ri))
428 int *e=(
int *)
omAlloc((ri->N+1)*
sizeof(
int));
439 if (
p ==
NULL || p_LmIsConstantComp(
p,ri))
444 int lV = ri->isLPring;
447 while ( (!expV[
j]) && (
j>=1) )
j--;
449 b = (int)((
j+lV-1)/lV);
468 ans = si_min(ans,ansnew);
480 if (
p ==
NULL || p_LmIsConstantComp(
p,ri))
485 int *e=(
int *)
omAlloc((ri->N+1)*
sizeof(
int));
496 if (
p ==
NULL || p_LmIsConstantComp(
p,ri))
501 int lV = ri->isLPring;
506 b = (int)(
j+lV-1)/lV;
511void p_LPExpVappend(
int *m1ExpV,
int *m2ExpV,
int m1Length,
int m2Length,
const ring ri) {
512#ifdef SHIFT_MULT_DEBUG
517 int last = m1Length + m2Length;
520 Werror(
"degree bound of Letterplace ring is %d, but at least %d is needed for this multiplication", ri->N/ri->isLPring,
last/ri->isLPring);
523 for (
int i = 1 + m1Length;
i < 1 +
last; ++
i)
525 assume(m2ExpV[
i - m1Length] <= 1);
526 m1ExpV[
i] = m2ExpV[
i - m1Length];
529 assume(m1ExpV[0] == 0 || m2ExpV[0] == 0);
530 m1ExpV[0] += m2ExpV[0];
531#ifdef SHIFT_MULT_DEBUG
538void p_LPExpVprepend(
int *m1ExpV,
int *m2ExpV,
int m1Length,
int m2Length,
const ring ri)
540#ifdef SHIFT_MULT_DEBUG
545 int last = m1Length + m2Length;
548 Werror(
"degree bound of Letterplace ring is %d, but at least %d is needed for this multiplication", ri->N/ri->isLPring,
last/ri->isLPring);
553 for (
int i =
last;
i >= 1 + m2Length; --
i)
555 m1ExpV[
i] = m1ExpV[
i - m2Length];
559 for (
int i = 1;
i < 1 + m2Length; ++
i)
562 m1ExpV[
i] = m2ExpV[
i];
565 assume(m1ExpV[0] == 0 || m2ExpV[0] == 0);
566 m1ExpV[0] += m2ExpV[0];
567#ifdef SHIFT_MULT_DEBUG
583 for (
int i = 0;
i <= ri->N; ++
i)
590 if (
i % ri->isLPring == 0 &&
i != ri->N)
603 assume(at <= r->
N/r->isLPring);
604 int lV = r->isLPring;
605 int split = (lV * (at - 1));
607 m2 = p_GetExp_k_n(m1, 1,
split, r);
613 for(
int i =
split + 1;
i <= r->N;
i++)
615 p_SetExp(m1,
i, 0, r);
626 int *e=(
int *)
omAlloc((r->N+1)*
sizeof(
int));
636 int lV = r->isLPring;
638 int ncGenCount = r->LPncGenCount;
641 for (
int j =
i*lV;
j > (
i*lV - ncGenCount);
j--)
658 if (
p ==
NULL)
return 0;
661 int lV = r->isLPring;
663 int ncGenCount = r->LPncGenCount;
666 for (
int j =
i*lV;
j > (
i*lV - ncGenCount);
j--)
668 if (p_GetExp(
p,
j, r))
670 return j -
i*lV + ncGenCount;
682 for(
i = 0;
i <=
s;
i++)
713 int lV = r->isLPring;
715 if ( p_Totaldegree(
p, r)==0 )
return(1);
719 int *e = (
int *)
omAlloc((r->N+1)*
sizeof(
int));
720 int b = (int)((r->N+lV-1)/lV);
729 for (
i=(
j-1)*lV + 1;
i<=
j*lV;
i++)
731 if (e[
i])
B[
j] =
B[
j]+1;
798#ifdef SHIFT_MULT_COMPAT_MODE
806 for (
int i = 0;
i <= bLastVblock - aLastVblock;
i++)
808 bool divisible =
true;
809 for (
int j = 1;
j <= aLastVblock * r->isLPring;
j++)
811 if (p_GetExp(a,
j, r) > p_GetExp(
b,
j + (
i * r->isLPring), r))
819 #ifdef SHIFT_MULT_COMPAT_MODE
826#ifdef SHIFT_MULT_COMPAT_MODE
847 if (
p ==
NULL || pos < 1 || pos > (r->N / r->isLPring))
return NULL;
850 if (p_GetExp(
p,
i, r)) {
851 p_SetExp(
v,
i - (pos-1) * r->isLPring, 1, r);
868 int lV = r->isLPring;
872 poly remaining = p_Head(
m, r);
874 p_SetComp(remaining, 0, r);
878 if (p_GetExp(remaining, var, r)) {
884 int startOfBlock = 1 + lV*
i;
885 int endOfBlock = lV*(
i+1);
887 poly left = p_GetExp_k_n(remaining, startOfBlock, r->N, r);
888 p_SetCoeff(left, n_Copy(
p_GetCoeff(remaining, r), r->cf), r);
891 poly right = p_GetExp_k_n(remaining, 1, endOfBlock, r);
892 p_Delete(&remaining, r);
895 left = p_Mult_q(left, p_Copy(e, r), r);
903 return p_Mult_q(
result, remaining, r);
928 int *
w=(
int*)
omAlloc(new_ring->N*
sizeof(
int));
931 for(
int i=old_ring->N-1;
i>=0;
i--)
933 if (old_ring->wvhdl[
p][
i]<-0)
return TRUE;
934 w[
b*old_ring->N+
i]=old_ring->wvhdl[
p][
i];
937 new_ring->wvhdl[
p]=
w;
938 new_ring->block1[
p]=new_ring->N;
944 if (ncGenCount) r =
rCopy0(r);
945 char *varname=(
char *)
omAlloc(20);
946 for (
int i = 1;
i <= ncGenCount;
i++)
948 snprintf(varname,20,
"ncgen(%d)",
i);
973 R->LPncGenCount=ncGenCount;
980 WerrorS(
"weights must be positive");
996 WerrorS(
"weights must be positive");
1005 WerrorS(
"ordering (a(..),lp/rp not implemented for Letterplace rings");
1008 int ** wvhdl=(
int**)
omAlloc0((r->N+3)*
sizeof(
int*));
1010 int* blk0=(
int*)
omAlloc0((r->N+3)*
sizeof(
int));
1011 int* blk1=(
int*)
omAlloc0((r->N+3)*
sizeof(
int));
1016 for(
int i=0;
i<r->N;
i++)
1023 for(
int j=0;
j<d;
j++)
1027 wvhdl[
i+
p][
j*r->N+
i]=1;
1029 wvhdl[
i+
p][(
j+1)*r->N-
i-1]=1;
1032 ord[r->N+
p]=r->order[
p];
1037 if (
p==1) ord[0]=r->order[0];
1038 else if (
p==0) ord[r->N+1]=r->order[1];
1041 WerrorS(
"ordering not implemented for Letterplace rings");
1048 default:
WerrorS(
"ordering not implemented for Letterplace rings");
1052 char **names=(
char**)
omAlloc(
R->N*
sizeof(
char*));
1053 for(
int b=0;
b<d;
b++)
1055 for(
int i=r->N-1;
i>=0;
i--)
const CanonicalForm CFMap CFMap & N
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
static CFList split(const CanonicalForm &F, const int m, const Variable &x)
void WerrorS(const char *s)
#define pIfThen1(cond, check)
#define p_LmCheckPolyRing1(p, r)
#define p_AllocBin(p, bin, r)
#define omFreeSize(addr, size)
#define p_MemCopy_LengthGeneral(d, s, length)
poly p_Head0(const poly p, const ring r)
like p_Head, but allow NULL coeff
void p_wrp(poly p, ring lmRing, ring tailRing)
Compatibility layer for legacy polynomial operations (over currRing).
void StringSetS(const char *st)
void StringAppendS(const char *st)
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...
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
void rDelete(ring r)
unconditionally deletes fields in r
ring rPlusVar(const ring r, char *v, int left)
K[x],"y" -> K[x,y] resp. K[y,x].
BOOLEAN _p_LPLmDivisibleByNoComp(poly a, poly b, const ring r)
void p_LPExpVprepend(int *m1ExpV, int *m2ExpV, int m1Length, int m2Length, const ring ri)
void p_LPshift(poly p, int sh, const ring ri)
BOOLEAN p_LPLmDivisibleBy(poly a, poly b, const ring r)
poly shift_pp_Mult_Coeff_mm_DivSelect_STUB(poly, const poly, int &, const ring)
int p_mFirstVblock(poly p, const ring ri)
int p_mLastVblock(poly p, const ring ri)
int id_IsInV(ideal I, const ring r)
poly shift_p_Minus_mm_Mult_qq(poly p, poly m, poly q, int &Shorter, const poly, const ring ri)
void p_mLPunshift(poly m, const ring ri)
int p_IsInV(poly p, const ring r)
BOOLEAN _p_mLPNCGenValid(poly p, const ring r)
poly shift_pp_mm_Mult(poly p, const poly m, const ring ri)
void p_LPunshift(poly p, const ring ri)
poly shift_pp_Mult_mm_Noether_STUB(poly p, const poly m, const poly, int &ll, const ring ri)
poly shift_p_mm_Mult(poly p, const poly m, const ring ri)
poly p_mLPSubst(poly m, int n, poly e, const ring r)
poly shift_p_Mult_mm(poly p, const poly m, const ring ri)
poly shift_pp_Mult_mm(poly p, const poly m, const ring ri)
BOOLEAN p_LPDivisibleBy(poly a, poly b, const ring r)
int p_GetNCGen(poly p, const ring r)
char * LPExpVString(int *expV, ring ri)
void WriteLPExpV(int *expV, ring ri)
int p_FirstVblock(poly p, const ring r)
int p_LastVblock(poly p, const ring r)
ring freeAlgebra(ring r, int d, int ncGenCount)
create the letterplace ring corresponding to r up to degree d
poly p_LPVarAt(poly p, int pos, const ring r)
void p_LPExpVappend(int *m1ExpV, int *m2ExpV, int m1Length, int m2Length, const ring ri)
int p_mIsInV(poly p, const ring r)
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
void p_mLPshift(poly m, int sh, const ring ri)
poly shift_pp_Mult_Coeff_mm_DivSelectMult_STUB(poly, const poly, const poly, const poly, int &, const ring)
poly p_LPSubst(poly p, int n, poly e, const ring r)
static BOOLEAN freeAlgebra_weights(const ring old_ring, ring new_ring, int p, int d)
substitute weights from orderings a,wp,Wp by d copies of it at position p