1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: ring.cc,v 1.166 2001-07-17 09:42:26 Singular Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT - the interpreter related ring operations |
---|
8 | */ |
---|
9 | |
---|
10 | /* includes */ |
---|
11 | #include <math.h> |
---|
12 | #include "mod2.h" |
---|
13 | #include "structs.h" |
---|
14 | #include "omalloc.h" |
---|
15 | #include "tok.h" |
---|
16 | #include "ipid.h" |
---|
17 | #include "polys.h" |
---|
18 | #include "numbers.h" |
---|
19 | #include "febase.h" |
---|
20 | #include "ipshell.h" |
---|
21 | #include "ipconv.h" |
---|
22 | #include "intvec.h" |
---|
23 | #include "longalg.h" |
---|
24 | #include "ffields.h" |
---|
25 | #include "subexpr.h" |
---|
26 | #include "ideals.h" |
---|
27 | #include "lists.h" |
---|
28 | #include "ring.h" |
---|
29 | #include "prCopy.h" |
---|
30 | #include "p_Procs.h" |
---|
31 | |
---|
32 | #define BITS_PER_LONG 8*SIZEOF_LONG |
---|
33 | |
---|
34 | static const char * const ringorder_name[] = |
---|
35 | { |
---|
36 | " ?", //ringorder_no = 0, |
---|
37 | "a", //ringorder_a, |
---|
38 | "c", //ringorder_c, |
---|
39 | "C", //ringorder_C, |
---|
40 | "M", //ringorder_M, |
---|
41 | "S", //ringorder_S, |
---|
42 | "s", //ringorder_s, |
---|
43 | "lp", //ringorder_lp, |
---|
44 | "dp", //ringorder_dp, |
---|
45 | "rp", //ringorder_rp, |
---|
46 | "Dp", //ringorder_Dp, |
---|
47 | "wp", //ringorder_wp, |
---|
48 | "Wp", //ringorder_Wp, |
---|
49 | "ls", //ringorder_ls, |
---|
50 | "ds", //ringorder_ds, |
---|
51 | "Ds", //ringorder_Ds, |
---|
52 | "ws", //ringorder_ws, |
---|
53 | "Ws", //ringorder_Ws, |
---|
54 | "L", //ringorder_L, |
---|
55 | "aa", //ringorder_aa |
---|
56 | " _" //ringorder_unspec |
---|
57 | }; |
---|
58 | |
---|
59 | static inline const char * rSimpleOrdStr(int ord) |
---|
60 | { |
---|
61 | return ringorder_name[ord]; |
---|
62 | } |
---|
63 | |
---|
64 | // unconditionally deletes fields in r |
---|
65 | static void rDelete(ring r); |
---|
66 | // set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex |
---|
67 | static void rSetVarL(ring r); |
---|
68 | // get r->divmask depending on bits per exponent |
---|
69 | static unsigned long rGetDivMask(int bits); |
---|
70 | // right-adjust r->VarOffset |
---|
71 | static void rRightAdjustVarOffset(ring r); |
---|
72 | static void rOptimizeLDeg(ring r); |
---|
73 | |
---|
74 | /*0 implementation*/ |
---|
75 | //BOOLEAN rField_is_R(ring r=currRing) |
---|
76 | //{ |
---|
77 | // if (r->ch== -1) |
---|
78 | // { |
---|
79 | // if (r->float_len==(short)0) return TRUE; |
---|
80 | // } |
---|
81 | // return FALSE; |
---|
82 | //} |
---|
83 | |
---|
84 | // internally changes the gloabl ring and resets the relevant |
---|
85 | // global variables: |
---|
86 | // complete == FALSE : only delete operations are enabled |
---|
87 | // complete == TRUE : full reset of all variables |
---|
88 | void rChangeCurrRing(ring r) |
---|
89 | { |
---|
90 | /*------------ set global ring vars --------------------------------*/ |
---|
91 | currRing = r; |
---|
92 | currQuotient=NULL; |
---|
93 | if (r != NULL) |
---|
94 | { |
---|
95 | rTest(r); |
---|
96 | /*------------ set global ring vars --------------------------------*/ |
---|
97 | currQuotient=r->qideal; |
---|
98 | |
---|
99 | /*------------ global variables related to coefficients ------------*/ |
---|
100 | nSetChar(r); |
---|
101 | |
---|
102 | /*------------ global variables related to polys -------------------*/ |
---|
103 | pSetGlobals(r); |
---|
104 | |
---|
105 | /*------------ set naMinimalPoly -----------------------------------*/ |
---|
106 | if (r->minpoly!=NULL) |
---|
107 | { |
---|
108 | naMinimalPoly=((lnumber)r->minpoly)->z; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | void rSetHdl(idhdl h) |
---|
114 | { |
---|
115 | int i; |
---|
116 | ring rg = NULL; |
---|
117 | if (h!=NULL) |
---|
118 | { |
---|
119 | rg = IDRING(h); |
---|
120 | omCheckAddrSize((ADDRESS)h,sizeof(idrec)); |
---|
121 | if (IDID(h)) // OB: ???? |
---|
122 | omCheckAddr((ADDRESS)IDID(h)); |
---|
123 | rTest(rg); |
---|
124 | } |
---|
125 | |
---|
126 | // clean up history |
---|
127 | if (sLastPrinted.RingDependend()) |
---|
128 | { |
---|
129 | sLastPrinted.CleanUp(); |
---|
130 | } |
---|
131 | |
---|
132 | /*------------ change the global ring -----------------------*/ |
---|
133 | rChangeCurrRing(rg); |
---|
134 | currRingHdl = h; |
---|
135 | } |
---|
136 | |
---|
137 | idhdl rDefault(char *s) |
---|
138 | { |
---|
139 | idhdl tmp=NULL; |
---|
140 | |
---|
141 | if (s!=NULL) tmp = enterid(s, myynest, RING_CMD, &IDROOT); |
---|
142 | if (tmp==NULL) return NULL; |
---|
143 | |
---|
144 | if (ppNoether!=NULL) pDelete(&ppNoether); |
---|
145 | if (sLastPrinted.RingDependend()) |
---|
146 | { |
---|
147 | sLastPrinted.CleanUp(); |
---|
148 | } |
---|
149 | |
---|
150 | ring r = IDRING(tmp); |
---|
151 | |
---|
152 | r->ch = 32003; |
---|
153 | r->N = 3; |
---|
154 | /*r->P = 0; Alloc0 in idhdl::set, ipid.cc*/ |
---|
155 | /*names*/ |
---|
156 | r->names = (char **) omAlloc0(3 * sizeof(char_ptr)); |
---|
157 | r->names[0] = omStrDup("x"); |
---|
158 | r->names[1] = omStrDup("y"); |
---|
159 | r->names[2] = omStrDup("z"); |
---|
160 | /*weights: entries for 3 blocks: NULL*/ |
---|
161 | r->wvhdl = (int **)omAlloc0(3 * sizeof(int_ptr)); |
---|
162 | /*order: dp,C,0*/ |
---|
163 | r->order = (int *) omAlloc(3 * sizeof(int *)); |
---|
164 | r->block0 = (int *)omAlloc0(3 * sizeof(int *)); |
---|
165 | r->block1 = (int *)omAlloc0(3 * sizeof(int *)); |
---|
166 | /* ringorder dp for the first block: var 1..3 */ |
---|
167 | r->order[0] = ringorder_dp; |
---|
168 | r->block0[0] = 1; |
---|
169 | r->block1[0] = 3; |
---|
170 | /* ringorder C for the second block: no vars */ |
---|
171 | r->order[1] = ringorder_C; |
---|
172 | /* the last block: everything is 0 */ |
---|
173 | r->order[2] = 0; |
---|
174 | /*polynomial ring*/ |
---|
175 | r->OrdSgn = 1; |
---|
176 | |
---|
177 | /* complete ring intializations */ |
---|
178 | rComplete(r); |
---|
179 | rSetHdl(tmp); |
---|
180 | return currRingHdl; |
---|
181 | } |
---|
182 | |
---|
183 | ring rDefault(int ch, int N, char **n) |
---|
184 | { |
---|
185 | ring r=(ring) omAlloc0Bin(sip_sring_bin); |
---|
186 | r->ch = ch; |
---|
187 | r->N = N; |
---|
188 | /*r->P = 0; Alloc0 */ |
---|
189 | /*names*/ |
---|
190 | r->names = (char **) omAlloc0(N * sizeof(char_ptr)); |
---|
191 | int i; |
---|
192 | for(i=0;i<N;i++) |
---|
193 | { |
---|
194 | r->names[i] = omStrDup(n[i]); |
---|
195 | } |
---|
196 | /*weights: entries for 2 blocks: NULL*/ |
---|
197 | r->wvhdl = (int **)omAlloc0(2 * sizeof(int_ptr)); |
---|
198 | /*order: lp,0*/ |
---|
199 | r->order = (int *) omAlloc(2* sizeof(int *)); |
---|
200 | r->block0 = (int *)omAlloc0(2 * sizeof(int *)); |
---|
201 | r->block1 = (int *)omAlloc0(2 * sizeof(int *)); |
---|
202 | /* ringorder dp for the first block: var 1..N */ |
---|
203 | r->order[0] = ringorder_lp; |
---|
204 | r->block0[0] = 1; |
---|
205 | r->block1[0] = N; |
---|
206 | /* the last block: everything is 0 */ |
---|
207 | r->order[1] = 0; |
---|
208 | /*polynomial ring*/ |
---|
209 | r->OrdSgn = 1; |
---|
210 | |
---|
211 | /* complete ring intializations */ |
---|
212 | rComplete(r); |
---|
213 | return r; |
---|
214 | } |
---|
215 | |
---|
216 | /////////////////////////////////////////////////////////////////////////// |
---|
217 | // |
---|
218 | // rInit: define a new ring from sleftv's |
---|
219 | // |
---|
220 | |
---|
221 | ///////////////////////////// |
---|
222 | // Auxillary functions |
---|
223 | // |
---|
224 | |
---|
225 | // check intvec, describing the ordering |
---|
226 | static BOOLEAN rCheckIV(intvec *iv) |
---|
227 | { |
---|
228 | if ((iv->length()!=2)&&(iv->length()!=3)) |
---|
229 | { |
---|
230 | WerrorS("weights only for orderings wp,ws,Wp,Ws,a,M"); |
---|
231 | return TRUE; |
---|
232 | } |
---|
233 | return FALSE; |
---|
234 | } |
---|
235 | |
---|
236 | static int rTypeOfMatrixOrder(intvec * order) |
---|
237 | { |
---|
238 | int i=0,j,typ=1; |
---|
239 | int sz = (int)sqrt((double)(order->length()-2)); |
---|
240 | |
---|
241 | while ((i<sz) && (typ==1)) |
---|
242 | { |
---|
243 | j=0; |
---|
244 | while ((j<sz) && ((*order)[j*sz+i+2]==0)) j++; |
---|
245 | if (j>=sz) |
---|
246 | { |
---|
247 | typ = 0; |
---|
248 | WerrorS("Matrix order not complete"); |
---|
249 | } |
---|
250 | else if ((*order)[j*sz+i+2]<0) |
---|
251 | typ = -1; |
---|
252 | else |
---|
253 | i++; |
---|
254 | } |
---|
255 | return typ; |
---|
256 | } |
---|
257 | |
---|
258 | // set R->order, R->block, R->wvhdl, r->OrdSgn from sleftv |
---|
259 | static BOOLEAN rSleftvOrdering2Ordering(sleftv *ord, ring R) |
---|
260 | { |
---|
261 | int last = 0, o=0, n = 1, i=0, typ = 1, j; |
---|
262 | sleftv *sl = ord; |
---|
263 | |
---|
264 | // determine nBlocks |
---|
265 | while (sl!=NULL) |
---|
266 | { |
---|
267 | intvec *iv = (intvec *)(sl->data); |
---|
268 | if (((*iv)[1]==ringorder_c)||((*iv)[1]==ringorder_C)) i++; |
---|
269 | else if ((*iv)[1]==ringorder_L) |
---|
270 | { |
---|
271 | R->bitmask=(*iv)[2]; |
---|
272 | n--; |
---|
273 | } |
---|
274 | else if ((*iv)[1]!=ringorder_a) o++; |
---|
275 | n++; |
---|
276 | sl=sl->next; |
---|
277 | } |
---|
278 | // check whether at least one real ordering |
---|
279 | if (o==0) |
---|
280 | { |
---|
281 | WerrorS("invalid combination of orderings"); |
---|
282 | return TRUE; |
---|
283 | } |
---|
284 | // if no c/C ordering is given, increment n |
---|
285 | if (i==0) n++; |
---|
286 | else if (i != 1) |
---|
287 | { |
---|
288 | // throw error if more than one is given |
---|
289 | WerrorS("more than one ordering c/C specified"); |
---|
290 | return TRUE; |
---|
291 | } |
---|
292 | |
---|
293 | // initialize fields of R |
---|
294 | R->order=(int *)omAlloc0(n*sizeof(int)); |
---|
295 | R->block0=(int *)omAlloc0(n*sizeof(int)); |
---|
296 | R->block1=(int *)omAlloc0(n*sizeof(int)); |
---|
297 | R->wvhdl=(int**)omAlloc0(n*sizeof(int_ptr)); |
---|
298 | |
---|
299 | // init order, so that rBlocks works correctly |
---|
300 | for (j=0; j < n-1; j++) |
---|
301 | R->order[j] = (int) ringorder_unspec; |
---|
302 | // set last _C order, if no c/C order was given |
---|
303 | if (i == 0) R->order[n-2] = ringorder_C; |
---|
304 | |
---|
305 | /* init orders */ |
---|
306 | sl=ord; |
---|
307 | n=-1; |
---|
308 | while (sl!=NULL) |
---|
309 | { |
---|
310 | intvec *iv; |
---|
311 | iv = (intvec *)(sl->data); |
---|
312 | if ((*iv)[1]!=ringorder_L) |
---|
313 | { |
---|
314 | n++; |
---|
315 | |
---|
316 | /* the format of an ordering: |
---|
317 | * iv[0]: factor |
---|
318 | * iv[1]: ordering |
---|
319 | * iv[2..end]: weights |
---|
320 | */ |
---|
321 | R->order[n] = (*iv)[1]; |
---|
322 | switch ((*iv)[1]) |
---|
323 | { |
---|
324 | case ringorder_ws: |
---|
325 | case ringorder_Ws: |
---|
326 | typ=-1; |
---|
327 | case ringorder_wp: |
---|
328 | case ringorder_Wp: |
---|
329 | R->wvhdl[n]=(int*)omAlloc((iv->length()-1)*sizeof(int)); |
---|
330 | for (i=2; i<iv->length(); i++) |
---|
331 | R->wvhdl[n][i-2] = (*iv)[i]; |
---|
332 | R->block0[n] = last+1; |
---|
333 | last += iv->length()-2; |
---|
334 | R->block1[n] = last; |
---|
335 | break; |
---|
336 | case ringorder_ls: |
---|
337 | case ringorder_ds: |
---|
338 | case ringorder_Ds: |
---|
339 | typ=-1; |
---|
340 | case ringorder_lp: |
---|
341 | case ringorder_dp: |
---|
342 | case ringorder_Dp: |
---|
343 | case ringorder_rp: |
---|
344 | R->block0[n] = last+1; |
---|
345 | if (iv->length() == 3) last+=(*iv)[2]; |
---|
346 | else last += (*iv)[0]; |
---|
347 | R->block1[n] = last; |
---|
348 | if (rCheckIV(iv)) return TRUE; |
---|
349 | break; |
---|
350 | case ringorder_S: |
---|
351 | case ringorder_c: |
---|
352 | case ringorder_C: |
---|
353 | if (rCheckIV(iv)) return TRUE; |
---|
354 | break; |
---|
355 | case ringorder_aa: |
---|
356 | case ringorder_a: |
---|
357 | R->block0[n] = last+1; |
---|
358 | R->block1[n] = min(last+iv->length()-2 , R->N); |
---|
359 | R->wvhdl[n] = (int*)omAlloc((iv->length()-1)*sizeof(int)); |
---|
360 | for (i=2; i<iv->length(); i++) |
---|
361 | { |
---|
362 | R->wvhdl[n][i-2]=(*iv)[i]; |
---|
363 | if ((*iv)[i]<0) typ=-1; |
---|
364 | } |
---|
365 | break; |
---|
366 | case ringorder_M: |
---|
367 | { |
---|
368 | int Mtyp=rTypeOfMatrixOrder(iv); |
---|
369 | if (Mtyp==0) return TRUE; |
---|
370 | if (Mtyp==-1) typ = -1; |
---|
371 | |
---|
372 | R->wvhdl[n] =( int *)omAlloc((iv->length()-1)*sizeof(int)); |
---|
373 | for (i=2; i<iv->length();i++) |
---|
374 | R->wvhdl[n][i-2]=(*iv)[i]; |
---|
375 | |
---|
376 | R->block0[n] = last+1; |
---|
377 | last += (int)sqrt((double)(iv->length()-2)); |
---|
378 | R->block1[n] = last; |
---|
379 | break; |
---|
380 | } |
---|
381 | |
---|
382 | case ringorder_no: |
---|
383 | R->order[n] = ringorder_unspec; |
---|
384 | return TRUE; |
---|
385 | |
---|
386 | default: |
---|
387 | Werror("Internal Error: Unknown ordering %d", (*iv)[1]); |
---|
388 | R->order[n] = ringorder_unspec; |
---|
389 | return TRUE; |
---|
390 | } |
---|
391 | } |
---|
392 | sl=sl->next; |
---|
393 | } |
---|
394 | |
---|
395 | // check for complete coverage |
---|
396 | if ((R->order[n]==ringorder_c) || (R->order[n]==ringorder_C)) n--; |
---|
397 | if (R->block1[n] != R->N) |
---|
398 | { |
---|
399 | if (((R->order[n]==ringorder_dp) || |
---|
400 | (R->order[n]==ringorder_ds) || |
---|
401 | (R->order[n]==ringorder_Dp) || |
---|
402 | (R->order[n]==ringorder_Ds) || |
---|
403 | (R->order[n]==ringorder_rp) || |
---|
404 | (R->order[n]==ringorder_lp) || |
---|
405 | (R->order[n]==ringorder_ls)) |
---|
406 | && |
---|
407 | R->block0[n] <= R->N) |
---|
408 | { |
---|
409 | R->block1[n] = R->N; |
---|
410 | } |
---|
411 | else |
---|
412 | { |
---|
413 | Werror("mismatch of number of vars (%d) and ordering (%d vars)", |
---|
414 | R->N,R->block1[n]); |
---|
415 | return TRUE; |
---|
416 | } |
---|
417 | } |
---|
418 | R->OrdSgn = typ; |
---|
419 | return FALSE; |
---|
420 | } |
---|
421 | |
---|
422 | // get array of strings from list of sleftv's |
---|
423 | static BOOLEAN rSleftvList2StringArray(sleftv* sl, char** p) |
---|
424 | { |
---|
425 | |
---|
426 | while(sl!=NULL) |
---|
427 | { |
---|
428 | if (sl->Name() == sNoName) |
---|
429 | { |
---|
430 | if (sl->Typ()==POLY_CMD) |
---|
431 | { |
---|
432 | sleftv s_sl; |
---|
433 | iiConvert(POLY_CMD,ANY_TYPE,-1,sl,&s_sl); |
---|
434 | if (s_sl.Name() != sNoName) |
---|
435 | *p = omStrDup(s_sl.Name()); |
---|
436 | else |
---|
437 | *p = NULL; |
---|
438 | sl->next = s_sl.next; |
---|
439 | s_sl.next = NULL; |
---|
440 | s_sl.CleanUp(); |
---|
441 | if (*p == NULL) return TRUE; |
---|
442 | } |
---|
443 | else |
---|
444 | return TRUE; |
---|
445 | } |
---|
446 | else |
---|
447 | *p = omStrDup(sl->Name()); |
---|
448 | p++; |
---|
449 | sl=sl->next; |
---|
450 | } |
---|
451 | return FALSE; |
---|
452 | } |
---|
453 | |
---|
454 | |
---|
455 | //////////////////// |
---|
456 | // |
---|
457 | // rInit itself: |
---|
458 | // |
---|
459 | // INPUT: s: name, pn: ch & parameter (names), rv: variable (names) |
---|
460 | // ord: ordering |
---|
461 | // RETURN: currRingHdl on success |
---|
462 | // NULL on error |
---|
463 | // NOTE: * makes new ring to current ring, on success |
---|
464 | // * considers input sleftv's as read-only |
---|
465 | //idhdl rInit(char *s, sleftv* pn, sleftv* rv, sleftv* ord) |
---|
466 | ring rInit(sleftv* pn, sleftv* rv, sleftv* ord) |
---|
467 | { |
---|
468 | int ch; |
---|
469 | int float_len=0; |
---|
470 | int float_len2=0; |
---|
471 | ring R = NULL; |
---|
472 | idhdl tmp = NULL; |
---|
473 | BOOLEAN ffChar=FALSE; |
---|
474 | int typ = 1; |
---|
475 | |
---|
476 | /* ch -------------------------------------------------------*/ |
---|
477 | // get ch of ground field |
---|
478 | int numberOfAllocatedBlocks; |
---|
479 | |
---|
480 | if (pn->Typ()==INT_CMD) |
---|
481 | { |
---|
482 | ch=(int)pn->Data(); |
---|
483 | } |
---|
484 | else if ((pn->name != NULL) |
---|
485 | && ((strcmp(pn->name,"real")==0) || (strcmp(pn->name,"complex")==0))) |
---|
486 | { |
---|
487 | BOOLEAN complex_flag=(strcmp(pn->name,"complex")==0); |
---|
488 | ch=-1; |
---|
489 | if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD)) |
---|
490 | { |
---|
491 | float_len=(int)pn->next->Data(); |
---|
492 | float_len2=float_len; |
---|
493 | pn=pn->next; |
---|
494 | if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD)) |
---|
495 | { |
---|
496 | float_len2=(int)pn->next->Data(); |
---|
497 | pn=pn->next; |
---|
498 | } |
---|
499 | } |
---|
500 | if ((pn->next==NULL) && complex_flag) |
---|
501 | { |
---|
502 | pn->next=(leftv)omAlloc0Bin(sleftv_bin); |
---|
503 | pn->next->name=omStrDup("i"); |
---|
504 | } |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | Werror("Wrong ground field specification"); |
---|
509 | goto rInitError; |
---|
510 | } |
---|
511 | pn=pn->next; |
---|
512 | |
---|
513 | int l, last; |
---|
514 | sleftv * sl; |
---|
515 | /*every entry in the new ring is initialized to 0*/ |
---|
516 | |
---|
517 | /* characteristic -----------------------------------------------*/ |
---|
518 | /* input: 0 ch=0 : Q parameter=NULL ffChar=FALSE float_len |
---|
519 | * 0 1 : Q(a,...) *names FALSE |
---|
520 | * 0 -1 : R NULL FALSE 0 |
---|
521 | * 0 -1 : R NULL FALSE prec. >6 |
---|
522 | * 0 -1 : C *names FALSE prec. 0..? |
---|
523 | * p p : Fp NULL FALSE |
---|
524 | * p -p : Fp(a) *names FALSE |
---|
525 | * q q : GF(q=p^n) *names TRUE |
---|
526 | */ |
---|
527 | if (ch!=-1) |
---|
528 | { |
---|
529 | int l = 0; |
---|
530 | |
---|
531 | if (ch!=0 && (ch<2) || (ch > 32003)) |
---|
532 | { |
---|
533 | Warn("%d is invalid characteristic of ground field. 32003 is used.", ch); |
---|
534 | ch=32003; |
---|
535 | } |
---|
536 | // load fftable, if necessary |
---|
537 | if (pn!=NULL) |
---|
538 | { |
---|
539 | while ((ch!=fftable[l]) && (fftable[l])) l++; |
---|
540 | if (fftable[l]==0) ch = IsPrime(ch); |
---|
541 | else |
---|
542 | { |
---|
543 | char *m[1]={(char *)sNoName}; |
---|
544 | nfSetChar(ch,m); |
---|
545 | if (errorreported) goto rInitError; |
---|
546 | else ffChar=TRUE; |
---|
547 | } |
---|
548 | } |
---|
549 | else |
---|
550 | ch = IsPrime(ch); |
---|
551 | } |
---|
552 | // allocated ring and set ch |
---|
553 | R = (ring) omAlloc0Bin(sip_sring_bin); |
---|
554 | R->ch = ch; |
---|
555 | if (ch == -1) |
---|
556 | { |
---|
557 | R->float_len= min(float_len,32767); |
---|
558 | R->float_len2= min(float_len2,32767); |
---|
559 | } |
---|
560 | |
---|
561 | /* parameter -------------------------------------------------------*/ |
---|
562 | if (pn!=NULL) |
---|
563 | { |
---|
564 | R->P=pn->listLength(); |
---|
565 | //if ((ffChar|| (ch == 1)) && (R->P > 1)) |
---|
566 | if ((R->P > 1) && (ffChar || (ch == -1))) |
---|
567 | { |
---|
568 | WerrorS("too many parameters"); |
---|
569 | goto rInitError; |
---|
570 | } |
---|
571 | R->parameter=(char**)omAlloc0(R->P*sizeof(char_ptr)); |
---|
572 | if (rSleftvList2StringArray(pn, R->parameter)) |
---|
573 | { |
---|
574 | WerrorS("parameter expected"); |
---|
575 | goto rInitError; |
---|
576 | } |
---|
577 | if (ch>1 && !ffChar) R->ch=-ch; |
---|
578 | else if (ch==0) R->ch=1; |
---|
579 | } |
---|
580 | else if (ffChar) |
---|
581 | { |
---|
582 | WerrorS("need one parameter"); |
---|
583 | goto rInitError; |
---|
584 | } |
---|
585 | /* post-processing of field description */ |
---|
586 | // we have short reals, but no short complex |
---|
587 | if ((R->ch == - 1) |
---|
588 | && (R->parameter !=NULL) |
---|
589 | && (R->float_len < SHORT_REAL_LENGTH)) |
---|
590 | { |
---|
591 | R->float_len = SHORT_REAL_LENGTH; |
---|
592 | R->float_len2 = SHORT_REAL_LENGTH; |
---|
593 | } |
---|
594 | |
---|
595 | /* names and number of variables-------------------------------------*/ |
---|
596 | R->N = rv->listLength(); |
---|
597 | R->names = (char **)omAlloc0(R->N * sizeof(char_ptr)); |
---|
598 | if (rSleftvList2StringArray(rv, R->names)) |
---|
599 | { |
---|
600 | WerrorS("name of ring variable expected"); |
---|
601 | goto rInitError; |
---|
602 | } |
---|
603 | |
---|
604 | /* check names and parameters for conflicts ------------------------- */ |
---|
605 | { |
---|
606 | int i,j; |
---|
607 | for(i=0;i<R->P; i++) |
---|
608 | { |
---|
609 | for(j=0;j<R->N;j++) |
---|
610 | { |
---|
611 | if (strcmp(R->parameter[i],R->names[j])==0) |
---|
612 | { |
---|
613 | Werror("parameter %d conflicts with variable %d",i+1,j+1); |
---|
614 | goto rInitError; |
---|
615 | } |
---|
616 | } |
---|
617 | } |
---|
618 | } |
---|
619 | /* ordering -------------------------------------------------------------*/ |
---|
620 | if (rSleftvOrdering2Ordering(ord, R)) |
---|
621 | goto rInitError; |
---|
622 | |
---|
623 | // Complete the initialization |
---|
624 | if (rComplete(R,1)) |
---|
625 | goto rInitError; |
---|
626 | |
---|
627 | rTest(R); |
---|
628 | |
---|
629 | // try to enter the ring into the name list |
---|
630 | // need to clean up sleftv here, before this ring can be set to |
---|
631 | // new currRing or currRing can be killed beacuse new ring has |
---|
632 | // same name |
---|
633 | if (pn != NULL) pn->CleanUp(); |
---|
634 | if (rv != NULL) rv->CleanUp(); |
---|
635 | if (ord != NULL) ord->CleanUp(); |
---|
636 | //if ((tmp = enterid(s, myynest, RING_CMD, &IDROOT))==NULL) |
---|
637 | // goto rInitError; |
---|
638 | |
---|
639 | //memcpy(IDRING(tmp),R,sizeof(*R)); |
---|
640 | // set current ring |
---|
641 | //omFreeBin(R, ip_sring_bin); |
---|
642 | //return tmp; |
---|
643 | return R; |
---|
644 | |
---|
645 | // error case: |
---|
646 | rInitError: |
---|
647 | if (R != NULL) rDelete(R); |
---|
648 | if (pn != NULL) pn->CleanUp(); |
---|
649 | if (rv != NULL) rv->CleanUp(); |
---|
650 | if (ord != NULL) ord->CleanUp(); |
---|
651 | return NULL; |
---|
652 | } |
---|
653 | |
---|
654 | /*2 |
---|
655 | * set a new ring from the data: |
---|
656 | s: name, chr: ch, varnames: rv, ordering: ord, typ: typ |
---|
657 | */ |
---|
658 | |
---|
659 | int r_IsRingVar(char *n, ring r) |
---|
660 | { |
---|
661 | if ((r!=NULL) && (r->names!=NULL)) |
---|
662 | { |
---|
663 | for (int i=0; i<r->N; i++) |
---|
664 | { |
---|
665 | if (r->names[i]==NULL) return -1; |
---|
666 | if (strcmp(n,r->names[i]) == 0) return (int)i; |
---|
667 | } |
---|
668 | } |
---|
669 | return -1; |
---|
670 | } |
---|
671 | |
---|
672 | |
---|
673 | void rWrite(ring r) |
---|
674 | { |
---|
675 | if ((r==NULL)||(r->order==NULL)) |
---|
676 | return; /*to avoid printing after errors....*/ |
---|
677 | |
---|
678 | int nblocks=rBlocks(r); |
---|
679 | |
---|
680 | // omCheckAddrSize(r,sizeof(ip_sring)); |
---|
681 | omCheckAddrSize(r->order,nblocks*sizeof(int)); |
---|
682 | omCheckAddrSize(r->block0,nblocks*sizeof(int)); |
---|
683 | omCheckAddrSize(r->block1,nblocks*sizeof(int)); |
---|
684 | omCheckAddrSize(r->wvhdl,nblocks*sizeof(int_ptr)); |
---|
685 | omCheckAddrSize(r->names,r->N*sizeof(char_ptr)); |
---|
686 | |
---|
687 | |
---|
688 | nblocks--; |
---|
689 | |
---|
690 | |
---|
691 | if (rField_is_GF(r)) |
---|
692 | { |
---|
693 | Print("// # ground field : %d\n",rInternalChar(r)); |
---|
694 | Print("// primitive element : %s\n", r->parameter[0]); |
---|
695 | if (r==currRing) |
---|
696 | { |
---|
697 | StringSetS("// minpoly : "); |
---|
698 | nfShowMipo();PrintS(StringAppendS("\n")); |
---|
699 | } |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | PrintS("// characteristic : "); |
---|
704 | if ( rField_is_R(r) ) PrintS("0 (real)\n"); /* R */ |
---|
705 | else if ( rField_is_long_R(r) ) |
---|
706 | Print("0 (real:%d digits, additional %d digits)\n", |
---|
707 | r->float_len,r->float_len2); /* long R */ |
---|
708 | else if ( rField_is_long_C(r) ) |
---|
709 | Print("0 (complex:%d digits, additional %d digits)\n", |
---|
710 | r->float_len, r->float_len2); /* long C */ |
---|
711 | else |
---|
712 | Print ("%d\n",rChar(r)); /* Fp(a) */ |
---|
713 | if (r->parameter!=NULL) |
---|
714 | { |
---|
715 | Print ("// %d parameter : ",rPar(r)); |
---|
716 | char **sp=r->parameter; |
---|
717 | int nop=0; |
---|
718 | while (nop<rPar(r)) |
---|
719 | { |
---|
720 | PrintS(*sp); |
---|
721 | PrintS(" "); |
---|
722 | sp++; nop++; |
---|
723 | } |
---|
724 | PrintS("\n// minpoly : "); |
---|
725 | if ( rField_is_long_C(r) ) |
---|
726 | { |
---|
727 | // i^2+1: |
---|
728 | Print("(%s^2+1)\n",r->parameter[0]); |
---|
729 | } |
---|
730 | else if (r->minpoly==NULL) |
---|
731 | { |
---|
732 | PrintS("0\n"); |
---|
733 | } |
---|
734 | else if (r==currRing) |
---|
735 | { |
---|
736 | StringSetS(""); nWrite(r->minpoly); PrintS(StringAppendS("\n")); |
---|
737 | } |
---|
738 | else |
---|
739 | { |
---|
740 | PrintS("...\n"); |
---|
741 | } |
---|
742 | } |
---|
743 | } |
---|
744 | Print("// number of vars : %d",r->N); |
---|
745 | |
---|
746 | //for (nblocks=0; r->order[nblocks]; nblocks++); |
---|
747 | nblocks=rBlocks(r)-1; |
---|
748 | |
---|
749 | for (int l=0, nlen=0 ; l<nblocks; l++) |
---|
750 | { |
---|
751 | int i; |
---|
752 | Print("\n// block %3d : ",l+1); |
---|
753 | |
---|
754 | Print("ordering %s", rSimpleOrdStr(r->order[l])); |
---|
755 | |
---|
756 | if ((r->order[l] >= ringorder_lp) |
---|
757 | ||(r->order[l] == ringorder_M) |
---|
758 | ||(r->order[l] == ringorder_a) |
---|
759 | ||(r->order[l] == ringorder_aa)) |
---|
760 | { |
---|
761 | PrintS("\n// : names "); |
---|
762 | for (i = r->block0[l]-1; i<r->block1[l]; i++) |
---|
763 | { |
---|
764 | nlen = strlen(r->names[i]); |
---|
765 | Print("%s ",r->names[i]); |
---|
766 | } |
---|
767 | } |
---|
768 | #ifndef NDEBUG |
---|
769 | else if (r->order[l] == ringorder_s) |
---|
770 | { |
---|
771 | Print(" syzcomp at %d",r->typ[l].data.syz.limit); |
---|
772 | } |
---|
773 | #endif |
---|
774 | |
---|
775 | if (r->wvhdl[l]!=NULL) |
---|
776 | { |
---|
777 | for (int j= 0; |
---|
778 | j<(r->block1[l]-r->block0[l]+1)*(r->block1[l]-r->block0[l]+1); |
---|
779 | j+=i) |
---|
780 | { |
---|
781 | PrintS("\n// : weights "); |
---|
782 | for (i = 0; i<=r->block1[l]-r->block0[l]; i++) |
---|
783 | { |
---|
784 | Print("%*d " ,nlen,r->wvhdl[l][i+j],i+j); |
---|
785 | } |
---|
786 | if (r->order[l]!=ringorder_M) break; |
---|
787 | } |
---|
788 | } |
---|
789 | } |
---|
790 | if (r->qideal!=NULL) |
---|
791 | { |
---|
792 | PrintS("\n// quotient ring from ideal"); |
---|
793 | if (r==currRing) |
---|
794 | { |
---|
795 | PrintLn(); |
---|
796 | iiWriteMatrix((matrix)r->qideal,"_",1); |
---|
797 | } |
---|
798 | else PrintS(" ..."); |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | static void rDelete(ring r) |
---|
803 | { |
---|
804 | int i, j; |
---|
805 | |
---|
806 | if (r == NULL) return; |
---|
807 | |
---|
808 | rUnComplete(r); |
---|
809 | // delete order stuff |
---|
810 | if (r->order != NULL) |
---|
811 | { |
---|
812 | i=rBlocks(r); |
---|
813 | assume(r->block0 != NULL && r->block1 != NULL && r->wvhdl != NULL); |
---|
814 | // delete order |
---|
815 | omFreeSize((ADDRESS)r->order,i*sizeof(int)); |
---|
816 | omFreeSize((ADDRESS)r->block0,i*sizeof(int)); |
---|
817 | omFreeSize((ADDRESS)r->block1,i*sizeof(int)); |
---|
818 | // delete weights |
---|
819 | for (j=0; j<i; j++) |
---|
820 | { |
---|
821 | if (r->wvhdl[j]!=NULL) |
---|
822 | omFree(r->wvhdl[j]); |
---|
823 | } |
---|
824 | omFreeSize((ADDRESS)r->wvhdl,i*sizeof(short *)); |
---|
825 | } |
---|
826 | else |
---|
827 | { |
---|
828 | assume(r->block0 == NULL && r->block1 == NULL && r->wvhdl == NULL); |
---|
829 | } |
---|
830 | |
---|
831 | // delete varnames |
---|
832 | if(r->names!=NULL) |
---|
833 | { |
---|
834 | for (i=0; i<r->N; i++) |
---|
835 | { |
---|
836 | if (r->names[i] != NULL) omFree((ADDRESS)r->names[i]); |
---|
837 | } |
---|
838 | omFreeSize((ADDRESS)r->names,r->N*sizeof(char_ptr)); |
---|
839 | } |
---|
840 | |
---|
841 | // delete parameter |
---|
842 | if (r->parameter!=NULL) |
---|
843 | { |
---|
844 | char **s=r->parameter; |
---|
845 | j = 0; |
---|
846 | while (j < rPar(r)) |
---|
847 | { |
---|
848 | if (*s != NULL) omFree((ADDRESS)*s); |
---|
849 | s++; |
---|
850 | j++; |
---|
851 | } |
---|
852 | omFreeSize((ADDRESS)r->parameter,rPar(r)*sizeof(char_ptr)); |
---|
853 | } |
---|
854 | omFreeBin(r, ip_sring_bin); |
---|
855 | } |
---|
856 | |
---|
857 | void rKill(ring r) |
---|
858 | { |
---|
859 | if ((r->ref<=0)&&(r->order!=NULL)) |
---|
860 | { |
---|
861 | #ifdef RDEBUG |
---|
862 | if (traceit &TRACE_SHOW_RINGS) Print("kill ring %x\n",r); |
---|
863 | #endif |
---|
864 | if (r==currRing) |
---|
865 | { |
---|
866 | if (r->qideal!=NULL) |
---|
867 | { |
---|
868 | idDelete(&r->qideal); |
---|
869 | r->qideal=NULL; |
---|
870 | currQuotient=NULL; |
---|
871 | } |
---|
872 | if (ppNoether!=NULL) pDelete(&ppNoether); |
---|
873 | if (sLastPrinted.RingDependend()) |
---|
874 | { |
---|
875 | sLastPrinted.CleanUp(); |
---|
876 | } |
---|
877 | if ((myynest>0) && (iiRETURNEXPR[myynest].RingDependend())) |
---|
878 | { |
---|
879 | WerrorS("return value depends on local ring variable (export missing ?)"); |
---|
880 | iiRETURNEXPR[myynest].CleanUp(); |
---|
881 | } |
---|
882 | currRing=NULL; |
---|
883 | currRingHdl=NULL; |
---|
884 | } |
---|
885 | else if (r->qideal!=NULL) |
---|
886 | { |
---|
887 | id_Delete(&r->qideal, r); |
---|
888 | r->qideal = NULL; |
---|
889 | } |
---|
890 | nKillChar(r); |
---|
891 | int i=1; |
---|
892 | int j; |
---|
893 | int *pi=r->order; |
---|
894 | #ifdef USE_IILOCALRING |
---|
895 | for (j=0;j<iiRETURNEXPR_len;j++) |
---|
896 | { |
---|
897 | if (iiLocalRing[j]==r) |
---|
898 | { |
---|
899 | if (j<myynest) Warn("killing the basering for level %d",j); |
---|
900 | iiLocalRing[j]=NULL; |
---|
901 | } |
---|
902 | } |
---|
903 | #else /* USE_IILOCALRING */ |
---|
904 | { |
---|
905 | namehdl nshdl = namespaceroot; |
---|
906 | |
---|
907 | for(nshdl=namespaceroot; nshdl->isroot != TRUE; nshdl = nshdl->next) { |
---|
908 | //Print("NSstack: %s:%d, nesting=%d\n", nshdl->name, nshdl->lev, nshdl->myynest); |
---|
909 | if (nshdl->currRing==r) |
---|
910 | { |
---|
911 | if (nshdl->myynest<myynest) |
---|
912 | // Warn("killing the basering for level %d/%d",nshdl->lev,nshdl->myynest); |
---|
913 | Warn("killing the basering for level %d",nshdl->myynest); |
---|
914 | nshdl->currRing=NULL; |
---|
915 | } |
---|
916 | } |
---|
917 | if (nshdl->currRing==r) |
---|
918 | { |
---|
919 | //Print("NSstack: %s:%d, nesting=%d\n", nshdl->name, nshdl->lev, nshdl->myynest); |
---|
920 | if (nshdl->myynest<myynest) |
---|
921 | // Warn("killing the basering for level %d/%d",nshdl->lev,nshdl->myynest); |
---|
922 | Warn("killing the basering for level %d",nshdl->myynest); |
---|
923 | nshdl->currRing=NULL; |
---|
924 | } |
---|
925 | } |
---|
926 | #endif /* USE_IILOCALRING */ |
---|
927 | |
---|
928 | rDelete(r); |
---|
929 | return; |
---|
930 | } |
---|
931 | r->ref--; |
---|
932 | } |
---|
933 | |
---|
934 | void rKill(idhdl h) |
---|
935 | { |
---|
936 | #ifndef HAVE_NAMESPACES1 |
---|
937 | ring r = IDRING(h); |
---|
938 | if (r!=NULL) rKill(r); |
---|
939 | if (h==currRingHdl) |
---|
940 | { |
---|
941 | #ifdef HAVE_NAMESPACES |
---|
942 | namehdl nsHdl = namespaceroot; |
---|
943 | while(nsHdl!=NULL) { |
---|
944 | currRingHdl=NSROOT(nsHdl); |
---|
945 | #else /* HAVE_NAMESPACES */ |
---|
946 | currRingHdl=IDROOT; |
---|
947 | #endif /* HAVE_NAMESPACES */ |
---|
948 | while (currRingHdl!=NULL) |
---|
949 | { |
---|
950 | if ((currRingHdl!=h) |
---|
951 | && (IDTYP(currRingHdl)==IDTYP(h)) |
---|
952 | && (h->data.uring==currRingHdl->data.uring)) |
---|
953 | break; |
---|
954 | currRingHdl=IDNEXT(currRingHdl); |
---|
955 | } |
---|
956 | #ifdef HAVE_NAMESPACES |
---|
957 | if ((currRingHdl != NULL) && (currRingHdl!=h) |
---|
958 | && (IDTYP(currRingHdl)==IDTYP(h)) |
---|
959 | && (h->data.uring==currRingHdl->data.uring)) |
---|
960 | break; |
---|
961 | nsHdl = nsHdl->next; |
---|
962 | } |
---|
963 | #endif /* HAVE_NAMESPACES */ |
---|
964 | } |
---|
965 | #else |
---|
966 | if(currRingHdl==NULL) |
---|
967 | { |
---|
968 | namehdl ns = namespaceroot; |
---|
969 | BOOLEAN found=FALSE; |
---|
970 | |
---|
971 | while(!ns->isroot) |
---|
972 | { |
---|
973 | currRingHdl=NSROOT(namespaceroot->next); |
---|
974 | while (currRingHdl!=NULL) |
---|
975 | { |
---|
976 | if ((currRingHdl!=h) |
---|
977 | && (IDTYP(currRingHdl)==IDTYP(h)) |
---|
978 | && (h->data.uring==currRingHdl->data.uring)) |
---|
979 | { found=TRUE; break; } |
---|
980 | |
---|
981 | currRingHdl=IDNEXT(currRingHdl); |
---|
982 | } |
---|
983 | if(found) break; |
---|
984 | ns=IDNEXT(ns); |
---|
985 | } |
---|
986 | } |
---|
987 | if(currRingHdl == NULL || IDRING(h) != IDRING(currRingHdl)) |
---|
988 | { |
---|
989 | currRingHdl = namespaceroot->currRingHdl; |
---|
990 | |
---|
991 | /* PrintS("Running rFind()\n"); |
---|
992 | currRingHdl = rFindHdl(IDRING(h), NULL, NULL); |
---|
993 | if(currRingHdl == NULL) |
---|
994 | { |
---|
995 | PrintS("rFind()return 0\n"); |
---|
996 | } |
---|
997 | else |
---|
998 | { |
---|
999 | PrintS("Huppi rfind return an currRingHDL\n"); |
---|
1000 | Print("%x, %x\n", IDRING(h),IDRING(currRingHdl) ); |
---|
1001 | } |
---|
1002 | */ |
---|
1003 | } |
---|
1004 | else |
---|
1005 | { |
---|
1006 | //PrintS("Huppi found an currRingHDL\n"); |
---|
1007 | //Print("%x, %x\n", IDRING(h),IDRING(currRingHdl) ); |
---|
1008 | |
---|
1009 | } |
---|
1010 | #endif /* HAVE_NAMESPACES */ |
---|
1011 | } |
---|
1012 | |
---|
1013 | idhdl rFindHdl(ring r, idhdl n, idhdl w) |
---|
1014 | { |
---|
1015 | #ifdef HAVE_NAMESPACES |
---|
1016 | idhdl h; |
---|
1017 | namehdl ns = namespaceroot; |
---|
1018 | |
---|
1019 | while(!ns->isroot) { |
---|
1020 | h = NSROOT(ns); |
---|
1021 | if(w != NULL) h = w; |
---|
1022 | while (h!=NULL) |
---|
1023 | { |
---|
1024 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
1025 | && (h->data.uring==r) |
---|
1026 | && (h!=n)) |
---|
1027 | return h; |
---|
1028 | h=IDNEXT(h); |
---|
1029 | } |
---|
1030 | ns = ns->next; |
---|
1031 | } |
---|
1032 | h = NSROOT(ns); |
---|
1033 | if(w != NULL) h = w; |
---|
1034 | while (h!=NULL) |
---|
1035 | { |
---|
1036 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
1037 | && (h->data.uring==r) |
---|
1038 | && (h!=n)) |
---|
1039 | return h; |
---|
1040 | h=IDNEXT(h); |
---|
1041 | } |
---|
1042 | #if 0 |
---|
1043 | if(namespaceroot->isroot) h = IDROOT; |
---|
1044 | else h = NSROOT(namespaceroot->next); |
---|
1045 | if(w != NULL) h = w; |
---|
1046 | while (h!=NULL) |
---|
1047 | { |
---|
1048 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
1049 | && (h->data.uring==r) |
---|
1050 | && (h!=n)) |
---|
1051 | return h; |
---|
1052 | h=IDNEXT(h); |
---|
1053 | } |
---|
1054 | #endif |
---|
1055 | #else |
---|
1056 | idhdl h=IDROOT; |
---|
1057 | if(w != NULL) h = w; |
---|
1058 | while (h!=NULL) |
---|
1059 | { |
---|
1060 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
1061 | && (h->data.uring==r) |
---|
1062 | && (h!=n)) |
---|
1063 | return h; |
---|
1064 | h=IDNEXT(h); |
---|
1065 | } |
---|
1066 | #endif |
---|
1067 | return NULL; |
---|
1068 | } |
---|
1069 | |
---|
1070 | int rOrderName(char * ordername) |
---|
1071 | { |
---|
1072 | int order=ringorder_unspec; |
---|
1073 | while (order!= 0) |
---|
1074 | { |
---|
1075 | if (strcmp(ordername,rSimpleOrdStr(order))==0) |
---|
1076 | break; |
---|
1077 | order--; |
---|
1078 | } |
---|
1079 | if (order==0) Werror("wrong ring order `%s`",ordername); |
---|
1080 | omFree((ADDRESS)ordername); |
---|
1081 | return order; |
---|
1082 | } |
---|
1083 | |
---|
1084 | char * rOrdStr(ring r) |
---|
1085 | { |
---|
1086 | int nblocks,l,i; |
---|
1087 | |
---|
1088 | for (nblocks=0; r->order[nblocks]; nblocks++); |
---|
1089 | nblocks--; |
---|
1090 | |
---|
1091 | StringSetS(""); |
---|
1092 | for (l=0; ; l++) |
---|
1093 | { |
---|
1094 | StringAppend((char *)rSimpleOrdStr(r->order[l])); |
---|
1095 | if ((r->order[l] != ringorder_c) && (r->order[l] != ringorder_C)) |
---|
1096 | { |
---|
1097 | if (r->wvhdl[l]!=NULL) |
---|
1098 | { |
---|
1099 | StringAppendS("("); |
---|
1100 | for (int j= 0; |
---|
1101 | j<(r->block1[l]-r->block0[l]+1)*(r->block1[l]-r->block0[l]+1); |
---|
1102 | j+=i+1) |
---|
1103 | { |
---|
1104 | char c=','; |
---|
1105 | for (i = 0; i<r->block1[l]-r->block0[l]; i++) |
---|
1106 | { |
---|
1107 | StringAppend("%d," ,r->wvhdl[l][i+j]); |
---|
1108 | } |
---|
1109 | if (r->order[l]!=ringorder_M) |
---|
1110 | { |
---|
1111 | StringAppend("%d)" ,r->wvhdl[l][i+j]); |
---|
1112 | break; |
---|
1113 | } |
---|
1114 | if (j+i+1==(r->block1[l]-r->block0[l]+1)*(r->block1[l]-r->block0[l]+1)) |
---|
1115 | c=')'; |
---|
1116 | StringAppend("%d%c" ,r->wvhdl[l][i+j],c); |
---|
1117 | } |
---|
1118 | } |
---|
1119 | else |
---|
1120 | StringAppend("(%d)",r->block1[l]-r->block0[l]+1); |
---|
1121 | } |
---|
1122 | if (l==nblocks) return omStrDup(StringAppendS("")); |
---|
1123 | StringAppendS(","); |
---|
1124 | } |
---|
1125 | } |
---|
1126 | |
---|
1127 | char * rVarStr(ring r) |
---|
1128 | { |
---|
1129 | int i; |
---|
1130 | int l=2; |
---|
1131 | char *s; |
---|
1132 | |
---|
1133 | for (i=0; i<r->N; i++) |
---|
1134 | { |
---|
1135 | l+=strlen(r->names[i])+1; |
---|
1136 | } |
---|
1137 | s=(char *)omAlloc(l); |
---|
1138 | s[0]='\0'; |
---|
1139 | for (i=0; i<r->N-1; i++) |
---|
1140 | { |
---|
1141 | strcat(s,r->names[i]); |
---|
1142 | strcat(s,","); |
---|
1143 | } |
---|
1144 | strcat(s,r->names[i]); |
---|
1145 | return s; |
---|
1146 | } |
---|
1147 | |
---|
1148 | char * rCharStr(ring r) |
---|
1149 | { |
---|
1150 | char *s; |
---|
1151 | int i; |
---|
1152 | |
---|
1153 | if (r->parameter==NULL) |
---|
1154 | { |
---|
1155 | i=r->ch; |
---|
1156 | if(i==-1) |
---|
1157 | s=omStrDup("real"); /* R */ |
---|
1158 | else |
---|
1159 | { |
---|
1160 | s=(char *)omAlloc(6); |
---|
1161 | sprintf(s,"%d",i); /* Q, Z/p */ |
---|
1162 | } |
---|
1163 | return s; |
---|
1164 | } |
---|
1165 | int l=0; |
---|
1166 | for(i=0; i<rPar(r);i++) |
---|
1167 | { |
---|
1168 | l+=(strlen(r->parameter[i])+1); |
---|
1169 | } |
---|
1170 | s=(char *)omAlloc(l+6); |
---|
1171 | s[0]='\0'; |
---|
1172 | if (r->ch<0) sprintf(s,"%d",-r->ch); /* Fp(a) */ |
---|
1173 | else if (r->ch==1) sprintf(s,"0"); /* Q(a) */ |
---|
1174 | else |
---|
1175 | { |
---|
1176 | sprintf(s,"%d,%s",r->ch,r->parameter[0]); /* Fq */ |
---|
1177 | return s; |
---|
1178 | } |
---|
1179 | char tt[2]; |
---|
1180 | tt[0]=','; |
---|
1181 | tt[1]='\0'; |
---|
1182 | for(i=0; i<rPar(r);i++) |
---|
1183 | { |
---|
1184 | strcat(s,tt); |
---|
1185 | strcat(s,r->parameter[i]); |
---|
1186 | } |
---|
1187 | return s; |
---|
1188 | } |
---|
1189 | |
---|
1190 | char * rParStr(ring r) |
---|
1191 | { |
---|
1192 | if (r->parameter==NULL) return omStrDup(""); |
---|
1193 | |
---|
1194 | int i; |
---|
1195 | int l=2; |
---|
1196 | |
---|
1197 | for (i=0; i<rPar(r); i++) |
---|
1198 | { |
---|
1199 | l+=strlen(r->parameter[i])+1; |
---|
1200 | } |
---|
1201 | char *s=(char *)omAlloc(l); |
---|
1202 | s[0]='\0'; |
---|
1203 | for (i=0; i<rPar(r)-1; i++) |
---|
1204 | { |
---|
1205 | strcat(s,r->parameter[i]); |
---|
1206 | strcat(s,","); |
---|
1207 | } |
---|
1208 | strcat(s,r->parameter[i]); |
---|
1209 | return s; |
---|
1210 | } |
---|
1211 | |
---|
1212 | char * rString(ring r) |
---|
1213 | { |
---|
1214 | char *ch=rCharStr(r); |
---|
1215 | char *var=rVarStr(r); |
---|
1216 | char *ord=rOrdStr(r); |
---|
1217 | char *res=(char *)omAlloc(strlen(ch)+strlen(var)+strlen(ord)+9); |
---|
1218 | sprintf(res,"(%s),(%s),(%s)",ch,var,ord); |
---|
1219 | omFree((ADDRESS)ch); |
---|
1220 | omFree((ADDRESS)var); |
---|
1221 | omFree((ADDRESS)ord); |
---|
1222 | return res; |
---|
1223 | } |
---|
1224 | |
---|
1225 | int rChar(ring r) |
---|
1226 | { |
---|
1227 | if (r->ch==-1) |
---|
1228 | return 0; |
---|
1229 | if (r->parameter==NULL) /* Q, Fp */ |
---|
1230 | return r->ch; |
---|
1231 | if (r->ch<0) /* Fp(a) */ |
---|
1232 | return -r->ch; |
---|
1233 | if (r->ch==1) /* Q(a) */ |
---|
1234 | return 0; |
---|
1235 | /*else*/ /* GF(p,n) */ |
---|
1236 | { |
---|
1237 | if ((r->ch & 1)==0) return 2; |
---|
1238 | int i=3; |
---|
1239 | while ((r->ch % i)!=0) i+=2; |
---|
1240 | return i; |
---|
1241 | } |
---|
1242 | } |
---|
1243 | |
---|
1244 | int rIsExtension(ring r) |
---|
1245 | { |
---|
1246 | if (r->parameter==NULL) /* Q, Fp */ |
---|
1247 | return FALSE; |
---|
1248 | else |
---|
1249 | return TRUE; |
---|
1250 | } |
---|
1251 | |
---|
1252 | int rIsExtension() |
---|
1253 | { |
---|
1254 | return rIsExtension( currRing ); |
---|
1255 | } |
---|
1256 | |
---|
1257 | /*2 |
---|
1258 | *returns -1 for not compatible, (sum is undefined) |
---|
1259 | * 0 for equal, (and sum) |
---|
1260 | * 1 for compatible (and sum) |
---|
1261 | */ |
---|
1262 | int rSum(ring r1, ring r2, ring &sum) |
---|
1263 | { |
---|
1264 | if (r1==r2) |
---|
1265 | { |
---|
1266 | sum=r1; |
---|
1267 | r1->ref++; |
---|
1268 | return 0; |
---|
1269 | } |
---|
1270 | ring save=currRing; |
---|
1271 | ip_sring tmpR; |
---|
1272 | memset(&tmpR,0,sizeof(tmpR)); |
---|
1273 | /* check coeff. field =====================================================*/ |
---|
1274 | if (rInternalChar(r1)==rInternalChar(r2)) |
---|
1275 | { |
---|
1276 | tmpR.ch=rInternalChar(r1); |
---|
1277 | if (rField_is_Q(r1)||rField_is_Zp(r1)||rField_is_GF(r1)) /*Q, Z/p, GF(p,n)*/ |
---|
1278 | { |
---|
1279 | if (r1->parameter!=NULL) |
---|
1280 | { |
---|
1281 | if (strcmp(r1->parameter[0],r2->parameter[0])==0) /* 1 char */ |
---|
1282 | { |
---|
1283 | tmpR.parameter=(char **)omAllocBin(char_ptr_bin); |
---|
1284 | tmpR.parameter[0]=omStrDup(r1->parameter[0]); |
---|
1285 | tmpR.P=1; |
---|
1286 | } |
---|
1287 | else |
---|
1288 | { |
---|
1289 | WerrorS("GF(p,n)+GF(p,n)"); |
---|
1290 | return -1; |
---|
1291 | } |
---|
1292 | } |
---|
1293 | } |
---|
1294 | else if ((r1->ch==1)||(r1->ch<-1)) /* Q(a),Z/p(a) */ |
---|
1295 | { |
---|
1296 | if (r1->minpoly!=NULL) |
---|
1297 | { |
---|
1298 | if (r2->minpoly!=NULL) |
---|
1299 | { |
---|
1300 | // HANNES: TODO: delete nSetChar |
---|
1301 | rChangeCurrRing(r1); |
---|
1302 | if ((strcmp(r1->parameter[0],r2->parameter[0])==0) /* 1 char */ |
---|
1303 | && n_Equal(r1->minpoly,r2->minpoly, r1)) |
---|
1304 | { |
---|
1305 | tmpR.parameter=(char **)omAllocBin(char_ptr_bin); |
---|
1306 | tmpR.parameter[0]=omStrDup(r1->parameter[0]); |
---|
1307 | tmpR.minpoly=n_Copy(r1->minpoly, r1); |
---|
1308 | tmpR.P=1; |
---|
1309 | // HANNES: TODO: delete nSetChar |
---|
1310 | rChangeCurrRing(save); |
---|
1311 | } |
---|
1312 | else |
---|
1313 | { |
---|
1314 | // HANNES: TODO: delete nSetChar |
---|
1315 | rChangeCurrRing(save); |
---|
1316 | WerrorS("different minpolys"); |
---|
1317 | return -1; |
---|
1318 | } |
---|
1319 | } |
---|
1320 | else |
---|
1321 | { |
---|
1322 | if ((strcmp(r1->parameter[0],r2->parameter[0])==0) /* 1 char */ |
---|
1323 | && (rPar(r2)==1)) |
---|
1324 | { |
---|
1325 | tmpR.parameter=(char **)omAlloc0Bin(char_ptr_bin); |
---|
1326 | tmpR.parameter[0]=omStrDup(r1->parameter[0]); |
---|
1327 | tmpR.P=1; |
---|
1328 | // HANNES: TODO: delete nSetChar |
---|
1329 | rChangeCurrRing(r1); |
---|
1330 | tmpR.minpoly=n_Copy(r1->minpoly, r1); |
---|
1331 | rChangeCurrRing(save); |
---|
1332 | } |
---|
1333 | else |
---|
1334 | { |
---|
1335 | WerrorS("different parameters and minpoly!=0"); |
---|
1336 | return -1; |
---|
1337 | } |
---|
1338 | } |
---|
1339 | } |
---|
1340 | else /* r1->minpoly==NULL */ |
---|
1341 | { |
---|
1342 | if (r2->minpoly!=NULL) |
---|
1343 | { |
---|
1344 | if ((strcmp(r1->parameter[0],r2->parameter[0])==0) /* 1 char */ |
---|
1345 | && (rPar(r1)==1)) |
---|
1346 | { |
---|
1347 | tmpR.parameter=(char **)omAllocBin(char_ptr_bin); |
---|
1348 | tmpR.parameter[0]=omStrDup(r1->parameter[0]); |
---|
1349 | tmpR.P=1; |
---|
1350 | // HANNES: TODO: delete nSetChar |
---|
1351 | rChangeCurrRing(r2); |
---|
1352 | tmpR.minpoly=n_Copy(r2->minpoly, r2); |
---|
1353 | rChangeCurrRing(save); |
---|
1354 | } |
---|
1355 | else |
---|
1356 | { |
---|
1357 | WerrorS("different parameters and minpoly!=0"); |
---|
1358 | return -1; |
---|
1359 | } |
---|
1360 | } |
---|
1361 | else |
---|
1362 | { |
---|
1363 | int len=rPar(r1)+rPar(r2); |
---|
1364 | tmpR.parameter=(char **)omAlloc(len*sizeof(char_ptr)); |
---|
1365 | int i; |
---|
1366 | for (i=0;i<rPar(r1);i++) |
---|
1367 | { |
---|
1368 | tmpR.parameter[i]=omStrDup(r1->parameter[i]); |
---|
1369 | } |
---|
1370 | int j,l; |
---|
1371 | for(j=0;j<rPar(r2);j++) |
---|
1372 | { |
---|
1373 | for(l=0;l<i;l++) |
---|
1374 | { |
---|
1375 | if(strcmp(tmpR.parameter[l],r2->parameter[j])==0) |
---|
1376 | break; |
---|
1377 | } |
---|
1378 | if (l==i) |
---|
1379 | { |
---|
1380 | tmpR.parameter[i]=omStrDup(r2->parameter[j]); |
---|
1381 | i++; |
---|
1382 | } |
---|
1383 | } |
---|
1384 | if (i!=len) |
---|
1385 | { |
---|
1386 | omReallocSize(tmpR.parameter,len*sizeof(char_ptr),i*sizeof(char_ptr)); |
---|
1387 | } |
---|
1388 | } |
---|
1389 | } |
---|
1390 | } |
---|
1391 | } |
---|
1392 | else /* r1->ch!=r2->ch */ |
---|
1393 | { |
---|
1394 | if (r1->ch<-1) /* Z/p(a) */ |
---|
1395 | { |
---|
1396 | if ((r2->ch==0) /* Q */ |
---|
1397 | || (r2->ch==-r1->ch)) /* Z/p */ |
---|
1398 | { |
---|
1399 | tmpR.ch=rInternalChar(r1); |
---|
1400 | tmpR.parameter=(char **)omAlloc(rPar(r1)*sizeof(char_ptr)); |
---|
1401 | tmpR.P=rPar(r1); |
---|
1402 | memcpy(tmpR.parameter,r1->parameter,rPar(r1)*sizeof(char_ptr)); |
---|
1403 | if (r1->minpoly!=NULL) |
---|
1404 | { |
---|
1405 | // HANNES: TODO: delete nSetChar |
---|
1406 | rChangeCurrRing(r1); |
---|
1407 | tmpR.minpoly=n_Copy(r1->minpoly, r1); |
---|
1408 | rChangeCurrRing(save); |
---|
1409 | } |
---|
1410 | } |
---|
1411 | else /* R, Q(a),Z/q,Z/p(a),GF(p,n) */ |
---|
1412 | { |
---|
1413 | WerrorS("Z/p(a)+(R,Q(a),Z/q(a),GF(q,n))"); |
---|
1414 | return -1; |
---|
1415 | } |
---|
1416 | } |
---|
1417 | else if (r1->ch==-1) /* R */ |
---|
1418 | { |
---|
1419 | WerrorS("R+.."); |
---|
1420 | return -1; |
---|
1421 | } |
---|
1422 | else if (r1->ch==0) /* Q */ |
---|
1423 | { |
---|
1424 | if ((r2->ch<-1)||(r2->ch==1)) /* Z/p(a),Q(a) */ |
---|
1425 | { |
---|
1426 | tmpR.ch=rInternalChar(r2); |
---|
1427 | tmpR.P=rPar(r2); |
---|
1428 | tmpR.parameter=(char **)omAlloc(rPar(r2)*sizeof(char_ptr)); |
---|
1429 | memcpy(tmpR.parameter,r2->parameter,rPar(r2)*sizeof(char_ptr)); |
---|
1430 | if (r2->minpoly!=NULL) |
---|
1431 | { |
---|
1432 | // HANNES: TODO: delete nSetChar |
---|
1433 | rChangeCurrRing(r1); |
---|
1434 | tmpR.minpoly=n_Copy(r2->minpoly, r2); |
---|
1435 | rChangeCurrRing(save); |
---|
1436 | } |
---|
1437 | } |
---|
1438 | else if (r2->ch>1) /* Z/p,GF(p,n) */ |
---|
1439 | { |
---|
1440 | tmpR.ch=r2->ch; |
---|
1441 | if (r2->parameter!=NULL) |
---|
1442 | { |
---|
1443 | tmpR.parameter=(char **)omAllocBin(char_ptr_bin); |
---|
1444 | tmpR.P=1; |
---|
1445 | tmpR.parameter[0]=omStrDup(r2->parameter[0]); |
---|
1446 | } |
---|
1447 | } |
---|
1448 | else |
---|
1449 | { |
---|
1450 | WerrorS("Q+R"); |
---|
1451 | return -1; /* R */ |
---|
1452 | } |
---|
1453 | } |
---|
1454 | else if (r1->ch==1) /* Q(a) */ |
---|
1455 | { |
---|
1456 | if (r2->ch==0) /* Q */ |
---|
1457 | { |
---|
1458 | tmpR.ch=rInternalChar(r1); |
---|
1459 | tmpR.P=rPar(r1); |
---|
1460 | tmpR.parameter=(char **)omAlloc0(rPar(r1)*sizeof(char_ptr)); |
---|
1461 | int i; |
---|
1462 | for(i=0;i<rPar(r1);i++) |
---|
1463 | { |
---|
1464 | tmpR.parameter[i]=omStrDup(r1->parameter[i]); |
---|
1465 | } |
---|
1466 | if (r1->minpoly!=NULL) |
---|
1467 | { |
---|
1468 | // HANNES: TODO: delete nSetChar |
---|
1469 | rChangeCurrRing(r1); |
---|
1470 | tmpR.minpoly=n_Copy(r1->minpoly, r1); |
---|
1471 | rChangeCurrRing(currRing); |
---|
1472 | } |
---|
1473 | } |
---|
1474 | else /* R, Z/p,GF(p,n) */ |
---|
1475 | { |
---|
1476 | WerrorS("Q(a)+(R,Z/p,GF(p,n))"); |
---|
1477 | return -1; |
---|
1478 | } |
---|
1479 | } |
---|
1480 | else /* r1->ch >=2 , Z/p */ |
---|
1481 | { |
---|
1482 | if (r2->ch==0) /* Q */ |
---|
1483 | { |
---|
1484 | tmpR.ch=r1->ch; |
---|
1485 | } |
---|
1486 | else if (r2->ch==-r1->ch) /* Z/p(a) */ |
---|
1487 | { |
---|
1488 | tmpR.ch=rInternalChar(r2); |
---|
1489 | tmpR.P=rPar(r2); |
---|
1490 | tmpR.parameter=(char **)omAlloc(rPar(r2)*sizeof(char_ptr)); |
---|
1491 | int i; |
---|
1492 | for(i=0;i<rPar(r2);i++) |
---|
1493 | { |
---|
1494 | tmpR.parameter[i]=omStrDup(r2->parameter[i]); |
---|
1495 | } |
---|
1496 | if (r2->minpoly!=NULL) |
---|
1497 | { |
---|
1498 | // HANNES: TODO: delete nSetChar |
---|
1499 | rChangeCurrRing(r2); |
---|
1500 | tmpR.minpoly=n_Copy(r2->minpoly, r2); |
---|
1501 | rChangeCurrRing(save); |
---|
1502 | } |
---|
1503 | } |
---|
1504 | else |
---|
1505 | { |
---|
1506 | WerrorS("Z/p+(GF(q,n),Z/q(a),R,Q(a))"); |
---|
1507 | return -1; /* GF(p,n),Z/q(a),R,Q(a) */ |
---|
1508 | } |
---|
1509 | } |
---|
1510 | } |
---|
1511 | /* variable names ========================================================*/ |
---|
1512 | int i,j,k; |
---|
1513 | int l=r1->N+r2->N; |
---|
1514 | char **names=(char **)omAlloc0(l*sizeof(char_ptr)); |
---|
1515 | k=0; |
---|
1516 | |
---|
1517 | // collect all varnames from r1, except those which are parameters |
---|
1518 | // of r2, or those which are the empty string |
---|
1519 | for (i=0;i<r1->N;i++) |
---|
1520 | { |
---|
1521 | BOOLEAN b=TRUE; |
---|
1522 | |
---|
1523 | if (*(r1->names[i]) == '\0') |
---|
1524 | b = FALSE; |
---|
1525 | else if ((r2->parameter!=NULL) && (strlen(r1->names[i])==1)) |
---|
1526 | { |
---|
1527 | for(j=0;j<rPar(r2);j++) |
---|
1528 | { |
---|
1529 | if (strcmp(r1->names[i],r2->parameter[j])==0) |
---|
1530 | { |
---|
1531 | b=FALSE; |
---|
1532 | break; |
---|
1533 | } |
---|
1534 | } |
---|
1535 | } |
---|
1536 | |
---|
1537 | if (b) |
---|
1538 | { |
---|
1539 | //Print("name : %d: %s\n",k,r1->names[i]); |
---|
1540 | names[k]=omStrDup(r1->names[i]); |
---|
1541 | k++; |
---|
1542 | } |
---|
1543 | //else |
---|
1544 | // Print("no name (par1) %s\n",r1->names[i]); |
---|
1545 | } |
---|
1546 | // Add variables from r2, except those which are parameters of r1 |
---|
1547 | // those which are empty strings, and those which equal a var of r1 |
---|
1548 | for(i=0;i<r2->N;i++) |
---|
1549 | { |
---|
1550 | BOOLEAN b=TRUE; |
---|
1551 | |
---|
1552 | if (*(r2->names[i]) == '\0') |
---|
1553 | b = FALSE; |
---|
1554 | else if ((r1->parameter!=NULL) && (strlen(r2->names[i])==1)) |
---|
1555 | { |
---|
1556 | for(j=0;j<rPar(r1);j++) |
---|
1557 | { |
---|
1558 | if (strcmp(r2->names[i],r1->parameter[j])==0) |
---|
1559 | { |
---|
1560 | b=FALSE; |
---|
1561 | break; |
---|
1562 | } |
---|
1563 | } |
---|
1564 | } |
---|
1565 | |
---|
1566 | if (b) |
---|
1567 | { |
---|
1568 | for(j=0;j<r1->N;j++) |
---|
1569 | { |
---|
1570 | if (strcmp(r1->names[j],r2->names[i])==0) |
---|
1571 | { |
---|
1572 | b=FALSE; |
---|
1573 | break; |
---|
1574 | } |
---|
1575 | } |
---|
1576 | if (b) |
---|
1577 | { |
---|
1578 | //Print("name : %d : %s\n",k,r2->names[i]); |
---|
1579 | names[k]=omStrDup(r2->names[i]); |
---|
1580 | k++; |
---|
1581 | } |
---|
1582 | //else |
---|
1583 | // Print("no name (var): %s\n",r2->names[i]); |
---|
1584 | } |
---|
1585 | //else |
---|
1586 | // Print("no name (par): %s\n",r2->names[i]); |
---|
1587 | } |
---|
1588 | // check whether we found any vars at all |
---|
1589 | if (k == 0) |
---|
1590 | { |
---|
1591 | names[k]=omStrDup(""); |
---|
1592 | k=1; |
---|
1593 | } |
---|
1594 | tmpR.N=k; |
---|
1595 | tmpR.names=names; |
---|
1596 | /* ordering *======================================================== */ |
---|
1597 | tmpR.OrdSgn=1; |
---|
1598 | if ((r1->order[0]==ringorder_unspec) |
---|
1599 | && (r2->order[0]==ringorder_unspec)) |
---|
1600 | { |
---|
1601 | tmpR.order=(int*)omAlloc(3*sizeof(int)); |
---|
1602 | tmpR.block0=(int*)omAlloc(3*sizeof(int)); |
---|
1603 | tmpR.block1=(int*)omAlloc(3*sizeof(int)); |
---|
1604 | tmpR.wvhdl=(int**)omAlloc0(3*sizeof(int_ptr)); |
---|
1605 | tmpR.order[0]=ringorder_unspec; |
---|
1606 | tmpR.order[1]=ringorder_C; |
---|
1607 | tmpR.order[2]=0; |
---|
1608 | tmpR.block0[0]=1; |
---|
1609 | tmpR.block1[0]=tmpR.N; |
---|
1610 | } |
---|
1611 | else if (l==k) /* r3=r1+r2 */ |
---|
1612 | { |
---|
1613 | int b; |
---|
1614 | ring rb; |
---|
1615 | if (r1->order[0]==ringorder_unspec) |
---|
1616 | { |
---|
1617 | /* extend order of r2 to r3 */ |
---|
1618 | b=rBlocks(r2); |
---|
1619 | rb=r2; |
---|
1620 | tmpR.OrdSgn=r2->OrdSgn; |
---|
1621 | } |
---|
1622 | else if (r2->order[0]==ringorder_unspec) |
---|
1623 | { |
---|
1624 | /* extend order of r1 to r3 */ |
---|
1625 | b=rBlocks(r1); |
---|
1626 | rb=r1; |
---|
1627 | tmpR.OrdSgn=r1->OrdSgn; |
---|
1628 | } |
---|
1629 | else |
---|
1630 | { |
---|
1631 | b=rBlocks(r1)+rBlocks(r2)-2; /* for only one order C, only one 0 */ |
---|
1632 | rb=NULL; |
---|
1633 | } |
---|
1634 | tmpR.order=(int*)omAlloc0(b*sizeof(int)); |
---|
1635 | tmpR.block0=(int*)omAlloc0(b*sizeof(int)); |
---|
1636 | tmpR.block1=(int*)omAlloc0(b*sizeof(int)); |
---|
1637 | tmpR.wvhdl=(int**)omAlloc0(b*sizeof(int_ptr)); |
---|
1638 | /* weights not implemented yet ...*/ |
---|
1639 | if (rb!=NULL) |
---|
1640 | { |
---|
1641 | for (i=0;i<b;i++) |
---|
1642 | { |
---|
1643 | tmpR.order[i]=rb->order[i]; |
---|
1644 | tmpR.block0[i]=rb->block0[i]; |
---|
1645 | tmpR.block1[i]=rb->block1[i]; |
---|
1646 | if (rb->wvhdl[i]!=NULL) |
---|
1647 | WarnS("rSum: weights not implemented"); |
---|
1648 | } |
---|
1649 | tmpR.block0[0]=1; |
---|
1650 | } |
---|
1651 | else /* ring sum for complete rings */ |
---|
1652 | { |
---|
1653 | for (i=0;r1->order[i]!=0;i++) |
---|
1654 | { |
---|
1655 | tmpR.order[i]=r1->order[i]; |
---|
1656 | tmpR.block0[i]=r1->block0[i]; |
---|
1657 | tmpR.block1[i]=r1->block1[i]; |
---|
1658 | if (r1->wvhdl[i]!=NULL) |
---|
1659 | tmpR.wvhdl[i] = (int*) omMemDup(r1->wvhdl[i]); |
---|
1660 | } |
---|
1661 | j=i; |
---|
1662 | i--; |
---|
1663 | if ((r1->order[i]==ringorder_c) |
---|
1664 | ||(r1->order[i]==ringorder_C)) |
---|
1665 | { |
---|
1666 | j--; |
---|
1667 | tmpR.order[b-2]=r1->order[i]; |
---|
1668 | } |
---|
1669 | for (i=0;r2->order[i]!=0;i++) |
---|
1670 | { |
---|
1671 | if ((r2->order[i]!=ringorder_c) |
---|
1672 | &&(r2->order[i]!=ringorder_C)) |
---|
1673 | { |
---|
1674 | tmpR.order[j]=r2->order[i]; |
---|
1675 | tmpR.block0[j]=r2->block0[i]+r1->N; |
---|
1676 | tmpR.block1[j]=r2->block1[i]+r1->N; |
---|
1677 | if (r2->wvhdl[i]!=NULL) |
---|
1678 | { |
---|
1679 | tmpR.wvhdl[j] = (int*) omMemDup(r2->wvhdl[i]); |
---|
1680 | } |
---|
1681 | j++; |
---|
1682 | } |
---|
1683 | } |
---|
1684 | if((r1->OrdSgn==-1)||(r2->OrdSgn==-1)) |
---|
1685 | tmpR.OrdSgn=-1; |
---|
1686 | } |
---|
1687 | } |
---|
1688 | else if ((k==r1->N) && (k==r2->N)) /* r1 and r2 are "quite" the same ring */ |
---|
1689 | /* copy r1, because we have the variables from r1 */ |
---|
1690 | { |
---|
1691 | int b=rBlocks(r1); |
---|
1692 | |
---|
1693 | tmpR.order=(int*)omAlloc0(b*sizeof(int)); |
---|
1694 | tmpR.block0=(int*)omAlloc0(b*sizeof(int)); |
---|
1695 | tmpR.block1=(int*)omAlloc0(b*sizeof(int)); |
---|
1696 | tmpR.wvhdl=(int**)omAlloc0(b*sizeof(int_ptr)); |
---|
1697 | /* weights not implemented yet ...*/ |
---|
1698 | for (i=0;i<b;i++) |
---|
1699 | { |
---|
1700 | tmpR.order[i]=r1->order[i]; |
---|
1701 | tmpR.block0[i]=r1->block0[i]; |
---|
1702 | tmpR.block1[i]=r1->block1[i]; |
---|
1703 | if (r1->wvhdl[i]!=NULL) |
---|
1704 | { |
---|
1705 | tmpR.wvhdl[i] = (int*) omMemDup(r1->wvhdl[i]); |
---|
1706 | } |
---|
1707 | } |
---|
1708 | tmpR.OrdSgn=r1->OrdSgn; |
---|
1709 | } |
---|
1710 | else |
---|
1711 | { |
---|
1712 | for(i=0;i<k;i++) omFree((ADDRESS)tmpR.names[i]); |
---|
1713 | omFreeSize((ADDRESS)names,tmpR.N*sizeof(char_ptr)); |
---|
1714 | Werror("difficulties with variables: %d,%d -> %d",r1->N,r2->N,k); |
---|
1715 | return -1; |
---|
1716 | } |
---|
1717 | sum=(ring)omAllocBin(ip_sring_bin); |
---|
1718 | memcpy(sum,&tmpR,sizeof(ip_sring)); |
---|
1719 | rComplete(sum); |
---|
1720 | return 1; |
---|
1721 | } |
---|
1722 | /*2 |
---|
1723 | * create a copy of the ring r, which must be equivalent to currRing |
---|
1724 | * used for qring definition,.. |
---|
1725 | * (i.e.: normal rings: same nCopy as currRing; |
---|
1726 | * qring: same nCopy, same idCopy as currRing) |
---|
1727 | * DOES NOT CALL rComplete |
---|
1728 | */ |
---|
1729 | static ring rCopy0(ring r, BOOLEAN copy_qideal = TRUE, |
---|
1730 | BOOLEAN copy_ordering = TRUE) |
---|
1731 | { |
---|
1732 | if (r == NULL) return NULL; |
---|
1733 | int i,j; |
---|
1734 | ring res=(ring)omAllocBin(ip_sring_bin); |
---|
1735 | |
---|
1736 | memcpy4(res,r,sizeof(ip_sring)); |
---|
1737 | res->VarOffset = NULL; |
---|
1738 | res->ref=0; |
---|
1739 | if (r->algring!=NULL) |
---|
1740 | r->algring->ref++; |
---|
1741 | if (r->parameter!=NULL) |
---|
1742 | { |
---|
1743 | res->minpoly=nCopy(r->minpoly); |
---|
1744 | int l=rPar(r); |
---|
1745 | res->parameter=(char **)omAlloc(l*sizeof(char_ptr)); |
---|
1746 | int i; |
---|
1747 | for(i=0;i<rPar(r);i++) |
---|
1748 | { |
---|
1749 | res->parameter[i]=omStrDup(r->parameter[i]); |
---|
1750 | } |
---|
1751 | } |
---|
1752 | if (copy_ordering == TRUE) |
---|
1753 | { |
---|
1754 | i=rBlocks(r); |
---|
1755 | res->wvhdl = (int **)omAlloc(i * sizeof(int_ptr)); |
---|
1756 | res->order = (int *) omAlloc(i * sizeof(int)); |
---|
1757 | res->block0 = (int *) omAlloc(i * sizeof(int)); |
---|
1758 | res->block1 = (int *) omAlloc(i * sizeof(int)); |
---|
1759 | for (j=0; j<i; j++) |
---|
1760 | { |
---|
1761 | if (r->wvhdl[j]!=NULL) |
---|
1762 | { |
---|
1763 | res->wvhdl[j] = (int*) omMemDup(r->wvhdl[j]); |
---|
1764 | } |
---|
1765 | else |
---|
1766 | res->wvhdl[j]=NULL; |
---|
1767 | } |
---|
1768 | memcpy4(res->order,r->order,i * sizeof(int)); |
---|
1769 | memcpy4(res->block0,r->block0,i * sizeof(int)); |
---|
1770 | memcpy4(res->block1,r->block1,i * sizeof(int)); |
---|
1771 | } |
---|
1772 | else |
---|
1773 | { |
---|
1774 | res->wvhdl = NULL; |
---|
1775 | res->order = NULL; |
---|
1776 | res->block0 = NULL; |
---|
1777 | res->block1 = NULL; |
---|
1778 | } |
---|
1779 | |
---|
1780 | res->names = (char **)omAlloc0(r->N * sizeof(char_ptr)); |
---|
1781 | for (i=0; i<res->N; i++) |
---|
1782 | { |
---|
1783 | res->names[i] = omStrDup(r->names[i]); |
---|
1784 | } |
---|
1785 | res->idroot = NULL; |
---|
1786 | if (r->qideal!=NULL) |
---|
1787 | { |
---|
1788 | if (copy_qideal) res->qideal= idrCopyR_NoSort(r->qideal, r); |
---|
1789 | else res->qideal = NULL; |
---|
1790 | } |
---|
1791 | return res; |
---|
1792 | } |
---|
1793 | |
---|
1794 | /*2 |
---|
1795 | * create a copy of the ring r, which must be equivalent to currRing |
---|
1796 | * used for qring definition,.. |
---|
1797 | * (i.e.: normal rings: same nCopy as currRing; |
---|
1798 | * qring: same nCopy, same idCopy as currRing) |
---|
1799 | */ |
---|
1800 | ring rCopy(ring r) |
---|
1801 | { |
---|
1802 | if (r == NULL) return NULL; |
---|
1803 | ring res=rCopy0(r); |
---|
1804 | rComplete(res, 1); |
---|
1805 | return res; |
---|
1806 | } |
---|
1807 | |
---|
1808 | // returns TRUE, if r1 equals r2 FALSE, otherwise Equality is |
---|
1809 | // determined componentwise, if qr == 1, then qrideal equality is |
---|
1810 | // tested, as well |
---|
1811 | BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr) |
---|
1812 | { |
---|
1813 | int i, j; |
---|
1814 | |
---|
1815 | if (r1 == r2) return 1; |
---|
1816 | |
---|
1817 | if (r1 == NULL || r2 == NULL) return 0; |
---|
1818 | |
---|
1819 | if ((rInternalChar(r1) != rInternalChar(r2)) |
---|
1820 | || (r1->float_len != r2->float_len) |
---|
1821 | || (r1->float_len2 != r2->float_len2) |
---|
1822 | || (r1->N != r2->N) |
---|
1823 | || (r1->OrdSgn != r2->OrdSgn) |
---|
1824 | || (rPar(r1) != rPar(r2))) |
---|
1825 | return 0; |
---|
1826 | |
---|
1827 | for (i=0; i<r1->N; i++) |
---|
1828 | { |
---|
1829 | if (r1->names[i] != NULL && r2->names[i] != NULL) |
---|
1830 | { |
---|
1831 | if (strcmp(r1->names[i], r2->names[i])) return 0; |
---|
1832 | } |
---|
1833 | else if ((r1->names[i] != NULL) ^ (r2->names[i] != NULL)) |
---|
1834 | { |
---|
1835 | return 0; |
---|
1836 | } |
---|
1837 | } |
---|
1838 | |
---|
1839 | i=0; |
---|
1840 | while (r1->order[i] != 0) |
---|
1841 | { |
---|
1842 | if (r2->order[i] == 0) return 0; |
---|
1843 | if ((r1->order[i] != r2->order[i]) || |
---|
1844 | (r1->block0[i] != r2->block0[i]) || (r2->block0[i] != r1->block0[i])) |
---|
1845 | return 0; |
---|
1846 | if (r1->wvhdl[i] != NULL) |
---|
1847 | { |
---|
1848 | if (r2->wvhdl[i] == NULL) |
---|
1849 | return 0; |
---|
1850 | for (j=0; j<r1->block1[i]-r1->block0[i]+1; j++) |
---|
1851 | if (r2->wvhdl[i][j] != r1->wvhdl[i][j]) |
---|
1852 | return 0; |
---|
1853 | } |
---|
1854 | else if (r2->wvhdl[i] != NULL) return 0; |
---|
1855 | i++; |
---|
1856 | } |
---|
1857 | |
---|
1858 | for (i=0; i<rPar(r1);i++) |
---|
1859 | { |
---|
1860 | if (strcmp(r1->parameter[i], r2->parameter[i])!=0) |
---|
1861 | return 0; |
---|
1862 | } |
---|
1863 | |
---|
1864 | if (r1->minpoly != NULL) |
---|
1865 | { |
---|
1866 | if (r2->minpoly == NULL) return 0; |
---|
1867 | if (currRing == r1 || currRing == r2) |
---|
1868 | { |
---|
1869 | if (! nEqual(r1->minpoly, r2->minpoly)) return 0; |
---|
1870 | } |
---|
1871 | } |
---|
1872 | else if (r2->minpoly != NULL) return 0; |
---|
1873 | |
---|
1874 | if (qr) |
---|
1875 | { |
---|
1876 | if (r1->qideal != NULL) |
---|
1877 | { |
---|
1878 | ideal id1 = r1->qideal, id2 = r2->qideal; |
---|
1879 | int i, n; |
---|
1880 | poly *m1, *m2; |
---|
1881 | |
---|
1882 | if (id2 == NULL) return 0; |
---|
1883 | if ((n = IDELEMS(id1)) != IDELEMS(id2)) return 0; |
---|
1884 | |
---|
1885 | if (currRing == r1 || currRing == r2) |
---|
1886 | { |
---|
1887 | m1 = id1->m; |
---|
1888 | m2 = id2->m; |
---|
1889 | for (i=0; i<n; i++) |
---|
1890 | if (! pEqualPolys(m1[i],m2[i])) return 0; |
---|
1891 | } |
---|
1892 | } |
---|
1893 | else if (r2->qideal != NULL) return 0; |
---|
1894 | } |
---|
1895 | |
---|
1896 | return 1; |
---|
1897 | } |
---|
1898 | |
---|
1899 | rOrderType_t rGetOrderType(ring r) |
---|
1900 | { |
---|
1901 | // check for simple ordering |
---|
1902 | if (rHasSimpleOrder(r)) |
---|
1903 | { |
---|
1904 | if ((r->order[1] == ringorder_c) || (r->order[1] == ringorder_C)) |
---|
1905 | { |
---|
1906 | switch(r->order[0]) |
---|
1907 | { |
---|
1908 | case ringorder_dp: |
---|
1909 | case ringorder_wp: |
---|
1910 | case ringorder_ds: |
---|
1911 | case ringorder_ws: |
---|
1912 | case ringorder_ls: |
---|
1913 | case ringorder_unspec: |
---|
1914 | if (r->order[1] == ringorder_C || r->order[0] == ringorder_unspec) |
---|
1915 | return rOrderType_ExpComp; |
---|
1916 | return rOrderType_Exp; |
---|
1917 | |
---|
1918 | default: |
---|
1919 | assume(r->order[0] == ringorder_lp || |
---|
1920 | r->order[0] == ringorder_rp || |
---|
1921 | r->order[0] == ringorder_Dp || |
---|
1922 | r->order[0] == ringorder_Wp || |
---|
1923 | r->order[0] == ringorder_Ds || |
---|
1924 | r->order[0] == ringorder_Ws); |
---|
1925 | |
---|
1926 | if (r->order[1] == ringorder_c) return rOrderType_ExpComp; |
---|
1927 | return rOrderType_Exp; |
---|
1928 | } |
---|
1929 | } |
---|
1930 | else |
---|
1931 | { |
---|
1932 | assume((r->order[0]==ringorder_c)||(r->order[0]==ringorder_C)); |
---|
1933 | return rOrderType_CompExp; |
---|
1934 | } |
---|
1935 | } |
---|
1936 | else |
---|
1937 | return rOrderType_General; |
---|
1938 | } |
---|
1939 | |
---|
1940 | BOOLEAN rHasSimpleOrder(ring r) |
---|
1941 | { |
---|
1942 | if (r->order[0] == ringorder_unspec) return TRUE; |
---|
1943 | int blocks = rBlocks(r) - 1; |
---|
1944 | assume(blocks >= 1); |
---|
1945 | if (blocks == 1) return TRUE; |
---|
1946 | if (blocks > 2) return FALSE; |
---|
1947 | if (r->order[0] != ringorder_c && r->order[0] != ringorder_C && |
---|
1948 | r->order[1] != ringorder_c && r->order[1] != ringorder_C) |
---|
1949 | return FALSE; |
---|
1950 | if (r->order[1] == ringorder_M || r->order[0] == ringorder_M) |
---|
1951 | return FALSE; |
---|
1952 | return TRUE; |
---|
1953 | } |
---|
1954 | |
---|
1955 | // returns TRUE, if simple lp or ls ordering |
---|
1956 | BOOLEAN rHasSimpleLexOrder(ring r) |
---|
1957 | { |
---|
1958 | return rHasSimpleOrder(r) && |
---|
1959 | (r->order[0] == ringorder_ls || |
---|
1960 | r->order[0] == ringorder_lp || |
---|
1961 | r->order[1] == ringorder_ls || |
---|
1962 | r->order[1] == ringorder_lp); |
---|
1963 | } |
---|
1964 | |
---|
1965 | BOOLEAN rOrder_is_DegOrdering(rRingOrder_t order) |
---|
1966 | { |
---|
1967 | switch(order) |
---|
1968 | { |
---|
1969 | case ringorder_dp: |
---|
1970 | case ringorder_Dp: |
---|
1971 | case ringorder_ds: |
---|
1972 | case ringorder_Ds: |
---|
1973 | case ringorder_Ws: |
---|
1974 | case ringorder_Wp: |
---|
1975 | case ringorder_ws: |
---|
1976 | case ringorder_wp: |
---|
1977 | return TRUE; |
---|
1978 | |
---|
1979 | default: |
---|
1980 | return FALSE; |
---|
1981 | } |
---|
1982 | } |
---|
1983 | |
---|
1984 | BOOLEAN rOrder_is_WeightedOrdering(rRingOrder_t order) |
---|
1985 | { |
---|
1986 | switch(order) |
---|
1987 | { |
---|
1988 | case ringorder_Ws: |
---|
1989 | case ringorder_Wp: |
---|
1990 | case ringorder_ws: |
---|
1991 | case ringorder_wp: |
---|
1992 | return TRUE; |
---|
1993 | |
---|
1994 | default: |
---|
1995 | return FALSE; |
---|
1996 | } |
---|
1997 | } |
---|
1998 | |
---|
1999 | BOOLEAN rHasSimpleOrderAA(ring r) |
---|
2000 | { |
---|
2001 | int blocks = rBlocks(r) - 1; |
---|
2002 | if (blocks > 3 || blocks < 2) return FALSE; |
---|
2003 | if (blocks == 3) |
---|
2004 | { |
---|
2005 | return ((r->order[0] == ringorder_aa && r->order[1] != ringorder_M && |
---|
2006 | (r->order[2] == ringorder_c || r->order[2] == ringorder_C)) || |
---|
2007 | ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) && |
---|
2008 | r->order[1] == ringorder_aa && r->order[2] != ringorder_M)); |
---|
2009 | } |
---|
2010 | else |
---|
2011 | { |
---|
2012 | return (r->order[0] == ringorder_aa && r->order[1] != ringorder_M); |
---|
2013 | } |
---|
2014 | } |
---|
2015 | |
---|
2016 | // return TRUE if p_SetComp requires p_Setm |
---|
2017 | BOOLEAN rOrd_SetCompRequiresSetm(ring r) |
---|
2018 | { |
---|
2019 | if (r->typ != NULL) |
---|
2020 | { |
---|
2021 | int pos; |
---|
2022 | for (pos=0;pos<r->OrdSize;pos++) |
---|
2023 | { |
---|
2024 | sro_ord* o=&(r->typ[pos]); |
---|
2025 | if (o->ord_typ == ro_syzcomp || o->ord_typ == ro_syz) return TRUE; |
---|
2026 | } |
---|
2027 | } |
---|
2028 | return FALSE; |
---|
2029 | } |
---|
2030 | |
---|
2031 | // return TRUE if p->exp[r->pOrdIndex] holds total degree of p */ |
---|
2032 | BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing) |
---|
2033 | { |
---|
2034 | // Hmm.... what about Syz orderings? |
---|
2035 | return (r->N > 1 && |
---|
2036 | ((rHasSimpleOrder(r) && |
---|
2037 | (rOrder_is_DegOrdering((rRingOrder_t)r->order[0]) || |
---|
2038 | rOrder_is_DegOrdering(( rRingOrder_t)r->order[1]))) || |
---|
2039 | (rHasSimpleOrderAA(r) && |
---|
2040 | (rOrder_is_DegOrdering((rRingOrder_t)r->order[1]) || |
---|
2041 | rOrder_is_DegOrdering((rRingOrder_t)r->order[2]))))); |
---|
2042 | } |
---|
2043 | |
---|
2044 | // return TRUE if p->exp[r->pOrdIndex] holds a weighted degree of p */ |
---|
2045 | BOOLEAN rOrd_is_WeightedDegree_Ordering(ring r =currRing) |
---|
2046 | { |
---|
2047 | // Hmm.... what about Syz orderings? |
---|
2048 | return (r->N > 1 && |
---|
2049 | rHasSimpleOrder(r) && |
---|
2050 | (rOrder_is_WeightedOrdering((rRingOrder_t)r->order[0]) || |
---|
2051 | rOrder_is_WeightedOrdering(( rRingOrder_t)r->order[1]))); |
---|
2052 | } |
---|
2053 | |
---|
2054 | BOOLEAN rIsPolyVar(int v, ring r) |
---|
2055 | { |
---|
2056 | int i=0; |
---|
2057 | while(r->order[i]!=0) |
---|
2058 | { |
---|
2059 | if((r->block0[i]<=v) |
---|
2060 | && (r->block1[i]>=v)) |
---|
2061 | { |
---|
2062 | switch(r->order[i]) |
---|
2063 | { |
---|
2064 | case ringorder_a: |
---|
2065 | return (r->wvhdl[i][v-r->block0[i]]>0); |
---|
2066 | case ringorder_M: |
---|
2067 | return 2; /*don't know*/ |
---|
2068 | case ringorder_lp: |
---|
2069 | case ringorder_rp: |
---|
2070 | case ringorder_dp: |
---|
2071 | case ringorder_Dp: |
---|
2072 | case ringorder_wp: |
---|
2073 | case ringorder_Wp: |
---|
2074 | return TRUE; |
---|
2075 | case ringorder_ls: |
---|
2076 | case ringorder_ds: |
---|
2077 | case ringorder_Ds: |
---|
2078 | case ringorder_ws: |
---|
2079 | case ringorder_Ws: |
---|
2080 | return FALSE; |
---|
2081 | default: |
---|
2082 | break; |
---|
2083 | } |
---|
2084 | } |
---|
2085 | i++; |
---|
2086 | } |
---|
2087 | return 3; /* could not find var v*/ |
---|
2088 | } |
---|
2089 | |
---|
2090 | #ifdef RDEBUG |
---|
2091 | // This should eventually become a full-fledge ring check, like pTest |
---|
2092 | BOOLEAN rDBTest(ring r, char* fn, int l) |
---|
2093 | { |
---|
2094 | int i,j; |
---|
2095 | |
---|
2096 | if (r == NULL) |
---|
2097 | { |
---|
2098 | dReportError("Null ring in %s:%d", fn, l); |
---|
2099 | return FALSE; |
---|
2100 | } |
---|
2101 | |
---|
2102 | |
---|
2103 | if (r->N == 0) return TRUE; |
---|
2104 | |
---|
2105 | // omCheckAddrSize(r,sizeof(ip_sring)); |
---|
2106 | #if OM_CHECK > 0 |
---|
2107 | i=rBlocks(r); |
---|
2108 | omCheckAddrSize(r->order,i*sizeof(int)); |
---|
2109 | omCheckAddrSize(r->block0,i*sizeof(int)); |
---|
2110 | omCheckAddrSize(r->block1,i*sizeof(int)); |
---|
2111 | omCheckAddrSize(r->wvhdl,i*sizeof(int *)); |
---|
2112 | for (j=0;j<i; j++) |
---|
2113 | { |
---|
2114 | if (r->wvhdl[j] != NULL) omCheckAddr(r->wvhdl[j]); |
---|
2115 | } |
---|
2116 | #endif |
---|
2117 | if (r->VarOffset == NULL) |
---|
2118 | { |
---|
2119 | dReportError("Null ring VarOffset -- no rComplete (?) in n %s:%d", fn, l); |
---|
2120 | return FALSE; |
---|
2121 | } |
---|
2122 | omCheckAddrSize(r->VarOffset,(r->N+1)*sizeof(int)); |
---|
2123 | |
---|
2124 | if ((r->OrdSize==0)!=(r->typ==NULL)) |
---|
2125 | { |
---|
2126 | dReportError("mismatch OrdSize and typ-pointer in %s:%d"); |
---|
2127 | return FALSE; |
---|
2128 | } |
---|
2129 | omcheckAddrSize(r->typ,r->OrdSize*sizeof(*(r->typ))); |
---|
2130 | omCheckAddrSize(r->VarOffset,(r->N+1)*sizeof(*(r->VarOffset))); |
---|
2131 | // test assumptions: |
---|
2132 | for(i=0;i<=r->N;i++) |
---|
2133 | { |
---|
2134 | if(r->typ!=NULL) |
---|
2135 | { |
---|
2136 | for(j=0;j<r->OrdSize;j++) |
---|
2137 | { |
---|
2138 | if (r->typ[j].ord_typ==ro_cp) |
---|
2139 | { |
---|
2140 | if(((short)r->VarOffset[i]) == r->typ[j].data.cp.place) |
---|
2141 | dReportError("ordrec %d conflicts with var %d",j,i); |
---|
2142 | } |
---|
2143 | else |
---|
2144 | if ((r->typ[j].ord_typ!=ro_syzcomp) |
---|
2145 | && (r->VarOffset[i] == r->typ[j].data.dp.place)) |
---|
2146 | dReportError("ordrec %d conflicts with var %d",j,i); |
---|
2147 | } |
---|
2148 | } |
---|
2149 | int tmp; |
---|
2150 | tmp=r->VarOffset[i] & 0xffffff; |
---|
2151 | #if SIZEOF_LONG == 8 |
---|
2152 | if ((r->VarOffset[i] >> 24) >63) |
---|
2153 | #else |
---|
2154 | if ((r->VarOffset[i] >> 24) >31) |
---|
2155 | #endif |
---|
2156 | dReportError("bit_start out of range:%d",r->VarOffset[i] >> 24); |
---|
2157 | if (i > 0 && ((tmp<0) ||(tmp>r->ExpL_Size-1))) |
---|
2158 | { |
---|
2159 | dReportError("varoffset out of range for var %d: %d",i,tmp); |
---|
2160 | } |
---|
2161 | } |
---|
2162 | if(r->typ!=NULL) |
---|
2163 | { |
---|
2164 | for(j=0;j<r->OrdSize;j++) |
---|
2165 | { |
---|
2166 | if ((r->typ[j].ord_typ==ro_dp) |
---|
2167 | || (r->typ[j].ord_typ==ro_wp) |
---|
2168 | || (r->typ[j].ord_typ==ro_wp_neg)) |
---|
2169 | { |
---|
2170 | if (r->typ[j].data.dp.start > r->typ[j].data.dp.end) |
---|
2171 | dReportError("in ordrec %d: start(%d) > end(%d)",j, |
---|
2172 | r->typ[j].data.dp.start, r->typ[j].data.dp.end); |
---|
2173 | if ((r->typ[j].data.dp.start < 1) |
---|
2174 | || (r->typ[j].data.dp.end > r->N)) |
---|
2175 | dReportError("in ordrec %d: start(%d)<1 or end(%d)>vars(%d)",j, |
---|
2176 | r->typ[j].data.dp.start, r->typ[j].data.dp.end,r->N); |
---|
2177 | } |
---|
2178 | } |
---|
2179 | } |
---|
2180 | //assume(r->cf!=NULL); |
---|
2181 | |
---|
2182 | return TRUE; |
---|
2183 | } |
---|
2184 | #endif |
---|
2185 | |
---|
2186 | static void rO_Align(int &place, int &bitplace) |
---|
2187 | { |
---|
2188 | // increment place to the next aligned one |
---|
2189 | // (count as Exponent_t,align as longs) |
---|
2190 | if (bitplace!=BITS_PER_LONG) |
---|
2191 | { |
---|
2192 | place++; |
---|
2193 | bitplace=BITS_PER_LONG; |
---|
2194 | } |
---|
2195 | } |
---|
2196 | |
---|
2197 | static void rO_TDegree(int &place, int &bitplace, int start, int end, |
---|
2198 | long *o, sro_ord &ord_struct) |
---|
2199 | { |
---|
2200 | // degree (aligned) of variables v_start..v_end, ordsgn 1 |
---|
2201 | rO_Align(place,bitplace); |
---|
2202 | ord_struct.ord_typ=ro_dp; |
---|
2203 | ord_struct.data.dp.start=start; |
---|
2204 | ord_struct.data.dp.end=end; |
---|
2205 | ord_struct.data.dp.place=place; |
---|
2206 | o[place]=1; |
---|
2207 | place++; |
---|
2208 | rO_Align(place,bitplace); |
---|
2209 | } |
---|
2210 | |
---|
2211 | static void rO_TDegree_neg(int &place, int &bitplace, int start, int end, |
---|
2212 | long *o, sro_ord &ord_struct) |
---|
2213 | { |
---|
2214 | // degree (aligned) of variables v_start..v_end, ordsgn -1 |
---|
2215 | rO_Align(place,bitplace); |
---|
2216 | ord_struct.ord_typ=ro_dp; |
---|
2217 | ord_struct.data.dp.start=start; |
---|
2218 | ord_struct.data.dp.end=end; |
---|
2219 | ord_struct.data.dp.place=place; |
---|
2220 | o[place]=-1; |
---|
2221 | place++; |
---|
2222 | rO_Align(place,bitplace); |
---|
2223 | } |
---|
2224 | |
---|
2225 | static void rO_WDegree(int &place, int &bitplace, int start, int end, |
---|
2226 | long *o, sro_ord &ord_struct, int *weights) |
---|
2227 | { |
---|
2228 | // weighted degree (aligned) of variables v_start..v_end, ordsgn 1 |
---|
2229 | rO_Align(place,bitplace); |
---|
2230 | ord_struct.ord_typ=ro_wp; |
---|
2231 | ord_struct.data.wp.start=start; |
---|
2232 | ord_struct.data.wp.end=end; |
---|
2233 | ord_struct.data.wp.place=place; |
---|
2234 | ord_struct.data.wp.weights=weights; |
---|
2235 | o[place]=1; |
---|
2236 | place++; |
---|
2237 | rO_Align(place,bitplace); |
---|
2238 | int i; |
---|
2239 | for(i=start;i<=end;i++) |
---|
2240 | { |
---|
2241 | if(weights[i-start]<0) |
---|
2242 | { |
---|
2243 | ord_struct.ord_typ=ro_wp_neg; |
---|
2244 | break; |
---|
2245 | } |
---|
2246 | } |
---|
2247 | } |
---|
2248 | |
---|
2249 | static void rO_WDegree_neg(int &place, int &bitplace, int start, int end, |
---|
2250 | long *o, sro_ord &ord_struct, int *weights) |
---|
2251 | { |
---|
2252 | // weighted degree (aligned) of variables v_start..v_end, ordsgn -1 |
---|
2253 | rO_Align(place,bitplace); |
---|
2254 | ord_struct.ord_typ=ro_wp; |
---|
2255 | ord_struct.data.wp.start=start; |
---|
2256 | ord_struct.data.wp.end=end; |
---|
2257 | ord_struct.data.wp.place=place; |
---|
2258 | ord_struct.data.wp.weights=weights; |
---|
2259 | o[place]=-1; |
---|
2260 | place++; |
---|
2261 | rO_Align(place,bitplace); |
---|
2262 | int i; |
---|
2263 | for(i=start;i<=end;i++) |
---|
2264 | { |
---|
2265 | if(weights[i-start]<0) |
---|
2266 | { |
---|
2267 | ord_struct.ord_typ=ro_wp_neg; |
---|
2268 | break; |
---|
2269 | } |
---|
2270 | } |
---|
2271 | } |
---|
2272 | |
---|
2273 | static void rO_LexVars(int &place, int &bitplace, int start, int end, |
---|
2274 | int &prev_ord, long *o,int *v, int bits, int opt_var) |
---|
2275 | { |
---|
2276 | // a block of variables v_start..v_end with lex order, ordsgn 1 |
---|
2277 | int k; |
---|
2278 | int incr=1; |
---|
2279 | if(prev_ord==-1) rO_Align(place,bitplace); |
---|
2280 | |
---|
2281 | if (start>end) |
---|
2282 | { |
---|
2283 | incr=-1; |
---|
2284 | } |
---|
2285 | for(k=start;;k+=incr) |
---|
2286 | { |
---|
2287 | bitplace-=bits; |
---|
2288 | if (bitplace < 0) { bitplace=BITS_PER_LONG-bits; place++; } |
---|
2289 | o[place]=1; |
---|
2290 | v[k]= place | (bitplace << 24); |
---|
2291 | if (k==end) break; |
---|
2292 | } |
---|
2293 | prev_ord=1; |
---|
2294 | if (opt_var!= -1) |
---|
2295 | { |
---|
2296 | assume((opt_var == end+1) ||(opt_var == end-1)); |
---|
2297 | if((opt_var != end+1) &&(opt_var != end-1)) WarnS("hier-2"); |
---|
2298 | int save_bitplace=bitplace; |
---|
2299 | bitplace-=bits; |
---|
2300 | if (bitplace < 0) |
---|
2301 | { |
---|
2302 | bitplace=save_bitplace; |
---|
2303 | return; |
---|
2304 | } |
---|
2305 | // there is enough space for the optional var |
---|
2306 | v[opt_var]=place | (bitplace << 24); |
---|
2307 | } |
---|
2308 | } |
---|
2309 | |
---|
2310 | static void rO_LexVars_neg(int &place, int &bitplace, int start, int end, |
---|
2311 | int &prev_ord, long *o,int *v, int bits, int opt_var) |
---|
2312 | { |
---|
2313 | // a block of variables v_start..v_end with lex order, ordsgn -1 |
---|
2314 | int k; |
---|
2315 | int incr=1; |
---|
2316 | if(prev_ord==1) rO_Align(place,bitplace); |
---|
2317 | |
---|
2318 | if (start>end) |
---|
2319 | { |
---|
2320 | incr=-1; |
---|
2321 | } |
---|
2322 | for(k=start;;k+=incr) |
---|
2323 | { |
---|
2324 | bitplace-=bits; |
---|
2325 | if (bitplace < 0) { bitplace=BITS_PER_LONG-bits; place++; } |
---|
2326 | o[place]=-1; |
---|
2327 | v[k]=place | (bitplace << 24); |
---|
2328 | if (k==end) break; |
---|
2329 | } |
---|
2330 | prev_ord=-1; |
---|
2331 | // #if 0 |
---|
2332 | if (opt_var!= -1) |
---|
2333 | { |
---|
2334 | assume((opt_var == end+1) ||(opt_var == end-1)); |
---|
2335 | if((opt_var != end+1) &&(opt_var != end-1)) WarnS("hier-1"); |
---|
2336 | int save_bitplace=bitplace; |
---|
2337 | bitplace-=bits; |
---|
2338 | if (bitplace < 0) |
---|
2339 | { |
---|
2340 | bitplace=save_bitplace; |
---|
2341 | return; |
---|
2342 | } |
---|
2343 | // there is enough space for the optional var |
---|
2344 | v[opt_var]=place | (bitplace << 24); |
---|
2345 | } |
---|
2346 | // #endif |
---|
2347 | } |
---|
2348 | |
---|
2349 | static void rO_Syzcomp(int &place, int &bitplace, int &prev_ord, |
---|
2350 | long *o, sro_ord &ord_struct) |
---|
2351 | { |
---|
2352 | // ordering is derived from component number |
---|
2353 | rO_Align(place,bitplace); |
---|
2354 | ord_struct.ord_typ=ro_syzcomp; |
---|
2355 | ord_struct.data.syzcomp.place=place; |
---|
2356 | ord_struct.data.syzcomp.Components=NULL; |
---|
2357 | ord_struct.data.syzcomp.ShiftedComponents=NULL; |
---|
2358 | o[place]=1; |
---|
2359 | prev_ord=1; |
---|
2360 | place++; |
---|
2361 | rO_Align(place,bitplace); |
---|
2362 | } |
---|
2363 | |
---|
2364 | static void rO_Syz(int &place, int &bitplace, int &prev_ord, |
---|
2365 | long *o, sro_ord &ord_struct) |
---|
2366 | { |
---|
2367 | // ordering is derived from component number |
---|
2368 | // let's reserve one Exponent_t for it |
---|
2369 | if ((prev_ord== 1) || (bitplace!=BITS_PER_LONG)) |
---|
2370 | rO_Align(place,bitplace); |
---|
2371 | ord_struct.ord_typ=ro_syz; |
---|
2372 | ord_struct.data.syz.place=place; |
---|
2373 | ord_struct.data.syz.limit=0; |
---|
2374 | ord_struct.data.syz.syz_index = NULL; |
---|
2375 | ord_struct.data.syz.curr_index = 1; |
---|
2376 | o[place]= -1; |
---|
2377 | prev_ord=-1; |
---|
2378 | place++; |
---|
2379 | } |
---|
2380 | |
---|
2381 | static unsigned long rGetExpSize(unsigned long bitmask, int & bits) |
---|
2382 | { |
---|
2383 | if (bitmask == 0) |
---|
2384 | { |
---|
2385 | bits=16; bitmask=0xffff; |
---|
2386 | } |
---|
2387 | else if (bitmask <= 1) |
---|
2388 | { |
---|
2389 | bits=1; bitmask = 1; |
---|
2390 | } |
---|
2391 | else if (bitmask <= 3) |
---|
2392 | { |
---|
2393 | bits=2; bitmask = 3; |
---|
2394 | } |
---|
2395 | else if (bitmask <= 7) |
---|
2396 | { |
---|
2397 | bits=3; bitmask=7; |
---|
2398 | } |
---|
2399 | else if (bitmask <= 0xf) |
---|
2400 | { |
---|
2401 | bits=4; bitmask=0xf; |
---|
2402 | } |
---|
2403 | else if (bitmask <= 0x1f) |
---|
2404 | { |
---|
2405 | bits=5; bitmask=0x1f; |
---|
2406 | } |
---|
2407 | else if (bitmask <= 0x3f) |
---|
2408 | { |
---|
2409 | bits=6; bitmask=0x3f; |
---|
2410 | } |
---|
2411 | #if SIZEOF_LONG == 8 |
---|
2412 | else if (bitmask <= 0x7f) |
---|
2413 | { |
---|
2414 | bits=7; bitmask=0x7f; /* 64 bit longs only */ |
---|
2415 | } |
---|
2416 | #endif |
---|
2417 | else if (bitmask <= 0xff) |
---|
2418 | { |
---|
2419 | bits=8; bitmask=0xff; |
---|
2420 | } |
---|
2421 | #if SIZEOF_LONG == 8 |
---|
2422 | else if (bitmask <= 0x1ff) |
---|
2423 | { |
---|
2424 | bits=9; bitmask=0x1ff; /* 64 bit longs only */ |
---|
2425 | } |
---|
2426 | #endif |
---|
2427 | else if (bitmask <= 0x3ff) |
---|
2428 | { |
---|
2429 | bits=10; bitmask=0x3ff; |
---|
2430 | } |
---|
2431 | #if SIZEOF_LONG == 8 |
---|
2432 | else if (bitmask <= 0xfff) |
---|
2433 | { |
---|
2434 | bits=12; bitmask=0xfff; /* 64 bit longs only */ |
---|
2435 | } |
---|
2436 | #endif |
---|
2437 | else if (bitmask <= 0xffff) |
---|
2438 | { |
---|
2439 | bits=16; bitmask=0xffff; |
---|
2440 | } |
---|
2441 | #if SIZEOF_LONG == 8 |
---|
2442 | else if (bitmask <= 0xfffff) |
---|
2443 | { |
---|
2444 | bits=20; bitmask=0xfffff; /* 64 bit longs only */ |
---|
2445 | } |
---|
2446 | else if (bitmask <= 0xffffffff) |
---|
2447 | { |
---|
2448 | bits=32; bitmask=0xffffffff; |
---|
2449 | } |
---|
2450 | else |
---|
2451 | { |
---|
2452 | bits=64; bitmask=0xffffffffffffffff; |
---|
2453 | } |
---|
2454 | #else |
---|
2455 | else |
---|
2456 | { |
---|
2457 | bits=32; bitmask=0xffffffff; |
---|
2458 | } |
---|
2459 | #endif |
---|
2460 | return bitmask; |
---|
2461 | } |
---|
2462 | |
---|
2463 | /*2 |
---|
2464 | * optimize rGetExpSize for a block of N variables, exp <=bitmask |
---|
2465 | */ |
---|
2466 | static unsigned long rGetExpSize(unsigned long bitmask, int & bits, int N) |
---|
2467 | { |
---|
2468 | bitmask =rGetExpSize(bitmask, bits); |
---|
2469 | int vars_per_long=BIT_SIZEOF_LONG/bits; |
---|
2470 | int bits1; |
---|
2471 | loop |
---|
2472 | { |
---|
2473 | if (bits == BIT_SIZEOF_LONG) |
---|
2474 | { |
---|
2475 | bits = BIT_SIZEOF_LONG - 1; |
---|
2476 | return LONG_MAX; |
---|
2477 | } |
---|
2478 | unsigned long bitmask1 =rGetExpSize(bitmask+1, bits1); |
---|
2479 | int vars_per_long1=BIT_SIZEOF_LONG/bits1; |
---|
2480 | if ((((N+vars_per_long-1)/vars_per_long) == |
---|
2481 | ((N+vars_per_long1-1)/vars_per_long1))) |
---|
2482 | { |
---|
2483 | vars_per_long=vars_per_long1; |
---|
2484 | bits=bits1; |
---|
2485 | bitmask=bitmask1; |
---|
2486 | } |
---|
2487 | else |
---|
2488 | { |
---|
2489 | return bitmask; /* and bits */ |
---|
2490 | } |
---|
2491 | } |
---|
2492 | } |
---|
2493 | |
---|
2494 | /*2 |
---|
2495 | * create a copy of the ring r, which must be equivalent to currRing |
---|
2496 | * used for std computations |
---|
2497 | * may share data structures with currRing |
---|
2498 | * DOES CALL rComplete |
---|
2499 | */ |
---|
2500 | ring rModifyRing(ring r, BOOLEAN omit_degree, |
---|
2501 | BOOLEAN omit_comp, |
---|
2502 | unsigned long exp_limit) |
---|
2503 | { |
---|
2504 | assume (r != NULL ); |
---|
2505 | assume (exp_limit > 1); |
---|
2506 | BOOLEAN need_other_ring; |
---|
2507 | BOOLEAN omitted_degree = FALSE; |
---|
2508 | int bits; |
---|
2509 | |
---|
2510 | exp_limit=rGetExpSize(exp_limit, bits, r->N); |
---|
2511 | need_other_ring = (exp_limit != r->bitmask); |
---|
2512 | |
---|
2513 | int nblocks=rBlocks(r); |
---|
2514 | int *order=(int*)omAlloc0((nblocks+1)*sizeof(int)); |
---|
2515 | int *block0=(int*)omAlloc0((nblocks+1)*sizeof(int)); |
---|
2516 | int *block1=(int*)omAlloc0((nblocks+1)*sizeof(int)); |
---|
2517 | int **wvhdl=(int**)omAlloc0((nblocks+1)*sizeof(int_ptr)); |
---|
2518 | |
---|
2519 | int i=0; |
---|
2520 | int j=0; /* i index in r, j index in res */ |
---|
2521 | loop |
---|
2522 | { |
---|
2523 | BOOLEAN copy_block_index=TRUE; |
---|
2524 | int r_ord=r->order[i]; |
---|
2525 | if (r->block0[i]==r->block1[i]) |
---|
2526 | { |
---|
2527 | switch(r_ord) |
---|
2528 | { |
---|
2529 | case ringorder_wp: |
---|
2530 | case ringorder_dp: |
---|
2531 | case ringorder_Wp: |
---|
2532 | case ringorder_Dp: |
---|
2533 | r_ord=ringorder_lp; |
---|
2534 | break; |
---|
2535 | case ringorder_Ws: |
---|
2536 | case ringorder_Ds: |
---|
2537 | case ringorder_ws: |
---|
2538 | case ringorder_ds: |
---|
2539 | r_ord=ringorder_ls; |
---|
2540 | break; |
---|
2541 | default: |
---|
2542 | break; |
---|
2543 | } |
---|
2544 | } |
---|
2545 | switch(r_ord) |
---|
2546 | { |
---|
2547 | case ringorder_C: |
---|
2548 | case ringorder_c: |
---|
2549 | if (!omit_comp) |
---|
2550 | { |
---|
2551 | order[j]=r_ord; /*r->order[i]*/; |
---|
2552 | } |
---|
2553 | else |
---|
2554 | { |
---|
2555 | j--; |
---|
2556 | need_other_ring=TRUE; |
---|
2557 | omit_comp=FALSE; |
---|
2558 | copy_block_index=FALSE; |
---|
2559 | } |
---|
2560 | break; |
---|
2561 | case ringorder_wp: |
---|
2562 | case ringorder_dp: |
---|
2563 | case ringorder_ws: |
---|
2564 | case ringorder_ds: |
---|
2565 | if(!omit_degree) |
---|
2566 | { |
---|
2567 | order[j]=r_ord; /*r->order[i]*/; |
---|
2568 | } |
---|
2569 | else |
---|
2570 | { |
---|
2571 | order[j]=ringorder_rp; |
---|
2572 | need_other_ring=TRUE; |
---|
2573 | omit_degree=FALSE; |
---|
2574 | omitted_degree = TRUE; |
---|
2575 | } |
---|
2576 | break; |
---|
2577 | case ringorder_Wp: |
---|
2578 | case ringorder_Dp: |
---|
2579 | case ringorder_Ws: |
---|
2580 | case ringorder_Ds: |
---|
2581 | if(!omit_degree) |
---|
2582 | { |
---|
2583 | order[j]=r_ord; /*r->order[i];*/ |
---|
2584 | } |
---|
2585 | else |
---|
2586 | { |
---|
2587 | order[j]=ringorder_lp; |
---|
2588 | need_other_ring=TRUE; |
---|
2589 | omit_degree=FALSE; |
---|
2590 | omitted_degree = TRUE; |
---|
2591 | } |
---|
2592 | break; |
---|
2593 | default: |
---|
2594 | order[j]=r_ord; /*r->order[i];*/ |
---|
2595 | break; |
---|
2596 | } |
---|
2597 | if (copy_block_index) |
---|
2598 | { |
---|
2599 | block0[j]=r->block0[i]; |
---|
2600 | block1[j]=r->block1[i]; |
---|
2601 | wvhdl[j]=r->wvhdl[i]; |
---|
2602 | } |
---|
2603 | i++;j++; |
---|
2604 | // order[j]=ringorder_no; // done by omAlloc0 |
---|
2605 | if (i==nblocks) break; |
---|
2606 | } |
---|
2607 | if(!need_other_ring) |
---|
2608 | { |
---|
2609 | omFreeSize(order,(nblocks+1)*sizeof(int)); |
---|
2610 | omFreeSize(block0,(nblocks+1)*sizeof(int)); |
---|
2611 | omFreeSize(block1,(nblocks+1)*sizeof(int)); |
---|
2612 | omFreeSize(wvhdl,(nblocks+1)*sizeof(int_ptr)); |
---|
2613 | return r; |
---|
2614 | } |
---|
2615 | ring res=(ring)omAlloc0Bin(ip_sring_bin); |
---|
2616 | *res = *r; |
---|
2617 | // res->qideal, res->idroot ??? |
---|
2618 | res->wvhdl=wvhdl; |
---|
2619 | res->order=order; |
---|
2620 | res->block0=block0; |
---|
2621 | res->block1=block1; |
---|
2622 | res->bitmask=exp_limit; |
---|
2623 | int tmpref=r->cf->ref; |
---|
2624 | rComplete(res, 1); |
---|
2625 | r->cf->ref=tmpref; |
---|
2626 | |
---|
2627 | // adjust res->pFDeg: if it was changed globally, then |
---|
2628 | // it must also be changed for new ring |
---|
2629 | if (r->pFDegOrig != res->pFDegOrig && |
---|
2630 | rOrd_is_WeightedDegree_Ordering(r)) |
---|
2631 | { |
---|
2632 | // still might need adjustment for weighted orderings |
---|
2633 | // and omit_degree |
---|
2634 | res->firstwv = r->firstwv; |
---|
2635 | res->firstBlockEnds = r->firstBlockEnds; |
---|
2636 | res->pFDeg = res->pFDegOrig = pWFirstTotalDegree; |
---|
2637 | } |
---|
2638 | if (omitted_degree) |
---|
2639 | res->pLDeg = res->pLDegOrig = r->pLDegOrig; |
---|
2640 | |
---|
2641 | rOptimizeLDeg(res); |
---|
2642 | |
---|
2643 | // set syzcomp |
---|
2644 | if (res->typ != NULL && res->typ[0].ord_typ == ro_syz) |
---|
2645 | { |
---|
2646 | res->typ[0] = r->typ[0]; |
---|
2647 | if (r->typ[0].data.syz.limit > 0) |
---|
2648 | { |
---|
2649 | res->typ[0].data.syz.syz_index |
---|
2650 | = (int*) omAlloc((r->typ[0].data.syz.limit +1)*sizeof(int)); |
---|
2651 | memcpy(res->typ[0].data.syz.syz_index, r->typ[0].data.syz.syz_index, |
---|
2652 | (r->typ[0].data.syz.limit +1)*sizeof(int)); |
---|
2653 | } |
---|
2654 | } |
---|
2655 | return res; |
---|
2656 | } |
---|
2657 | |
---|
2658 | void rKillModifiedRing(ring r) |
---|
2659 | { |
---|
2660 | rUnComplete(r); |
---|
2661 | omFree(r->order); |
---|
2662 | omFree(r->block0); |
---|
2663 | omFree(r->block1); |
---|
2664 | omFree(r->wvhdl); |
---|
2665 | omFreeBin(r,ip_sring_bin); |
---|
2666 | } |
---|
2667 | |
---|
2668 | static void rSetOutParams(ring r) |
---|
2669 | { |
---|
2670 | r->VectorOut = (r->order[0] == ringorder_c); |
---|
2671 | r->ShortOut = TRUE; |
---|
2672 | #ifdef HAVE_TCL |
---|
2673 | if (tcllmode) |
---|
2674 | { |
---|
2675 | r->ShortOut = FALSE; |
---|
2676 | } |
---|
2677 | else |
---|
2678 | #endif |
---|
2679 | { |
---|
2680 | int i; |
---|
2681 | if ((r->parameter!=NULL) && (r->ch<2)) |
---|
2682 | { |
---|
2683 | for (i=0;i<rPar(r);i++) |
---|
2684 | { |
---|
2685 | if(strlen(r->parameter[i])>1) |
---|
2686 | { |
---|
2687 | r->ShortOut=FALSE; |
---|
2688 | break; |
---|
2689 | } |
---|
2690 | } |
---|
2691 | } |
---|
2692 | if (r->ShortOut) |
---|
2693 | { |
---|
2694 | // Hmm... sometimes (e.g., from maGetPreimage) new variables |
---|
2695 | // are intorduced, but their names are never set |
---|
2696 | // hence, we do the following awkward trick |
---|
2697 | int N = omSizeWOfAddr(r->names); |
---|
2698 | if (r->N < N) N = r->N; |
---|
2699 | |
---|
2700 | for (i=(N-1);i>=0;i--) |
---|
2701 | { |
---|
2702 | if(r->names[i] != NULL && strlen(r->names[i])>1) |
---|
2703 | { |
---|
2704 | r->ShortOut=FALSE; |
---|
2705 | break; |
---|
2706 | } |
---|
2707 | } |
---|
2708 | } |
---|
2709 | } |
---|
2710 | r->CanShortOut = r->ShortOut; |
---|
2711 | } |
---|
2712 | |
---|
2713 | /*2 |
---|
2714 | * sets pMixedOrder and pComponentOrder for orderings with more than one block |
---|
2715 | * block of variables (ip is the block number, o_r the number of the ordering) |
---|
2716 | * o is the position of the orderingering in r |
---|
2717 | */ |
---|
2718 | static void rHighSet(ring r, int o_r, int o) |
---|
2719 | { |
---|
2720 | switch(o_r) |
---|
2721 | { |
---|
2722 | case ringorder_lp: |
---|
2723 | case ringorder_dp: |
---|
2724 | case ringorder_Dp: |
---|
2725 | case ringorder_wp: |
---|
2726 | case ringorder_Wp: |
---|
2727 | case ringorder_rp: |
---|
2728 | case ringorder_a: |
---|
2729 | case ringorder_aa: |
---|
2730 | if (r->OrdSgn==-1) r->MixedOrder=TRUE; |
---|
2731 | break; |
---|
2732 | case ringorder_ls: |
---|
2733 | case ringorder_ds: |
---|
2734 | case ringorder_Ds: |
---|
2735 | case ringorder_s: |
---|
2736 | break; |
---|
2737 | case ringorder_ws: |
---|
2738 | case ringorder_Ws: |
---|
2739 | { |
---|
2740 | int i; |
---|
2741 | for(i=r->block1[o]-r->block0[o];i>=0;i--) |
---|
2742 | if (r->wvhdl[o][i]<0) { r->MixedOrder=TRUE; break; } |
---|
2743 | } |
---|
2744 | break; |
---|
2745 | case ringorder_c: |
---|
2746 | r->ComponentOrder=1; |
---|
2747 | break; |
---|
2748 | case ringorder_C: |
---|
2749 | case ringorder_S: |
---|
2750 | r->ComponentOrder=-1; |
---|
2751 | break; |
---|
2752 | case ringorder_M: |
---|
2753 | r->MixedOrder=TRUE; |
---|
2754 | break; |
---|
2755 | default: |
---|
2756 | dReportError("wrong internal ordering:%d at %s, l:%d\n",o_r,__FILE__,__LINE__); |
---|
2757 | } |
---|
2758 | } |
---|
2759 | |
---|
2760 | static void rSetFirstWv(ring r, int i, int* order, int* block1, int** wvhdl) |
---|
2761 | { |
---|
2762 | // cheat for ringorder_aa |
---|
2763 | if (order[i] == ringorder_aa) |
---|
2764 | i++; |
---|
2765 | if(block1[i]!=r->N) r->LexOrder=TRUE; |
---|
2766 | r->firstBlockEnds=block1[i]; |
---|
2767 | r->firstwv = wvhdl[i]; |
---|
2768 | if ((order[i]== ringorder_ws) || (order[i]==ringorder_Ws)) |
---|
2769 | { |
---|
2770 | int j; |
---|
2771 | for(j=block1[i]-r->block0[i];j>=0;j--) |
---|
2772 | if (r->firstwv[j]<0) { r->MixedOrder=TRUE; break; } |
---|
2773 | } |
---|
2774 | } |
---|
2775 | |
---|
2776 | static void rOptimizeLDeg(ring r) |
---|
2777 | { |
---|
2778 | if (r->pFDeg == pDeg) |
---|
2779 | { |
---|
2780 | if (r->pLDeg == pLDeg1) |
---|
2781 | r->pLDeg = pLDeg1_Deg; |
---|
2782 | if (r->pLDeg == pLDeg1c) |
---|
2783 | r->pLDeg = pLDeg1c_Deg; |
---|
2784 | } |
---|
2785 | else if (r->pFDeg == pTotaldegree) |
---|
2786 | { |
---|
2787 | if (r->pLDeg == pLDeg1) |
---|
2788 | r->pLDeg = pLDeg1_Totaldegree; |
---|
2789 | if (r->pLDeg == pLDeg1c) |
---|
2790 | r->pLDeg = pLDeg1c_Totaldegree; |
---|
2791 | } |
---|
2792 | else if (r->pFDeg == pWFirstTotalDegree) |
---|
2793 | { |
---|
2794 | if (r->pLDeg == pLDeg1) |
---|
2795 | r->pLDeg = pLDeg1_WFirstTotalDegree; |
---|
2796 | if (r->pLDeg == pLDeg1c) |
---|
2797 | r->pLDeg = pLDeg1c_WFirstTotalDegree; |
---|
2798 | } |
---|
2799 | } |
---|
2800 | |
---|
2801 | // set pFDeg, pLDeg, MixOrder, ComponentOrder, etc |
---|
2802 | static void rSetDegStuff(ring r) |
---|
2803 | { |
---|
2804 | int* order = r->order; |
---|
2805 | int* block0 = r->block0; |
---|
2806 | int* block1 = r->block1; |
---|
2807 | int** wvhdl = r->wvhdl; |
---|
2808 | |
---|
2809 | if (order[0]==ringorder_S ||order[0]==ringorder_s) |
---|
2810 | { |
---|
2811 | order++; |
---|
2812 | block0++; |
---|
2813 | block1++; |
---|
2814 | wvhdl++; |
---|
2815 | } |
---|
2816 | r->LexOrder = FALSE; |
---|
2817 | r->MixedOrder = FALSE; |
---|
2818 | r->ComponentOrder = 1; |
---|
2819 | r->pFDeg = pTotaldegree; |
---|
2820 | r->pLDeg = (r->OrdSgn == 1 ? pLDegb : pLDeg0); |
---|
2821 | |
---|
2822 | /*======== ordering type is (_,c) =========================*/ |
---|
2823 | if ((order[0]==ringorder_unspec) || (order[1] == 0) |
---|
2824 | ||( |
---|
2825 | ((order[1]==ringorder_c)||(order[1]==ringorder_C) |
---|
2826 | ||(order[1]==ringorder_S) |
---|
2827 | ||(order[1]==ringorder_s)) |
---|
2828 | && (order[0]!=ringorder_M) |
---|
2829 | && (order[2]==0)) |
---|
2830 | ) |
---|
2831 | { |
---|
2832 | if ((order[0]!=ringorder_unspec) |
---|
2833 | && ((order[1]==ringorder_C)||(order[1]==ringorder_S)|| |
---|
2834 | (order[1]==ringorder_s))) |
---|
2835 | r->ComponentOrder=-1; |
---|
2836 | if (r->OrdSgn == -1) r->pLDeg = pLDeg0c; |
---|
2837 | if ((order[0] == ringorder_lp) || (order[0] == ringorder_ls) || order[0] == ringorder_rp) |
---|
2838 | { |
---|
2839 | r->LexOrder=TRUE; |
---|
2840 | r->pLDeg = pLDeg1c; |
---|
2841 | } |
---|
2842 | if (order[0] == ringorder_wp || order[0] == ringorder_Wp || |
---|
2843 | order[0] == ringorder_ws || order[0] == ringorder_Ws) |
---|
2844 | r->pFDeg = pWFirstTotalDegree; |
---|
2845 | r->firstBlockEnds=block1[0]; |
---|
2846 | r->firstwv = wvhdl[0]; |
---|
2847 | } |
---|
2848 | /*======== ordering type is (c,_) =========================*/ |
---|
2849 | else if (((order[0]==ringorder_c) |
---|
2850 | ||(order[0]==ringorder_C) |
---|
2851 | ||(order[0]==ringorder_S) |
---|
2852 | ||(order[0]==ringorder_s)) |
---|
2853 | && (order[1]!=ringorder_M) |
---|
2854 | && (order[2]==0)) |
---|
2855 | { |
---|
2856 | if ((order[0]==ringorder_C)||(order[0]==ringorder_S)|| |
---|
2857 | order[0]==ringorder_s) |
---|
2858 | r->ComponentOrder=-1; |
---|
2859 | if ((order[1] == ringorder_lp) || (order[1] == ringorder_ls) || order[1] == ringorder_rp) |
---|
2860 | { |
---|
2861 | r->LexOrder=TRUE; |
---|
2862 | r->pLDeg = pLDeg1c; |
---|
2863 | } |
---|
2864 | r->firstBlockEnds=block1[1]; |
---|
2865 | r->firstwv = wvhdl[1]; |
---|
2866 | if (order[1] == ringorder_wp || order[1] == ringorder_Wp || |
---|
2867 | order[1] == ringorder_ws || order[1] == ringorder_Ws) |
---|
2868 | r->pFDeg = pWFirstTotalDegree; |
---|
2869 | } |
---|
2870 | /*------- more than one block ----------------------*/ |
---|
2871 | else |
---|
2872 | { |
---|
2873 | if ((r->VectorOut)||(order[0]==ringorder_C)||(order[0]==ringorder_S)||(order[0]==ringorder_s)) |
---|
2874 | { |
---|
2875 | rSetFirstWv(r, 1, order, block1, wvhdl); |
---|
2876 | } |
---|
2877 | else |
---|
2878 | rSetFirstWv(r, 0, order, block1, wvhdl); |
---|
2879 | |
---|
2880 | /*the number of orderings:*/ |
---|
2881 | int i = 0; |
---|
2882 | while (order[++i] != 0); |
---|
2883 | do |
---|
2884 | { |
---|
2885 | i--; |
---|
2886 | rHighSet(r, order[i],i); |
---|
2887 | } |
---|
2888 | while (i != 0); |
---|
2889 | |
---|
2890 | if ((order[0]!=ringorder_c) |
---|
2891 | && (order[0]!=ringorder_C) |
---|
2892 | && (order[0]!=ringorder_S) |
---|
2893 | && (order[0]!=ringorder_s)) |
---|
2894 | { |
---|
2895 | r->pLDeg = pLDeg1c; |
---|
2896 | } |
---|
2897 | else |
---|
2898 | { |
---|
2899 | r->pLDeg = pLDeg1; |
---|
2900 | } |
---|
2901 | r->pFDeg = pWTotaldegree; // may be improved: pTotaldegree for lp/dp/ls/.. blocks |
---|
2902 | } |
---|
2903 | if (rOrd_is_Totaldegree_Ordering(r) || rOrd_is_WeightedDegree_Ordering(r)) |
---|
2904 | r->pFDeg = pDeg; |
---|
2905 | |
---|
2906 | r->pFDegOrig = r->pFDeg; |
---|
2907 | r->pLDegOrig = r->pLDeg; |
---|
2908 | rOptimizeLDeg(r); |
---|
2909 | } |
---|
2910 | |
---|
2911 | /*2 |
---|
2912 | * set NegWeightL_Size, NegWeightL_Offset |
---|
2913 | */ |
---|
2914 | static void rSetNegWeight(ring r) |
---|
2915 | { |
---|
2916 | int i,l; |
---|
2917 | if (r->typ!=NULL) |
---|
2918 | { |
---|
2919 | l=0; |
---|
2920 | for(i=0;i<r->OrdSize;i++) |
---|
2921 | { |
---|
2922 | if(r->typ[i].ord_typ==ro_wp_neg) l++; |
---|
2923 | } |
---|
2924 | if (l>0) |
---|
2925 | { |
---|
2926 | r->NegWeightL_Size=l; |
---|
2927 | r->NegWeightL_Offset=(int *) omAlloc(l*sizeof(int)); |
---|
2928 | l=0; |
---|
2929 | for(i=0;i<r->OrdSize;i++) |
---|
2930 | { |
---|
2931 | if(r->typ[i].ord_typ==ro_wp_neg) |
---|
2932 | { |
---|
2933 | r->NegWeightL_Offset[l]=r->typ[i].data.wp.place; |
---|
2934 | l++; |
---|
2935 | } |
---|
2936 | } |
---|
2937 | return; |
---|
2938 | } |
---|
2939 | } |
---|
2940 | r->NegWeightL_Size = 0; |
---|
2941 | r->NegWeightL_Offset = NULL; |
---|
2942 | } |
---|
2943 | |
---|
2944 | static void rSetOption(ring r) |
---|
2945 | { |
---|
2946 | // set redthrough |
---|
2947 | if (!TEST_OPT_OLDSTD && r->OrdSgn == 1 && ! r->LexOrder) |
---|
2948 | r->options |= Sy_bit(OPT_REDTHROUGH); |
---|
2949 | else |
---|
2950 | r->options &= ~Sy_bit(OPT_REDTHROUGH); |
---|
2951 | |
---|
2952 | // set intStrategy |
---|
2953 | if (rField_is_Extension(r) || rField_is_Q(r)) |
---|
2954 | r->options |= Sy_bit(OPT_INTSTRATEGY); |
---|
2955 | else |
---|
2956 | r->options &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
2957 | |
---|
2958 | // set redTail |
---|
2959 | if (r->LexOrder || r->OrdSgn == -1 || rField_is_Extension(r)) |
---|
2960 | r->options &= ~Sy_bit(OPT_REDTAIL); |
---|
2961 | else |
---|
2962 | r->options |= Sy_bit(OPT_REDTAIL); |
---|
2963 | } |
---|
2964 | |
---|
2965 | BOOLEAN rComplete(ring r, int force) |
---|
2966 | { |
---|
2967 | if (r->VarOffset!=NULL && force == 0) return FALSE; |
---|
2968 | nInitChar(r); |
---|
2969 | rSetOutParams(r); |
---|
2970 | rSetDegStuff(r); |
---|
2971 | rSetOption(r); |
---|
2972 | int n=rBlocks(r)-1; |
---|
2973 | int i; |
---|
2974 | int bits; |
---|
2975 | r->bitmask=rGetExpSize(r->bitmask,bits,r->N); |
---|
2976 | r->BitsPerExp = bits; |
---|
2977 | r->ExpPerLong = BIT_SIZEOF_LONG / bits; |
---|
2978 | r->divmask=rGetDivMask(bits); |
---|
2979 | |
---|
2980 | // will be used for ordsgn: |
---|
2981 | long *tmp_ordsgn=(long *)omAlloc0(2*(n+r->N)*sizeof(long)); |
---|
2982 | // will be used for VarOffset: |
---|
2983 | int *v=(int *)omAlloc((r->N+1)*sizeof(int)); |
---|
2984 | for(i=r->N; i>=0 ; i--) |
---|
2985 | { |
---|
2986 | v[i]=-1; |
---|
2987 | } |
---|
2988 | sro_ord *tmp_typ=(sro_ord *)omAlloc0(2*(n+r->N)*sizeof(sro_ord)); |
---|
2989 | int typ_i=0; |
---|
2990 | int prev_ordsgn=0; |
---|
2991 | |
---|
2992 | // fill in v, tmp_typ, tmp_ordsgn, determine typ_i (== ordSize) |
---|
2993 | int j=0; |
---|
2994 | int j_bits=BITS_PER_LONG; |
---|
2995 | BOOLEAN need_to_add_comp=FALSE; |
---|
2996 | for(i=0;i<n;i++) |
---|
2997 | { |
---|
2998 | tmp_typ[typ_i].order_index=i; |
---|
2999 | switch (r->order[i]) |
---|
3000 | { |
---|
3001 | case ringorder_a: |
---|
3002 | case ringorder_aa: |
---|
3003 | rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,tmp_typ[typ_i], |
---|
3004 | r->wvhdl[i]); |
---|
3005 | typ_i++; |
---|
3006 | break; |
---|
3007 | |
---|
3008 | case ringorder_c: |
---|
3009 | rO_Align(j, j_bits); |
---|
3010 | rO_LexVars_neg(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1); |
---|
3011 | break; |
---|
3012 | |
---|
3013 | case ringorder_C: |
---|
3014 | rO_Align(j, j_bits); |
---|
3015 | rO_LexVars(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1); |
---|
3016 | break; |
---|
3017 | |
---|
3018 | case ringorder_M: |
---|
3019 | { |
---|
3020 | int k,l; |
---|
3021 | k=r->block1[i]-r->block0[i]+1; // number of vars |
---|
3022 | for(l=0;l<k;l++) |
---|
3023 | { |
---|
3024 | rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3025 | tmp_typ[typ_i], |
---|
3026 | r->wvhdl[i]+(r->block1[i]-r->block0[i]+1)*l); |
---|
3027 | typ_i++; |
---|
3028 | } |
---|
3029 | break; |
---|
3030 | } |
---|
3031 | |
---|
3032 | case ringorder_lp: |
---|
3033 | rO_LexVars(j, j_bits, r->block0[i],r->block1[i], prev_ordsgn, |
---|
3034 | tmp_ordsgn,v,bits, -1); |
---|
3035 | break; |
---|
3036 | |
---|
3037 | case ringorder_ls: |
---|
3038 | rO_LexVars_neg(j, j_bits, r->block0[i],r->block1[i], prev_ordsgn, |
---|
3039 | tmp_ordsgn,v, bits, -1); |
---|
3040 | break; |
---|
3041 | |
---|
3042 | case ringorder_rp: |
---|
3043 | rO_LexVars_neg(j, j_bits, r->block1[i],r->block0[i], prev_ordsgn, |
---|
3044 | tmp_ordsgn,v, bits, -1); |
---|
3045 | break; |
---|
3046 | |
---|
3047 | case ringorder_dp: |
---|
3048 | if (r->block0[i]==r->block1[i]) |
---|
3049 | { |
---|
3050 | rO_LexVars(j, j_bits, r->block0[i],r->block0[i], prev_ordsgn, |
---|
3051 | tmp_ordsgn,v, bits, -1); |
---|
3052 | } |
---|
3053 | else |
---|
3054 | { |
---|
3055 | rO_TDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3056 | tmp_typ[typ_i]); |
---|
3057 | typ_i++; |
---|
3058 | rO_LexVars_neg(j, j_bits, r->block1[i],r->block0[i]+1, |
---|
3059 | prev_ordsgn,tmp_ordsgn,v,bits, r->block0[i]); |
---|
3060 | } |
---|
3061 | break; |
---|
3062 | |
---|
3063 | case ringorder_Dp: |
---|
3064 | if (r->block0[i]==r->block1[i]) |
---|
3065 | { |
---|
3066 | rO_LexVars(j, j_bits, r->block0[i],r->block0[i], prev_ordsgn, |
---|
3067 | tmp_ordsgn,v, bits, -1); |
---|
3068 | } |
---|
3069 | else |
---|
3070 | { |
---|
3071 | rO_TDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3072 | tmp_typ[typ_i]); |
---|
3073 | typ_i++; |
---|
3074 | rO_LexVars(j, j_bits, r->block0[i],r->block1[i]-1, prev_ordsgn, |
---|
3075 | tmp_ordsgn,v, bits, r->block1[i]); |
---|
3076 | } |
---|
3077 | break; |
---|
3078 | |
---|
3079 | case ringorder_ds: |
---|
3080 | if (r->block0[i]==r->block1[i]) |
---|
3081 | { |
---|
3082 | rO_LexVars_neg(j, j_bits,r->block0[i],r->block1[i],prev_ordsgn, |
---|
3083 | tmp_ordsgn,v,bits, -1); |
---|
3084 | } |
---|
3085 | else |
---|
3086 | { |
---|
3087 | rO_TDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3088 | tmp_typ[typ_i]); |
---|
3089 | typ_i++; |
---|
3090 | rO_LexVars_neg(j, j_bits, r->block1[i],r->block0[i]+1, |
---|
3091 | prev_ordsgn,tmp_ordsgn,v,bits, r->block0[i]); |
---|
3092 | } |
---|
3093 | break; |
---|
3094 | |
---|
3095 | case ringorder_Ds: |
---|
3096 | if (r->block0[i]==r->block1[i]) |
---|
3097 | { |
---|
3098 | rO_LexVars_neg(j, j_bits, r->block0[i],r->block0[i],prev_ordsgn, |
---|
3099 | tmp_ordsgn,v, bits, -1); |
---|
3100 | } |
---|
3101 | else |
---|
3102 | { |
---|
3103 | rO_TDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3104 | tmp_typ[typ_i]); |
---|
3105 | typ_i++; |
---|
3106 | rO_LexVars(j, j_bits, r->block0[i],r->block1[i]-1, prev_ordsgn, |
---|
3107 | tmp_ordsgn,v, bits, r->block1[i]); |
---|
3108 | } |
---|
3109 | break; |
---|
3110 | |
---|
3111 | case ringorder_wp: |
---|
3112 | rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3113 | tmp_typ[typ_i], r->wvhdl[i]); |
---|
3114 | typ_i++; |
---|
3115 | if (r->block1[i]!=r->block0[i]) |
---|
3116 | { |
---|
3117 | rO_LexVars_neg(j, j_bits,r->block1[i],r->block0[i]+1, prev_ordsgn, |
---|
3118 | tmp_ordsgn, v,bits, r->block0[i]); |
---|
3119 | } |
---|
3120 | break; |
---|
3121 | |
---|
3122 | case ringorder_Wp: |
---|
3123 | rO_WDegree(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3124 | tmp_typ[typ_i], r->wvhdl[i]); |
---|
3125 | typ_i++; |
---|
3126 | if (r->block1[i]!=r->block0[i]) |
---|
3127 | { |
---|
3128 | rO_LexVars(j, j_bits,r->block0[i],r->block1[i]-1, prev_ordsgn, |
---|
3129 | tmp_ordsgn,v, bits, r->block1[i]); |
---|
3130 | } |
---|
3131 | break; |
---|
3132 | |
---|
3133 | case ringorder_ws: |
---|
3134 | rO_WDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3135 | tmp_typ[typ_i], r->wvhdl[i]); |
---|
3136 | typ_i++; |
---|
3137 | if (r->block1[i]!=r->block0[i]) |
---|
3138 | { |
---|
3139 | rO_LexVars_neg(j, j_bits,r->block1[i],r->block0[i]+1, prev_ordsgn, |
---|
3140 | tmp_ordsgn, v,bits, r->block0[i]); |
---|
3141 | } |
---|
3142 | break; |
---|
3143 | |
---|
3144 | case ringorder_Ws: |
---|
3145 | rO_WDegree_neg(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn, |
---|
3146 | tmp_typ[typ_i], r->wvhdl[i]); |
---|
3147 | typ_i++; |
---|
3148 | if (r->block1[i]!=r->block0[i]) |
---|
3149 | { |
---|
3150 | rO_LexVars(j, j_bits,r->block0[i],r->block1[i]-1, prev_ordsgn, |
---|
3151 | tmp_ordsgn,v, bits, r->block1[i]); |
---|
3152 | } |
---|
3153 | break; |
---|
3154 | |
---|
3155 | case ringorder_S: |
---|
3156 | rO_Syzcomp(j, j_bits,prev_ordsgn, tmp_ordsgn,tmp_typ[typ_i]); |
---|
3157 | need_to_add_comp=TRUE; |
---|
3158 | typ_i++; |
---|
3159 | break; |
---|
3160 | |
---|
3161 | case ringorder_s: |
---|
3162 | rO_Syz(j, j_bits,prev_ordsgn, tmp_ordsgn,tmp_typ[typ_i]); |
---|
3163 | need_to_add_comp=TRUE; |
---|
3164 | typ_i++; |
---|
3165 | break; |
---|
3166 | |
---|
3167 | case ringorder_unspec: |
---|
3168 | case ringorder_no: |
---|
3169 | default: |
---|
3170 | dReportError("undef. ringorder used\n"); |
---|
3171 | break; |
---|
3172 | } |
---|
3173 | } |
---|
3174 | |
---|
3175 | int j0=j; // save j |
---|
3176 | int j_bits0=j_bits; // save jbits |
---|
3177 | rO_Align(j,j_bits); |
---|
3178 | r->CmpL_Size = j; |
---|
3179 | |
---|
3180 | j_bits=j_bits0; j=j0; |
---|
3181 | |
---|
3182 | // fill in some empty slots with variables not already covered |
---|
3183 | // v0 is special, is therefore normally already covered |
---|
3184 | // now we do have rings without comp... |
---|
3185 | if((need_to_add_comp) && (v[0]== -1)) |
---|
3186 | { |
---|
3187 | if (prev_ordsgn==1) |
---|
3188 | { |
---|
3189 | rO_Align(j, j_bits); |
---|
3190 | rO_LexVars(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1); |
---|
3191 | } |
---|
3192 | else |
---|
3193 | { |
---|
3194 | rO_Align(j, j_bits); |
---|
3195 | rO_LexVars_neg(j, j_bits, 0,0, prev_ordsgn,tmp_ordsgn,v,BITS_PER_LONG, -1); |
---|
3196 | } |
---|
3197 | } |
---|
3198 | // the variables |
---|
3199 | for(i=1 ; i<r->N+1 ; i++) |
---|
3200 | { |
---|
3201 | if(v[i]==(-1)) |
---|
3202 | { |
---|
3203 | if (prev_ordsgn==1) |
---|
3204 | { |
---|
3205 | rO_LexVars(j, j_bits, i,i, prev_ordsgn,tmp_ordsgn,v,bits, -1); |
---|
3206 | } |
---|
3207 | else |
---|
3208 | { |
---|
3209 | rO_LexVars_neg(j,j_bits,i,i, prev_ordsgn,tmp_ordsgn,v,bits, -1); |
---|
3210 | } |
---|
3211 | } |
---|
3212 | } |
---|
3213 | |
---|
3214 | rO_Align(j,j_bits); |
---|
3215 | // ---------------------------- |
---|
3216 | // finished with constructing the monomial, computing sizes: |
---|
3217 | |
---|
3218 | r->ExpL_Size=j; |
---|
3219 | r->PolyBin = omGetSpecBin(POLYSIZE + (r->ExpL_Size)*sizeof(long)); |
---|
3220 | assume(r->PolyBin != NULL); |
---|
3221 | |
---|
3222 | // ---------------------------- |
---|
3223 | // indices and ordsgn vector for comparison |
---|
3224 | // |
---|
3225 | // r->pCompHighIndex already set |
---|
3226 | r->ordsgn=(long *)omAlloc0(r->ExpL_Size*sizeof(long)); |
---|
3227 | |
---|
3228 | for(j=0;j<r->CmpL_Size;j++) |
---|
3229 | { |
---|
3230 | r->ordsgn[j] = tmp_ordsgn[j]; |
---|
3231 | } |
---|
3232 | |
---|
3233 | omFreeSize((ADDRESS)tmp_ordsgn,(2*(n+r->N)*sizeof(long))); |
---|
3234 | |
---|
3235 | // ---------------------------- |
---|
3236 | // description of orderings for setm: |
---|
3237 | // |
---|
3238 | r->OrdSize=typ_i; |
---|
3239 | if (typ_i==0) r->typ=NULL; |
---|
3240 | else |
---|
3241 | { |
---|
3242 | r->typ=(sro_ord*)omAlloc(typ_i*sizeof(sro_ord)); |
---|
3243 | memcpy(r->typ,tmp_typ,typ_i*sizeof(sro_ord)); |
---|
3244 | } |
---|
3245 | omFreeSize((ADDRESS)tmp_typ,(2*(n+r->N)*sizeof(sro_ord))); |
---|
3246 | |
---|
3247 | // ---------------------------- |
---|
3248 | // indices for (first copy of ) variable entries in exp.e vector (VarOffset): |
---|
3249 | r->VarOffset=v; |
---|
3250 | |
---|
3251 | // ---------------------------- |
---|
3252 | // other indicies |
---|
3253 | r->pCompIndex=(r->VarOffset[0] & 0xffff); //r->VarOffset[0]; |
---|
3254 | i=0; // position |
---|
3255 | j=0; // index in r->typ |
---|
3256 | if (i==r->pCompIndex) i++; |
---|
3257 | while ((j < r->OrdSize) |
---|
3258 | && ((r->typ[j].ord_typ==ro_syzcomp) || |
---|
3259 | (r->typ[j].ord_typ==ro_syz) || |
---|
3260 | (r->order[r->typ[j].order_index] == ringorder_aa))) |
---|
3261 | { |
---|
3262 | i++; j++; |
---|
3263 | } |
---|
3264 | if (i==r->pCompIndex) i++; |
---|
3265 | r->pOrdIndex=i; |
---|
3266 | |
---|
3267 | // ---------------------------- |
---|
3268 | // r->p_Setm |
---|
3269 | r->p_Setm = p_GetSetmProc(r); |
---|
3270 | |
---|
3271 | // ---------------------------- |
---|
3272 | // set VarL_* |
---|
3273 | rSetVarL(r); |
---|
3274 | |
---|
3275 | // ---------------------------- |
---|
3276 | // right-adjust VarOffset |
---|
3277 | rRightAdjustVarOffset(r); |
---|
3278 | |
---|
3279 | // ---------------------------- |
---|
3280 | // set NegWeightL* |
---|
3281 | rSetNegWeight(r); |
---|
3282 | |
---|
3283 | // ---------------------------- |
---|
3284 | // p_Procs: call AFTER NegWeightL |
---|
3285 | r->p_Procs = (p_Procs_s*)omAlloc(sizeof(p_Procs_s)); |
---|
3286 | p_ProcsSet(r, r->p_Procs); |
---|
3287 | |
---|
3288 | return FALSE; |
---|
3289 | } |
---|
3290 | |
---|
3291 | void rUnComplete(ring r) |
---|
3292 | { |
---|
3293 | if (r == NULL) return; |
---|
3294 | if (r->VarOffset != NULL) |
---|
3295 | { |
---|
3296 | if (r->PolyBin != NULL) |
---|
3297 | omUnGetSpecBin(&(r->PolyBin)); |
---|
3298 | |
---|
3299 | omFreeSize((ADDRESS)r->VarOffset, (r->N +1)*sizeof(int)); |
---|
3300 | if (r->order != NULL) |
---|
3301 | { |
---|
3302 | if (r->order[0] == ringorder_s && r->typ[0].data.syz.limit > 0) |
---|
3303 | { |
---|
3304 | omFreeSize(r->typ[0].data.syz.syz_index, |
---|
3305 | (r->typ[0].data.syz.limit +1)*sizeof(int)); |
---|
3306 | } |
---|
3307 | } |
---|
3308 | if (r->OrdSize!=0 && r->typ != NULL) |
---|
3309 | { |
---|
3310 | omFreeSize((ADDRESS)r->typ,r->OrdSize*sizeof(sro_ord)); |
---|
3311 | } |
---|
3312 | if (r->ordsgn != NULL && r->CmpL_Size != 0) |
---|
3313 | omFreeSize((ADDRESS)r->ordsgn,r->ExpL_Size*sizeof(long)); |
---|
3314 | if (r->p_Procs != NULL) |
---|
3315 | omFreeSize(r->p_Procs, sizeof(p_Procs_s)); |
---|
3316 | omfreeSize(r->VarL_Offset, r->VarL_Size*sizeof(int)); |
---|
3317 | } |
---|
3318 | if (r->NegWeightL_Offset!=NULL) |
---|
3319 | { |
---|
3320 | omFreeSize(r->NegWeightL_Offset, r->NegWeightL_Size*sizeof(int)); |
---|
3321 | r->NegWeightL_Offset=NULL; |
---|
3322 | } |
---|
3323 | } |
---|
3324 | |
---|
3325 | // set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex |
---|
3326 | static void rSetVarL(ring r) |
---|
3327 | { |
---|
3328 | int min = INT_MAX, min_j = -1; |
---|
3329 | int* VarL_Number = (int*) omAlloc0(r->ExpL_Size*sizeof(int)); |
---|
3330 | |
---|
3331 | int i,j; |
---|
3332 | |
---|
3333 | // count how often a var long is occupied by an exponent |
---|
3334 | for (i=1; i<=r->N; i++) |
---|
3335 | { |
---|
3336 | VarL_Number[r->VarOffset[i] & 0xffffff]++; |
---|
3337 | } |
---|
3338 | |
---|
3339 | // determine how many and min |
---|
3340 | for (i=0, j=0; i<r->ExpL_Size; i++) |
---|
3341 | { |
---|
3342 | if (VarL_Number[i] != 0) |
---|
3343 | { |
---|
3344 | if (min > VarL_Number[i]) |
---|
3345 | { |
---|
3346 | min = VarL_Number[i]; |
---|
3347 | min_j = j; |
---|
3348 | } |
---|
3349 | j++; |
---|
3350 | } |
---|
3351 | } |
---|
3352 | |
---|
3353 | r->VarL_Size = j; |
---|
3354 | r->VarL_Offset = (int*) omAlloc(r->VarL_Size*sizeof(int)); |
---|
3355 | r->VarL_LowIndex = 0; |
---|
3356 | |
---|
3357 | // set VarL_Offset |
---|
3358 | for (i=0, j=0; i<r->ExpL_Size; i++) |
---|
3359 | { |
---|
3360 | if (VarL_Number[i] != 0) |
---|
3361 | { |
---|
3362 | r->VarL_Offset[j] = i; |
---|
3363 | if (j > 0 && r->VarL_Offset[j-1] != r->VarL_Offset[j] - 1) |
---|
3364 | r->VarL_LowIndex = -1; |
---|
3365 | j++; |
---|
3366 | } |
---|
3367 | } |
---|
3368 | if (r->VarL_LowIndex >= 0) |
---|
3369 | r->VarL_LowIndex = r->VarL_Offset[0]; |
---|
3370 | |
---|
3371 | r->MinExpPerLong = min; |
---|
3372 | if (min_j != 0) |
---|
3373 | { |
---|
3374 | j = r->VarL_Offset[min_j]; |
---|
3375 | r->VarL_Offset[min_j] = r->VarL_Offset[0]; |
---|
3376 | r->VarL_Offset[0] = j; |
---|
3377 | } |
---|
3378 | omFree(VarL_Number); |
---|
3379 | } |
---|
3380 | |
---|
3381 | static void rRightAdjustVarOffset(ring r) |
---|
3382 | { |
---|
3383 | int* shifts = (int*) omAlloc(r->ExpL_Size*sizeof(int)); |
---|
3384 | int i; |
---|
3385 | // initialize shifts |
---|
3386 | for (i=0;i<r->ExpL_Size;i++) |
---|
3387 | shifts[i] = BIT_SIZEOF_LONG; |
---|
3388 | |
---|
3389 | // find minimal bit in each long var |
---|
3390 | for (i=1;i<=r->N;i++) |
---|
3391 | { |
---|
3392 | if (shifts[r->VarOffset[i] & 0xffffff] > r->VarOffset[i] >> 24) |
---|
3393 | shifts[r->VarOffset[i] & 0xffffff] = r->VarOffset[i] >> 24; |
---|
3394 | } |
---|
3395 | // reset r->VarOffset |
---|
3396 | for (i=1;i<=r->N;i++) |
---|
3397 | { |
---|
3398 | if (shifts[r->VarOffset[i] & 0xffffff] != 0) |
---|
3399 | r->VarOffset[i] |
---|
3400 | = (r->VarOffset[i] & 0xffffff) | |
---|
3401 | (((r->VarOffset[i] >> 24) - shifts[r->VarOffset[i] & 0xffffff]) << 24); |
---|
3402 | } |
---|
3403 | omFree(shifts); |
---|
3404 | } |
---|
3405 | |
---|
3406 | // get r->divmask depending on bits per exponent |
---|
3407 | static unsigned long rGetDivMask(int bits) |
---|
3408 | { |
---|
3409 | unsigned long divmask = 1; |
---|
3410 | int i = bits; |
---|
3411 | |
---|
3412 | while (i < BIT_SIZEOF_LONG) |
---|
3413 | { |
---|
3414 | divmask |= (((unsigned long) 1) << (unsigned long) i); |
---|
3415 | i += bits; |
---|
3416 | } |
---|
3417 | return divmask; |
---|
3418 | } |
---|
3419 | |
---|
3420 | #ifdef RDEBUG |
---|
3421 | void rDebugPrint(ring r) |
---|
3422 | { |
---|
3423 | if (r==NULL) |
---|
3424 | { |
---|
3425 | PrintS("NULL ?\n"); |
---|
3426 | return; |
---|
3427 | } |
---|
3428 | char *TYP[]={"ro_dp","ro_wp","ro_wp_neg","ro_cp", |
---|
3429 | "ro_syzcomp", "ro_syz", "ro_none"}; |
---|
3430 | int i,j; |
---|
3431 | |
---|
3432 | Print("ExpL_Size:%d ",r->ExpL_Size); |
---|
3433 | Print("CmpL_Size:%d ",r->CmpL_Size); |
---|
3434 | Print("VarL_Size:%d\n",r->VarL_Size); |
---|
3435 | Print("bitmask=0x%x (expbound=%d) \n",r->bitmask, r->bitmask); |
---|
3436 | Print("BitsPerExp=%d ExpPerLong=%d MinExpPerLong=%d at L[%d]\n", r->BitsPerExp, r->ExpPerLong, r->MinExpPerLong, r->VarL_Offset[0]); |
---|
3437 | PrintS("varoffset:\n"); |
---|
3438 | for(j=0;j<=r->N;j++) Print(" v%d at e-pos %d, bit %d\n", |
---|
3439 | j,r->VarOffset[j] & 0xffffff, r->VarOffset[j] >>24); |
---|
3440 | Print("divmask=%p\n", r->divmask); |
---|
3441 | PrintS("ordsgn:\n"); |
---|
3442 | for(j=0;j<r->CmpL_Size;j++) |
---|
3443 | Print(" ordsgn %d at pos %d\n",r->ordsgn[j],j); |
---|
3444 | Print("OrdSgn:%d\n",r->OrdSgn); |
---|
3445 | PrintS("ordrec:\n"); |
---|
3446 | for(j=0;j<r->OrdSize;j++) |
---|
3447 | { |
---|
3448 | Print(" typ %s",TYP[r->typ[j].ord_typ]); |
---|
3449 | Print(" place %d",r->typ[j].data.dp.place); |
---|
3450 | if (r->typ[j].ord_typ!=ro_syzcomp) |
---|
3451 | { |
---|
3452 | Print(" start %d",r->typ[j].data.dp.start); |
---|
3453 | Print(" end %d",r->typ[j].data.dp.end); |
---|
3454 | if (r->typ[j].ord_typ==ro_wp) |
---|
3455 | { |
---|
3456 | Print(" w:"); |
---|
3457 | int l; |
---|
3458 | for(l=r->typ[j].data.wp.start;l<=r->typ[j].data.wp.end;l++) |
---|
3459 | Print(" %d",r->typ[j].data.wp.weights[l-r->typ[j].data.wp.start]); |
---|
3460 | } |
---|
3461 | } |
---|
3462 | PrintLn(); |
---|
3463 | } |
---|
3464 | Print("pOrdIndex:%d pCompIndex:%d\n", r->pOrdIndex, r->pCompIndex); |
---|
3465 | Print("OrdSize:%d\n",r->OrdSize); |
---|
3466 | PrintS("--------------------\n"); |
---|
3467 | for(j=0;j<r->ExpL_Size;j++) |
---|
3468 | { |
---|
3469 | Print("L[%d]: ",j); |
---|
3470 | if (j< r->CmpL_Size) |
---|
3471 | Print("ordsgn %d ", r->ordsgn[j]); |
---|
3472 | else |
---|
3473 | PrintS("no comp "); |
---|
3474 | i=1; |
---|
3475 | for(;i<=r->N;i++) |
---|
3476 | { |
---|
3477 | if( (r->VarOffset[i] & 0xffffff) == j ) |
---|
3478 | { Print("v%d at e[%d], bit %d; ", i,r->VarOffset[i] & 0xffffff, |
---|
3479 | r->VarOffset[i] >>24 ); } |
---|
3480 | } |
---|
3481 | if( r->pCompIndex==j ) PrintS("v0; "); |
---|
3482 | for(i=0;i<r->OrdSize;i++) |
---|
3483 | { |
---|
3484 | if (r->typ[i].data.dp.place == j) |
---|
3485 | { |
---|
3486 | Print("ordrec:%s (start:%d, end:%d) ",TYP[r->typ[i].ord_typ], |
---|
3487 | r->typ[i].data.dp.start, r->typ[i].data.dp.end); |
---|
3488 | } |
---|
3489 | } |
---|
3490 | |
---|
3491 | if (j==r->pOrdIndex) |
---|
3492 | PrintS("pOrdIndex\n"); |
---|
3493 | else |
---|
3494 | PrintLn(); |
---|
3495 | } |
---|
3496 | |
---|
3497 | // p_Procs stuff |
---|
3498 | p_Procs_s proc_names; |
---|
3499 | char* field; |
---|
3500 | char* length; |
---|
3501 | char* ord; |
---|
3502 | p_Debug_GetProcNames(r, &proc_names); |
---|
3503 | p_Debug_GetSpecNames(r, field, length, ord); |
---|
3504 | |
---|
3505 | Print("p_Spec : %s, %s, %s\n", field, length, ord); |
---|
3506 | PrintS("p_Procs :\n"); |
---|
3507 | for (i=0; i<(int) (sizeof(p_Procs_s)/sizeof(void*)); i++) |
---|
3508 | { |
---|
3509 | Print(" %s,\n", ((char**) &proc_names)[i]); |
---|
3510 | } |
---|
3511 | } |
---|
3512 | |
---|
3513 | void pDebugPrintR(poly p, ring r) |
---|
3514 | { |
---|
3515 | int i,j; |
---|
3516 | pWrite(p); |
---|
3517 | j=2; |
---|
3518 | while(p!=NULL) |
---|
3519 | { |
---|
3520 | Print("\nexp[0..%d]\n",r->ExpL_Size-1); |
---|
3521 | for(i=0;i<r->ExpL_Size;i++) |
---|
3522 | Print("%d ",p->exp[i]); |
---|
3523 | PrintLn(); |
---|
3524 | Print("v0:%d ",p_GetComp(p, r)); |
---|
3525 | for(i=1;i<=r->N;i++) Print(" v%d:%d",i,p_GetExp(p,i, r)); |
---|
3526 | PrintLn(); |
---|
3527 | pIter(p); |
---|
3528 | j--; |
---|
3529 | if (j==0) { PrintS("...\n"); break; } |
---|
3530 | } |
---|
3531 | } |
---|
3532 | |
---|
3533 | void pDebugPrint(poly p) |
---|
3534 | { |
---|
3535 | pDebugPrintR(p, currRing); |
---|
3536 | } |
---|
3537 | #endif // RDEBUG |
---|
3538 | |
---|
3539 | |
---|
3540 | /*2 |
---|
3541 | * asssume that rComplete was called with r |
---|
3542 | * assume that the first block ist ringorder_S |
---|
3543 | * change the block to reflect the sequence given by appending v |
---|
3544 | */ |
---|
3545 | |
---|
3546 | #ifdef PDEBUG |
---|
3547 | void rDBChangeSComps(int* currComponents, |
---|
3548 | long* currShiftedComponents, |
---|
3549 | int length, |
---|
3550 | ring r) |
---|
3551 | { |
---|
3552 | r->typ[1].data.syzcomp.length = length; |
---|
3553 | rNChangeSComps( currComponents, currShiftedComponents, r); |
---|
3554 | } |
---|
3555 | void rDBGetSComps(int** currComponents, |
---|
3556 | long** currShiftedComponents, |
---|
3557 | int *length, |
---|
3558 | ring r) |
---|
3559 | { |
---|
3560 | *length = r->typ[1].data.syzcomp.length; |
---|
3561 | rNGetSComps( currComponents, currShiftedComponents, r); |
---|
3562 | } |
---|
3563 | #endif |
---|
3564 | |
---|
3565 | void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r) |
---|
3566 | { |
---|
3567 | assume(r->order[1]==ringorder_S); |
---|
3568 | |
---|
3569 | r->typ[1].data.syzcomp.ShiftedComponents = currShiftedComponents; |
---|
3570 | r->typ[1].data.syzcomp.Components = currComponents; |
---|
3571 | } |
---|
3572 | |
---|
3573 | void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r) |
---|
3574 | { |
---|
3575 | assume(r->order[1]==ringorder_S); |
---|
3576 | |
---|
3577 | *currShiftedComponents = r->typ[1].data.syzcomp.ShiftedComponents; |
---|
3578 | *currComponents = r->typ[1].data.syzcomp.Components; |
---|
3579 | } |
---|
3580 | |
---|
3581 | ///////////////////////////////////////////////////////////////////////////// |
---|
3582 | // |
---|
3583 | // The following routines all take as input a ring r, and return R |
---|
3584 | // where R has a certain property. P might be equal r in which case r |
---|
3585 | // had already this property |
---|
3586 | // |
---|
3587 | // Without argument, these functions work on currRing and change it, |
---|
3588 | // if necessary |
---|
3589 | |
---|
3590 | // for the time being, this is still here |
---|
3591 | static ring rAssure_SyzComp(ring r, BOOLEAN complete = TRUE); |
---|
3592 | |
---|
3593 | ring rCurrRingAssure_SyzComp() |
---|
3594 | { |
---|
3595 | ring r = rAssure_SyzComp(currRing); |
---|
3596 | if (r != currRing) |
---|
3597 | { |
---|
3598 | ring old_ring = currRing; |
---|
3599 | rChangeCurrRing(r); |
---|
3600 | if (old_ring->qideal != NULL) |
---|
3601 | { |
---|
3602 | r->qideal = idrCopyR_NoSort(old_ring->qideal, old_ring); |
---|
3603 | assume(idRankFreeModule(r->qideal) == 0); |
---|
3604 | currQuotient = r->qideal; |
---|
3605 | } |
---|
3606 | } |
---|
3607 | return r; |
---|
3608 | } |
---|
3609 | |
---|
3610 | static ring rAssure_SyzComp(ring r, BOOLEAN complete) |
---|
3611 | { |
---|
3612 | if (r->order[0] == ringorder_s) return r; |
---|
3613 | ring res=rCopy0(r, FALSE, FALSE); |
---|
3614 | int i=rBlocks(r); |
---|
3615 | int j; |
---|
3616 | |
---|
3617 | res->order=(int *)omAlloc0((i+1)*sizeof(int)); |
---|
3618 | for(j=i;j>0;j--) res->order[j]=r->order[j-1]; |
---|
3619 | res->order[0]=ringorder_s; |
---|
3620 | |
---|
3621 | res->block0=(int *)omAlloc0((i+1)*sizeof(int)); |
---|
3622 | for(j=i;j>0;j--) res->block0[j]=r->block0[j-1]; |
---|
3623 | |
---|
3624 | res->block1=(int *)omAlloc0((i+1)*sizeof(int)); |
---|
3625 | for(j=i;j>0;j--) res->block1[j]=r->block1[j-1]; |
---|
3626 | |
---|
3627 | int ** wvhdl =(int **)omAlloc0((i+1)*sizeof(int**)); |
---|
3628 | for(j=i;j>0;j--) |
---|
3629 | { |
---|
3630 | if (r->wvhdl[j-1] != NULL) |
---|
3631 | { |
---|
3632 | wvhdl[j] = (int*) omMemDup(r->wvhdl[j-1]); |
---|
3633 | } |
---|
3634 | } |
---|
3635 | res->wvhdl = wvhdl; |
---|
3636 | |
---|
3637 | if (complete) rComplete(res, 1); |
---|
3638 | return res; |
---|
3639 | } |
---|
3640 | |
---|
3641 | static ring rAssure_CompLastBlock(ring r, BOOLEAN complete = TRUE) |
---|
3642 | { |
---|
3643 | int last_block = rBlocks(r) - 2; |
---|
3644 | if (r->order[last_block] != ringorder_c && |
---|
3645 | r->order[last_block] != ringorder_C) |
---|
3646 | { |
---|
3647 | int c_pos = 0; |
---|
3648 | int i; |
---|
3649 | |
---|
3650 | for (i=0; i< last_block; i++) |
---|
3651 | { |
---|
3652 | if (r->order[i] == ringorder_c || r->order[i] == ringorder_C) |
---|
3653 | { |
---|
3654 | c_pos = i; |
---|
3655 | break; |
---|
3656 | } |
---|
3657 | } |
---|
3658 | if (c_pos != -1) |
---|
3659 | { |
---|
3660 | ring new_r = rCopy0(r, FALSE, TRUE); |
---|
3661 | for (i=c_pos+1; i<=last_block; i++) |
---|
3662 | { |
---|
3663 | new_r->order[i-1] = new_r->order[i]; |
---|
3664 | new_r->block0[i-1] = new_r->block0[i]; |
---|
3665 | new_r->block1[i-1] = new_r->block1[i]; |
---|
3666 | new_r->wvhdl[i-1] = new_r->wvhdl[i]; |
---|
3667 | } |
---|
3668 | new_r->order[last_block] = r->order[c_pos]; |
---|
3669 | new_r->block0[last_block] = r->block0[c_pos]; |
---|
3670 | new_r->block1[last_block] = r->block1[c_pos]; |
---|
3671 | new_r->wvhdl[last_block] = r->wvhdl[c_pos]; |
---|
3672 | if (complete) rComplete(new_r, 1); |
---|
3673 | return new_r; |
---|
3674 | } |
---|
3675 | } |
---|
3676 | return r; |
---|
3677 | } |
---|
3678 | |
---|
3679 | ring rCurrRingAssure_CompLastBlock() |
---|
3680 | { |
---|
3681 | ring new_r = rAssure_CompLastBlock(currRing); |
---|
3682 | if (currRing != new_r) |
---|
3683 | { |
---|
3684 | ring old_r = currRing; |
---|
3685 | rChangeCurrRing(new_r); |
---|
3686 | if (old_r->qideal != NULL) |
---|
3687 | { |
---|
3688 | new_r->qideal = idrCopyR(old_r->qideal, old_r); |
---|
3689 | currQuotient = new_r->qideal; |
---|
3690 | } |
---|
3691 | } |
---|
3692 | return new_r; |
---|
3693 | } |
---|
3694 | |
---|
3695 | ring rCurrRingAssure_SyzComp_CompLastBlock() |
---|
3696 | { |
---|
3697 | ring new_r_1 = rAssure_CompLastBlock(currRing, FALSE); |
---|
3698 | ring new_r = rAssure_SyzComp(new_r_1, FALSE); |
---|
3699 | |
---|
3700 | if (new_r != currRing) |
---|
3701 | { |
---|
3702 | ring old_r = currRing; |
---|
3703 | if (new_r_1 != new_r && new_r_1 != old_r) rDelete(new_r_1); |
---|
3704 | rComplete(new_r, 1); |
---|
3705 | rChangeCurrRing(new_r); |
---|
3706 | if (old_r->qideal != NULL) |
---|
3707 | { |
---|
3708 | new_r->qideal = idrCopyR(old_r->qideal, old_r); |
---|
3709 | currQuotient = new_r->qideal; |
---|
3710 | } |
---|
3711 | rTest(new_r); |
---|
3712 | rTest(old_r); |
---|
3713 | } |
---|
3714 | return new_r; |
---|
3715 | } |
---|
3716 | |
---|
3717 | // use this for global orderings consisting of two blocks |
---|
3718 | static ring rCurrRingAssure_Global(rRingOrder_t b1, rRingOrder_t b2) |
---|
3719 | { |
---|
3720 | int r_blocks = rBlocks(currRing); |
---|
3721 | int i; |
---|
3722 | |
---|
3723 | assume(b1 == ringorder_c || b1 == ringorder_C || |
---|
3724 | b2 == ringorder_c || b2 == ringorder_C || |
---|
3725 | b2 == ringorder_S); |
---|
3726 | if ((r_blocks == 3) && |
---|
3727 | (currRing->order[0] == b1) && |
---|
3728 | (currRing->order[1] == b2) && |
---|
3729 | (currRing->order[2] == 0)) |
---|
3730 | return currRing; |
---|
3731 | ring res = rCopy0(currRing, TRUE, FALSE); |
---|
3732 | res->order = (int*)omAlloc0(3*sizeof(int)); |
---|
3733 | res->block0 = (int*)omAlloc0(3*sizeof(int)); |
---|
3734 | res->block1 = (int*)omAlloc0(3*sizeof(int)); |
---|
3735 | res->wvhdl = (int**)omAlloc0(3*sizeof(int*)); |
---|
3736 | res->order[0] = b1; |
---|
3737 | res->order[1] = b2; |
---|
3738 | if (b1 == ringorder_c || b1 == ringorder_C) |
---|
3739 | { |
---|
3740 | res->block0[1] = 1; |
---|
3741 | res->block1[1] = currRing->N; |
---|
3742 | } |
---|
3743 | else |
---|
3744 | { |
---|
3745 | res->block0[0] = 1; |
---|
3746 | res->block1[0] = currRing->N; |
---|
3747 | } |
---|
3748 | // HANNES: This sould be set in rComplete |
---|
3749 | res->OrdSgn = 1; |
---|
3750 | rComplete(res, 1); |
---|
3751 | rChangeCurrRing(res); |
---|
3752 | return res; |
---|
3753 | } |
---|
3754 | |
---|
3755 | |
---|
3756 | ring rCurrRingAssure_dp_S() |
---|
3757 | { |
---|
3758 | return rCurrRingAssure_Global(ringorder_dp, ringorder_S); |
---|
3759 | } |
---|
3760 | |
---|
3761 | ring rCurrRingAssure_dp_C() |
---|
3762 | { |
---|
3763 | return rCurrRingAssure_Global(ringorder_dp, ringorder_C); |
---|
3764 | } |
---|
3765 | |
---|
3766 | ring rCurrRingAssure_C_dp() |
---|
3767 | { |
---|
3768 | return rCurrRingAssure_Global(ringorder_C, ringorder_dp); |
---|
3769 | } |
---|
3770 | |
---|
3771 | |
---|
3772 | void rSetSyzComp(int k) |
---|
3773 | { |
---|
3774 | if (TEST_OPT_PROT) Print("{%d}", k); |
---|
3775 | if ((currRing->typ!=NULL) && (currRing->typ[0].ord_typ==ro_syz)) |
---|
3776 | { |
---|
3777 | assume(k > currRing->typ[0].data.syz.limit); |
---|
3778 | int i; |
---|
3779 | if (currRing->typ[0].data.syz.limit == 0) |
---|
3780 | { |
---|
3781 | currRing->typ[0].data.syz.syz_index = (int*) omAlloc0((k+1)*sizeof(int)); |
---|
3782 | currRing->typ[0].data.syz.syz_index[0] = 0; |
---|
3783 | currRing->typ[0].data.syz.curr_index = 1; |
---|
3784 | } |
---|
3785 | else |
---|
3786 | { |
---|
3787 | currRing->typ[0].data.syz.syz_index = (int*) |
---|
3788 | omReallocSize(currRing->typ[0].data.syz.syz_index, |
---|
3789 | (currRing->typ[0].data.syz.limit+1)*sizeof(int), |
---|
3790 | (k+1)*sizeof(int)); |
---|
3791 | } |
---|
3792 | for (i=currRing->typ[0].data.syz.limit + 1; i<= k; i++) |
---|
3793 | { |
---|
3794 | currRing->typ[0].data.syz.syz_index[i] = |
---|
3795 | currRing->typ[0].data.syz.curr_index; |
---|
3796 | } |
---|
3797 | currRing->typ[0].data.syz.limit = k; |
---|
3798 | currRing->typ[0].data.syz.curr_index++; |
---|
3799 | } |
---|
3800 | else if ((currRing->order[0]!=ringorder_c) && (k!=0)) |
---|
3801 | { |
---|
3802 | dReportError("syzcomp in incompatible ring"); |
---|
3803 | } |
---|
3804 | #ifdef PDEBUG |
---|
3805 | extern int pDBsyzComp; |
---|
3806 | pDBsyzComp=k; |
---|
3807 | #endif |
---|
3808 | } |
---|
3809 | |
---|
3810 | // return the max-comonent wchich has syzIndex i |
---|
3811 | int rGetMaxSyzComp(int i) |
---|
3812 | { |
---|
3813 | if ((currRing->typ!=NULL) && (currRing->typ[0].ord_typ==ro_syz) && |
---|
3814 | currRing->typ[0].data.syz.limit > 0 && i > 0) |
---|
3815 | { |
---|
3816 | assume(i <= currRing->typ[0].data.syz.limit); |
---|
3817 | int j; |
---|
3818 | for (j=0; j<currRing->typ[0].data.syz.limit; j++) |
---|
3819 | { |
---|
3820 | if (currRing->typ[0].data.syz.syz_index[j] == i && |
---|
3821 | currRing->typ[0].data.syz.syz_index[j+1] != i) |
---|
3822 | { |
---|
3823 | assume(currRing->typ[0].data.syz.syz_index[j+1] == i+1); |
---|
3824 | return j; |
---|
3825 | } |
---|
3826 | } |
---|
3827 | return currRing->typ[0].data.syz.limit; |
---|
3828 | } |
---|
3829 | else |
---|
3830 | { |
---|
3831 | return 0; |
---|
3832 | } |
---|
3833 | } |
---|
3834 | |
---|
3835 | BOOLEAN rRing_is_Homog(ring r) |
---|
3836 | { |
---|
3837 | if (r == NULL) return FALSE; |
---|
3838 | int i, j, nb = rBlocks(r); |
---|
3839 | for (i=0; i<nb; i++) |
---|
3840 | { |
---|
3841 | if (r->wvhdl[i] != NULL) |
---|
3842 | { |
---|
3843 | int length = r->block1[i] - r->block0[i]; |
---|
3844 | int* wvhdl = r->wvhdl[i]; |
---|
3845 | if (r->order[i] == ringorder_M) length *= length; |
---|
3846 | assume(omSizeOfAddr(wvhdl) >= length*sizeof(int)); |
---|
3847 | |
---|
3848 | for (j=0; j< length; j++) |
---|
3849 | { |
---|
3850 | if (wvhdl[j] != 0 && wvhdl[j] != 1) return FALSE; |
---|
3851 | } |
---|
3852 | } |
---|
3853 | } |
---|
3854 | return TRUE; |
---|
3855 | } |
---|
3856 | |
---|
3857 | BOOLEAN rRing_has_CompLastBlock(ring r) |
---|
3858 | { |
---|
3859 | assume(r != NULL); |
---|
3860 | int lb = rBlocks(r) - 2; |
---|
3861 | return (r->order[lb] == ringorder_c || r->order[lb] == ringorder_C); |
---|
3862 | } |
---|
3863 | |
---|
3864 | n_coeffType rFieldType(ring r) |
---|
3865 | { |
---|
3866 | if (rField_is_Zp(r)) return n_Zp; |
---|
3867 | if (rField_is_Q(r)) return n_Q; |
---|
3868 | if (rField_is_R(r)) return n_R; |
---|
3869 | if (rField_is_GF(r)) return n_GF; |
---|
3870 | if (rField_is_long_R(r)) return n_long_R; |
---|
3871 | if (rField_is_Zp_a(r)) return n_Zp_a; |
---|
3872 | if (rField_is_Q_a(r)) return n_Q_a; |
---|
3873 | if (rField_is_long_C(r)) return n_long_C; |
---|
3874 | return n_unknown; |
---|
3875 | } |
---|
3876 | |
---|
3877 | int * rGetWeightVec(ring r) |
---|
3878 | { |
---|
3879 | assume(r!=NULL); |
---|
3880 | assume(r->OrdSize>0); |
---|
3881 | assume(r->typ[0].ord_typ==ro_wp); |
---|
3882 | return (r->typ[0].data.wp.weights); |
---|
3883 | } |
---|
3884 | |
---|
3885 | void rSetWeightVec(ring r, int *wv) |
---|
3886 | { |
---|
3887 | assume(r!=NULL); |
---|
3888 | assume(r->OrdSize>0); |
---|
3889 | assume(r->typ[0].ord_typ==ro_wp); |
---|
3890 | memcpy(r->typ[0].data.wp.weights,wv,r->N*sizeof(int)); |
---|
3891 | } |
---|
3892 | |
---|
3893 | lists rDecompose(ring r) |
---|
3894 | { |
---|
3895 | // 0: char/ cf - ring |
---|
3896 | // 1: list (var) |
---|
3897 | // 3: list (ord) |
---|
3898 | // 4: qideal |
---|
3899 | lists L=(lists)omAlloc0Bin(slists_bin); |
---|
3900 | L->Init(4); |
---|
3901 | // ---------------------------------------- |
---|
3902 | #if 0 /* TODO */ |
---|
3903 | if (rIsExtension(r)) |
---|
3904 | rDecomposeCF(&(L->m[0]),r); |
---|
3905 | else |
---|
3906 | #endif |
---|
3907 | { |
---|
3908 | L->m[0].rtyp=INT_CMD; |
---|
3909 | L->m[0].data=(void *)r->ch; |
---|
3910 | } |
---|
3911 | // ---------------------------------------- |
---|
3912 | lists LL=(lists)omAlloc0Bin(slists_bin); |
---|
3913 | L->m[1].rtyp=LIST_CMD; |
---|
3914 | L->m[1].data=(void *)LL; |
---|
3915 | LL->Init(r->N); |
---|
3916 | int i; |
---|
3917 | for(i=0; i<r->N; i++) |
---|
3918 | { |
---|
3919 | LL->m[i].rtyp=STRING_CMD; |
---|
3920 | LL->m[i].data=(void *)omStrDup(r->names[i]); |
---|
3921 | } |
---|
3922 | // ---------------------------------------- |
---|
3923 | LL=(lists)omAlloc0Bin(slists_bin); |
---|
3924 | L->m[2].rtyp=LIST_CMD; |
---|
3925 | L->m[2].data=(void *)LL; |
---|
3926 | LL->Init((i=rBlocks(r)-1)); |
---|
3927 | lists LLL; |
---|
3928 | for(; i>=0; i--) |
---|
3929 | { |
---|
3930 | intvec *iv; |
---|
3931 | int j; |
---|
3932 | LL->m[i].rtyp=LIST_CMD; |
---|
3933 | LLL=(lists)omAlloc0Bin(slists_bin); |
---|
3934 | LLL->Init(2); |
---|
3935 | LLL->m[0].rtyp=STRING_CMD; |
---|
3936 | LLL->m[0].data=(void *)omStrDup(rSimpleOrdStr(r->order[i])); |
---|
3937 | LLL->m[1].rtyp=INTVEC_CMD; |
---|
3938 | j=r->block1[i]-r->block0[i]; |
---|
3939 | iv=new intvec(j+1); |
---|
3940 | LLL->m[1].data=(void *)iv; |
---|
3941 | if (r->block1[i]-r->block0[i] >=0 ) |
---|
3942 | { |
---|
3943 | if ((r->wvhdl!=NULL) && (r->wvhdl[i]!=NULL)) |
---|
3944 | { |
---|
3945 | for(;j>=0; j--) (*iv)[j]=r->wvhdl[i][j]; |
---|
3946 | } |
---|
3947 | else switch (r->order[i]) |
---|
3948 | { |
---|
3949 | case ringorder_dp: |
---|
3950 | case ringorder_Dp: |
---|
3951 | case ringorder_ds: |
---|
3952 | case ringorder_Ds: |
---|
3953 | case ringorder_lp: |
---|
3954 | for(;j>=0; j--) (*iv)[j]=1; |
---|
3955 | break; |
---|
3956 | default: /* do nothing */; |
---|
3957 | } |
---|
3958 | } |
---|
3959 | LL->m[i].data=(void *)LLL; |
---|
3960 | } |
---|
3961 | // ---------------------------------------- |
---|
3962 | L->m[3].rtyp=IDEAL_CMD; |
---|
3963 | if (r->qideal==NULL) |
---|
3964 | L->m[3].data=(void *)idInit(1,1); |
---|
3965 | else |
---|
3966 | L->m[3].data=(void *)idCopy(r->qideal); |
---|
3967 | return L; |
---|
3968 | } |
---|