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