1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: ipshell.cc,v 1.94 2005-01-18 15:41:59 Singular Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: |
---|
7 | */ |
---|
8 | |
---|
9 | //#include <stdlib.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include <ctype.h> |
---|
13 | #include <math.h> |
---|
14 | |
---|
15 | #include "mod2.h" |
---|
16 | #include "tok.h" |
---|
17 | #include "ipid.h" |
---|
18 | #include "intvec.h" |
---|
19 | #include "omalloc.h" |
---|
20 | #include "febase.h" |
---|
21 | #include "polys.h" |
---|
22 | #include "ideals.h" |
---|
23 | #include "matpol.h" |
---|
24 | #include "kstd1.h" |
---|
25 | #include "ring.h" |
---|
26 | #include "subexpr.h" |
---|
27 | #include "maps.h" |
---|
28 | #include "syz.h" |
---|
29 | #include "numbers.h" |
---|
30 | #include "lists.h" |
---|
31 | #include "attrib.h" |
---|
32 | #include "ipconv.h" |
---|
33 | #include "silink.h" |
---|
34 | #include "stairc.h" |
---|
35 | #include "weight.h" |
---|
36 | #include "semic.h" |
---|
37 | #include "splist.h" |
---|
38 | #include "spectrum.h" |
---|
39 | #include "gnumpfl.h" |
---|
40 | #include "mpr_base.h" |
---|
41 | #include "ffields.h" |
---|
42 | #include "clapsing.h" |
---|
43 | #include "hutil.h" |
---|
44 | #include "ipshell.h" |
---|
45 | #ifdef HAVE_FACTORY |
---|
46 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
47 | #include <factory.h> |
---|
48 | #endif |
---|
49 | |
---|
50 | // define this if you want to use the fast_map routine for mapping ideals |
---|
51 | #define FAST_MAP |
---|
52 | |
---|
53 | #ifdef FAST_MAP |
---|
54 | #include "fast_maps.h" |
---|
55 | #endif |
---|
56 | |
---|
57 | leftv iiCurrArgs=NULL; |
---|
58 | int traceit = 0; |
---|
59 | char *lastreserved=NULL; |
---|
60 | |
---|
61 | int myynest = -1; |
---|
62 | |
---|
63 | static BOOLEAN iiNoKeepRing=TRUE; |
---|
64 | |
---|
65 | /*0 implementation*/ |
---|
66 | |
---|
67 | char * Tok2Cmdname(int tok) |
---|
68 | { |
---|
69 | int i = 0; |
---|
70 | if (tok < 0) |
---|
71 | { |
---|
72 | return cmds[0].name; |
---|
73 | } |
---|
74 | if (tok==ANY_TYPE) return "any_type"; |
---|
75 | if (tok==NONE) return "nothing"; |
---|
76 | //if (tok==IFBREAK) return "if_break"; |
---|
77 | //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys"; |
---|
78 | //if (tok==ORDER_VECTOR) return "ordering"; |
---|
79 | //if (tok==REF_VAR) return "ref"; |
---|
80 | //if (tok==OBJECT) return "object"; |
---|
81 | //if (tok==PRINT_EXPR) return "print_expr"; |
---|
82 | if (tok==IDHDL) return "identifier"; |
---|
83 | while (cmds[i].tokval!=0) |
---|
84 | { |
---|
85 | if ((cmds[i].tokval == tok)&&(cmds[i].alias==0)) |
---|
86 | { |
---|
87 | return cmds[i].name; |
---|
88 | } |
---|
89 | i++; |
---|
90 | } |
---|
91 | return cmds[0].name; |
---|
92 | } |
---|
93 | |
---|
94 | char * iiTwoOps(int t) |
---|
95 | { |
---|
96 | if (t<127) |
---|
97 | { |
---|
98 | static char ch[2]; |
---|
99 | switch (t) |
---|
100 | { |
---|
101 | case '&': |
---|
102 | return "and"; |
---|
103 | case '|': |
---|
104 | return "or"; |
---|
105 | default: |
---|
106 | ch[0]=t; |
---|
107 | ch[1]='\0'; |
---|
108 | return ch; |
---|
109 | } |
---|
110 | } |
---|
111 | switch (t) |
---|
112 | { |
---|
113 | case COLONCOLON: return "::"; |
---|
114 | case DOTDOT: return ".."; |
---|
115 | //case PLUSEQUAL: return "+="; |
---|
116 | //case MINUSEQUAL: return "-="; |
---|
117 | case MINUSMINUS: return "--"; |
---|
118 | case PLUSPLUS: return "++"; |
---|
119 | case EQUAL_EQUAL: return "=="; |
---|
120 | case LE: return "<="; |
---|
121 | case GE: return ">="; |
---|
122 | case NOTEQUAL: return "<>"; |
---|
123 | default: return Tok2Cmdname(t); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | static void list1(char* s, idhdl h,BOOLEAN c, BOOLEAN fullname) |
---|
128 | { |
---|
129 | char buffer[22]; |
---|
130 | int l; |
---|
131 | char buf2[128]; |
---|
132 | |
---|
133 | if(fullname) sprintf(buf2, "%s::%s", "", IDID(h)); |
---|
134 | else sprintf(buf2, "%s", IDID(h)); |
---|
135 | |
---|
136 | Print("%s%-20.20s [%d] ",s,buf2,IDLEV(h)); |
---|
137 | if (h == currRingHdl) PrintS("*"); |
---|
138 | PrintS(Tok2Cmdname((int)IDTYP(h))); |
---|
139 | |
---|
140 | ipListFlag(h); |
---|
141 | switch(IDTYP(h)) |
---|
142 | { |
---|
143 | case INT_CMD: Print(" %d",IDINT(h)); break; |
---|
144 | case INTVEC_CMD:Print(" (%d)",IDINTVEC(h)->length()); break; |
---|
145 | case INTMAT_CMD:Print(" %d x %d",IDINTVEC(h)->rows(),IDINTVEC(h)->cols()); |
---|
146 | break; |
---|
147 | case POLY_CMD: |
---|
148 | case VECTOR_CMD:if (c) |
---|
149 | { |
---|
150 | PrintS(" ");wrp(IDPOLY(h)); |
---|
151 | if(IDPOLY(h) != NULL) |
---|
152 | { |
---|
153 | Print(", %d monomial(s)",pLength(IDPOLY(h))); |
---|
154 | } |
---|
155 | } |
---|
156 | break; |
---|
157 | case MODUL_CMD: Print(", rk %d", IDIDEAL(h)->rank); |
---|
158 | case IDEAL_CMD: Print(", %u generator(s)", |
---|
159 | IDELEMS(IDIDEAL(h)),IDIDEAL(h)->rank); break; |
---|
160 | case MAP_CMD: |
---|
161 | Print(" from %s",IDMAP(h)->preimage); break; |
---|
162 | case MATRIX_CMD:Print(" %u x %u" |
---|
163 | ,MATROWS(IDMATRIX(h)) |
---|
164 | ,MATCOLS(IDMATRIX(h)) |
---|
165 | ); |
---|
166 | break; |
---|
167 | case PACKAGE_CMD: |
---|
168 | PrintS(" ("); |
---|
169 | switch (IDPACKAGE(h)->language) |
---|
170 | { |
---|
171 | case LANG_SINGULAR: PrintS("S"); break; |
---|
172 | case LANG_C: PrintS("C"); break; |
---|
173 | case LANG_TOP: PrintS("T"); break; |
---|
174 | case LANG_NONE: PrintS("N"); break; |
---|
175 | default: PrintS("U"); |
---|
176 | } |
---|
177 | if(IDPACKAGE(h)->libname!=NULL) |
---|
178 | Print(",%s", IDPACKAGE(h)->libname); |
---|
179 | PrintS(")"); |
---|
180 | break; |
---|
181 | case PROC_CMD: if(strlen(IDPROC(h)->libname)>0) |
---|
182 | Print(" from %s",IDPROC(h)->libname); |
---|
183 | if(IDPROC(h)->is_static) |
---|
184 | PrintS(" (static)"); |
---|
185 | break; |
---|
186 | case STRING_CMD: |
---|
187 | { |
---|
188 | char *s; |
---|
189 | l=strlen(IDSTRING(h)); |
---|
190 | memset(buffer,0,22); |
---|
191 | strncpy(buffer,IDSTRING(h),min(l,20)); |
---|
192 | if ((s=strchr(buffer,'\n'))!=NULL) |
---|
193 | { |
---|
194 | *s='\0'; |
---|
195 | } |
---|
196 | PrintS(" "); |
---|
197 | PrintS(buffer); |
---|
198 | if((s!=NULL) ||(l>20)) |
---|
199 | { |
---|
200 | Print("..., %d char(s)",l); |
---|
201 | } |
---|
202 | break; |
---|
203 | } |
---|
204 | case LIST_CMD: Print(", size: %d",IDLIST(h)->nr+1); |
---|
205 | break; |
---|
206 | case QRING_CMD: |
---|
207 | case RING_CMD: |
---|
208 | if ((IDRING(h)==currRing) && (currRingHdl!=h)) |
---|
209 | PrintS("(*)"); /* this is an alias to currRing */ |
---|
210 | #ifdef RDEBUG |
---|
211 | if (traceit &TRACE_SHOW_RINGS) |
---|
212 | Print(" <%x>",IDRING(h)); |
---|
213 | #endif |
---|
214 | break; |
---|
215 | /*default: break;*/ |
---|
216 | } |
---|
217 | PrintLn(); |
---|
218 | } |
---|
219 | |
---|
220 | void type_cmd(idhdl h) |
---|
221 | { |
---|
222 | BOOLEAN oldShortOut = FALSE; |
---|
223 | |
---|
224 | if (currRing != NULL) |
---|
225 | { |
---|
226 | oldShortOut = currRing->ShortOut; |
---|
227 | currRing->ShortOut = 1; |
---|
228 | } |
---|
229 | list1("// ",h,FALSE,FALSE); |
---|
230 | if (IDTYP(h)!=INT_CMD) |
---|
231 | { |
---|
232 | sleftv expr; |
---|
233 | memset(&expr,0,sizeof(expr)); |
---|
234 | expr.rtyp=IDHDL; |
---|
235 | expr.name=IDID(h); |
---|
236 | expr.data=(void *)h; |
---|
237 | expr.Print(); |
---|
238 | } |
---|
239 | if (currRing != NULL) |
---|
240 | currRing->ShortOut = oldShortOut; |
---|
241 | } |
---|
242 | |
---|
243 | static void killlocals0(int v, idhdl * localhdl) |
---|
244 | { |
---|
245 | idhdl h = *localhdl; |
---|
246 | while (h!=NULL) |
---|
247 | { |
---|
248 | int vv; |
---|
249 | //Print("consider %s, lev: %d:",IDID(h),IDLEV(h)); |
---|
250 | if ((vv=IDLEV(h))>0) |
---|
251 | { |
---|
252 | if (vv < v) |
---|
253 | { |
---|
254 | if (iiNoKeepRing) |
---|
255 | { |
---|
256 | //PrintS(" break\n"); |
---|
257 | return; |
---|
258 | } |
---|
259 | h = IDNEXT(h); |
---|
260 | //PrintLn(); |
---|
261 | } |
---|
262 | else if (vv >= v) |
---|
263 | { |
---|
264 | idhdl nexth = IDNEXT(h); |
---|
265 | killhdl2(h,localhdl,currRing); |
---|
266 | h = nexth; |
---|
267 | //PrintS("kill\n"); |
---|
268 | } |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | h = IDNEXT(h); |
---|
273 | //PrintLn(); |
---|
274 | } |
---|
275 | } |
---|
276 | } |
---|
277 | #ifndef HAVE_NS |
---|
278 | void killlocals(int v) |
---|
279 | { |
---|
280 | killlocals0(v,&IDROOT); |
---|
281 | |
---|
282 | if ((iiRETURNEXPR_len > myynest) |
---|
283 | && ((iiRETURNEXPR[myynest].Typ()==RING_CMD) |
---|
284 | || (iiRETURNEXPR[myynest].Typ()==QRING_CMD))) |
---|
285 | { |
---|
286 | leftv h=&iiRETURNEXPR[myynest]; |
---|
287 | killlocals0(v,&(((ring)h->data)->idroot)); |
---|
288 | } |
---|
289 | |
---|
290 | idhdl sh=currRingHdl; |
---|
291 | ring sr=currRing; |
---|
292 | BOOLEAN changed=FALSE; |
---|
293 | idhdl h = IDROOT; |
---|
294 | |
---|
295 | // Print("killlocals in %s\n",IDID(currPackHdl)); |
---|
296 | while (h!=NULL) |
---|
297 | { |
---|
298 | if (((IDTYP(h)==QRING_CMD) || (IDTYP(h) == RING_CMD)) |
---|
299 | && (IDRING(h)->idroot!=NULL)) |
---|
300 | { |
---|
301 | if (IDRING(h)!=currRing) {changed=TRUE;rSetHdl(h);} |
---|
302 | killlocals0(v,&(IDRING(h)->idroot)); |
---|
303 | } |
---|
304 | else if (IDTYP(h) == PACKAGE_CMD) |
---|
305 | { |
---|
306 | killlocals0(v,&(IDPACKAGE(h)->idroot)); |
---|
307 | } |
---|
308 | h = IDNEXT(h); |
---|
309 | } |
---|
310 | if (changed) |
---|
311 | { |
---|
312 | currRing=NULL; |
---|
313 | currRingHdl=NULL; |
---|
314 | if (sh!=NULL) rSetHdl(sh); |
---|
315 | else if (sr!=NULL) |
---|
316 | { |
---|
317 | sh=rFindHdl(sr,NULL,NULL); |
---|
318 | rSetHdl(sh); |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | if (myynest<=1) iiNoKeepRing=TRUE; |
---|
323 | //Print("end killlocals >= %d\n",v); |
---|
324 | //listall(); |
---|
325 | } |
---|
326 | #endif |
---|
327 | #ifdef HAVE_NS |
---|
328 | void killlocals_rec(idhdl *root,int v, ring r) |
---|
329 | { |
---|
330 | idhdl h=*root; |
---|
331 | while (h!=NULL) |
---|
332 | { |
---|
333 | if (IDLEV(h)>=v) |
---|
334 | { |
---|
335 | // Print("kill %s, lev %d for lev %d\n",IDID(h),IDLEV(h),v); |
---|
336 | idhdl n=IDNEXT(h); |
---|
337 | killhdl2(h,root,r); |
---|
338 | h=n; |
---|
339 | } |
---|
340 | else if (IDTYP(h)==PACKAGE_CMD) |
---|
341 | { |
---|
342 | // Print("into pack %s, lev %d for lev %d\n",IDID(h),IDLEV(h),v); |
---|
343 | if (IDPACKAGE(h)!=basePack) |
---|
344 | killlocals_rec(&(IDRING(h)->idroot),v,r); |
---|
345 | h=IDNEXT(h); |
---|
346 | } |
---|
347 | else if ((IDTYP(h)==RING_CMD) |
---|
348 | ||(IDTYP(h)==QRING_CMD)) |
---|
349 | { |
---|
350 | if (IDRING(h)->idroot!=NULL) |
---|
351 | { |
---|
352 | // Print("into ring %s, lev %d for lev %d\n",IDID(h),IDLEV(h),v); |
---|
353 | killlocals_rec(&(IDRING(h)->idroot),v,IDRING(h)); |
---|
354 | } |
---|
355 | h=IDNEXT(h); |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | // Print("skip %s lev %d for lev %d\n",IDID(h),IDLEV(h),v); |
---|
360 | h=IDNEXT(h); |
---|
361 | } |
---|
362 | } |
---|
363 | } |
---|
364 | BOOLEAN killlocals_list(int v, lists L) |
---|
365 | { |
---|
366 | if (L==NULL) return FALSE; |
---|
367 | BOOLEAN changed=FALSE; |
---|
368 | int n=L->nr; |
---|
369 | for(;n>=0;n--) |
---|
370 | { |
---|
371 | leftv h=&(L->m[n]); |
---|
372 | void *d=h->data; |
---|
373 | if (((h->rtyp==RING_CMD) || (h->rtyp==QRING_CMD)) |
---|
374 | && (((ring)d)->idroot!=NULL)) |
---|
375 | { |
---|
376 | if (d!=currRing) {changed=TRUE;rChangeCurrRing((ring)d);} |
---|
377 | killlocals0(v,&(((ring)h->data)->idroot)); |
---|
378 | } |
---|
379 | else if (h->rtyp==LIST_CMD) |
---|
380 | changed|=killlocals_list(v,(lists)d); |
---|
381 | } |
---|
382 | return changed; |
---|
383 | } |
---|
384 | void killlocals(int v) |
---|
385 | { |
---|
386 | BOOLEAN changed=FALSE; |
---|
387 | idhdl sh=currRingHdl; |
---|
388 | ring cr=currRing; |
---|
389 | if (sh!=NULL) changed=((IDLEV(sh)<v) || (IDRING(sh)->ref>0)); |
---|
390 | //if (changed) Print("currRing=%s(%x), lev=%d,ref=%d\n",IDID(sh),IDRING(sh),IDLEV(sh),IDRING(sh)->ref); |
---|
391 | |
---|
392 | killlocals_rec(&(basePack->idroot),v,currRing); |
---|
393 | |
---|
394 | if (iiRETURNEXPR_len > myynest) |
---|
395 | { |
---|
396 | int t=iiRETURNEXPR[myynest].Typ(); |
---|
397 | if ((/*iiRETURNEXPR[myynest].Typ()*/ t==RING_CMD) |
---|
398 | || (/*iiRETURNEXPR[myynest].Typ()*/ t==QRING_CMD)) |
---|
399 | { |
---|
400 | leftv h=&iiRETURNEXPR[myynest]; |
---|
401 | if (((ring)h->data)->idroot!=NULL) |
---|
402 | killlocals0(v,&(((ring)h->data)->idroot)); |
---|
403 | } |
---|
404 | else if (/*iiRETURNEXPR[myynest].Typ()*/ t==LIST_CMD) |
---|
405 | { |
---|
406 | leftv h=&iiRETURNEXPR[myynest]; |
---|
407 | changed |=killlocals_list(v,(lists)h->data); |
---|
408 | } |
---|
409 | } |
---|
410 | if (changed) |
---|
411 | { |
---|
412 | currRing=cr; |
---|
413 | currRingHdl=rFindHdl(cr,NULL,NULL); |
---|
414 | if (currRingHdl==NULL) currRingHdl=sh; |
---|
415 | } |
---|
416 | |
---|
417 | if (myynest<=1) iiNoKeepRing=TRUE; |
---|
418 | //Print("end killlocals >= %d\n",v); |
---|
419 | //listall(); |
---|
420 | } |
---|
421 | #endif |
---|
422 | |
---|
423 | void list_cmd(int typ, const char* what, char *prefix,BOOLEAN iterate, BOOLEAN fullname) |
---|
424 | { |
---|
425 | idhdl h,start; |
---|
426 | BOOLEAN all = typ<0; |
---|
427 | BOOLEAN really_all=FALSE; |
---|
428 | BOOLEAN do_packages=FALSE; |
---|
429 | |
---|
430 | if ( typ == -1 ) do_packages=TRUE; |
---|
431 | if ( typ==0 ) |
---|
432 | { |
---|
433 | if (strcmp(what,"all")==0) |
---|
434 | { |
---|
435 | really_all=TRUE; |
---|
436 | #ifdef HAVE_NS |
---|
437 | h=basePack->idroot; |
---|
438 | #else |
---|
439 | h=IDROOT; |
---|
440 | #endif |
---|
441 | } |
---|
442 | else |
---|
443 | { |
---|
444 | h = ggetid(what); |
---|
445 | if (h!=NULL) |
---|
446 | { |
---|
447 | if (iterate) list1(prefix,h,TRUE,fullname); |
---|
448 | if ((IDTYP(h)==RING_CMD) |
---|
449 | || (IDTYP(h)==QRING_CMD) |
---|
450 | #ifdef HAVE_NS |
---|
451 | //|| (IDTYP(h)==PACKE_CMD) |
---|
452 | #endif |
---|
453 | ) |
---|
454 | { |
---|
455 | h=IDRING(h)->idroot; |
---|
456 | } |
---|
457 | else if((IDTYP(h)==PACKAGE_CMD) || (IDTYP(h)==POINTER_CMD)) |
---|
458 | { |
---|
459 | Print("list_cmd:package or pointer\n"); |
---|
460 | all=TRUE;typ=PROC_CMD;fullname=TRUE;really_all=TRUE; |
---|
461 | h=IDPACKAGE(h)->idroot; |
---|
462 | } |
---|
463 | else |
---|
464 | return; |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | Werror("%s is undefined",what); |
---|
469 | return; |
---|
470 | } |
---|
471 | } |
---|
472 | all=TRUE; |
---|
473 | } |
---|
474 | else if (RingDependend(typ)) |
---|
475 | { |
---|
476 | h = currRing->idroot; |
---|
477 | } |
---|
478 | else |
---|
479 | h = IDROOT; |
---|
480 | start=h; |
---|
481 | while (h!=NULL) |
---|
482 | { |
---|
483 | if ((all && (IDTYP(h)!=PROC_CMD) &&(IDTYP(h)!=PACKAGE_CMD)) |
---|
484 | || (typ == IDTYP(h)) |
---|
485 | || ((IDTYP(h)==QRING_CMD) && (typ==RING_CMD))) |
---|
486 | { |
---|
487 | list1(prefix,h,start==currRingHdl, fullname); |
---|
488 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
489 | && (really_all || (all && (h==currRingHdl))) |
---|
490 | && ((IDLEV(h)==0)||(IDLEV(h)==myynest))) |
---|
491 | { |
---|
492 | list_cmd(0,IDID(h),"// ",FALSE); |
---|
493 | } |
---|
494 | #ifdef HAVE_NS |
---|
495 | if (IDTYP(h)==PACKAGE_CMD && really_all) |
---|
496 | { |
---|
497 | list_cmd(0,IDID(h),"// ",FALSE); |
---|
498 | } |
---|
499 | #endif /* HAVE_NS */ |
---|
500 | } |
---|
501 | h = IDNEXT(h); |
---|
502 | } |
---|
503 | } |
---|
504 | |
---|
505 | void test_cmd(int i) |
---|
506 | { |
---|
507 | int ii=(char)i; |
---|
508 | |
---|
509 | if (i == (-32)) |
---|
510 | { |
---|
511 | test = 0; |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | if (i<0) |
---|
516 | { |
---|
517 | ii= -i; |
---|
518 | if (Sy_bit(ii) & kOptions) |
---|
519 | { |
---|
520 | Warn("Gerhard, use the option command"); |
---|
521 | test &= ~Sy_bit(ii); |
---|
522 | } |
---|
523 | else if (Sy_bit(ii) & validOpts) |
---|
524 | test &= ~Sy_bit(ii); |
---|
525 | } |
---|
526 | else if (i<32) |
---|
527 | { |
---|
528 | if (Sy_bit(ii) & kOptions) |
---|
529 | { |
---|
530 | Warn("Gerhard, use the option command"); |
---|
531 | test |= Sy_bit(ii); |
---|
532 | } |
---|
533 | else if (Sy_bit(ii) & validOpts) |
---|
534 | test |= Sy_bit(ii); |
---|
535 | } |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | int exprlist_length(leftv v) |
---|
540 | { |
---|
541 | int rc = 0; |
---|
542 | while (v!=NULL) |
---|
543 | { |
---|
544 | switch (v->Typ()) |
---|
545 | { |
---|
546 | case INT_CMD: |
---|
547 | case POLY_CMD: |
---|
548 | case VECTOR_CMD: |
---|
549 | case NUMBER_CMD: |
---|
550 | rc++; |
---|
551 | break; |
---|
552 | case INTVEC_CMD: |
---|
553 | case INTMAT_CMD: |
---|
554 | rc += ((intvec *)(v->Data()))->length(); |
---|
555 | break; |
---|
556 | case MATRIX_CMD: |
---|
557 | case IDEAL_CMD: |
---|
558 | case MODUL_CMD: |
---|
559 | { |
---|
560 | matrix mm = (matrix)(v->Data()); |
---|
561 | rc += mm->rows() * mm->cols(); |
---|
562 | } |
---|
563 | break; |
---|
564 | case LIST_CMD: |
---|
565 | rc+=((lists)v->Data())->nr+1; |
---|
566 | break; |
---|
567 | default: |
---|
568 | rc++; |
---|
569 | } |
---|
570 | v = v->next; |
---|
571 | } |
---|
572 | return rc; |
---|
573 | } |
---|
574 | |
---|
575 | int IsPrime(int p) /* brute force !!!! */ |
---|
576 | { |
---|
577 | int i,j; |
---|
578 | if (p == 0) return 0; |
---|
579 | else if (p == 1) return 1/*1*/; |
---|
580 | else if (p == 2) return p; |
---|
581 | else if (p < 0) return (-IsPrime(-p)); |
---|
582 | else if (!(p & 1)) return IsPrime(p-1); |
---|
583 | #ifdef HAVE_FACTORY |
---|
584 | else if (p<=32749) // max. small prime in factory |
---|
585 | { |
---|
586 | int a=0; |
---|
587 | int e=cf_getNumSmallPrimes()-1; |
---|
588 | i=e/2; |
---|
589 | do |
---|
590 | { |
---|
591 | if (p==(j=cf_getSmallPrime(i))) return p; |
---|
592 | if (p<j) e=i-1; |
---|
593 | else a=i+1; |
---|
594 | i=a+(e-a)/2; |
---|
595 | } while ( a<= e); |
---|
596 | if (p>j) return j; |
---|
597 | else return cf_getSmallPrime(i-1); |
---|
598 | } |
---|
599 | #endif |
---|
600 | #ifdef HAVE_FACTORY |
---|
601 | int end_i=cf_getNumSmallPrimes()-1; |
---|
602 | #else |
---|
603 | int end_i=p/2; |
---|
604 | #endif |
---|
605 | int end_p=(int)sqrt((double)p); |
---|
606 | restart: |
---|
607 | for (i=0; i<end_i; i++) |
---|
608 | { |
---|
609 | #ifdef HAVE_FACTORY |
---|
610 | j=cf_getSmallPrime(i); |
---|
611 | #else |
---|
612 | if (i==0) j=2; |
---|
613 | else j=2*i-1; |
---|
614 | #endif |
---|
615 | if ((p%j) == 0) |
---|
616 | { |
---|
617 | #ifdef HAVE_FACTORY |
---|
618 | if (p<=32751) return IsPrime(p-2); |
---|
619 | #endif |
---|
620 | p-=2; |
---|
621 | goto restart; |
---|
622 | } |
---|
623 | if (j > end_p) return p; |
---|
624 | } |
---|
625 | return p; |
---|
626 | } |
---|
627 | |
---|
628 | BOOLEAN iiWRITE(leftv res,leftv v) |
---|
629 | { |
---|
630 | sleftv vf; |
---|
631 | if (iiConvert(v->Typ(),LINK_CMD,iiTestConvert(v->Typ(),LINK_CMD),v,&vf)) |
---|
632 | { |
---|
633 | WerrorS("link expected"); |
---|
634 | return TRUE; |
---|
635 | } |
---|
636 | si_link l=(si_link)vf.Data(); |
---|
637 | if (vf.next == NULL) |
---|
638 | { |
---|
639 | WerrorS("write: need at least two arguments"); |
---|
640 | return TRUE; |
---|
641 | } |
---|
642 | |
---|
643 | BOOLEAN b=slWrite(l,vf.next); /* iiConvert preserves next */ |
---|
644 | if (b) |
---|
645 | { |
---|
646 | const char *s; |
---|
647 | if ((l!=NULL)&&(l->name!=NULL)) s=l->name; |
---|
648 | else s=sNoName; |
---|
649 | Werror("cannot write to %s",s); |
---|
650 | } |
---|
651 | vf.CleanUp(); |
---|
652 | return b; |
---|
653 | } |
---|
654 | |
---|
655 | leftv iiMap(map theMap, char * what) |
---|
656 | { |
---|
657 | idhdl w,r; |
---|
658 | leftv v; |
---|
659 | int i; |
---|
660 | nMapFunc nMap; |
---|
661 | |
---|
662 | r=IDROOT->get(theMap->preimage,myynest); |
---|
663 | #ifdef HAVE_NS |
---|
664 | if ((currPack!=basePack) |
---|
665 | &&((r==NULL) || ((r->typ != RING_CMD) && (r->typ != QRING_CMD)))) |
---|
666 | r=basePack->idroot->get(theMap->preimage,myynest); |
---|
667 | if ((r==NULL) && (currRingHdl!=NULL) |
---|
668 | && (strcmp(theMap->preimage,IDID(currRingHdl))==0)) |
---|
669 | { |
---|
670 | r=currRingHdl; |
---|
671 | } |
---|
672 | #endif /* HAVE_NS */ |
---|
673 | if ((r!=NULL) && ((r->typ == RING_CMD) || (r->typ== QRING_CMD))) |
---|
674 | { |
---|
675 | //if ((nMap=nSetMap(rInternalChar(IDRING(r)), |
---|
676 | // IDRING(r)->parameter, |
---|
677 | // rPar(IDRING(r)), |
---|
678 | // IDRING(r)->minpoly))) |
---|
679 | if ((nMap=nSetMap(IDRING(r)))==NULL) |
---|
680 | { |
---|
681 | if (rEqual(IDRING(r),currRing)) |
---|
682 | { |
---|
683 | nMap=nCopy; |
---|
684 | } |
---|
685 | else |
---|
686 | { |
---|
687 | Werror("can not map from ground field of %s to current ground field", |
---|
688 | theMap->preimage); |
---|
689 | return NULL; |
---|
690 | } |
---|
691 | } |
---|
692 | if (IDELEMS(theMap)<IDRING(r)->N) |
---|
693 | { |
---|
694 | theMap->m=(polyset)omReallocSize((ADDRESS)theMap->m, |
---|
695 | IDELEMS(theMap)*sizeof(poly), |
---|
696 | (IDRING(r)->N)*sizeof(poly)); |
---|
697 | for(i=IDELEMS(theMap);i<IDRING(r)->N;i++) |
---|
698 | theMap->m[i]=NULL; |
---|
699 | IDELEMS(theMap)=IDRING(r)->N; |
---|
700 | } |
---|
701 | if (what==NULL) |
---|
702 | { |
---|
703 | WerrorS("argument of a map must have a name"); |
---|
704 | } |
---|
705 | else if ((w=IDRING(r)->idroot->get(what,myynest))!=NULL) |
---|
706 | { |
---|
707 | v=(leftv)omAlloc0Bin(sleftv_bin); |
---|
708 | sleftv tmpW; |
---|
709 | memset(&tmpW,0,sizeof(sleftv)); |
---|
710 | tmpW.rtyp=IDTYP(w); |
---|
711 | tmpW.data=IDDATA(w); |
---|
712 | #ifdef FAST_MAP |
---|
713 | if ((tmpW.rtyp==IDEAL_CMD) && (nMap==nCopy) |
---|
714 | #ifdef HAVE_PLURAL |
---|
715 | && (!rIsPluralRing(currRing)) |
---|
716 | #endif |
---|
717 | ) |
---|
718 | { |
---|
719 | v->rtyp=IDEAL_CMD; |
---|
720 | v->data=fast_map(IDIDEAL(w), IDRING(r), (ideal)theMap, currRing); |
---|
721 | } |
---|
722 | else |
---|
723 | #endif |
---|
724 | if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,IDRING(r),NULL,NULL,0,nMap)) |
---|
725 | { |
---|
726 | Werror("cannot map %s(%d)",Tok2Cmdname(w->typ),w->typ); |
---|
727 | omFreeBin((ADDRESS)v, sleftv_bin); |
---|
728 | return NULL; |
---|
729 | } |
---|
730 | return v; |
---|
731 | } |
---|
732 | else |
---|
733 | { |
---|
734 | Werror("%s undefined in %s",what,theMap->preimage); |
---|
735 | } |
---|
736 | } |
---|
737 | else |
---|
738 | { |
---|
739 | Werror("cannot find preimage %s",theMap->preimage); |
---|
740 | } |
---|
741 | return NULL; |
---|
742 | } |
---|
743 | |
---|
744 | #ifdef OLD_RES |
---|
745 | void iiMakeResolv(resolvente r, int length, int rlen, char * name, int typ0, |
---|
746 | intvec ** weights) |
---|
747 | { |
---|
748 | lists L=liMakeResolv(r,length,rlen,typ0,weights); |
---|
749 | int i=0; |
---|
750 | idhdl h; |
---|
751 | char * s=(char *)omAlloc(strlen(name)+5); |
---|
752 | |
---|
753 | while (i<=L->nr) |
---|
754 | { |
---|
755 | sprintf(s,"%s(%d)",name,i+1); |
---|
756 | if (i==0) |
---|
757 | h=enterid(s,myynest,typ0,&(currRing->idroot), FALSE); |
---|
758 | else |
---|
759 | h=enterid(s,myynest,MODUL_CMD,&(currRing->idroot), FALSE); |
---|
760 | if (h!=NULL) |
---|
761 | { |
---|
762 | h->data.uideal=(ideal)L->m[i].data; |
---|
763 | h->attribute=L->m[i].attribute; |
---|
764 | if (BVERBOSE(V_DEF_RES)) |
---|
765 | Print("//defining: %s as %d-th syzygy module\n",s,i+1); |
---|
766 | } |
---|
767 | else |
---|
768 | { |
---|
769 | idDelete((ideal *)&(L->m[i].data)); |
---|
770 | Warn("cannot define %s",s); |
---|
771 | } |
---|
772 | //L->m[i].data=NULL; |
---|
773 | //L->m[i].rtyp=0; |
---|
774 | //L->m[i].attribute=NULL; |
---|
775 | i++; |
---|
776 | } |
---|
777 | omFreeSize((ADDRESS)L->m,(L->nr+1)*sizeof(sleftv)); |
---|
778 | omFreeBin((ADDRESS)L, slists_bin); |
---|
779 | omFreeSize((ADDRESS)s,strlen(name)+5); |
---|
780 | } |
---|
781 | #endif |
---|
782 | |
---|
783 | //resolvente iiFindRes(char * name, int * len, int *typ0) |
---|
784 | //{ |
---|
785 | // char *s=(char *)omAlloc(strlen(name)+5); |
---|
786 | // int i=-1; |
---|
787 | // resolvente r; |
---|
788 | // idhdl h; |
---|
789 | // |
---|
790 | // do |
---|
791 | // { |
---|
792 | // i++; |
---|
793 | // sprintf(s,"%s(%d)",name,i+1); |
---|
794 | // h=currRing->idroot->get(s,myynest); |
---|
795 | // } while (h!=NULL); |
---|
796 | // *len=i-1; |
---|
797 | // if (*len<=0) |
---|
798 | // { |
---|
799 | // Werror("no objects %s(1),.. found",name); |
---|
800 | // omFreeSize((ADDRESS)s,strlen(name)+5); |
---|
801 | // return NULL; |
---|
802 | // } |
---|
803 | // r=(ideal *)omAlloc(/*(len+1)*/ i*sizeof(ideal)); |
---|
804 | // memset(r,0,(*len)*sizeof(ideal)); |
---|
805 | // i=-1; |
---|
806 | // *typ0=MODUL_CMD; |
---|
807 | // while (i<(*len)) |
---|
808 | // { |
---|
809 | // i++; |
---|
810 | // sprintf(s,"%s(%d)",name,i+1); |
---|
811 | // h=currRing->idroot->get(s,myynest); |
---|
812 | // if (h->typ != MODUL_CMD) |
---|
813 | // { |
---|
814 | // if ((i!=0) || (h->typ!=IDEAL_CMD)) |
---|
815 | // { |
---|
816 | // Werror("%s is not of type module",s); |
---|
817 | // omFreeSize((ADDRESS)r,(*len)*sizeof(ideal)); |
---|
818 | // omFreeSize((ADDRESS)s,strlen(name)+5); |
---|
819 | // return NULL; |
---|
820 | // } |
---|
821 | // *typ0=IDEAL_CMD; |
---|
822 | // } |
---|
823 | // if ((i>0) && (idIs0(r[i-1]))) |
---|
824 | // { |
---|
825 | // *len=i-1; |
---|
826 | // break; |
---|
827 | // } |
---|
828 | // r[i]=IDIDEAL(h); |
---|
829 | // } |
---|
830 | // omFreeSize((ADDRESS)s,strlen(name)+5); |
---|
831 | // return r; |
---|
832 | //} |
---|
833 | |
---|
834 | static resolvente iiCopyRes(resolvente r, int l) |
---|
835 | { |
---|
836 | int i; |
---|
837 | resolvente res=(ideal *)omAlloc0((l+1)*sizeof(ideal)); |
---|
838 | |
---|
839 | for (i=0; i<l; i++) |
---|
840 | res[i]=idCopy(r[i]); |
---|
841 | return res; |
---|
842 | } |
---|
843 | |
---|
844 | BOOLEAN jjMINRES(leftv res, leftv v) |
---|
845 | { |
---|
846 | int len=0; |
---|
847 | int typ0; |
---|
848 | resolvente rr=liFindRes((lists)v->Data(),&len,&typ0); |
---|
849 | if (rr==NULL) return TRUE; |
---|
850 | resolvente r=iiCopyRes(rr,len); |
---|
851 | |
---|
852 | syMinimizeResolvente(r,len,0); |
---|
853 | omFreeSize((ADDRESS)rr,len*sizeof(ideal)); |
---|
854 | len++; |
---|
855 | res->data=(char *)liMakeResolv(r,len,-1,typ0,NULL); |
---|
856 | return FALSE; |
---|
857 | } |
---|
858 | |
---|
859 | BOOLEAN jjBETTI(leftv res, leftv u) |
---|
860 | { |
---|
861 | sleftv tmp; |
---|
862 | memset(&tmp,0,sizeof(tmp)); |
---|
863 | tmp.rtyp=INT_CMD; |
---|
864 | tmp.data=(void *)1; |
---|
865 | if ((u->Typ()==IDEAL_CMD) |
---|
866 | || (u->Typ()==MODUL_CMD)) |
---|
867 | return jjBETTI2_ID(res,u,&tmp); |
---|
868 | else |
---|
869 | return jjBETTI2(res,u,&tmp); |
---|
870 | } |
---|
871 | |
---|
872 | BOOLEAN jjBETTI2_ID(leftv res, leftv u, leftv v) |
---|
873 | { |
---|
874 | lists l=(lists) omAllocBin(slists_bin); |
---|
875 | l->Init(1); |
---|
876 | l->m[0].rtyp=u->Typ(); |
---|
877 | l->m[0].data=u->Data(); |
---|
878 | l->m[0].attribute=u->attribute; |
---|
879 | sleftv tmp2; |
---|
880 | memset(&tmp2,0,sizeof(tmp2)); |
---|
881 | tmp2.rtyp=LIST_CMD; |
---|
882 | tmp2.data=(void *)l; |
---|
883 | BOOLEAN r=jjBETTI2(res,&tmp2,v); |
---|
884 | l->m[0].data=NULL; |
---|
885 | l->m[0].attribute=NULL; |
---|
886 | l->m[0].rtyp=DEF_CMD; |
---|
887 | l->Clean(); |
---|
888 | return r; |
---|
889 | } |
---|
890 | |
---|
891 | BOOLEAN jjBETTI2(leftv res, leftv u, leftv v) |
---|
892 | { |
---|
893 | resolvente r; |
---|
894 | int len; |
---|
895 | int reg,typ0; |
---|
896 | lists l=(lists)u->Data(); |
---|
897 | |
---|
898 | intvec *weights=NULL; |
---|
899 | int add_row_shift=0; |
---|
900 | intvec *ww=(intvec *)atGet(&(l->m[0]),"isHomog",INTVEC_CMD); |
---|
901 | if (ww!=NULL) |
---|
902 | { |
---|
903 | weights=ivCopy(ww); |
---|
904 | add_row_shift = ww->min_in(); |
---|
905 | (*weights) -= add_row_shift; |
---|
906 | } |
---|
907 | //Print("attr:%x\n",weights); |
---|
908 | |
---|
909 | r=liFindRes(l,&len,&typ0); |
---|
910 | if (r==NULL) return TRUE; |
---|
911 | res->data=(char *)syBetti(r,len,®,weights,(int)v->Data()); |
---|
912 | omFreeSize((ADDRESS)r,(len)*sizeof(ideal)); |
---|
913 | if (add_row_shift!=0) |
---|
914 | atSet(res,omStrDup("rowShift"),(void*)add_row_shift,INT_CMD); |
---|
915 | if (weights!=NULL) delete weights; |
---|
916 | return FALSE; |
---|
917 | } |
---|
918 | |
---|
919 | int iiRegularity(lists L) |
---|
920 | { |
---|
921 | int len,reg,typ0; |
---|
922 | |
---|
923 | resolvente r=liFindRes(L,&len,&typ0); |
---|
924 | |
---|
925 | if (r==NULL) |
---|
926 | return -2; |
---|
927 | intvec * dummy=syBetti(r,len,®); |
---|
928 | omFreeSize((ADDRESS)r,len*sizeof(ideal)); |
---|
929 | delete dummy; |
---|
930 | return reg+1; |
---|
931 | } |
---|
932 | |
---|
933 | BOOLEAN iiDebugMarker=TRUE; |
---|
934 | #define BREAK_LINE_LENGTH 80 |
---|
935 | void iiDebug() |
---|
936 | { |
---|
937 | Print("\n-- break point in %s --\n",VoiceName()); |
---|
938 | if (iiDebugMarker) VoiceBackTrack(); |
---|
939 | char * s; |
---|
940 | iiDebugMarker=FALSE; |
---|
941 | s = (char *)omAlloc(BREAK_LINE_LENGTH+4); |
---|
942 | loop |
---|
943 | { |
---|
944 | memset(s,0,80); |
---|
945 | fe_fgets_stdin("",s,BREAK_LINE_LENGTH); |
---|
946 | if (s[BREAK_LINE_LENGTH-1]!='\0') |
---|
947 | { |
---|
948 | Print("line too long, max is %d chars\n",BREAK_LINE_LENGTH); |
---|
949 | } |
---|
950 | else |
---|
951 | break; |
---|
952 | } |
---|
953 | if (*s=='\n') |
---|
954 | { |
---|
955 | iiDebugMarker=TRUE; |
---|
956 | } |
---|
957 | #if MDEBUG |
---|
958 | else if(strncmp(s,"cont;",5)==0) |
---|
959 | { |
---|
960 | iiDebugMarker=TRUE; |
---|
961 | } |
---|
962 | #endif /* MDEBUG */ |
---|
963 | else |
---|
964 | { |
---|
965 | strcat( s, "\n;~\n"); |
---|
966 | newBuffer(s,BT_execute); |
---|
967 | } |
---|
968 | } |
---|
969 | |
---|
970 | lists scIndIndset(ideal S, BOOLEAN all, ideal Q) |
---|
971 | { |
---|
972 | int i; |
---|
973 | indset save; |
---|
974 | lists res=(lists)omAlloc0Bin(slists_bin); |
---|
975 | |
---|
976 | hexist = hInit(S, Q, &hNexist); |
---|
977 | if ((hNexist == 0) || (hisModule!=0)) |
---|
978 | { |
---|
979 | res->Init(0); |
---|
980 | return res; |
---|
981 | } |
---|
982 | save = ISet = (indset)omAlloc0Bin(indlist_bin); |
---|
983 | hMu = 0; |
---|
984 | hwork = (scfmon)omAlloc(hNexist * sizeof(scmon)); |
---|
985 | hvar = (varset)omAlloc((pVariables + 1) * sizeof(int)); |
---|
986 | hpure = (scmon)omAlloc((1 + (pVariables * pVariables)) * sizeof(Exponent_t)); |
---|
987 | hrad = hexist; |
---|
988 | hNrad = hNexist; |
---|
989 | radmem = hCreate(pVariables - 1); |
---|
990 | hCo = pVariables + 1; |
---|
991 | hNvar = pVariables; |
---|
992 | hRadical(hrad, &hNrad, hNvar); |
---|
993 | hSupp(hrad, hNrad, hvar, &hNvar); |
---|
994 | if (hNvar) |
---|
995 | { |
---|
996 | hCo = hNvar; |
---|
997 | memset(hpure, 0, (pVariables + 1) * sizeof(Exponent_t)); |
---|
998 | hPure(hrad, 0, &hNrad, hvar, hNvar, hpure, &hNpure); |
---|
999 | hLexR(hrad, hNrad, hvar, hNvar); |
---|
1000 | hDimSolve(hpure, hNpure, hrad, hNrad, hvar, hNvar); |
---|
1001 | } |
---|
1002 | if (hCo && (hCo < pVariables)) |
---|
1003 | { |
---|
1004 | hIndMult(hpure, hNpure, hrad, hNrad, hvar, hNvar); |
---|
1005 | } |
---|
1006 | if (hMu!=0) |
---|
1007 | { |
---|
1008 | ISet = save; |
---|
1009 | hMu2 = 0; |
---|
1010 | if (all && (hCo+1 < pVariables)) |
---|
1011 | { |
---|
1012 | JSet = (indset)omAlloc0Bin(indlist_bin); |
---|
1013 | hIndAllMult(hpure, hNpure, hrad, hNrad, hvar, hNvar); |
---|
1014 | i=hMu+hMu2; |
---|
1015 | res->Init(i); |
---|
1016 | if (hMu2 == 0) |
---|
1017 | { |
---|
1018 | omFreeBin((ADDRESS)JSet, indlist_bin); |
---|
1019 | } |
---|
1020 | } |
---|
1021 | else |
---|
1022 | { |
---|
1023 | res->Init(hMu); |
---|
1024 | } |
---|
1025 | for (i=0;i<hMu;i++) |
---|
1026 | { |
---|
1027 | res->m[i].data = (void *)save->set; |
---|
1028 | res->m[i].rtyp = INTVEC_CMD; |
---|
1029 | ISet = save; |
---|
1030 | save = save->nx; |
---|
1031 | omFreeBin((ADDRESS)ISet, indlist_bin); |
---|
1032 | } |
---|
1033 | omFreeBin((ADDRESS)save, indlist_bin); |
---|
1034 | if (hMu2 != 0) |
---|
1035 | { |
---|
1036 | save = JSet; |
---|
1037 | for (i=hMu;i<hMu+hMu2;i++) |
---|
1038 | { |
---|
1039 | res->m[i].data = (void *)save->set; |
---|
1040 | res->m[i].rtyp = INTVEC_CMD; |
---|
1041 | JSet = save; |
---|
1042 | save = save->nx; |
---|
1043 | omFreeBin((ADDRESS)JSet, indlist_bin); |
---|
1044 | } |
---|
1045 | omFreeBin((ADDRESS)save, indlist_bin); |
---|
1046 | } |
---|
1047 | } |
---|
1048 | else |
---|
1049 | { |
---|
1050 | res->Init(0); |
---|
1051 | omFreeBin((ADDRESS)ISet, indlist_bin); |
---|
1052 | } |
---|
1053 | hKill(radmem, pVariables - 1); |
---|
1054 | omFreeSize((ADDRESS)hpure, (1 + (pVariables * pVariables)) * sizeof(Exponent_t)); |
---|
1055 | omFreeSize((ADDRESS)hvar, (pVariables + 1) * sizeof(int)); |
---|
1056 | omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon)); |
---|
1057 | hDelete(hexist, hNexist); |
---|
1058 | return res; |
---|
1059 | } |
---|
1060 | |
---|
1061 | int iiDeclCommand(leftv sy, leftv name, int lev,int t, idhdl* root,BOOLEAN isring, BOOLEAN init_b) |
---|
1062 | { |
---|
1063 | BOOLEAN res=FALSE; |
---|
1064 | char *id = name->name; |
---|
1065 | |
---|
1066 | memset(sy,0,sizeof(sleftv)); |
---|
1067 | if ((name->name==NULL)||(isdigit(name->name[0]))) |
---|
1068 | { |
---|
1069 | WerrorS("object to declare is not a name"); |
---|
1070 | res=TRUE; |
---|
1071 | } |
---|
1072 | else |
---|
1073 | { |
---|
1074 | //if (name->rtyp!=0) |
---|
1075 | //{ |
---|
1076 | // Warn("`%s` is already in use",name->name); |
---|
1077 | //} |
---|
1078 | { |
---|
1079 | sy->data = (char *)enterid(id,lev,t,root,init_b); |
---|
1080 | } |
---|
1081 | if (sy->data!=NULL) |
---|
1082 | { |
---|
1083 | sy->rtyp=IDHDL; |
---|
1084 | currid=sy->name=IDID((idhdl)sy->data); |
---|
1085 | // name->name=NULL; /* used in enterid */ |
---|
1086 | //sy->e = NULL; |
---|
1087 | if (name->next!=NULL) |
---|
1088 | { |
---|
1089 | sy->next=(leftv)omAllocBin(sleftv_bin); |
---|
1090 | res=iiDeclCommand(sy->next,name->next,lev,t,root, isring); |
---|
1091 | } |
---|
1092 | } |
---|
1093 | else res=TRUE; |
---|
1094 | } |
---|
1095 | name->CleanUp(); |
---|
1096 | return res; |
---|
1097 | } |
---|
1098 | |
---|
1099 | BOOLEAN iiParameter(leftv p) |
---|
1100 | { |
---|
1101 | if (iiCurrArgs==NULL) |
---|
1102 | { |
---|
1103 | if (strcmp(p->name,"#")==0) return FALSE; |
---|
1104 | Werror("not enough arguments for proc %s",VoiceName()); |
---|
1105 | p->CleanUp(); |
---|
1106 | return TRUE; |
---|
1107 | } |
---|
1108 | leftv h=iiCurrArgs; |
---|
1109 | if (strcmp(p->name,"#")==0) |
---|
1110 | { |
---|
1111 | iiCurrArgs=NULL; |
---|
1112 | } |
---|
1113 | else |
---|
1114 | { |
---|
1115 | iiCurrArgs=h->next; |
---|
1116 | h->next=NULL; |
---|
1117 | } |
---|
1118 | BOOLEAN res=iiAssign(p,h); |
---|
1119 | omFreeBin((ADDRESS)h, sleftv_bin); |
---|
1120 | return res; |
---|
1121 | } |
---|
1122 | |
---|
1123 | static BOOLEAN iiInternalExport (leftv v, int toLev) |
---|
1124 | { |
---|
1125 | idhdl h=(idhdl)v->data; |
---|
1126 | //Print("iiInternalExport('%s',%d)%s\n", v->name, toLev,""); |
---|
1127 | if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h)); |
---|
1128 | else |
---|
1129 | { |
---|
1130 | h=IDROOT->get(v->name,toLev); |
---|
1131 | idhdl *root=&IDROOT; |
---|
1132 | if ((h==NULL)&&(currRing!=NULL)) |
---|
1133 | { |
---|
1134 | h=currRing->idroot->get(v->name,toLev); |
---|
1135 | root=&currRing->idroot; |
---|
1136 | } |
---|
1137 | BOOLEAN keepring=FALSE; |
---|
1138 | if ((h!=NULL)&&(IDLEV(h)==toLev)) |
---|
1139 | { |
---|
1140 | if (IDTYP(h)==v->Typ()) |
---|
1141 | { |
---|
1142 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
1143 | && (v->Data()==IDDATA(h))) |
---|
1144 | { |
---|
1145 | IDRING(h)->ref++; |
---|
1146 | keepring=TRUE; |
---|
1147 | IDLEV(h)=toLev; |
---|
1148 | //WarnS("keepring"); |
---|
1149 | return FALSE; |
---|
1150 | } |
---|
1151 | if (BVERBOSE(V_REDEFINE)) |
---|
1152 | { |
---|
1153 | Warn("redefining %s",IDID(h)); |
---|
1154 | } |
---|
1155 | #ifdef USE_IILOCALRING |
---|
1156 | if (iiLocalRing[0]==IDRING(h) && (!keepring)) iiLocalRing[0]=NULL; |
---|
1157 | #else |
---|
1158 | proclevel *p=procstack; |
---|
1159 | while (p->next!=NULL) p=p->next; |
---|
1160 | if ((p->cRing==IDRING(h)) && (!keepring)) |
---|
1161 | { |
---|
1162 | p->cRing=NULL; |
---|
1163 | p->cRingHdl=NULL; |
---|
1164 | } |
---|
1165 | #endif |
---|
1166 | killhdl2(h,root,currRing); |
---|
1167 | } |
---|
1168 | else |
---|
1169 | { |
---|
1170 | return TRUE; |
---|
1171 | } |
---|
1172 | } |
---|
1173 | h=(idhdl)v->data; |
---|
1174 | IDLEV(h)=toLev; |
---|
1175 | if (keepring) IDRING(h)->ref--; |
---|
1176 | iiNoKeepRing=FALSE; |
---|
1177 | //Print("export %s\n",IDID(h)); |
---|
1178 | } |
---|
1179 | return FALSE; |
---|
1180 | } |
---|
1181 | |
---|
1182 | #ifdef HAVE_NS |
---|
1183 | BOOLEAN iiInternalExport (leftv v, int toLev, idhdl roothdl) |
---|
1184 | { |
---|
1185 | idhdl h=(idhdl)v->data; |
---|
1186 | if(h==NULL) |
---|
1187 | { |
---|
1188 | Warn("'%s': no such identifier\n", v->name); |
---|
1189 | return FALSE; |
---|
1190 | } |
---|
1191 | package frompack=v->req_packhdl; |
---|
1192 | if (frompack==NULL) frompack=currPack; |
---|
1193 | package rootpack = IDPACKAGE(roothdl); |
---|
1194 | // Print("iiInternalExport('%s',%d,%s->%s) typ:%d\n", v->name, toLev, IDID(currPackHdl),IDID(roothdl),v->Typ()); |
---|
1195 | if ((RingDependend(IDTYP(h))) |
---|
1196 | || ((IDTYP(h)==LIST_CMD) |
---|
1197 | && (lRingDependend(IDLIST(h))) |
---|
1198 | ) |
---|
1199 | ) |
---|
1200 | { |
---|
1201 | //Print("// ==> Ringdependent set nesting to 0\n"); |
---|
1202 | return (iiInternalExport(v, toLev)); |
---|
1203 | } |
---|
1204 | else |
---|
1205 | { |
---|
1206 | IDLEV(h)=toLev; |
---|
1207 | v->req_packhdl=rootpack; |
---|
1208 | if (h==frompack->idroot) |
---|
1209 | { |
---|
1210 | frompack->idroot=h->next; |
---|
1211 | } |
---|
1212 | else |
---|
1213 | { |
---|
1214 | idhdl hh=frompack->idroot; |
---|
1215 | while ((hh!=NULL) && (hh->next!=h)) |
---|
1216 | hh=hh->next; |
---|
1217 | if ((hh!=NULL) && (hh->next==h)) |
---|
1218 | hh->next=h->next; |
---|
1219 | else |
---|
1220 | { |
---|
1221 | Werror("`%s` not found",v->Name()); |
---|
1222 | return TRUE; |
---|
1223 | } |
---|
1224 | } |
---|
1225 | h->next=rootpack->idroot; |
---|
1226 | rootpack->idroot=h; |
---|
1227 | } |
---|
1228 | return FALSE; |
---|
1229 | } |
---|
1230 | #endif /* HAVE_NS */ |
---|
1231 | |
---|
1232 | BOOLEAN iiExport (leftv v, int toLev) |
---|
1233 | { |
---|
1234 | #ifdef HAVE_NS |
---|
1235 | checkall(); |
---|
1236 | #endif |
---|
1237 | BOOLEAN nok=FALSE; |
---|
1238 | leftv r=v; |
---|
1239 | while (v!=NULL) |
---|
1240 | { |
---|
1241 | if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL)) |
---|
1242 | { |
---|
1243 | WerrorS("cannot export"); |
---|
1244 | nok=TRUE; |
---|
1245 | } |
---|
1246 | else |
---|
1247 | { |
---|
1248 | if(iiInternalExport(v, toLev)) |
---|
1249 | { |
---|
1250 | r->CleanUp(); |
---|
1251 | return TRUE; |
---|
1252 | } |
---|
1253 | } |
---|
1254 | v=v->next; |
---|
1255 | } |
---|
1256 | r->CleanUp(); |
---|
1257 | #ifdef HAVE_NS |
---|
1258 | checkall(); |
---|
1259 | #endif |
---|
1260 | return nok; |
---|
1261 | } |
---|
1262 | |
---|
1263 | /*assume root!=idroot*/ |
---|
1264 | #ifdef HAVE_NS |
---|
1265 | BOOLEAN iiExport (leftv v, int toLev, idhdl root) |
---|
1266 | { |
---|
1267 | checkall(); |
---|
1268 | // Print("iiExport1: pack=%s\n",IDID(root)); |
---|
1269 | BOOLEAN nok=FALSE; |
---|
1270 | leftv rv=v; |
---|
1271 | while (v!=NULL) |
---|
1272 | { |
---|
1273 | if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL) |
---|
1274 | ) |
---|
1275 | { |
---|
1276 | WerrorS("cannot export"); |
---|
1277 | nok=TRUE; |
---|
1278 | } |
---|
1279 | else |
---|
1280 | { |
---|
1281 | idhdl old=root->get(v->name,toLev); |
---|
1282 | if (old!=NULL) |
---|
1283 | { |
---|
1284 | if (IDTYP(old)==v->Typ()) |
---|
1285 | { |
---|
1286 | if (BVERBOSE(V_REDEFINE)) |
---|
1287 | { |
---|
1288 | Warn("redefining %s",IDID(old)); |
---|
1289 | } |
---|
1290 | killhdl2(old,&root,currRing); |
---|
1291 | } |
---|
1292 | else |
---|
1293 | { |
---|
1294 | rv->CleanUp(); |
---|
1295 | return TRUE; |
---|
1296 | } |
---|
1297 | } |
---|
1298 | //Print("iiExport: pack=%s\n",IDID(root)); |
---|
1299 | if(iiInternalExport(v, toLev, root)) |
---|
1300 | { |
---|
1301 | rv->CleanUp(); |
---|
1302 | return TRUE; |
---|
1303 | } |
---|
1304 | } |
---|
1305 | v=v->next; |
---|
1306 | } |
---|
1307 | rv->CleanUp(); |
---|
1308 | checkall(); |
---|
1309 | return nok; |
---|
1310 | } |
---|
1311 | #endif |
---|
1312 | |
---|
1313 | BOOLEAN iiCheckRing(int i) |
---|
1314 | { |
---|
1315 | if (currRingHdl==NULL) |
---|
1316 | { |
---|
1317 | #ifdef SIQ |
---|
1318 | if (siq<=0) |
---|
1319 | { |
---|
1320 | #endif |
---|
1321 | if (RingDependend(i)) |
---|
1322 | { |
---|
1323 | WerrorS("no ring active"); |
---|
1324 | return TRUE; |
---|
1325 | } |
---|
1326 | #ifdef SIQ |
---|
1327 | } |
---|
1328 | #endif |
---|
1329 | } |
---|
1330 | return FALSE; |
---|
1331 | } |
---|
1332 | |
---|
1333 | poly iiHighCorner(ideal I, int ak) |
---|
1334 | { |
---|
1335 | int i; |
---|
1336 | if(!idIsZeroDim(I)) return NULL; // not zero-dim. |
---|
1337 | poly po=NULL; |
---|
1338 | if (currRing->OrdSgn== -1) |
---|
1339 | { |
---|
1340 | scComputeHC(I,currQuotient,ak,po); |
---|
1341 | if (po!=NULL) |
---|
1342 | { |
---|
1343 | pGetCoeff(po)=nInit(1); |
---|
1344 | for (i=pVariables; i>0; i--) |
---|
1345 | { |
---|
1346 | if (pGetExp(po, i) > 0) pDecrExp(po,i); |
---|
1347 | } |
---|
1348 | pSetComp(po,ak); |
---|
1349 | pSetm(po); |
---|
1350 | } |
---|
1351 | } |
---|
1352 | else |
---|
1353 | po=pOne(); |
---|
1354 | return po; |
---|
1355 | } |
---|
1356 | |
---|
1357 | #ifdef HAVE_NS |
---|
1358 | void iiCheckPack(package &p) |
---|
1359 | { |
---|
1360 | if (p==basePack) return; |
---|
1361 | |
---|
1362 | idhdl t=basePack->idroot; |
---|
1363 | |
---|
1364 | while ((t!=NULL) && (IDTYP(t)!=PACKAGE_CMD) && (IDPACKAGE(t)!=p)) t=t->next; |
---|
1365 | |
---|
1366 | if (t==NULL) |
---|
1367 | { |
---|
1368 | WarnS("package not found\n"); |
---|
1369 | p=basePack; |
---|
1370 | } |
---|
1371 | return; |
---|
1372 | } |
---|
1373 | #endif |
---|
1374 | |
---|
1375 | idhdl rDefault(char *s) |
---|
1376 | { |
---|
1377 | idhdl tmp=NULL; |
---|
1378 | |
---|
1379 | if (s!=NULL) tmp = enterid(s, myynest, RING_CMD, &IDROOT); |
---|
1380 | if (tmp==NULL) return NULL; |
---|
1381 | |
---|
1382 | if (ppNoether!=NULL) pDelete(&ppNoether); |
---|
1383 | if (sLastPrinted.RingDependend()) |
---|
1384 | { |
---|
1385 | sLastPrinted.CleanUp(); |
---|
1386 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
1387 | } |
---|
1388 | |
---|
1389 | ring r = IDRING(tmp); |
---|
1390 | |
---|
1391 | r->ch = 32003; |
---|
1392 | r->N = 3; |
---|
1393 | /*r->P = 0; Alloc0 in idhdl::set, ipid.cc*/ |
---|
1394 | /*names*/ |
---|
1395 | r->names = (char **) omAlloc0(3 * sizeof(char_ptr)); |
---|
1396 | r->names[0] = omStrDup("x"); |
---|
1397 | r->names[1] = omStrDup("y"); |
---|
1398 | r->names[2] = omStrDup("z"); |
---|
1399 | /*weights: entries for 3 blocks: NULL*/ |
---|
1400 | r->wvhdl = (int **)omAlloc0(3 * sizeof(int_ptr)); |
---|
1401 | /*order: dp,C,0*/ |
---|
1402 | r->order = (int *) omAlloc(3 * sizeof(int *)); |
---|
1403 | r->block0 = (int *)omAlloc0(3 * sizeof(int *)); |
---|
1404 | r->block1 = (int *)omAlloc0(3 * sizeof(int *)); |
---|
1405 | /* ringorder dp for the first block: var 1..3 */ |
---|
1406 | r->order[0] = ringorder_dp; |
---|
1407 | r->block0[0] = 1; |
---|
1408 | r->block1[0] = 3; |
---|
1409 | /* ringorder C for the second block: no vars */ |
---|
1410 | r->order[1] = ringorder_C; |
---|
1411 | /* the last block: everything is 0 */ |
---|
1412 | r->order[2] = 0; |
---|
1413 | /*polynomial ring*/ |
---|
1414 | r->OrdSgn = 1; |
---|
1415 | |
---|
1416 | /* complete ring intializations */ |
---|
1417 | rComplete(r); |
---|
1418 | rSetHdl(tmp); |
---|
1419 | return currRingHdl; |
---|
1420 | } |
---|
1421 | |
---|
1422 | idhdl rFindHdl(ring r, idhdl n, idhdl w) |
---|
1423 | { |
---|
1424 | idhdl h=rSimpleFindHdl(r,IDROOT,n); |
---|
1425 | if (h!=NULL) return h; |
---|
1426 | #ifdef HAVE_NS |
---|
1427 | if (IDROOT!=basePack->idroot) h=rSimpleFindHdl(r,basePack->idroot,n); |
---|
1428 | if (h!=NULL) return h; |
---|
1429 | proclevel *p=procstack; |
---|
1430 | while(p!=NULL) |
---|
1431 | { |
---|
1432 | if ((p->cPack!=basePack) |
---|
1433 | && (p->cPack!=currPack)) |
---|
1434 | h=rSimpleFindHdl(r,p->cPack->idroot,n); |
---|
1435 | if (h!=NULL) return h; |
---|
1436 | p=p->next; |
---|
1437 | } |
---|
1438 | idhdl tmp=basePack->idroot; |
---|
1439 | while (tmp!=NULL) |
---|
1440 | { |
---|
1441 | if (IDTYP(tmp)==PACKAGE_CMD) |
---|
1442 | h=rSimpleFindHdl(r,IDPACKAGE(tmp)->idroot,n); |
---|
1443 | if (h!=NULL) return h; |
---|
1444 | tmp=IDNEXT(tmp); |
---|
1445 | } |
---|
1446 | #endif |
---|
1447 | return NULL; |
---|
1448 | } |
---|
1449 | |
---|
1450 | lists rDecompose(ring r) |
---|
1451 | { |
---|
1452 | // 0: char/ cf - ring |
---|
1453 | // 1: list (var) |
---|
1454 | // 2: list (ord) |
---|
1455 | // 3: qideal |
---|
1456 | lists L=(lists)omAlloc0Bin(slists_bin); |
---|
1457 | L->Init(4); |
---|
1458 | // ---------------------------------------- |
---|
1459 | // 0: char/ cf - ring |
---|
1460 | #if 0 /* TODO */ |
---|
1461 | if (rIsExtension(r)) |
---|
1462 | rDecomposeCF(&(L->m[0]),r); |
---|
1463 | else |
---|
1464 | #endif |
---|
1465 | { |
---|
1466 | L->m[0].rtyp=INT_CMD; |
---|
1467 | L->m[0].data=(void *)r->ch; |
---|
1468 | } |
---|
1469 | // ---------------------------------------- |
---|
1470 | // 1: list (var) |
---|
1471 | lists LL=(lists)omAlloc0Bin(slists_bin); |
---|
1472 | LL->Init(r->N); |
---|
1473 | int i; |
---|
1474 | for(i=0; i<r->N; i++) |
---|
1475 | { |
---|
1476 | LL->m[i].rtyp=STRING_CMD; |
---|
1477 | LL->m[i].data=(void *)omStrDup(r->names[i]); |
---|
1478 | } |
---|
1479 | L->m[1].rtyp=LIST_CMD; |
---|
1480 | L->m[1].data=(void *)LL; |
---|
1481 | // ---------------------------------------- |
---|
1482 | // 2: list (ord) |
---|
1483 | LL=(lists)omAlloc0Bin(slists_bin); |
---|
1484 | i=rBlocks(r)-1; |
---|
1485 | LL->Init(i); |
---|
1486 | i--; |
---|
1487 | lists LLL; |
---|
1488 | for(; i>=0; i--) |
---|
1489 | { |
---|
1490 | intvec *iv; |
---|
1491 | int j; |
---|
1492 | LL->m[i].rtyp=LIST_CMD; |
---|
1493 | LLL=(lists)omAlloc0Bin(slists_bin); |
---|
1494 | LLL->Init(2); |
---|
1495 | LLL->m[0].rtyp=STRING_CMD; |
---|
1496 | LLL->m[0].data=(void *)omStrDup(rSimpleOrdStr(r->order[i])); |
---|
1497 | if (r->block1[i]-r->block0[i] >=0 ) |
---|
1498 | { |
---|
1499 | j=r->block1[i]-r->block0[i]; |
---|
1500 | iv=new intvec(j+1); |
---|
1501 | if ((r->wvhdl!=NULL) && (r->wvhdl[i]!=NULL)) |
---|
1502 | { |
---|
1503 | for(;j>=0; j--) (*iv)[j]=r->wvhdl[i][j]; |
---|
1504 | } |
---|
1505 | else switch (r->order[i]) |
---|
1506 | { |
---|
1507 | case ringorder_dp: |
---|
1508 | case ringorder_Dp: |
---|
1509 | case ringorder_ds: |
---|
1510 | case ringorder_Ds: |
---|
1511 | case ringorder_lp: |
---|
1512 | for(;j>=0; j--) (*iv)[j]=1; |
---|
1513 | break; |
---|
1514 | default: /* do nothing */; |
---|
1515 | } |
---|
1516 | } |
---|
1517 | else |
---|
1518 | { |
---|
1519 | iv=new intvec(1); |
---|
1520 | } |
---|
1521 | LLL->m[1].rtyp=INTVEC_CMD; |
---|
1522 | LLL->m[1].data=(void *)iv; |
---|
1523 | LL->m[i].data=(void *)LLL; |
---|
1524 | } |
---|
1525 | L->m[2].rtyp=LIST_CMD; |
---|
1526 | L->m[2].data=(void *)LL; |
---|
1527 | // ---------------------------------------- |
---|
1528 | // 3: qideal |
---|
1529 | L->m[3].rtyp=IDEAL_CMD; |
---|
1530 | if (r->qideal==NULL) |
---|
1531 | L->m[3].data=(void *)idInit(1,1); |
---|
1532 | else |
---|
1533 | L->m[3].data=(void *)idCopy(r->qideal); |
---|
1534 | // ---------------------------------------- |
---|
1535 | return L; |
---|
1536 | } |
---|
1537 | |
---|
1538 | ring rCompose(lists L) |
---|
1539 | { |
---|
1540 | if (L->nr!=3) return NULL; |
---|
1541 | // 0: char/ cf - ring |
---|
1542 | // 1: list (var) |
---|
1543 | // 2: list (ord) |
---|
1544 | // 3: qideal |
---|
1545 | ring R=(ring) omAlloc0Bin(sip_sring_bin); |
---|
1546 | if (L->m[0].Typ()==INT_CMD) |
---|
1547 | { |
---|
1548 | R->ch=(int)L->m[0].Data(); |
---|
1549 | } |
---|
1550 | else if (L->m[0].Typ()==LIST_CMD) |
---|
1551 | { |
---|
1552 | R->algring=rCompose((lists)L->m[0].Data()); |
---|
1553 | if (R->algring==NULL) |
---|
1554 | { |
---|
1555 | WerrorS("could not create rational function coefficient field"); |
---|
1556 | goto rCompose_err; |
---|
1557 | } |
---|
1558 | R->ch=R->algring->ch; |
---|
1559 | R->parameter=R->algring->names; |
---|
1560 | R->P=R->algring->N; |
---|
1561 | } |
---|
1562 | else |
---|
1563 | { |
---|
1564 | WerrorS("coefficient field must be described by `int` or `list`"); |
---|
1565 | goto rCompose_err; |
---|
1566 | } |
---|
1567 | // ------------------------- VARS --------------------------- |
---|
1568 | if (L->m[1].Typ()==LIST_CMD) |
---|
1569 | { |
---|
1570 | lists v=(lists)L->m[1].Data(); |
---|
1571 | R->N = v->nr+1; |
---|
1572 | R->names = (char **)omAlloc0(R->N * sizeof(char_ptr)); |
---|
1573 | int i; |
---|
1574 | for(i=0;i<R->N;i++) |
---|
1575 | { |
---|
1576 | if (v->m[i].Typ()==STRING_CMD) |
---|
1577 | R->names[i]=omStrDup((char *)v->m[i].Data()); |
---|
1578 | else if (v->m[i].Typ()==POLY_CMD) |
---|
1579 | { |
---|
1580 | poly p=(poly)v->m[i].Data(); |
---|
1581 | int nr=pIsPurePower(p); |
---|
1582 | if (nr>0) |
---|
1583 | R->names[i]=omStrDup(currRing->names[nr-1]); |
---|
1584 | else |
---|
1585 | { |
---|
1586 | Werror("var name %d must be a string or a ring variable",i+1); |
---|
1587 | goto rCompose_err; |
---|
1588 | } |
---|
1589 | } |
---|
1590 | else |
---|
1591 | { |
---|
1592 | Werror("var name %d must be `string`",i+1); |
---|
1593 | goto rCompose_err; |
---|
1594 | } |
---|
1595 | } |
---|
1596 | } |
---|
1597 | else |
---|
1598 | { |
---|
1599 | WerrorS("variable must be given as `list`"); |
---|
1600 | goto rCompose_err; |
---|
1601 | } |
---|
1602 | // ------------------------ ORDER ------------------------------ |
---|
1603 | if (L->m[2].Typ()==LIST_CMD) |
---|
1604 | { |
---|
1605 | lists v=(lists)L->m[2].Data(); |
---|
1606 | int n= v->nr+2; |
---|
1607 | int j; |
---|
1608 | // initialize fields of R |
---|
1609 | R->order=(int *)omAlloc0(n*sizeof(int)); |
---|
1610 | R->block0=(int *)omAlloc0(n*sizeof(int)); |
---|
1611 | R->block1=(int *)omAlloc0(n*sizeof(int)); |
---|
1612 | R->wvhdl=(int**)omAlloc0(n*sizeof(int_ptr)); |
---|
1613 | // init order, so that rBlocks works correctly |
---|
1614 | for (j=0; j < n-2; j++) |
---|
1615 | R->order[j] = (int) ringorder_unspec; |
---|
1616 | // orderings |
---|
1617 | R->OrdSgn=1; |
---|
1618 | for(j=0;j<n-1;j++) |
---|
1619 | { |
---|
1620 | // todo: a(..), M |
---|
1621 | if (v->m[j].Typ()!=LIST_CMD) |
---|
1622 | { |
---|
1623 | WerrorS("ordering must be list of lists"); |
---|
1624 | goto rCompose_err; |
---|
1625 | } |
---|
1626 | lists vv=(lists)v->m[j].Data(); |
---|
1627 | if ((vv->nr!=1) |
---|
1628 | || (vv->m[0].Typ()!=STRING_CMD) |
---|
1629 | || ((vv->m[1].Typ()!=INTVEC_CMD) && (vv->m[1].Typ()!=INT_CMD))) |
---|
1630 | { |
---|
1631 | WerrorS("ordering name must be a (string,intvec)"); |
---|
1632 | goto rCompose_err; |
---|
1633 | } |
---|
1634 | R->order[j]=rOrderName(omStrDup((char*)vv->m[0].Data())); // assume STRING |
---|
1635 | if (j==0) R->block0[0]=1; |
---|
1636 | else R->block0[j]=R->block1[j-1]+1; |
---|
1637 | intvec *iv; |
---|
1638 | if (vv->m[1].Typ()==INT_CMD) |
---|
1639 | iv=new intvec((int)vv->m[1].Data(),(int)vv->m[1].Data()); |
---|
1640 | else |
---|
1641 | iv=ivCopy((intvec*)vv->m[1].Data()); //assume INTVEC |
---|
1642 | R->block1[j]=max(R->block0[j],R->block0[j]+iv->length()-1); |
---|
1643 | int i; |
---|
1644 | switch (R->order[j]) |
---|
1645 | { |
---|
1646 | case ringorder_ws: |
---|
1647 | case ringorder_Ws: |
---|
1648 | R->OrdSgn=-1; |
---|
1649 | case ringorder_wp: |
---|
1650 | case ringorder_Wp: |
---|
1651 | R->wvhdl[j] =( int *)omAlloc((iv->length())*sizeof(int)); |
---|
1652 | for (i=0; i<iv->length();i++) R->wvhdl[j][i]=(*iv)[i]; |
---|
1653 | break; |
---|
1654 | case ringorder_ls: |
---|
1655 | case ringorder_ds: |
---|
1656 | case ringorder_Ds: |
---|
1657 | R->OrdSgn=-1; |
---|
1658 | case ringorder_lp: |
---|
1659 | case ringorder_dp: |
---|
1660 | case ringorder_Dp: |
---|
1661 | case ringorder_rp: |
---|
1662 | break; |
---|
1663 | case ringorder_S: |
---|
1664 | break; |
---|
1665 | case ringorder_c: |
---|
1666 | case ringorder_C: |
---|
1667 | R->block1[j]=R->block0[j]-1; |
---|
1668 | break; |
---|
1669 | case ringorder_aa: |
---|
1670 | case ringorder_a: |
---|
1671 | R->wvhdl[j] =( int *)omAlloc((iv->length())*sizeof(int)); |
---|
1672 | for (i=1; i<iv->length();i++) R->wvhdl[n][i-1]=(*iv)[i]; |
---|
1673 | // todo |
---|
1674 | break; |
---|
1675 | case ringorder_M: |
---|
1676 | // todo |
---|
1677 | break; |
---|
1678 | } |
---|
1679 | } |
---|
1680 | // sanity check |
---|
1681 | j=n-2; |
---|
1682 | if ((R->order[j]==ringorder_c) |
---|
1683 | || (R->order[j]==ringorder_C)) j--; |
---|
1684 | if (R->block1[j] != R->N) |
---|
1685 | { |
---|
1686 | if (((R->order[j]==ringorder_dp) || |
---|
1687 | (R->order[j]==ringorder_ds) || |
---|
1688 | (R->order[j]==ringorder_Dp) || |
---|
1689 | (R->order[j]==ringorder_Ds) || |
---|
1690 | (R->order[j]==ringorder_rp) || |
---|
1691 | (R->order[j]==ringorder_lp) || |
---|
1692 | (R->order[j]==ringorder_ls)) |
---|
1693 | && |
---|
1694 | R->block0[j] <= R->N) |
---|
1695 | { |
---|
1696 | R->block1[j] = R->N; |
---|
1697 | } |
---|
1698 | else |
---|
1699 | { |
---|
1700 | Werror("ordering incomplete: size (%d) should be %d",R->block1[j],R->N); |
---|
1701 | goto rCompose_err; |
---|
1702 | } |
---|
1703 | } |
---|
1704 | } |
---|
1705 | else |
---|
1706 | { |
---|
1707 | WerrorS("ordering must be given as `list`"); |
---|
1708 | goto rCompose_err; |
---|
1709 | } |
---|
1710 | // ------------------------ Q-IDEAL ------------------------ |
---|
1711 | if (L->m[3].Typ()==IDEAL_CMD) |
---|
1712 | { |
---|
1713 | ideal q=(ideal)L->m[3].Data(); |
---|
1714 | if (q->m[0]!=NULL) |
---|
1715 | R->qideal=idCopy(q); |
---|
1716 | } |
---|
1717 | else |
---|
1718 | { |
---|
1719 | WerrorS("q-ideal must be given as `ideal`"); |
---|
1720 | goto rCompose_err; |
---|
1721 | } |
---|
1722 | |
---|
1723 | // todo |
---|
1724 | rComplete(R); |
---|
1725 | return R; |
---|
1726 | |
---|
1727 | rCompose_err: |
---|
1728 | if (R->N>0) |
---|
1729 | { |
---|
1730 | int i; |
---|
1731 | if (R->names!=NULL) |
---|
1732 | { |
---|
1733 | i=R->N; |
---|
1734 | while (i>=0) { if (R->names[i]!=NULL) omFree(R->names[i]); i--; } |
---|
1735 | omFree(R->names); |
---|
1736 | } |
---|
1737 | } |
---|
1738 | if (R->order!=NULL) omFree(R->order); |
---|
1739 | if (R->block0!=NULL) omFree(R->block0); |
---|
1740 | if (R->block1!=NULL) omFree(R->block1); |
---|
1741 | if (R->wvhdl!=NULL) omFree(R->wvhdl); |
---|
1742 | omFree(R); |
---|
1743 | return NULL; |
---|
1744 | } |
---|
1745 | |
---|
1746 | // from matpol.cc |
---|
1747 | |
---|
1748 | /*2 |
---|
1749 | * compute the jacobi matrix of an ideal |
---|
1750 | */ |
---|
1751 | BOOLEAN mpJacobi(leftv res,leftv a) |
---|
1752 | { |
---|
1753 | int i,j; |
---|
1754 | matrix result; |
---|
1755 | ideal id=(ideal)a->Data(); |
---|
1756 | |
---|
1757 | result =mpNew(IDELEMS(id),pVariables); |
---|
1758 | for (i=1; i<=IDELEMS(id); i++) |
---|
1759 | { |
---|
1760 | for (j=1; j<=pVariables; j++) |
---|
1761 | { |
---|
1762 | MATELEM(result,i,j) = pDiff(id->m[i-1],j); |
---|
1763 | } |
---|
1764 | } |
---|
1765 | res->data=(char *)result; |
---|
1766 | return FALSE; |
---|
1767 | } |
---|
1768 | |
---|
1769 | /*2 |
---|
1770 | * returns the Koszul-matrix of degree d of a vectorspace with dimension n |
---|
1771 | * uses the first n entrees of id, if id <> NULL |
---|
1772 | */ |
---|
1773 | BOOLEAN mpKoszul(leftv res,leftv c/*ip*/, leftv b/*in*/, leftv id) |
---|
1774 | { |
---|
1775 | int n=(int)b->Data(); |
---|
1776 | int d=(int)c->Data(); |
---|
1777 | int k,l,sign,row,col; |
---|
1778 | matrix result; |
---|
1779 | ideal temp; |
---|
1780 | BOOLEAN bo; |
---|
1781 | poly p; |
---|
1782 | |
---|
1783 | if ((d>n) || (d<1) || (n<1)) |
---|
1784 | { |
---|
1785 | res->data=(char *)mpNew(1,1); |
---|
1786 | return FALSE; |
---|
1787 | } |
---|
1788 | int *choise = (int*)omAlloc(d*sizeof(int)); |
---|
1789 | if (id==NULL) |
---|
1790 | temp=idMaxIdeal(1); |
---|
1791 | else |
---|
1792 | temp=(ideal)id->Data(); |
---|
1793 | |
---|
1794 | k = binom(n,d); |
---|
1795 | l = k*d; |
---|
1796 | l /= n-d+1; |
---|
1797 | result =mpNew(l,k); |
---|
1798 | col = 1; |
---|
1799 | idInitChoise(d,1,n,&bo,choise); |
---|
1800 | while (!bo) |
---|
1801 | { |
---|
1802 | sign = 1; |
---|
1803 | for (l=1;l<=d;l++) |
---|
1804 | { |
---|
1805 | if (choise[l-1]<=IDELEMS(temp)) |
---|
1806 | { |
---|
1807 | p = pCopy(temp->m[choise[l-1]-1]); |
---|
1808 | if (sign == -1) p = pNeg(p); |
---|
1809 | sign *= -1; |
---|
1810 | row = idGetNumberOfChoise(l-1,d,1,n,choise); |
---|
1811 | MATELEM(result,row,col) = p; |
---|
1812 | } |
---|
1813 | } |
---|
1814 | col++; |
---|
1815 | idGetNextChoise(d,n,&bo,choise); |
---|
1816 | } |
---|
1817 | if (id==NULL) idDelete(&temp); |
---|
1818 | |
---|
1819 | res->data=(char *)result; |
---|
1820 | return FALSE; |
---|
1821 | } |
---|
1822 | |
---|
1823 | // from syz1.cc |
---|
1824 | /*2 |
---|
1825 | * read out the Betti numbers from resolution |
---|
1826 | * (interpreter interface) |
---|
1827 | */ |
---|
1828 | BOOLEAN syBetti2(leftv res, leftv u, leftv w) |
---|
1829 | { |
---|
1830 | syStrategy syzstr=(syStrategy)u->Data(); |
---|
1831 | BOOLEAN minim=(int)w->Data(); |
---|
1832 | int row_shift=0; |
---|
1833 | int add_row_shift=0; |
---|
1834 | intvec *weights=NULL; |
---|
1835 | intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
1836 | if (ww!=NULL) |
---|
1837 | { |
---|
1838 | weights=ivCopy(ww); |
---|
1839 | add_row_shift = ww->min_in(); |
---|
1840 | (*weights) -= add_row_shift; |
---|
1841 | } |
---|
1842 | res->data=(void *)syBettiOfComputation(syzstr,minim,&row_shift,weights); |
---|
1843 | //row_shift += add_row_shift; |
---|
1844 | //Print("row_shift=%d, add_row_shift=%d\n",row_shift,add_row_shift); |
---|
1845 | atSet(res,omStrDup("rowShift"),(void*)add_row_shift,INT_CMD); |
---|
1846 | return FALSE; |
---|
1847 | } |
---|
1848 | BOOLEAN syBetti1(leftv res, leftv u) |
---|
1849 | { |
---|
1850 | sleftv tmp; |
---|
1851 | memset(&tmp,0,sizeof(tmp)); |
---|
1852 | tmp.rtyp=INT_CMD; |
---|
1853 | tmp.data=(void *)1; |
---|
1854 | return syBetti2(res,u,&tmp); |
---|
1855 | } |
---|
1856 | |
---|
1857 | /*3 |
---|
1858 | * converts a resolution into a list of modules |
---|
1859 | */ |
---|
1860 | lists syConvRes(syStrategy syzstr,BOOLEAN toDel) |
---|
1861 | { |
---|
1862 | if ((syzstr->fullres==NULL) && (syzstr->minres==NULL)) |
---|
1863 | { |
---|
1864 | if (syzstr->hilb_coeffs==NULL) |
---|
1865 | { |
---|
1866 | syzstr->fullres = syReorder(syzstr->res,syzstr->length,syzstr); |
---|
1867 | } |
---|
1868 | else |
---|
1869 | { |
---|
1870 | syzstr->minres = syReorder(syzstr->orderedRes,syzstr->length,syzstr); |
---|
1871 | syKillEmptyEntres(syzstr->minres,syzstr->length); |
---|
1872 | } |
---|
1873 | } |
---|
1874 | resolvente tr; |
---|
1875 | int typ0=IDEAL_CMD; |
---|
1876 | if (syzstr->minres!=NULL) |
---|
1877 | tr = syzstr->minres; |
---|
1878 | else |
---|
1879 | tr = syzstr->fullres; |
---|
1880 | resolvente trueres=NULL; |
---|
1881 | intvec ** w=NULL; |
---|
1882 | if (syzstr->length>0) |
---|
1883 | { |
---|
1884 | trueres=(resolvente)omAlloc0((syzstr->length)*sizeof(ideal)); |
---|
1885 | for (int i=(syzstr->length)-1;i>=0;i--) |
---|
1886 | { |
---|
1887 | if (tr[i]!=NULL) |
---|
1888 | { |
---|
1889 | trueres[i] = idCopy(tr[i]); |
---|
1890 | } |
---|
1891 | } |
---|
1892 | if (idRankFreeModule(trueres[0]) > 0) |
---|
1893 | typ0 = MODUL_CMD; |
---|
1894 | if (syzstr->weights!=NULL) |
---|
1895 | { |
---|
1896 | w = (intvec**)omAlloc0((syzstr->length)*sizeof(intvec*)); |
---|
1897 | for (int i=(syzstr->length)-1;i>=0;i--) |
---|
1898 | { |
---|
1899 | if (syzstr->weights[i]!=NULL) w[i] = ivCopy(syzstr->weights[i]); |
---|
1900 | } |
---|
1901 | } |
---|
1902 | } |
---|
1903 | lists li = liMakeResolv(trueres,syzstr->length,syzstr->list_length,typ0,w); |
---|
1904 | if (w != NULL) omFreeSize(w, (syzstr->length)*sizeof(intvec*)); |
---|
1905 | if (toDel) syKillComputation(syzstr); |
---|
1906 | return li; |
---|
1907 | } |
---|
1908 | |
---|
1909 | /*3 |
---|
1910 | * converts a list of modules into a resolution |
---|
1911 | */ |
---|
1912 | syStrategy syConvList(lists li,BOOLEAN toDel) |
---|
1913 | { |
---|
1914 | int typ0; |
---|
1915 | syStrategy result=(syStrategy)omAlloc0(sizeof(ssyStrategy)); |
---|
1916 | |
---|
1917 | resolvente fr = liFindRes(li,&(result->length),&typ0,&(result->weights)); |
---|
1918 | if (fr != NULL) |
---|
1919 | { |
---|
1920 | |
---|
1921 | result->fullres = (resolvente)omAlloc0((result->length+1)*sizeof(ideal)); |
---|
1922 | for (int i=result->length-1;i>=0;i--) |
---|
1923 | { |
---|
1924 | if (fr[i]!=NULL) |
---|
1925 | result->fullres[i] = idCopy(fr[i]); |
---|
1926 | } |
---|
1927 | result->list_length=result->length; |
---|
1928 | omFreeSize((ADDRESS)fr,(result->length)*sizeof(ideal)); |
---|
1929 | } |
---|
1930 | else |
---|
1931 | { |
---|
1932 | omFreeSize(result, sizeof(ssyStrategy)); |
---|
1933 | result = NULL; |
---|
1934 | } |
---|
1935 | if (toDel) li->Clean(); |
---|
1936 | return result; |
---|
1937 | } |
---|
1938 | |
---|
1939 | /*3 |
---|
1940 | * converts a list of modules into a minimal resolution |
---|
1941 | */ |
---|
1942 | syStrategy syForceMin(lists li) |
---|
1943 | { |
---|
1944 | int typ0; |
---|
1945 | syStrategy result=(syStrategy)omAlloc0(sizeof(ssyStrategy)); |
---|
1946 | |
---|
1947 | resolvente fr = liFindRes(li,&(result->length),&typ0); |
---|
1948 | result->minres = (resolvente)omAlloc0((result->length+1)*sizeof(ideal)); |
---|
1949 | for (int i=result->length-1;i>=0;i--) |
---|
1950 | { |
---|
1951 | if (fr[i]!=NULL) |
---|
1952 | result->minres[i] = idCopy(fr[i]); |
---|
1953 | } |
---|
1954 | omFreeSize((ADDRESS)fr,(result->length)*sizeof(ideal)); |
---|
1955 | return result; |
---|
1956 | } |
---|
1957 | // from weight.cc |
---|
1958 | BOOLEAN kWeight(leftv res,leftv id) |
---|
1959 | { |
---|
1960 | ideal F=(ideal)id->Data(); |
---|
1961 | intvec * iv = new intvec(pVariables); |
---|
1962 | polyset s; |
---|
1963 | int sl, n, i; |
---|
1964 | int *x; |
---|
1965 | |
---|
1966 | res->data=(char *)iv; |
---|
1967 | s = F->m; |
---|
1968 | sl = IDELEMS(F) - 1; |
---|
1969 | n = pVariables; |
---|
1970 | wNsqr = (double)2.0 / (double)n; |
---|
1971 | wFunctional = wFunctionalBuch; |
---|
1972 | x = (int * )omAlloc(2 * (n + 1) * sizeof(int)); |
---|
1973 | wCall(s, sl, x); |
---|
1974 | for (i = n; i!=0; i--) |
---|
1975 | (*iv)[i-1] = x[i + n + 1]; |
---|
1976 | omFreeSize((ADDRESS)x, 2 * (n + 1) * sizeof(int)); |
---|
1977 | return FALSE; |
---|
1978 | } |
---|
1979 | |
---|
1980 | BOOLEAN kQHWeight(leftv res,leftv v) |
---|
1981 | { |
---|
1982 | res->data=(char *)idQHomWeight((ideal)v->Data()); |
---|
1983 | if (res->data==NULL) |
---|
1984 | res->data=(char *)new intvec(pVariables); |
---|
1985 | return FALSE; |
---|
1986 | } |
---|
1987 | /*==============================================================*/ |
---|
1988 | // from clapsing.cc |
---|
1989 | #if 0 |
---|
1990 | BOOLEAN jjIS_SQR_FREE(leftv res, leftv u) |
---|
1991 | { |
---|
1992 | BOOLEAN b=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
1993 | res->data=(void *)b; |
---|
1994 | } |
---|
1995 | #endif |
---|
1996 | |
---|
1997 | BOOLEAN jjRESULTANT(leftv res, leftv u, leftv v, leftv w) |
---|
1998 | { |
---|
1999 | res->data=singclap_resultant((poly)u->Data(),(poly)v->Data(), (poly)w->Data()); |
---|
2000 | return errorreported; |
---|
2001 | } |
---|
2002 | BOOLEAN jjCHARSERIES(leftv res, leftv u) |
---|
2003 | { |
---|
2004 | res->data=singclap_irrCharSeries((ideal)u->Data()); |
---|
2005 | return (res->data==NULL); |
---|
2006 | } |
---|
2007 | |
---|
2008 | // from semic.cc |
---|
2009 | #ifdef HAVE_SPECTRUM |
---|
2010 | |
---|
2011 | // ---------------------------------------------------------------------------- |
---|
2012 | // Initialize a spectrum deep from another spectrum |
---|
2013 | // ---------------------------------------------------------------------------- |
---|
2014 | |
---|
2015 | void spectrum::copy_deep( const spectrum &spec ) |
---|
2016 | { |
---|
2017 | mu = spec.mu; |
---|
2018 | pg = spec.pg; |
---|
2019 | n = spec.n; |
---|
2020 | |
---|
2021 | copy_new( n ); |
---|
2022 | |
---|
2023 | for( int i=0; i<n; i++ ) |
---|
2024 | { |
---|
2025 | s[i] = spec.s[i]; |
---|
2026 | w[i] = spec.w[i]; |
---|
2027 | } |
---|
2028 | } |
---|
2029 | |
---|
2030 | // ---------------------------------------------------------------------------- |
---|
2031 | // Initialize a spectrum deep from a singular lists |
---|
2032 | // ---------------------------------------------------------------------------- |
---|
2033 | |
---|
2034 | void spectrum::copy_deep( lists l ) |
---|
2035 | { |
---|
2036 | mu = (int)(l->m[0].Data( )); |
---|
2037 | pg = (int)(l->m[1].Data( )); |
---|
2038 | n = (int)(l->m[2].Data( )); |
---|
2039 | |
---|
2040 | copy_new( n ); |
---|
2041 | |
---|
2042 | intvec *num = (intvec*)l->m[3].Data( ); |
---|
2043 | intvec *den = (intvec*)l->m[4].Data( ); |
---|
2044 | intvec *mul = (intvec*)l->m[5].Data( ); |
---|
2045 | |
---|
2046 | for( int i=0; i<n; i++ ) |
---|
2047 | { |
---|
2048 | s[i] = (Rational)((*num)[i])/(Rational)((*den)[i]); |
---|
2049 | w[i] = (*mul)[i]; |
---|
2050 | } |
---|
2051 | } |
---|
2052 | |
---|
2053 | // ---------------------------------------------------------------------------- |
---|
2054 | // singular lists constructor for spectrum |
---|
2055 | // ---------------------------------------------------------------------------- |
---|
2056 | |
---|
2057 | spectrum::spectrum( lists l ) |
---|
2058 | { |
---|
2059 | copy_deep( l ); |
---|
2060 | } |
---|
2061 | |
---|
2062 | // ---------------------------------------------------------------------------- |
---|
2063 | // generate a Singular lists from a spectrum |
---|
2064 | // ---------------------------------------------------------------------------- |
---|
2065 | |
---|
2066 | lists spectrum::thelist( void ) |
---|
2067 | { |
---|
2068 | lists L = (lists)omAllocBin( slists_bin); |
---|
2069 | |
---|
2070 | L->Init( 6 ); |
---|
2071 | |
---|
2072 | intvec *num = new intvec( n ); |
---|
2073 | intvec *den = new intvec( n ); |
---|
2074 | intvec *mult = new intvec( n ); |
---|
2075 | |
---|
2076 | for( int i=0; i<n; i++ ) |
---|
2077 | { |
---|
2078 | (*num) [i] = s[i].get_num_si( ); |
---|
2079 | (*den) [i] = s[i].get_den_si( ); |
---|
2080 | (*mult)[i] = w[i]; |
---|
2081 | } |
---|
2082 | |
---|
2083 | L->m[0].rtyp = INT_CMD; // milnor number |
---|
2084 | L->m[1].rtyp = INT_CMD; // geometrical genus |
---|
2085 | L->m[2].rtyp = INT_CMD; // # of spectrum numbers |
---|
2086 | L->m[3].rtyp = INTVEC_CMD; // numerators |
---|
2087 | L->m[4].rtyp = INTVEC_CMD; // denomiantors |
---|
2088 | L->m[5].rtyp = INTVEC_CMD; // multiplicities |
---|
2089 | |
---|
2090 | L->m[0].data = (void*)mu; |
---|
2091 | L->m[1].data = (void*)pg; |
---|
2092 | L->m[2].data = (void*)n; |
---|
2093 | L->m[3].data = (void*)num; |
---|
2094 | L->m[4].data = (void*)den; |
---|
2095 | L->m[5].data = (void*)mult; |
---|
2096 | |
---|
2097 | return L; |
---|
2098 | } |
---|
2099 | // from spectrum.cc |
---|
2100 | // ---------------------------------------------------------------------------- |
---|
2101 | // print out an error message for a spectrum list |
---|
2102 | // ---------------------------------------------------------------------------- |
---|
2103 | |
---|
2104 | void list_error( semicState state ) |
---|
2105 | { |
---|
2106 | switch( state ) |
---|
2107 | { |
---|
2108 | case semicListTooShort: |
---|
2109 | WerrorS( "the list is too short" ); |
---|
2110 | break; |
---|
2111 | case semicListTooLong: |
---|
2112 | WerrorS( "the list is too long" ); |
---|
2113 | break; |
---|
2114 | |
---|
2115 | case semicListFirstElementWrongType: |
---|
2116 | WerrorS( "first element of the list should be int" ); |
---|
2117 | break; |
---|
2118 | case semicListSecondElementWrongType: |
---|
2119 | WerrorS( "second element of the list should be int" ); |
---|
2120 | break; |
---|
2121 | case semicListThirdElementWrongType: |
---|
2122 | WerrorS( "third element of the list should be int" ); |
---|
2123 | break; |
---|
2124 | case semicListFourthElementWrongType: |
---|
2125 | WerrorS( "fourth element of the list should be intvec" ); |
---|
2126 | break; |
---|
2127 | case semicListFifthElementWrongType: |
---|
2128 | WerrorS( "fifth element of the list should be intvec" ); |
---|
2129 | break; |
---|
2130 | case semicListSixthElementWrongType: |
---|
2131 | WerrorS( "sixth element of the list should be intvec" ); |
---|
2132 | break; |
---|
2133 | |
---|
2134 | case semicListNNegative: |
---|
2135 | WerrorS( "first element of the list should be positive" ); |
---|
2136 | break; |
---|
2137 | case semicListWrongNumberOfNumerators: |
---|
2138 | WerrorS( "wrong number of numerators" ); |
---|
2139 | break; |
---|
2140 | case semicListWrongNumberOfDenominators: |
---|
2141 | WerrorS( "wrong number of denominators" ); |
---|
2142 | break; |
---|
2143 | case semicListWrongNumberOfMultiplicities: |
---|
2144 | WerrorS( "wrong number of multiplicities" ); |
---|
2145 | break; |
---|
2146 | |
---|
2147 | case semicListMuNegative: |
---|
2148 | WerrorS( "the Milnor number should be positive" ); |
---|
2149 | break; |
---|
2150 | case semicListPgNegative: |
---|
2151 | WerrorS( "the geometrical genus should be nonnegative" ); |
---|
2152 | break; |
---|
2153 | case semicListNumNegative: |
---|
2154 | WerrorS( "all numerators should be positive" ); |
---|
2155 | break; |
---|
2156 | case semicListDenNegative: |
---|
2157 | WerrorS( "all denominators should be positive" ); |
---|
2158 | break; |
---|
2159 | case semicListMulNegative: |
---|
2160 | WerrorS( "all multiplicities should be positive" ); |
---|
2161 | break; |
---|
2162 | |
---|
2163 | case semicListNotSymmetric: |
---|
2164 | WerrorS( "it is not symmetric" ); |
---|
2165 | break; |
---|
2166 | case semicListNotMonotonous: |
---|
2167 | WerrorS( "it is not monotonous" ); |
---|
2168 | break; |
---|
2169 | |
---|
2170 | case semicListMilnorWrong: |
---|
2171 | WerrorS( "the Milnor number is wrong" ); |
---|
2172 | break; |
---|
2173 | case semicListPGWrong: |
---|
2174 | WerrorS( "the geometrical genus is wrong" ); |
---|
2175 | break; |
---|
2176 | |
---|
2177 | default: |
---|
2178 | WerrorS( "unspecific error" ); |
---|
2179 | break; |
---|
2180 | } |
---|
2181 | } |
---|
2182 | // ---------------------------------------------------------------------------- |
---|
2183 | // this is the main spectrum computation function |
---|
2184 | // ---------------------------------------------------------------------------- |
---|
2185 | |
---|
2186 | spectrumState spectrumCompute( poly h,lists *L,int fast ) |
---|
2187 | { |
---|
2188 | int i,j; |
---|
2189 | |
---|
2190 | #ifdef SPECTRUM_DEBUG |
---|
2191 | #ifdef SPECTRUM_PRINT |
---|
2192 | #ifdef SPECTRUM_IOSTREAM |
---|
2193 | cout << "spectrumCompute\n"; |
---|
2194 | if( fast==0 ) cout << " no optimization" << endl; |
---|
2195 | if( fast==1 ) cout << " weight optimization" << endl; |
---|
2196 | if( fast==2 ) cout << " symmetry optimization" << endl; |
---|
2197 | #else |
---|
2198 | fprintf( stdout,"spectrumCompute\n" ); |
---|
2199 | if( fast==0 ) fprintf( stdout," no optimization\n" ); |
---|
2200 | if( fast==1 ) fprintf( stdout," weight optimization\n" ); |
---|
2201 | if( fast==2 ) fprintf( stdout," symmetry optimization\n" ); |
---|
2202 | #endif |
---|
2203 | #endif |
---|
2204 | #endif |
---|
2205 | |
---|
2206 | // ---------------------- |
---|
2207 | // check if h is zero |
---|
2208 | // ---------------------- |
---|
2209 | |
---|
2210 | if( h==(poly)NULL ) |
---|
2211 | { |
---|
2212 | return spectrumZero; |
---|
2213 | } |
---|
2214 | |
---|
2215 | // ---------------------------------- |
---|
2216 | // check if h has a constant term |
---|
2217 | // ---------------------------------- |
---|
2218 | |
---|
2219 | if( hasConstTerm( h ) ) |
---|
2220 | { |
---|
2221 | return spectrumBadPoly; |
---|
2222 | } |
---|
2223 | |
---|
2224 | // -------------------------------- |
---|
2225 | // check if h has a linear term |
---|
2226 | // -------------------------------- |
---|
2227 | |
---|
2228 | if( hasLinearTerm( h ) ) |
---|
2229 | { |
---|
2230 | *L = (lists)omAllocBin( slists_bin); |
---|
2231 | (*L)->Init( 1 ); |
---|
2232 | (*L)->m[0].rtyp = INT_CMD; // milnor number |
---|
2233 | /* (*L)->m[0].data = (void*)0;a -- done by Init */ |
---|
2234 | |
---|
2235 | return spectrumNoSingularity; |
---|
2236 | } |
---|
2237 | |
---|
2238 | // ---------------------------------- |
---|
2239 | // compute the jacobi ideal of (h) |
---|
2240 | // ---------------------------------- |
---|
2241 | |
---|
2242 | ideal J = NULL; |
---|
2243 | J = idInit( pVariables,1 ); |
---|
2244 | |
---|
2245 | #ifdef SPECTRUM_DEBUG |
---|
2246 | #ifdef SPECTRUM_PRINT |
---|
2247 | #ifdef SPECTRUM_IOSTREAM |
---|
2248 | cout << "\n computing the Jacobi ideal...\n"; |
---|
2249 | #else |
---|
2250 | fprintf( stdout,"\n computing the Jacobi ideal...\n" ); |
---|
2251 | #endif |
---|
2252 | #endif |
---|
2253 | #endif |
---|
2254 | |
---|
2255 | for( i=0; i<pVariables; i++ ) |
---|
2256 | { |
---|
2257 | J->m[i] = pDiff( h,i+1); //j ); |
---|
2258 | |
---|
2259 | #ifdef SPECTRUM_DEBUG |
---|
2260 | #ifdef SPECTRUM_PRINT |
---|
2261 | #ifdef SPECTRUM_IOSTREAM |
---|
2262 | cout << " "; |
---|
2263 | #else |
---|
2264 | fprintf( stdout," " ); |
---|
2265 | #endif |
---|
2266 | pWrite( J->m[i] ); |
---|
2267 | #endif |
---|
2268 | #endif |
---|
2269 | } |
---|
2270 | |
---|
2271 | // -------------------------------------------- |
---|
2272 | // compute a standard basis stdJ of jac(h) |
---|
2273 | // -------------------------------------------- |
---|
2274 | |
---|
2275 | #ifdef SPECTRUM_DEBUG |
---|
2276 | #ifdef SPECTRUM_PRINT |
---|
2277 | #ifdef SPECTRUM_IOSTREAM |
---|
2278 | cout << endl; |
---|
2279 | cout << " computing a standard basis..." << endl; |
---|
2280 | #else |
---|
2281 | fprintf( stdout,"\n" ); |
---|
2282 | fprintf( stdout," computing a standard basis...\n" ); |
---|
2283 | #endif |
---|
2284 | #endif |
---|
2285 | #endif |
---|
2286 | |
---|
2287 | ideal stdJ = kStd(J,currQuotient,isNotHomog,NULL); |
---|
2288 | idSkipZeroes( stdJ ); |
---|
2289 | |
---|
2290 | #ifdef SPECTRUM_DEBUG |
---|
2291 | #ifdef SPECTRUM_PRINT |
---|
2292 | for( i=0; i<IDELEMS(stdJ); i++ ) |
---|
2293 | { |
---|
2294 | #ifdef SPECTRUM_IOSTREAM |
---|
2295 | cout << " "; |
---|
2296 | #else |
---|
2297 | fprintf( stdout," " ); |
---|
2298 | #endif |
---|
2299 | |
---|
2300 | pWrite( stdJ->m[i] ); |
---|
2301 | } |
---|
2302 | #endif |
---|
2303 | #endif |
---|
2304 | |
---|
2305 | idDelete( &J ); |
---|
2306 | |
---|
2307 | // ------------------------------------------ |
---|
2308 | // check if the h has a singularity |
---|
2309 | // ------------------------------------------ |
---|
2310 | |
---|
2311 | if( hasOne( stdJ ) ) |
---|
2312 | { |
---|
2313 | // ------------------------------- |
---|
2314 | // h is smooth in the origin |
---|
2315 | // return only the Milnor number |
---|
2316 | // ------------------------------- |
---|
2317 | |
---|
2318 | *L = (lists)omAllocBin( slists_bin); |
---|
2319 | (*L)->Init( 1 ); |
---|
2320 | (*L)->m[0].rtyp = INT_CMD; // milnor number |
---|
2321 | /* (*L)->m[0].data = (void*)0;a -- done by Init */ |
---|
2322 | |
---|
2323 | return spectrumNoSingularity; |
---|
2324 | } |
---|
2325 | |
---|
2326 | // ------------------------------------------ |
---|
2327 | // check if the singularity h is isolated |
---|
2328 | // ------------------------------------------ |
---|
2329 | |
---|
2330 | for( i=pVariables; i>0; i-- ) |
---|
2331 | { |
---|
2332 | if( hasAxis( stdJ,i )==FALSE ) |
---|
2333 | { |
---|
2334 | return spectrumNotIsolated; |
---|
2335 | } |
---|
2336 | } |
---|
2337 | |
---|
2338 | // ------------------------------------------ |
---|
2339 | // compute the highest corner hc of stdJ |
---|
2340 | // ------------------------------------------ |
---|
2341 | |
---|
2342 | #ifdef SPECTRUM_DEBUG |
---|
2343 | #ifdef SPECTRUM_PRINT |
---|
2344 | #ifdef SPECTRUM_IOSTREAM |
---|
2345 | cout << "\n computing the highest corner...\n"; |
---|
2346 | #else |
---|
2347 | fprintf( stdout,"\n computing the highest corner...\n" ); |
---|
2348 | #endif |
---|
2349 | #endif |
---|
2350 | #endif |
---|
2351 | |
---|
2352 | poly hc = (poly)NULL; |
---|
2353 | |
---|
2354 | scComputeHC( stdJ,currQuotient, 0,hc ); |
---|
2355 | |
---|
2356 | if( hc!=(poly)NULL ) |
---|
2357 | { |
---|
2358 | pGetCoeff(hc) = nInit(1); |
---|
2359 | |
---|
2360 | for( i=pVariables; i>0; i-- ) |
---|
2361 | { |
---|
2362 | if( pGetExp( hc,i )>0 ) pDecrExp( hc,i ); |
---|
2363 | } |
---|
2364 | pSetm( hc ); |
---|
2365 | } |
---|
2366 | else |
---|
2367 | { |
---|
2368 | return spectrumNoHC; |
---|
2369 | } |
---|
2370 | |
---|
2371 | #ifdef SPECTRUM_DEBUG |
---|
2372 | #ifdef SPECTRUM_PRINT |
---|
2373 | #ifdef SPECTRUM_IOSTREAM |
---|
2374 | cout << " "; |
---|
2375 | #else |
---|
2376 | fprintf( stdout," " ); |
---|
2377 | #endif |
---|
2378 | pWrite( hc ); |
---|
2379 | #endif |
---|
2380 | #endif |
---|
2381 | |
---|
2382 | // ---------------------------------------- |
---|
2383 | // compute the Newton polygon nph of h |
---|
2384 | // ---------------------------------------- |
---|
2385 | |
---|
2386 | #ifdef SPECTRUM_DEBUG |
---|
2387 | #ifdef SPECTRUM_PRINT |
---|
2388 | #ifdef SPECTRUM_IOSTREAM |
---|
2389 | cout << "\n computing the newton polygon...\n"; |
---|
2390 | #else |
---|
2391 | fprintf( stdout,"\n computing the newton polygon...\n" ); |
---|
2392 | #endif |
---|
2393 | #endif |
---|
2394 | #endif |
---|
2395 | |
---|
2396 | newtonPolygon nph( h ); |
---|
2397 | |
---|
2398 | #ifdef SPECTRUM_DEBUG |
---|
2399 | #ifdef SPECTRUM_PRINT |
---|
2400 | cout << nph; |
---|
2401 | #endif |
---|
2402 | #endif |
---|
2403 | |
---|
2404 | // ----------------------------------------------- |
---|
2405 | // compute the weight corner wc of (stdj,nph) |
---|
2406 | // ----------------------------------------------- |
---|
2407 | |
---|
2408 | #ifdef SPECTRUM_DEBUG |
---|
2409 | #ifdef SPECTRUM_PRINT |
---|
2410 | #ifdef SPECTRUM_IOSTREAM |
---|
2411 | cout << "\n computing the weight corner...\n"; |
---|
2412 | #else |
---|
2413 | fprintf( stdout,"\n computing the weight corner...\n" ); |
---|
2414 | #endif |
---|
2415 | #endif |
---|
2416 | #endif |
---|
2417 | |
---|
2418 | poly wc = ( fast==0 ? pCopy( hc ) : |
---|
2419 | ( fast==1 ? computeWC( nph,(Rational)pVariables ) : |
---|
2420 | /* fast==2 */computeWC( nph,((Rational)pVariables)/(Rational)2 ) ) ); |
---|
2421 | |
---|
2422 | #ifdef SPECTRUM_DEBUG |
---|
2423 | #ifdef SPECTRUM_PRINT |
---|
2424 | #ifdef SPECTRUM_IOSTREAM |
---|
2425 | cout << " "; |
---|
2426 | #else |
---|
2427 | fprintf( stdout," " ); |
---|
2428 | #endif |
---|
2429 | pWrite( wc ); |
---|
2430 | #endif |
---|
2431 | #endif |
---|
2432 | |
---|
2433 | // ------------- |
---|
2434 | // compute NF |
---|
2435 | // ------------- |
---|
2436 | |
---|
2437 | #ifdef SPECTRUM_DEBUG |
---|
2438 | #ifdef SPECTRUM_PRINT |
---|
2439 | #ifdef SPECTRUM_IOSTREAM |
---|
2440 | cout << "\n computing NF...\n" << endl; |
---|
2441 | #else |
---|
2442 | fprintf( stdout,"\n computing NF...\n" ); |
---|
2443 | #endif |
---|
2444 | #endif |
---|
2445 | #endif |
---|
2446 | |
---|
2447 | spectrumPolyList NF( &nph ); |
---|
2448 | |
---|
2449 | computeNF( stdJ,hc,wc,&NF ); |
---|
2450 | |
---|
2451 | #ifdef SPECTRUM_DEBUG |
---|
2452 | #ifdef SPECTRUM_PRINT |
---|
2453 | cout << NF; |
---|
2454 | #ifdef SPECTRUM_IOSTREAM |
---|
2455 | cout << endl; |
---|
2456 | #else |
---|
2457 | fprintf( stdout,"\n" ); |
---|
2458 | #endif |
---|
2459 | #endif |
---|
2460 | #endif |
---|
2461 | |
---|
2462 | // ---------------------------- |
---|
2463 | // compute the spectrum of h |
---|
2464 | // ---------------------------- |
---|
2465 | |
---|
2466 | return NF.spectrum( L,fast ); |
---|
2467 | } |
---|
2468 | |
---|
2469 | // ---------------------------------------------------------------------------- |
---|
2470 | // this procedure is called from the interpreter |
---|
2471 | // ---------------------------------------------------------------------------- |
---|
2472 | // first = polynomial |
---|
2473 | // result = list of spectrum numbers |
---|
2474 | // ---------------------------------------------------------------------------- |
---|
2475 | |
---|
2476 | BOOLEAN spectrumProc( leftv result,leftv first ) |
---|
2477 | { |
---|
2478 | spectrumState state = spectrumOK; |
---|
2479 | |
---|
2480 | // ------------------- |
---|
2481 | // check consistency |
---|
2482 | // ------------------- |
---|
2483 | |
---|
2484 | // check for a local ring |
---|
2485 | |
---|
2486 | if( !ringIsLocal( ) ) |
---|
2487 | { |
---|
2488 | WerrorS( "only works for local orderings" ); |
---|
2489 | state = spectrumWrongRing; |
---|
2490 | } |
---|
2491 | |
---|
2492 | // no quotient rings are allowed |
---|
2493 | |
---|
2494 | else if( currRing->qideal != NULL ) |
---|
2495 | { |
---|
2496 | WerrorS( "does not work in quotient rings" ); |
---|
2497 | state = spectrumWrongRing; |
---|
2498 | } |
---|
2499 | else |
---|
2500 | { |
---|
2501 | lists L = (lists)NULL; |
---|
2502 | int flag = 1; // weight corner optimization is safe |
---|
2503 | |
---|
2504 | state = spectrumCompute( (poly)first->Data( ),&L,flag ); |
---|
2505 | |
---|
2506 | if( state==spectrumOK ) |
---|
2507 | { |
---|
2508 | result->rtyp = LIST_CMD; |
---|
2509 | result->data = (char*)L; |
---|
2510 | } |
---|
2511 | else |
---|
2512 | { |
---|
2513 | spectrumPrintError(state); |
---|
2514 | } |
---|
2515 | } |
---|
2516 | |
---|
2517 | return (state!=spectrumOK); |
---|
2518 | } |
---|
2519 | |
---|
2520 | // ---------------------------------------------------------------------------- |
---|
2521 | // this procedure is called from the interpreter |
---|
2522 | // ---------------------------------------------------------------------------- |
---|
2523 | // first = polynomial |
---|
2524 | // result = list of spectrum numbers |
---|
2525 | // ---------------------------------------------------------------------------- |
---|
2526 | |
---|
2527 | BOOLEAN spectrumfProc( leftv result,leftv first ) |
---|
2528 | { |
---|
2529 | spectrumState state = spectrumOK; |
---|
2530 | |
---|
2531 | // ------------------- |
---|
2532 | // check consistency |
---|
2533 | // ------------------- |
---|
2534 | |
---|
2535 | // check for a local polynomial ring |
---|
2536 | |
---|
2537 | if( currRing->OrdSgn != -1 ) |
---|
2538 | // ?? HS: the test above is also true for k[x][[y]], k[[x]][y] |
---|
2539 | // or should we use: |
---|
2540 | //if( !ringIsLocal( ) ) |
---|
2541 | { |
---|
2542 | WerrorS( "only works for local orderings" ); |
---|
2543 | state = spectrumWrongRing; |
---|
2544 | } |
---|
2545 | else if( currRing->qideal != NULL ) |
---|
2546 | { |
---|
2547 | WerrorS( "does not work in quotient rings" ); |
---|
2548 | state = spectrumWrongRing; |
---|
2549 | } |
---|
2550 | else |
---|
2551 | { |
---|
2552 | lists L = (lists)NULL; |
---|
2553 | int flag = 2; // symmetric optimization |
---|
2554 | |
---|
2555 | state = spectrumCompute( (poly)first->Data( ),&L,flag ); |
---|
2556 | |
---|
2557 | if( state==spectrumOK ) |
---|
2558 | { |
---|
2559 | result->rtyp = LIST_CMD; |
---|
2560 | result->data = (char*)L; |
---|
2561 | } |
---|
2562 | else |
---|
2563 | { |
---|
2564 | spectrumPrintError(state); |
---|
2565 | } |
---|
2566 | } |
---|
2567 | |
---|
2568 | return (state!=spectrumOK); |
---|
2569 | } |
---|
2570 | |
---|
2571 | // ---------------------------------------------------------------------------- |
---|
2572 | // check if a list is a spectrum |
---|
2573 | // check for: |
---|
2574 | // list has 6 elements |
---|
2575 | // 1st element is int (mu=Milnor number) |
---|
2576 | // 2nd element is int (pg=geometrical genus) |
---|
2577 | // 3rd element is int (n =number of different spectrum numbers) |
---|
2578 | // 4th element is intvec (num=numerators) |
---|
2579 | // 5th element is intvec (den=denomiantors) |
---|
2580 | // 6th element is intvec (mul=multiplicities) |
---|
2581 | // exactly n numerators |
---|
2582 | // exactly n denominators |
---|
2583 | // exactly n multiplicities |
---|
2584 | // mu>0 |
---|
2585 | // pg>=0 |
---|
2586 | // n>0 |
---|
2587 | // num>0 |
---|
2588 | // den>0 |
---|
2589 | // mul>0 |
---|
2590 | // symmetriy with respect to numberofvariables/2 |
---|
2591 | // monotony |
---|
2592 | // mu = sum of all multiplicities |
---|
2593 | // pg = sum of all multiplicities where num/den<=1 |
---|
2594 | // ---------------------------------------------------------------------------- |
---|
2595 | |
---|
2596 | semicState list_is_spectrum( lists l ) |
---|
2597 | { |
---|
2598 | // ------------------- |
---|
2599 | // check list length |
---|
2600 | // ------------------- |
---|
2601 | |
---|
2602 | if( l->nr < 5 ) |
---|
2603 | { |
---|
2604 | return semicListTooShort; |
---|
2605 | } |
---|
2606 | else if( l->nr > 5 ) |
---|
2607 | { |
---|
2608 | return semicListTooLong; |
---|
2609 | } |
---|
2610 | |
---|
2611 | // ------------- |
---|
2612 | // check types |
---|
2613 | // ------------- |
---|
2614 | |
---|
2615 | if( l->m[0].rtyp != INT_CMD ) |
---|
2616 | { |
---|
2617 | return semicListFirstElementWrongType; |
---|
2618 | } |
---|
2619 | else if( l->m[1].rtyp != INT_CMD ) |
---|
2620 | { |
---|
2621 | return semicListSecondElementWrongType; |
---|
2622 | } |
---|
2623 | else if( l->m[2].rtyp != INT_CMD ) |
---|
2624 | { |
---|
2625 | return semicListThirdElementWrongType; |
---|
2626 | } |
---|
2627 | else if( l->m[3].rtyp != INTVEC_CMD ) |
---|
2628 | { |
---|
2629 | return semicListFourthElementWrongType; |
---|
2630 | } |
---|
2631 | else if( l->m[4].rtyp != INTVEC_CMD ) |
---|
2632 | { |
---|
2633 | return semicListFifthElementWrongType; |
---|
2634 | } |
---|
2635 | else if( l->m[5].rtyp != INTVEC_CMD ) |
---|
2636 | { |
---|
2637 | return semicListSixthElementWrongType; |
---|
2638 | } |
---|
2639 | |
---|
2640 | // ------------------------- |
---|
2641 | // check number of entries |
---|
2642 | // ------------------------- |
---|
2643 | |
---|
2644 | int mu = (int)(l->m[0].Data( )); |
---|
2645 | int pg = (int)(l->m[1].Data( )); |
---|
2646 | int n = (int)(l->m[2].Data( )); |
---|
2647 | |
---|
2648 | if( n <= 0 ) |
---|
2649 | { |
---|
2650 | return semicListNNegative; |
---|
2651 | } |
---|
2652 | |
---|
2653 | intvec *num = (intvec*)l->m[3].Data( ); |
---|
2654 | intvec *den = (intvec*)l->m[4].Data( ); |
---|
2655 | intvec *mul = (intvec*)l->m[5].Data( ); |
---|
2656 | |
---|
2657 | if( n != num->length( ) ) |
---|
2658 | { |
---|
2659 | return semicListWrongNumberOfNumerators; |
---|
2660 | } |
---|
2661 | else if( n != den->length( ) ) |
---|
2662 | { |
---|
2663 | return semicListWrongNumberOfDenominators; |
---|
2664 | } |
---|
2665 | else if( n != mul->length( ) ) |
---|
2666 | { |
---|
2667 | return semicListWrongNumberOfMultiplicities; |
---|
2668 | } |
---|
2669 | |
---|
2670 | // -------- |
---|
2671 | // values |
---|
2672 | // -------- |
---|
2673 | |
---|
2674 | if( mu <= 0 ) |
---|
2675 | { |
---|
2676 | return semicListMuNegative; |
---|
2677 | } |
---|
2678 | if( pg < 0 ) |
---|
2679 | { |
---|
2680 | return semicListPgNegative; |
---|
2681 | } |
---|
2682 | |
---|
2683 | int i; |
---|
2684 | |
---|
2685 | for( i=0; i<n; i++ ) |
---|
2686 | { |
---|
2687 | if( (*num)[i] <= 0 ) |
---|
2688 | { |
---|
2689 | return semicListNumNegative; |
---|
2690 | } |
---|
2691 | if( (*den)[i] <= 0 ) |
---|
2692 | { |
---|
2693 | return semicListDenNegative; |
---|
2694 | } |
---|
2695 | if( (*mul)[i] <= 0 ) |
---|
2696 | { |
---|
2697 | return semicListMulNegative; |
---|
2698 | } |
---|
2699 | } |
---|
2700 | |
---|
2701 | // ---------------- |
---|
2702 | // check symmetry |
---|
2703 | // ---------------- |
---|
2704 | |
---|
2705 | int j; |
---|
2706 | |
---|
2707 | for( i=0, j=n-1; i<=j; i++,j-- ) |
---|
2708 | { |
---|
2709 | if( (*num)[i] != pVariables*((*den)[i]) - (*num)[j] || |
---|
2710 | (*den)[i] != (*den)[j] || |
---|
2711 | (*mul)[i] != (*mul)[j] ) |
---|
2712 | { |
---|
2713 | return semicListNotSymmetric; |
---|
2714 | } |
---|
2715 | } |
---|
2716 | |
---|
2717 | // ---------------- |
---|
2718 | // check monotony |
---|
2719 | // ---------------- |
---|
2720 | |
---|
2721 | for( i=0, j=1; i<n/2; i++,j++ ) |
---|
2722 | { |
---|
2723 | if( (*num)[i]*(*den)[j] >= (*num)[j]*(*den)[i] ) |
---|
2724 | { |
---|
2725 | return semicListNotMonotonous; |
---|
2726 | } |
---|
2727 | } |
---|
2728 | |
---|
2729 | // --------------------- |
---|
2730 | // check Milnor number |
---|
2731 | // --------------------- |
---|
2732 | |
---|
2733 | for( mu=0, i=0; i<n; i++ ) |
---|
2734 | { |
---|
2735 | mu += (*mul)[i]; |
---|
2736 | } |
---|
2737 | |
---|
2738 | if( mu != (int)(l->m[0].Data( )) ) |
---|
2739 | { |
---|
2740 | return semicListMilnorWrong; |
---|
2741 | } |
---|
2742 | |
---|
2743 | // ------------------------- |
---|
2744 | // check geometrical genus |
---|
2745 | // ------------------------- |
---|
2746 | |
---|
2747 | for( pg=0, i=0; i<n; i++ ) |
---|
2748 | { |
---|
2749 | if( (*num)[i]<=(*den)[i] ) |
---|
2750 | { |
---|
2751 | pg += (*mul)[i]; |
---|
2752 | } |
---|
2753 | } |
---|
2754 | |
---|
2755 | if( pg != (int)(l->m[1].Data( )) ) |
---|
2756 | { |
---|
2757 | return semicListPGWrong; |
---|
2758 | } |
---|
2759 | |
---|
2760 | return semicOK; |
---|
2761 | } |
---|
2762 | |
---|
2763 | // ---------------------------------------------------------------------------- |
---|
2764 | // this procedure is called from the interpreter |
---|
2765 | // ---------------------------------------------------------------------------- |
---|
2766 | // first = list of spectrum numbers |
---|
2767 | // second = list of spectrum numbers |
---|
2768 | // result = sum of the two lists |
---|
2769 | // ---------------------------------------------------------------------------- |
---|
2770 | |
---|
2771 | BOOLEAN spaddProc( leftv result,leftv first,leftv second ) |
---|
2772 | { |
---|
2773 | semicState state; |
---|
2774 | |
---|
2775 | // ----------------- |
---|
2776 | // check arguments |
---|
2777 | // ----------------- |
---|
2778 | |
---|
2779 | lists l1 = (lists)first->Data( ); |
---|
2780 | lists l2 = (lists)second->Data( ); |
---|
2781 | |
---|
2782 | if( (state=list_is_spectrum( l1 )) != semicOK ) |
---|
2783 | { |
---|
2784 | WerrorS( "first argument is not a spectrum:" ); |
---|
2785 | list_error( state ); |
---|
2786 | } |
---|
2787 | else if( (state=list_is_spectrum( l2 )) != semicOK ) |
---|
2788 | { |
---|
2789 | WerrorS( "second argument is not a spectrum:" ); |
---|
2790 | list_error( state ); |
---|
2791 | } |
---|
2792 | else |
---|
2793 | { |
---|
2794 | spectrum s1( l1 ); |
---|
2795 | spectrum s2( l2 ); |
---|
2796 | spectrum sum( s1+s2 ); |
---|
2797 | |
---|
2798 | result->rtyp = LIST_CMD; |
---|
2799 | result->data = (char*)(sum.thelist( )); |
---|
2800 | } |
---|
2801 | |
---|
2802 | return (state!=semicOK); |
---|
2803 | } |
---|
2804 | |
---|
2805 | // ---------------------------------------------------------------------------- |
---|
2806 | // this procedure is called from the interpreter |
---|
2807 | // ---------------------------------------------------------------------------- |
---|
2808 | // first = list of spectrum numbers |
---|
2809 | // second = integer |
---|
2810 | // result = the multiple of the first list by the second factor |
---|
2811 | // ---------------------------------------------------------------------------- |
---|
2812 | |
---|
2813 | BOOLEAN spmulProc( leftv result,leftv first,leftv second ) |
---|
2814 | { |
---|
2815 | semicState state; |
---|
2816 | |
---|
2817 | // ----------------- |
---|
2818 | // check arguments |
---|
2819 | // ----------------- |
---|
2820 | |
---|
2821 | lists l = (lists)first->Data( ); |
---|
2822 | int k = (int)second->Data( ); |
---|
2823 | |
---|
2824 | if( (state=list_is_spectrum( l ))!=semicOK ) |
---|
2825 | { |
---|
2826 | WerrorS( "first argument is not a spectrum" ); |
---|
2827 | list_error( state ); |
---|
2828 | } |
---|
2829 | else if( k < 0 ) |
---|
2830 | { |
---|
2831 | WerrorS( "second argument should be positive" ); |
---|
2832 | state = semicMulNegative; |
---|
2833 | } |
---|
2834 | else |
---|
2835 | { |
---|
2836 | spectrum s( l ); |
---|
2837 | spectrum product( k*s ); |
---|
2838 | |
---|
2839 | result->rtyp = LIST_CMD; |
---|
2840 | result->data = (char*)product.thelist( ); |
---|
2841 | } |
---|
2842 | |
---|
2843 | return (state!=semicOK); |
---|
2844 | } |
---|
2845 | |
---|
2846 | // ---------------------------------------------------------------------------- |
---|
2847 | // this procedure is called from the interpreter |
---|
2848 | // ---------------------------------------------------------------------------- |
---|
2849 | // first = list of spectrum numbers |
---|
2850 | // second = list of spectrum numbers |
---|
2851 | // result = semicontinuity index |
---|
2852 | // ---------------------------------------------------------------------------- |
---|
2853 | |
---|
2854 | BOOLEAN semicProc3 ( leftv res,leftv u,leftv v,leftv w ) |
---|
2855 | { |
---|
2856 | semicState state; |
---|
2857 | BOOLEAN qh=(((int)w->Data())==1); |
---|
2858 | |
---|
2859 | // ----------------- |
---|
2860 | // check arguments |
---|
2861 | // ----------------- |
---|
2862 | |
---|
2863 | lists l1 = (lists)u->Data( ); |
---|
2864 | lists l2 = (lists)v->Data( ); |
---|
2865 | |
---|
2866 | if( (state=list_is_spectrum( l1 ))!=semicOK ) |
---|
2867 | { |
---|
2868 | WerrorS( "first argument is not a spectrum" ); |
---|
2869 | list_error( state ); |
---|
2870 | } |
---|
2871 | else if( (state=list_is_spectrum( l2 ))!=semicOK ) |
---|
2872 | { |
---|
2873 | WerrorS( "second argument is not a spectrum" ); |
---|
2874 | list_error( state ); |
---|
2875 | } |
---|
2876 | else |
---|
2877 | { |
---|
2878 | spectrum s1( l1 ); |
---|
2879 | spectrum s2( l2 ); |
---|
2880 | |
---|
2881 | res->rtyp = INT_CMD; |
---|
2882 | if (qh) |
---|
2883 | res->data = (void*)(s1.mult_spectrumh( s2 )); |
---|
2884 | else |
---|
2885 | res->data = (void*)(s1.mult_spectrum( s2 )); |
---|
2886 | } |
---|
2887 | |
---|
2888 | // ----------------- |
---|
2889 | // check status |
---|
2890 | // ----------------- |
---|
2891 | |
---|
2892 | return (state!=semicOK); |
---|
2893 | } |
---|
2894 | BOOLEAN semicProc ( leftv res,leftv u,leftv v ) |
---|
2895 | { |
---|
2896 | sleftv tmp; |
---|
2897 | memset(&tmp,0,sizeof(tmp)); |
---|
2898 | tmp.rtyp=INT_CMD; |
---|
2899 | /* tmp.data = (void *)0; -- done by memset */ |
---|
2900 | |
---|
2901 | return semicProc3(res,u,v,&tmp); |
---|
2902 | } |
---|
2903 | // from splist.cc |
---|
2904 | // ---------------------------------------------------------------------------- |
---|
2905 | // Compute the spectrum of a spectrumPolyList |
---|
2906 | // ---------------------------------------------------------------------------- |
---|
2907 | |
---|
2908 | spectrumState spectrumPolyList::spectrum( lists *L,int fast ) |
---|
2909 | { |
---|
2910 | spectrumPolyNode **node = &root; |
---|
2911 | spectrumPolyNode *search; |
---|
2912 | |
---|
2913 | poly f,tmp; |
---|
2914 | int found,cmp; |
---|
2915 | |
---|
2916 | Rational smax( ( fast==0 ? 0 : pVariables ), |
---|
2917 | ( fast==2 ? 2 : 1 ) ); |
---|
2918 | |
---|
2919 | Rational weight_prev( 0,1 ); |
---|
2920 | |
---|
2921 | int mu = 0; // the milnor number |
---|
2922 | int pg = 0; // the geometrical genus |
---|
2923 | int n = 0; // number of different spectral numbers |
---|
2924 | int z = 0; // number of spectral number equal to smax |
---|
2925 | |
---|
2926 | int k = 0; |
---|
2927 | |
---|
2928 | while( (*node)!=(spectrumPolyNode*)NULL && |
---|
2929 | ( fast==0 || (*node)->weight<=smax ) ) |
---|
2930 | { |
---|
2931 | // --------------------------------------- |
---|
2932 | // determine the first normal form which |
---|
2933 | // contains the monomial node->mon |
---|
2934 | // --------------------------------------- |
---|
2935 | |
---|
2936 | found = FALSE; |
---|
2937 | search = *node; |
---|
2938 | |
---|
2939 | while( search!=(spectrumPolyNode*)NULL && found==FALSE ) |
---|
2940 | { |
---|
2941 | if( search->nf!=(poly)NULL ) |
---|
2942 | { |
---|
2943 | f = search->nf; |
---|
2944 | |
---|
2945 | do |
---|
2946 | { |
---|
2947 | // -------------------------------- |
---|
2948 | // look for (*node)->mon in f |
---|
2949 | // -------------------------------- |
---|
2950 | |
---|
2951 | cmp = pCmp( (*node)->mon,f ); |
---|
2952 | |
---|
2953 | if( cmp<0 ) |
---|
2954 | { |
---|
2955 | f = pNext( f ); |
---|
2956 | } |
---|
2957 | else if( cmp==0 ) |
---|
2958 | { |
---|
2959 | // ----------------------------- |
---|
2960 | // we have found a normal form |
---|
2961 | // ----------------------------- |
---|
2962 | |
---|
2963 | found = TRUE; |
---|
2964 | |
---|
2965 | // normalize coefficient |
---|
2966 | |
---|
2967 | number inv = nInvers( pGetCoeff( f ) ); |
---|
2968 | pMult_nn( search->nf,inv ); |
---|
2969 | nDelete( &inv ); |
---|
2970 | |
---|
2971 | // exchange normal forms |
---|
2972 | |
---|
2973 | tmp = (*node)->nf; |
---|
2974 | (*node)->nf = search->nf; |
---|
2975 | search->nf = tmp; |
---|
2976 | } |
---|
2977 | } |
---|
2978 | while( cmp<0 && f!=(poly)NULL ); |
---|
2979 | } |
---|
2980 | search = search->next; |
---|
2981 | } |
---|
2982 | |
---|
2983 | if( found==FALSE ) |
---|
2984 | { |
---|
2985 | // ------------------------------------------------ |
---|
2986 | // the weight of node->mon is a spectrum number |
---|
2987 | // ------------------------------------------------ |
---|
2988 | |
---|
2989 | mu++; |
---|
2990 | |
---|
2991 | if( (*node)->weight<=(Rational)1 ) pg++; |
---|
2992 | if( (*node)->weight==smax ) z++; |
---|
2993 | if( (*node)->weight>weight_prev ) n++; |
---|
2994 | |
---|
2995 | weight_prev = (*node)->weight; |
---|
2996 | node = &((*node)->next); |
---|
2997 | } |
---|
2998 | else |
---|
2999 | { |
---|
3000 | // ----------------------------------------------- |
---|
3001 | // determine all other normal form which contain |
---|
3002 | // the monomial node->mon |
---|
3003 | // replace for node->mon its normal form |
---|
3004 | // ----------------------------------------------- |
---|
3005 | |
---|
3006 | while( search!=(spectrumPolyNode*)NULL ) |
---|
3007 | { |
---|
3008 | if( search->nf!=(poly)NULL ) |
---|
3009 | { |
---|
3010 | f = search->nf; |
---|
3011 | |
---|
3012 | do |
---|
3013 | { |
---|
3014 | // -------------------------------- |
---|
3015 | // look for (*node)->mon in f |
---|
3016 | // -------------------------------- |
---|
3017 | |
---|
3018 | cmp = pCmp( (*node)->mon,f ); |
---|
3019 | |
---|
3020 | if( cmp<0 ) |
---|
3021 | { |
---|
3022 | f = pNext( f ); |
---|
3023 | } |
---|
3024 | else if( cmp==0 ) |
---|
3025 | { |
---|
3026 | search->nf = pSub( search->nf, |
---|
3027 | ppMult_nn( (*node)->nf,pGetCoeff( f ) ) ); |
---|
3028 | pNorm( search->nf ); |
---|
3029 | } |
---|
3030 | } |
---|
3031 | while( cmp<0 && f!=(poly)NULL ); |
---|
3032 | } |
---|
3033 | search = search->next; |
---|
3034 | } |
---|
3035 | delete_node( node ); |
---|
3036 | } |
---|
3037 | |
---|
3038 | } |
---|
3039 | |
---|
3040 | // -------------------------------------------------------- |
---|
3041 | // fast computation exploits the symmetry of the spectrum |
---|
3042 | // -------------------------------------------------------- |
---|
3043 | |
---|
3044 | if( fast==2 ) |
---|
3045 | { |
---|
3046 | mu = 2*mu - z; |
---|
3047 | n = ( z > 0 ? 2*n - 1 : 2*n ); |
---|
3048 | } |
---|
3049 | |
---|
3050 | // -------------------------------------------------------- |
---|
3051 | // compute the spectrum numbers with their multiplicities |
---|
3052 | // -------------------------------------------------------- |
---|
3053 | |
---|
3054 | intvec *nom = new intvec( n ); |
---|
3055 | intvec *den = new intvec( n ); |
---|
3056 | intvec *mult = new intvec( n ); |
---|
3057 | |
---|
3058 | int count = 0; |
---|
3059 | int multiplicity = 1; |
---|
3060 | |
---|
3061 | for( search=root; search!=(spectrumPolyNode*)NULL && |
---|
3062 | ( fast==0 || search->weight<=smax ); |
---|
3063 | search=search->next ) |
---|
3064 | { |
---|
3065 | if( search->next==(spectrumPolyNode*)NULL || |
---|
3066 | search->weight<search->next->weight ) |
---|
3067 | { |
---|
3068 | (*nom) [count] = search->weight.get_num_si( ); |
---|
3069 | (*den) [count] = search->weight.get_den_si( ); |
---|
3070 | (*mult)[count] = multiplicity; |
---|
3071 | |
---|
3072 | multiplicity=1; |
---|
3073 | count++; |
---|
3074 | } |
---|
3075 | else |
---|
3076 | { |
---|
3077 | multiplicity++; |
---|
3078 | } |
---|
3079 | } |
---|
3080 | |
---|
3081 | // -------------------------------------------------------- |
---|
3082 | // fast computation exploits the symmetry of the spectrum |
---|
3083 | // -------------------------------------------------------- |
---|
3084 | |
---|
3085 | if( fast==2 ) |
---|
3086 | { |
---|
3087 | int n1,n2; |
---|
3088 | for( n1=0, n2=n-1; n1<n2; n1++, n2-- ) |
---|
3089 | { |
---|
3090 | (*nom) [n2] = pVariables*(*den)[n1]-(*nom)[n1]; |
---|
3091 | (*den) [n2] = (*den)[n1]; |
---|
3092 | (*mult)[n2] = (*mult)[n1]; |
---|
3093 | } |
---|
3094 | } |
---|
3095 | |
---|
3096 | // ----------------------------------- |
---|
3097 | // test if the spectrum is symmetric |
---|
3098 | // ----------------------------------- |
---|
3099 | |
---|
3100 | if( fast==0 || fast==1 ) |
---|
3101 | { |
---|
3102 | int symmetric=TRUE; |
---|
3103 | |
---|
3104 | for( int n1=0, n2=n-1 ; n1<n2 && symmetric==TRUE; n1++, n2-- ) |
---|
3105 | { |
---|
3106 | if( (*mult)[n1]!=(*mult)[n2] || |
---|
3107 | (*den) [n1]!= (*den)[n2] || |
---|
3108 | (*nom)[n1]+(*nom)[n2]!=pVariables*(*den) [n1] ) |
---|
3109 | { |
---|
3110 | symmetric = FALSE; |
---|
3111 | } |
---|
3112 | } |
---|
3113 | |
---|
3114 | if( symmetric==FALSE ) |
---|
3115 | { |
---|
3116 | // --------------------------------------------- |
---|
3117 | // the spectrum is not symmetric => degenerate |
---|
3118 | // principal part |
---|
3119 | // --------------------------------------------- |
---|
3120 | |
---|
3121 | *L = (lists)omAllocBin( slists_bin); |
---|
3122 | (*L)->Init( 1 ); |
---|
3123 | (*L)->m[0].rtyp = INT_CMD; // milnor number |
---|
3124 | (*L)->m[0].data = (void*)mu; |
---|
3125 | |
---|
3126 | return spectrumDegenerate; |
---|
3127 | } |
---|
3128 | } |
---|
3129 | |
---|
3130 | *L = (lists)omAllocBin( slists_bin); |
---|
3131 | |
---|
3132 | (*L)->Init( 6 ); |
---|
3133 | |
---|
3134 | (*L)->m[0].rtyp = INT_CMD; // milnor number |
---|
3135 | (*L)->m[1].rtyp = INT_CMD; // geometrical genus |
---|
3136 | (*L)->m[2].rtyp = INT_CMD; // number of spectrum values |
---|
3137 | (*L)->m[3].rtyp = INTVEC_CMD; // nominators |
---|
3138 | (*L)->m[4].rtyp = INTVEC_CMD; // denomiantors |
---|
3139 | (*L)->m[5].rtyp = INTVEC_CMD; // multiplicities |
---|
3140 | |
---|
3141 | (*L)->m[0].data = (void*)mu; |
---|
3142 | (*L)->m[1].data = (void*)pg; |
---|
3143 | (*L)->m[2].data = (void*)n; |
---|
3144 | (*L)->m[3].data = (void*)nom; |
---|
3145 | (*L)->m[4].data = (void*)den; |
---|
3146 | (*L)->m[5].data = (void*)mult; |
---|
3147 | |
---|
3148 | return spectrumOK; |
---|
3149 | } |
---|
3150 | |
---|
3151 | #endif |
---|
3152 | |
---|
3153 | //from mpr_inout.cc |
---|
3154 | extern void nPrint(number n); |
---|
3155 | |
---|
3156 | BOOLEAN loNewtonP( leftv res, leftv arg1 ) |
---|
3157 | { |
---|
3158 | res->data= (void*)loNewtonPolytope( (ideal)arg1->Data() ); |
---|
3159 | return FALSE; |
---|
3160 | } |
---|
3161 | |
---|
3162 | BOOLEAN loSimplex( leftv res, leftv args ) |
---|
3163 | { |
---|
3164 | if ( !(rField_is_long_R()) ) |
---|
3165 | { |
---|
3166 | WerrorS("Ground field not implemented!"); |
---|
3167 | return TRUE; |
---|
3168 | } |
---|
3169 | |
---|
3170 | simplex * LP; |
---|
3171 | matrix m; |
---|
3172 | |
---|
3173 | leftv v= args; |
---|
3174 | if ( v->Typ() != MATRIX_CMD ) // 1: matrix |
---|
3175 | return TRUE; |
---|
3176 | else |
---|
3177 | m= (matrix)(v->CopyD()); |
---|
3178 | |
---|
3179 | LP = new simplex(MATROWS(m),MATCOLS(m)); |
---|
3180 | LP->mapFromMatrix(m); |
---|
3181 | |
---|
3182 | v= v->next; |
---|
3183 | if ( v->Typ() != INT_CMD ) // 2: m = number of constraints |
---|
3184 | return TRUE; |
---|
3185 | else |
---|
3186 | LP->m= (int)(v->Data()); |
---|
3187 | |
---|
3188 | v= v->next; |
---|
3189 | if ( v->Typ() != INT_CMD ) // 3: n = number of variables |
---|
3190 | return TRUE; |
---|
3191 | else |
---|
3192 | LP->n= (int)(v->Data()); |
---|
3193 | |
---|
3194 | v= v->next; |
---|
3195 | if ( v->Typ() != INT_CMD ) // 4: m1 = number of <= constraints |
---|
3196 | return TRUE; |
---|
3197 | else |
---|
3198 | LP->m1= (int)(v->Data()); |
---|
3199 | |
---|
3200 | v= v->next; |
---|
3201 | if ( v->Typ() != INT_CMD ) // 5: m2 = number of >= constraints |
---|
3202 | return TRUE; |
---|
3203 | else |
---|
3204 | LP->m2= (int)(v->Data()); |
---|
3205 | |
---|
3206 | v= v->next; |
---|
3207 | if ( v->Typ() != INT_CMD ) // 6: m3 = number of == constraints |
---|
3208 | return TRUE; |
---|
3209 | else |
---|
3210 | LP->m3= (int)(v->Data()); |
---|
3211 | |
---|
3212 | #ifdef mprDEBUG_PROT |
---|
3213 | Print("m (constraints) %d\n",LP->m); |
---|
3214 | Print("n (columns) %d\n",LP->n); |
---|
3215 | Print("m1 (<=) %d\n",LP->m1); |
---|
3216 | Print("m2 (>=) %d\n",LP->m2); |
---|
3217 | Print("m3 (==) %d\n",LP->m3); |
---|
3218 | #endif |
---|
3219 | |
---|
3220 | LP->compute(); |
---|
3221 | |
---|
3222 | lists lres= (lists)omAlloc( sizeof(slists) ); |
---|
3223 | lres->Init( 6 ); |
---|
3224 | |
---|
3225 | lres->m[0].rtyp= MATRIX_CMD; // output matrix |
---|
3226 | lres->m[0].data=(void*)LP->mapToMatrix(m); |
---|
3227 | |
---|
3228 | lres->m[1].rtyp= INT_CMD; // found a solution? |
---|
3229 | lres->m[1].data=(void*)LP->icase; |
---|
3230 | |
---|
3231 | lres->m[2].rtyp= INTVEC_CMD; |
---|
3232 | lres->m[2].data=(void*)LP->posvToIV(); |
---|
3233 | |
---|
3234 | lres->m[3].rtyp= INTVEC_CMD; |
---|
3235 | lres->m[3].data=(void*)LP->zrovToIV(); |
---|
3236 | |
---|
3237 | lres->m[4].rtyp= INT_CMD; |
---|
3238 | lres->m[4].data=(void*)LP->m; |
---|
3239 | |
---|
3240 | lres->m[5].rtyp= INT_CMD; |
---|
3241 | lres->m[5].data=(void*)LP->n; |
---|
3242 | |
---|
3243 | res->data= (void*)lres; |
---|
3244 | |
---|
3245 | return FALSE; |
---|
3246 | } |
---|
3247 | |
---|
3248 | BOOLEAN nuMPResMat( leftv res, leftv arg1, leftv arg2 ) |
---|
3249 | { |
---|
3250 | ideal gls = (ideal)(arg1->Data()); |
---|
3251 | int imtype= (int)arg2->Data(); |
---|
3252 | |
---|
3253 | uResultant::resMatType mtype= determineMType( imtype ); |
---|
3254 | |
---|
3255 | // check input ideal ( = polynomial system ) |
---|
3256 | if ( mprIdealCheck( gls, arg1->Name(), mtype, true ) != mprOk ) |
---|
3257 | { |
---|
3258 | return TRUE; |
---|
3259 | } |
---|
3260 | |
---|
3261 | uResultant *resMat= new uResultant( gls, mtype, false ); |
---|
3262 | |
---|
3263 | res->rtyp = MODUL_CMD; |
---|
3264 | res->data= (void*)resMat->accessResMat()->getMatrix(); |
---|
3265 | |
---|
3266 | delete resMat; |
---|
3267 | |
---|
3268 | return FALSE; |
---|
3269 | } |
---|
3270 | |
---|
3271 | BOOLEAN nuLagSolve( leftv res, leftv arg1, leftv arg2, leftv arg3 ) |
---|
3272 | { |
---|
3273 | |
---|
3274 | poly gls; |
---|
3275 | gls= (poly)(arg1->Data()); |
---|
3276 | int howclean= (int)arg3->Data(); |
---|
3277 | |
---|
3278 | if ( !(rField_is_R() || |
---|
3279 | rField_is_Q() || |
---|
3280 | rField_is_long_R() || |
---|
3281 | rField_is_long_C()) ) |
---|
3282 | { |
---|
3283 | WerrorS("Ground field not implemented!"); |
---|
3284 | return TRUE; |
---|
3285 | } |
---|
3286 | |
---|
3287 | if ( !(rField_is_R()||rField_is_long_R()||rField_is_long_C()) ) |
---|
3288 | { |
---|
3289 | unsigned long int ii = (unsigned long int)arg2->Data(); |
---|
3290 | setGMPFloatDigits( ii, ii ); |
---|
3291 | } |
---|
3292 | |
---|
3293 | if ( gls == NULL || pIsConstant( gls ) ) |
---|
3294 | { |
---|
3295 | WerrorS("Input polynomial is constant!"); |
---|
3296 | return TRUE; |
---|
3297 | } |
---|
3298 | |
---|
3299 | int ldummy; |
---|
3300 | int deg= pLDeg( gls, &ldummy ); |
---|
3301 | // int deg= pDeg( gls ); |
---|
3302 | int len= pLength( gls ); |
---|
3303 | int i,vpos; |
---|
3304 | poly piter; |
---|
3305 | lists elist; |
---|
3306 | lists rlist; |
---|
3307 | |
---|
3308 | elist= (lists)omAlloc( sizeof(slists) ); |
---|
3309 | elist->Init( 0 ); |
---|
3310 | |
---|
3311 | if ( pVariables > 1 ) |
---|
3312 | { |
---|
3313 | piter= gls; |
---|
3314 | for ( i= 1; i <= pVariables; i++ ) |
---|
3315 | if ( pGetExp( piter, i ) ) |
---|
3316 | { |
---|
3317 | vpos= i; |
---|
3318 | break; |
---|
3319 | } |
---|
3320 | while ( piter ) |
---|
3321 | { |
---|
3322 | for ( i= 1; i <= pVariables; i++ ) |
---|
3323 | if ( (vpos != i) && (pGetExp( piter, i ) != 0) ) |
---|
3324 | { |
---|
3325 | WerrorS("The input polynomial must be univariate!"); |
---|
3326 | return TRUE; |
---|
3327 | } |
---|
3328 | pIter( piter ); |
---|
3329 | } |
---|
3330 | } |
---|
3331 | |
---|
3332 | rootContainer * roots= new rootContainer(); |
---|
3333 | number * pcoeffs= (number *)omAlloc( (deg+1) * sizeof( number ) ); |
---|
3334 | piter= gls; |
---|
3335 | for ( i= deg; i >= 0; i-- ) |
---|
3336 | { |
---|
3337 | //if ( piter ) Print("deg %d, pDeg(piter) %d\n",i,pTotaldegree(piter)); |
---|
3338 | if ( piter && pTotaldegree(piter) == i ) |
---|
3339 | { |
---|
3340 | pcoeffs[i]= nCopy( pGetCoeff( piter ) ); |
---|
3341 | //nPrint( pcoeffs[i] );PrintS(" "); |
---|
3342 | pIter( piter ); |
---|
3343 | } |
---|
3344 | else |
---|
3345 | { |
---|
3346 | pcoeffs[i]= nInit(0); |
---|
3347 | } |
---|
3348 | } |
---|
3349 | |
---|
3350 | #ifdef mprDEBUG_PROT |
---|
3351 | for (i=deg; i >= 0; i--) |
---|
3352 | { |
---|
3353 | nPrint( pcoeffs[i] );PrintS(" "); |
---|
3354 | } |
---|
3355 | PrintLn(); |
---|
3356 | #endif |
---|
3357 | |
---|
3358 | roots->fillContainer( pcoeffs, NULL, 1, deg, rootContainer::onepoly, 1 ); |
---|
3359 | roots->solver( howclean ); |
---|
3360 | |
---|
3361 | int elem= roots->getAnzRoots(); |
---|
3362 | char *out; |
---|
3363 | char *dummy; |
---|
3364 | int j; |
---|
3365 | |
---|
3366 | rlist= (lists)omAlloc( sizeof(slists) ); |
---|
3367 | rlist->Init( elem ); |
---|
3368 | |
---|
3369 | if (rField_is_long_C()) |
---|
3370 | { |
---|
3371 | for ( j= 0; j < elem; j++ ) |
---|
3372 | { |
---|
3373 | rlist->m[j].rtyp=NUMBER_CMD; |
---|
3374 | rlist->m[j].data=(void *)nCopy((number)(roots->getRoot(j))); |
---|
3375 | //rlist->m[j].data=(void *)(number)(roots->getRoot(j)); |
---|
3376 | } |
---|
3377 | } |
---|
3378 | else |
---|
3379 | { |
---|
3380 | for ( j= 0; j < elem; j++ ) |
---|
3381 | { |
---|
3382 | dummy = complexToStr( (*roots)[j], gmp_output_digits ); |
---|
3383 | rlist->m[j].rtyp=STRING_CMD; |
---|
3384 | rlist->m[j].data=(void *)dummy; |
---|
3385 | } |
---|
3386 | } |
---|
3387 | |
---|
3388 | elist->Clean(); |
---|
3389 | //omFreeSize( (ADDRESS) elist, sizeof(slists) ); |
---|
3390 | |
---|
3391 | for ( i= deg; i >= 0; i-- ) nDelete( &pcoeffs[i] ); |
---|
3392 | omFreeSize( (ADDRESS) pcoeffs, (deg+1) * sizeof( number ) ); |
---|
3393 | |
---|
3394 | res->rtyp= LIST_CMD; |
---|
3395 | res->data= (void*)rlist; |
---|
3396 | |
---|
3397 | return FALSE; |
---|
3398 | } |
---|
3399 | |
---|
3400 | BOOLEAN nuVanderSys( leftv res, leftv arg1, leftv arg2, leftv arg3) |
---|
3401 | { |
---|
3402 | int i; |
---|
3403 | ideal p,w; |
---|
3404 | p= (ideal)arg1->Data(); |
---|
3405 | w= (ideal)arg2->Data(); |
---|
3406 | |
---|
3407 | // w[0] = f(p^0) |
---|
3408 | // w[1] = f(p^1) |
---|
3409 | // ... |
---|
3410 | // p can be a vector of numbers (multivariate polynom) |
---|
3411 | // or one number (univariate polynom) |
---|
3412 | // tdg = deg(f) |
---|
3413 | |
---|
3414 | int n= IDELEMS( p ); |
---|
3415 | int m= IDELEMS( w ); |
---|
3416 | int tdg= (int)arg3->Data(); |
---|
3417 | |
---|
3418 | res->data= (void*)NULL; |
---|
3419 | |
---|
3420 | // check the input |
---|
3421 | if ( tdg < 1 ) |
---|
3422 | { |
---|
3423 | WerrorS("Last input parameter must be > 0!"); |
---|
3424 | return TRUE; |
---|
3425 | } |
---|
3426 | if ( n != pVariables ) |
---|
3427 | { |
---|
3428 | Werror("Size of first input ideal must be equal to %d!",pVariables); |
---|
3429 | return TRUE; |
---|
3430 | } |
---|
3431 | if ( m != (int)pow((double)tdg+1,(double)n) ) |
---|
3432 | { |
---|
3433 | Werror("Size of second input ideal must be equal to %d!", |
---|
3434 | (int)pow((double)tdg+1,(double)n)); |
---|
3435 | return TRUE; |
---|
3436 | } |
---|
3437 | if ( !(rField_is_Q() /* || |
---|
3438 | rField_is_R() || rField_is_long_R() || |
---|
3439 | rField_is_long_C()*/ ) ) |
---|
3440 | { |
---|
3441 | WerrorS("Ground field not implemented!"); |
---|
3442 | return TRUE; |
---|
3443 | } |
---|
3444 | |
---|
3445 | number tmp; |
---|
3446 | number *pevpoint= (number *)omAlloc( n * sizeof( number ) ); |
---|
3447 | for ( i= 0; i < n; i++ ) |
---|
3448 | { |
---|
3449 | pevpoint[i]=nInit(0); |
---|
3450 | if ( (p->m)[i] ) |
---|
3451 | { |
---|
3452 | tmp = pGetCoeff( (p->m)[i] ); |
---|
3453 | if ( nIsZero(tmp) || nIsOne(tmp) || nIsMOne(tmp) ) |
---|
3454 | { |
---|
3455 | omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) ); |
---|
3456 | WerrorS("Elements of first input ideal must not be equal to -1, 0, 1!"); |
---|
3457 | return TRUE; |
---|
3458 | } |
---|
3459 | } else tmp= NULL; |
---|
3460 | if ( !nIsZero(tmp) ) |
---|
3461 | { |
---|
3462 | if ( !pIsConstant((p->m)[i])) |
---|
3463 | { |
---|
3464 | omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) ); |
---|
3465 | WerrorS("Elements of first input ideal must be numbers!"); |
---|
3466 | return TRUE; |
---|
3467 | } |
---|
3468 | pevpoint[i]= nCopy( tmp ); |
---|
3469 | } |
---|
3470 | } |
---|
3471 | |
---|
3472 | number *wresults= (number *)omAlloc( m * sizeof( number ) ); |
---|
3473 | for ( i= 0; i < m; i++ ) |
---|
3474 | { |
---|
3475 | wresults[i]= nInit(0); |
---|
3476 | if ( (w->m)[i] && !nIsZero(pGetCoeff((w->m)[i])) ) |
---|
3477 | { |
---|
3478 | if ( !pIsConstant((w->m)[i])) |
---|
3479 | { |
---|
3480 | omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) ); |
---|
3481 | omFreeSize( (ADDRESS)wresults, m * sizeof( number ) ); |
---|
3482 | WerrorS("Elements of second input ideal must be numbers!"); |
---|
3483 | return TRUE; |
---|
3484 | } |
---|
3485 | wresults[i]= nCopy(pGetCoeff((w->m)[i])); |
---|
3486 | } |
---|
3487 | } |
---|
3488 | |
---|
3489 | vandermonde vm( m, n, tdg, pevpoint, FALSE ); |
---|
3490 | number *ncpoly= vm.interpolateDense( wresults ); |
---|
3491 | // do not free ncpoly[]!! |
---|
3492 | poly rpoly= vm.numvec2poly( ncpoly ); |
---|
3493 | |
---|
3494 | omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) ); |
---|
3495 | omFreeSize( (ADDRESS)wresults, m * sizeof( number ) ); |
---|
3496 | |
---|
3497 | res->data= (void*)rpoly; |
---|
3498 | return FALSE; |
---|
3499 | } |
---|
3500 | |
---|
3501 | BOOLEAN nuUResSolve( leftv res, leftv args ) |
---|
3502 | { |
---|
3503 | leftv v= args; |
---|
3504 | |
---|
3505 | ideal gls; |
---|
3506 | int imtype; |
---|
3507 | int howclean; |
---|
3508 | |
---|
3509 | // get ideal |
---|
3510 | if ( v->Typ() != IDEAL_CMD ) |
---|
3511 | return TRUE; |
---|
3512 | else gls= (ideal)(v->Data()); |
---|
3513 | v= v->next; |
---|
3514 | |
---|
3515 | // get resultant matrix type to use (0,1) |
---|
3516 | if ( v->Typ() != INT_CMD ) |
---|
3517 | return TRUE; |
---|
3518 | else imtype= (int)v->Data(); |
---|
3519 | v= v->next; |
---|
3520 | |
---|
3521 | // get and set precision in digits ( > 0 ) |
---|
3522 | if ( v->Typ() != INT_CMD ) |
---|
3523 | return TRUE; |
---|
3524 | else if ( !(rField_is_R()||rField_is_long_R()||rField_is_long_C()) ) |
---|
3525 | { |
---|
3526 | unsigned long int ii=(unsigned long int)v->Data(); |
---|
3527 | setGMPFloatDigits( ii, ii ); |
---|
3528 | } |
---|
3529 | v= v->next; |
---|
3530 | |
---|
3531 | // get interpolation steps (0,1,2) |
---|
3532 | if ( v->Typ() != INT_CMD ) |
---|
3533 | return TRUE; |
---|
3534 | else howclean= (int)v->Data(); |
---|
3535 | |
---|
3536 | uResultant::resMatType mtype= determineMType( imtype ); |
---|
3537 | int i,c,count; |
---|
3538 | lists listofroots= NULL; |
---|
3539 | lists emptylist; |
---|
3540 | number smv= NULL; |
---|
3541 | BOOLEAN interpolate_det= (mtype==uResultant::denseResMat)?TRUE:FALSE; |
---|
3542 | |
---|
3543 | //emptylist= (lists)omAlloc( sizeof(slists) ); |
---|
3544 | //emptylist->Init( 0 ); |
---|
3545 | |
---|
3546 | //res->rtyp = LIST_CMD; |
---|
3547 | //res->data= (void *)emptylist; |
---|
3548 | |
---|
3549 | // check input ideal ( = polynomial system ) |
---|
3550 | if ( mprIdealCheck( gls, args->Name(), mtype ) != mprOk ) |
---|
3551 | { |
---|
3552 | return TRUE; |
---|
3553 | } |
---|
3554 | |
---|
3555 | uResultant * ures; |
---|
3556 | rootContainer ** iproots; |
---|
3557 | rootContainer ** muiproots; |
---|
3558 | rootArranger * arranger; |
---|
3559 | |
---|
3560 | // main task 1: setup of resultant matrix |
---|
3561 | ures= new uResultant( gls, mtype ); |
---|
3562 | if ( ures->accessResMat()->initState() != resMatrixBase::ready ) |
---|
3563 | { |
---|
3564 | WerrorS("Error occurred during matrix setup!"); |
---|
3565 | return TRUE; |
---|
3566 | } |
---|
3567 | |
---|
3568 | // if dense resultant, check if minor nonsingular |
---|
3569 | if ( mtype == uResultant::denseResMat ) |
---|
3570 | { |
---|
3571 | smv= ures->accessResMat()->getSubDet(); |
---|
3572 | #ifdef mprDEBUG_PROT |
---|
3573 | PrintS("// Determinant of submatrix: ");nPrint(smv);PrintLn(); |
---|
3574 | #endif |
---|
3575 | if ( nIsZero(smv) ) |
---|
3576 | { |
---|
3577 | WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!"); |
---|
3578 | return TRUE; |
---|
3579 | } |
---|
3580 | } |
---|
3581 | |
---|
3582 | // main task 2: Interpolate specialized resultant polynomials |
---|
3583 | if ( interpolate_det ) |
---|
3584 | iproots= ures->interpolateDenseSP( false, smv ); |
---|
3585 | else |
---|
3586 | iproots= ures->specializeInU( false, smv ); |
---|
3587 | |
---|
3588 | // main task 3: Interpolate specialized resultant polynomials |
---|
3589 | if ( interpolate_det ) |
---|
3590 | muiproots= ures->interpolateDenseSP( true, smv ); |
---|
3591 | else |
---|
3592 | muiproots= ures->specializeInU( true, smv ); |
---|
3593 | |
---|
3594 | #ifdef mprDEBUG_PROT |
---|
3595 | c= iproots[0]->getAnzElems(); |
---|
3596 | for (i=0; i < c; i++) pWrite(iproots[i]->getPoly()); |
---|
3597 | c= muiproots[0]->getAnzElems(); |
---|
3598 | for (i=0; i < c; i++) pWrite(muiproots[i]->getPoly()); |
---|
3599 | #endif |
---|
3600 | |
---|
3601 | // main task 4: Compute roots of specialized polys and match them up |
---|
3602 | arranger= new rootArranger( iproots, muiproots, howclean ); |
---|
3603 | arranger->solve_all(); |
---|
3604 | |
---|
3605 | // get list of roots |
---|
3606 | if ( arranger->success() ) |
---|
3607 | { |
---|
3608 | arranger->arrange(); |
---|
3609 | listofroots= arranger->listOfRoots( gmp_output_digits ); |
---|
3610 | } |
---|
3611 | else |
---|
3612 | { |
---|
3613 | WerrorS("Solver was unable to find any roots!"); |
---|
3614 | return TRUE; |
---|
3615 | } |
---|
3616 | |
---|
3617 | // free everything |
---|
3618 | count= iproots[0]->getAnzElems(); |
---|
3619 | for (i=0; i < count; i++) delete iproots[i]; |
---|
3620 | omFreeSize( (ADDRESS) iproots, count * sizeof(rootContainer*) ); |
---|
3621 | count= muiproots[0]->getAnzElems(); |
---|
3622 | for (i=0; i < count; i++) delete muiproots[i]; |
---|
3623 | omFreeSize( (ADDRESS) muiproots, count * sizeof(rootContainer*) ); |
---|
3624 | |
---|
3625 | delete ures; |
---|
3626 | delete arranger; |
---|
3627 | nDelete( &smv ); |
---|
3628 | |
---|
3629 | res->data= (void *)listofroots; |
---|
3630 | |
---|
3631 | //emptylist->Clean(); |
---|
3632 | // omFreeSize( (ADDRESS) emptylist, sizeof(slists) ); |
---|
3633 | |
---|
3634 | return FALSE; |
---|
3635 | } |
---|
3636 | |
---|
3637 | // from mpr_numeric.cc |
---|
3638 | lists rootArranger::listOfRoots( const unsigned int oprec ) |
---|
3639 | { |
---|
3640 | int i,j,tr; |
---|
3641 | int count= roots[0]->getAnzRoots(); // number of roots |
---|
3642 | int elem= roots[0]->getAnzElems(); // number of koordinates per root |
---|
3643 | |
---|
3644 | lists listofroots= (lists)omAlloc( sizeof(slists) ); // must be done this way! |
---|
3645 | |
---|
3646 | if ( found_roots ) |
---|
3647 | { |
---|
3648 | listofroots->Init( count ); |
---|
3649 | |
---|
3650 | for (i=0; i < count; i++) |
---|
3651 | { |
---|
3652 | lists onepoint= (lists)omAlloc(sizeof(slists)); // must be done this way! |
---|
3653 | onepoint->Init(elem); |
---|
3654 | for ( j= 0; j < elem; j++ ) |
---|
3655 | { |
---|
3656 | if ( !rField_is_long_C() ) |
---|
3657 | { |
---|
3658 | onepoint->m[j].rtyp=STRING_CMD; |
---|
3659 | onepoint->m[j].data=(void *)complexToStr((*roots[j])[i],oprec); |
---|
3660 | } |
---|
3661 | else |
---|
3662 | { |
---|
3663 | onepoint->m[j].rtyp=NUMBER_CMD; |
---|
3664 | onepoint->m[j].data=(void *)nCopy((number)(roots[j]->getRoot(i))); |
---|
3665 | } |
---|
3666 | onepoint->m[j].next= NULL; |
---|
3667 | onepoint->m[j].name= NULL; |
---|
3668 | } |
---|
3669 | listofroots->m[i].rtyp=LIST_CMD; |
---|
3670 | listofroots->m[i].data=(void *)onepoint; |
---|
3671 | listofroots->m[j].next= NULL; |
---|
3672 | listofroots->m[j].name= NULL; |
---|
3673 | } |
---|
3674 | |
---|
3675 | } |
---|
3676 | else |
---|
3677 | { |
---|
3678 | listofroots->Init( 0 ); |
---|
3679 | } |
---|
3680 | |
---|
3681 | return listofroots; |
---|
3682 | } |
---|
3683 | |
---|
3684 | #ifdef PDEBUG |
---|
3685 | |
---|
3686 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
3687 | |
---|
3688 | void p_SetRingOfPoly(poly p, ring r) |
---|
3689 | { |
---|
3690 | while (p != NULL) |
---|
3691 | { |
---|
3692 | p_SetRingOfLm(p, r); |
---|
3693 | pIter(p); |
---|
3694 | } |
---|
3695 | } |
---|
3696 | |
---|
3697 | void p_SetRingOfIdeal(ideal id, ring r) |
---|
3698 | { |
---|
3699 | if (id == NULL) return; |
---|
3700 | |
---|
3701 | int i, n = id->ncols*id->nrows; |
---|
3702 | |
---|
3703 | for (i=0; i<n; i++) |
---|
3704 | { |
---|
3705 | p_SetRingOfPoly(id->m[i], r); |
---|
3706 | } |
---|
3707 | } |
---|
3708 | |
---|
3709 | void p_SetRingOfList(lists L, ring r) |
---|
3710 | { |
---|
3711 | int i; |
---|
3712 | for (i=0; i<L->nr; i++) |
---|
3713 | { |
---|
3714 | p_SetRingOfLeftv(&(L->m[i]), r); |
---|
3715 | } |
---|
3716 | } |
---|
3717 | |
---|
3718 | void p_SetRingOfCommand(command cmd, ring r) |
---|
3719 | { |
---|
3720 | if (cmd->op == PROC_CMD && cmd->argc == 2) |
---|
3721 | p_SetRingOfLeftv(&(cmd->arg2), r); |
---|
3722 | else if (cmd->argc > 0) |
---|
3723 | { |
---|
3724 | p_SetRingOfLeftv(&(cmd->arg1), r); |
---|
3725 | if (cmd->argc > 1) |
---|
3726 | { |
---|
3727 | p_SetRingOfLeftv(&(cmd->arg2), r); |
---|
3728 | if (cmd->argc > 2) |
---|
3729 | p_SetRingOfLeftv(&(cmd->arg3), r); |
---|
3730 | } |
---|
3731 | } |
---|
3732 | } |
---|
3733 | |
---|
3734 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
3735 | { |
---|
3736 | while (l != NULL) |
---|
3737 | { |
---|
3738 | switch(l->rtyp) |
---|
3739 | { |
---|
3740 | case POLY_CMD: |
---|
3741 | case VECTOR_CMD: |
---|
3742 | p_SetRingOfPoly((poly) l->data, r); |
---|
3743 | break; |
---|
3744 | |
---|
3745 | case IDEAL_CMD: |
---|
3746 | case MODUL_CMD: |
---|
3747 | case MATRIX_CMD: |
---|
3748 | case MAP_CMD: |
---|
3749 | p_SetRingOfIdeal((ideal) l->data, r); |
---|
3750 | break; |
---|
3751 | |
---|
3752 | case LIST_CMD: |
---|
3753 | p_SetRingOfList((lists) l->data, r); |
---|
3754 | break; |
---|
3755 | |
---|
3756 | case COMMAND: |
---|
3757 | p_SetRingOfCommand((command)l->data, r); |
---|
3758 | default: |
---|
3759 | break; |
---|
3760 | } |
---|
3761 | l = l->next; |
---|
3762 | } |
---|
3763 | } |
---|
3764 | #endif // (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
3765 | |
---|
3766 | #endif // PDEBUG |
---|
3767 | |
---|
3768 | // from ring.cc |
---|
3769 | void rSetHdl(idhdl h) |
---|
3770 | { |
---|
3771 | int i; |
---|
3772 | ring rg = NULL; |
---|
3773 | if (h!=NULL) |
---|
3774 | { |
---|
3775 | // Print(" new ring:%s (l:%d)\n",IDID(h),IDLEV(h)); |
---|
3776 | rg = IDRING(h); |
---|
3777 | omCheckAddrSize((ADDRESS)h,sizeof(idrec)); |
---|
3778 | if (IDID(h)) // OB: ???? |
---|
3779 | omCheckAddr((ADDRESS)IDID(h)); |
---|
3780 | rTest(rg); |
---|
3781 | } |
---|
3782 | |
---|
3783 | // clean up history |
---|
3784 | if (sLastPrinted.RingDependend()) |
---|
3785 | { |
---|
3786 | sLastPrinted.CleanUp(); |
---|
3787 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
3788 | } |
---|
3789 | |
---|
3790 | /*------------ change the global ring -----------------------*/ |
---|
3791 | rChangeCurrRing(rg); |
---|
3792 | currRingHdl = h; |
---|
3793 | } |
---|
3794 | |
---|
3795 | BOOLEAN rSleftvOrdering2Ordering(sleftv *ord, ring R) |
---|
3796 | { |
---|
3797 | int last = 0, o=0, n = 1, i=0, typ = 1, j; |
---|
3798 | sleftv *sl = ord; |
---|
3799 | |
---|
3800 | // determine nBlocks |
---|
3801 | while (sl!=NULL) |
---|
3802 | { |
---|
3803 | intvec *iv = (intvec *)(sl->data); |
---|
3804 | if (((*iv)[1]==ringorder_c)||((*iv)[1]==ringorder_C)) i++; |
---|
3805 | else if ((*iv)[1]==ringorder_L) |
---|
3806 | { |
---|
3807 | R->bitmask=(*iv)[2]; |
---|
3808 | n--; |
---|
3809 | } |
---|
3810 | else if ((*iv)[1]!=ringorder_a) o++; |
---|
3811 | n++; |
---|
3812 | sl=sl->next; |
---|
3813 | } |
---|
3814 | // check whether at least one real ordering |
---|
3815 | if (o==0) |
---|
3816 | { |
---|
3817 | WerrorS("invalid combination of orderings"); |
---|
3818 | return TRUE; |
---|
3819 | } |
---|
3820 | // if no c/C ordering is given, increment n |
---|
3821 | if (i==0) n++; |
---|
3822 | else if (i != 1) |
---|
3823 | { |
---|
3824 | // throw error if more than one is given |
---|
3825 | WerrorS("more than one ordering c/C specified"); |
---|
3826 | return TRUE; |
---|
3827 | } |
---|
3828 | |
---|
3829 | // initialize fields of R |
---|
3830 | R->order=(int *)omAlloc0(n*sizeof(int)); |
---|
3831 | R->block0=(int *)omAlloc0(n*sizeof(int)); |
---|
3832 | R->block1=(int *)omAlloc0(n*sizeof(int)); |
---|
3833 | R->wvhdl=(int**)omAlloc0(n*sizeof(int_ptr)); |
---|
3834 | |
---|
3835 | // init order, so that rBlocks works correctly |
---|
3836 | for (j=0; j < n-1; j++) |
---|
3837 | R->order[j] = (int) ringorder_unspec; |
---|
3838 | // set last _C order, if no c/C order was given |
---|
3839 | if (i == 0) R->order[n-2] = ringorder_C; |
---|
3840 | |
---|
3841 | /* init orders */ |
---|
3842 | sl=ord; |
---|
3843 | n=-1; |
---|
3844 | while (sl!=NULL) |
---|
3845 | { |
---|
3846 | intvec *iv; |
---|
3847 | iv = (intvec *)(sl->data); |
---|
3848 | if ((*iv)[1]!=ringorder_L) |
---|
3849 | { |
---|
3850 | n++; |
---|
3851 | |
---|
3852 | /* the format of an ordering: |
---|
3853 | * iv[0]: factor |
---|
3854 | * iv[1]: ordering |
---|
3855 | * iv[2..end]: weights |
---|
3856 | */ |
---|
3857 | R->order[n] = (*iv)[1]; |
---|
3858 | switch ((*iv)[1]) |
---|
3859 | { |
---|
3860 | case ringorder_ws: |
---|
3861 | case ringorder_Ws: |
---|
3862 | typ=-1; |
---|
3863 | case ringorder_wp: |
---|
3864 | case ringorder_Wp: |
---|
3865 | R->wvhdl[n]=(int*)omAlloc((iv->length()-1)*sizeof(int)); |
---|
3866 | for (i=2; i<iv->length(); i++) |
---|
3867 | R->wvhdl[n][i-2] = (*iv)[i]; |
---|
3868 | R->block0[n] = last+1; |
---|
3869 | last += iv->length()-2; |
---|
3870 | R->block1[n] = last; |
---|
3871 | break; |
---|
3872 | case ringorder_ls: |
---|
3873 | case ringorder_ds: |
---|
3874 | case ringorder_Ds: |
---|
3875 | typ=-1; |
---|
3876 | case ringorder_lp: |
---|
3877 | case ringorder_dp: |
---|
3878 | case ringorder_Dp: |
---|
3879 | case ringorder_rp: |
---|
3880 | R->block0[n] = last+1; |
---|
3881 | if (iv->length() == 3) last+=(*iv)[2]; |
---|
3882 | else last += (*iv)[0]; |
---|
3883 | R->block1[n] = last; |
---|
3884 | if (rCheckIV(iv)) return TRUE; |
---|
3885 | break; |
---|
3886 | case ringorder_S: |
---|
3887 | case ringorder_c: |
---|
3888 | case ringorder_C: |
---|
3889 | if (rCheckIV(iv)) return TRUE; |
---|
3890 | break; |
---|
3891 | case ringorder_aa: |
---|
3892 | case ringorder_a: |
---|
3893 | R->block0[n] = last+1; |
---|
3894 | R->block1[n] = si_min(last+iv->length()-2 , R->N); |
---|
3895 | R->wvhdl[n] = (int*)omAlloc((iv->length()-1)*sizeof(int)); |
---|
3896 | for (i=2; i<iv->length(); i++) |
---|
3897 | { |
---|
3898 | R->wvhdl[n][i-2]=(*iv)[i]; |
---|
3899 | if ((*iv)[i]<0) typ=-1; |
---|
3900 | } |
---|
3901 | break; |
---|
3902 | case ringorder_M: |
---|
3903 | { |
---|
3904 | int Mtyp=rTypeOfMatrixOrder(iv); |
---|
3905 | if (Mtyp==0) return TRUE; |
---|
3906 | if (Mtyp==-1) typ = -1; |
---|
3907 | |
---|
3908 | R->wvhdl[n] =( int *)omAlloc((iv->length()-1)*sizeof(int)); |
---|
3909 | for (i=2; i<iv->length();i++) |
---|
3910 | R->wvhdl[n][i-2]=(*iv)[i]; |
---|
3911 | |
---|
3912 | R->block0[n] = last+1; |
---|
3913 | last += (int)sqrt((double)(iv->length()-2)); |
---|
3914 | R->block1[n] = last; |
---|
3915 | break; |
---|
3916 | } |
---|
3917 | |
---|
3918 | case ringorder_no: |
---|
3919 | R->order[n] = ringorder_unspec; |
---|
3920 | return TRUE; |
---|
3921 | |
---|
3922 | default: |
---|
3923 | Werror("Internal Error: Unknown ordering %d", (*iv)[1]); |
---|
3924 | R->order[n] = ringorder_unspec; |
---|
3925 | return TRUE; |
---|
3926 | } |
---|
3927 | } |
---|
3928 | sl=sl->next; |
---|
3929 | } |
---|
3930 | |
---|
3931 | // check for complete coverage |
---|
3932 | if ((R->order[n]==ringorder_c) || (R->order[n]==ringorder_C)) n--; |
---|
3933 | if (R->block1[n] != R->N) |
---|
3934 | { |
---|
3935 | if (((R->order[n]==ringorder_dp) || |
---|
3936 | (R->order[n]==ringorder_ds) || |
---|
3937 | (R->order[n]==ringorder_Dp) || |
---|
3938 | (R->order[n]==ringorder_Ds) || |
---|
3939 | (R->order[n]==ringorder_rp) || |
---|
3940 | (R->order[n]==ringorder_lp) || |
---|
3941 | (R->order[n]==ringorder_ls)) |
---|
3942 | && |
---|
3943 | R->block0[n] <= R->N) |
---|
3944 | { |
---|
3945 | R->block1[n] = R->N; |
---|
3946 | } |
---|
3947 | else |
---|
3948 | { |
---|
3949 | Werror("mismatch of number of vars (%d) and ordering (%d vars)", |
---|
3950 | R->N,R->block1[n]); |
---|
3951 | return TRUE; |
---|
3952 | } |
---|
3953 | } |
---|
3954 | R->OrdSgn = typ; |
---|
3955 | return FALSE; |
---|
3956 | } |
---|
3957 | |
---|
3958 | BOOLEAN rSleftvList2StringArray(sleftv* sl, char** p) |
---|
3959 | { |
---|
3960 | |
---|
3961 | while(sl!=NULL) |
---|
3962 | { |
---|
3963 | if (sl->Name() == sNoName) |
---|
3964 | { |
---|
3965 | if (sl->Typ()==POLY_CMD) |
---|
3966 | { |
---|
3967 | sleftv s_sl; |
---|
3968 | iiConvert(POLY_CMD,ANY_TYPE,-1,sl,&s_sl); |
---|
3969 | if (s_sl.Name() != sNoName) |
---|
3970 | *p = omStrDup(s_sl.Name()); |
---|
3971 | else |
---|
3972 | *p = NULL; |
---|
3973 | sl->next = s_sl.next; |
---|
3974 | s_sl.next = NULL; |
---|
3975 | s_sl.CleanUp(); |
---|
3976 | if (*p == NULL) return TRUE; |
---|
3977 | } |
---|
3978 | else |
---|
3979 | return TRUE; |
---|
3980 | } |
---|
3981 | else |
---|
3982 | *p = omStrDup(sl->Name()); |
---|
3983 | p++; |
---|
3984 | sl=sl->next; |
---|
3985 | } |
---|
3986 | return FALSE; |
---|
3987 | } |
---|
3988 | |
---|
3989 | //////////////////// |
---|
3990 | // |
---|
3991 | // rInit itself: |
---|
3992 | // |
---|
3993 | // INPUT: s: name, pn: ch & parameter (names), rv: variable (names) |
---|
3994 | // ord: ordering |
---|
3995 | // RETURN: currRingHdl on success |
---|
3996 | // NULL on error |
---|
3997 | // NOTE: * makes new ring to current ring, on success |
---|
3998 | // * considers input sleftv's as read-only |
---|
3999 | //idhdl rInit(char *s, sleftv* pn, sleftv* rv, sleftv* ord) |
---|
4000 | ring rInit(sleftv* pn, sleftv* rv, sleftv* ord) |
---|
4001 | { |
---|
4002 | int ch; |
---|
4003 | int float_len=0; |
---|
4004 | int float_len2=0; |
---|
4005 | ring R = NULL; |
---|
4006 | idhdl tmp = NULL; |
---|
4007 | BOOLEAN ffChar=FALSE; |
---|
4008 | int typ = 1; |
---|
4009 | |
---|
4010 | /* ch -------------------------------------------------------*/ |
---|
4011 | // get ch of ground field |
---|
4012 | int numberOfAllocatedBlocks; |
---|
4013 | |
---|
4014 | if (pn->Typ()==INT_CMD) |
---|
4015 | { |
---|
4016 | ch=(int)pn->Data(); |
---|
4017 | } |
---|
4018 | else if ((pn->name != NULL) |
---|
4019 | && ((strcmp(pn->name,"real")==0) || (strcmp(pn->name,"complex")==0))) |
---|
4020 | { |
---|
4021 | BOOLEAN complex_flag=(strcmp(pn->name,"complex")==0); |
---|
4022 | ch=-1; |
---|
4023 | if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD)) |
---|
4024 | { |
---|
4025 | float_len=(int)pn->next->Data(); |
---|
4026 | float_len2=float_len; |
---|
4027 | pn=pn->next; |
---|
4028 | if ((pn->next!=NULL) && (pn->next->Typ()==INT_CMD)) |
---|
4029 | { |
---|
4030 | float_len2=(int)pn->next->Data(); |
---|
4031 | pn=pn->next; |
---|
4032 | } |
---|
4033 | } |
---|
4034 | if ((pn->next==NULL) && complex_flag) |
---|
4035 | { |
---|
4036 | pn->next=(leftv)omAlloc0Bin(sleftv_bin); |
---|
4037 | pn->next->name=omStrDup("i"); |
---|
4038 | } |
---|
4039 | } |
---|
4040 | else |
---|
4041 | { |
---|
4042 | Werror("Wrong ground field specification"); |
---|
4043 | goto rInitError; |
---|
4044 | } |
---|
4045 | pn=pn->next; |
---|
4046 | |
---|
4047 | int l, last; |
---|
4048 | sleftv * sl; |
---|
4049 | /*every entry in the new ring is initialized to 0*/ |
---|
4050 | |
---|
4051 | /* characteristic -----------------------------------------------*/ |
---|
4052 | /* input: 0 ch=0 : Q parameter=NULL ffChar=FALSE float_len |
---|
4053 | * 0 1 : Q(a,...) *names FALSE |
---|
4054 | * 0 -1 : R NULL FALSE 0 |
---|
4055 | * 0 -1 : R NULL FALSE prec. >6 |
---|
4056 | * 0 -1 : C *names FALSE prec. 0..? |
---|
4057 | * p p : Fp NULL FALSE |
---|
4058 | * p -p : Fp(a) *names FALSE |
---|
4059 | * q q : GF(q=p^n) *names TRUE |
---|
4060 | */ |
---|
4061 | if (ch!=-1) |
---|
4062 | { |
---|
4063 | int l = 0; |
---|
4064 | |
---|
4065 | if (ch!=0 && (ch<2) |
---|
4066 | #ifndef NV_OPS |
---|
4067 | || (ch > 32003) |
---|
4068 | #endif |
---|
4069 | ) |
---|
4070 | { |
---|
4071 | Warn("%d is invalid characteristic of ground field. 32003 is used.", ch); |
---|
4072 | ch=32003; |
---|
4073 | } |
---|
4074 | // load fftable, if necessary |
---|
4075 | if (pn!=NULL) |
---|
4076 | { |
---|
4077 | while ((ch!=fftable[l]) && (fftable[l])) l++; |
---|
4078 | if (fftable[l]==0) ch = IsPrime(ch); |
---|
4079 | else |
---|
4080 | { |
---|
4081 | char *m[1]={(char *)sNoName}; |
---|
4082 | nfSetChar(ch,m); |
---|
4083 | if (errorreported) goto rInitError; |
---|
4084 | else ffChar=TRUE; |
---|
4085 | } |
---|
4086 | } |
---|
4087 | else |
---|
4088 | ch = IsPrime(ch); |
---|
4089 | } |
---|
4090 | // allocated ring and set ch |
---|
4091 | R = (ring) omAlloc0Bin(sip_sring_bin); |
---|
4092 | R->ch = ch; |
---|
4093 | if (ch == -1) |
---|
4094 | { |
---|
4095 | R->float_len= si_min(float_len,32767); |
---|
4096 | R->float_len2= si_min(float_len2,32767); |
---|
4097 | } |
---|
4098 | |
---|
4099 | /* parameter -------------------------------------------------------*/ |
---|
4100 | if (pn!=NULL) |
---|
4101 | { |
---|
4102 | R->P=pn->listLength(); |
---|
4103 | //if ((ffChar|| (ch == 1)) && (R->P > 1)) |
---|
4104 | if ((R->P > 1) && (ffChar || (ch == -1))) |
---|
4105 | { |
---|
4106 | WerrorS("too many parameters"); |
---|
4107 | goto rInitError; |
---|
4108 | } |
---|
4109 | R->parameter=(char**)omAlloc0(R->P*sizeof(char_ptr)); |
---|
4110 | if (rSleftvList2StringArray(pn, R->parameter)) |
---|
4111 | { |
---|
4112 | WerrorS("parameter expected"); |
---|
4113 | goto rInitError; |
---|
4114 | } |
---|
4115 | if (ch>1 && !ffChar) R->ch=-ch; |
---|
4116 | else if (ch==0) R->ch=1; |
---|
4117 | } |
---|
4118 | else if (ffChar) |
---|
4119 | { |
---|
4120 | WerrorS("need one parameter"); |
---|
4121 | goto rInitError; |
---|
4122 | } |
---|
4123 | /* post-processing of field description */ |
---|
4124 | // we have short reals, but no short complex |
---|
4125 | if ((R->ch == - 1) |
---|
4126 | && (R->parameter !=NULL) |
---|
4127 | && (R->float_len < SHORT_REAL_LENGTH)) |
---|
4128 | { |
---|
4129 | R->float_len = SHORT_REAL_LENGTH; |
---|
4130 | R->float_len2 = SHORT_REAL_LENGTH; |
---|
4131 | } |
---|
4132 | |
---|
4133 | /* names and number of variables-------------------------------------*/ |
---|
4134 | { |
---|
4135 | int l=rv->listLength(); |
---|
4136 | #if SIZEOF_SHORT == 2 |
---|
4137 | #define MAX_SHORT 0x7fff |
---|
4138 | #endif |
---|
4139 | if (l>MAX_SHORT) |
---|
4140 | { |
---|
4141 | Werror("too many ring variables(%d), max is %d",l,MAX_SHORT); |
---|
4142 | goto rInitError; |
---|
4143 | } |
---|
4144 | R->N = l; /*rv->listLength();*/ |
---|
4145 | } |
---|
4146 | R->names = (char **)omAlloc0(R->N * sizeof(char_ptr)); |
---|
4147 | if (rSleftvList2StringArray(rv, R->names)) |
---|
4148 | { |
---|
4149 | WerrorS("name of ring variable expected"); |
---|
4150 | goto rInitError; |
---|
4151 | } |
---|
4152 | |
---|
4153 | /* check names and parameters for conflicts ------------------------- */ |
---|
4154 | { |
---|
4155 | int i,j; |
---|
4156 | for(i=0;i<R->P; i++) |
---|
4157 | { |
---|
4158 | for(j=0;j<R->N;j++) |
---|
4159 | { |
---|
4160 | if (strcmp(R->parameter[i],R->names[j])==0) |
---|
4161 | { |
---|
4162 | Werror("parameter %d conflicts with variable %d",i+1,j+1); |
---|
4163 | goto rInitError; |
---|
4164 | } |
---|
4165 | } |
---|
4166 | } |
---|
4167 | } |
---|
4168 | /* ordering -------------------------------------------------------------*/ |
---|
4169 | if (rSleftvOrdering2Ordering(ord, R)) |
---|
4170 | goto rInitError; |
---|
4171 | |
---|
4172 | // Complete the initialization |
---|
4173 | if (rComplete(R,1)) |
---|
4174 | goto rInitError; |
---|
4175 | |
---|
4176 | rTest(R); |
---|
4177 | |
---|
4178 | // try to enter the ring into the name list |
---|
4179 | // need to clean up sleftv here, before this ring can be set to |
---|
4180 | // new currRing or currRing can be killed beacuse new ring has |
---|
4181 | // same name |
---|
4182 | if (pn != NULL) pn->CleanUp(); |
---|
4183 | if (rv != NULL) rv->CleanUp(); |
---|
4184 | if (ord != NULL) ord->CleanUp(); |
---|
4185 | //if ((tmp = enterid(s, myynest, RING_CMD, &IDROOT))==NULL) |
---|
4186 | // goto rInitError; |
---|
4187 | |
---|
4188 | //memcpy(IDRING(tmp),R,sizeof(*R)); |
---|
4189 | // set current ring |
---|
4190 | //omFreeBin(R, ip_sring_bin); |
---|
4191 | //return tmp; |
---|
4192 | return R; |
---|
4193 | |
---|
4194 | // error case: |
---|
4195 | rInitError: |
---|
4196 | if (R != NULL) rDelete(R); |
---|
4197 | if (pn != NULL) pn->CleanUp(); |
---|
4198 | if (rv != NULL) rv->CleanUp(); |
---|
4199 | if (ord != NULL) ord->CleanUp(); |
---|
4200 | return NULL; |
---|
4201 | } |
---|
4202 | |
---|
4203 | void rKill(ring r) |
---|
4204 | { |
---|
4205 | if ((r->ref<=0)&&(r->order!=NULL)) |
---|
4206 | { |
---|
4207 | #ifdef RDEBUG |
---|
4208 | if (traceit &TRACE_SHOW_RINGS) Print("kill ring %x\n",r); |
---|
4209 | #endif |
---|
4210 | if (r==currRing) |
---|
4211 | { |
---|
4212 | if (r->qideal!=NULL) |
---|
4213 | { |
---|
4214 | idDelete(&r->qideal); |
---|
4215 | r->qideal=NULL; |
---|
4216 | currQuotient=NULL; |
---|
4217 | } |
---|
4218 | if (ppNoether!=NULL) pDelete(&ppNoether); |
---|
4219 | if (sLastPrinted.RingDependend()) |
---|
4220 | { |
---|
4221 | sLastPrinted.CleanUp(); |
---|
4222 | } |
---|
4223 | if ((myynest>0) && (iiRETURNEXPR[myynest].RingDependend())) |
---|
4224 | { |
---|
4225 | WerrorS("return value depends on local ring variable (export missing ?)"); |
---|
4226 | iiRETURNEXPR[myynest].CleanUp(); |
---|
4227 | } |
---|
4228 | currRing=NULL; |
---|
4229 | currRingHdl=NULL; |
---|
4230 | } |
---|
4231 | else if (r->qideal!=NULL) |
---|
4232 | { |
---|
4233 | id_Delete(&r->qideal, r); |
---|
4234 | r->qideal = NULL; |
---|
4235 | } |
---|
4236 | int i=1; |
---|
4237 | int j; |
---|
4238 | int *pi=r->order; |
---|
4239 | #ifdef USE_IILOCALRING |
---|
4240 | for (j=0;j<iiRETURNEXPR_len;j++) |
---|
4241 | { |
---|
4242 | if (iiLocalRing[j]==r) |
---|
4243 | { |
---|
4244 | if (j<myynest) Warn("killing the basering for level %d",j); |
---|
4245 | iiLocalRing[j]=NULL; |
---|
4246 | } |
---|
4247 | } |
---|
4248 | #else /* USE_IILOCALRING */ |
---|
4249 | //#endif /* USE_IILOCALRING */ |
---|
4250 | { |
---|
4251 | proclevel * nshdl = procstack; |
---|
4252 | int lev=myynest-1; |
---|
4253 | |
---|
4254 | for(; nshdl != NULL; nshdl = nshdl->next) |
---|
4255 | { |
---|
4256 | if (nshdl->cRing==r) |
---|
4257 | { |
---|
4258 | Warn("killing the basering for level %d",lev); |
---|
4259 | nshdl->cRing=NULL; |
---|
4260 | nshdl->cRingHdl=NULL; |
---|
4261 | } |
---|
4262 | } |
---|
4263 | } |
---|
4264 | #endif /* USE_IILOCALRING */ |
---|
4265 | |
---|
4266 | /* nKillChar(r); will be called from inside of rDelete */ |
---|
4267 | rDelete(r); |
---|
4268 | return; |
---|
4269 | } |
---|
4270 | r->ref--; |
---|
4271 | } |
---|
4272 | |
---|
4273 | void rKill(idhdl h) |
---|
4274 | { |
---|
4275 | ring r = IDRING(h); |
---|
4276 | int ref=0; |
---|
4277 | if (r!=NULL) |
---|
4278 | { |
---|
4279 | ref=r->ref; |
---|
4280 | rKill(r); |
---|
4281 | } |
---|
4282 | if (h==currRingHdl) |
---|
4283 | { |
---|
4284 | if (ref<=0) { currRing=NULL; currRingHdl=NULL;} |
---|
4285 | else |
---|
4286 | { |
---|
4287 | currRingHdl=rFindHdl(r,currRingHdl,NULL); |
---|
4288 | } |
---|
4289 | } |
---|
4290 | } |
---|
4291 | |
---|
4292 | idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n=NULL) |
---|
4293 | { |
---|
4294 | //idhdl next_best=NULL; |
---|
4295 | idhdl h=root; |
---|
4296 | while (h!=NULL) |
---|
4297 | { |
---|
4298 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
4299 | && (h!=n) |
---|
4300 | && (IDRING(h)==r) |
---|
4301 | ) |
---|
4302 | { |
---|
4303 | // if (IDLEV(h)==myynest) |
---|
4304 | // return h; |
---|
4305 | // if ((IDLEV(h)==0) || (next_best==NULL)) |
---|
4306 | // next_best=h; |
---|
4307 | // else if (IDLEV(next_best)<IDLEV(h)) |
---|
4308 | // next_best=h; |
---|
4309 | return h; |
---|
4310 | } |
---|
4311 | h=IDNEXT(h); |
---|
4312 | } |
---|
4313 | //return next_best; |
---|
4314 | return NULL; |
---|
4315 | } |
---|
4316 | |
---|