My Project  debian-1:4.1.1-p2+ds-4build3
ring.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT - the interpreter related ring operations
6 */
7 
8 /* includes */
9 #include <cmath>
10 
11 #include "omalloc/omalloc.h"
12 
13 #include "misc/auxiliary.h"
14 #include "misc/mylimits.h"
15 #include "misc/options.h"
16 #include "misc/int64vec.h"
17 
18 #include "coeffs/numbers.h"
19 #include "coeffs/coeffs.h"
20 
22 #include "polys/simpleideals.h"
23 #include "polys/monomials/ring.h"
24 #include "polys/monomials/maps.h"
25 #include "polys/prCopy.h"
27 
28 #include "polys/matpol.h"
29 
30 #include "polys/monomials/ring.h"
31 
32 #ifdef HAVE_PLURAL
33 #include "polys/nc/nc.h"
34 #include "polys/nc/sca.h"
35 #endif
36 
37 
38 #include "ext_fields/algext.h"
39 #include "ext_fields/transext.h"
40 
41 
42 #define BITS_PER_LONG 8*SIZEOF_LONG
43 
45 omBin char_ptr_bin = omGetSpecBin(sizeof(char*));
46 
47 
48 static const char * const ringorder_name[] =
49 {
50  " ?", ///< ringorder_no = 0,
51  "a", ///< ringorder_a,
52  "A", ///< ringorder_a64,
53  "c", ///< ringorder_c,
54  "C", ///< ringorder_C,
55  "M", ///< ringorder_M,
56  "S", ///< ringorder_S,
57  "s", ///< ringorder_s,
58  "lp", ///< ringorder_lp,
59  "dp", ///< ringorder_dp,
60  "rp", ///< ringorder_rp,
61  "Dp", ///< ringorder_Dp,
62  "wp", ///< ringorder_wp,
63  "Wp", ///< ringorder_Wp,
64  "ls", ///< ringorder_ls,
65  "ds", ///< ringorder_ds,
66  "Ds", ///< ringorder_Ds,
67  "ws", ///< ringorder_ws,
68  "Ws", ///< ringorder_Ws,
69  "am", ///< ringorder_am,
70  "L", ///< ringorder_L,
71  "aa", ///< ringorder_aa
72  "rs", ///< ringorder_rs,
73  "IS", ///< ringorder_IS
74  " _" ///< ringorder_unspec
75 };
76 
77 
78 const char * rSimpleOrdStr(int ord)
79 {
80  return ringorder_name[ord];
81 }
82 
83 /// unconditionally deletes fields in r
84 void rDelete(ring r);
85 /// set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex
86 static void rSetVarL(ring r);
87 /// get r->divmask depending on bits per exponent
88 static unsigned long rGetDivMask(int bits);
89 /// right-adjust r->VarOffset
90 static void rRightAdjustVarOffset(ring r);
91 static void rOptimizeLDeg(ring r);
92 
93 /*0 implementation*/
94 //BOOLEAN rField_is_R(ring r)
95 //{
96 // if (r->cf->ch== -1)
97 // {
98 // if (r->float_len==(short)0) return TRUE;
99 // }
100 // return FALSE;
101 //}
102 
103 ring rDefault(const coeffs cf, int N, char **n,int ord_size, rRingOrder_t *ord, int *block0, int *block1, int** wvhdl, unsigned long bitmask)
104 {
105  assume( cf != NULL);
106  ring r=(ring) omAlloc0Bin(sip_sring_bin);
107  r->N = N;
108  r->cf = cf;
109  /*rPar(r) = 0; Alloc0 */
110  /*names*/
111  r->names = (char **) omAlloc0(N * sizeof(char *));
112  int i;
113  for(i=0;i<N;i++)
114  {
115  r->names[i] = omStrDup(n[i]);
116  }
117  /*weights: entries for 2 blocks: NULL*/
118  if (wvhdl==NULL)
119  r->wvhdl = (int **)omAlloc0((ord_size+1) * sizeof(int *));
120  else
121  r->wvhdl=wvhdl;
122  r->order = ord;
123  r->block0 = block0;
124  r->block1 = block1;
125  r->bitmask = bitmask;
126 
127  /* complete ring intializations */
128  rComplete(r);
129  return r;
130 }
131 ring rDefault(int ch, int N, char **n,int ord_size, rRingOrder_t *ord, int *block0, int *block1,int ** wvhdl)
132 {
133  coeffs cf;
134  if (ch==0) cf=nInitChar(n_Q,NULL);
135  else cf=nInitChar(n_Zp,(void*)(long)ch);
136  assume( cf != NULL);
137  return rDefault(cf,N,n,ord_size,ord,block0,block1,wvhdl);
138 }
139 ring rDefault(const coeffs cf, int N, char **n, const rRingOrder_t o)
140 {
141  assume( cf != NULL);
142  /*order: o=lp,0*/
143  rRingOrder_t *order = (rRingOrder_t *) omAlloc(2* sizeof(rRingOrder_t));
144  int *block0 = (int *)omAlloc0(2 * sizeof(int));
145  int *block1 = (int *)omAlloc0(2 * sizeof(int));
146  /* ringorder o=lp for the first block: var 1..N */
147  order[0] = o;
148  block0[0] = 1;
149  block1[0] = N;
150  /* the last block: everything is 0 */
151  order[1] = (rRingOrder_t)0;
152 
153  return rDefault(cf,N,n,2,order,block0,block1);
154 }
155 
156 ring rDefault(int ch, int N, char **n)
157 {
158  coeffs cf;
159  if (ch==0) cf=nInitChar(n_Q,NULL);
160  else cf=nInitChar(n_Zp,(void*)(long)ch);
161  assume( cf != NULL);
162  return rDefault(cf,N,n);
163 }
164 
165 ///////////////////////////////////////////////////////////////////////////
166 //
167 // rInit: define a new ring from sleftv's
168 //
169 //-> ipshell.cc
170 
171 /////////////////////////////
172 // Auxillary functions
173 //
174 
175 // check intvec, describing the ordering
177 {
178  if ((iv->length()!=2)&&(iv->length()!=3))
179  {
180  WerrorS("weights only for orderings wp,ws,Wp,Ws,a,M");
181  return TRUE;
182  }
183  return FALSE;
184 }
185 
186 int rTypeOfMatrixOrder(const intvec* order)
187 {
188  int i=0,j,typ=1;
189  int sz = (int)sqrt((double)(order->length()-2));
190  if ((sz*sz)!=(order->length()-2))
191  {
192  WerrorS("Matrix order is not a square matrix");
193  typ=0;
194  }
195  while ((i<sz) && (typ==1))
196  {
197  j=0;
198  while ((j<sz) && ((*order)[j*sz+i+2]==0)) j++;
199  if (j>=sz)
200  {
201  typ = 0;
202  WerrorS("Matrix order not complete");
203  }
204  else if ((*order)[j*sz+i+2]<0)
205  typ = -1;
206  else
207  i++;
208  }
209  return typ;
210 }
211 
212 
213 int r_IsRingVar(const char *n, char**names,int N)
214 {
215  if (names!=NULL)
216  {
217  for (int i=0; i<N; i++)
218  {
219  if (names[i]==NULL) return -1;
220  if (strcmp(n,names[i]) == 0) return (int)i;
221  }
222  }
223  return -1;
224 }
225 
226 
227 void rWrite(ring r, BOOLEAN details)
228 {
229  if ((r==NULL)||(r->order==NULL))
230  return; /*to avoid printing after errors....*/
231 
232  assume(r != NULL);
233  const coeffs C = r->cf;
234  assume(C != NULL);
235 
236  int nblocks=rBlocks(r);
237 
238  // omCheckAddrSize(r,sizeof(ip_sring));
239  omCheckAddrSize(r->order,nblocks*sizeof(int));
240  omCheckAddrSize(r->block0,nblocks*sizeof(int));
241  omCheckAddrSize(r->block1,nblocks*sizeof(int));
242  omCheckAddrSize(r->wvhdl,nblocks*sizeof(int *));
243  omCheckAddrSize(r->names,r->N*sizeof(char *));
244 
245  nblocks--;
246 
247 
248  PrintS("// coefficients: ");
249  if( nCoeff_is_algExt(C) )
250  {
251  // NOTE: the following (non-thread-safe!) UGLYNESS
252  // (changing naRing->ShortOut for a while) is due to Hans!
253  // Just think of other ring using the VERY SAME naRing and possible
254  // side-effects...
255  ring R = C->extRing;
256  const BOOLEAN bSaveShortOut = rShortOut(R); R->ShortOut = rShortOut(r) & rCanShortOut(R);
257 
258  n_CoeffWrite(C, details); // for correct printing of minpoly... WHAT AN UGLYNESS!!!
259 
260  R->ShortOut = bSaveShortOut;
261  }
262  else
263  n_CoeffWrite(C, details);
264  PrintLn();
265 // {
266 // PrintS("// characteristic : ");
267 //
268 // char const * const * const params = rParameter(r);
269 //
270 // if (params!=NULL)
271 // {
272 // Print ("// %d parameter : ",rPar(r));
273 //
274 // char const * const * sp= params;
275 // int nop=0;
276 // while (nop<rPar(r))
277 // {
278 // PrintS(*sp);
279 // PrintS(" ");
280 // sp++; nop++;
281 // }
282 // PrintS("\n// minpoly : ");
283 // if ( rField_is_long_C(r) )
284 // {
285 // // i^2+1:
286 // Print("(%s^2+1)\n", params[0]);
287 // }
288 // else if (rMinpolyIsNULL(r))
289 // {
290 // PrintS("0\n");
291 // }
292 // else
293 // {
294 // StringSetS(""); n_Write(r->cf->minpoly, r); PrintS(StringEndS("\n")); // NOTE/TODO: use StringAppendS("\n"); omFree(s);
295 // }
296 // //if (r->qideal!=NULL)
297 // //{
298 // // iiWriteMatrix((matrix)r->qideal,"// minpolys",1,r,0);
299 // // PrintLn();
300 // //}
301 // }
302 // }
303  Print("// number of vars : %d",r->N);
304 
305  //for (nblocks=0; r->order[nblocks]; nblocks++);
306  nblocks=rBlocks(r)-1;
307 
308  for (int l=0, nlen=0 ; l<nblocks; l++)
309  {
310  int i;
311  Print("\n// block %3d : ",l+1);
312 
313  Print("ordering %s", rSimpleOrdStr(r->order[l]));
314 
315 
316  if (r->order[l] == ringorder_IS)
317  {
318  assume( r->block0[l] == r->block1[l] );
319  const int s = r->block0[l];
320  assume( (-2 < s) && (s < 2) );
321  Print("(%d)", s); // 0 => prefix! +/-1 => suffix!
322  continue;
323  }
324  else if (r->order[l]==ringorder_s)
325  {
326  assume( l == 0 );
327  Print(" syz_comp: %d",r->block0[l]);
328  continue;
329  }
330  else if (
331  ( (r->order[l] >= ringorder_lp)
332  ||(r->order[l] == ringorder_M)
333  ||(r->order[l] == ringorder_a)
334  ||(r->order[l] == ringorder_am)
335  ||(r->order[l] == ringorder_a64)
336  ||(r->order[l] == ringorder_aa) ) && (r->order[l] < ringorder_IS) )
337  {
338  PrintS("\n// : names ");
339  for (i = r->block0[l]-1; i<r->block1[l]; i++)
340  {
341  nlen = strlen(r->names[i]);
342  Print(" %s",r->names[i]);
343  }
344  }
345 
346  if (r->wvhdl[l]!=NULL)
347  {
348  for (int j= 0;
349  j<(r->block1[l]-r->block0[l]+1)*(r->block1[l]-r->block0[l]+1);
350  j+=i)
351  {
352  PrintS("\n// : weights ");
353  for (i = 0; i<=r->block1[l]-r->block0[l]; i++)
354  {
355  if (r->order[l] == ringorder_a64)
356  {
357  int64 *w=(int64 *)r->wvhdl[l];
358  #if SIZEOF_LONG == 4
359  Print("%*lld " ,nlen,w[i+j]);
360  #else
361  Print(" %*ld" ,nlen,w[i+j]);
362  #endif
363  }
364  else
365  Print(" %*d" ,nlen,r->wvhdl[l][i+j]);
366  }
367  if (r->order[l]!=ringorder_M) break;
368  }
369  if (r->order[l]==ringorder_am)
370  {
371  int m=r->wvhdl[l][i];
372  Print("\n// : %d module weights ",m);
373  m+=i;i++;
374  for(;i<=m;i++) Print(" %*d" ,nlen,r->wvhdl[l][i]);
375  }
376  }
377  }
378 #ifdef HAVE_PLURAL
379  if(rIsPluralRing(r))
380  {
381  PrintS("\n// noncommutative relations:");
382  if( details )
383  {
384  poly pl=NULL;
385  int nl;
386  int i,j;
387  for (i = 1; i<r->N; i++)
388  {
389  for (j = i+1; j<=r->N; j++)
390  {
391  nl = n_IsOne(p_GetCoeff(MATELEM(r->GetNC()->C,i,j),r), r->cf);
392  if ( (MATELEM(r->GetNC()->D,i,j)!=NULL) || (!nl) )
393  {
394  Print("\n// %s%s=",r->names[j-1],r->names[i-1]);
395  pl = MATELEM(r->GetNC()->MT[UPMATELEM(i,j,r->N)],1,1);
396  p_Write0(pl, r, r);
397  }
398  }
399  }
400  } else
401  PrintS(" ...");
402 
403 #if MYTEST /*Singularg should not differ from Singular except in error case*/
404  Print("\n// noncommutative type:%d", (int)ncRingType(r));
405  Print("\n// is skew constant:%d",r->GetNC()->IsSkewConstant);
406  if( rIsSCA(r) )
407  {
408  Print("\n// alternating variables: [%d, %d]", scaFirstAltVar(r), scaLastAltVar(r));
409  const ideal Q = SCAQuotient(r); // resides within r!
410  PrintS("\n// quotient of sca by ideal");
411 
412  if (Q!=NULL)
413  {
414 // if (r==currRing)
415 // {
416 // PrintLn();
417  iiWriteMatrix((matrix)Q,"scaQ",1,r,0);
418 // }
419 // else
420 // PrintS(" ...");
421  }
422  else
423  PrintS(" (NULL)");
424  }
425 #endif
426  }
427 #endif
428  if (r->qideal!=NULL)
429  {
430  PrintS("\n// quotient ring from ideal");
431  if( details )
432  {
433  PrintLn();
434  iiWriteMatrix((matrix)r->qideal,"_",1,r,0);
435  } else PrintS(" ...");
436  }
437 }
438 
439 void rDelete(ring r)
440 {
441  int i, j;
442 
443  if (r == NULL) return;
444 
445  assume( r->ref <= 0 );
446 
447  if( r->ref > 0 ) // ->ref means the number of Interpreter objects referring to the ring...
448  return; // this should never happen.
449 
450  if( r->qideal != NULL )
451  {
452  ideal q = r->qideal;
453  r->qideal = NULL;
454  id_Delete(&q, r);
455  }
456 
457 #ifdef HAVE_PLURAL
458  if (rIsPluralRing(r))
459  nc_rKill(r);
460 #endif
461 
462  rUnComplete(r); // may need r->cf for p_Delete
463  nKillChar(r->cf); r->cf = NULL;
464  // delete order stuff
465  if (r->order != NULL)
466  {
467  i=rBlocks(r);
468  assume(r->block0 != NULL && r->block1 != NULL && r->wvhdl != NULL);
469  // delete order
470  omFreeSize((ADDRESS)r->order,i*sizeof(rRingOrder_t));
471  omFreeSize((ADDRESS)r->block0,i*sizeof(int));
472  omFreeSize((ADDRESS)r->block1,i*sizeof(int));
473  // delete weights
474  for (j=0; j<i; j++)
475  {
476  if (r->wvhdl[j]!=NULL)
477  omFree(r->wvhdl[j]);
478  }
479  omFreeSize((ADDRESS)r->wvhdl,i*sizeof(int *));
480  }
481  else
482  {
483  assume(r->block0 == NULL && r->block1 == NULL && r->wvhdl == NULL);
484  }
485 
486  // delete varnames
487  if(r->names!=NULL)
488  {
489  for (i=0; i<r->N; i++)
490  {
491  if (r->names[i] != NULL) omFree((ADDRESS)r->names[i]);
492  }
493  omFreeSize((ADDRESS)r->names,r->N*sizeof(char *));
494  }
495 
497 }
498 
499 rRingOrder_t rOrderName(char * ordername)
500 {
501  int order=ringorder_unspec;
502  while (order!= 0)
503  {
504  if (strcmp(ordername,rSimpleOrdStr(order))==0)
505  break;
506  order--;
507  }
508  if (order==0) Werror("wrong ring order `%s`",ordername);
509  omFree((ADDRESS)ordername);
510  return (rRingOrder_t)order;
511 }
512 
513 char * rOrdStr(ring r)
514 {
515  if ((r==NULL)||(r->order==NULL)) return omStrDup("");
516  int nblocks,l,i;
517 
518  for (nblocks=0; r->order[nblocks]; nblocks++);
519  nblocks--;
520 
521  StringSetS("");
522  for (l=0; ; l++)
523  {
524  StringAppendS((char *)rSimpleOrdStr(r->order[l]));
525  if (r->order[l] == ringorder_s)
526  {
527  StringAppend("(%d)",r->block0[l]);
528  }
529  else if (
530  (r->order[l] != ringorder_c)
531  && (r->order[l] != ringorder_C)
532  && (r->order[l] != ringorder_s)
533  && (r->order[l] != ringorder_S)
534  && (r->order[l] != ringorder_IS)
535  )
536  {
537  if (r->wvhdl[l]!=NULL)
538  {
539  StringAppendS("(");
540  for (int j= 0;
541  j<(r->block1[l]-r->block0[l]+1)*(r->block1[l]-r->block0[l]+1);
542  j+=i+1)
543  {
544  char c=',';
545  if(r->order[l]==ringorder_a64)
546  {
547  int64 * w=(int64 *)r->wvhdl[l];
548  for (i = 0; i<r->block1[l]-r->block0[l]; i++)
549  {
550  StringAppend("%lld," ,w[i]);
551  }
552  StringAppend("%lld)" ,w[i]);
553  break;
554  }
555  else
556  {
557  for (i = 0; i<r->block1[l]-r->block0[l]; i++)
558  {
559  StringAppend("%d," ,r->wvhdl[l][i+j]);
560  }
561  }
562  if (r->order[l]!=ringorder_M)
563  {
564  StringAppend("%d)" ,r->wvhdl[l][i+j]);
565  break;
566  }
567  if (j+i+1==(r->block1[l]-r->block0[l]+1)*(r->block1[l]-r->block0[l]+1))
568  c=')';
569  StringAppend("%d%c" ,r->wvhdl[l][i+j],c);
570  }
571  }
572  else
573  StringAppend("(%d)",r->block1[l]-r->block0[l]+1);
574  }
575  else if (r->order[l] == ringorder_IS)
576  {
577  assume( r->block0[l] == r->block1[l] );
578  const int s = r->block0[l];
579  assume( (-2 < s) && (s < 2) );
580 
581  StringAppend("(%d)", s);
582  }
583 
584  if (l==nblocks)
585  {
586  if (r->bitmask!=0xffff)
587  {
588  long mm=r->bitmask;
589  if (mm>MAX_INT_VAL) mm=MAX_INT_VAL;
590  StringAppend(",L(%ld)",mm);
591  }
592  return StringEndS();
593  }
594  StringAppendS(",");
595  }
596 }
597 
598 char * rVarStr(ring r)
599 {
600  if ((r==NULL)||(r->names==NULL)) return omStrDup("");
601  int i;
602  int l=2;
603  char *s;
604 
605  for (i=0; i<r->N; i++)
606  {
607  l+=strlen(r->names[i])+1;
608  }
609  s=(char *)omAlloc((long)l);
610  s[0]='\0';
611  for (i=0; i<r->N-1; i++)
612  {
613  strcat(s,r->names[i]);
614  strcat(s,",");
615  }
616  strcat(s,r->names[i]);
617  return s;
618 }
619 
620 /// TODO: make it a virtual method of coeffs, together with:
621 /// Decompose & Compose, rParameter & rPar
622 char * rCharStr(const ring r){ assume( r != NULL ); return nCoeffString(r->cf); }
623 
624 char * rParStr(ring r)
625 {
626  if ((r==NULL)||(rParameter(r)==NULL)) return omStrDup("");
627 
628  char const * const * const params = rParameter(r);
629 
630  int i;
631  int l=2;
632 
633  for (i=0; i<rPar(r); i++)
634  {
635  l+=strlen(params[i])+1;
636  }
637  char *s=(char *)omAlloc((long)l);
638  s[0]='\0';
639  for (i=0; i<rPar(r)-1; i++)
640  {
641  strcat(s, params[i]);
642  strcat(s,",");
643  }
644  strcat(s, params[i]);
645  return s;
646 }
647 
648 char * rString(ring r)
649 {
650  if ((r!=NULL)&&(r->cf!=NULL))
651  {
652  char *ch=rCharStr(r);
653  char *var=rVarStr(r);
654  char *ord=rOrdStr(r);
655  char *res=(char *)omAlloc(strlen(ch)+strlen(var)+strlen(ord)+9);
656  sprintf(res,"(%s),(%s),(%s)",ch,var,ord);
657  omFree((ADDRESS)ch);
658  omFree((ADDRESS)var);
659  omFree((ADDRESS)ord);
660  return res;
661  }
662  else
663  return omStrDup("undefined");
664 }
665 
666 
667 /*
668 // The fowolling function seems to be never used. Remove?
669 static int binaryPower (const int a, const int b)
670 {
671  // computes a^b according to the binary representation of b,
672  // i.e., a^7 = a^4 * a^2 * a^1. This saves some multiplications.
673  int result = 1;
674  int factor = a;
675  int bb = b;
676  while (bb != 0)
677  {
678  if (bb % 2 != 0) result = result * factor;
679  bb = bb / 2;
680  factor = factor * factor;
681  }
682  return result;
683 }
684 */
685 
686 /* we keep this otherwise superfluous method for compatibility reasons
687  towards the SINGULAR svn trunk */
688 int rChar(ring r) { return r->cf->ch; }
689 
690 // typedef char * char_ptr;
691 // omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr)); // deallocation?
692 
693 
694 // creates a commutative nc extension; "converts" comm.ring to a Plural ring
695 #ifdef HAVE_PLURAL
697 {
698  r = rCopy(r);
699  if (rIsPluralRing(r))
700  return r;
701 
702  matrix C = mpNew(r->N,r->N); // ring-independent!?!
703  matrix D = mpNew(r->N,r->N);
704 
705  for(int i=1; i<r->N; i++)
706  for(int j=i+1; j<=r->N; j++)
707  MATELEM(C,i,j) = p_One( r);
708 
709  if (nc_CallPlural(C, D, NULL, NULL, r, false, true, false, r/*??currRing??*/, TRUE)) // TODO: what about quotient ideal?
710  WarnS("Error initializing multiplication!"); // No reaction!???
711 
712  return r;
713 }
714 #endif
715 
716 
717 /*2
718  *returns -1 for not compatible, (sum is undefined)
719  * 1 for compatible (and sum)
720  */
721 /* vartest: test for variable/paramter names
722 * dp_dp: 0:block ordering
723 * 1:for comm. rings: use block order dp + dp/ds/wp
724 * 2:order aa(..),dp
725 */
726 int rSumInternal(ring r1, ring r2, ring &sum, BOOLEAN vartest, BOOLEAN dp_dp)
727 {
728 
729  ip_sring tmpR;
730  memset(&tmpR,0,sizeof(tmpR));
731  /* check coeff. field =====================================================*/
732 
733  if (r1->cf==r2->cf)
734  {
735  tmpR.cf=nCopyCoeff(r1->cf);
736  }
737  else /* different type */
738  {
739  if (getCoeffType(r1->cf)==n_Zp)
740  {
741  if (getCoeffType(r2->cf)==n_Q)
742  {
743  tmpR.cf=nCopyCoeff(r1->cf);
744  }
745  else if (nCoeff_is_Extension(r2->cf) && rChar(r2) == rChar(r1))
746  {
747  /*AlgExtInfo extParam;
748  extParam.r = r2->cf->extRing;
749  extParam.i = r2->cf->extRing->qideal;*/
750  tmpR.cf=nCopyCoeff(r2->cf);
751  }
752  else
753  {
754  WerrorS("Z/p+...");
755  return -1;
756  }
757  }
758  else if (getCoeffType(r1->cf)==n_R)
759  {
760  WerrorS("R+..");
761  return -1;
762  }
763  else if (getCoeffType(r1->cf)==n_Q)
764  {
765  if (getCoeffType(r2->cf)==n_Zp)
766  {
767  tmpR.cf=nCopyCoeff(r2->cf);
768  }
769  else if (nCoeff_is_Extension(r2->cf))
770  {
771  tmpR.cf=nCopyCoeff(r2->cf);
772  }
773  else
774  {
775  WerrorS("Q+...");
776  return -1;
777  }
778  }
779  else if (nCoeff_is_Extension(r1->cf))
780  {
781  if (r1->cf->extRing->cf==r2->cf)
782  {
783  tmpR.cf=nCopyCoeff(r1->cf);
784  }
785  else if (getCoeffType(r1->cf->extRing->cf)==n_Zp && getCoeffType(r2->cf)==n_Q) //r2->cf == n_Zp should have been handled above
786  {
787  tmpR.cf=nCopyCoeff(r1->cf);
788  }
789  else
790  {
791  WerrorS ("coeff sum of two extension fields not implemented");
792  return -1;
793  }
794  }
795  else
796  {
797  WerrorS("coeff sum not yet implemented");
798  return -1;
799  }
800  }
801  /* variable names ========================================================*/
802  int i,j,k;
803  int l=r1->N+r2->N;
804  char **names=(char **)omAlloc0(l*sizeof(char *));
805  k=0;
806 
807  // collect all varnames from r1, except those which are parameters
808  // of r2, or those which are the empty string
809  for (i=0;i<r1->N;i++)
810  {
811  BOOLEAN b=TRUE;
812 
813  if (*(r1->names[i]) == '\0')
814  b = FALSE;
815  else if ((rParameter(r2)!=NULL) && (strlen(r1->names[i])==1))
816  {
817  if (vartest)
818  {
819  for(j=0;j<rPar(r2);j++)
820  {
821  if (strcmp(r1->names[i],rParameter(r2)[j])==0)
822  {
823  b=FALSE;
824  break;
825  }
826  }
827  }
828  }
829 
830  if (b)
831  {
832  //Print("name : %d: %s\n",k,r1->names[i]);
833  names[k]=omStrDup(r1->names[i]);
834  k++;
835  }
836  //else
837  // Print("no name (par1) %s\n",r1->names[i]);
838  }
839  // Add variables from r2, except those which are parameters of r1
840  // those which are empty strings, and those which equal a var of r1
841  for(i=0;i<r2->N;i++)
842  {
843  BOOLEAN b=TRUE;
844 
845  if (*(r2->names[i]) == '\0')
846  b = FALSE;
847  else if ((rParameter(r1)!=NULL) && (strlen(r2->names[i])==1))
848  {
849  if (vartest)
850  {
851  for(j=0;j<rPar(r1);j++)
852  {
853  if (strcmp(r2->names[i],rParameter(r1)[j])==0)
854  {
855  b=FALSE;
856  break;
857  }
858  }
859  }
860  }
861 
862  if (b)
863  {
864  if (vartest)
865  {
866  for(j=0;j<r1->N;j++)
867  {
868  if (strcmp(r1->names[j],r2->names[i])==0)
869  {
870  b=FALSE;
871  break;
872  }
873  }
874  }
875  if (b)
876  {
877  //Print("name : %d : %s\n",k,r2->names[i]);
878  names[k]=omStrDup(r2->names[i]);
879  k++;
880  }
881  //else
882  // Print("no name (var): %s\n",r2->names[i]);
883  }
884  //else
885  // Print("no name (par): %s\n",r2->names[i]);
886  }
887  // check whether we found any vars at all
888  if (k == 0)
889  {
890  names[k]=omStrDup("");
891  k=1;
892  }
893  tmpR.N=k;
894  tmpR.names=names;
895  /* ordering *======================================================== */
896  tmpR.OrdSgn=0;
897  if ((dp_dp==2)
898  && (r1->OrdSgn==1)
899  && (r2->OrdSgn==1)
900 #ifdef HAVE_PLURAL
901  && !rIsPluralRing(r1) && !rIsPluralRing(r2)
902 #endif
903  )
904  {
905  tmpR.order=(rRingOrder_t*)omAlloc0(4*sizeof(rRingOrder_t));
906  tmpR.block0=(int*)omAlloc0(4*sizeof(int));
907  tmpR.block1=(int*)omAlloc0(4*sizeof(int));
908  tmpR.wvhdl=(int**) omAlloc0(4*sizeof(int**));
909  // ----
910  tmpR.block0[0] = 1;
911  tmpR.block1[0] = rVar(r1)+rVar(r2);
912  tmpR.order[0] = ringorder_aa;
913  tmpR.wvhdl[0]=(int*)omAlloc0((rVar(r1)+rVar(r2) + 1)*sizeof(int));
914  for(int i=0;i<rVar(r1);i++) tmpR.wvhdl[0][i]=1;
915  // ----
916  tmpR.block0[1] = 1;
917  tmpR.block1[1] = rVar(r1)+rVar(r2);
918  tmpR.order[1] = ringorder_dp;
919  // ----
920  tmpR.order[2] = ringorder_C;
921  }
922  else if (dp_dp
923 #ifdef HAVE_PLURAL
924  && !rIsPluralRing(r1) && !rIsPluralRing(r2)
925 #endif
926  )
927  {
928  tmpR.order=(rRingOrder_t*)omAlloc(4*sizeof(rRingOrder_t));
929  tmpR.block0=(int*)omAlloc0(4*sizeof(int));
930  tmpR.block1=(int*)omAlloc0(4*sizeof(int));
931  tmpR.wvhdl=(int**)omAlloc0(4*sizeof(int *));
932  tmpR.order[0]=ringorder_dp;
933  tmpR.block0[0]=1;
934  tmpR.block1[0]=rVar(r1);
935  if (r2->OrdSgn==1)
936  {
937  if ((r2->block0[0]==1)
938  && (r2->block1[0]==rVar(r2))
939  && ((r2->order[0]==ringorder_wp)
940  || (r2->order[0]==ringorder_Wp)
941  || (r2->order[0]==ringorder_Dp))
942  )
943  {
944  tmpR.order[1]=r2->order[0];
945  if (r2->wvhdl[0]!=NULL)
946  tmpR.wvhdl[1]=(int *)omMemDup(r2->wvhdl[0]);
947  }
948  else
949  tmpR.order[1]=ringorder_dp;
950  }
951  else
952  {
953  tmpR.order[1]=ringorder_ds;
954  tmpR.OrdSgn=-1;
955  }
956  tmpR.block0[1]=rVar(r1)+1;
957  tmpR.block1[1]=rVar(r1)+rVar(r2);
958  tmpR.order[2]=ringorder_C;
959  tmpR.order[3]=(rRingOrder_t)0;
960  }
961  else
962  {
963  if ((r1->order[0]==ringorder_unspec)
964  && (r2->order[0]==ringorder_unspec))
965  {
966  tmpR.order=(rRingOrder_t*)omAlloc(3*sizeof(rRingOrder_t));
967  tmpR.block0=(int*)omAlloc(3*sizeof(int));
968  tmpR.block1=(int*)omAlloc(3*sizeof(int));
969  tmpR.wvhdl=(int**)omAlloc0(3*sizeof(int *));
970  tmpR.order[0]=ringorder_unspec;
971  tmpR.order[1]=ringorder_C;
972  tmpR.order[2]=(rRingOrder_t)0;
973  tmpR.block0[0]=1;
974  tmpR.block1[0]=tmpR.N;
975  }
976  else if (l==k) /* r3=r1+r2 */
977  {
978  int b;
979  ring rb;
980  if (r1->order[0]==ringorder_unspec)
981  {
982  /* extend order of r2 to r3 */
983  b=rBlocks(r2);
984  rb=r2;
985  tmpR.OrdSgn=r2->OrdSgn;
986  }
987  else if (r2->order[0]==ringorder_unspec)
988  {
989  /* extend order of r1 to r3 */
990  b=rBlocks(r1);
991  rb=r1;
992  tmpR.OrdSgn=r1->OrdSgn;
993  }
994  else
995  {
996  b=rBlocks(r1)+rBlocks(r2)-2; /* for only one order C, only one 0 */
997  rb=NULL;
998  }
999  tmpR.order=(rRingOrder_t*)omAlloc0(b*sizeof(rRingOrder_t));
1000  tmpR.block0=(int*)omAlloc0(b*sizeof(int));
1001  tmpR.block1=(int*)omAlloc0(b*sizeof(int));
1002  tmpR.wvhdl=(int**)omAlloc0(b*sizeof(int *));
1003  /* weights not implemented yet ...*/
1004  if (rb!=NULL)
1005  {
1006  for (i=0;i<b;i++)
1007  {
1008  tmpR.order[i]=rb->order[i];
1009  tmpR.block0[i]=rb->block0[i];
1010  tmpR.block1[i]=rb->block1[i];
1011  if (rb->wvhdl[i]!=NULL)
1012  WarnS("rSum: weights not implemented");
1013  }
1014  tmpR.block0[0]=1;
1015  }
1016  else /* ring sum for complete rings */
1017  {
1018  for (i=0;r1->order[i]!=0;i++)
1019  {
1020  tmpR.order[i]=r1->order[i];
1021  tmpR.block0[i]=r1->block0[i];
1022  tmpR.block1[i]=r1->block1[i];
1023  if (r1->wvhdl[i]!=NULL)
1024  tmpR.wvhdl[i] = (int*) omMemDup(r1->wvhdl[i]);
1025  }
1026  j=i;
1027  i--;
1028  if ((r1->order[i]==ringorder_c)
1029  ||(r1->order[i]==ringorder_C))
1030  {
1031  j--;
1032  tmpR.order[b-2]=r1->order[i];
1033  }
1034  for (i=0;r2->order[i]!=0;i++)
1035  {
1036  if ((r2->order[i]!=ringorder_c)
1037  &&(r2->order[i]!=ringorder_C))
1038  {
1039  tmpR.order[j]=r2->order[i];
1040  tmpR.block0[j]=r2->block0[i]+rVar(r1);
1041  tmpR.block1[j]=r2->block1[i]+rVar(r1);
1042  if (r2->wvhdl[i]!=NULL)
1043  {
1044  tmpR.wvhdl[j] = (int*) omMemDup(r2->wvhdl[i]);
1045  }
1046  j++;
1047  }
1048  }
1049  if((r1->OrdSgn==-1)||(r2->OrdSgn==-1))
1050  tmpR.OrdSgn=-1;
1051  }
1052  }
1053  else if ((k==rVar(r1)) && (k==rVar(r2))) /* r1 and r2 are "quite"
1054  the same ring */
1055  /* copy r1, because we have the variables from r1 */
1056  {
1057  int b=rBlocks(r1);
1058 
1059  tmpR.order=(rRingOrder_t*)omAlloc0(b*sizeof(rRingOrder_t));
1060  tmpR.block0=(int*)omAlloc0(b*sizeof(int));
1061  tmpR.block1=(int*)omAlloc0(b*sizeof(int));
1062  tmpR.wvhdl=(int**)omAlloc0(b*sizeof(int *));
1063  /* weights not implemented yet ...*/
1064  for (i=0;i<b;i++)
1065  {
1066  tmpR.order[i]=r1->order[i];
1067  tmpR.block0[i]=r1->block0[i];
1068  tmpR.block1[i]=r1->block1[i];
1069  if (r1->wvhdl[i]!=NULL)
1070  {
1071  tmpR.wvhdl[i] = (int*) omMemDup(r1->wvhdl[i]);
1072  }
1073  }
1074  tmpR.OrdSgn=r1->OrdSgn;
1075  }
1076  else
1077  {
1078  for(i=0;i<k;i++) omFree((ADDRESS)tmpR.names[i]);
1079  omFreeSize((ADDRESS)names,tmpR.N*sizeof(char *));
1080  Werror("variables must not overlap (# of vars: %d,%d -> %d)",rVar(r1),rVar(r2),k);
1081  return -1;
1082  }
1083  }
1084  tmpR.bitmask=si_max(r1->bitmask,r2->bitmask);
1085  sum=(ring)omAllocBin(sip_sring_bin);
1086  memcpy(sum,&tmpR,sizeof(ip_sring));
1087  rComplete(sum);
1088 
1089 //#ifdef RDEBUG
1090 // rDebugPrint(sum);
1091 //#endif
1092 
1093 
1094 
1095 #ifdef HAVE_PLURAL
1096  if(1)
1097  {
1098 // ring old_ring = currRing;
1099 
1100  BOOLEAN R1_is_nc = rIsPluralRing(r1);
1101  BOOLEAN R2_is_nc = rIsPluralRing(r2);
1102 
1103  if ( (R1_is_nc) || (R2_is_nc))
1104  {
1105  ring R1 = nc_rCreateNCcomm_rCopy(r1);
1106  assume( rIsPluralRing(R1) );
1107 
1108 #if 0
1109 #ifdef RDEBUG
1110  rWrite(R1);
1111  rDebugPrint(R1);
1112 #endif
1113 #endif
1114  ring R2 = nc_rCreateNCcomm_rCopy(r2);
1115 #if 0
1116 #ifdef RDEBUG
1117  rWrite(R2);
1118  rDebugPrint(R2);
1119 #endif
1120 #endif
1121 
1122 // rChangeCurrRing(sum); // ?
1123 
1124  // Projections from R_i into Sum:
1125  /* multiplication matrices business: */
1126  /* find permutations of vars and pars */
1127  int *perm1 = (int *)omAlloc0((rVar(R1)+1)*sizeof(int));
1128  int *par_perm1 = NULL;
1129  if (rPar(R1)!=0) par_perm1=(int *)omAlloc0((rPar(R1)+1)*sizeof(int));
1130 
1131  int *perm2 = (int *)omAlloc0((rVar(R2)+1)*sizeof(int));
1132  int *par_perm2 = NULL;
1133  if (rPar(R2)!=0) par_perm2=(int *)omAlloc0((rPar(R2)+1)*sizeof(int));
1134 
1135  maFindPerm(R1->names, rVar(R1), rParameter(R1), rPar(R1),
1136  sum->names, rVar(sum), rParameter(sum), rPar(sum),
1137  perm1, par_perm1, sum->cf->type);
1138 
1139  maFindPerm(R2->names, rVar(R2), rParameter(R2), rPar(R2),
1140  sum->names, rVar(sum), rParameter(sum), rPar(sum),
1141  perm2, par_perm2, sum->cf->type);
1142 
1143 
1144  matrix C1 = R1->GetNC()->C, C2 = R2->GetNC()->C;
1145  matrix D1 = R1->GetNC()->D, D2 = R2->GetNC()->D;
1146 
1147  // !!!! BUG? C1 and C2 might live in different baserings!!!
1148 
1149  int l = rVar(R1) + rVar(R2);
1150 
1151  matrix C = mpNew(l,l);
1152  matrix D = mpNew(l,l);
1153 
1154  for (i = 1; i <= rVar(R1); i++)
1155  for (j= rVar(R1)+1; j <= l; j++)
1156  MATELEM(C,i,j) = p_One(sum); // in 'sum'
1157 
1158  id_Test((ideal)C, sum);
1159 
1160  nMapFunc nMap1 = n_SetMap(R1->cf,sum->cf); /* can change something global: not usable
1161  after the next nSetMap call :( */
1162  // Create blocked C and D matrices:
1163  for (i=1; i<= rVar(R1); i++)
1164  for (j=i+1; j<=rVar(R1); j++)
1165  {
1166  assume(MATELEM(C1,i,j) != NULL);
1167  MATELEM(C,i,j) = p_PermPoly(MATELEM(C1,i,j), perm1, R1, sum, nMap1, par_perm1, rPar(R1)); // need ADD + CMP ops.
1168 
1169  if (MATELEM(D1,i,j) != NULL)
1170  MATELEM(D,i,j) = p_PermPoly(MATELEM(D1,i,j), perm1, R1, sum, nMap1, par_perm1, rPar(R1));
1171  }
1172 
1173  id_Test((ideal)C, sum);
1174  id_Test((ideal)D, sum);
1175 
1176 
1177  nMapFunc nMap2 = n_SetMap(R2->cf,sum->cf); /* can change something global: not usable
1178  after the next nSetMap call :( */
1179  for (i=1; i<= rVar(R2); i++)
1180  for (j=i+1; j<=rVar(R2); j++)
1181  {
1182  assume(MATELEM(C2,i,j) != NULL);
1183  MATELEM(C,rVar(R1)+i,rVar(R1)+j) = p_PermPoly(MATELEM(C2,i,j),perm2,R2,sum, nMap2,par_perm2,rPar(R2));
1184 
1185  if (MATELEM(D2,i,j) != NULL)
1186  MATELEM(D,rVar(R1)+i,rVar(R1)+j) = p_PermPoly(MATELEM(D2,i,j),perm2,R2,sum, nMap2,par_perm2,rPar(R2));
1187  }
1188 
1189  id_Test((ideal)C, sum);
1190  id_Test((ideal)D, sum);
1191 
1192  // Now sum is non-commutative with blocked structure constants!
1193  if (nc_CallPlural(C, D, NULL, NULL, sum, false, false, true, sum))
1194  WarnS("Error initializing non-commutative multiplication!");
1195 
1196  /* delete R1, R2*/
1197 
1198 #if 0
1199 #ifdef RDEBUG
1200  rWrite(sum);
1201  rDebugPrint(sum);
1202 
1203  Print("\nRefs: R1: %d, R2: %d\n", R1->GetNC()->ref, R2->GetNC()->ref);
1204 
1205 #endif
1206 #endif
1207 
1208 
1209  rDelete(R1);
1210  rDelete(R2);
1211 
1212  /* delete perm arrays */
1213  if (perm1!=NULL) omFree((ADDRESS)perm1);
1214  if (perm2!=NULL) omFree((ADDRESS)perm2);
1215  if (par_perm1!=NULL) omFree((ADDRESS)par_perm1);
1216  if (par_perm2!=NULL) omFree((ADDRESS)par_perm2);
1217 
1218 // rChangeCurrRing(old_ring);
1219  }
1220 
1221  }
1222 #endif
1223 
1224  ideal Q=NULL;
1225  ideal Q1=NULL, Q2=NULL;
1226  if (r1->qideal!=NULL)
1227  {
1228 // rChangeCurrRing(sum);
1229 // if (r2->qideal!=NULL)
1230 // {
1231 // WerrorS("todo: qring+qring");
1232 // return -1;
1233 // }
1234 // else
1235 // {}
1236  /* these were defined in the Plural Part above... */
1237  int *perm1 = (int *)omAlloc0((rVar(r1)+1)*sizeof(int));
1238  int *par_perm1 = NULL;
1239  if (rPar(r1)!=0) par_perm1=(int *)omAlloc0((rPar(r1)+1)*sizeof(int));
1240  maFindPerm(r1->names, rVar(r1), rParameter(r1), rPar(r1),
1241  sum->names, rVar(sum), rParameter(sum), rPar(sum),
1242  perm1, par_perm1, sum->cf->type);
1243  nMapFunc nMap1 = n_SetMap(r1->cf,sum->cf);
1244  Q1 = idInit(IDELEMS(r1->qideal),1);
1245 
1246  for (int for_i=0;for_i<IDELEMS(r1->qideal);for_i++)
1247  Q1->m[for_i] = p_PermPoly(
1248  r1->qideal->m[for_i], perm1,
1249  r1, sum,
1250  nMap1,
1251  par_perm1, rPar(r1));
1252 
1253  omFree((ADDRESS)perm1);
1254  }
1255 
1256  if (r2->qideal!=NULL)
1257  {
1258  //if (currRing!=sum)
1259  // rChangeCurrRing(sum);
1260  int *perm2 = (int *)omAlloc0((rVar(r2)+1)*sizeof(int));
1261  int *par_perm2 = NULL;
1262  if (rPar(r2)!=0) par_perm2=(int *)omAlloc0((rPar(r2)+1)*sizeof(int));
1263  maFindPerm(r2->names, rVar(r2), rParameter(r2), rPar(r2),
1264  sum->names, rVar(sum), rParameter(sum), rPar(sum),
1265  perm2, par_perm2, sum->cf->type);
1266  nMapFunc nMap2 = n_SetMap(r2->cf,sum->cf);
1267  Q2 = idInit(IDELEMS(r2->qideal),1);
1268 
1269  for (int for_i=0;for_i<IDELEMS(r2->qideal);for_i++)
1270  Q2->m[for_i] = p_PermPoly(
1271  r2->qideal->m[for_i], perm2,
1272  r2, sum,
1273  nMap2,
1274  par_perm2, rPar(r2));
1275 
1276  omFree((ADDRESS)perm2);
1277  }
1278  if (Q1!=NULL)
1279  {
1280  if ( Q2!=NULL)
1281  Q = id_SimpleAdd(Q1,Q2,sum);
1282  else
1283  Q=id_Copy(Q1,sum);
1284  }
1285  else
1286  {
1287  if ( Q2!=NULL)
1288  Q = id_Copy(Q2,sum);
1289  else
1290  Q=NULL;
1291  }
1292  sum->qideal = Q;
1293 
1294 #ifdef HAVE_PLURAL
1295  if( rIsPluralRing(sum) )
1296  nc_SetupQuotient( sum );
1297 #endif
1298  return 1;
1299 }
1300 
1301 /*2
1302  *returns -1 for not compatible, (sum is undefined)
1303  * 0 for equal, (and sum)
1304  * 1 for compatible (and sum)
1305  */
1306 int rSum(ring r1, ring r2, ring &sum)
1307 {
1308  if ((r1==NULL)||(r2==NULL)
1309  ||(r1->cf==NULL)||(r2->cf==NULL))
1310  return -1;
1311  if (r1==r2)
1312  {
1313  sum=r1;
1314  r1->ref++;
1315  return 0;
1316  }
1317  return rSumInternal(r1,r2,sum,TRUE,FALSE);
1318 }
1319 
1320 /*2
1321  * create a copy of the ring r
1322  * used for qring definition,..
1323  * DOES NOT CALL rComplete
1324  */
1325 ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
1326 {
1327  if (r == NULL) return NULL;
1328  int i,j;
1329  ring res=(ring)omAlloc0Bin(sip_sring_bin);
1330  //memset: res->idroot=NULL; /* local objects */
1331  //ideal minideal;
1332  res->options=r->options; /* ring dependent options */
1333 
1334  //memset: res->ordsgn=NULL;
1335  //memset: res->typ=NULL;
1336  //memset: res->VarOffset=NULL;
1337  //memset: res->firstwv=NULL;
1338 
1339  //struct omBin PolyBin; /* Bin from where monoms are allocated */
1340  //memset: res->PolyBin=NULL; // rComplete
1341  res->cf=nCopyCoeff(r->cf); /* coeffs */
1342 
1343  //memset: res->ref=0; /* reference counter to the ring */
1344 
1345  res->N=rVar(r); /* number of vars */
1346 
1347  res->firstBlockEnds=r->firstBlockEnds;
1348 #ifdef HAVE_PLURAL
1349  res->real_var_start=r->real_var_start;
1350  res->real_var_end=r->real_var_end;
1351 #endif
1352 
1353 #ifdef HAVE_SHIFTBBA
1354  res->isLPring=r->isLPring; /* 0 for non-letterplace rings, otherwise the number of LP blocks, at least 1, known also as lV */
1355 #endif
1356 
1357  res->VectorOut=r->VectorOut;
1358  res->ShortOut=r->ShortOut;
1359  res->CanShortOut=r->CanShortOut;
1360 
1361  //memset: res->ExpL_Size=0;
1362  //memset: res->CmpL_Size=0;
1363  //memset: res->VarL_Size=0;
1364  //memset: res->pCompIndex=0;
1365  //memset: res->pOrdIndex=0;
1366  //memset: res->OrdSize=0;
1367  //memset: res->VarL_LowIndex=0;
1368  //memset: res->NegWeightL_Size=0;
1369  //memset: res->NegWeightL_Offset=NULL;
1370  //memset: res->VarL_Offset=NULL;
1371 
1372  // the following are set by rComplete unless predefined
1373  // therefore, we copy these values: maybe they are non-standard
1374  /* mask for getting single exponents */
1375  res->bitmask=r->bitmask;
1376  res->divmask=r->divmask;
1377  res->BitsPerExp = r->BitsPerExp;
1378  res->ExpPerLong = r->ExpPerLong;
1379 
1380  //memset: res->p_Procs=NULL;
1381  //memset: res->pFDeg=NULL;
1382  //memset: res->pLDeg=NULL;
1383  //memset: res->pFDegOrig=NULL;
1384  //memset: res->pLDegOrig=NULL;
1385  //memset: res->p_Setm=NULL;
1386  //memset: res->cf=NULL;
1387 
1388 /*
1389  if (r->extRing!=NULL)
1390  r->extRing->ref++;
1391 
1392  res->extRing=r->extRing;
1393  //memset: res->qideal=NULL;
1394 */
1395 
1396 
1397  if (copy_ordering == TRUE)
1398  {
1399  res->LexOrder=r->LexOrder; // TRUE if the monomial ordering has polynomial and power series blocks
1400  res->MixedOrder=r->MixedOrder; // TRUE for mixed (global/local) ordering, FALSE otherwise,
1401  i=rBlocks(r);
1402  res->wvhdl = (int **)omAlloc(i * sizeof(int *));
1403  res->order = (rRingOrder_t *) omAlloc(i * sizeof(rRingOrder_t));
1404  res->block0 = (int *) omAlloc(i * sizeof(int));
1405  res->block1 = (int *) omAlloc(i * sizeof(int));
1406  for (j=0; j<i; j++)
1407  {
1408  if (r->wvhdl[j]!=NULL)
1409  {
1410  res->wvhdl[j] = (int*) omMemDup(r->wvhdl[j]);
1411  }
1412  else
1413  res->wvhdl[j]=NULL;
1414  }
1415  memcpy(res->order,r->order,i * sizeof(rRingOrder_t));
1416  memcpy(res->block0,r->block0,i * sizeof(int));
1417  memcpy(res->block1,r->block1,i * sizeof(int));
1418  }
1419  //memset: else
1420  //memset: {
1421  //memset: res->wvhdl = NULL;
1422  //memset: res->order = NULL;
1423  //memset: res->block0 = NULL;
1424  //memset: res->block1 = NULL;
1425  //memset: }
1426 
1427  res->names = (char **)omAlloc0(rVar(r) * sizeof(char *));
1428  for (i=0; i<rVar(res); i++)
1429  {
1430  res->names[i] = omStrDup(r->names[i]);
1431  }
1432  if (r->qideal!=NULL)
1433  {
1434  if (copy_qideal)
1435  {
1436  assume(copy_ordering);
1437  rComplete(res);
1438  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
1439  rUnComplete(res);
1440  }
1441  //memset: else res->qideal = NULL;
1442  }
1443  //memset: else res->qideal = NULL;
1444  //memset: res->GetNC() = NULL; // copy is purely commutative!!!
1445  return res;
1446 }
1447 
1448 /*2
1449  * create a copy of the ring r
1450  * used for qring definition,..
1451  * DOES NOT CALL rComplete
1452  */
1453 ring rCopy0AndAddA(const ring r, int64vec *wv64, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
1454 {
1455  if (r == NULL) return NULL;
1456  int i,j;
1457  ring res=(ring)omAlloc0Bin(sip_sring_bin);
1458  //memcpy(res,r,sizeof(ip_sring));
1459  //memset: res->idroot=NULL; /* local objects */
1460  //ideal minideal;
1461  res->options=r->options; /* ring dependent options */
1462 
1463  //memset: res->ordsgn=NULL;
1464  //memset: res->typ=NULL;
1465  //memset: res->VarOffset=NULL;
1466  //memset: res->firstwv=NULL;
1467 
1468  //struct omBin PolyBin; /* Bin from where monoms are allocated */
1469  //memset: res->PolyBin=NULL; // rComplete
1470  res->cf=nCopyCoeff(r->cf); /* coeffs */
1471 
1472  //memset: res->ref=0; /* reference counter to the ring */
1473 
1474  res->N=rVar(r); /* number of vars */
1475 
1476  res->firstBlockEnds=r->firstBlockEnds;
1477 #ifdef HAVE_PLURAL
1478  res->real_var_start=r->real_var_start;
1479  res->real_var_end=r->real_var_end;
1480 #endif
1481 
1482 #ifdef HAVE_SHIFTBBA
1483  res->isLPring=r->isLPring; /* 0 for non-letterplace rings, otherwise the number of LP blocks, at least 1, known also as lV */
1484 #endif
1485 
1486  res->VectorOut=r->VectorOut;
1487  res->ShortOut=r->ShortOut;
1488  res->CanShortOut=r->CanShortOut;
1489  res->LexOrder=r->LexOrder; // TRUE if the monomial ordering has polynomial and power series blocks
1490  res->MixedOrder=r->MixedOrder; // TRUE for mixed (global/local) ordering, FALSE otherwise,
1491 
1492  //memset: res->ExpL_Size=0;
1493  //memset: res->CmpL_Size=0;
1494  //memset: res->VarL_Size=0;
1495  //memset: res->pCompIndex=0;
1496  //memset: res->pOrdIndex=0;
1497  //memset: res->OrdSize=0;
1498  //memset: res->VarL_LowIndex=0;
1499  //memset: res->NegWeightL_Size=0;
1500  //memset: res->NegWeightL_Offset=NULL;
1501  //memset: res->VarL_Offset=NULL;
1502 
1503  // the following are set by rComplete unless predefined
1504  // therefore, we copy these values: maybe they are non-standard
1505  /* mask for getting single exponents */
1506  res->bitmask=r->bitmask;
1507  res->divmask=r->divmask;
1508  res->BitsPerExp = r->BitsPerExp;
1509  res->ExpPerLong = r->ExpPerLong;
1510 
1511  //memset: res->p_Procs=NULL;
1512  //memset: res->pFDeg=NULL;
1513  //memset: res->pLDeg=NULL;
1514  //memset: res->pFDegOrig=NULL;
1515  //memset: res->pLDegOrig=NULL;
1516  //memset: res->p_Setm=NULL;
1517  //memset: res->cf=NULL;
1518 
1519 /*
1520  if (r->extRing!=NULL)
1521  r->extRing->ref++;
1522 
1523  res->extRing=r->extRing;
1524  //memset: res->qideal=NULL;
1525 */
1526 
1527 
1528  if (copy_ordering == TRUE)
1529  {
1530  i=rBlocks(r)+1; // DIFF to rCopy0
1531  res->wvhdl = (int **)omAlloc(i * sizeof(int *));
1532  res->order = (rRingOrder_t *) omAlloc(i * sizeof(rRingOrder_t));
1533  res->block0 = (int *) omAlloc(i * sizeof(int));
1534  res->block1 = (int *) omAlloc(i * sizeof(int));
1535  for (j=0; j<i-1; j++)
1536  {
1537  if (r->wvhdl[j]!=NULL)
1538  {
1539  res->wvhdl[j+1] = (int*) omMemDup(r->wvhdl[j]); //DIFF
1540  }
1541  else
1542  res->wvhdl[j+1]=NULL; //DIFF
1543  }
1544  memcpy(&(res->order[1]),r->order,(i-1) * sizeof(rRingOrder_t)); //DIFF
1545  memcpy(&(res->block0[1]),r->block0,(i-1) * sizeof(int)); //DIFF
1546  memcpy(&(res->block1[1]),r->block1,(i-1) * sizeof(int)); //DIFF
1547  }
1548  //memset: else
1549  //memset: {
1550  //memset: res->wvhdl = NULL;
1551  //memset: res->order = NULL;
1552  //memset: res->block0 = NULL;
1553  //memset: res->block1 = NULL;
1554  //memset: }
1555 
1556  //the added A
1557  res->order[0]=ringorder_a64;
1558  int length=wv64->rows();
1559  int64 *A=(int64 *)omAlloc(length*sizeof(int64));
1560  for(j=length-1;j>=0;j--)
1561  {
1562  A[j]=(*wv64)[j];
1563  }
1564  res->wvhdl[0]=(int *)A;
1565  res->block0[0]=1;
1566  res->block1[0]=length;
1567  //
1568 
1569  res->names = (char **)omAlloc0(rVar(r) * sizeof(char *));
1570  for (i=0; i<rVar(res); i++)
1571  {
1572  res->names[i] = omStrDup(r->names[i]);
1573  }
1574  if (r->qideal!=NULL)
1575  {
1576  if (copy_qideal)
1577  {
1578  #ifndef SING_NDEBUG
1579  if (!copy_ordering)
1580  WerrorS("internal error: rCopy0(Q,TRUE,FALSE)");
1581  else
1582  #endif
1583  {
1584  #ifndef SING_NDEBUG
1585  WarnS("internal bad stuff: rCopy0(Q,TRUE,TRUE)");
1586  #endif
1587  rComplete(res);
1588  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
1589  rUnComplete(res);
1590  }
1591  }
1592  //memset: else res->qideal = NULL;
1593  }
1594  //memset: else res->qideal = NULL;
1595  //memset: res->GetNC() = NULL; // copy is purely commutative!!!
1596  return res;
1597 }
1598 
1599 /*2
1600  * create a copy of the ring r, which must be equivalent to currRing
1601  * used for qring definition,..
1602  * (i.e.: normal rings: same nCopy as currRing;
1603  * qring: same nCopy, same idCopy as currRing)
1604  */
1605 ring rCopy(ring r)
1606 {
1607  if (r == NULL) return NULL;
1608  ring res=rCopy0(r,FALSE,TRUE);
1609  rComplete(res, 1); // res is purely commutative so far
1610  if (r->qideal!=NULL) res->qideal=idrCopyR_NoSort(r->qideal, r, res);
1611 
1612 #ifdef HAVE_PLURAL
1613  if (rIsPluralRing(r))
1614  if( nc_rCopy(res, r, true) ) {}
1615 #endif
1616 
1617  return res;
1618 }
1619 
1620 BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
1621 {
1622  if (r1 == r2) return TRUE;
1623  if (r1 == NULL || r2 == NULL) return FALSE;
1624  if (r1->cf!=r2->cf) return FALSE;
1625  if (rVar(r1)!=rVar(r2)) return FALSE;
1626 
1627  if( !rSamePolyRep(r1, r2) )
1628  return FALSE;
1629 
1630  int i/*, j*/;
1631 
1632  for (i=0; i<rVar(r1); i++)
1633  {
1634  if ((r1->names[i] != NULL) && (r2->names[i] != NULL))
1635  {
1636  if (strcmp(r1->names[i], r2->names[i])) return FALSE;
1637  }
1638  else if ((r1->names[i] != NULL) ^ (r2->names[i] != NULL))
1639  {
1640  return FALSE;
1641  }
1642  }
1643 
1644  if (qr)
1645  {
1646  if (r1->qideal != NULL)
1647  {
1648  ideal id1 = r1->qideal, id2 = r2->qideal;
1649  int i, n;
1650  poly *m1, *m2;
1651 
1652  if (id2 == NULL) return FALSE;
1653  if ((n = IDELEMS(id1)) != IDELEMS(id2)) return FALSE;
1654 
1655  {
1656  m1 = id1->m;
1657  m2 = id2->m;
1658  for (i=0; i<n; i++)
1659  if (! p_EqualPolys(m1[i],m2[i], r1, r2)) return FALSE;
1660  }
1661  }
1662  else if (r2->qideal != NULL) return FALSE;
1663  }
1664 
1665  return TRUE;
1666 }
1667 
1668 BOOLEAN rSamePolyRep(ring r1, ring r2)
1669 {
1670  int i, j;
1671 
1672  if (r1 == r2) return TRUE;
1673 
1674  if (r1 == NULL || r2 == NULL) return FALSE;
1675 
1676  if ((r1->cf != r2->cf)
1677  || (rVar(r1) != rVar(r2))
1678  || (r1->OrdSgn != r2->OrdSgn))
1679  return FALSE;
1680 
1681  i=0;
1682  while (r1->order[i] != 0)
1683  {
1684  if (r2->order[i] == 0) return FALSE;
1685  if ((r1->order[i] != r2->order[i])
1686  || (r1->block0[i] != r2->block0[i])
1687  || (r1->block1[i] != r2->block1[i]))
1688  return FALSE;
1689  if (r1->wvhdl[i] != NULL)
1690  {
1691  if (r2->wvhdl[i] == NULL)
1692  return FALSE;
1693  for (j=0; j<r1->block1[i]-r1->block0[i]+1; j++)
1694  if (r2->wvhdl[i][j] != r1->wvhdl[i][j])
1695  return FALSE;
1696  }
1697  else if (r2->wvhdl[i] != NULL) return FALSE;
1698  i++;
1699  }
1700  if (r2->order[i] != 0) return FALSE;
1701 
1702  // we do not check variable names
1703  // we do not check minpoly/minideal
1704  // we do not check qideal
1705 
1706  return TRUE;
1707 }
1708 
1710 {
1711  // check for simple ordering
1712  if (rHasSimpleOrder(r))
1713  {
1714  if ((r->order[1] == ringorder_c)
1715  || (r->order[1] == ringorder_C))
1716  {
1717  switch(r->order[0])
1718  {
1719  case ringorder_dp:
1720  case ringorder_wp:
1721  case ringorder_ds:
1722  case ringorder_ws:
1723  case ringorder_ls:
1724  case ringorder_unspec:
1725  if (r->order[1] == ringorder_C
1726  || r->order[0] == ringorder_unspec)
1727  return rOrderType_ExpComp;
1728  return rOrderType_Exp;
1729 
1730  default:
1731  assume(r->order[0] == ringorder_lp ||
1732  r->order[0] == ringorder_rs ||
1733  r->order[0] == ringorder_Dp ||
1734  r->order[0] == ringorder_Wp ||
1735  r->order[0] == ringorder_Ds ||
1736  r->order[0] == ringorder_Ws);
1737 
1738  if (r->order[1] == ringorder_c) return rOrderType_ExpComp;
1739  return rOrderType_Exp;
1740  }
1741  }
1742  else
1743  {
1744  assume((r->order[0]==ringorder_c)||(r->order[0]==ringorder_C));
1745  return rOrderType_CompExp;
1746  }
1747  }
1748  else
1749  return rOrderType_General;
1750 }
1751 
1753 {
1754  return (r->order[0] == ringorder_c);
1755 }
1757 {
1758  if (r->order[0] == ringorder_unspec) return TRUE;
1759  int blocks = rBlocks(r) - 1;
1760  assume(blocks >= 1);
1761  if (blocks == 1) return TRUE;
1762 
1763  int s = 0;
1764  while( (s < blocks) && (r->order[s] == ringorder_IS) && (r->order[blocks-1] == ringorder_IS) )
1765  {
1766  s++;
1767  blocks--;
1768  }
1769 
1770  if ((blocks - s) > 2) return FALSE;
1771 
1772  assume( blocks == s + 2 );
1773 
1774  if (
1775  (r->order[s] != ringorder_c)
1776  && (r->order[s] != ringorder_C)
1777  && (r->order[s+1] != ringorder_c)
1778  && (r->order[s+1] != ringorder_C)
1779  )
1780  return FALSE;
1781  if ((r->order[s+1] == ringorder_M)
1782  || (r->order[s] == ringorder_M))
1783  return FALSE;
1784  return TRUE;
1785 }
1786 
1787 // returns TRUE, if simple lp or ls ordering
1789 {
1790  return rHasSimpleOrder(r) &&
1791  (r->order[0] == ringorder_ls ||
1792  r->order[0] == ringorder_lp ||
1793  r->order[1] == ringorder_ls ||
1794  r->order[1] == ringorder_lp);
1795 }
1796 
1798 {
1799  switch(order)
1800  {
1801  case ringorder_dp:
1802  case ringorder_Dp:
1803  case ringorder_ds:
1804  case ringorder_Ds:
1805  case ringorder_Ws:
1806  case ringorder_Wp:
1807  case ringorder_ws:
1808  case ringorder_wp:
1809  return TRUE;
1810 
1811  default:
1812  return FALSE;
1813  }
1814 }
1815 
1817 {
1818  switch(order)
1819  {
1820  case ringorder_Ws:
1821  case ringorder_Wp:
1822  case ringorder_ws:
1823  case ringorder_wp:
1824  return TRUE;
1825 
1826  default:
1827  return FALSE;
1828  }
1829 }
1830 
1832 {
1833  if (r->order[0] == ringorder_unspec) return TRUE;
1834  int blocks = rBlocks(r) - 1;
1835  assume(blocks >= 1);
1836  if (blocks == 1) return TRUE;
1837 
1838  int s = 0;
1839  while( (s < blocks) && (r->order[s] == ringorder_IS) && (r->order[blocks-1] == ringorder_IS) )
1840  {
1841  s++;
1842  blocks--;
1843  }
1844 
1845  if ((blocks - s) > 3) return FALSE;
1846 
1847 // if ((blocks > 3) || (blocks < 2)) return FALSE;
1848  if ((blocks - s) == 3)
1849  {
1850  return (((r->order[s] == ringorder_aa) && (r->order[s+1] != ringorder_M) &&
1851  ((r->order[s+2] == ringorder_c) || (r->order[s+2] == ringorder_C))) ||
1852  (((r->order[s] == ringorder_c) || (r->order[s] == ringorder_C)) &&
1853  (r->order[s+1] == ringorder_aa) && (r->order[s+2] != ringorder_M)));
1854  }
1855  else
1856  {
1857  return ((r->order[s] == ringorder_aa) && (r->order[s+1] != ringorder_M));
1858  }
1859 }
1860 
1861 // return TRUE if p_SetComp requires p_Setm
1863 {
1864  if (r->typ != NULL)
1865  {
1866  int pos;
1867  for (pos=0;pos<r->OrdSize;pos++)
1868  {
1869  sro_ord* o=&(r->typ[pos]);
1870  if ( (o->ord_typ == ro_syzcomp)
1871  || (o->ord_typ == ro_syz)
1872  || (o->ord_typ == ro_is)
1873  || (o->ord_typ == ro_am)
1874  || (o->ord_typ == ro_isTemp))
1875  return TRUE;
1876  }
1877  }
1878  return FALSE;
1879 }
1880 
1881 // return TRUE if p->exp[r->pOrdIndex] holds total degree of p */
1883 {
1884  // Hmm.... what about Syz orderings?
1885  return (rVar(r) > 1 &&
1886  ((rHasSimpleOrder(r) &&
1887  (rOrder_is_DegOrdering((rRingOrder_t)r->order[0]) ||
1888  rOrder_is_DegOrdering(( rRingOrder_t)r->order[1]))) ||
1889  (rHasSimpleOrderAA(r) &&
1890  (rOrder_is_DegOrdering((rRingOrder_t)r->order[1]) ||
1891  ((r->order[1]!=0) &&
1892  rOrder_is_DegOrdering((rRingOrder_t)r->order[2]))))));
1893 }
1894 
1895 // return TRUE if p->exp[r->pOrdIndex] holds a weighted degree of p */
1897 {
1898  // Hmm.... what about Syz orderings?
1899  return ((rVar(r) > 1) &&
1900  rHasSimpleOrder(r) &&
1901  (rOrder_is_WeightedOrdering((rRingOrder_t)r->order[0]) ||
1902  rOrder_is_WeightedOrdering(( rRingOrder_t)r->order[1])));
1903 }
1904 
1905 BOOLEAN rIsPolyVar(int v,const ring r)
1906 {
1907  int i=0;
1908  while(r->order[i]!=0)
1909  {
1910  if((r->block0[i]<=v)
1911  && (r->block1[i]>=v))
1912  {
1913  switch(r->order[i])
1914  {
1915  case ringorder_a:
1916  return (r->wvhdl[i][v-r->block0[i]]>0);
1917  case ringorder_M:
1918  return 2; /*don't know*/
1919  case ringorder_a64: /* assume: all weight are non-negative!*/
1920  case ringorder_lp:
1921  case ringorder_rs:
1922  case ringorder_dp:
1923  case ringorder_Dp:
1924  case ringorder_wp:
1925  case ringorder_Wp:
1926  return TRUE;
1927  case ringorder_ls:
1928  case ringorder_ds:
1929  case ringorder_Ds:
1930  case ringorder_ws:
1931  case ringorder_Ws:
1932  return FALSE;
1933  default:
1934  break;
1935  }
1936  }
1937  i++;
1938  }
1939  return 3; /* could not find var v*/
1940 }
1941 
1942 #ifdef RDEBUG
1943 // This should eventually become a full-fledge ring check, like pTest
1944 BOOLEAN rDBTest(ring r, const char* fn, const int l)
1945 {
1946  int i,j;
1947 
1948  if (r == NULL)
1949  {
1950  dReportError("Null ring in %s:%d", fn, l);
1951  return FALSE;
1952  }
1953 
1954 
1955  if (r->N == 0) return TRUE;
1956 
1957  if ((r->OrdSgn!=1) && (r->OrdSgn!= -1))
1958  {
1959  dReportError("missing OrdSgn in %s:%d", fn, l);
1960  return FALSE;
1961  }
1962 
1963 // omCheckAddrSize(r,sizeof(ip_sring));
1964 #if OM_CHECK > 0
1965  i=rBlocks(r);
1966  omCheckAddrSize(r->order,i*sizeof(int));
1967  omCheckAddrSize(r->block0,i*sizeof(int));
1968  omCheckAddrSize(r->block1,i*sizeof(int));
1969  for(int j=0;j<=i;j++)
1970  {
1971  if((r->order[j]<0)||(r->order[j]>ringorder_unspec))
1972  dError("wrong order in r->order");
1973  }
1974  if (r->wvhdl!=NULL)
1975  {
1976  omCheckAddrSize(r->wvhdl,i*sizeof(int *));
1977  for (j=0;j<i; j++)
1978  {
1979  if (r->wvhdl[j] != NULL) omCheckAddr(r->wvhdl[j]);
1980  }
1981  }
1982 #endif
1983  if (r->VarOffset == NULL)
1984  {
1985  dReportError("Null ring VarOffset -- no rComplete (?) in n %s:%d", fn, l);
1986  return FALSE;
1987  }
1988  omCheckAddrSize(r->VarOffset,(r->N+1)*sizeof(int));
1989 
1990  if ((r->OrdSize==0)!=(r->typ==NULL))
1991  {
1992  dReportError("mismatch OrdSize and typ-pointer in %s:%d");
1993  return FALSE;
1994  }
1995  omcheckAddrSize(r->typ,r->OrdSize*sizeof(*(r->typ)));
1996  omCheckAddrSize(r->VarOffset,(r->N+1)*sizeof(*(r->VarOffset)));
1997  // test assumptions:
1998  for(i=0;i<=r->N;i++) // for all variables (i = 0..N)
1999  {
2000  if(r->typ!=NULL)
2001  {
2002  for(j=0;j<r->OrdSize;j++) // for all ordering blocks (j =0..OrdSize-1)
2003  {
2004  if(r->typ[j].ord_typ == ro_isTemp)
2005  {
2006  const int p = r->typ[j].data.isTemp.suffixpos;
2007 
2008  if(p <= j)
2009  dReportError("ordrec prefix %d is unmatched",j);
2010 
2011  assume( p < r->OrdSize );
2012 
2013  if(r->typ[p].ord_typ != ro_is)
2014  dReportError("ordrec prefix %d is unmatched (suffix: %d is wrong!!!)",j, p);
2015 
2016  // Skip all intermediate blocks for undone variables:
2017  if(r->typ[j].data.isTemp.pVarOffset[i] != -1) // Check i^th variable
2018  {
2019  j = p - 1; // SKIP ALL INTERNAL BLOCKS...???
2020  continue; // To make for check OrdSize bound...
2021  }
2022  }
2023  else if (r->typ[j].ord_typ == ro_is)
2024  {
2025  // Skip all intermediate blocks for undone variables:
2026  if(r->typ[j].data.is.pVarOffset[i] != -1)
2027  {
2028  // TODO???
2029  }
2030 
2031  }
2032  else
2033  {
2034  if (r->typ[j].ord_typ==ro_cp)
2035  {
2036  if(((short)r->VarOffset[i]) == r->typ[j].data.cp.place)
2037  dReportError("ordrec %d conflicts with var %d",j,i);
2038  }
2039  else
2040  if ((r->typ[j].ord_typ!=ro_syzcomp)
2041  && (r->VarOffset[i] == r->typ[j].data.dp.place))
2042  dReportError("ordrec %d conflicts with var %d",j,i);
2043  }
2044  }
2045  }
2046  int tmp;
2047  tmp=r->VarOffset[i] & 0xffffff;
2048  #if SIZEOF_LONG == 8
2049  if ((r->VarOffset[i] >> 24) >63)
2050  #else
2051  if ((r->VarOffset[i] >> 24) >31)
2052  #endif
2053  dReportError("bit_start out of range:%d",r->VarOffset[i] >> 24);
2054  if (i > 0 && ((tmp<0) ||(tmp>r->ExpL_Size-1)))
2055  {
2056  dReportError("varoffset out of range for var %d: %d",i,tmp);
2057  }
2058  }
2059  if(r->typ!=NULL)
2060  {
2061  for(j=0;j<r->OrdSize;j++)
2062  {
2063  if ((r->typ[j].ord_typ==ro_dp)
2064  || (r->typ[j].ord_typ==ro_wp)
2065  || (r->typ[j].ord_typ==ro_wp_neg))
2066  {
2067  if (r->typ[j].data.dp.start > r->typ[j].data.dp.end)
2068  dReportError("in ordrec %d: start(%d) > end(%d)",j,
2069  r->typ[j].data.dp.start, r->typ[j].data.dp.end);
2070  if ((r->typ[j].data.dp.start < 1)
2071  || (r->typ[j].data.dp.end > r->N))
2072  dReportError("in ordrec %d: start(%d)<1 or end(%d)>vars(%d)",j,
2073  r->typ[j].data.dp.start, r->typ[j].data.dp.end,r->N);
2074  }
2075  }
2076  }
2077 
2078  assume(r != NULL);
2079  assume(r->cf != NULL);
2080 
2081  if (nCoeff_is_algExt(r->cf))
2082  {
2083  assume(r->cf->extRing != NULL);
2084  assume(r->cf->extRing->qideal != NULL);
2085  omCheckAddr(r->cf->extRing->qideal->m[0]);
2086  }
2087 
2088  //assume(r->cf!=NULL);
2089 
2090  return TRUE;
2091 }
2092 #endif
2093 
2094 static void rO_Align(int &place, int &bitplace)
2095 {
2096  // increment place to the next aligned one
2097  // (count as Exponent_t,align as longs)
2098  if (bitplace!=BITS_PER_LONG)
2099  {
2100  place++;
2101  bitplace=BITS_PER_LONG;
2102  }
2103 }
2104 
2105 static void rO_TDegree(int &place, int &bitplace, int start, int end,
2106  long *o, sro_ord &ord_struct)
2107 {
2108  // degree (aligned) of variables v_start..v_end, ordsgn 1
2109  rO_Align(place,bitplace);
2110  ord_struct.ord_typ=ro_dp;
2111  ord_struct.data.dp.start=start;
2112  ord_struct.data.dp.end=end;
2113  ord_struct.data.dp.place=place;
2114  o[place]=1;
2115  place++;
2116  rO_Align(place,bitplace);
2117 }
2118 
2119 static void rO_TDegree_neg(int &place, int &bitplace, int start, int end,
2120  long *o, sro_ord &ord_struct)
2121 {
2122  // degree (aligned) of variables v_start..v_end, ordsgn -1
2123  rO_Align(place,bitplace);
2124  ord_struct.ord_typ=ro_dp;
2125  ord_struct.data.dp.start=start;
2126  ord_struct.data.dp.end=end;
2127  ord_struct.data.dp.place=place;
2128  o[place]=-1;
2129  place++;
2130  rO_Align(place,bitplace);
2131 }
2132 
2133 static void rO_WDegree(int &place, int &bitplace, int start, int end,
2134  long *o, sro_ord &ord_struct, int *weights)
2135 {
2136  // weighted degree (aligned) of variables v_start..v_end, ordsgn 1
2137  while((start<end) && (weights[0]==0)) { start++; weights++; }
2138  while((start<end) && (weights[end-start]==0)) { end--; }
2139  int i;
2140  int pure_tdeg=1;
2141  for(i=start;i<=end;i++)
2142  {
2143  if(weights[i-start]!=1)
2144  {
2145  pure_tdeg=0;
2146  break;
2147  }
2148  }
2149  if (pure_tdeg)
2150  {
2151  rO_TDegree(place,bitplace,start,end,o,ord_struct);
2152  return;
2153  }
2154  rO_Align(place,bitplace);
2155  ord_struct.ord_typ=ro_wp;
2156  ord_struct.data.wp.start=start;
2157  ord_struct.data.wp.end=end;
2158  ord_struct.data.wp.place=place;
2159  ord_struct.data.wp.weights=weights;
2160  o[place]=1;
2161  place++;
2162  rO_Align(place,bitplace);
2163  for(i=start;i<=end;i++)
2164  {
2165  if(weights[i-start]<0)
2166  {
2167  ord_struct.ord_typ=ro_wp_neg;
2168  break;
2169  }
2170  }
2171 }
2172 
2173 static void rO_WMDegree(int &place, int &bitplace, int start, int end,
2174  long *o, sro_ord &ord_struct, int *weights)
2175 {
2176  assume(weights != NULL);
2177 
2178  // weighted degree (aligned) of variables v_start..v_end, ordsgn 1
2179 // while((start<end) && (weights[0]==0)) { start++; weights++; }
2180 // while((start<end) && (weights[end-start]==0)) { end--; }
2181  rO_Align(place,bitplace);
2182  ord_struct.ord_typ=ro_am;
2183  ord_struct.data.am.start=start;
2184  ord_struct.data.am.end=end;
2185  ord_struct.data.am.place=place;
2186  ord_struct.data.am.weights=weights;
2187  ord_struct.data.am.weights_m = weights + (end-start+1);
2188  ord_struct.data.am.len_gen=weights[end-start+1];
2189  assume( ord_struct.data.am.weights_m[0] == ord_struct.data.am.len_gen );
2190  o[place]=1;
2191  place++;
2192  rO_Align(place,bitplace);
2193 }
2194 
2195 static void rO_WDegree64(int &place, int &bitplace, int start, int end,
2196  long *o, sro_ord &ord_struct, int64 *weights)
2197 {
2198  // weighted degree (aligned) of variables v_start..v_end, ordsgn 1,
2199  // reserved 2 places
2200  rO_Align(place,bitplace);
2201  ord_struct.ord_typ=ro_wp64;
2202  ord_struct.data.wp64.start=start;
2203  ord_struct.data.wp64.end=end;
2204  ord_struct.data.wp64.place=place;
2205  ord_struct.data.wp64.weights64=weights;
2206  o[place]=1;
2207  place++;
2208  o[place]=1;
2209  place++;
2210  rO_Align(place,bitplace);
2211 }
2212 
2213 static void rO_WDegree_neg(int &place, int &bitplace, int start, int end,
2214  long *o, sro_ord &ord_struct, int *weights)
2215 {
2216  // weighted degree (aligned) of variables v_start..v_end, ordsgn -1
2217  while((start<end) && (weights[0]==0)) { start++; weights++; }
2218  while((start<end) && (weights[end-start]==0)) { end--; }
2219  rO_Align(place,bitplace);
2220  ord_struct.ord_typ=ro_wp;
2221  ord_struct.data.wp.start=start;
2222  ord_struct.data.wp.end=end;
2223  ord_struct.data.wp.place=place;
2224  ord_struct.data.wp.weights=weights;
2225  o[place]=-1;
2226  place++;
2227  rO_Align(place,bitplace);
2228  int i;
2229  for(i=start;i<=end;i++)
2230  {
2231  if(weights[i-start]<0)
2232  {
2233  ord_struct.ord_typ=ro_wp_neg;
2234  break;
2235  }
2236  }
2237 }
2238 
2239 static void rO_LexVars(int &place, int &bitplace, int start, int end,
2240  int &prev_ord, long *o,int *v, int bits, int opt_var)
2241 {
2242  // a block of variables v_start..v_end with lex order, ordsgn 1
2243  int k;
2244  int incr=1;
2245  if(prev_ord==-1) rO_Align(place,bitplace);
2246 
2247  if (start>end)
2248  {
2249  incr=-1;
2250  }
2251  for(k=start;;k+=incr)
2252  {
2253  bitplace-=bits;
2254  if (bitplace < 0) { bitplace=BITS_PER_LONG-bits; place++; }
2255  o[place]=1;
2256  v[k]= place | (bitplace << 24);
2257  if (k==end) break;
2258  }
2259  prev_ord=1;
2260  if (opt_var!= -1)
2261  {
2262  assume((opt_var == end+1) ||(opt_var == end-1));
2263  if((opt_var != end+1) &&(opt_var != end-1)) WarnS("hier-2");
2264  int save_bitplace=bitplace;
2265  bitplace-=bits;
2266  if (bitplace < 0)
2267  {
2268  bitplace=save_bitplace;
2269  return;
2270  }
2271  // there is enough space for the optional var
2272  v[opt_var]=place | (bitplace << 24);
2273  }
2274 }
2275 
2276 static void rO_LexVars_neg(int &place, int &bitplace, int start, int end,
2277  int &prev_ord, long *o,int *v, int bits, int opt_var)
2278 {
2279  // a block of variables v_start..v_end with lex order, ordsgn -1
2280  int k;
2281  int incr=1;
2282  if(prev_ord==1) rO_Align(place,bitplace);
2283 
2284  if (start>end)
2285  {
2286  incr=-1;
2287  }
2288  for(k=start;;k+=incr)
2289  {
2290  bitplace-=bits;
2291  if (bitplace < 0) { bitplace=BITS_PER_LONG-bits; place++; }
2292  o[place]=-1;
2293  v[k]=place | (bitplace << 24);
2294  if (k==end) break;
2295  }
2296  prev_ord=-1;
2297 // #if 0
2298  if (opt_var!= -1)
2299  {
2300  assume((opt_var == end+1) ||(opt_var == end-1));
2301  if((opt_var != end+1) &&(opt_var != end-1)) WarnS("hier-1");
2302  int save_bitplace=bitplace;
2303  bitplace-=bits;
2304  if (bitplace < 0)
2305  {
2306  bitplace=save_bitplace;
2307  return;
2308  }
2309  // there is enough space for the optional var
2310  v[opt_var]=place | (bitplace << 24);
2311  }
2312 // #endif
2313 }
2314 
2315 static void rO_Syzcomp(int &place, int &bitplace, int &prev_ord,
2316  long *o, sro_ord &ord_struct)
2317 {
2318  // ordering is derived from component number
2319  rO_Align(place,bitplace);
2320  ord_struct.ord_typ=ro_syzcomp;
2321  ord_struct.data.syzcomp.place=place;
2322  ord_struct.data.syzcomp.Components=NULL;
2323  ord_struct.data.syzcomp.ShiftedComponents=NULL;
2324  o[place]=1;
2325  prev_ord=1;
2326  place++;
2327  rO_Align(place,bitplace);
2328 }
2329 
2330 static void rO_Syz(int &place, int &bitplace, int &prev_ord,
2331  int syz_comp, long *o, sro_ord &ord_struct)
2332 {
2333  // ordering is derived from component number
2334  // let's reserve one Exponent_t for it
2335  if ((prev_ord== 1) || (bitplace!=BITS_PER_LONG))
2336  rO_Align(place,bitplace);
2337  ord_struct.ord_typ=ro_syz;
2338  ord_struct.data.syz.place=place;
2339  ord_struct.data.syz.limit=syz_comp;
2340  if (syz_comp>0)
2341  ord_struct.data.syz.syz_index = (int*) omAlloc0((syz_comp+1)*sizeof(int));
2342  else
2343  ord_struct.data.syz.syz_index = NULL;
2344  ord_struct.data.syz.curr_index = 1;
2345  o[place]= -1;
2346  prev_ord=-1;
2347  place++;
2348 }
2349 
2350 #ifndef SING_NDEBUG
2351 # define MYTEST 0
2352 #else /* ifndef SING_NDEBUG */
2353 # define MYTEST 0
2354 #endif /* ifndef SING_NDEBUG */
2355 
2356 static void rO_ISPrefix(int &place, int &bitplace, int &prev_ord,
2357  long *o, int /*N*/, int *v, sro_ord &ord_struct)
2358 {
2359  if ((prev_ord== 1) || (bitplace!=BITS_PER_LONG))
2360  rO_Align(place,bitplace);
2361  // since we add something afterwards - it's better to start with anew!?
2362 
2363  ord_struct.ord_typ = ro_isTemp;
2364  ord_struct.data.isTemp.start = place;
2365  ord_struct.data.isTemp.pVarOffset = (int *)omMemDup(v);
2366  ord_struct.data.isTemp.suffixpos = -1;
2367 
2368  // We will act as rO_Syz on our own!!!
2369  // Here we allocate an exponent as a level placeholder
2370  o[place]= -1;
2371  prev_ord=-1;
2372  place++;
2373 }
2374 static void rO_ISSuffix(int &place, int &bitplace, int &prev_ord, long *o,
2375  int N, int *v, sro_ord *tmp_typ, int &typ_i, int sgn)
2376 {
2377 
2378  // Let's find previous prefix:
2379  int typ_j = typ_i - 1;
2380  while(typ_j >= 0)
2381  {
2382  if( tmp_typ[typ_j].ord_typ == ro_isTemp)
2383  break;
2384  typ_j --;
2385  }
2386 
2387  assume( typ_j >= 0 );
2388 
2389  if( typ_j < 0 ) // Found NO prefix!!! :(
2390  return;
2391 
2392  assume( tmp_typ[typ_j].ord_typ == ro_isTemp );
2393 
2394  // Get saved state:
2395  const int start = tmp_typ[typ_j].data.isTemp.start;
2396  int *pVarOffset = tmp_typ[typ_j].data.isTemp.pVarOffset;
2397 
2398 /*
2399  // shift up all blocks
2400  while(typ_j < (typ_i-1))
2401  {
2402  tmp_typ[typ_j] = tmp_typ[typ_j+1];
2403  typ_j++;
2404  }
2405  typ_j = typ_i - 1; // No increment for typ_i
2406 */
2407  tmp_typ[typ_j].data.isTemp.suffixpos = typ_i;
2408 
2409  // Let's keep that dummy for now...
2410  typ_j = typ_i; // the typ to change!
2411  typ_i++; // Just for now...
2412 
2413 
2414  for( int i = 0; i <= N; i++ ) // Note [0] == component !!! No Skip?
2415  {
2416  // Was i-th variable allocated inbetween?
2417  if( v[i] != pVarOffset[i] )
2418  {
2419  pVarOffset[i] = v[i]; // Save for later...
2420  v[i] = -1; // Undo!
2421  assume( pVarOffset[i] != -1 );
2422  }
2423  else
2424  pVarOffset[i] = -1; // No change here...
2425  }
2426 
2427  if( pVarOffset[0] != -1 )
2428  pVarOffset[0] &= 0x0fff;
2429 
2430  sro_ord &ord_struct = tmp_typ[typ_j];
2431 
2432 
2433  ord_struct.ord_typ = ro_is;
2434  ord_struct.data.is.start = start;
2435  ord_struct.data.is.end = place;
2436  ord_struct.data.is.pVarOffset = pVarOffset;
2437 
2438 
2439  // What about component???
2440 // if( v[0] != -1 ) // There is a component already...???
2441 // if( o[ v[0] & 0x0fff ] == sgn )
2442 // {
2443 // pVarOffset[0] = -1; // NEVER USED Afterwards...
2444 // return;
2445 // }
2446 
2447 
2448  // Moreover: we need to allocate the module component (v[0]) here!
2449  if( v[0] == -1) // It's possible that there was module component v0 at the begining (before prefix)!
2450  {
2451  // Start with a whole long exponent
2452  if( bitplace != BITS_PER_LONG )
2453  rO_Align(place, bitplace);
2454 
2455  assume( bitplace == BITS_PER_LONG );
2456  bitplace -= BITS_PER_LONG;
2457  assume(bitplace == 0);
2458  v[0] = place | (bitplace << 24); // Never mind whether pVarOffset[0] > 0!!!
2459  o[place] = sgn; // Singnum for component ordering
2460  prev_ord = sgn;
2461  }
2462 }
2463 
2464 
2465 static unsigned long rGetExpSize(unsigned long bitmask, int & bits)
2466 {
2467  if (bitmask == 0)
2468  {
2469  bits=16; bitmask=0xffff;
2470  }
2471  else if (bitmask <= 1L)
2472  {
2473  bits=1; bitmask = 1L;
2474  }
2475  else if (bitmask <= 3L)
2476  {
2477  bits=2; bitmask = 3L;
2478  }
2479  else if (bitmask <= 7L)
2480  {
2481  bits=3; bitmask=7L;
2482  }
2483  else if (bitmask <= 0xfL)
2484  {
2485  bits=4; bitmask=0xfL;
2486  }
2487  else if (bitmask <= 0x1fL)
2488  {
2489  bits=5; bitmask=0x1fL;
2490  }
2491  else if (bitmask <= 0x3fL)
2492  {
2493  bits=6; bitmask=0x3fL;
2494  }
2495 #if SIZEOF_LONG == 8
2496  else if (bitmask <= 0x7fL)
2497  {
2498  bits=7; bitmask=0x7fL; /* 64 bit longs only */
2499  }
2500 #endif
2501  else if (bitmask <= 0xffL)
2502  {
2503  bits=8; bitmask=0xffL;
2504  }
2505 #if SIZEOF_LONG == 8
2506  else if (bitmask <= 0x1ffL)
2507  {
2508  bits=9; bitmask=0x1ffL; /* 64 bit longs only */
2509  }
2510 #endif
2511  else if (bitmask <= 0x3ffL)
2512  {
2513  bits=10; bitmask=0x3ffL;
2514  }
2515 #if SIZEOF_LONG == 8
2516  else if (bitmask <= 0xfffL)
2517  {
2518  bits=12; bitmask=0xfff; /* 64 bit longs only */
2519  }
2520 #endif
2521  else if (bitmask <= 0xffffL)
2522  {
2523  bits=16; bitmask=0xffffL;
2524  }
2525 #if SIZEOF_LONG == 8
2526  else if (bitmask <= 0xfffffL)
2527  {
2528  bits=20; bitmask=0xfffffL; /* 64 bit longs only */
2529  }
2530  else if (bitmask <= 0xffffffffL)
2531  {
2532  bits=32; bitmask=0xffffffffL;
2533  }
2534  else if (bitmask <= 0x7fffffffffffffffL)
2535  {
2536  bits=63; bitmask=0x7fffffffffffffffL; /* for overflow tests*/
2537  }
2538  else
2539  {
2540  bits=63; bitmask=0x7fffffffffffffffL; /* for overflow tests*/
2541  }
2542 #else
2543  else if (bitmask <= 0x7fffffff)
2544  {
2545  bits=31; bitmask=0x7fffffff; /* for overflow tests*/
2546  }
2547  else
2548  {
2549  bits=31; bitmask=0x7fffffffL; /* for overflow tests*/
2550  }
2551 #endif
2552  return bitmask;
2553 }
2554 
2555 /*2
2556 * optimize rGetExpSize for a block of N variables, exp <=bitmask
2557 */
2558 unsigned long rGetExpSize(unsigned long bitmask, int & bits, int N)
2559 {
2560 #if SIZEOF_LONG == 8
2561  if (N<4) N=4;
2562 #else
2563  if (N<2) N=2;
2564 #endif
2565  bitmask =rGetExpSize(bitmask, bits);
2566  int vars_per_long=BIT_SIZEOF_LONG/bits;
2567  int bits1;
2568  loop
2569  {
2570  if (bits == BIT_SIZEOF_LONG-1)
2571  {
2572  bits = BIT_SIZEOF_LONG - 1;
2573  return LONG_MAX;
2574  }
2575  unsigned long bitmask1 =rGetExpSize(bitmask+1, bits1);
2576  int vars_per_long1=BIT_SIZEOF_LONG/bits1;
2577  if ((((N+vars_per_long-1)/vars_per_long) ==
2578  ((N+vars_per_long1-1)/vars_per_long1)))
2579  {
2580  vars_per_long=vars_per_long1;
2581  bits=bits1;
2582  bitmask=bitmask1;
2583  }
2584  else
2585  {
2586  return bitmask; /* and bits */
2587  }
2588  }
2589 }
2590 
2591 
2592 /*2
2593  * create a copy of the ring r, which must be equivalent to currRing
2594  * used for std computations
2595  * may share data structures with currRing
2596  * DOES CALL rComplete
2597  */
2598 ring rModifyRing(ring r, BOOLEAN omit_degree,
2599  BOOLEAN try_omit_comp,
2600  unsigned long exp_limit)
2601 {
2602  assume (r != NULL );
2603  assume (exp_limit > 1);
2604  BOOLEAN need_other_ring;
2605  BOOLEAN omitted_degree = FALSE;
2606 
2607  int iNeedInducedOrderingSetup = 0; ///< How many induced ordering block do we have?
2608  int bits;
2609 
2610  exp_limit=rGetExpSize(exp_limit, bits, r->N);
2611  need_other_ring = (exp_limit != r->bitmask);
2612 
2613  int nblocks=rBlocks(r);
2614  rRingOrder_t *order=(rRingOrder_t*)omAlloc0((nblocks+1)*sizeof(rRingOrder_t));
2615  int *block0=(int*)omAlloc0((nblocks+1)*sizeof(int));
2616  int *block1=(int*)omAlloc0((nblocks+1)*sizeof(int));
2617  int **wvhdl=(int**)omAlloc0((nblocks+1)*sizeof(int *));
2618 
2619  int i=0;
2620  int j=0; /* i index in r, j index in res */
2621 
2622  for( rRingOrder_t r_ord=r->order[i]; (r_ord != (rRingOrder_t)0) && (i < nblocks); j++, r_ord=r->order[++i])
2623  {
2624  BOOLEAN copy_block_index=TRUE;
2625 
2626  if (r->block0[i]==r->block1[i])
2627  {
2628  switch(r_ord)
2629  {
2630  case ringorder_wp:
2631  case ringorder_dp:
2632  case ringorder_Wp:
2633  case ringorder_Dp:
2634  r_ord=ringorder_lp;
2635  break;
2636  case ringorder_Ws:
2637  case ringorder_Ds:
2638  case ringorder_ws:
2639  case ringorder_ds:
2640  r_ord=ringorder_ls;
2641  break;
2642  default:
2643  break;
2644  }
2645  }
2646  switch(r_ord)
2647  {
2648  case ringorder_S:
2649  {
2650 #ifndef SING_NDEBUG
2651  Warn("Error: unhandled ordering in rModifyRing: ringorder_S = [%d]", r_ord);
2652 #endif
2653  order[j]=r_ord; /*r->order[i];*/
2654  break;
2655  }
2656  case ringorder_C:
2657  case ringorder_c:
2658  if (!try_omit_comp)
2659  {
2660  order[j]=r_ord; /*r->order[i]*/;
2661  }
2662  else
2663  {
2664  j--;
2665  need_other_ring=TRUE;
2666  try_omit_comp=FALSE;
2667  copy_block_index=FALSE;
2668  }
2669  break;
2670  case ringorder_wp:
2671  case ringorder_dp:
2672  case ringorder_ws:
2673  case ringorder_ds:
2674  if(!omit_degree)
2675  {
2676  order[j]=r_ord; /*r->order[i]*/;
2677  }
2678  else
2679  {
2680  order[j]=ringorder_rs;
2681  need_other_ring=TRUE;
2682  omit_degree=FALSE;
2683  omitted_degree = TRUE;
2684  }
2685  break;
2686  case ringorder_Wp:
2687  case ringorder_Dp:
2688  case ringorder_Ws:
2689  case ringorder_Ds:
2690  if(!omit_degree)
2691  {
2692  order[j]=r_ord; /*r->order[i];*/
2693  }
2694  else
2695  {
2696  order[j]=ringorder_lp;
2697  need_other_ring=TRUE;
2698  omit_degree=FALSE;
2699  omitted_degree = TRUE;
2700  }
2701  break;
2702  case ringorder_IS:
2703  {
2704  if (try_omit_comp)
2705  {
2706  // tried, but cannot omit component due to the ordering block [%d]: %d (ringorder_IS)", i, r_ord
2707  try_omit_comp = FALSE;
2708  }
2709  order[j]=r_ord; /*r->order[i];*/
2710  iNeedInducedOrderingSetup++;
2711  break;
2712  }
2713  case ringorder_s:
2714  {
2715  assume((i == 0) && (j == 0));
2716  if (try_omit_comp)
2717  {
2718  // tried, but cannot omit component due to the ordering block [%d]: %d (ringorder_s)", i, r_ord
2719  try_omit_comp = FALSE;
2720  }
2721  order[j]=r_ord; /*r->order[i];*/
2722  break;
2723  }
2724  default:
2725  order[j]=r_ord; /*r->order[i];*/
2726  break;
2727  }
2728  if (copy_block_index)
2729  {
2730  block0[j]=r->block0[i];
2731  block1[j]=r->block1[i];
2732  wvhdl[j]=r->wvhdl[i];
2733  }
2734 
2735  // order[j]=ringorder_no; // done by omAlloc0
2736  }
2737  if(!need_other_ring)
2738  {
2739  omFreeSize(order,(nblocks+1)*sizeof(rRingOrder_t));
2740  omFreeSize(block0,(nblocks+1)*sizeof(int));
2741  omFreeSize(block1,(nblocks+1)*sizeof(int));
2742  omFreeSize(wvhdl,(nblocks+1)*sizeof(int *));
2743  return r;
2744  }
2745  ring res=(ring)omAlloc0Bin(sip_sring_bin);
2746  *res = *r;
2747 
2748 #ifdef HAVE_PLURAL
2749  res->GetNC() = NULL;
2750 #endif
2751 
2752  // res->qideal, res->idroot ???
2753  res->wvhdl=wvhdl;
2754  res->order=order;
2755  res->block0=block0;
2756  res->block1=block1;
2757  res->bitmask=exp_limit;
2758  //int tmpref=r->cf->ref0;
2759  rComplete(res, 1);
2760  //r->cf->ref=tmpref;
2761 
2762  // adjust res->pFDeg: if it was changed globally, then
2763  // it must also be changed for new ring
2764  if (r->pFDegOrig != res->pFDegOrig &&
2766  {
2767  // still might need adjustment for weighted orderings
2768  // and omit_degree
2769  res->firstwv = r->firstwv;
2770  res->firstBlockEnds = r->firstBlockEnds;
2771  res->pFDeg = res->pFDegOrig = p_WFirstTotalDegree;
2772  }
2773  if (omitted_degree)
2774  res->pLDeg = r->pLDegOrig;
2775 
2776  rOptimizeLDeg(res); // also sets res->pLDegOrig
2777 
2778  // set syzcomp
2779  if (res->typ != NULL)
2780  {
2781  if( res->typ[0].ord_typ == ro_syz) // "s" Always on [0] place!
2782  {
2783  res->typ[0] = r->typ[0]; // Copy struct!? + setup the same limit!
2784 
2785  if (r->typ[0].data.syz.limit > 0)
2786  {
2787  res->typ[0].data.syz.syz_index
2788  = (int*) omAlloc((r->typ[0].data.syz.limit +1)*sizeof(int));
2789  memcpy(res->typ[0].data.syz.syz_index, r->typ[0].data.syz.syz_index,
2790  (r->typ[0].data.syz.limit +1)*sizeof(int));
2791  }
2792  }
2793 
2794  if( iNeedInducedOrderingSetup > 0 )
2795  {
2796  for(j = 0, i = 0; (i < nblocks) && (iNeedInducedOrderingSetup > 0); i++)
2797  if( res->typ[i].ord_typ == ro_is ) // Search for suffixes!
2798  {
2799  ideal F = idrHeadR(r->typ[i].data.is.F, r, res); // Copy F from r into res!
2800  assume(
2802  F, // WILL BE COPIED!
2803  r->typ[i].data.is.limit,
2804  j++
2805  )
2806  );
2807  id_Delete(&F, res);
2808  iNeedInducedOrderingSetup--;
2809  }
2810  } // Process all induced Ordering blocks! ...
2811  }
2812  // the special case: homog (omit_degree) and 1 block rs: that is global:
2813  // it comes from dp
2814  res->OrdSgn=r->OrdSgn;
2815 
2816 
2817 #ifdef HAVE_PLURAL
2818  if (rIsPluralRing(r))
2819  {
2820  if ( nc_rComplete(r, res, false) ) // no qideal!
2821  {
2822 #ifndef SING_NDEBUG
2823  WarnS("error in nc_rComplete");
2824 #endif
2825  // cleanup?
2826 
2827 // rDelete(res);
2828 // return r;
2829 
2830  // just go on..
2831  }
2832 
2833  if( rIsSCA(r) )
2834  {
2835  if( !sca_Force(res, scaFirstAltVar(r), scaLastAltVar(r)) )
2836  WarnS("error in sca_Force!");
2837  }
2838  }
2839 #endif
2840 
2841  return res;
2842 }
2843 
2844 // construct Wp,C ring
2845 ring rModifyRing_Wp(ring r, int* weights)
2846 {
2847  ring res=(ring)omAlloc0Bin(sip_sring_bin);
2848  *res = *r;
2849 #ifdef HAVE_PLURAL
2850  res->GetNC() = NULL;
2851 #endif
2852 
2853  /*weights: entries for 3 blocks: NULL*/
2854  res->wvhdl = (int **)omAlloc0(3 * sizeof(int *));
2855  /*order: Wp,C,0*/
2856  res->order = (rRingOrder_t *) omAlloc(3 * sizeof(rRingOrder_t *));
2857  res->block0 = (int *)omAlloc0(3 * sizeof(int *));
2858  res->block1 = (int *)omAlloc0(3 * sizeof(int *));
2859  /* ringorder Wp for the first block: var 1..r->N */
2860  res->order[0] = ringorder_Wp;
2861  res->block0[0] = 1;
2862  res->block1[0] = r->N;
2863  res->wvhdl[0] = weights;
2864  /* ringorder C for the second block: no vars */
2865  res->order[1] = ringorder_C;
2866  /* the last block: everything is 0 */
2867  res->order[2] = (rRingOrder_t)0;
2868 
2869  //int tmpref=r->cf->ref;
2870  rComplete(res, 1);
2871  //r->cf->ref=tmpref;
2872 #ifdef HAVE_PLURAL
2873  if (rIsPluralRing(r))
2874  {
2875  if ( nc_rComplete(r, res, false) ) // no qideal!
2876  {
2877 #ifndef SING_NDEBUG
2878  WarnS("error in nc_rComplete");
2879 #endif
2880  // cleanup?
2881 
2882 // rDelete(res);
2883 // return r;
2884 
2885  // just go on..
2886  }
2887  }
2888 #endif
2889  return res;
2890 }
2891 
2892 // construct lp, C ring with r->N variables, r->names vars....
2893 ring rModifyRing_Simple(ring r, BOOLEAN ommit_degree, BOOLEAN ommit_comp, unsigned long exp_limit, BOOLEAN &simple)
2894 {
2895  simple=TRUE;
2896  if (!rHasSimpleOrder(r))
2897  {
2898  simple=FALSE; // sorting needed
2899  assume (r != NULL );
2900  assume (exp_limit > 1);
2901  int bits;
2902 
2903  exp_limit=rGetExpSize(exp_limit, bits, r->N);
2904 
2905  int nblocks=1+(ommit_comp!=0);
2906  rRingOrder_t *order=(rRingOrder_t*)omAlloc0((nblocks+1)*sizeof(rRingOrder_t));
2907  int *block0=(int*)omAlloc0((nblocks+1)*sizeof(int));
2908  int *block1=(int*)omAlloc0((nblocks+1)*sizeof(int));
2909  int **wvhdl=(int**)omAlloc0((nblocks+1)*sizeof(int *));
2910 
2911  order[0]=ringorder_lp;
2912  block0[0]=1;
2913  block1[0]=r->N;
2914  if (!ommit_comp)
2915  {
2916  order[1]=ringorder_C;
2917  }
2918  ring res=(ring)omAlloc0Bin(sip_sring_bin);
2919  *res = *r;
2920 #ifdef HAVE_PLURAL
2921  res->GetNC() = NULL;
2922 #endif
2923  // res->qideal, res->idroot ???
2924  res->wvhdl=wvhdl;
2925  res->order=order;
2926  res->block0=block0;
2927  res->block1=block1;
2928  res->bitmask=exp_limit;
2929  //int tmpref=r->cf->ref;
2930  rComplete(res, 1);
2931  //r->cf->ref=tmpref;
2932 
2933 #ifdef HAVE_PLURAL
2934  if (rIsPluralRing(r))
2935  {
2936  if ( nc_rComplete(r, res, false) ) // no qideal!
2937  {
2938 #ifndef SING_NDEBUG
2939  WarnS("error in nc_rComplete");
2940 #endif
2941  // cleanup?
2942 
2943 // rDelete(res);
2944 // return r;
2945 
2946  // just go on..
2947  }
2948  }
2949 #endif
2950 
2951  rOptimizeLDeg(res);
2952 
2953  return res;
2954  }
2955  return rModifyRing(r, ommit_degree, ommit_comp, exp_limit);
2956 }
2957 
2958 void rKillModifiedRing(ring r)
2959 {
2960  rUnComplete(r);
2961  omFree(r->order);
2962  omFree(r->block0);
2963  omFree(r->block1);
2964  omFree(r->wvhdl);
2966 }
2967 
2969 {
2970  rUnComplete(r);
2971  omFree(r->order);
2972  omFree(r->block0);
2973  omFree(r->block1);
2974  omFree(r->wvhdl[0]);
2975  omFree(r->wvhdl);
2977 }
2978 
2979 static void rSetOutParams(ring r)
2980 {
2981  r->VectorOut = (r->order[0] == ringorder_c);
2982  r->CanShortOut = TRUE;
2983  {
2984  int i;
2985  if (rParameter(r)!=NULL)
2986  {
2987  for (i=0;i<rPar(r);i++)
2988  {
2989  if(strlen(rParameter(r)[i])>1)
2990  {
2991  r->CanShortOut=FALSE;
2992  break;
2993  }
2994  }
2995  }
2996  if (r->CanShortOut)
2997  {
2998  // Hmm... sometimes (e.g., from maGetPreimage) new variables
2999  // are introduced, but their names are never set
3000  // hence, we do the following awkward trick
3001  int N = omSizeOfAddr(r->names)/sizeof(char*);
3002  if (r->N < N) N = r->N;
3003 
3004  for (i=(N-1);i>=0;i--)
3005  {
3006  if(r->names[i] != NULL && strlen(r->names[i])>1)
3007  {
3008  r->CanShortOut=FALSE;
3009  break;
3010  }
3011  }
3012  }
3013  }
3014  r->ShortOut = r->CanShortOut;
3015 
3016  assume( !( !r->CanShortOut && r->ShortOut ) );
3017 }
3018 
3019 static void rSetFirstWv(ring r, int i, rRingOrder_t* order, int* block1, int** wvhdl)
3020 {
3021  // cheat for ringorder_aa
3022  if (order[i] == ringorder_aa)
3023  i++;
3024  if(block1[i]!=r->N) r->LexOrder=TRUE;
3025  r->firstBlockEnds=block1[i];
3026  r->firstwv = wvhdl[i];
3027  if ((order[i]== ringorder_ws)
3028  || (order[i]==ringorder_Ws)
3029  || (order[i]== ringorder_wp)
3030  || (order[i]==ringorder_Wp)
3031  || (order[i]== ringorder_a)
3032  /*|| (order[i]==ringorder_A)*/)
3033  {
3034  int j;
3035  for(j=block1[i]-r->block0[i];j>=0;j--)
3036  {
3037  if (r->firstwv[j]==0) r->LexOrder=TRUE;
3038  }
3039  }
3040  else if (order[i]==ringorder_a64)
3041  {
3042  int j;
3043  int64 *w=rGetWeightVec(r);
3044  for(j=block1[i]-r->block0[i];j>=0;j--)
3045  {
3046  if (w[j]==0) r->LexOrder=TRUE;
3047  }
3048  }
3049 }
3050 
3051 static void rOptimizeLDeg(ring r)
3052 {
3053  if (r->pFDeg == p_Deg)
3054  {
3055  if (r->pLDeg == pLDeg1)
3056  r->pLDeg = pLDeg1_Deg;
3057  if (r->pLDeg == pLDeg1c)
3058  r->pLDeg = pLDeg1c_Deg;
3059  }
3060  else if (r->pFDeg == p_Totaldegree)
3061  {
3062  if (r->pLDeg == pLDeg1)
3063  r->pLDeg = pLDeg1_Totaldegree;
3064  if (r->pLDeg == pLDeg1c)
3065  r->pLDeg = pLDeg1c_Totaldegree;
3066  }
3067  else if (r->pFDeg == p_WFirstTotalDegree)
3068  {
3069  if (r->pLDeg == pLDeg1)
3070  r->pLDeg = pLDeg1_WFirstTotalDegree;
3071  if (r->pLDeg == pLDeg1c)
3072  r->pLDeg = pLDeg1c_WFirstTotalDegree;
3073  }
3074  r->pLDegOrig = r->pLDeg;
3075 }
3076 
3077 // set pFDeg, pLDeg, requires OrdSgn already set
3078 static void rSetDegStuff(ring r)
3079 {
3080  rRingOrder_t* order = r->order;
3081  int* block0 = r->block0;
3082  int* block1 = r->block1;
3083  int** wvhdl = r->wvhdl;
3084 
3085  if (order[0]==ringorder_S ||order[0]==ringorder_s || order[0]==ringorder_IS)
3086  {
3087  order++;
3088  block0++;
3089  block1++;
3090  wvhdl++;
3091  }
3092  r->LexOrder = FALSE;
3093  r->pFDeg = p_Totaldegree;
3094  r->pLDeg = (r->OrdSgn == 1 ? pLDegb : pLDeg0);
3095 
3096  /*======== ordering type is (am,_) ==================*/
3097  if (order[0]==ringorder_am)
3098  {
3099  for(int ii=block0[0];ii<=block1[0];ii++)
3100  if (wvhdl[0][ii-1]<0) { r->MixedOrder=2;break;}
3101  r->LexOrder=FALSE;
3102  for(int ii=block0[0];ii<=block1[0];ii++)
3103  if (wvhdl[0][ii-1]==0) { r->LexOrder=TRUE;break;}
3104  if ((block0[0]==1)&&(block1[0]==r->N))
3105  {
3106  r->pFDeg = p_Deg;
3107  r->pLDeg = pLDeg1c_Deg;
3108  }
3109  else
3110  {
3111  r->pFDeg = p_WTotaldegree;
3112  r->LexOrder=TRUE;
3113  r->pLDeg = pLDeg1c_WFirstTotalDegree;
3114  }
3115  r->firstwv = wvhdl[0];
3116  }
3117  /*======== ordering type is (_,c) =========================*/
3118  else if ((order[0]==ringorder_unspec) || (order[1] == 0)
3119  ||(
3120  ((order[1]==ringorder_c)||(order[1]==ringorder_C)
3121  ||(order[1]==ringorder_S)
3122  ||(order[1]==ringorder_s))
3123  && (order[0]!=ringorder_M)
3124  && (order[2]==0))
3125  )
3126  {
3127  if (r->OrdSgn == -1) r->pLDeg = pLDeg0c;
3128  if ((order[0] == ringorder_lp)
3129  || (order[0] == ringorder_ls)
3130  || (order[0] == ringorder_rp)
3131  || (order[0] == ringorder_rs))
3132  {
3133  r->LexOrder=TRUE;
3134  r->pLDeg = pLDeg1c;
3135  r->pFDeg = p_Totaldegree;
3136  }
3137  else if ((order[0] == ringorder_a)
3138  || (order[0] == ringorder_wp)
3139  || (order[0] == ringorder_Wp))
3140  {
3141  r->pFDeg = p_WFirstTotalDegree;
3142  }
3143  else if ((order[0] == ringorder_ws)
3144  || (order[0] == ringorder_Ws))
3145  {
3146  for(int ii=block0[0];ii<=block1[0];ii++)
3147  {
3148  if (wvhdl[0][ii-1]<0) { r->MixedOrder=2;break;}
3149  }
3150  if (r->MixedOrder==0)
3151  {
3152  if ((block0[0]==1)&&(block1[0]==r->N))
3153  r->pFDeg = p_WTotaldegree;
3154  else
3155  r->pFDeg = p_WFirstTotalDegree;
3156  }
3157  else
3158  r->pFDeg = p_Totaldegree;
3159  }
3160  r->firstBlockEnds=block1[0];
3161  r->firstwv = wvhdl[0];
3162  }
3163  /*======== ordering type is (c,_) =========================*/
3164  else if (((order[0]==ringorder_c)
3165  ||(order[0]==ringorder_C)
3166  ||(order[0]==ringorder_S)
3167  ||(order[0]==ringorder_s))
3168  && (order[1]!=ringorder_M)
3169  && (order[2]==0))
3170  {
3171  if ((order[1] == ringorder_lp)
3172  || (order[1] == ringorder_ls)
3173  || (order[1] == ringorder_rp)
3174  || order[1] == ringorder_rs)
3175  {
3176  r->LexOrder=TRUE;
3177  r->pLDeg = pLDeg1c;
3178  r->pFDeg = p_Totaldegree;
3179  }
3180  r->firstBlockEnds=block1[1];
3181  if (wvhdl!=NULL) r->firstwv = wvhdl[1];
3182  if ((order[1] == ringorder_a)
3183  || (order[1] == ringorder_wp)
3184  || (order[1] == ringorder_Wp))
3185  r->pFDeg = p_WFirstTotalDegree;
3186  else if ((order[1] == ringorder_ws)
3187  || (order[1] == ringorder_Ws))
3188  {
3189  for(int ii=block0[1];ii<=block1[1];ii++)
3190  if (wvhdl[1][ii-1]<0) { r->MixedOrder=2;break;}
3191  if (r->MixedOrder==FALSE)
3192  r->pFDeg = p_WFirstTotalDegree;
3193  else
3194  r->pFDeg = p_Totaldegree;
3195  }
3196  }
3197  /*------- more than one block ----------------------*/
3198  else
3199  {
3200  if ((r->VectorOut)||(order[0]==ringorder_C)||(order[0]==ringorder_S)||(order[0]==ringorder_s))
3201  {
3202  rSetFirstWv(r, 1, order, block1, wvhdl);
3203  }
3204  else
3205  rSetFirstWv(r, 0, order, block1, wvhdl);
3206 
3207  if ((order[0]!=ringorder_c)
3208  && (order[0]!=ringorder_C)
3209  && (order[0]!=ringorder_S)
3210  && (order[0]!=ringorder_s))
3211  {
3212  r->pLDeg = pLDeg1c;
3213  }
3214  else
3215  {
3216  r->pLDeg = pLDeg1;
3217  }
3218  r->pFDeg = p_WTotaldegree; // may be improved: p_Totaldegree for lp/dp/ls/.. blocks
3219  }
3220 
3223  {
3224  if(r->MixedOrder==FALSE)
3225  r->pFDeg = p_Deg;
3226  else
3227  r->pFDeg = p_Totaldegree;
3228  }
3229 
3230  if( rGetISPos(0, r) != -1 ) // Are there Schreyer induced blocks?
3231  {
3232 #ifndef SING_NDEBUG
3233  assume( r->pFDeg == p_Deg || r->pFDeg == p_WTotaldegree || r->pFDeg == p_Totaldegree);
3234 #endif
3235 
3236  r->pLDeg = pLDeg1; // ?
3237  }
3238 
3239  r->pFDegOrig = r->pFDeg;
3240  // NOTE: this leads to wrong ecart during std
3241  // in Old/sre.tst
3242  rOptimizeLDeg(r); // also sets r->pLDegOrig
3243 }
3244 
3245 /*2
3246 * set NegWeightL_Size, NegWeightL_Offset
3247 */
3248 static void rSetNegWeight(ring r)
3249 {
3250  int i,l;
3251  if (r->typ!=NULL)
3252  {
3253  l=0;
3254  for(i=0;i<r->OrdSize;i++)
3255  {
3256  if((r->typ[i].ord_typ==ro_wp_neg)
3257  ||(r->typ[i].ord_typ==ro_am))
3258  l++;
3259  }
3260  if (l>0)
3261  {
3262  r->NegWeightL_Size=l;
3263  r->NegWeightL_Offset=(int *) omAlloc(l*sizeof(int));
3264  l=0;
3265  for(i=0;i<r->OrdSize;i++)
3266  {
3267  if(r->typ[i].ord_typ==ro_wp_neg)
3268  {
3269  r->NegWeightL_Offset[l]=r->typ[i].data.wp.place;
3270  l++;
3271  }
3272  else if(r->typ[i].ord_typ==ro_am)
3273  {
3274  r->NegWeightL_Offset[l]=r->typ[i].data.am.place;
3275  l++;
3276  }
3277  }
3278  return;
3279  }
3280  }
3281  r->NegWeightL_Size = 0;
3282  r->NegWeightL_Offset = NULL;
3283 }
3284 
3285 static void rSetOption(ring r)
3286 {
3287  // set redthrough
3288  if (!TEST_OPT_OLDSTD && r->OrdSgn == 1 && ! r->LexOrder)
3289  r->options |= Sy_bit(OPT_REDTHROUGH);
3290  else
3291  r->options &= ~Sy_bit(OPT_REDTHROUGH);
3292 
3293  // set intStrategy
3294  if ( (r->cf->extRing!=NULL)
3295  || rField_is_Q(r)
3296  || rField_is_Ring(r)
3297  )
3298  r->options |= Sy_bit(OPT_INTSTRATEGY);
3299  else
3300  r->options &= ~Sy_bit(OPT_INTSTRATEGY);
3301 
3302  // set redTail
3303  if (r->LexOrder || r->OrdSgn == -1 || (r->cf->extRing!=NULL))
3304  r->options &= ~Sy_bit(OPT_REDTAIL);
3305  else
3306  r->options |= Sy_bit(OPT_REDTAIL);
3307 }
3308 
3309 static void rCheckOrdSgn(ring r,int i/*last block*/);
3310 
3311 /* -------------------------------------------------------- */
3312 /*2
3313 * change all global variables to fit the description of the new ring
3314 */
3315 
3316 void p_SetGlobals(const ring r, BOOLEAN complete)
3317 {
3318 // // // if (r->ppNoether!=NULL) p_Delete(&r->ppNoether,r); // ???
3319 
3320  r->pLexOrder=r->LexOrder;
3321  if (complete)
3322  {
3324  si_opt_1 |= r->options;
3325  }
3326 }
3327 
3328 static inline int sign(int x) { return (x > 0) - (x < 0);}
3330 {
3331  int i;
3332  poly p=p_One(r);
3333  p_SetExp(p,1,1,r);
3334  p_Setm(p,r);
3335  int vz=sign(p_FDeg(p,r));
3336  for(i=2;i<=rVar(r);i++)
3337  {
3338  p_SetExp(p,i-1,0,r);
3339  p_SetExp(p,i,1,r);
3340  p_Setm(p,r);
3341  if (sign(p_FDeg(p,r))!=vz)
3342  {
3343  p_Delete(&p,r);
3344  return TRUE;
3345  }
3346  }
3347  p_Delete(&p,r);
3348  return FALSE;
3349 }
3350 
3351 BOOLEAN rComplete(ring r, int force)
3352 {
3353  if (r->VarOffset!=NULL && force == 0) return FALSE;
3354  rSetOutParams(r);
3355  int n=rBlocks(r)-1;
3356  int i;
3357  int bits;
3358  r->bitmask=rGetExpSize(r->bitmask,bits,r->N);
3359  r->BitsPerExp = bits;
3360  r->ExpPerLong = BIT_SIZEOF_LONG / bits;
3361  r->divmask=rGetDivMask(bits);
3362 
3363  // will be used for ordsgn:
3364  long *tmp_ordsgn=(long *)omAlloc0(3*(n+r->N)*sizeof(long));
3365  // will be used for VarOffset:
3366  int *v=(int *)omAlloc((r->N+1)*sizeof(int));
3367  for(i=r->N; i>=0 ; i--)
3368  {
3369  v[i]=-1;
3370  }
3371  sro_ord *tmp_typ=(sro_ord *)omAlloc0(3*(n+r->N)*sizeof(sro_ord));
3372  int typ_i=0;
3373  int prev_ordsgn=0;
3374 
3375  // fill in v, tmp_typ, tmp_ordsgn, determine typ_i (== ordSize)
3376  int j=0;
3377  int j_bits=BITS_PER_LONG;
3378 
3379  BOOLEAN need_to_add_comp=FALSE; // Only for ringorder_s and ringorder_S!
3380 
3381  for(i=0;i<n;i++)
3382  {
3383  tmp_typ[typ_i].order_index=i;
3384  switch (r->order[i])
3385  {
3386  case ringorder_a:
3387  case ringorder_aa:
3388  rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,tmp_typ[typ_i],
3389  r->wvhdl[i]);
3390  typ_i++;
3391  break;
3392 
3393  case ringorder_am:
3394  rO_WMDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,tmp_typ[typ_i],
3395  r->wvhdl[i]);
3396  typ_i++;
3397  break;
3398 
3399  case ringorder_a64:
3400  rO_WDegree64(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3401  tmp_typ[typ_i], (int64 *)(r->wvhdl[i]));
3402  typ_i++;
3403  break;
3404 
3405  case ringorder_c:
3406  rO_Align(j, j_bits);
3407  rO_LexVars_neg(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1);
3408  r->ComponentOrder=1;
3409  break;
3410 
3411  case ringorder_C:
3412  rO_Align(j, j_bits);
3413  rO_LexVars(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1);
3414  r->ComponentOrder=-1;
3415  break;
3416 
3417  case ringorder_M:
3418  {
3419  int k,l;
3420  k=r->block1[i]-r->block0[i]+1; // number of vars
3421  for(l=0;l<k;l++)
3422  {
3423  rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3424  tmp_typ[typ_i],
3425  r->wvhdl[i]+(r->block1[i]-r->block0[i]+1)*l);
3426  typ_i++;
3427  }
3428  break;
3429  }
3430 
3431  case ringorder_lp:
3432  rO_LexVars(j, j_bits, r->block0[i],r->block1[i], prev_ordsgn,
3433  tmp_ordsgn,v,bits, -1);
3434  break;
3435 
3436  case ringorder_ls:
3437  rO_LexVars_neg(j, j_bits, r->block0[i],r->block1[i], prev_ordsgn,
3438  tmp_ordsgn,v, bits, -1);
3439  break;
3440 
3441  case ringorder_rs:
3442  rO_LexVars_neg(j, j_bits, r->block1[i],r->block0[i], prev_ordsgn,
3443  tmp_ordsgn,v, bits, -1);
3444  break;
3445 
3446  case ringorder_rp:
3447  rO_LexVars(j, j_bits, r->block1[i],r->block0[i], prev_ordsgn,
3448  tmp_ordsgn,v, bits, -1);
3449  break;
3450 
3451  case ringorder_dp:
3452  if (r->block0[i]==r->block1[i])
3453  {
3454  rO_LexVars(j, j_bits, r->block0[i],r->block0[i], prev_ordsgn,
3455  tmp_ordsgn,v, bits, -1);
3456  }
3457  else
3458  {
3459  rO_TDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3460  tmp_typ[typ_i]);
3461  typ_i++;
3462  rO_LexVars_neg(j, j_bits, r->block1[i],r->block0[i]+1,
3463  prev_ordsgn,tmp_ordsgn,v,bits, r->block0[i]);
3464  }
3465  break;
3466 
3467  case ringorder_Dp:
3468  if (r->block0[i]==r->block1[i])
3469  {
3470  rO_LexVars(j, j_bits, r->block0[i],r->block0[i], prev_ordsgn,
3471  tmp_ordsgn,v, bits, -1);
3472  }
3473  else
3474  {
3475  rO_TDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3476  tmp_typ[typ_i]);
3477  typ_i++;
3478  rO_LexVars(j, j_bits, r->block0[i],r->block1[i]-1, prev_ordsgn,
3479  tmp_ordsgn,v, bits, r->block1[i]);
3480  }
3481  break;
3482 
3483  case ringorder_ds:
3484  if (r->block0[i]==r->block1[i])
3485  {
3486  rO_LexVars_neg(j, j_bits,r->block0[i],r->block1[i],prev_ordsgn,
3487  tmp_ordsgn,v,bits, -1);
3488  }
3489  else
3490  {
3491  rO_TDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3492  tmp_typ[typ_i]);
3493  typ_i++;
3494  rO_LexVars_neg(j, j_bits, r->block1[i],r->block0[i]+1,
3495  prev_ordsgn,tmp_ordsgn,v,bits, r->block0[i]);
3496  }
3497  break;
3498 
3499  case ringorder_Ds:
3500  if (r->block0[i]==r->block1[i])
3501  {
3502  rO_LexVars_neg(j, j_bits, r->block0[i],r->block0[i],prev_ordsgn,
3503  tmp_ordsgn,v, bits, -1);
3504  }
3505  else
3506  {
3507  rO_TDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3508  tmp_typ[typ_i]);
3509  typ_i++;
3510  rO_LexVars(j, j_bits, r->block0[i],r->block1[i]-1, prev_ordsgn,
3511  tmp_ordsgn,v, bits, r->block1[i]);
3512  }
3513  break;
3514 
3515  case ringorder_wp:
3516  rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3517  tmp_typ[typ_i], r->wvhdl[i]);
3518  typ_i++;
3519  { // check for weights <=0
3520  int jj;
3521  BOOLEAN have_bad_weights=FALSE;
3522  for(jj=r->block1[i]-r->block0[i];jj>=0; jj--)
3523  {
3524  if (r->wvhdl[i][jj]<=0) have_bad_weights=TRUE;
3525  }
3526  if (have_bad_weights)
3527  {
3528  rO_TDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3529  tmp_typ[typ_i]);
3530  typ_i++;
3531  }
3532  }
3533  if (r->block1[i]!=r->block0[i])
3534  {
3535  rO_LexVars_neg(j, j_bits,r->block1[i],r->block0[i]+1, prev_ordsgn,
3536  tmp_ordsgn, v,bits, r->block0[i]);
3537  }
3538  break;
3539 
3540  case ringorder_Wp:
3541  rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3542  tmp_typ[typ_i], r->wvhdl[i]);
3543  typ_i++;
3544  { // check for weights <=0
3545  int jj;
3546  BOOLEAN have_bad_weights=FALSE;
3547  for(jj=r->block1[i]-r->block0[i];jj>=0; jj--)
3548  {
3549  if (r->wvhdl[i][jj]<=0) have_bad_weights=TRUE;
3550  }
3551  if (have_bad_weights)
3552  {
3553  rO_TDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3554  tmp_typ[typ_i]);
3555  typ_i++;
3556  }
3557  }
3558  if (r->block1[i]!=r->block0[i])
3559  {
3560  rO_LexVars(j, j_bits,r->block0[i],r->block1[i]-1, prev_ordsgn,
3561  tmp_ordsgn,v, bits, r->block1[i]);
3562  }
3563  break;
3564 
3565  case ringorder_ws:
3566  rO_WDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3567  tmp_typ[typ_i], r->wvhdl[i]);
3568  typ_i++;
3569  if (r->block1[i]!=r->block0[i])
3570  {
3571  rO_LexVars_neg(j, j_bits,r->block1[i],r->block0[i]+1, prev_ordsgn,
3572  tmp_ordsgn, v,bits, r->block0[i]);
3573  }
3574  break;
3575 
3576  case ringorder_Ws:
3577  rO_WDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
3578  tmp_typ[typ_i], r->wvhdl[i]);
3579  typ_i++;
3580  if (r->block1[i]!=r->block0[i])
3581  {
3582  rO_LexVars(j, j_bits,r->block0[i],r->block1[i]-1, prev_ordsgn,
3583  tmp_ordsgn,v, bits, r->block1[i]);
3584  }
3585  break;
3586 
3587  case ringorder_S:
3588  assume(typ_i == 1); // For LaScala3 only: on the 2nd place ([1])!
3589  // TODO: for K[x]: it is 0...?!
3590  rO_Syzcomp(j, j_bits,prev_ordsgn, tmp_ordsgn,tmp_typ[typ_i]);
3591  need_to_add_comp=TRUE;
3592  r->ComponentOrder=-1;
3593  typ_i++;
3594  break;
3595 
3596  case ringorder_s:
3597  assume(typ_i == 0 && j == 0);
3598  rO_Syz(j, j_bits, prev_ordsgn, r->block0[i], tmp_ordsgn, tmp_typ[typ_i]); // set syz-limit?
3599  need_to_add_comp=TRUE;
3600  r->ComponentOrder=-1;
3601  typ_i++;
3602  break;
3603 
3604  case ringorder_IS:
3605  {
3606 
3607  assume( r->block0[i] == r->block1[i] );
3608  const int s = r->block0[i];
3609  assume( -2 < s && s < 2);
3610 
3611  if(s == 0) // Prefix IS
3612  rO_ISPrefix(j, j_bits, prev_ordsgn, tmp_ordsgn, r->N, v, tmp_typ[typ_i++]); // What about prev_ordsgn?
3613  else // s = +1 or -1 // Note: typ_i might be incrimented here inside!
3614  {
3615  rO_ISSuffix(j, j_bits, prev_ordsgn, tmp_ordsgn, r->N, v, tmp_typ, typ_i, s); // Suffix.
3616  need_to_add_comp=FALSE;
3617  }
3618 
3619  break;
3620  }
3621  case ringorder_unspec:
3622  case ringorder_no:
3623  default:
3624  dReportError("undef. ringorder used\n");
3625  break;
3626  }
3627  }
3628  rCheckOrdSgn(r,n-1);
3629 
3630  int j0=j; // save j
3631  int j_bits0=j_bits; // save jbits
3632  rO_Align(j,j_bits);
3633  r->CmpL_Size = j;
3634 
3635  j_bits=j_bits0; j=j0;
3636 
3637  // fill in some empty slots with variables not already covered
3638  // v0 is special, is therefore normally already covered
3639  // now we do have rings without comp...
3640  if((need_to_add_comp) && (v[0]== -1))
3641  {
3642  if (prev_ordsgn==1)
3643  {
3644  rO_Align(j, j_bits);
3645  rO_LexVars(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1);
3646  }
3647  else
3648  {
3649  rO_Align(j, j_bits);
3650  rO_LexVars_neg(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1);
3651  }
3652  }
3653  // the variables
3654  for(i=1 ; i<=r->N ; i++)
3655  {
3656  if(v[i]==(-1))
3657  {
3658  if (prev_ordsgn==1)
3659  {
3660  rO_LexVars(j, j_bits, i,i, prev_ordsgn,tmp_ordsgn,v,bits, -1);
3661  }
3662  else
3663  {
3664  rO_LexVars_neg(j,j_bits,i,i, prev_ordsgn,tmp_ordsgn,v,bits, -1);
3665  }
3666  }
3667  }
3668 
3669  rO_Align(j,j_bits);
3670  // ----------------------------
3671  // finished with constructing the monomial, computing sizes:
3672 
3673  r->ExpL_Size=j;
3674  r->PolyBin = omGetSpecBin(POLYSIZE + (r->ExpL_Size)*sizeof(long));
3675  assume(r->PolyBin != NULL);
3676 
3677  // ----------------------------
3678  // indices and ordsgn vector for comparison
3679  //
3680  // r->pCompHighIndex already set
3681  r->ordsgn=(long *)omAlloc0(r->ExpL_Size*sizeof(long));
3682 
3683  for(j=0;j<r->CmpL_Size;j++)
3684  {
3685  r->ordsgn[j] = tmp_ordsgn[j];
3686  }
3687 
3688  omFreeSize((ADDRESS)tmp_ordsgn,(3*(n+r->N)*sizeof(long)));
3689 
3690  // ----------------------------
3691  // description of orderings for setm:
3692  //
3693  r->OrdSize=typ_i;
3694  if (typ_i==0) r->typ=NULL;
3695  else
3696  {
3697  r->typ=(sro_ord*)omAlloc(typ_i*sizeof(sro_ord));
3698  memcpy(r->typ,tmp_typ,typ_i*sizeof(sro_ord));
3699  }
3700  omFreeSize((ADDRESS)tmp_typ,(3*(n+r->N)*sizeof(sro_ord)));
3701 
3702  // ----------------------------
3703  // indices for (first copy of ) variable entries in exp.e vector (VarOffset):
3704  r->VarOffset=v;
3705 
3706  // ----------------------------
3707  // other indicies
3708  r->pCompIndex=(r->VarOffset[0] & 0xffff); //r->VarOffset[0];
3709  i=0; // position
3710  j=0; // index in r->typ
3711  if (i==r->pCompIndex) i++; // IS???
3712  while ((j < r->OrdSize)
3713  && ((r->typ[j].ord_typ==ro_syzcomp) ||
3714  (r->typ[j].ord_typ==ro_syz) || (r->typ[j].ord_typ==ro_isTemp) || (r->typ[j].ord_typ==ro_is) ||
3715  (r->order[r->typ[j].order_index] == ringorder_aa)))
3716  {
3717  i++; j++;
3718  }
3719 
3720  if (i==r->pCompIndex) i++;
3721  r->pOrdIndex=i;
3722 
3723  // ----------------------------
3724  rSetDegStuff(r); // OrdSgn etc already set
3725  rSetOption(r);
3726  // ----------------------------
3727  // r->p_Setm
3728  r->p_Setm = p_GetSetmProc(r);
3729 
3730  // ----------------------------
3731  // set VarL_*
3732  rSetVarL(r);
3733 
3734  // ----------------------------
3735  // right-adjust VarOffset
3737 
3738  // ----------------------------
3739  // set NegWeightL*
3740  rSetNegWeight(r);
3741 
3742  // ----------------------------
3743  // p_Procs: call AFTER NegWeightL
3744  r->p_Procs = (p_Procs_s*)omAlloc(sizeof(p_Procs_s));
3745  p_ProcsSet(r, r->p_Procs);
3746 
3747  // use totaldegree on crazy oderings:
3748  if ((r->pFDeg==p_WTotaldegree) && rOrd_is_MixedDegree_Ordering(r))
3749  r->pFDeg = p_Totaldegree;
3750  return FALSE;
3751 }
3752 
3753 static void rCheckOrdSgn(ring r,int b/*last block*/)
3754 { // set r->OrdSgn, r->MixedOrder
3755  // for each variable:
3756  int nonpos=0;
3757  int nonneg=0;
3758  for(int i=1;i<=r->N;i++)
3759  {
3760  int found=0;
3761  // for all blocks:
3762  for(int j=0;(j<=b) && (found==0);j++)
3763  {
3764  // search the first block containing var(i)
3765  if ((r->block0[j]<=i)&&(r->block1[j]>=i))
3766  {
3767  // what kind if block is it?
3768  if ((r->order[j]==ringorder_ls)
3769  || (r->order[j]==ringorder_ds)
3770  || (r->order[j]==ringorder_Ds)
3771  || (r->order[j]==ringorder_ws)
3772  || (r->order[j]==ringorder_Ws)
3773  || (r->order[j]==ringorder_rs))
3774  {
3775  r->OrdSgn=-1;
3776  nonpos++;
3777  found=1;
3778  }
3779  else if((r->order[j]==ringorder_a)
3780  ||(r->order[j]==ringorder_aa))
3781  {
3782  // <0: local/mixed ordering
3783  // >0: var(i) is okay, look at other vars
3784  // ==0: look at other blocks for var(i)
3785  if(r->wvhdl[j][i-r->block0[j]]<0)
3786  {
3787  r->OrdSgn=-1;
3788  nonpos++;
3789  found=1;
3790  }
3791  else if(r->wvhdl[j][i-r->block0[j]]>0)
3792  {
3793  nonneg++;
3794  found=1;
3795  }
3796  }
3797  else if(r->order[j]==ringorder_M)
3798  {
3799  // <0: local/mixed ordering
3800  // >0: var(i) is okay, look at other vars
3801  // ==0: look at other blocks for var(i)
3802  if(r->wvhdl[j][i-r->block0[j]]<0)
3803  {
3804  r->OrdSgn=-1;
3805  nonpos++;
3806  found=1;
3807  }
3808  else if(r->wvhdl[j][i-r->block0[j]]>0)
3809  {
3810  nonneg++;
3811  found=1;
3812  }
3813  else
3814  {
3815  // very bad:
3816  nonpos++;
3817  nonneg++;
3818  found=1;
3819  }
3820  }
3821  else if ((r->order[j]==ringorder_lp)
3822  || (r->order[j]==ringorder_dp)
3823  || (r->order[j]==ringorder_Dp)
3824  || (r->order[j]==ringorder_wp)
3825  || (r->order[j]==ringorder_Wp)
3826  || (r->order[j]==ringorder_rp))
3827  {
3828  found=1;
3829  nonneg++;
3830  }
3831  }
3832  }
3833  }
3834  if (nonpos>0)
3835  {
3836  r->OrdSgn=-1;
3837  if (nonneg>0) r->MixedOrder=1;
3838  }
3839  else
3840  {
3841  r->OrdSgn=1;
3842  r->MixedOrder=0;
3843  }
3844 }
3845 
3846 void rUnComplete(ring r)
3847 {
3848  if (r == NULL) return;
3849  if (r->VarOffset != NULL)
3850  {
3851  if (r->OrdSize!=0 && r->typ != NULL)
3852  {
3853  for(int i = 0; i < r->OrdSize; i++)
3854  if( r->typ[i].ord_typ == ro_is) // Search for suffixes! (prefix have the same VarOffset)
3855  {
3856  id_Delete(&r->typ[i].data.is.F, r);
3857  r->typ[i].data.is.F = NULL; // ?
3858 
3859  if( r->typ[i].data.is.pVarOffset != NULL )
3860  {
3861  omFreeSize((ADDRESS)r->typ[i].data.is.pVarOffset, (r->N +1)*sizeof(int));
3862  r->typ[i].data.is.pVarOffset = NULL; // ?
3863  }
3864  }
3865  else if (r->typ[i].ord_typ == ro_syz)
3866  {
3867  if(r->typ[i].data.syz.limit > 0)
3868  omFreeSize(r->typ[i].data.syz.syz_index, ((r->typ[i].data.syz.limit) +1)*sizeof(int));
3869  r->typ[i].data.syz.syz_index = NULL;
3870  }
3871  else if (r->typ[i].ord_typ == ro_syzcomp)
3872  {
3873  assume( r->typ[i].data.syzcomp.ShiftedComponents == NULL );
3874  assume( r->typ[i].data.syzcomp.Components == NULL );
3875 // WarnS( "rUnComplete : ord_typ == ro_syzcomp was unhandled!!! Possibly memory leak!!!" );
3876 #ifndef SING_NDEBUG
3877 // assume(0);
3878 #endif
3879  }
3880 
3881  omFreeSize((ADDRESS)r->typ,r->OrdSize*sizeof(sro_ord)); r->typ = NULL;
3882  }
3883 
3884  if (r->PolyBin != NULL)
3885  omUnGetSpecBin(&(r->PolyBin));
3886 
3887  omFreeSize((ADDRESS)r->VarOffset, (r->N +1)*sizeof(int));
3888 
3889  if (r->ordsgn != NULL && r->CmpL_Size != 0)
3890  omFreeSize((ADDRESS)r->ordsgn,r->ExpL_Size*sizeof(long));
3891  if (r->p_Procs != NULL)
3892  omFreeSize(r->p_Procs, sizeof(p_Procs_s));
3893  omfreeSize(r->VarL_Offset, r->VarL_Size*sizeof(int));
3894  }
3895  if (r->NegWeightL_Offset!=NULL)
3896  {
3897  omFreeSize(r->NegWeightL_Offset, r->NegWeightL_Size*sizeof(int));
3898  r->NegWeightL_Offset=NULL;
3899  }
3900 }
3901 
3902 // set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex
3903 static void rSetVarL(ring r)
3904 {
3905  int min = MAX_INT_VAL, min_j = -1;
3906  int* VarL_Number = (int*) omAlloc0(r->ExpL_Size*sizeof(int));
3907 
3908  int i,j;
3909 
3910  // count how often a var long is occupied by an exponent
3911  for (i=1; i<=r->N; i++)
3912  {
3913  VarL_Number[r->VarOffset[i] & 0xffffff]++;
3914  }
3915 
3916  // determine how many and min
3917  for (i=0, j=0; i<r->ExpL_Size; i++)
3918  {
3919  if (VarL_Number[i] != 0)
3920  {
3921  if (min > VarL_Number[i])
3922  {
3923  min = VarL_Number[i];
3924  min_j = j;
3925  }
3926  j++;
3927  }
3928  }
3929 
3930  r->VarL_Size = j; // number of long with exp. entries in
3931  // in p->exp
3932  r->VarL_Offset = (int*) omAlloc(r->VarL_Size*sizeof(int));
3933  r->VarL_LowIndex = 0;
3934 
3935  // set VarL_Offset
3936  for (i=0, j=0; i<r->ExpL_Size; i++)
3937  {
3938  if (VarL_Number[i] != 0)
3939  {
3940  r->VarL_Offset[j] = i;
3941  if (j > 0 && r->VarL_Offset[j-1] != r->VarL_Offset[j] - 1)
3942  r->VarL_LowIndex = -1;
3943  j++;
3944  }
3945  }
3946  if (r->VarL_LowIndex >= 0)
3947  r->VarL_LowIndex = r->VarL_Offset[0];
3948 
3949  if (min_j != 0)
3950  {
3951  j = r->VarL_Offset[min_j];
3952  r->VarL_Offset[min_j] = r->VarL_Offset[0];
3953  r->VarL_Offset[0] = j;
3954  }
3955  omFree(VarL_Number);
3956 }
3957 
3958 static void rRightAdjustVarOffset(ring r)
3959 {
3960  int* shifts = (int*) omAlloc(r->ExpL_Size*sizeof(int));
3961  int i;
3962  // initialize shifts
3963  for (i=0;i<r->ExpL_Size;i++)
3964  shifts[i] = BIT_SIZEOF_LONG;
3965 
3966  // find minimal bit shift in each long exp entry
3967  for (i=1;i<=r->N;i++)
3968  {
3969  if (shifts[r->VarOffset[i] & 0xffffff] > r->VarOffset[i] >> 24)
3970  shifts[r->VarOffset[i] & 0xffffff] = r->VarOffset[i] >> 24;
3971  }
3972  // reset r->VarOffset: set the minimal shift to 0
3973  for (i=1;i<=r->N;i++)
3974  {
3975  if (shifts[r->VarOffset[i] & 0xffffff] != 0)
3976  r->VarOffset[i]
3977  = (r->VarOffset[i] & 0xffffff) |
3978  (((r->VarOffset[i] >> 24) - shifts[r->VarOffset[i] & 0xffffff]) << 24);
3979  }
3980  omFree(shifts);
3981 }
3982 
3983 // get r->divmask depending on bits per exponent
3984 static unsigned long rGetDivMask(int bits)
3985 {
3986  unsigned long divmask = 1;
3987  int i = bits;
3988 
3989  while (i < BIT_SIZEOF_LONG)
3990  {
3991  divmask |= (((unsigned long) 1) << (unsigned long) i);
3992  i += bits;
3993  }
3994  return divmask;
3995 }
3996 
3997 #ifdef RDEBUG
3998 void rDebugPrint(const ring r)
3999 {
4000  if (r==NULL)
4001  {
4002  PrintS("NULL ?\n");
4003  return;
4004  }
4005  // corresponds to ro_typ from ring.h:
4006  const char *TYP[]={"ro_dp","ro_wp","ro_am","ro_wp64","ro_wp_neg","ro_cp",
4007  "ro_syzcomp", "ro_syz", "ro_isTemp", "ro_is", "ro_none"};
4008  int i,j;
4009 
4010  Print("ExpL_Size:%d ",r->ExpL_Size);
4011  Print("CmpL_Size:%d ",r->CmpL_Size);
4012  Print("VarL_Size:%d\n",r->VarL_Size);
4013  Print("bitmask=0x%lx (expbound=%ld) \n",r->bitmask, r->bitmask);
4014  Print("divmask=%lx\n", r->divmask);
4015  Print("BitsPerExp=%d ExpPerLong=%d at L[%d]\n", r->BitsPerExp, r->ExpPerLong, r->VarL_Offset[0]);
4016 
4017  Print("VarL_LowIndex: %d\n", r->VarL_LowIndex);
4018  PrintS("VarL_Offset:\n");
4019  if (r->VarL_Offset==NULL) PrintS(" NULL");
4020  else
4021  for(j = 0; j < r->VarL_Size; j++)
4022  Print(" VarL_Offset[%d]: %d ", j, r->VarL_Offset[j]);
4023  PrintLn();
4024 
4025 
4026  PrintS("VarOffset:\n");
4027  if (r->VarOffset==NULL) PrintS(" NULL\n");
4028  else
4029  for(j=0;j<=r->N;j++)
4030  Print(" v%d at e-pos %d, bit %d\n",
4031  j,r->VarOffset[j] & 0xffffff, r->VarOffset[j] >>24);
4032  PrintS("ordsgn:\n");
4033  for(j=0;j<r->CmpL_Size;j++)
4034  Print(" ordsgn %ld at pos %d\n",r->ordsgn[j],j);
4035  Print("OrdSgn:%d\n",r->OrdSgn);
4036  PrintS("ordrec:\n");
4037  for(j=0;j<r->OrdSize;j++)
4038  {
4039  Print(" typ %s", TYP[r->typ[j].ord_typ]);
4040  if (r->typ[j].ord_typ==ro_syz)
4041  {
4042  const short place = r->typ[j].data.syz.place;
4043  const int limit = r->typ[j].data.syz.limit;
4044  const int curr_index = r->typ[j].data.syz.curr_index;
4045  const int* syz_index = r->typ[j].data.syz.syz_index;
4046 
4047  Print(" limit %d (place: %d, curr_index: %d), syz_index: ", limit, place, curr_index);
4048 
4049  if( syz_index == NULL )
4050  PrintS("(NULL)");
4051  else
4052  {
4053  PrintS("{");
4054  for( i=0; i <= limit; i++ )
4055  Print("%d ", syz_index[i]);
4056  PrintS("}");
4057  }
4058 
4059  }
4060  else if (r->typ[j].ord_typ==ro_isTemp)
4061  {
4062  Print(" start (level) %d, suffixpos: %d, VO: ",r->typ[j].data.isTemp.start, r->typ[j].data.isTemp.suffixpos);
4063 
4064  }
4065  else if (r->typ[j].ord_typ==ro_is)
4066  {
4067  Print(" start %d, end: %d: ",r->typ[j].data.is.start, r->typ[j].data.is.end);
4068 
4069 // for( int k = 0; k <= r->N; k++) if (r->typ[j].data.is.pVarOffset[k] != -1) Print("[%2d]: %04x; ", k, r->typ[j].data.is.pVarOffset[k]);
4070 
4071  Print(" limit %d",r->typ[j].data.is.limit);
4072 #ifndef SING_NDEBUG
4073  //PrintS(" F: ");idShow(r->typ[j].data.is.F, r, r, 1);
4074 #endif
4075 
4076  PrintLn();
4077  }
4078  else if (r->typ[j].ord_typ==ro_am)
4079  {
4080  Print(" place %d",r->typ[j].data.am.place);
4081  Print(" start %d",r->typ[j].data.am.start);
4082  Print(" end %d",r->typ[j].data.am.end);
4083  Print(" len_gen %d",r->typ[j].data.am.len_gen);
4084  PrintS(" w:");
4085  int l=0;
4086  for(l=r->typ[j].data.am.start;l<=r->typ[j].data.am.end;l++)
4087  Print(" %d",r->typ[j].data.am.weights[l-r->typ[j].data.am.start]);
4088  l=r->typ[j].data.am.end+1;
4089  int ll=r->typ[j].data.am.weights[l-r->typ[j].data.am.start];
4090  PrintS(" m:");
4091  for(int lll=l+1;lll<l+ll+1;lll++)
4092  Print(" %d",r->typ[j].data.am.weights[lll-r->typ[j].data.am.start]);
4093  }
4094  else
4095  {
4096  Print(" place %d",r->typ[j].data.dp.place);
4097 
4098  if (r->typ[j].ord_typ!=ro_syzcomp && r->typ[j].ord_typ!=ro_syz)
4099  {
4100  Print(" start %d",r->typ[j].data.dp.start);
4101  Print(" end %d",r->typ[j].data.dp.end);
4102  if ((r->typ[j].ord_typ==ro_wp)
4103  || (r->typ[j].ord_typ==ro_wp_neg))
4104  {
4105  PrintS(" w:");
4106  for(int l=r->typ[j].data.wp.start;l<=r->typ[j].data.wp.end;l++)
4107  Print(" %d",r->typ[j].data.wp.weights[l-r->typ[j].data.wp.start]);
4108  }
4109  else if (r->typ[j].ord_typ==ro_wp64)
4110  {
4111  PrintS(" w64:");
4112  int l;
4113  for(l=r->typ[j].data.wp64.start;l<=r->typ[j].data.wp64.end;l++)
4114  Print(" %ld",(long)(((int64*)r->typ[j].data.wp64.weights64)+l-r->typ[j].data.wp64.start));
4115  }
4116  }
4117  }
4118  PrintLn();
4119  }
4120  Print("pOrdIndex:%d pCompIndex:%d\n", r->pOrdIndex, r->pCompIndex);
4121  Print("OrdSize:%d\n",r->OrdSize);
4122  PrintS("--------------------\n");
4123  for(j=0;j<r->ExpL_Size;j++)
4124  {
4125  Print("L[%d]: ",j);
4126  if (j< r->CmpL_Size)
4127  Print("ordsgn %ld ", r->ordsgn[j]);
4128  else
4129  PrintS("no comp ");
4130  i=1;
4131  for(;i<=r->N;i++)
4132  {
4133  if( (r->VarOffset[i] & 0xffffff) == j )
4134  { Print("v%d at e[%d], bit %d; ", i,r->VarOffset[i] & 0xffffff,
4135  r->VarOffset[i] >>24 ); }
4136  }
4137  if( r->pCompIndex==j ) PrintS("v0; ");
4138  for(i=0;i<r->OrdSize;i++)
4139  {
4140  if (r->typ[i].data.dp.place == j)
4141  {
4142  Print("ordrec:%s (start:%d, end:%d) ",TYP[r->typ[i].ord_typ],
4143  r->typ[i].data.dp.start, r->typ[i].data.dp.end);
4144  }
4145  }
4146 
4147  if (j==r->pOrdIndex)
4148  PrintS("pOrdIndex\n");
4149  else
4150  PrintLn();
4151  }
4152  Print("LexOrder:%d, MixedOrder:%d\n",r->LexOrder, r->MixedOrder);
4153 
4154  Print("NegWeightL_Size: %d, NegWeightL_Offset: ", r->NegWeightL_Size);
4155  if (r->NegWeightL_Offset==NULL) PrintS(" NULL");
4156  else
4157  for(j = 0; j < r->NegWeightL_Size; j++)
4158  Print(" [%d]: %d ", j, r->NegWeightL_Offset[j]);
4159  PrintLn();
4160 
4161  // p_Procs stuff
4162  p_Procs_s proc_names;
4163  const char* field;
4164  const char* length;
4165  const char* ord;
4166  p_Debug_GetProcNames(r, &proc_names); // changes p_Procs!!!
4167  p_Debug_GetSpecNames(r, field, length, ord);
4168 
4169  Print("p_Spec : %s, %s, %s\n", field, length, ord);
4170  PrintS("p_Procs :\n");
4171  for (i=0; i<(int) (sizeof(p_Procs_s)/sizeof(void*)); i++)
4172  {
4173  Print(" %s,\n", ((char**) &proc_names)[i]);
4174  }
4175 
4176  {
4177  PrintLn();
4178  PrintS("pFDeg : ");
4179 #define pFDeg_CASE(A) if(r->pFDeg == A) PrintS( "" #A "" )
4180  pFDeg_CASE(p_Totaldegree); else
4182  pFDeg_CASE(p_WTotaldegree); else
4183  pFDeg_CASE(p_Deg); else
4184 #undef pFDeg_CASE
4185  Print("(%p)", r->pFDeg); // default case
4186 
4187  PrintLn();
4188  Print("pLDeg : (%p)", r->pLDeg);
4189  PrintLn();
4190  }
4191  PrintS("pSetm:");
4192  void p_Setm_Dummy(poly p, const ring r);
4193  void p_Setm_TotalDegree(poly p, const ring r);
4194  void p_Setm_WFirstTotalDegree(poly p, const ring r);
4195  void p_Setm_General(poly p, const ring r);
4196  if (r->p_Setm==p_Setm_General) PrintS("p_Setm_General\n");
4197  else if (r->p_Setm==p_Setm_Dummy) PrintS("p_Setm_Dummy\n");
4198  else if (r->p_Setm==p_Setm_TotalDegree) PrintS("p_Setm_Totaldegree\n");
4199  else if (r->p_Setm==p_Setm_WFirstTotalDegree) PrintS("p_Setm_WFirstTotalDegree\n");
4200  else Print("%p\n",r->p_Setm);
4201 }
4202 
4203 void p_DebugPrint(poly p, const ring r)
4204 {
4205  int i,j;
4206  p_Write(p,r);
4207  j=2;
4208  while(p!=NULL)
4209  {
4210  Print("\nexp[0..%d]\n",r->ExpL_Size-1);
4211  for(i=0;i<r->ExpL_Size;i++)
4212  Print("%ld ",p->exp[i]);
4213  PrintLn();
4214  Print("v0:%ld ",p_GetComp(p, r));
4215  for(i=1;i<=r->N;i++) Print(" v%d:%ld",i,p_GetExp(p,i, r));
4216  PrintLn();
4217  pIter(p);
4218  j--;
4219  if (j==0) { PrintS("...\n"); break; }
4220  }
4221 }
4222 
4223 #endif // RDEBUG
4224 
4225 /// debug-print monomial poly/vector p, assuming that it lives in the ring R
4226 static inline void m_DebugPrint(const poly p, const ring R)
4227 {
4228  Print("\nexp[0..%d]\n", R->ExpL_Size - 1);
4229  for(int i = 0; i < R->ExpL_Size; i++)
4230  Print("%09lx ", p->exp[i]);
4231  PrintLn();
4232  Print("v0:%9ld ", p_GetComp(p, R));
4233  for(int i = 1; i <= R->N; i++) Print(" v%d:%5ld",i, p_GetExp(p, i, R));
4234  PrintLn();
4235 }
4236 
4237 
4238 // F = system("ISUpdateComponents", F, V, MIN );
4239 // // replace gen(i) -> gen(MIN + V[i-MIN]) for all i > MIN in all terms from F!
4240 void pISUpdateComponents(ideal F, const intvec *const V, const int MIN, const ring r )
4241 {
4242  assume( V != NULL );
4243  assume( MIN >= 0 );
4244 
4245  if( F == NULL )
4246  return;
4247 
4248  for( int j = (F->ncols*F->nrows) - 1; j >= 0; j-- )
4249  {
4250 #ifdef PDEBUG
4251  Print("F[%d]:", j);
4252  p_wrp(F->m[j], r);
4253 #endif
4254 
4255  for( poly p = F->m[j]; p != NULL; pIter(p) )
4256  {
4257  int c = p_GetComp(p, r);
4258 
4259  if( c > MIN )
4260  {
4261 #ifdef PDEBUG
4262  Print("gen[%d] -> gen(%d)\n", c, MIN + (*V)[ c - MIN - 1 ]);
4263 #endif
4264 
4265  p_SetComp( p, MIN + (*V)[ c - MIN - 1 ], r );
4266  }
4267  }
4268 #ifdef PDEBUG
4269  Print("new F[%d]:", j);
4270  p_Test(F->m[j], r);
4271  p_wrp(F->m[j], r);
4272 #endif
4273  }
4274 }
4275 
4276 /*2
4277 * asssume that rComplete was called with r
4278 * assume that the first block ist ringorder_S
4279 * change the block to reflect the sequence given by appending v
4280 */
4281 static inline void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r)
4282 {
4283  assume(r->typ[1].ord_typ == ro_syzcomp);
4284 
4285  r->typ[1].data.syzcomp.ShiftedComponents = currShiftedComponents;
4286  r->typ[1].data.syzcomp.Components = currComponents;
4287 }
4288 
4289 static inline void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r)
4290 {
4291  assume(r->typ[1].ord_typ == ro_syzcomp);
4292 
4293  *currShiftedComponents = r->typ[1].data.syzcomp.ShiftedComponents;
4294  *currComponents = r->typ[1].data.syzcomp.Components;
4295 }
4296 #ifdef PDEBUG
4297 static inline void rDBChangeSComps(int* currComponents,
4298  long* currShiftedComponents,
4299  int length,
4300  ring r)
4301 {
4302  assume(r->typ[1].ord_typ == ro_syzcomp);
4303 
4304  r->typ[1].data.syzcomp.length = length;
4305  rNChangeSComps( currComponents, currShiftedComponents, r);
4306 }
4307 static inline void rDBGetSComps(int** currComponents,
4308  long** currShiftedComponents,
4309  int *length,
4310  ring r)
4311 {
4312  assume(r->typ[1].ord_typ == ro_syzcomp);
4313 
4314  *length = r->typ[1].data.syzcomp.length;
4315  rNGetSComps( currComponents, currShiftedComponents, r);
4316 }
4317 #endif
4318 
4319 void rChangeSComps(int* currComponents, long* currShiftedComponents, int length, ring r)
4320 {
4321 #ifdef PDEBUG
4322  rDBChangeSComps(currComponents, currShiftedComponents, length, r);
4323 #else
4324  rNChangeSComps(currComponents, currShiftedComponents, r);
4325 #endif
4326 }
4327 
4328 void rGetSComps(int** currComponents, long** currShiftedComponents, int *length, ring r)
4329 {
4330 #ifdef PDEBUG
4331  rDBGetSComps(currComponents, currShiftedComponents, length, r);
4332 #else
4333  rNGetSComps(currComponents, currShiftedComponents, r);
4334 #endif
4335 }
4336 
4337 
4338 /////////////////////////////////////////////////////////////////////////////
4339 //
4340 // The following routines all take as input a ring r, and return R
4341 // where R has a certain property. R might be equal r in which case r
4342 // had already this property
4343 //
4344 ring rAssure_SyzOrder(const ring r, BOOLEAN complete)
4345 {
4346  if ( r->order[0] == ringorder_c ) return r;
4347  return rAssure_SyzComp(r,complete);
4348 }
4349 ring rAssure_SyzComp(const ring r, BOOLEAN complete)
4350 {
4351  if ( r->order[0] == ringorder_s ) return r;
4352 
4353  if ( r->order[0] == ringorder_IS )
4354  {
4355 #ifndef SING_NDEBUG
4356  WarnS("rAssure_SyzComp: input ring has an IS-ordering!");
4357 #endif
4358 // return r;
4359  }
4360  ring res=rCopy0(r, FALSE, FALSE);
4361  int i=rBlocks(r);
4362  int j;
4363 
4364  res->order=(rRingOrder_t *)omAlloc((i+1)*sizeof(rRingOrder_t));
4365  res->block0=(int *)omAlloc0((i+1)*sizeof(int));
4366  res->block1=(int *)omAlloc0((i+1)*sizeof(int));
4367  int ** wvhdl =(int **)omAlloc0((i+1)*sizeof(int**));
4368  for(j=i;j>0;j--)
4369  {
4370  res->order[j]=r->order[j-1];
4371  res->block0[j]=r->block0[j-1];
4372  res->block1[j]=r->block1[j-1];
4373  if (r->wvhdl[j-1] != NULL)
4374  {
4375  wvhdl[j] = (int*) omMemDup(r->wvhdl[j-1]);
4376  }
4377  }
4378  res->order[0]=ringorder_s;
4379 
4380  res->wvhdl = wvhdl;
4381 
4382  if (complete)
4383  {
4384  rComplete(res, 1);
4385 #ifdef HAVE_PLURAL
4386  if (rIsPluralRing(r))
4387  {
4388  if ( nc_rComplete(r, res, false) ) // no qideal!
4389  {
4390 #ifndef SING_NDEBUG
4391  WarnS("error in nc_rComplete"); // cleanup?// rDelete(res);// return r; // just go on..
4392 #endif
4393  }
4394  }
4396 #endif
4397 
4398 #ifdef HAVE_PLURAL
4399  ring old_ring = r;
4400 #endif
4401  if (r->qideal!=NULL)
4402  {
4403  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
4404  assume(id_RankFreeModule(res->qideal, res) == 0);
4405 #ifdef HAVE_PLURAL
4406  if( rIsPluralRing(res) )
4407  {
4408  if( nc_SetupQuotient(res, r, true) )
4409  {
4410 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
4411  }
4412  assume(id_RankFreeModule(res->qideal, res) == 0);
4413  }
4414 #endif
4415  }
4416 
4417 #ifdef HAVE_PLURAL
4418  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
4419  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
4420  assume(rIsSCA(res) == rIsSCA(old_ring));
4421  assume(ncRingType(res) == ncRingType(old_ring));
4422 #endif
4423  }
4424  return res;
4425 }
4426 
4428 {
4429  int i;
4430  if (r->typ!=NULL)
4431  {
4432  for(i=r->OrdSize-1;i>=0;i--)
4433  {
4434  if ((r->typ[i].ord_typ==ro_dp)
4435  && (r->typ[i].data.dp.start==1)
4436  && (r->typ[i].data.dp.end==r->N))
4437  {
4438  return TRUE;
4439  }
4440  }
4441  }
4442  return FALSE;
4443 }
4444 
4445 ring rAssure_TDeg(ring r, int &pos)
4446 {
4447  int i;
4448  if (r->typ!=NULL)
4449  {
4450  for(i=r->OrdSize-1;i>=0;i--)
4451  {
4452  if ((r->typ[i].ord_typ==ro_dp)
4453  && (r->typ[i].data.dp.start==1)
4454  && (r->typ[i].data.dp.end==r->N))
4455  {
4456  pos=r->typ[i].data.dp.place;
4457  //printf("no change, pos=%d\n",pos);
4458  return r;
4459  }
4460  }
4461  }
4462 
4463 #ifdef HAVE_PLURAL
4464  nc_struct* save=r->GetNC();
4465  r->GetNC()=NULL;
4466 #endif
4467  ring res=rCopy(r);
4468  if (res->qideal!=NULL)
4469  {
4470  id_Delete(&res->qideal,r);
4471  }
4472 
4473  i=rBlocks(r);
4474  int j;
4475 
4476  res->ExpL_Size=r->ExpL_Size+1; // one word more in each monom
4477  res->PolyBin=omGetSpecBin(POLYSIZE + (res->ExpL_Size)*sizeof(long));
4478  omFree((ADDRESS)res->ordsgn);
4479  res->ordsgn=(long *)omAlloc0(res->ExpL_Size*sizeof(long));
4480  for(j=0;j<r->CmpL_Size;j++)
4481  {
4482  res->ordsgn[j] = r->ordsgn[j];
4483  }
4484  res->OrdSize=r->OrdSize+1; // one block more for pSetm
4485  if (r->typ!=NULL)
4486  omFree((ADDRESS)res->typ);
4487  res->typ=(sro_ord*)omAlloc0(res->OrdSize*sizeof(sro_ord));
4488  if (r->typ!=NULL)
4489  memcpy(res->typ,r->typ,r->OrdSize*sizeof(sro_ord));
4490  // the additional block for pSetm: total degree at the last word
4491  // but not included in the compare part
4492  res->typ[res->OrdSize-1].ord_typ=ro_dp;
4493  res->typ[res->OrdSize-1].data.dp.start=1;
4494  res->typ[res->OrdSize-1].data.dp.end=res->N;
4495  res->typ[res->OrdSize-1].data.dp.place=res->ExpL_Size-1;
4496  pos=res->ExpL_Size-1;
4497  //res->pOrdIndex=pos; //NO: think of a(1,0),dp !
4498  extern void p_Setm_General(poly p, ring r);
4499  res->p_Setm=p_Setm_General;
4500  // ----------------------------
4501  omFree((ADDRESS)res->p_Procs);
4502  res->p_Procs = (p_Procs_s*)omAlloc(sizeof(p_Procs_s));
4503 
4504  p_ProcsSet(res, res->p_Procs);
4505 #ifdef HAVE_PLURAL
4506  r->GetNC()=save;
4507  if (rIsPluralRing(r))
4508  {
4509  if ( nc_rComplete(r, res, false) ) // no qideal!
4510  {
4511 #ifndef SING_NDEBUG
4512  WarnS("error in nc_rComplete");
4513 #endif
4514  // just go on..
4515  }
4516  }
4517 #endif
4518  if (r->qideal!=NULL)
4519  {
4520  res->qideal=idrCopyR_NoSort(r->qideal,r, res);
4521 #ifdef HAVE_PLURAL
4522  if (rIsPluralRing(res))
4523  {
4524 // nc_SetupQuotient(res, currRing);
4525  nc_SetupQuotient(res, r); // ?
4526  }
4527  assume((res->qideal==NULL) == (r->qideal==NULL));
4528 #endif
4529  }
4530 
4531 #ifdef HAVE_PLURAL
4533  assume(rIsSCA(res) == rIsSCA(r));
4534  assume(ncRingType(res) == ncRingType(r));
4535 #endif
4536 
4537  return res;
4538 }
4539 
4540 ring rAssure_HasComp(const ring r)
4541 {
4542  int last_block;
4543  int i=0;
4544  do
4545  {
4546  if (r->order[i] == ringorder_c ||
4547  r->order[i] == ringorder_C) return r;
4548  if (r->order[i] == 0)
4549  break;
4550  i++;
4551  } while (1);
4552  //WarnS("re-creating ring with comps");
4553  last_block=i-1;
4554 
4555  ring new_r = rCopy0(r, FALSE, FALSE);
4556  i+=2;
4557  new_r->wvhdl=(int **)omAlloc0(i * sizeof(int *));
4558  new_r->order = (rRingOrder_t *) omAlloc0(i * sizeof(rRingOrder_t));
4559  new_r->block0 = (int *) omAlloc0(i * sizeof(int));
4560  new_r->block1 = (int *) omAlloc0(i * sizeof(int));
4561  memcpy(new_r->order,r->order,(i-1) * sizeof(rRingOrder_t));
4562  memcpy(new_r->block0,r->block0,(i-1) * sizeof(int));
4563  memcpy(new_r->block1,r->block1,(i-1) * sizeof(int));
4564  for (int j=0; j<=last_block; j++)
4565  {
4566  if (r->wvhdl[j]!=NULL)
4567  {
4568  new_r->wvhdl[j] = (int*) omMemDup(r->wvhdl[j]);
4569  }
4570  }
4571  last_block++;
4572  new_r->order[last_block]=ringorder_C;
4573  //new_r->block0[last_block]=0;
4574  //new_r->block1[last_block]=0;
4575  //new_r->wvhdl[last_block]=NULL;
4576 
4577  rComplete(new_r, 1);
4578 
4579 #ifdef HAVE_PLURAL
4580  if (rIsPluralRing(r))
4581  {
4582  if ( nc_rComplete(r, new_r, false) ) // no qideal!
4583  {
4584 #ifndef SING_NDEBUG
4585  WarnS("error in nc_rComplete"); // cleanup?// rDelete(res);// return r; // just go on..
4586 #endif
4587  }
4588  }
4589  assume(rIsPluralRing(r) == rIsPluralRing(new_r));
4590 #endif
4591 
4592  return new_r;
4593 }
4594 
4595 ring rAssure_CompLastBlock(ring r, BOOLEAN complete)
4596 {
4597  int last_block = rBlocks(r) - 2;
4598  if (r->order[last_block] != ringorder_c &&
4599  r->order[last_block] != ringorder_C)
4600  {
4601  int c_pos = 0;
4602  int i;
4603 
4604  for (i=0; i< last_block; i++)
4605  {
4606  if (r->order[i] == ringorder_c || r->order[i] == ringorder_C)
4607  {
4608  c_pos = i;
4609  break;
4610  }
4611  }
4612  if (c_pos != -1)
4613  {
4614  ring new_r = rCopy0(r, FALSE, TRUE);
4615  for (i=c_pos+1; i<=last_block; i++)
4616  {
4617  new_r->order[i-1] = new_r->order[i];
4618  new_r->block0[i-1] = new_r->block0[i];
4619  new_r->block1[i-1] = new_r->block1[i];
4620  new_r->wvhdl[i-1] = new_r->wvhdl[i];
4621  }
4622  new_r->order[last_block] = r->order[c_pos];
4623  new_r->block0[last_block] = r->block0[c_pos];
4624  new_r->block1[last_block] = r->block1[c_pos];
4625  new_r->wvhdl[last_block] = r->wvhdl[c_pos];
4626  if (complete)
4627  {
4628  rComplete(new_r, 1);
4629 
4630 #ifdef HAVE_PLURAL
4631  if (rIsPluralRing(r))
4632  {
4633  if ( nc_rComplete(r, new_r, false) ) // no qideal!
4634  {
4635 #ifndef SING_NDEBUG
4636  WarnS("error in nc_rComplete"); // cleanup?// rDelete(res);// return r; // just go on..
4637 #endif
4638  }
4639  }
4640  assume(rIsPluralRing(r) == rIsPluralRing(new_r));
4641 #endif
4642  }
4643  return new_r;
4644  }
4645  }
4646  return r;
4647 }
4648 
4649 // Moves _c or _C ordering to the last place AND adds _s on the 1st place
4651 {
4652  rTest(r);
4653 
4654  ring new_r_1 = rAssure_CompLastBlock(r, FALSE); // due to this FALSE - no completion!
4655  ring new_r = rAssure_SyzComp(new_r_1, FALSE); // new_r_1 is used only here!!!
4656 
4657  if (new_r == r)
4658  return r;
4659 
4660  ring old_r = r;
4661  if (new_r_1 != new_r && new_r_1 != old_r) rDelete(new_r_1);
4662 
4663  rComplete(new_r, TRUE);
4664 #ifdef HAVE_PLURAL
4665  if (rIsPluralRing(old_r))
4666  {
4667  if ( nc_rComplete(old_r, new_r, false) ) // no qideal!
4668  {
4669 # ifndef SING_NDEBUG
4670  WarnS("error in nc_rComplete"); // cleanup? rDelete(res); return r; // just go on...?
4671 # endif
4672  }
4673  }
4674 #endif
4675 
4676 ///? rChangeCurrRing(new_r);
4677  if (old_r->qideal != NULL)
4678  {
4679  new_r->qideal = idrCopyR(old_r->qideal, old_r, new_r);
4680  }
4681 
4682 #ifdef HAVE_PLURAL
4683  if( rIsPluralRing(old_r) )
4684  if( nc_SetupQuotient(new_r, old_r, true) )
4685  {
4686 #ifndef SING_NDEBUG
4687  WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
4688 #endif
4689  }
4690 #endif
4691 
4692 #ifdef HAVE_PLURAL
4693  assume((new_r->qideal==NULL) == (old_r->qideal==NULL));
4694  assume(rIsPluralRing(new_r) == rIsPluralRing(old_r));
4695  assume(rIsSCA(new_r) == rIsSCA(old_r));
4696  assume(ncRingType(new_r) == ncRingType(old_r));
4697 #endif
4698 
4699  rTest(new_r);
4700  rTest(old_r);
4701  return new_r;
4702 }
4703 
4704 // use this for global orderings consisting of two blocks
4705 static ring rAssure_Global(rRingOrder_t b1, rRingOrder_t b2, const ring r)
4706 {
4707  int r_blocks = rBlocks(r);
4708 
4709  assume(b1 == ringorder_c || b1 == ringorder_C ||
4710  b2 == ringorder_c || b2 == ringorder_C ||
4711  b2 == ringorder_S);
4712  if ((r_blocks == 3) &&
4713  (r->order[0] == b1) &&
4714  (r->order[1] == b2) &&
4715  (r->order[2] == 0))
4716  return r;
4717  ring res = rCopy0(r, FALSE, FALSE);
4718  res->order = (rRingOrder_t*)omAlloc0(3*sizeof(rRingOrder_t));
4719  res->block0 = (int*)omAlloc0(3*sizeof(int));
4720  res->block1 = (int*)omAlloc0(3*sizeof(int));
4721  res->wvhdl = (int**)omAlloc0(3*sizeof(int*));
4722  res->order[0] = b1;
4723  res->order[1] = b2;
4724  if (b1 == ringorder_c || b1 == ringorder_C)
4725  {
4726  res->block0[1] = 1;
4727  res->block1[1] = r->N;
4728  }
4729  else
4730  {
4731  res->block0[0] = 1;
4732  res->block1[0] = r->N;
4733  }
4734  rComplete(res, 1);
4735  if (r->qideal!=NULL) res->qideal= idrCopyR_NoSort(r->qideal, r, res);
4736 #ifdef HAVE_PLURAL
4737  if (rIsPluralRing(r))
4738  {
4739  if ( nc_rComplete(r, res, false) ) // no qideal!
4740  {
4741 #ifndef SING_NDEBUG
4742  WarnS("error in nc_rComplete");
4743 #endif
4744  }
4745  }
4746 #endif
4747 // rChangeCurrRing(res);
4748  return res;
4749 }
4750 
4751 ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete/* = TRUE*/, int sgn/* = 1*/)
4752 { // TODO: ???? Add leading Syz-comp ordering here...????
4753 
4754 #if MYTEST
4755  Print("rAssure_InducedSchreyerOrdering(r, complete = %d, sgn = %d): r: \n", complete, sgn);
4756  rWrite(r);
4757 #ifdef RDEBUG
4758  rDebugPrint(r);
4759 #endif
4760  PrintLn();
4761 #endif
4762  assume((sgn == 1) || (sgn == -1));
4763 
4764  ring res=rCopy0(r, FALSE, FALSE); // No qideal & ordering copy.
4765 
4766  int n = rBlocks(r); // Including trailing zero!
4767 
4768  // Create 2 more blocks for prefix/suffix:
4769  res->order=(rRingOrder_t *)omAlloc0((n+2)*sizeof(rRingOrder_t)); // 0 .. n+1
4770  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
4771  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
4772  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
4773 
4774  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
4775  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
4776 
4777  // new 1st block
4778  int j = 0;
4779  res->order[j] = ringorder_IS; // Prefix
4780  res->block0[j] = res->block1[j] = 0;
4781  // wvhdl[j] = NULL;
4782  j++;
4783 
4784  for(int i = 0; (i <= n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
4785  {
4786  res->order [j] = r->order [i];
4787  res->block0[j] = r->block0[i];
4788  res->block1[j] = r->block1[i];
4789 
4790  if (r->wvhdl[i] != NULL)
4791  {
4792  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
4793  } // else wvhdl[j] = NULL;
4794  }
4795 
4796  // new last block
4797  res->order [j] = ringorder_IS; // Suffix
4798  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
4799  // wvhdl[j] = NULL;
4800  j++;
4801 
4802  // res->order [j] = 0; // The End!
4803  res->wvhdl = wvhdl;
4804 
4805  // j == the last zero block now!
4806  assume(j == (n+1));
4807  assume(res->order[0]==ringorder_IS);
4808  assume(res->order[j-1]==ringorder_IS);
4809  assume(res->order[j]==0);
4810 
4811 
4812  if (complete)
4813  {
4814  rComplete(res, 1);
4815 
4816 #ifdef HAVE_PLURAL
4817  if (rIsPluralRing(r))
4818  {
4819  if ( nc_rComplete(r, res, false) ) // no qideal!
4820  {
4821 #ifndef SING_NDEBUG
4822  WarnS("error in nc_rComplete"); // cleanup?// rDelete(res);// return r; // just go on..
4823 #endif
4824  }
4825  }
4827 #endif
4828 
4829 
4830 #ifdef HAVE_PLURAL
4831  ring old_ring = r;
4832 #endif
4833 
4834  if (r->qideal!=NULL)
4835  {
4836  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
4837 
4838  assume(id_RankFreeModule(res->qideal, res) == 0);
4839 
4840 #ifdef HAVE_PLURAL
4841  if( rIsPluralRing(res) )
4842  if( nc_SetupQuotient(res, r, true) )
4843  {
4844 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
4845  }
4846 
4847 #endif
4848  assume(id_RankFreeModule(res->qideal, res) == 0);
4849  }
4850 
4851 #ifdef HAVE_PLURAL
4852  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
4853  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
4854  assume(rIsSCA(res) == rIsSCA(old_ring));
4855  assume(ncRingType(res) == ncRingType(old_ring));
4856 #endif
4857  }
4858 
4859  return res;
4860 }
4861 
4862 ring rAssure_dp_S(const ring r)
4863 {
4865 }
4866 
4867 ring rAssure_dp_C(const ring r)
4868 {
4870 }
4871 
4872 ring rAssure_C_dp(const ring r)
4873 {
4875 }
4876 
4877 ring rAssure_c_dp(const ring r)
4878 {
4880 }
4881 
4882 
4883 
4884 /// Finds p^th IS ordering, and returns its position in r->typ[]
4885 /// returns -1 if something went wrong!
4886 /// p - starts with 0!
4887 int rGetISPos(const int p, const ring r)
4888 {
4889  // Put the reference set F into the ring -ordering -recor
4890 #if MYTEST
4891  Print("rIsIS(p: %d)\nF:", p);
4892  PrintLn();
4893 #endif
4894 
4895  if (r->typ==NULL)
4896  {
4897 // dReportError("'rIsIS:' Error: wrong ring! (typ == NULL)");
4898  return -1;
4899  }
4900 
4901  int j = p; // Which IS record to use...
4902  for( int pos = 0; pos < r->OrdSize; pos++ )
4903  if( r->typ[pos].ord_typ == ro_is)
4904  if( j-- == 0 )
4905  return pos;
4906 
4907  return -1;
4908 }
4909 
4910 
4911 
4912 
4913 
4914 
4915 /// Changes r by setting induced ordering parameters: limit and reference leading terms
4916 /// F belong to r, we will DO a copy!
4917 /// We will use it AS IS!
4918 /// returns true is everything was allright!
4919 BOOLEAN rSetISReference(const ring r, const ideal F, const int i, const int p)
4920 {
4921  // Put the reference set F into the ring -ordering -recor
4922 
4923  if (r->typ==NULL)
4924  {
4925  dReportError("Error: WRONG USE of rSetISReference: wrong ring! (typ == NULL)");
4926  return FALSE;
4927  }
4928 
4929 
4930  int pos = rGetISPos(p, r);
4931 
4932  if( pos == -1 )
4933  {
4934  dReportError("Error: WRONG USE of rSetISReference: specified ordering block was not found!!!" );
4935  return FALSE;
4936  }
4937 
4938 #if MYTEST
4939  if( i != r->typ[pos].data.is.limit )
4940  Print("Changing record on pos: %d\nOld limit: %d --->> New Limit: %d\n", pos, r->typ[pos].data.is.limit, i);
4941 #endif
4942 
4943  const ideal FF = idrHeadR(F, r, r); // id_Copy(F, r); // ???
4944 
4945 
4946  if( r->typ[pos].data.is.F != NULL)
4947  {
4948 #if MYTEST
4949  PrintS("Deleting old reference set F... \n"); // idShow(r->typ[pos].data.is.F, r); PrintLn();
4950 #endif
4951  id_Delete(&r->typ[pos].data.is.F, r);
4952  r->typ[pos].data.is.F = NULL;
4953  }
4954 
4955  assume(r->typ[pos].data.is.F == NULL);
4956 
4957  r->typ[pos].data.is.F = FF; // F is owened by ring now! TODO: delete at the end!
4958 
4959  r->typ[pos].data.is.limit = i; // First induced component
4960 
4961 #if MYTEST
4962  PrintS("New reference set FF : \n"); idShow(FF, r, r, 1); PrintLn();
4963 #endif
4964 
4965  return TRUE;
4966 }
4967 
4968 #ifdef PDEBUG
4970 #endif
4971 
4972 
4973 void rSetSyzComp(int k, const ring r)
4974 {
4975  if(k < 0)
4976  {
4977  dReportError("rSetSyzComp with negative limit!");
4978  return;
4979  }
4980 
4981  assume( k >= 0 );
4982  if (TEST_OPT_PROT) Print("{%d}", k);
4983  if ((r->typ!=NULL) && (r->typ[0].ord_typ==ro_syz))
4984  {
4985  r->block0[0]=r->block1[0] = k;
4986  if( k == r->typ[0].data.syz.limit )
4987  return; // nothing to do
4988 
4989  int i;
4990  if (r->typ[0].data.syz.limit == 0)
4991  {
4992  r->typ[0].data.syz.syz_index = (int*) omAlloc0((k+1)*sizeof(int));
4993  r->typ[0].data.syz.syz_index[0] = 0;
4994  r->typ[0].data.syz.curr_index = 1;
4995  }
4996  else
4997  {
4998  r->typ[0].data.syz.syz_index = (int*)
4999  omReallocSize(r->typ[0].data.syz.syz_index,
5000  (r->typ[0].data.syz.limit+1)*sizeof(int),
5001  (k+1)*sizeof(int));
5002  }
5003  for (i=r->typ[0].data.syz.limit + 1; i<= k; i++)
5004  {
5005  r->typ[0].data.syz.syz_index[i] =
5006  r->typ[0].data.syz.curr_index;
5007  }
5008  if(k < r->typ[0].data.syz.limit) // ?
5009  {
5010 #ifndef SING_NDEBUG
5011  Warn("rSetSyzComp called with smaller limit (%d) as before (%d)", k, r->typ[0].data.syz.limit);
5012 #endif
5013  r->typ[0].data.syz.curr_index = 1 + r->typ[0].data.syz.syz_index[k];
5014  }
5015 
5016 
5017  r->typ[0].data.syz.limit = k;
5018  r->typ[0].data.syz.curr_index++;
5019  }
5020  else if(
5021  (r->typ!=NULL) &&
5022  (r->typ[0].ord_typ==ro_isTemp)
5023  )
5024  {
5025 // (r->typ[currRing->typ[0].data.isTemp.suffixpos].data.is.limit == k)
5026 #ifndef SING_NDEBUG
5027  Warn("rSetSyzComp(%d) in an IS ring! Be careful!", k);
5028 #endif
5029  }
5030  else if (r->order[0]==ringorder_s)
5031  {
5032  r->block0[0] = r->block1[0] = k;
5033  }
5034  else if (r->order[0]!=ringorder_c)
5035  {
5036  dReportError("syzcomp in incompatible ring");
5037  }
5038 #ifdef PDEBUG
5039  extern int pDBsyzComp;
5040  pDBsyzComp=k;
5041 #endif
5042 }
5043 
5044 // return the max-comonent wchich has syzIndex i
5045 int rGetMaxSyzComp(int i, const ring r)
5046 {
5047  if ((r->typ!=NULL) && (r->typ[0].ord_typ==ro_syz) &&
5048  r->typ[0].data.syz.limit > 0 && i > 0)
5049  {
5050  assume(i <= r->typ[0].data.syz.limit);
5051  int j;
5052  for (j=0; j<r->typ[0].data.syz.limit; j++)
5053  {
5054  if (r->typ[0].data.syz.syz_index[j] == i &&
5055  r->typ[0].data.syz.syz_index[j+1] != i)
5056  {
5057  assume(r->typ[0].data.syz.syz_index[j+1] == i+1);
5058  return j;
5059  }
5060  }
5061  return r->typ[0].data.syz.limit;
5062  }
5063  else
5064  {
5065  #ifndef SING_NDEBUG
5066  WarnS("rGetMaxSyzComp: order c");
5067  #endif
5068  return 0;
5069  }
5070 }
5071 
5073 {
5074  if (r == NULL) return FALSE;
5075  int i, j, nb = rBlocks(r);
5076  for (i=0; i<nb; i++)
5077  {
5078  if (r->wvhdl[i] != NULL)
5079  {
5080  int length = r->block1[i] - r->block0[i];
5081  int* wvhdl = r->wvhdl[i];
5082  if (r->order[i] == ringorder_M) length *= length;
5083  assume(omSizeOfAddr(wvhdl) >= length*sizeof(int));
5084 
5085  for (j=0; j< length; j++)
5086  {
5087  if (wvhdl[j] != 0 && wvhdl[j] != 1) return FALSE;
5088  }
5089  }
5090  }
5091  return TRUE;
5092 }
5093 
5095 {
5096  assume(r != NULL);
5097  int lb = rBlocks(r) - 2;
5098  return (r->order[lb] == ringorder_c || r->order[lb] == ringorder_C);
5099 }
5100 
5102 {
5103  return (r->cf->type);
5104  if (rField_is_Zp(r)) return n_Zp;
5105  if (rField_is_Q(r)) return n_Q;
5106  if (rField_is_R(r)) return n_R;
5107  if (rField_is_GF(r)) return n_GF;
5108  if (rField_is_long_R(r)) return n_long_R;
5109  if (rField_is_Zp_a(r)) return getCoeffType(r->cf);
5110  if (rField_is_Q_a(r)) return getCoeffType(r->cf);
5111  if (rField_is_long_C(r)) return n_long_C;
5112  if (rField_is_Ring_Z(r)) return n_Z;
5113  if (rField_is_Ring_ModN(r)) return n_Zn;
5114  if (rField_is_Ring_PtoM(r)) return n_Znm;
5115  if (rField_is_Ring_2toM(r)) return n_Z2m;
5116 
5117  return n_unknown;
5118 }
5119 
5120 int64 * rGetWeightVec(const ring r)
5121 {
5122  assume(r!=NULL);
5123  assume(r->OrdSize>0);
5124  int i=0;
5125  while((r->typ[i].ord_typ!=ro_wp64) && (r->typ[i].ord_typ>0)) i++;
5126  assume(r->typ[i].ord_typ==ro_wp64);
5127  return (int64*)(r->typ[i].data.wp64.weights64);
5128 }
5129 
5130 void rSetWeightVec(ring r, int64 *wv)
5131 {
5132  assume(r!=NULL);
5133  assume(r->OrdSize>0);
5134  assume(r->typ[0].ord_typ==ro_wp64);
5135  memcpy(r->typ[0].data.wp64.weights64,wv,r->N*sizeof(int64));
5136 }
5137 
5138 #include <ctype.h>
5139 
5140 static int rRealloc1(ring r, int size, int pos)
5141 {
5142  r->order=(rRingOrder_t*)omReallocSize(r->order, size*sizeof(rRingOrder_t), (size+1)*sizeof(rRingOrder_t));
5143  r->block0=(int*)omReallocSize(r->block0, size*sizeof(int), (size+1)*sizeof(int));
5144  r->block1=(int*)omReallocSize(r->block1, size*sizeof(int), (size+1)*sizeof(int));
5145  r->wvhdl=(int **)omReallocSize(r->wvhdl,size*sizeof(int *), (size+1)*sizeof(int *));
5146  for(int k=size; k>pos; k--) r->wvhdl[k]=r->wvhdl[k-1];
5147  r->order[size]=(rRingOrder_t)0;
5148  size++;
5149  return size;
5150 }
5151 #if 0 // currently unused
5152 static int rReallocM1(ring r, int size, int pos)
5153 {
5154  r->order=(int*)omReallocSize(r->order, size*sizeof(int), (size-1)*sizeof(int));
5155  r->block0=(int*)omReallocSize(r->block0, size*sizeof(int), (size-1)*sizeof(int));
5156  r->block1=(int*)omReallocSize(r->block1, size*sizeof(int), (size-1)*sizeof(int));
5157  r->wvhdl=(int **)omReallocSize(r->wvhdl,size*sizeof(int *), (size-1)*sizeof(int *));
5158  for(int k=pos+1; k<size; k++) r->wvhdl[k]=r->wvhdl[k+1];
5159  size--;
5160  return size;
5161 }
5162 #endif
5163 static void rOppWeight(int *w, int l)
5164 {
5165  int i2=(l+1)/2;
5166  for(int j=0; j<=i2; j++)
5167  {
5168  int t=w[j];
5169  w[j]=w[l-j];
5170  w[l-j]=t;
5171  }
5172 }
5173 
5174 #define rOppVar(R,I) (rVar(R)+1-I)
5176 ring rOpposite(ring src)
5177  /* creates an opposite algebra of R */
5178  /* that is R^opp, where f (*^opp) g = g*f */
5179  /* treats the case of qring */
5180 {
5181  if (src == NULL) return(NULL);
5182 
5183 #ifdef RDEBUG
5184  rTest(src);
5185 #endif
5186 
5187  //rChangeCurrRing(src);
5188 
5189 #ifdef RDEBUG
5190  rTest(src);
5191 // rWrite(src);
5192 // rDebugPrint(src);
5193 #endif
5194 
5195 
5196  ring r = rCopy0(src,FALSE); /* qideal will be deleted later on!!! */
5197 
5198  // change vars v1..vN -> vN..v1
5199  int i;
5200  int i2 = (rVar(r)-1)/2;
5201  for(i=i2; i>=0; i--)
5202  {
5203  // index: 0..N-1
5204  //Print("ex var names: %d <-> %d\n",i,rOppVar(r,i));
5205  // exchange names
5206  char *p;
5207  p = r->names[rVar(r)-1-i];
5208  r->names[rVar(r)-1-i] = r->names[i];
5209  r->names[i] = p;
5210  }
5211 // i2=(rVar(r)+1)/2;
5212 // for(int i=i2; i>0; i--)
5213 // {
5214 // // index: 1..N
5215 // //Print("ex var places: %d <-> %d\n",i,rVar(r)+1-i);
5216 // // exchange VarOffset
5217 // int t;
5218 // t=r->VarOffset[i];
5219 // r->VarOffset[i]=r->VarOffset[rOppVar(r,i)];
5220 // r->VarOffset[rOppVar(r,i)]=t;
5221 // }
5222  // change names:
5223  for (i=rVar(r)-1; i>=0; i--)
5224  {
5225  char *p=r->names[i];
5226  if(isupper(*p)) *p = tolower(*p);
5227  else *p = toupper(*p);
5228  }
5229  // change ordering: listing
5230  // change ordering: compare
5231 // for(i=0; i<r->OrdSize; i++)
5232 // {
5233 // int t,tt;
5234 // switch(r->typ[i].ord_typ)
5235 // {
5236 // case ro_dp:
5237 // //
5238 // t=r->typ[i].data.dp.start;
5239 // r->typ[i].data.dp.start=rOppVar(r,r->typ[i].data.dp.end);
5240 // r->typ[i].data.dp.end=rOppVar(r,t);
5241 // break;
5242 // case ro_wp:
5243 // case ro_wp_neg:
5244 // {
5245 // t=r->typ[i].data.wp.start;
5246 // r->typ[i].data.wp.start=rOppVar(r,r->typ[i].data.wp.end);
5247 // r->typ[i].data.wp.end=rOppVar(r,t);
5248 // // invert r->typ[i].data.wp.weights
5249 // rOppWeight(r->typ[i].data.wp.weights,
5250 // r->typ[i].data.wp.end-r->typ[i].data.wp.start);
5251 // break;
5252 // }
5253 // //case ro_wp64:
5254 // case ro_syzcomp:
5255 // case ro_syz:
5256 // WerrorS("not implemented in rOpposite");
5257 // // should not happen
5258 // break;
5259 //
5260 // case ro_cp:
5261 // t=r->typ[i].data.cp.start;
5262 // r->typ[i].data.cp.start=rOppVar(r,r->typ[i].data.cp.end);
5263 // r->typ[i].data.cp.end=rOppVar(r,t);
5264 // break;
5265 // case ro_none:
5266 // default:
5267 // Werror("unknown type in rOpposite(%d)",r->typ[i].ord_typ);
5268 // break;
5269 // }
5270 // }
5271  // Change order/block structures (needed for rPrint, rAdd etc.)
5272  int j=0;
5273  int l=rBlocks(src);
5274  for(i=0; src->order[i]!=0; i++)
5275  {
5276  switch (src->order[i])
5277  {
5278  case ringorder_c: /* c-> c */
5279  case ringorder_C: /* C-> C */
5280  case ringorder_no /*=0*/: /* end-of-block */
5281  r->order[j]=src->order[i];
5282  j++; break;
5283  case ringorder_lp: /* lp -> rp */
5284  r->order[j]=ringorder_rp;
5285  r->block0[j]=rOppVar(r, src->block1[i]);
5286  r->block1[j]=rOppVar(r, src->block0[i]);
5287  break;
5288  case ringorder_rp: /* rp -> lp */
5289  r->order[j]=ringorder_lp;
5290  r->block0[j]=rOppVar(r, src->block1[i]);
5291  r->block1[j]=rOppVar(r, src->block0[i]);
5292  break;
5293  case ringorder_dp: /* dp -> a(1..1),ls */
5294  {
5295  l=rRealloc1(r,l,j);
5296  r->order[j]=ringorder_a;
5297  r->block0[j]=rOppVar(r, src->block1[i]);
5298  r->block1[j]=rOppVar(r, src->block0[i]);
5299  r->wvhdl[j]=(int*)omAlloc((r->block1[j]-r->block0[j]+1)*sizeof(int));
5300  for(int k=r->block0[j]; k<=r->block1[j]; k++)
5301  r->wvhdl[j][k-r->block0[j]]=1;
5302  j++;
5303  r->order[j]=ringorder_ls;
5304  r->block0[j]=rOppVar(r, src->block1[i]);
5305  r->block1[j]=rOppVar(r, src->block0[i]);
5306  j++;
5307  break;
5308  }
5309  case ringorder_Dp: /* Dp -> a(1..1),rp */
5310  {
5311  l=rRealloc1(r,l,j);
5312  r->order[j]=ringorder_a;
5313  r->block0[j]=rOppVar(r, src->block1[i]);
5314  r->block1[j]=rOppVar(r, src->block0[i]);
5315  r->wvhdl[j]=(int*)omAlloc((r->block1[j]-r->block0[j]+1)*sizeof(int));
5316  for(int k=r->block0[j]; k<=r->block1[j]; k++)
5317  r->wvhdl[j][k-r->block0[j]]=1;
5318  j++;
5319  r->order[j]=ringorder_rp;
5320  r->block0[j]=rOppVar(r, src->block1[i]);
5321  r->block1[j]=rOppVar(r, src->block0[i]);
5322  j++;
5323  break;
5324  }
5325  case ringorder_wp: /* wp -> a(...),ls */
5326  {
5327  l=rRealloc1(r,l,j);
5328  r->order[j]=ringorder_a;
5329  r->block0[j]=rOppVar(r, src->block1[i]);
5330  r->block1[j]=rOppVar(r, src->block0[i]);
5331  r->wvhdl[j]=r->wvhdl[j+1]; r->wvhdl[j+1]=NULL;
5332  rOppWeight(r->wvhdl[j], r->block1[j]-r->block0[j]);
5333  j++;
5334  r->order[j]=ringorder_ls;
5335  r->block0[j]=rOppVar(r, src->block1[i]);
5336  r->block1[j]=rOppVar(r, src->block0[i]);
5337  j++;
5338  break;
5339  }
5340  case ringorder_Wp: /* Wp -> a(...),rp */
5341  {
5342  l=rRealloc1(r,l,j);
5343  r->order[j]=ringorder_a;
5344  r->block0[j]=rOppVar(r, src->block1[i]);
5345  r->block1[j]=rOppVar(r, src->block0[i]);
5346  r->wvhdl[j]=r->wvhdl[j+1]; r->wvhdl[j+1]=NULL;
5347  rOppWeight(r->wvhdl[j], r->block1[j]-r->block0[j]);
5348  j++;
5349  r->order[j]=ringorder_rp;
5350  r->block0[j]=rOppVar(r, src->block1[i]);
5351  r->block1[j]=rOppVar(r, src->block0[i]);
5352  j++;
5353  break;
5354  }
5355  case ringorder_M: /* M -> M */
5356  {
5357  r->order[j]=ringorder_M;
5358  r->block0[j]=rOppVar(r, src->block1[i]);
5359  r->block1[j]=rOppVar(r, src->block0[i]);
5360  int n=r->block1[j]-r->block0[j];
5361  /* M is a (n+1)x(n+1) matrix */
5362  for (int nn=0; nn<=n; nn++)
5363  {
5364  rOppWeight(&(r->wvhdl[j][nn*(n+1)]), n /*r->block1[j]-r->block0[j]*/);
5365  }
5366  j++;
5367  break;
5368  }
5369  case ringorder_a: /* a(...),ls -> wp/dp */
5370  {
5371  r->block0[j]=rOppVar(r, src->block1[i]);
5372  r->block1[j]=rOppVar(r, src->block0[i]);
5373  rOppWeight(r->wvhdl[j], r->block1[j]-r->block0[j]);
5374  if (src->order[i+1]==ringorder_ls)
5375  {
5376  r->order[j]=ringorder_wp;
5377  i++;
5378  //l=rReallocM1(r,l,j);
5379  }
5380  else
5381  {
5382  r->order[j]=ringorder_a;
5383  }
5384  j++;
5385  break;
5386  }
5387  // not yet done:
5388  case ringorder_ls:
5389  case ringorder_rs:
5390  case ringorder_ds:
5391  case ringorder_Ds:
5392  case ringorder_ws:
5393  case ringorder_Ws:
5394  case ringorder_am:
5395  case ringorder_a64:
5396  // should not occur:
5397  case ringorder_S:
5398  case ringorder_IS:
5399  case ringorder_s:
5400  case ringorder_aa:
5401  case ringorder_L:
5402  case ringorder_unspec:
5403  Werror("order %s not (yet) supported", rSimpleOrdStr(src->order[i]));
5404  break;
5405  }
5406  }
5407  rComplete(r);
5408 
5409 
5410 #ifdef RDEBUG
5411  rTest(r);
5412 #endif
5413 
5414  //rChangeCurrRing(r);
5415 
5416 #ifdef RDEBUG
5417  rTest(r);
5418 // rWrite(r);
5419 // rDebugPrint(r);
5420 #endif
5421 
5422 
5423 #ifdef HAVE_PLURAL
5424  // now, we initialize a non-comm structure on r
5425  if (rIsPluralRing(src))
5426  {
5427 // assume( currRing == r);
5428 
5429  int *perm = (int *)omAlloc0((rVar(r)+1)*sizeof(int));
5430  int *par_perm = NULL;
5431  nMapFunc nMap = n_SetMap(src->cf,r->cf);
5432  int ni,nj;
5433  for(i=1; i<=r->N; i++)
5434  {
5435  perm[i] = rOppVar(r,i);
5436  }
5437 
5438  matrix C = mpNew(rVar(r),rVar(r));
5439  matrix D = mpNew(rVar(r),rVar(r));
5440 
5441  for (i=1; i< rVar(r); i++)
5442  {
5443  for (j=i+1; j<=rVar(r); j++)
5444  {
5445  ni = r->N +1 - i;
5446  nj = r->N +1 - j; /* i<j ==> nj < ni */
5447 
5448  assume(MATELEM(src->GetNC()->C,i,j) != NULL);
5449  MATELEM(C,nj,ni) = p_PermPoly(MATELEM(src->GetNC()->C,i,j),perm,src,r, nMap,par_perm,rPar(src));
5450 
5451  if(MATELEM(src->GetNC()->D,i,j) != NULL)
5452  MATELEM(D,nj,ni) = p_PermPoly(MATELEM(src->GetNC()->D,i,j),perm,src,r, nMap,par_perm,rPar(src));
5453  }
5454  }
5455 
5456  id_Test((ideal)C, r);
5457  id_Test((ideal)D, r);
5458 
5459  if (nc_CallPlural(C, D, NULL, NULL, r, false, false, true, r)) // no qring setup!
5460  WarnS("Error initializing non-commutative multiplication!");
5461 
5462 #ifdef RDEBUG
5463  rTest(r);
5464 // rWrite(r);
5465 // rDebugPrint(r);
5466 #endif
5467 
5468  assume( r->GetNC()->IsSkewConstant == src->GetNC()->IsSkewConstant);
5469 
5470  omFreeSize((ADDRESS)perm,(rVar(r)+1)*sizeof(int));
5471  }
5472 #endif /* HAVE_PLURAL */
5473 
5474  /* now oppose the qideal for qrings */
5475  if (src->qideal != NULL)
5476  {
5477  id_Delete(&(r->qideal), r);
5478 
5479 #ifdef HAVE_PLURAL
5480  r->qideal = idOppose(src, src->qideal, r); // into the currRing: r
5481 #else
5482  r->qideal = id_Copy(src->qideal, r); // ?
5483 #endif
5484 
5485 #ifdef HAVE_PLURAL
5486  if( rIsPluralRing(r) )
5487  {
5488  nc_SetupQuotient(r);
5489 #ifdef RDEBUG
5490  rTest(r);
5491 // rWrite(r);
5492 // rDebugPrint(r);
5493 #endif
5494  }
5495 #endif
5496  }
5497 #ifdef HAVE_PLURAL
5498  if( rIsPluralRing(r) )
5499  assume( ncRingType(r) == ncRingType(src) );
5500 #endif
5501  rTest(r);
5502 
5503  return r;
5504 }
5505 
5506 ring rEnvelope(ring R)
5507  /* creates an enveloping algebra of R */
5508  /* that is R^e = R \tensor_K R^opp */
5509 {
5510  ring Ropp = rOpposite(R);
5511  ring Renv = NULL;
5512  int stat = rSum(R, Ropp, Renv); /* takes care of qideals */
5513  if ( stat <=0 )
5514  WarnS("Error in rEnvelope at rSum");
5515  rTest(Renv);
5516  return Renv;
5517 }
5518 
5519 #ifdef HAVE_PLURAL
5520 BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
5521 /* returns TRUE is there were errors */
5522 /* dest is actualy equals src with the different ordering */
5523 /* we map src->nc correctly to dest->src */
5524 /* to be executed after rComplete, before rChangeCurrRing */
5525 {
5526 // NOTE: Originally used only by idElimination to transfer NC structure to dest
5527 // ring created by dirty hack (without nc_CallPlural)
5528  rTest(src);
5529 
5530  assume(!rIsPluralRing(dest)); // destination must be a newly constructed commutative ring
5531 
5532  if (!rIsPluralRing(src))
5533  {
5534  return FALSE;
5535  }
5536 
5537  const int N = dest->N;
5538 
5539  assume(src->N == N);
5540 
5541 // ring save = currRing;
5542 
5543 // if (dest != save)
5544 // rChangeCurrRing(dest);
5545 
5546  const ring srcBase = src;
5547 
5548  assume( n_SetMap(srcBase->cf,dest->cf) == n_SetMap(dest->cf,dest->cf) ); // currRing is important here!
5549 
5550  matrix C = mpNew(N,N); // ring independent
5551  matrix D = mpNew(N,N);
5552 
5553  matrix C0 = src->GetNC()->C;
5554  matrix D0 = src->GetNC()->D;
5555 
5556  // map C and D into dest
5557  for (int i = 1; i < N; i++)
5558  {
5559  for (int j = i + 1; j <= N; j++)
5560  {
5561  const number n = n_Copy(p_GetCoeff(MATELEM(C0,i,j), srcBase), srcBase->cf); // src, mapping for coeffs into currRing = dest!
5562  const poly p = p_NSet(n, dest);
5563  MATELEM(C,i,j) = p;
5564  if (MATELEM(D0,i,j) != NULL)
5565  MATELEM(D,i,j) = prCopyR(MATELEM(D0,i,j), srcBase, dest); // ?
5566  }
5567  }
5568  /* One must test C and D _only_ in r->GetNC()->basering!!! not in r!!! */
5569 
5570  id_Test((ideal)C, dest);
5571  id_Test((ideal)D, dest);
5572 
5573  if (nc_CallPlural(C, D, NULL, NULL, dest, bSetupQuotient, false, true, dest)) // also takes care about quotient ideal
5574  {
5575  //WarnS("Error transferring non-commutative structure");
5576  // error message should be in the interpreter interface
5577 
5578  mp_Delete(&C, dest);
5579  mp_Delete(&D, dest);
5580 
5581 // if (currRing != save)
5582 // rChangeCurrRing(save);
5583 
5584  return TRUE;
5585  }
5586 
5587 // mp_Delete(&C, dest); // used by nc_CallPlural!
5588 // mp_Delete(&D, dest);
5589 
5590 // if (dest != save)
5591 // rChangeCurrRing(save);
5592 
5593  assume(rIsPluralRing(dest));
5594  return FALSE;
5595 }
5596 #endif
5597 
5598 void rModify_a_to_A(ring r)
5599 // to be called BEFORE rComplete:
5600 // changes every Block with a(...) to A(...)
5601 {
5602  int i=0;
5603  int j;
5604  while(r->order[i]!=0)
5605  {
5606  if (r->order[i]==ringorder_a)
5607  {
5608  r->order[i]=ringorder_a64;
5609  int *w=r->wvhdl[i];
5610  int64 *w64=(int64 *)omAlloc((r->block1[i]-r->block0[i]+1)*sizeof(int64));
5611  for(j=r->block1[i]-r->block0[i];j>=0;j--)
5612  w64[j]=(int64)w[j];
5613  r->wvhdl[i]=(int*)w64;
5614  omFreeSize(w,(r->block1[i]-r->block0[i]+1)*sizeof(int));
5615  }
5616  i++;
5617  }
5618 }
5619 
5620 
5621 poly rGetVar(const int varIndex, const ring r)
5622 {
5623  poly p = p_ISet(1, r);
5624  p_SetExp(p, varIndex, 1, r);
5625  p_Setm(p, r);
5626  return p;
5627 }
5628 
5629 
5630 /// TODO: rewrite somehow...
5631 int n_IsParam(const number m, const ring r)
5632 {
5633  assume(r != NULL);
5634  const coeffs C = r->cf;
5635  assume(C != NULL);
5636 
5638 
5639  const n_coeffType _filed_type = getCoeffType(C);
5640 
5641  if(( _filed_type == n_algExt )||( _filed_type == n_polyExt ))
5642  return naIsParam(m, C);
5643 
5644  if( _filed_type == n_transExt )
5645  return ntIsParam(m, C);
5646 
5647  Werror("n_IsParam: IsParam is not to be used for (coeff_type = %d)",getCoeffType(C));
5648 
5649  return 0;
5650 }
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
nc_struct
Definition: nc.h:76
BIT_SIZEOF_LONG
#define BIT_SIZEOF_LONG
Definition: auxiliary.h:78
ro_am
@ ro_am
Definition: ring.h:61
rAssure_SyzComp_CompLastBlock
ring rAssure_SyzComp_CompLastBlock(const ring r)
makes sure that c/C ordering is last ordering and SyzIndex is first
Definition: ring.cc:4650
FALSE
#define FALSE
Definition: auxiliary.h:94
id_SimpleAdd
ideal id_SimpleAdd(ideal h1, ideal h2, const ring R)
concat the lists h1 and h2 without zeros
Definition: simpleideals.cc:598
rRealloc1
static int rRealloc1(ring r, int size, int pos)
Definition: ring.cc:5140
dReportError
int dReportError(const char *fmt,...)
Definition: dError.cc:45
ip_sring::names
char ** names
Definition: ring.h:265
rRing_has_CompLastBlock
BOOLEAN rRing_has_CompLastBlock(ring r)
Definition: ring.cc:5094
omCheckAddrSize
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
pLDeg1
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:833
omalloc.h
n_Zn
@ n_Zn
only used if HAVE_RINGS is defined
Definition: coeffs.h:45
rField_is_long_R
static BOOLEAN rField_is_long_R(const ring r)
Definition: ring.h:534
rRing_is_Homog
BOOLEAN rRing_is_Homog(ring r)
Definition: ring.cc:5072
p_Procs.h
p_GetCoeff
#define p_GetCoeff(p, r)
Definition: monomials.h:57
rSetWeightVec
void rSetWeightVec(ring r, int64 *wv)
Definition: ring.cc:5130
p_GetComp
#define p_GetComp(p, r)
Definition: monomials.h:71
rCheckIV
BOOLEAN rCheckIV(const intvec *iv)
Definition: ring.cc:176
ringorder_Ds
@ ringorder_Ds
Definition: ring.h:92
ip_smatrix
Definition: matpol.h:15
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:107
rAssure_SyzComp
ring rAssure_SyzComp(const ring r, BOOLEAN complete)
Definition: ring.cc:4349
p_GetExp
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:469
j
int j
Definition: facHensel.cc:105
omcheckAddrSize
#define omcheckAddrSize(addr, size)
Definition: omAllocDecl.h:329
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
rO_Align
static void rO_Align(int &place, int &bitplace)
Definition: ring.cc:2094
omSizeOfAddr
size_t omSizeOfAddr(const void *addr)
Definition: omAllocSystem.c:100
TEST_OPT_PROT
#define TEST_OPT_PROT
Definition: options.h:102
pLDeg0c
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:762
k
int k
Definition: cfEzgcd.cc:92
p_Write0
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:194
idrCopyR_NoSort
ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:205
rOrd_is_MixedDegree_Ordering
BOOLEAN rOrd_is_MixedDegree_Ordering(ring r)
Definition: ring.cc:3329
rOrd_SetCompRequiresSetm
BOOLEAN rOrd_SetCompRequiresSetm(const ring r)
return TRUE if p_SetComp requires p_Setm
Definition: ring.cc:1862
rCanShortOut
static BOOLEAN rCanShortOut(const ring r)
Definition: ring.h:577
rO_LexVars
static void rO_LexVars(int &place, int &bitplace, int start, int end, int &prev_ord, long *o, int *v, int bits, int opt_var)
Definition: ring.cc:2239
x
Variable x
Definition: cfModGcd.cc:4023
rDebugPrint
void rDebugPrint(const ring r)
Definition: ring.cc:3998
MATELEM
#define MATELEM(mat, i, j)
Definition: matpol.h:30
pFDeg_CASE
#define pFDeg_CASE(A)
pLDeg0
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:731
rField_is_Ring_2toM
static BOOLEAN rField_is_Ring_2toM(const ring r)
Definition: ring.h:465
naIsParam
int naIsParam(number m, const coeffs cf)
if m == var(i)/1 => return i,
Definition: algext.cc:1095
omGetSpecBin
#define omGetSpecBin(size)
Definition: omBin.h:11
rOrderType_ExpComp
@ rOrderType_ExpComp
simple ordering, exponent vector has priority component not compatible with exp-vector order
Definition: ring.h:108
p_DebugPrint
void p_DebugPrint(poly p, const ring r)
Definition: ring.cc:4203
n_long_C
@ n_long_C
complex floating point (GMP) numbers
Definition: coeffs.h:42
pLDeg1_Totaldegree
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:967
ringorder_ds
@ ringorder_ds
Definition: ring.h:91
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
ringorder_ws
@ ringorder_ws
Definition: ring.h:93
rOrder_is_WeightedOrdering
BOOLEAN rOrder_is_WeightedOrdering(rRingOrder_t order)
Definition: ring.cc:1816
nCoeffString
static FORCE_INLINE char * nCoeffString(const coeffs cf)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar.
Definition: coeffs.h:973
ncRingType
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:167
rModify_a_to_A
void rModify_a_to_A(ring r)
Definition: ring.cc:5598
rO_ISPrefix
static void rO_ISPrefix(int &place, int &bitplace, int &prev_ord, long *o, int, int *v, sro_ord &ord_struct)
Definition: ring.cc:2356
rO_TDegree
static void rO_TDegree(int &place, int &bitplace, int start, int end, long *o, sro_ord &ord_struct)
Definition: ring.cc:2105
n_Z2m
@ n_Z2m
only used if HAVE_RINGS is defined
Definition: coeffs.h:47
ip_sring::cf
n_Procs_s * cf
Definition: ring.h:372
pISUpdateComponents
void pISUpdateComponents(ideal F, const intvec *const V, const int MIN, const ring r)
Definition: ring.cc:4240
rKillModifiedRing
void rKillModifiedRing(ring r)
Definition: ring.cc:2958
cf
CanonicalForm cf
Definition: cfModGcd.cc:4024
rAssure_Global
static ring rAssure_Global(rRingOrder_t b1, rRingOrder_t b2, const ring r)
Definition: ring.cc:4705
simpleideals.h
rSetNegWeight
static void rSetNegWeight(ring r)
Definition: ring.cc:3248
p_ProcsSet
void p_ProcsSet(ring r, p_Procs_s *p_Procs)
Definition: p_Procs_Set.h:138
MIN
#define MIN(a, b)
Definition: omDebug.c:102
length
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:267
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:263
sign
static int sign(int x)
Definition: ring.cc:3328
rO_TDegree_neg
static void rO_TDegree_neg(int &place, int &bitplace, int start, int end, long *o, sro_ord &ord_struct)
Definition: ring.cc:2119
pLDeg1c_Deg
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:933
n_GF
@ n_GF
\GF{p^n < 2^16}
Definition: coeffs.h:33
p_Test
#define p_Test(p, r)
Definition: p_polys.h:163
nc_rComplete
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5520
p_wrp
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:235
nInitChar
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:349
omAllocBin
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
n_Q
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:31
options.h
sqrt
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:328
rOrderType_General
@ rOrderType_General
non-simple ordering as specified by currRing
Definition: ring.h:106
auxiliary.h
rNGetSComps
static void rNGetSComps(int **currComponents, long **currShiftedComponents, ring r)
Definition: ring.cc:4289
ro_wp
@ ro_wp
Definition: ring.h:60
rOppWeight
static void rOppWeight(int *w, int l)
Definition: ring.cc:5163
omAlloc0Bin
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
pLDeg1c_WFirstTotalDegree
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1060
n_Znm
@ n_Znm
only used if HAVE_RINGS is defined
Definition: coeffs.h:46
N
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
rTest
#define rTest(r)
Definition: ring.h:777
rField_is_Zp_a
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:521
rUnComplete
void rUnComplete(ring r)
Definition: ring.cc:3846
ip_sring::wvhdl
int ** wvhdl
Definition: ring.h:264
rO_Syzcomp
static void rO_Syzcomp(int &place, int &bitplace, int &prev_ord, long *o, sro_ord &ord_struct)
Definition: ring.cc:2315
StringEndS
char * StringEndS()
Definition: reporter.cc:151
n_IsOne
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:469
p_Debug_GetSpecNames
void p_Debug_GetSpecNames(const ring r, const char *&field, const char *&length, const char *&ord)
Definition: p_Procs_Set.h:200
loop
#define loop
Definition: structs.h:78
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
b
CanonicalForm b
Definition: cfModGcd.cc:4044
iiWriteMatrix
void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
set spaces to zero by default
Definition: matpol.cc:734
nc_rCreateNCcomm_rCopy
ring nc_rCreateNCcomm_rCopy(ring r)
Definition: ring.cc:696
rSum
int rSum(ring r1, ring r2, ring &sum)
Definition: ring.cc:1306
rVarStr
char * rVarStr(ring r)
Definition: ring.cc:598
pLDegb
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:803
rSetISReference
BOOLEAN rSetISReference(const ring r, const ideal F, const int i, const int p)
Changes r by setting induced ordering parameters: limit and reference leading terms F belong to r,...
Definition: ring.cc:4919
n_long_R
@ n_long_R
real floating point (GMP) numbers
Definition: coeffs.h:34
found
bool found
Definition: facFactorize.cc:56
p_Setm_Dummy
void p_Setm_Dummy(poly p, const ring r)
Definition: p_polys.cc:533
rGetMaxSyzComp
int rGetMaxSyzComp(int i, const ring r)
return the max-comonent wchich has syzIndex i Assume: i<= syzIndex_limit
Definition: ring.cc:5045
p_SetExp
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
Definition: p_polys.h:488
int64vec::rows
int rows() const
Definition: int64vec.h:65
rSetVarL
static void rSetVarL(ring r)
set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex
Definition: ring.cc:3903
rGetSComps
void rGetSComps(int **currComponents, long **currShiftedComponents, int *length, ring r)
Definition: ring.cc:4328
ringorder_C
@ ringorder_C
Definition: ring.h:80
rCopy0
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1325
rIsPluralRing
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
rDefault
ring rDefault(const coeffs cf, int N, char **n, int ord_size, rRingOrder_t *ord, int *block0, int *block1, int **wvhdl, unsigned long bitmask)
Definition: ring.cc:103
n_coeffType
n_coeffType
Definition: coeffs.h:28
rAssure_c_dp
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4877
rEqual
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise,...
Definition: ring.cc:1620
rAssure_SyzOrder
ring rAssure_SyzOrder(const ring r, BOOLEAN complete)
Definition: ring.cc:4344
ringorder_Wp
@ ringorder_Wp
Definition: ring.h:89
ringorder_S
@ ringorder_S
S?
Definition: ring.h:82
r_IsRingVar
int r_IsRingVar(const char *n, char **names, int N)
Definition: ring.cc:213
sca_Force
bool sca_Force(ring rGR, int b, int e)
Definition: sca.cc:1161
for
for(int i=0;i<=n;i++) degsf[i]
Definition: cfEzgcd.cc:65
sro_ord::order_index
int order_index
Definition: ring.h:228
rOrderType_Exp
@ rOrderType_Exp
simple ordering, exponent vector has priority component is compatible with exp-vector order
Definition: ring.h:110
p_WFirstTotalDegree
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:588
n_CoeffWrite
static FORCE_INLINE void n_CoeffWrite(const coeffs r, BOOLEAN details=TRUE)
output the coeff description
Definition: coeffs.h:742
rModifyRing_Wp
ring rModifyRing_Wp(ring r, int *weights)
construct Wp, C ring
Definition: ring.cc:2845
rHasSimpleOrder
BOOLEAN rHasSimpleOrder(const ring r)
Definition: ring.cc:1756
char_ptr_bin
omBin char_ptr_bin
Definition: ring.cc:45
rOrderType_t
rOrderType_t
Definition: ring.h:105
rVar
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
n_polyExt
@ n_polyExt
used to represent polys as coeffcients
Definition: coeffs.h:35
rField_is_Ring_Z
static BOOLEAN rField_is_Ring_Z(const ring r)
Definition: ring.h:474
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
rFieldType
n_coeffType rFieldType(ring r)
Definition: ring.cc:5101
rChar
int rChar(ring r)
Definition: ring.cc:688
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition: simpleideals.cc:114
p_PermPoly
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition: p_polys.cc:4014
rModifyRing_Simple
ring rModifyRing_Simple(ring r, BOOLEAN ommit_degree, BOOLEAN ommit_comp, unsigned long exp_limit, BOOLEAN &simple)
Definition: ring.cc:2893
res
CanonicalForm res
Definition: facAbsFact.cc:64
sro_ord::data
union sro_ord::@0 data
rDBTest
BOOLEAN rDBTest(ring r, const char *fn, const int l)
Definition: ring.cc:1944
prCopy.h
id_RankFreeModule
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
Definition: simpleideals.cc:782
nMapFunc
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:74
ro_isTemp
@ ro_isTemp
Definition: ring.h:68
matpol.h
int64vec
Definition: int64vec.h:21
rField_is_Q_a
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:531
ringorder_Dp
@ ringorder_Dp
Definition: ring.h:87
rIsPolyVar
BOOLEAN rIsPolyVar(int v, const ring r)
returns TRUE if var(i) belongs to p-block
Definition: ring.cc:1905
Sy_bit
#define Sy_bit(x)
Definition: options.h:32
idShow
void idShow(const ideal id, const ring lmRing, const ring tailRing, const int debugPrint)
Definition: simpleideals.cc:59
idrHeadR
ideal idrHeadR(ideal id, ring r, ring dest_r)
Copy leading terms of id[i] via prHeeadR into dest_r.
Definition: prCopy.cc:156
PrintS
void PrintS(const char *s)
Definition: reporter.cc:284
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
p_SetGlobals
void p_SetGlobals(const ring r, BOOLEAN complete)
set all properties of a new ring - also called by rComplete
Definition: ring.cc:3316
rOptimizeLDeg
static void rOptimizeLDeg(ring r)
Definition: ring.cc:3051
rOrdStr
char * rOrdStr(ring r)
Definition: ring.cc:513
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
rAssure_dp_C
ring rAssure_dp_C(const ring r)
Definition: ring.cc:4867
rOrderType_CompExp
@ rOrderType_CompExp
simple ordering, component has priority
Definition: ring.h:107
nCoeff_is_algExt
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition: coeffs.h:924
pLDeg1_WFirstTotalDegree
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1030
rSetOutParams
static void rSetOutParams(ring r)
Definition: ring.cc:2979
omfreeSize
#define omfreeSize(addr, size)
Definition: omAllocDecl.h:236
TEST_OPT_OLDSTD
#define TEST_OPT_OLDSTD
Definition: options.h:121
ip_sring::bitmask
unsigned long bitmask
Definition: ring.h:356
rAssure_dp_S
ring rAssure_dp_S(const ring r)
Definition: ring.cc:4862
scaFirstAltVar
static short scaFirstAltVar(ring r)
Definition: sca.h:18
rField_is_Ring
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
rAssure_C_dp
ring rAssure_C_dp(const ring r)
Definition: ring.cc:4872
rSetDegStuff
static void rSetDegStuff(ring r)
Definition: ring.cc:3078
rOpposite
ring rOpposite(ring src)
Definition: ring.cc:5176
ip_sring::OrdSgn
short OrdSgn
Definition: ring.h:312
ringorder_M
@ ringorder_M
Definition: ring.h:81
omMemDup
#define omMemDup(s)
Definition: omAllocDecl.h:264
ro_cp
@ ro_cp
Definition: ring.h:65
D
#define D(A)
Definition: gentable.cc:129
rOppVar
#define rOppVar(R, I)
Definition: ring.cc:5174
sca.h
rOrd_is_WeightedDegree_Ordering
BOOLEAN rOrd_is_WeightedDegree_Ordering(const ring r)
Definition: ring.cc:1896
rAssure_TDeg
ring rAssure_TDeg(ring r, int &pos)
Definition: ring.cc:4445
ro_wp_neg
@ ro_wp_neg
Definition: ring.h:63
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
rString
char * rString(ring r)
Definition: ring.cc:648
coeffs
OPT_REDTAIL
#define OPT_REDTAIL
Definition: options.h:90
ip_sring
Definition: ring.h:255
nc_rCopy
bool nc_rCopy(ring res, const ring r, bool bSetupQuotient)
Definition: old.gring.cc:3028
rGetDivMask
static unsigned long rGetDivMask(int bits)
get r->divmask depending on bits per exponent
Definition: ring.cc:3984
p_Write
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:204
intvec
Definition: intvec.h:21
rField_is_Ring_PtoM
static BOOLEAN rField_is_Ring_PtoM(const ring r)
Definition: ring.h:471
ringorder_name
static const char *const ringorder_name[]
Definition: ring.cc:48
pLDeg1c_Totaldegree
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:997
n_Z
@ n_Z
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
pIter
#define pIter(p)
Definition: monomials.h:44
rCopy0AndAddA
ring rCopy0AndAddA(const ring r, int64vec *wv64, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1453
rRightAdjustVarOffset
static void rRightAdjustVarOffset(ring r)
right-adjust r->VarOffset
Definition: ring.cc:3958
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
p_polys.h
rPar
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
pLDeg1c
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:869
ro_wp64
@ ro_wp64
Definition: ring.h:62
rO_WDegree_neg
static void rO_WDegree_neg(int &place, int &bitplace, int start, int end, long *o, sro_ord &ord_struct, int *weights)
Definition: ring.cc:2213
rHasTDeg
BOOLEAN rHasTDeg(ring r)
Definition: ring.cc:4427
p_Procs_s
struct p_Procs_s p_Procs_s
Definition: ring.h:30
rField_is_R
static BOOLEAN rField_is_R(const ring r)
Definition: ring.h:510
rCheckOrdSgn
static void rCheckOrdSgn(ring r, int i)
Definition: ring.cc:3753
rHas_c_Ordering
BOOLEAN rHas_c_Ordering(const ring r)
Definition: ring.cc:1752
mp_Delete
void mp_Delete(matrix *a, const ring r)
Definition: matpol.cc:780
ip_sring::block1
int * block1
Definition: ring.h:262
ringorder_am
@ ringorder_am
Definition: ring.h:95
p_Setm_WFirstTotalDegree
void p_Setm_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:546
maps.h
rSetOption
static void rSetOption(ring r)
Definition: ring.cc:3285
rBlocks
static int rBlocks(ring r)
Definition: ring.h:559
m_DebugPrint
static void m_DebugPrint(const poly p, const ring R)
debug-print monomial poly/vector p, assuming that it lives in the ring R
Definition: ring.cc:4226
nc_rKill
void nc_rKill(ring r)
complete destructor
Definition: old.gring.cc:2474
nCoeff_is_Extension
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
Definition: coeffs.h:860
rGetOrderType
rOrderType_t rGetOrderType(ring r)
Definition: ring.cc:1709
rAssure_InducedSchreyerOrdering
ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sgn)
Definition: ring.cc:4751
n_IsParam
int n_IsParam(const number m, const ring r)
TODO: rewrite somehow...
Definition: ring.cc:5631
p_Debug_GetProcNames
void p_Debug_GetProcNames(const ring r, p_Procs_s *p_Procs)
Definition: p_Procs_Set.h:211
mpNew
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:36
rSumInternal
int rSumInternal(ring r1, ring r2, ring &sum, BOOLEAN vartest, BOOLEAN dp_dp)
returns -1 for not compatible, 1 for compatible (and sum) dp_dp:0: block ordering,...
Definition: ring.cc:726
ringorder_c
@ ringorder_c
Definition: ring.h:79
ringorder_lp
@ ringorder_lp
Definition: ring.h:84
OPT_INTSTRATEGY
#define OPT_INTSTRATEGY
Definition: options.h:91
rOrd_is_Totaldegree_Ordering
BOOLEAN rOrd_is_Totaldegree_Ordering(const ring r)
Definition: ring.cc:1882
n_transExt
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:39
ringorder_dp
@ ringorder_dp
Definition: ring.h:85
p_Setm_General
void p_Setm_General(poly p, const ring r)
Definition: p_polys.cc:154
ip_sring::block0
int * block0
Definition: ring.h:261
n_R
@ n_R
single prescision (6,6) real numbers
Definition: coeffs.h:32
UPMATELEM
#define UPMATELEM(i, j, nVar)
Definition: nc.h:36
rDelete
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:439
pDBsyzComp
int pDBsyzComp
Definition: ring.cc:4969
ntIsParam
int ntIsParam(number m, const coeffs cf)
if m == var(i)/1 => return i,
Definition: transext.cc:2193
sip_sring_bin
omBin sip_sring_bin
Definition: ring.cc:44
ring.h
p_Deg
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:579
omBin
omBin_t * omBin
Definition: omStructs.h:12
transext.h
rEnvelope
ring rEnvelope(ring R)
Definition: ring.cc:5506
p_Delete
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:857
rO_ISSuffix
static void rO_ISSuffix(int &place, int &bitplace, int &prev_ord, long *o, int N, int *v, sro_ord *tmp_typ, int &typ_i, int sgn)
Definition: ring.cc:2374
sro_ord
Definition: ring.h:226
min
static int min(int a, int b)
Definition: fast_mult.cc:268
rO_WDegree64
static void rO_WDegree64(int &place, int &bitplace, int start, int end, long *o, sro_ord &ord_struct, int64 *weights)
Definition: ring.cc:2195
p_One
poly p_One(const ring r)
Definition: p_polys.cc:1305
rField_is_GF
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:513
nc_CallPlural
BOOLEAN nc_CallPlural(matrix cc, matrix dd, poly cn, poly dn, ring r, bool bSetupQuotient, bool bCopyInput, bool bBeQuiet, ring curr, bool dummy_ring=false)
returns TRUE if there were errors analyze inputs, check them for consistency detects nc_type,...
Definition: old.gring.cc:2681
p_GetSetmProc
p_SetmProc p_GetSetmProc(const ring r)
Definition: p_polys.cc:552
nCopyCoeff
static FORCE_INLINE coeffs nCopyCoeff(const coeffs r)
"copy" coeffs, i.e. increment ref
Definition: coeffs.h:430
p_EqualPolys
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition: p_polys.cc:4396
rO_WMDegree
static void rO_WMDegree(int &place, int &bitplace, int start, int end, long *o, sro_ord &ord_struct, int *weights)
Definition: ring.cc:2173
nc.h
n_Zp
@ n_Zp
\F{p < 2^31}
Definition: coeffs.h:30
rWrite
void rWrite(ring r, BOOLEAN details)
Definition: ring.cc:227
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:128
si_max
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
sro_ord::ord_typ
ro_typ ord_typ
Definition: ring.h:227
rSetFirstWv
static void rSetFirstWv(ring r, int i, rRingOrder_t *order, int *block1, int **wvhdl)
Definition: ring.cc:3019
omUnGetSpecBin
#define omUnGetSpecBin(bin_ptr)
Definition: omBin.h:14
pLDeg1_Deg
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:902
ringorder_a
@ ringorder_a
Definition: ring.h:77
Print
#define Print
Definition: emacs.cc:80
mylimits.h
rDBGetSComps
static void rDBGetSComps(int **currComponents, long **currShiftedComponents, int *length, ring r)
Definition: ring.cc:4307
rSetSyzComp
void rSetSyzComp(int k, const ring r)
Definition: ring.cc:4973
p_NSet
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1435
ringorder_IS
@ ringorder_IS
Induced (Schreyer) ordering.
Definition: ring.h:100
rOrder_is_DegOrdering
BOOLEAN rOrder_is_DegOrdering(const rRingOrder_t order)
Definition: ring.cc:1797
Werror
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int64
long int64
Definition: auxiliary.h:66
scaLastAltVar
static short scaLastAltVar(ring r)
Definition: sca.h:25
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:37
rO_LexVars_neg
static void rO_LexVars_neg(int &place, int &bitplace, int start, int end, int &prev_ord, long *o, int *v, int bits, int opt_var)
Definition: ring.cc:2276
rSimpleOrdStr
const char * rSimpleOrdStr(int ord)
Definition: ring.cc:78
ringorder_ls
@ ringorder_ls
Definition: ring.h:90
ringorder_rp
@ ringorder_rp
Definition: ring.h:86
ip_sring::order
rRingOrder_t * order
Definition: ring.h:260
ro_syzcomp
@ ro_syzcomp
Definition: ring.h:66
n_Copy
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:452
rModifyRing
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2598
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
ringorder_s
@ ringorder_s
s?
Definition: ring.h:83
m
int m
Definition: cfEzgcd.cc:121
rCharStr
char * rCharStr(const ring r)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar.
Definition: ring.cc:622
rHasSimpleLexOrder
BOOLEAN rHasSimpleLexOrder(const ring r)
returns TRUE, if simple lp or ls ordering
Definition: ring.cc:1788
WarnS
#define WarnS
Definition: emacs.cc:78
assume
#define assume(x)
Definition: mod2.h:390
ringorder_L
@ ringorder_L
Definition: ring.h:96
OPT_REDTHROUGH
#define OPT_REDTHROUGH
Definition: options.h:81
NULL
#define NULL
Definition: omList.c:10
SCAQuotient
ideal SCAQuotient(const ring r)
Definition: sca.h:10
ringorder_Ws
@ ringorder_Ws
Definition: ring.h:94
ro_is
@ ro_is
Definition: ring.h:68
ringorder_no
@ ringorder_no
Definition: ring.h:76
maFindPerm
void maFindPerm(char const *const *const preim_names, int preim_n, char const *const *const preim_par, int preim_p, char const *const *const names, int n, char const *const *const par, int nop, int *perm, int *par_perm, n_coeffType ch)
Definition: maps.cc:165
p_SetComp
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:247
l
int l
Definition: cfEzgcd.cc:93
rAssure_CompLastBlock
ring rAssure_CompLastBlock(ring r, BOOLEAN complete)
makes sure that c/C ordering is last ordering
Definition: ring.cc:4595
p_WTotaldegree
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:605
R
#define R
Definition: sirandom.c:26
idOppose
ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst)
opposes a module I from Rop to currRing(dst)
Definition: old.gring.cc:3406
p_Setm
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
rAssure_HasComp
ring rAssure_HasComp(const ring r)
Definition: ring.cc:4540
Warn
#define Warn
Definition: emacs.cc:77
StringAppend
#define StringAppend
Definition: emacs.cc:79
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
ringorder_wp
@ ringorder_wp
Definition: ring.h:88
rSamePolyRep
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition: ring.cc:1668
omCheckAddr
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
p_Totaldegree
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1453
p
int p
Definition: cfModGcd.cc:4019
rChangeSComps
void rChangeSComps(int *currComponents, long *currShiftedComponents, int length, ring r)
Definition: ring.cc:4319
rGetWeightVec
int64 * rGetWeightVec(const ring r)
Definition: ring.cc:5120
ringorder_unspec
@ ringorder_unspec
Definition: ring.h:101
ringorder_aa
@ ringorder_aa
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition: ring.h:98
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
rTypeOfMatrixOrder
int rTypeOfMatrixOrder(const intvec *order)
Definition: ring.cc:186
qr
Definition: qr.h:46
BITS_PER_LONG
#define BITS_PER_LONG
Definition: ring.cc:42
rParStr
char * rParStr(ring r)
Definition: ring.cc:624
nc_SetupQuotient
bool nc_SetupQuotient(ring rGR, const ring rG=NULL, bool bCopy=false)
Definition: old.gring.cc:3428
rO_WDegree
static void rO_WDegree(int &place, int &bitplace, int start, int end, long *o, sro_ord &ord_struct, int *weights)
Definition: ring.cc:2133
n_SetMap
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:722
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:26
rHasSimpleOrderAA
BOOLEAN rHasSimpleOrderAA(ring r)
Definition: ring.cc:1831
p_ISet
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1289
p_Setm_TotalDegree
void p_Setm_TotalDegree(poly p, const ring r)
Definition: p_polys.cc:539
Q
#define Q
Definition: sirandom.c:25
id_Copy
ideal id_Copy(ideal h1, const ring r)
copy an ideal
Definition: simpleideals.cc:404
ringorder_rs
@ ringorder_rs
opposite of ls
Definition: ring.h:99
ringorder_a64
@ ringorder_a64
for int64 weights
Definition: ring.h:78
TEST_RINGDEP_OPTS
#define TEST_RINGDEP_OPTS
Definition: options.h:99
rCopy
ring rCopy(ring r)
Definition: ring.cc:1605
PrintLn
void PrintLn()
Definition: reporter.cc:310
rParameter
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:616
rField_is_Ring_ModN
static BOOLEAN rField_is_Ring_ModN(const ring r)
Definition: ring.h:468
rIsSCA
static bool rIsSCA(const ring r)
Definition: nc.h:198
rField_is_long_C
static BOOLEAN rField_is_long_C(const ring r)
Definition: ring.h:537
intvec::length
int length() const
Definition: intvec.h:94
ro_syz
@ ro_syz
Definition: ring.h:67
id_Test
#define id_Test(A, lR)
Definition: simpleideals.h:80
omFreeBin
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
rField_is_Zp
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:495
rShortOut
static BOOLEAN rShortOut(const ring r)
Definition: ring.h:572
n_unknown
@ n_unknown
Definition: coeffs.h:29
p_FDeg
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:380
algext.h
rOrderName
rRingOrder_t rOrderName(char *ordername)
Definition: ring.cc:499
A
#define A
Definition: sirandom.c:23
rRingOrder_t
rRingOrder_t
order stuff
Definition: ring.h:75
numbers.h
int64vec.h
rDBChangeSComps
static void rDBChangeSComps(int *currComponents, long *currShiftedComponents, int length, ring r)
Definition: ring.cc:4297
POLYSIZE
#define POLYSIZE
Definition: monomials.h:240
rNChangeSComps
static void rNChangeSComps(int *currComponents, long *currShiftedComponents, ring r)
Definition: ring.cc:4281
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:211
rO_Syz
static void rO_Syz(int &place, int &bitplace, int &prev_ord, int syz_comp, long *o, sro_ord &ord_struct)
Definition: ring.cc:2330
prCopyR
poly prCopyR(poly p, ring src_r, ring dest_r)
Definition: prCopy.cc:35
currShiftedComponents
long * currShiftedComponents
Definition: syz1.cc:35
if
if(yy_init)
Definition: libparse.cc:1418
ip_sring::N
short N
Definition: ring.h:310
rGetISPos
int rGetISPos(const int p, const ring r)
Finds p^th IS ordering, and returns its position in r->typ[] returns -1 if something went wrong!...
Definition: ring.cc:4887
ro_dp
@ ro_dp
Definition: ring.h:59
MAX_INT_VAL
const int MAX_INT_VAL
Definition: mylimits.h:12
nKillChar
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:510
idrCopyR
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:192
rKillModified_Wp_Ring
void rKillModified_Wp_Ring(ring r)
Definition: ring.cc:2968
sgn
int sgn(const Rational &a)
Definition: GMPrat.cc:433
rGetExpSize
static unsigned long rGetExpSize(unsigned long bitmask, int &bits)
Definition: ring.cc:2465
n_algExt
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:36
coeffs.h
rField_is_Q
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:501
rComplete
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...
Definition: ring.cc:3351
omReallocSize
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
rGetVar
poly rGetVar(const int varIndex, const ring r)
Definition: ring.cc:5621
si_opt_1
unsigned si_opt_1
Definition: options.c:5