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