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