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