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