[a53ae5] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
| 5 | * ABSTRACT: interpreter: |
---|
| 6 | * assignment of expressions and lists to objects or lists |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include <stdlib.h> |
---|
| 10 | #include <string.h> |
---|
| 11 | #include <ctype.h> |
---|
| 12 | |
---|
[9f7665] | 13 | |
---|
[fd1b1be] | 14 | #include <kernel/mod2.h> |
---|
[9f7665] | 15 | |
---|
[08d98a] | 16 | #include <omalloc/omalloc.h> |
---|
| 17 | |
---|
[16f511] | 18 | #define TRANSEXT_PRIVATES |
---|
| 19 | #include <polys/ext_fields/transext.h> |
---|
| 20 | |
---|
[0fb34ba] | 21 | #include <misc/options.h> |
---|
| 22 | #include <misc/intvec.h> |
---|
[08d98a] | 23 | |
---|
| 24 | #include <coeffs/coeffs.h> |
---|
| 25 | #include <coeffs/numbers.h> |
---|
[75f10d] | 26 | #include <coeffs/bigintmat.h> |
---|
[08d98a] | 27 | |
---|
| 28 | |
---|
| 29 | #include <polys/ext_fields/algext.h> |
---|
| 30 | |
---|
| 31 | #include <polys/monomials/ring.h> |
---|
| 32 | #include <polys/matpol.h> |
---|
| 33 | #include <polys/monomials/maps.h> |
---|
| 34 | #include <polys/nc/nc.h> |
---|
| 35 | #include <polys/nc/sca.h> |
---|
[8ca38a7] | 36 | #include <polys/prCopy.h> |
---|
[08d98a] | 37 | |
---|
[737a68] | 38 | #include <kernel/polys.h> |
---|
[a53ae5] | 39 | #include <kernel/ideals.h> |
---|
[57fa2c4] | 40 | #include <kernel/GBEngine/kstd1.h> |
---|
[c5e82e] | 41 | #include <kernel/oswrapper/timer.h> |
---|
[922890] | 42 | #include <kernel/combinatorics/stairc.h> |
---|
[57fa2c4] | 43 | #include <kernel/GBEngine/syz.h> |
---|
[08d98a] | 44 | |
---|
[a53ae5] | 45 | //#include "weight.h" |
---|
[08d98a] | 46 | #include "tok.h" |
---|
| 47 | #include "ipid.h" |
---|
| 48 | #include "idrec.h" |
---|
| 49 | #include "subexpr.h" |
---|
| 50 | #include "lists.h" |
---|
| 51 | #include "ipconv.h" |
---|
| 52 | #include "attrib.h" |
---|
[44ca2f] | 53 | #include "links/silink.h" |
---|
[08d98a] | 54 | #include "ipshell.h" |
---|
| 55 | #include "blackbox.h" |
---|
[afbc156] | 56 | #include "Singular/number2.h" |
---|
[855a8f] | 57 | |
---|
[a53ae5] | 58 | /*=================== proc =================*/ |
---|
[3c0498] | 59 | static BOOLEAN jjECHO(leftv, leftv a) |
---|
[a53ae5] | 60 | { |
---|
| 61 | si_echo=(int)((long)(a->Data())); |
---|
| 62 | return FALSE; |
---|
| 63 | } |
---|
[3c0498] | 64 | static BOOLEAN jjPRINTLEVEL(leftv, leftv a) |
---|
[a53ae5] | 65 | { |
---|
| 66 | printlevel=(int)((long)(a->Data())); |
---|
| 67 | return FALSE; |
---|
| 68 | } |
---|
[3c0498] | 69 | static BOOLEAN jjCOLMAX(leftv, leftv a) |
---|
[a53ae5] | 70 | { |
---|
| 71 | colmax=(int)((long)(a->Data())); |
---|
| 72 | return FALSE; |
---|
| 73 | } |
---|
[3c0498] | 74 | static BOOLEAN jjTIMER(leftv, leftv a) |
---|
[a53ae5] | 75 | { |
---|
| 76 | timerv=(int)((long)(a->Data())); |
---|
| 77 | initTimer(); |
---|
| 78 | return FALSE; |
---|
| 79 | } |
---|
| 80 | #ifdef HAVE_GETTIMEOFDAY |
---|
[3c0498] | 81 | static BOOLEAN jjRTIMER(leftv, leftv a) |
---|
[a53ae5] | 82 | { |
---|
| 83 | rtimerv=(int)((long)(a->Data())); |
---|
| 84 | initRTimer(); |
---|
| 85 | return FALSE; |
---|
| 86 | } |
---|
| 87 | #endif |
---|
[3c0498] | 88 | static BOOLEAN jjMAXDEG(leftv, leftv a) |
---|
[a53ae5] | 89 | { |
---|
| 90 | Kstd1_deg=(int)((long)(a->Data())); |
---|
| 91 | if (Kstd1_deg!=0) |
---|
[d30a399] | 92 | si_opt_1 |=Sy_bit(OPT_DEGBOUND); |
---|
[a53ae5] | 93 | else |
---|
[d30a399] | 94 | si_opt_1 &=(~Sy_bit(OPT_DEGBOUND)); |
---|
[a53ae5] | 95 | return FALSE; |
---|
| 96 | } |
---|
[d30a399] | 97 | static BOOLEAN jjMAXMULT(leftv, leftv a) |
---|
[a53ae5] | 98 | { |
---|
| 99 | Kstd1_mu=(int)((long)(a->Data())); |
---|
| 100 | if (Kstd1_mu!=0) |
---|
[d30a399] | 101 | si_opt_1 |=Sy_bit(OPT_MULTBOUND); |
---|
[a53ae5] | 102 | else |
---|
[d30a399] | 103 | si_opt_1 &=(~Sy_bit(OPT_MULTBOUND)); |
---|
[a53ae5] | 104 | return FALSE; |
---|
| 105 | } |
---|
[3c0498] | 106 | static BOOLEAN jjTRACE(leftv, leftv a) |
---|
[a53ae5] | 107 | { |
---|
| 108 | traceit=(int)((long)(a->Data())); |
---|
| 109 | return FALSE; |
---|
| 110 | } |
---|
[3c0498] | 111 | static BOOLEAN jjSHORTOUT(leftv, leftv a) |
---|
[a53ae5] | 112 | { |
---|
| 113 | if (currRing != NULL) |
---|
| 114 | { |
---|
| 115 | BOOLEAN shortOut = (BOOLEAN)((long)a->Data()); |
---|
| 116 | #if HAVE_CAN_SHORT_OUT |
---|
| 117 | if (!shortOut) |
---|
| 118 | currRing->ShortOut = 0; |
---|
| 119 | else |
---|
| 120 | { |
---|
| 121 | if (currRing->CanShortOut) |
---|
| 122 | currRing->ShortOut = 1; |
---|
| 123 | } |
---|
| 124 | #else |
---|
| 125 | currRing->ShortOut = shortOut; |
---|
[61a050] | 126 | coeffs cf = currRing->cf; |
---|
| 127 | while (nCoeff_is_Extension(cf)) { |
---|
| 128 | cf->extRing->ShortOut = shortOut; |
---|
| 129 | assume(cf->extRing != NULL); |
---|
| 130 | cf = cf->extRing->cf; |
---|
| 131 | } |
---|
[a53ae5] | 132 | #endif |
---|
| 133 | } |
---|
| 134 | return FALSE; |
---|
| 135 | } |
---|
| 136 | static void jjMINPOLY_red(idhdl h) |
---|
| 137 | { |
---|
| 138 | switch(IDTYP(h)) |
---|
| 139 | { |
---|
| 140 | case NUMBER_CMD: |
---|
| 141 | { |
---|
| 142 | number n=(number)IDDATA(h); |
---|
| 143 | number one = nInit(1); |
---|
| 144 | number nn=nMult(n,one); |
---|
| 145 | nDelete(&n);nDelete(&one); |
---|
| 146 | IDDATA(h)=(char*)nn; |
---|
| 147 | break; |
---|
| 148 | } |
---|
| 149 | case VECTOR_CMD: |
---|
| 150 | case POLY_CMD: |
---|
| 151 | { |
---|
| 152 | poly p=(poly)IDDATA(h); |
---|
[3b1d9a] | 153 | IDDATA(h)=(char*)p_MinPolyNormalize(p, currRing); |
---|
[a53ae5] | 154 | break; |
---|
| 155 | } |
---|
| 156 | case IDEAL_CMD: |
---|
| 157 | case MODUL_CMD: |
---|
| 158 | case MAP_CMD: |
---|
| 159 | case MATRIX_CMD: |
---|
| 160 | { |
---|
| 161 | int i; |
---|
| 162 | ideal I=(ideal)IDDATA(h); |
---|
[3b1d9a] | 163 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
[8a5c49] | 164 | I->m[i]=p_MinPolyNormalize(I->m[i], currRing); |
---|
[a53ae5] | 165 | break; |
---|
| 166 | } |
---|
| 167 | case LIST_CMD: |
---|
| 168 | { |
---|
| 169 | lists L=(lists)IDDATA(h); |
---|
| 170 | int i=L->nr; |
---|
| 171 | for(;i>=0;i--) |
---|
| 172 | { |
---|
| 173 | jjMINPOLY_red((idhdl)&(L->m[i])); |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | default: |
---|
| 177 | //case RESOLUTION_CMD: |
---|
| 178 | Werror("type %d too complex...set minpoly before",IDTYP(h)); break; |
---|
| 179 | } |
---|
| 180 | } |
---|
[3c0498] | 181 | static BOOLEAN jjMINPOLY(leftv, leftv a) |
---|
[a53ae5] | 182 | { |
---|
[4eda6b] | 183 | if( !nCoeff_is_transExt(currRing->cf) && (currRing->idroot == NULL) && n_IsZero((number)a->Data(), currRing->cf) ) |
---|
| 184 | { |
---|
[7fe9e13] | 185 | #ifndef SING_NDEBUG |
---|
[4eda6b] | 186 | WarnS("Set minpoly over non-transcendental ground field to 0?!"); |
---|
[891122] | 187 | Warn("in >>%s<<",my_yylinebuf); |
---|
[47719a] | 188 | #endif |
---|
[52d480] | 189 | return FALSE; |
---|
[4eda6b] | 190 | } |
---|
[52d480] | 191 | |
---|
| 192 | |
---|
[08d98a] | 193 | if ( !nCoeff_is_transExt(currRing->cf) ) |
---|
[8a5c49] | 194 | { |
---|
[108e2ec] | 195 | WarnS("Trying to set minpoly over non-transcendental ground field..."); |
---|
[0f60f3] | 196 | if(!nCoeff_is_algExt(currRing->cf) ) |
---|
| 197 | { |
---|
| 198 | WerrorS("cannot set minpoly for these coeffients"); |
---|
| 199 | return TRUE; |
---|
| 200 | } |
---|
[8a5c49] | 201 | } |
---|
[1beccea] | 202 | if ((rVar(currRing->cf->extRing)!=1) |
---|
| 203 | && !n_IsZero((number)a->Data(), currRing->cf) ) |
---|
| 204 | { |
---|
| 205 | WerrorS("only univarite minpoly allowed"); |
---|
| 206 | return TRUE; |
---|
| 207 | } |
---|
[08d98a] | 208 | |
---|
| 209 | if ( currRing->idroot != NULL ) |
---|
| 210 | { |
---|
[81c5cb] | 211 | // return TRUE; |
---|
[7fe9e13] | 212 | #ifndef SING_NDEBUG |
---|
[108e2ec] | 213 | idhdl p = currRing->idroot; |
---|
| 214 | |
---|
| 215 | WarnS("no minpoly allowed if there are local objects belonging to the basering: "); |
---|
| 216 | |
---|
| 217 | while(p != NULL) |
---|
| 218 | { |
---|
[3c0498] | 219 | PrintS(p->String(TRUE)); PrintLn(); |
---|
[108e2ec] | 220 | p = p->next; |
---|
[52d480] | 221 | } |
---|
[81c5cb] | 222 | #endif |
---|
[08d98a] | 223 | } |
---|
[81c5cb] | 224 | |
---|
[09b7bc] | 225 | // assume (currRing->idroot==NULL); |
---|
[52d480] | 226 | |
---|
[08d98a] | 227 | number p = (number)a->CopyD(NUMBER_CMD); |
---|
[fe7fe88] | 228 | n_Normalize(p, currRing->cf); |
---|
[08d98a] | 229 | |
---|
| 230 | if (n_IsZero(p, currRing->cf)) |
---|
[a53ae5] | 231 | { |
---|
[81c5cb] | 232 | n_Delete(&p, currRing); |
---|
[108e2ec] | 233 | if( nCoeff_is_transExt(currRing->cf) ) |
---|
| 234 | { |
---|
[7fe9e13] | 235 | #ifndef SING_NDEBUG |
---|
[108e2ec] | 236 | WarnS("minpoly is already 0..."); |
---|
| 237 | #endif |
---|
| 238 | return FALSE; |
---|
| 239 | } |
---|
| 240 | WarnS("cannot set minpoly to 0 / alg. extension?"); |
---|
[fe7fe88] | 241 | return TRUE; |
---|
[a53ae5] | 242 | } |
---|
[08d98a] | 243 | |
---|
| 244 | // remove all object currently in the ring |
---|
| 245 | while(currRing->idroot!=NULL) |
---|
| 246 | { |
---|
[7fe9e13] | 247 | #ifndef SING_NDEBUG |
---|
[81c5cb] | 248 | Warn("killing a local object due to minpoly change: %s", IDID(currRing->idroot)); |
---|
| 249 | #endif |
---|
[08d98a] | 250 | killhdl2(currRing->idroot,&(currRing->idroot),currRing); |
---|
| 251 | } |
---|
[52d480] | 252 | |
---|
[08d98a] | 253 | AlgExtInfo A; |
---|
[52d480] | 254 | |
---|
[7e9f12] | 255 | A.r = rCopy(currRing->cf->extRing); // Copy ground field! |
---|
[c8e7d63] | 256 | // if minpoly was already set: |
---|
| 257 | if( currRing->cf->extRing->qideal != NULL ) id_Delete(&(A.r->qideal),A.r); |
---|
[7e9f12] | 258 | ideal q = idInit(1,1); |
---|
[1cd0f4] | 259 | if ((p==NULL) ||(NUM((fraction)p)==NULL)) |
---|
[c8e7d63] | 260 | { |
---|
[7b9b8e5] | 261 | WerrorS("Could not construct the alg. extension: minpoly==0"); |
---|
[c8e7d63] | 262 | // cleanup A: TODO |
---|
| 263 | rDelete( A.r ); |
---|
| 264 | return TRUE; |
---|
| 265 | } |
---|
[1cd0f4] | 266 | if (DEN((fraction)(p)) != NULL) // minpoly must be a fraction with poly numerator...!! |
---|
| 267 | { |
---|
| 268 | poly z=NUM((fraction)p); |
---|
| 269 | poly n=DEN((fraction)(p)); |
---|
| 270 | z=p_Mult_nn(z,pGetCoeff(n),currRing->cf->extRing); |
---|
| 271 | NUM((fraction)p)=z; |
---|
| 272 | DEN((fraction)(p))=NULL; |
---|
| 273 | p_Delete(&n,currRing->cf->extRing); |
---|
| 274 | } |
---|
[52d480] | 275 | |
---|
[9f6cc0] | 276 | q->m[0] = NUM((fraction)p); |
---|
[7e9f12] | 277 | A.r->qideal = q; |
---|
[08d98a] | 278 | |
---|
[60dc849] | 279 | #if 0 |
---|
[08d98a] | 280 | PrintS("\nTrying to conver the currRing into an algebraic field: "); |
---|
| 281 | PrintS("Ground poly. ring: \n"); |
---|
| 282 | rWrite( A.r ); |
---|
| 283 | PrintS("\nGiven MinPOLY: "); |
---|
| 284 | p_Write( A.i->m[0], A.r ); |
---|
| 285 | #endif |
---|
| 286 | |
---|
[1882ae] | 287 | // :( |
---|
[9f6cc0] | 288 | // NUM((fractionObject *)p) = NULL; // makes 0/ NULL fraction - which should not happen! |
---|
| 289 | // n_Delete(&p, currRing->cf); // doesn't expect 0/ NULL :( |
---|
| 290 | if(true) |
---|
| 291 | { |
---|
| 292 | extern omBin fractionObjectBin; |
---|
| 293 | NUM((fractionObject *)p) = NULL; // not necessary, but still... |
---|
| 294 | omFreeBin((ADDRESS)p, fractionObjectBin); |
---|
| 295 | } |
---|
| 296 | |
---|
[52d480] | 297 | |
---|
[08d98a] | 298 | coeffs new_cf = nInitChar(n_algExt, &A); |
---|
[52d480] | 299 | |
---|
[08d98a] | 300 | if (new_cf==NULL) |
---|
| 301 | { |
---|
[7b9b8e5] | 302 | WerrorS("Could not construct the alg. extension: llegal minpoly?"); |
---|
[08d98a] | 303 | // cleanup A: TODO |
---|
[7e9f12] | 304 | rDelete( A.r ); |
---|
[08d98a] | 305 | return TRUE; |
---|
| 306 | } |
---|
[a53ae5] | 307 | else |
---|
| 308 | { |
---|
[08d98a] | 309 | nKillChar(currRing->cf); currRing->cf=new_cf; |
---|
[a53ae5] | 310 | } |
---|
[08d98a] | 311 | |
---|
[a53ae5] | 312 | return FALSE; |
---|
| 313 | } |
---|
[3c0498] | 314 | static BOOLEAN jjNOETHER(leftv, leftv a) |
---|
[a53ae5] | 315 | { |
---|
| 316 | poly p=(poly)a->CopyD(POLY_CMD); |
---|
[993ae2] | 317 | pDelete(&(currRing->ppNoether)); |
---|
| 318 | (currRing->ppNoether)=p; |
---|
[a53ae5] | 319 | return FALSE; |
---|
| 320 | } |
---|
| 321 | /*=================== proc =================*/ |
---|
| 322 | static void jiAssignAttr(leftv l,leftv r) |
---|
| 323 | { |
---|
| 324 | // get the attribute of th right side |
---|
| 325 | // and set it to l |
---|
| 326 | leftv rv=r->LData(); |
---|
| 327 | if (rv!=NULL) |
---|
| 328 | { |
---|
| 329 | if (rv->e==NULL) |
---|
| 330 | { |
---|
| 331 | if (rv->attribute!=NULL) |
---|
| 332 | { |
---|
| 333 | attr la; |
---|
| 334 | if (r->rtyp!=IDHDL) |
---|
| 335 | { |
---|
| 336 | la=rv->attribute; |
---|
| 337 | rv->attribute=NULL; |
---|
| 338 | } |
---|
| 339 | else |
---|
| 340 | { |
---|
| 341 | la=rv->attribute->Copy(); |
---|
| 342 | } |
---|
| 343 | l->attribute=la; |
---|
| 344 | } |
---|
| 345 | l->flag=rv->flag; |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | if (l->rtyp==IDHDL) |
---|
| 349 | { |
---|
| 350 | idhdl h=(idhdl)l->data; |
---|
| 351 | IDATTR(h)=l->attribute; |
---|
| 352 | IDFLAG(h)=l->flag; |
---|
| 353 | } |
---|
| 354 | } |
---|
| 355 | static BOOLEAN jiA_INT(leftv res, leftv a, Subexpr e) |
---|
| 356 | { |
---|
| 357 | if (e==NULL) |
---|
| 358 | { |
---|
| 359 | res->data=(void *)a->Data(); |
---|
| 360 | jiAssignAttr(res,a); |
---|
| 361 | } |
---|
| 362 | else |
---|
| 363 | { |
---|
| 364 | int i=e->start-1; |
---|
| 365 | if (i<0) |
---|
| 366 | { |
---|
| 367 | Werror("index[%d] must be positive",i+1); |
---|
| 368 | return TRUE; |
---|
| 369 | } |
---|
| 370 | intvec *iv=(intvec *)res->data; |
---|
| 371 | if (e->next==NULL) |
---|
| 372 | { |
---|
| 373 | if (i>=iv->length()) |
---|
| 374 | { |
---|
| 375 | intvec *iv1=new intvec(i+1); |
---|
| 376 | (*iv1)[i]=(int)((long)(a->Data())); |
---|
| 377 | intvec *ivn=ivAdd(iv,iv1); |
---|
| 378 | delete iv; |
---|
| 379 | delete iv1; |
---|
| 380 | res->data=(void *)ivn; |
---|
| 381 | } |
---|
| 382 | else |
---|
| 383 | (*iv)[i]=(int)((long)(a->Data())); |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | int c=e->next->start; |
---|
| 388 | if ((i>=iv->rows())||(c<1)||(c>iv->cols())) |
---|
| 389 | { |
---|
[cdb69c] | 390 | Werror("wrong range [%d,%d] in intmat %s(%d,%d)",i+1,c,res->Name(),iv->rows(),iv->cols()); |
---|
[a53ae5] | 391 | return TRUE; |
---|
| 392 | } |
---|
| 393 | else |
---|
| 394 | IMATELEM(*iv,i+1,c) = (int)((long)(a->Data())); |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | return FALSE; |
---|
| 398 | } |
---|
[d30a399] | 399 | static BOOLEAN jiA_NUMBER(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 400 | { |
---|
| 401 | number p=(number)a->CopyD(NUMBER_CMD); |
---|
| 402 | if (res->data!=NULL) nDelete((number *)&res->data); |
---|
| 403 | nNormalize(p); |
---|
| 404 | res->data=(void *)p; |
---|
| 405 | jiAssignAttr(res,a); |
---|
| 406 | return FALSE; |
---|
| 407 | } |
---|
[4a51c1] | 408 | #ifdef SINGULAR_4_1 |
---|
| 409 | static BOOLEAN jiA_NUMBER2(leftv res, leftv a, Subexpr e) |
---|
| 410 | { |
---|
| 411 | number2 n=(number2)a->CopyD(CNUMBER_CMD); |
---|
| 412 | if (e==NULL) |
---|
| 413 | { |
---|
| 414 | if (res->data!=NULL) |
---|
| 415 | { |
---|
| 416 | number2 nn=(number2)res->data; |
---|
| 417 | n2Delete(nn); |
---|
| 418 | } |
---|
| 419 | res->data=(void *)n; |
---|
| 420 | jiAssignAttr(res,a); |
---|
| 421 | } |
---|
| 422 | else |
---|
| 423 | { |
---|
| 424 | int i=e->start-1; |
---|
| 425 | if (i<0) |
---|
| 426 | { |
---|
| 427 | Werror("index[%d] must be positive",i+1); |
---|
| 428 | return TRUE; |
---|
| 429 | } |
---|
| 430 | bigintmat *iv=(bigintmat *)res->data; |
---|
| 431 | if (e->next==NULL) |
---|
| 432 | { |
---|
| 433 | WerrorS("only one index given"); |
---|
| 434 | return TRUE; |
---|
| 435 | } |
---|
| 436 | else |
---|
| 437 | { |
---|
| 438 | int c=e->next->start; |
---|
| 439 | if ((i>=iv->rows())||(c<1)||(c>iv->cols())) |
---|
| 440 | { |
---|
| 441 | Werror("wrong range [%d,%d] in cmatrix %s(%d,%d)",i+1,c,res->Name(),iv->rows(),iv->cols()); |
---|
| 442 | return TRUE; |
---|
| 443 | } |
---|
| 444 | else if (iv->basecoeffs()==n->cf) |
---|
| 445 | { |
---|
| 446 | n_Delete((number *)&BIMATELEM(*iv,i+1,c),iv->basecoeffs()); |
---|
| 447 | BIMATELEM(*iv,i+1,c) = n->n; |
---|
| 448 | } |
---|
| 449 | else |
---|
| 450 | { |
---|
| 451 | WerrorS("different base"); |
---|
| 452 | return TRUE; |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | jiAssignAttr(res,a); |
---|
| 457 | return FALSE; |
---|
| 458 | } |
---|
[70be3a] | 459 | static BOOLEAN jiA_NUMBER2_I(leftv res, leftv a, Subexpr e) |
---|
| 460 | { |
---|
| 461 | if (e==NULL) |
---|
| 462 | { |
---|
| 463 | if (res->data!=NULL) |
---|
| 464 | { |
---|
| 465 | number2 nn=(number2)res->data; |
---|
| 466 | number2 n=n2Init((long)a->Data(),nn->cf); |
---|
| 467 | n2Delete(nn); |
---|
| 468 | res->data=(void *)n; |
---|
| 469 | } |
---|
| 470 | else |
---|
| 471 | { |
---|
[e54c6ee] | 472 | WerrorS("no Ring avialable for conversion from int"); |
---|
[70be3a] | 473 | return TRUE; |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | else |
---|
| 477 | { |
---|
| 478 | int i=e->start-1; |
---|
| 479 | if (i<0) |
---|
| 480 | { |
---|
| 481 | Werror("index[%d] must be positive",i+1); |
---|
| 482 | return TRUE; |
---|
| 483 | } |
---|
| 484 | bigintmat *iv=(bigintmat *)res->data; |
---|
| 485 | if (e->next==NULL) |
---|
| 486 | { |
---|
| 487 | WerrorS("only one index given"); |
---|
| 488 | return TRUE; |
---|
| 489 | } |
---|
| 490 | else |
---|
| 491 | { |
---|
| 492 | int c=e->next->start; |
---|
| 493 | if ((i>=iv->rows())||(c<1)||(c>iv->cols())) |
---|
| 494 | { |
---|
| 495 | Werror("wrong range [%d,%d] in cmatrix %s(%d,%d)",i+1,c,res->Name(),iv->rows(),iv->cols()); |
---|
| 496 | return TRUE; |
---|
| 497 | } |
---|
| 498 | else |
---|
| 499 | { |
---|
| 500 | n_Delete((number *)&BIMATELEM(*iv,i+1,c),iv->basecoeffs()); |
---|
| 501 | BIMATELEM(*iv,i+1,c) = n_Init((long)a->Data(),iv->basecoeffs()); |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | return FALSE; |
---|
| 506 | } |
---|
| 507 | static BOOLEAN jiA_NUMBER2_N(leftv res, leftv a, Subexpr e) |
---|
| 508 | { |
---|
| 509 | if (e==NULL) |
---|
| 510 | { |
---|
| 511 | if (res->data!=NULL) |
---|
| 512 | { |
---|
| 513 | number2 nn=(number2)res->data; |
---|
| 514 | if (currRing->cf==nn->cf) |
---|
| 515 | { |
---|
| 516 | number2 n=(number2)omAlloc(sizeof(*n)); |
---|
| 517 | n->cf=currRing->cf; n->cf++; |
---|
| 518 | n->n=(number)a->CopyD(NUMBER_CMD); |
---|
| 519 | n2Delete(nn); |
---|
| 520 | res->data=(void *)n; |
---|
| 521 | } |
---|
| 522 | else |
---|
| 523 | { |
---|
| 524 | WerrorS("different base"); |
---|
| 525 | return TRUE; |
---|
| 526 | } |
---|
| 527 | } |
---|
| 528 | else |
---|
| 529 | { |
---|
| 530 | WerrorS("no (c)ring avialable for conversion from number"); |
---|
| 531 | return TRUE; |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | else |
---|
| 535 | { |
---|
| 536 | int i=e->start-1; |
---|
| 537 | if (i<0) |
---|
| 538 | { |
---|
| 539 | Werror("index[%d] must be positive",i+1); |
---|
| 540 | return TRUE; |
---|
| 541 | } |
---|
| 542 | bigintmat *iv=(bigintmat *)res->data; |
---|
| 543 | if (e->next==NULL) |
---|
| 544 | { |
---|
| 545 | WerrorS("only one index given"); |
---|
| 546 | return TRUE; |
---|
| 547 | } |
---|
| 548 | else |
---|
| 549 | { |
---|
| 550 | int c=e->next->start; |
---|
| 551 | if ((i>=iv->rows())||(c<1)||(c>iv->cols())) |
---|
| 552 | { |
---|
| 553 | Werror("wrong range [%d,%d] in cmatrix %s(%d,%d)",i+1,c,res->Name(),iv->rows(),iv->cols()); |
---|
| 554 | return TRUE; |
---|
| 555 | } |
---|
| 556 | else if (iv->basecoeffs()==currRing->cf) |
---|
| 557 | { |
---|
| 558 | n_Delete((number *)&BIMATELEM(*iv,i+1,c),iv->basecoeffs()); |
---|
| 559 | BIMATELEM(*iv,i+1,c) = (number)(a->CopyD(NUMBER_CMD)); |
---|
| 560 | } |
---|
| 561 | else |
---|
| 562 | { |
---|
| 563 | WerrorS("different base"); |
---|
| 564 | return TRUE; |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | } |
---|
| 568 | return FALSE; |
---|
| 569 | } |
---|
[4a51c1] | 570 | #endif |
---|
[a53ae5] | 571 | static BOOLEAN jiA_BIGINT(leftv res, leftv a, Subexpr e) |
---|
| 572 | { |
---|
| 573 | number p=(number)a->CopyD(BIGINT_CMD); |
---|
[75f10d] | 574 | if (e==NULL) |
---|
| 575 | { |
---|
| 576 | if (res->data!=NULL) n_Delete((number *)&res->data,coeffs_BIGINT); |
---|
| 577 | res->data=(void *)p; |
---|
| 578 | } |
---|
| 579 | else |
---|
| 580 | { |
---|
| 581 | int i=e->start-1; |
---|
| 582 | if (i<0) |
---|
| 583 | { |
---|
| 584 | Werror("index[%d] must be positive",i+1); |
---|
| 585 | return TRUE; |
---|
| 586 | } |
---|
| 587 | bigintmat *iv=(bigintmat *)res->data; |
---|
| 588 | if (e->next==NULL) |
---|
| 589 | { |
---|
| 590 | WerrorS("only one index given"); |
---|
| 591 | return TRUE; |
---|
| 592 | } |
---|
| 593 | else |
---|
| 594 | { |
---|
| 595 | int c=e->next->start; |
---|
| 596 | if ((i>=iv->rows())||(c<1)||(c>iv->cols())) |
---|
| 597 | { |
---|
[cdb69c] | 598 | Werror("wrong range [%d,%d] in bigintmat %s(%d,%d)",i+1,c,res->Name(),iv->rows(),iv->cols()); |
---|
[75f10d] | 599 | return TRUE; |
---|
| 600 | } |
---|
| 601 | else |
---|
| 602 | { |
---|
| 603 | n_Delete((number *)&BIMATELEM(*iv,i+1,c),iv->basecoeffs()); |
---|
| 604 | BIMATELEM(*iv,i+1,c) = p; |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | } |
---|
[a53ae5] | 608 | jiAssignAttr(res,a); |
---|
| 609 | return FALSE; |
---|
| 610 | } |
---|
[d30a399] | 611 | static BOOLEAN jiA_LIST_RES(leftv res, leftv a,Subexpr) |
---|
[a53ae5] | 612 | { |
---|
| 613 | syStrategy r=(syStrategy)a->CopyD(RESOLUTION_CMD); |
---|
| 614 | if (res->data!=NULL) ((lists)res->data)->Clean(); |
---|
| 615 | int add_row_shift = 0; |
---|
| 616 | intvec *weights=(intvec*)atGet(a,"isHomog",INTVEC_CMD); |
---|
| 617 | if (weights!=NULL) add_row_shift=weights->min_in(); |
---|
| 618 | res->data=(void *)syConvRes(r,TRUE,add_row_shift); |
---|
| 619 | //jiAssignAttr(res,a); |
---|
| 620 | return FALSE; |
---|
| 621 | } |
---|
[d30a399] | 622 | static BOOLEAN jiA_LIST(leftv res, leftv a,Subexpr) |
---|
[a53ae5] | 623 | { |
---|
| 624 | lists l=(lists)a->CopyD(LIST_CMD); |
---|
| 625 | if (res->data!=NULL) ((lists)res->data)->Clean(); |
---|
| 626 | res->data=(void *)l; |
---|
| 627 | jiAssignAttr(res,a); |
---|
| 628 | return FALSE; |
---|
| 629 | } |
---|
| 630 | static BOOLEAN jiA_POLY(leftv res, leftv a,Subexpr e) |
---|
| 631 | { |
---|
| 632 | poly p=(poly)a->CopyD(POLY_CMD); |
---|
| 633 | pNormalize(p); |
---|
| 634 | if (e==NULL) |
---|
| 635 | { |
---|
[75214e] | 636 | if ((p!=NULL) && TEST_V_QRING && (currRing->qideal!=NULL) |
---|
| 637 | && (!hasFlag(a,FLAG_QRING))) |
---|
| 638 | { |
---|
| 639 | jjNormalizeQRingP(p); |
---|
| 640 | setFlag(res,FLAG_QRING); |
---|
| 641 | } |
---|
[a53ae5] | 642 | if (res->data!=NULL) pDelete((poly*)&res->data); |
---|
| 643 | res->data=(void*)p; |
---|
| 644 | jiAssignAttr(res,a); |
---|
| 645 | } |
---|
| 646 | else |
---|
| 647 | { |
---|
| 648 | int i,j; |
---|
| 649 | matrix m=(matrix)res->data; |
---|
| 650 | i=e->start; |
---|
| 651 | if (e->next==NULL) |
---|
| 652 | { |
---|
| 653 | j=i; i=1; |
---|
| 654 | // for all ideal like data types: check indices |
---|
| 655 | if (j>MATCOLS(m)) |
---|
| 656 | { |
---|
[0d0313] | 657 | if (TEST_V_ALLWARN) |
---|
| 658 | { |
---|
| 659 | Warn("increase ideal %d -> %d in %s",MATCOLS(m),j,my_yylinebuf); |
---|
| 660 | } |
---|
[a53ae5] | 661 | pEnlargeSet(&(m->m),MATCOLS(m),j-MATCOLS(m)); |
---|
| 662 | MATCOLS(m)=j; |
---|
| 663 | } |
---|
| 664 | else if (j<=0) |
---|
| 665 | { |
---|
| 666 | Werror("index[%d] must be positive",j/*e->start*/); |
---|
| 667 | return TRUE; |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | else |
---|
| 671 | { |
---|
| 672 | // for matrices: indices are correct (see ipExprArith3(..,'['..) ) |
---|
| 673 | j=e->next->start; |
---|
| 674 | } |
---|
[75214e] | 675 | if ((p!=NULL) && TEST_V_QRING && (currRing->qideal!=NULL)) |
---|
| 676 | { |
---|
| 677 | jjNormalizeQRingP(p); |
---|
| 678 | } |
---|
[a53ae5] | 679 | pDelete(&MATELEM(m,i,j)); |
---|
| 680 | MATELEM(m,i,j)=p; |
---|
| 681 | /* for module: update rank */ |
---|
| 682 | if ((p!=NULL) && (pGetComp(p)!=0)) |
---|
| 683 | { |
---|
| 684 | m->rank=si_max(m->rank,pMaxComp(p)); |
---|
| 685 | } |
---|
| 686 | } |
---|
| 687 | return FALSE; |
---|
| 688 | } |
---|
| 689 | static BOOLEAN jiA_1x1INTMAT(leftv res, leftv a,Subexpr e) |
---|
| 690 | { |
---|
[a9c298] | 691 | if (/*(*/ res->rtyp!=INTMAT_CMD /*)*/) /*|| (e!=NULL) - TRUE because of type int */ |
---|
[a53ae5] | 692 | { |
---|
| 693 | // no error message: assignment simply fails |
---|
| 694 | return TRUE; |
---|
| 695 | } |
---|
| 696 | intvec* am=(intvec*)a->CopyD(INTMAT_CMD); |
---|
| 697 | if ((am->rows()!=1) || (am->cols()!=1)) |
---|
| 698 | { |
---|
| 699 | WerrorS("must be 1x1 intmat"); |
---|
| 700 | delete am; |
---|
| 701 | return TRUE; |
---|
| 702 | } |
---|
| 703 | intvec* m=(intvec *)res->data; |
---|
| 704 | // indices are correct (see ipExprArith3(..,'['..) ) |
---|
| 705 | int i=e->start; |
---|
| 706 | int j=e->next->start; |
---|
| 707 | IMATELEM(*m,i,j)=IMATELEM(*am,1,1); |
---|
| 708 | delete am; |
---|
| 709 | return FALSE; |
---|
| 710 | } |
---|
| 711 | static BOOLEAN jiA_1x1MATRIX(leftv res, leftv a,Subexpr e) |
---|
| 712 | { |
---|
[a9c298] | 713 | if (/*(*/ res->rtyp!=MATRIX_CMD /*)*/) /*|| (e!=NULL) - TRUE because of type poly */ |
---|
[a53ae5] | 714 | { |
---|
| 715 | // no error message: assignment simply fails |
---|
| 716 | return TRUE; |
---|
| 717 | } |
---|
| 718 | matrix am=(matrix)a->CopyD(MATRIX_CMD); |
---|
| 719 | if ((MATROWS(am)!=1) || (MATCOLS(am)!=1)) |
---|
| 720 | { |
---|
| 721 | WerrorS("must be 1x1 matrix"); |
---|
| 722 | idDelete((ideal *)&am); |
---|
| 723 | return TRUE; |
---|
| 724 | } |
---|
| 725 | matrix m=(matrix)res->data; |
---|
| 726 | // indices are correct (see ipExprArith3(..,'['..) ) |
---|
| 727 | int i=e->start; |
---|
| 728 | int j=e->next->start; |
---|
| 729 | pDelete(&MATELEM(m,i,j)); |
---|
| 730 | pNormalize(MATELEM(am,1,1)); |
---|
| 731 | MATELEM(m,i,j)=MATELEM(am,1,1); |
---|
| 732 | MATELEM(am,1,1)=NULL; |
---|
| 733 | idDelete((ideal *)&am); |
---|
| 734 | return FALSE; |
---|
| 735 | } |
---|
| 736 | static BOOLEAN jiA_STRING(leftv res, leftv a, Subexpr e) |
---|
| 737 | { |
---|
| 738 | if (e==NULL) |
---|
| 739 | { |
---|
| 740 | void* tmp = res->data; |
---|
| 741 | res->data=(void *)a->CopyD(STRING_CMD); |
---|
| 742 | jiAssignAttr(res,a); |
---|
| 743 | omfree(tmp); |
---|
| 744 | } |
---|
| 745 | else |
---|
| 746 | { |
---|
| 747 | char *s=(char *)res->data; |
---|
| 748 | if ((e->start>0)&&(e->start<=(int)strlen(s))) |
---|
| 749 | s[e->start-1]=(char)(*((char *)a->Data())); |
---|
| 750 | else |
---|
| 751 | { |
---|
| 752 | Werror("string index %d out of range 1..%d",e->start,(int)strlen(s)); |
---|
| 753 | return TRUE; |
---|
| 754 | } |
---|
| 755 | } |
---|
| 756 | return FALSE; |
---|
| 757 | } |
---|
[d30a399] | 758 | static BOOLEAN jiA_PROC(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 759 | { |
---|
| 760 | extern procinfo *iiInitSingularProcinfo(procinfo *pi, const char *libname, |
---|
| 761 | const char *procname, int line, |
---|
| 762 | long pos, BOOLEAN pstatic=FALSE); |
---|
[ed07eb] | 763 | if(res->data!=NULL) piKill((procinfo *)res->data); |
---|
[f98a260] | 764 | if(a->Typ()==STRING_CMD) |
---|
[a53ae5] | 765 | { |
---|
| 766 | res->data = (void *)omAlloc0Bin(procinfo_bin); |
---|
| 767 | ((procinfo *)(res->data))->language=LANG_NONE; |
---|
| 768 | iiInitSingularProcinfo((procinfo *)res->data,"",res->name,0,0); |
---|
| 769 | ((procinfo *)res->data)->data.s.body=(char *)a->CopyD(STRING_CMD); |
---|
| 770 | } |
---|
| 771 | else |
---|
| 772 | res->data=(void *)a->CopyD(PROC_CMD); |
---|
| 773 | jiAssignAttr(res,a); |
---|
| 774 | return FALSE; |
---|
| 775 | } |
---|
[d30a399] | 776 | static BOOLEAN jiA_INTVEC(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 777 | { |
---|
| 778 | //if ((res->data==NULL) || (res->Typ()==a->Typ())) |
---|
| 779 | { |
---|
| 780 | if (res->data!=NULL) delete ((intvec *)res->data); |
---|
| 781 | res->data=(void *)a->CopyD(INTVEC_CMD); |
---|
| 782 | jiAssignAttr(res,a); |
---|
| 783 | return FALSE; |
---|
| 784 | } |
---|
| 785 | #if 0 |
---|
| 786 | else |
---|
| 787 | { |
---|
| 788 | intvec *r=(intvec *)(res->data); |
---|
| 789 | intvec *s=(intvec *)(a->Data()); |
---|
| 790 | int i=si_min(r->length(), s->length())-1; |
---|
| 791 | for(;i>=0;i--) |
---|
| 792 | { |
---|
| 793 | (*r)[i]=(*s)[i]; |
---|
| 794 | } |
---|
| 795 | return FALSE; //(r->length()< s->length()); |
---|
| 796 | } |
---|
| 797 | #endif |
---|
| 798 | } |
---|
[d30a399] | 799 | static BOOLEAN jiA_BIGINTMAT(leftv res, leftv a, Subexpr) |
---|
[75f10d] | 800 | { |
---|
| 801 | if (res->data!=NULL) delete ((bigintmat *)res->data); |
---|
| 802 | res->data=(void *)a->CopyD(BIGINTMAT_CMD); |
---|
| 803 | jiAssignAttr(res,a); |
---|
| 804 | return FALSE; |
---|
| 805 | } |
---|
[d30a399] | 806 | static BOOLEAN jiA_IDEAL(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 807 | { |
---|
| 808 | if (res->data!=NULL) idDelete((ideal*)&res->data); |
---|
| 809 | res->data=(void *)a->CopyD(MATRIX_CMD); |
---|
[3b1d9a] | 810 | if (a->rtyp==IDHDL) id_Normalize((ideal)a->Data(), currRing); |
---|
| 811 | else id_Normalize((ideal)res->data, currRing); |
---|
[a53ae5] | 812 | jiAssignAttr(res,a); |
---|
| 813 | if (((res->rtyp==IDEAL_CMD)||(res->rtyp==MODUL_CMD)) |
---|
| 814 | && (IDELEMS((ideal)(res->data))==1) |
---|
| 815 | && (currRing->qideal==NULL) |
---|
| 816 | && (!rIsPluralRing(currRing)) |
---|
| 817 | ) |
---|
| 818 | { |
---|
| 819 | setFlag(res,FLAG_STD); |
---|
| 820 | } |
---|
[ac00e2f] | 821 | if (TEST_V_QRING && (currRing->qideal!=NULL)&& (!hasFlag(res,FLAG_QRING))) jjNormalizeQRingId(res); |
---|
[a53ae5] | 822 | return FALSE; |
---|
| 823 | } |
---|
[d30a399] | 824 | static BOOLEAN jiA_RESOLUTION(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 825 | { |
---|
| 826 | if (res->data!=NULL) syKillComputation((syStrategy)res->data); |
---|
| 827 | res->data=(void *)a->CopyD(RESOLUTION_CMD); |
---|
| 828 | jiAssignAttr(res,a); |
---|
| 829 | return FALSE; |
---|
| 830 | } |
---|
[d30a399] | 831 | static BOOLEAN jiA_MODUL_P(leftv res, leftv a, Subexpr) |
---|
[49c9a13] | 832 | /* module = poly */ |
---|
[a53ae5] | 833 | { |
---|
| 834 | if (res->data!=NULL) idDelete((ideal*)&res->data); |
---|
| 835 | ideal I=idInit(1,1); |
---|
| 836 | I->m[0]=(poly)a->CopyD(POLY_CMD); |
---|
| 837 | if (I->m[0]!=NULL) pSetCompP(I->m[0],1); |
---|
| 838 | pNormalize(I->m[0]); |
---|
| 839 | res->data=(void *)I; |
---|
[ac00e2f] | 840 | if (TEST_V_QRING && (currRing->qideal!=NULL)) |
---|
[3e7095] | 841 | { |
---|
| 842 | if (hasFlag(a,FLAG_QRING)) setFlag(res,FLAG_QRING); |
---|
| 843 | else jjNormalizeQRingId(res); |
---|
| 844 | } |
---|
[a53ae5] | 845 | return FALSE; |
---|
| 846 | } |
---|
[d30a399] | 847 | static BOOLEAN jiA_IDEAL_M(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 848 | { |
---|
| 849 | if (res->data!=NULL) idDelete((ideal*)&res->data); |
---|
| 850 | matrix m=(matrix)a->CopyD(MATRIX_CMD); |
---|
[91fb73] | 851 | if (TEST_V_ALLWARN) |
---|
| 852 | if (MATROWS(m)>1) |
---|
| 853 | Warn("assign matrix with %d rows to an ideal in >>%s<<",MATROWS(m),my_yylinebuf); |
---|
[a53ae5] | 854 | IDELEMS((ideal)m)=MATROWS(m)*MATCOLS(m); |
---|
| 855 | ((ideal)m)->rank=1; |
---|
| 856 | MATROWS(m)=1; |
---|
[3b1d9a] | 857 | id_Normalize((ideal)m, currRing); |
---|
[a53ae5] | 858 | res->data=(void *)m; |
---|
[ac00e2f] | 859 | if (TEST_V_QRING && (currRing->qideal!=NULL)) jjNormalizeQRingId(res); |
---|
[a53ae5] | 860 | return FALSE; |
---|
| 861 | } |
---|
[d30a399] | 862 | static BOOLEAN jiA_LINK(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 863 | { |
---|
| 864 | si_link l=(si_link)res->data; |
---|
| 865 | |
---|
| 866 | if (l!=NULL) slCleanUp(l); |
---|
| 867 | |
---|
| 868 | if (a->Typ() == STRING_CMD) |
---|
| 869 | { |
---|
| 870 | if (l == NULL) |
---|
| 871 | { |
---|
| 872 | l = (si_link) omAlloc0Bin(sip_link_bin); |
---|
| 873 | res->data = (void *) l; |
---|
| 874 | } |
---|
| 875 | return slInit(l, (char *) a->Data()); |
---|
| 876 | } |
---|
| 877 | else if (a->Typ() == LINK_CMD) |
---|
| 878 | { |
---|
| 879 | if (l != NULL) omFreeBin(l, sip_link_bin); |
---|
| 880 | res->data = slCopy((si_link)a->Data()); |
---|
| 881 | return FALSE; |
---|
| 882 | } |
---|
| 883 | return TRUE; |
---|
| 884 | } |
---|
| 885 | // assign map -> map |
---|
[d30a399] | 886 | static BOOLEAN jiA_MAP(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 887 | { |
---|
| 888 | if (res->data!=NULL) |
---|
| 889 | { |
---|
| 890 | omFree((ADDRESS)((map)res->data)->preimage); |
---|
| 891 | ((map)res->data)->preimage=NULL; |
---|
| 892 | idDelete((ideal*)&res->data); |
---|
| 893 | } |
---|
| 894 | res->data=(void *)a->CopyD(MAP_CMD); |
---|
| 895 | jiAssignAttr(res,a); |
---|
| 896 | return FALSE; |
---|
| 897 | } |
---|
| 898 | // assign ideal -> map |
---|
[d30a399] | 899 | static BOOLEAN jiA_MAP_ID(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 900 | { |
---|
| 901 | map f=(map)res->data; |
---|
| 902 | char *rn=f->preimage; // save the old/already assigned preimage ring name |
---|
| 903 | f->preimage=NULL; |
---|
| 904 | idDelete((ideal *)&f); |
---|
| 905 | res->data=(void *)a->CopyD(IDEAL_CMD); |
---|
| 906 | f=(map)res->data; |
---|
[3b1d9a] | 907 | id_Normalize((ideal)f, currRing); |
---|
[a53ae5] | 908 | f->preimage = rn; |
---|
| 909 | return FALSE; |
---|
| 910 | } |
---|
| 911 | static BOOLEAN jiA_QRING(leftv res, leftv a,Subexpr e) |
---|
| 912 | { |
---|
| 913 | // the follwing can only happen, if: |
---|
| 914 | // - the left side is of type qring AND not an id |
---|
| 915 | if ((e!=NULL)||(res->rtyp!=IDHDL)) |
---|
| 916 | { |
---|
| 917 | WerrorS("qring_id expected"); |
---|
| 918 | return TRUE; |
---|
| 919 | } |
---|
[ad75784] | 920 | ring old_ring=(ring)res->Data(); |
---|
[fc8d35] | 921 | |
---|
[d02a206] | 922 | coeffs newcf = currRing->cf; |
---|
| 923 | ideal id = (ideal)a->Data(); //? |
---|
[91c0af] | 924 | const int cpos = idPosConstant(id); |
---|
[d02a206] | 925 | if(rField_is_Ring(currRing)) |
---|
| 926 | if (cpos >= 0) |
---|
[3e31b2] | 927 | { |
---|
[d02a206] | 928 | newcf = n_CoeffRingQuot1(p_GetCoeff(id->m[cpos], currRing), currRing->cf); |
---|
| 929 | if(newcf == NULL) |
---|
| 930 | return TRUE; |
---|
[3e31b2] | 931 | } |
---|
[d02a206] | 932 | //qr=(ring)res->Data(); |
---|
| 933 | //if (qr!=NULL) omFreeBin((ADDRESS)qr, ip_sring_bin); |
---|
| 934 | ring qr = rCopy(currRing); |
---|
| 935 | assume(qr->cf == currRing->cf); |
---|
[91c0af] | 936 | |
---|
[d02a206] | 937 | if ( qr->cf != newcf ) |
---|
| 938 | { |
---|
| 939 | nKillChar ( qr->cf ); // ??? |
---|
| 940 | qr->cf = newcf; |
---|
[91c0af] | 941 | } |
---|
[8ca38a7] | 942 | // we have to fill it, but the copy also allocates space |
---|
| 943 | idhdl h=(idhdl)res->data; // we have res->rtyp==IDHDL |
---|
| 944 | IDRING(h)=qr; |
---|
[91c0af] | 945 | |
---|
[8ca38a7] | 946 | ideal qid; |
---|
[d02a206] | 947 | |
---|
| 948 | if((rField_is_Ring(currRing)) && (cpos != -1)) |
---|
[e6f1e6] | 949 | { |
---|
| 950 | int i, j; |
---|
| 951 | int *perm = (int *)omAlloc0((qr->N+1)*sizeof(int)); |
---|
[91c0af] | 952 | |
---|
[e6f1e6] | 953 | for(i=qr->N;i>0;i--) |
---|
| 954 | perm[i]=i; |
---|
[d02a206] | 955 | |
---|
[e6f1e6] | 956 | nMapFunc nMap = n_SetMap(currRing->cf, newcf); |
---|
| 957 | qid = idInit(IDELEMS(id)-1,1); |
---|
| 958 | for(i = 0, j = 0; i<IDELEMS(id); i++) |
---|
| 959 | if( i != cpos ) |
---|
| 960 | qid->m[j++] = p_PermPoly(id->m[i], perm, currRing, qr, nMap, NULL, 0); |
---|
| 961 | } |
---|
| 962 | else |
---|
| 963 | qid = idrCopyR(id,currRing,qr); |
---|
[91c0af] | 964 | |
---|
[8ca38a7] | 965 | idSkipZeroes(qid); |
---|
| 966 | //idPrint(qid); |
---|
| 967 | if ((idElem(qid)>1) || rIsSCA(currRing) || (currRing->qideal!=NULL)) |
---|
| 968 | assumeStdFlag(a); |
---|
| 969 | |
---|
[a53ae5] | 970 | if (currRing->qideal!=NULL) /* we are already in a qring! */ |
---|
| 971 | { |
---|
[8ca38a7] | 972 | ideal tmp=idSimpleAdd(qid,currRing->qideal); |
---|
[a53ae5] | 973 | // both ideals should be GB, so dSimpleAdd is sufficient |
---|
[8ca38a7] | 974 | idDelete(&qid); |
---|
| 975 | qid=tmp; |
---|
[a53ae5] | 976 | // delete the qr copy of quotient ideal!!! |
---|
| 977 | idDelete(&qr->qideal); |
---|
| 978 | } |
---|
[8ca38a7] | 979 | if (idElem(qid)==0) |
---|
[bbcf7c8] | 980 | { |
---|
| 981 | qr->qideal = NULL; |
---|
[8ca38a7] | 982 | id_Delete(&qid,currRing); |
---|
[bbcf7c8] | 983 | IDTYP(h)=RING_CMD; |
---|
| 984 | } |
---|
| 985 | else |
---|
[8ca38a7] | 986 | qr->qideal = qid; |
---|
[a53ae5] | 987 | |
---|
| 988 | // qr is a copy of currRing with the new qideal! |
---|
| 989 | #ifdef HAVE_PLURAL |
---|
[bbcf7c8] | 990 | if(rIsPluralRing(currRing) &&(qr->qideal!=NULL)) |
---|
[a53ae5] | 991 | { |
---|
| 992 | if (!hasFlag(a,FLAG_TWOSTD)) |
---|
| 993 | { |
---|
| 994 | Warn("%s is no twosided standard basis",a->Name()); |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | if( nc_SetupQuotient(qr, currRing) ) |
---|
| 998 | { |
---|
| 999 | // WarnS("error in nc_SetupQuotient"); |
---|
| 1000 | } |
---|
| 1001 | } |
---|
| 1002 | #endif |
---|
[8ca38a7] | 1003 | //rWrite(qr); |
---|
[a53ae5] | 1004 | rSetHdl((idhdl)res->data); |
---|
[ad75784] | 1005 | if (old_ring!=NULL) |
---|
| 1006 | { |
---|
| 1007 | rDelete(old_ring); |
---|
| 1008 | } |
---|
[a53ae5] | 1009 | return FALSE; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | static BOOLEAN jiA_RING(leftv res, leftv a, Subexpr e) |
---|
| 1013 | { |
---|
| 1014 | BOOLEAN have_id=TRUE; |
---|
| 1015 | if ((e!=NULL)||(res->rtyp!=IDHDL)) |
---|
| 1016 | { |
---|
| 1017 | //WerrorS("id expected"); |
---|
| 1018 | //return TRUE; |
---|
| 1019 | have_id=FALSE; |
---|
| 1020 | } |
---|
| 1021 | ring r=(ring)a->Data(); |
---|
[595145] | 1022 | if ((r==NULL)||(r->cf==NULL)) return TRUE; |
---|
[a53ae5] | 1023 | if (have_id) |
---|
| 1024 | { |
---|
| 1025 | idhdl rl=(idhdl)res->data; |
---|
| 1026 | if (IDRING(rl)!=NULL) rKill(rl); |
---|
| 1027 | IDRING(rl)=r; |
---|
| 1028 | if ((IDLEV((idhdl)a->data)!=myynest) && (r==currRing)) |
---|
| 1029 | currRingHdl=(idhdl)res->data; |
---|
| 1030 | } |
---|
| 1031 | else |
---|
| 1032 | { |
---|
| 1033 | if (e==NULL) res->data=(char *)r; |
---|
| 1034 | else |
---|
| 1035 | { |
---|
| 1036 | WerrorS("id expected"); |
---|
| 1037 | return TRUE; |
---|
| 1038 | } |
---|
| 1039 | } |
---|
| 1040 | r->ref++; |
---|
| 1041 | jiAssignAttr(res,a); |
---|
| 1042 | return FALSE; |
---|
| 1043 | } |
---|
[d30a399] | 1044 | static BOOLEAN jiA_PACKAGE(leftv res, leftv a, Subexpr) |
---|
[a53ae5] | 1045 | { |
---|
| 1046 | res->data=(void *)a->CopyD(PACKAGE_CMD); |
---|
| 1047 | jiAssignAttr(res,a); |
---|
| 1048 | return FALSE; |
---|
| 1049 | } |
---|
[0338ae9] | 1050 | static BOOLEAN jiA_DEF(leftv res, leftv, Subexpr) |
---|
[0d008d] | 1051 | { |
---|
| 1052 | res->data=(void *)0; |
---|
| 1053 | return FALSE; |
---|
| 1054 | } |
---|
[9b12fce] | 1055 | #ifdef SINGULAR_4_1 |
---|
| 1056 | static BOOLEAN jiA_CRING(leftv res, leftv a, Subexpr e) |
---|
| 1057 | { |
---|
| 1058 | res->data=(void *)a->CopyD(CRING_CMD); |
---|
| 1059 | jiAssignAttr(res,a); |
---|
| 1060 | return FALSE; |
---|
| 1061 | } |
---|
| 1062 | #endif |
---|
| 1063 | |
---|
[a53ae5] | 1064 | /*=================== table =================*/ |
---|
| 1065 | #define IPASSIGN |
---|
[1882ae] | 1066 | #define D(A) A |
---|
| 1067 | #define NULL_VAL NULL |
---|
[08d98a] | 1068 | #include "table.h" |
---|
[a53ae5] | 1069 | /*=================== operations ============================*/ |
---|
| 1070 | /*2 |
---|
| 1071 | * assign a = b |
---|
| 1072 | */ |
---|
[4a74cc] | 1073 | static BOOLEAN jiAssign_1(leftv l, leftv r, BOOLEAN toplevel) |
---|
[a53ae5] | 1074 | { |
---|
| 1075 | int rt=r->Typ(); |
---|
| 1076 | if (rt==0) |
---|
| 1077 | { |
---|
| 1078 | if (!errorreported) Werror("`%s` is undefined",r->Fullname()); |
---|
| 1079 | return TRUE; |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | int lt=l->Typ(); |
---|
[4a74cc] | 1083 | if (lt==0) |
---|
[a53ae5] | 1084 | { |
---|
| 1085 | if (!errorreported) Werror("left side `%s` is undefined",l->Fullname()); |
---|
| 1086 | return TRUE; |
---|
| 1087 | } |
---|
[2bc7fb] | 1088 | if(rt==NONE) |
---|
[a53ae5] | 1089 | { |
---|
| 1090 | WarnS("right side is not a datum, assignment ignored"); |
---|
[e35529] | 1091 | Warn("in line >>%s<<",my_yylinebuf); |
---|
[a53ae5] | 1092 | // if (!errorreported) |
---|
| 1093 | // WerrorS("right side is not a datum"); |
---|
| 1094 | //return TRUE; |
---|
| 1095 | return FALSE; |
---|
| 1096 | } |
---|
| 1097 | |
---|
| 1098 | if (lt==DEF_CMD) |
---|
| 1099 | { |
---|
[137883e] | 1100 | if (TEST_V_ALLWARN |
---|
| 1101 | && (rt!=RING_CMD) |
---|
| 1102 | && (l->name!=NULL) |
---|
| 1103 | && (l->e==NULL) |
---|
| 1104 | && (iiCurrArgs==NULL) /* not in proc header */ |
---|
| 1105 | ) |
---|
| 1106 | { |
---|
[ab1e00] | 1107 | Warn("use `%s` instead of `def` in %s:%d:%s",Tok2Cmdname(rt), |
---|
| 1108 | currentVoice->filename,yylineno,my_yylinebuf); |
---|
[137883e] | 1109 | } |
---|
[0d008d] | 1110 | if (l->rtyp==IDHDL) |
---|
[a53ae5] | 1111 | { |
---|
[0d008d] | 1112 | IDTYP((idhdl)l->data)=rt; |
---|
| 1113 | } |
---|
| 1114 | else if (l->name!=NULL) |
---|
| 1115 | { |
---|
| 1116 | sleftv ll; |
---|
| 1117 | iiDeclCommand(&ll,l,myynest,rt,&IDROOT); |
---|
| 1118 | memcpy(l,&ll,sizeof(sleftv)); |
---|
| 1119 | } |
---|
| 1120 | else |
---|
| 1121 | { |
---|
| 1122 | l->rtyp=rt; |
---|
[a53ae5] | 1123 | } |
---|
[0d008d] | 1124 | lt=rt; |
---|
[a53ae5] | 1125 | } |
---|
| 1126 | else |
---|
| 1127 | { |
---|
| 1128 | if ((l->data==r->data)&&(l->e==NULL)&&(r->e==NULL)) |
---|
| 1129 | return FALSE; |
---|
| 1130 | } |
---|
| 1131 | leftv ld=l; |
---|
[4a74cc] | 1132 | if (l->rtyp==IDHDL) |
---|
| 1133 | { |
---|
[d2fc5c5] | 1134 | if (lt!=RING_CMD) |
---|
[4a74cc] | 1135 | ld=(leftv)l->data; |
---|
| 1136 | } |
---|
| 1137 | else if (toplevel) |
---|
| 1138 | { |
---|
| 1139 | WerrorS("error in assign: left side is not an l-value"); |
---|
| 1140 | return TRUE; |
---|
| 1141 | } |
---|
[eab100d] | 1142 | if (lt>MAX_TOK) |
---|
| 1143 | { |
---|
| 1144 | blackbox *bb=getBlackboxStuff(lt); |
---|
| 1145 | #ifdef BLACKBOX_DEVEL |
---|
| 1146 | Print("bb-assign: bb=%lx\n",bb); |
---|
| 1147 | #endif |
---|
| 1148 | return (bb==NULL) || bb->blackbox_Assign(l,r); |
---|
| 1149 | } |
---|
[0eeee4] | 1150 | int start=0; |
---|
| 1151 | while ((dAssign[start].res!=lt) |
---|
| 1152 | && (dAssign[start].res!=0)) start++; |
---|
| 1153 | int i=start; |
---|
| 1154 | while ((dAssign[i].res==lt) |
---|
| 1155 | && (dAssign[i].arg!=rt)) i++; |
---|
| 1156 | if (dAssign[i].res==lt) |
---|
[a53ae5] | 1157 | { |
---|
[a97ac0] | 1158 | if (traceit&TRACE_ASSIGN) Print("assign %s=%s\n",Tok2Cmdname(lt),Tok2Cmdname(rt)); |
---|
[a53ae5] | 1159 | BOOLEAN b; |
---|
| 1160 | b=dAssign[i].p(ld,r,l->e); |
---|
| 1161 | if(l!=ld) /* i.e. l is IDHDL, l->data is ld */ |
---|
| 1162 | { |
---|
| 1163 | l->flag=ld->flag; |
---|
| 1164 | l->attribute=ld->attribute; |
---|
| 1165 | } |
---|
| 1166 | return b; |
---|
| 1167 | } |
---|
| 1168 | // implicite type conversion ---------------------------------------------- |
---|
[0eeee4] | 1169 | if (dAssign[i].res!=lt) |
---|
[a53ae5] | 1170 | { |
---|
| 1171 | int ri; |
---|
| 1172 | leftv rn = (leftv)omAlloc0Bin(sleftv_bin); |
---|
| 1173 | BOOLEAN failed=FALSE; |
---|
[0eeee4] | 1174 | i=start; |
---|
| 1175 | //while ((dAssign[i].res!=lt) |
---|
| 1176 | // && (dAssign[i].res!=0)) i++; |
---|
[a53ae5] | 1177 | while (dAssign[i].res==lt) |
---|
| 1178 | { |
---|
| 1179 | if ((ri=iiTestConvert(rt,dAssign[i].arg))!=0) |
---|
| 1180 | { |
---|
| 1181 | failed= iiConvert(rt,dAssign[i].arg,ri,r,rn); |
---|
| 1182 | if(!failed) |
---|
| 1183 | { |
---|
| 1184 | failed= dAssign[i].p(ld,rn,l->e); |
---|
[a97ac0] | 1185 | if (traceit&TRACE_ASSIGN) |
---|
[fc8d35] | 1186 | Print("assign %s=%s ok? %d\n",Tok2Cmdname(lt),Tok2Cmdname(rn->rtyp),!failed); |
---|
[a53ae5] | 1187 | } |
---|
| 1188 | // everything done, clean up temp. variables |
---|
| 1189 | rn->CleanUp(); |
---|
| 1190 | omFreeBin((ADDRESS)rn, sleftv_bin); |
---|
| 1191 | if (failed) |
---|
| 1192 | { |
---|
| 1193 | // leave loop, goto error handling |
---|
| 1194 | break; |
---|
| 1195 | } |
---|
| 1196 | else |
---|
| 1197 | { |
---|
| 1198 | if(l!=ld) /* i.e. l is IDHDL, l->data is ld */ |
---|
| 1199 | { |
---|
| 1200 | l->flag=ld->flag; |
---|
| 1201 | l->attribute=ld->attribute; |
---|
| 1202 | } |
---|
| 1203 | // everything ok, return |
---|
| 1204 | return FALSE; |
---|
| 1205 | } |
---|
| 1206 | } |
---|
| 1207 | i++; |
---|
| 1208 | } |
---|
| 1209 | // error handling --------------------------------------------------- |
---|
| 1210 | if (!errorreported) |
---|
| 1211 | { |
---|
| 1212 | if ((l->rtyp==IDHDL) && (l->e==NULL)) |
---|
| 1213 | Werror("`%s`(%s) = `%s` is not supported", |
---|
| 1214 | Tok2Cmdname(lt),l->Name(),Tok2Cmdname(rt)); |
---|
| 1215 | else |
---|
| 1216 | Werror("`%s` = `%s` is not supported" |
---|
| 1217 | ,Tok2Cmdname(lt),Tok2Cmdname(rt)); |
---|
| 1218 | if (BVERBOSE(V_SHOW_USE)) |
---|
| 1219 | { |
---|
| 1220 | i=0; |
---|
| 1221 | while ((dAssign[i].res!=lt) |
---|
| 1222 | && (dAssign[i].res!=0)) i++; |
---|
| 1223 | while (dAssign[i].res==lt) |
---|
| 1224 | { |
---|
| 1225 | Werror("expected `%s` = `%s`" |
---|
| 1226 | ,Tok2Cmdname(lt),Tok2Cmdname(dAssign[i].arg)); |
---|
| 1227 | i++; |
---|
| 1228 | } |
---|
| 1229 | } |
---|
| 1230 | } |
---|
| 1231 | } |
---|
| 1232 | return TRUE; |
---|
| 1233 | } |
---|
| 1234 | /*2 |
---|
| 1235 | * assign sys_var = val |
---|
| 1236 | */ |
---|
| 1237 | static BOOLEAN iiAssign_sys(leftv l, leftv r) |
---|
| 1238 | { |
---|
| 1239 | int rt=r->Typ(); |
---|
| 1240 | |
---|
| 1241 | if (rt==0) |
---|
| 1242 | { |
---|
| 1243 | if (!errorreported) Werror("`%s` is undefined",r->Fullname()); |
---|
| 1244 | return TRUE; |
---|
| 1245 | } |
---|
| 1246 | int i=0; |
---|
| 1247 | int lt=l->rtyp; |
---|
| 1248 | while (((dAssign_sys[i].res!=lt) |
---|
| 1249 | || (dAssign_sys[i].arg!=rt)) |
---|
| 1250 | && (dAssign_sys[i].res!=0)) i++; |
---|
| 1251 | if (dAssign_sys[i].res!=0) |
---|
| 1252 | { |
---|
| 1253 | if (!dAssign_sys[i].p(l,r)) |
---|
| 1254 | { |
---|
| 1255 | // everything ok, clean up |
---|
| 1256 | return FALSE; |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | // implicite type conversion ---------------------------------------------- |
---|
| 1260 | if (dAssign_sys[i].res==0) |
---|
| 1261 | { |
---|
| 1262 | int ri; |
---|
| 1263 | leftv rn = (leftv)omAlloc0Bin(sleftv_bin); |
---|
| 1264 | BOOLEAN failed=FALSE; |
---|
| 1265 | i=0; |
---|
| 1266 | while ((dAssign_sys[i].res!=lt) |
---|
| 1267 | && (dAssign_sys[i].res!=0)) i++; |
---|
| 1268 | while (dAssign_sys[i].res==lt) |
---|
| 1269 | { |
---|
| 1270 | if ((ri=iiTestConvert(rt,dAssign_sys[i].arg))!=0) |
---|
| 1271 | { |
---|
| 1272 | failed= ((iiConvert(rt,dAssign_sys[i].arg,ri,r,rn)) |
---|
| 1273 | || (dAssign_sys[i].p(l,rn))); |
---|
| 1274 | // everything done, clean up temp. variables |
---|
| 1275 | rn->CleanUp(); |
---|
| 1276 | omFreeBin((ADDRESS)rn, sleftv_bin); |
---|
| 1277 | if (failed) |
---|
| 1278 | { |
---|
| 1279 | // leave loop, goto error handling |
---|
| 1280 | break; |
---|
| 1281 | } |
---|
| 1282 | else |
---|
| 1283 | { |
---|
| 1284 | // everything ok, return |
---|
| 1285 | return FALSE; |
---|
| 1286 | } |
---|
| 1287 | } |
---|
| 1288 | i++; |
---|
| 1289 | } |
---|
| 1290 | // error handling --------------------------------------------------- |
---|
| 1291 | if(!errorreported) |
---|
| 1292 | { |
---|
| 1293 | Werror("`%s` = `%s` is not supported" |
---|
| 1294 | ,Tok2Cmdname(lt),Tok2Cmdname(rt)); |
---|
| 1295 | if (BVERBOSE(V_SHOW_USE)) |
---|
| 1296 | { |
---|
| 1297 | i=0; |
---|
| 1298 | while ((dAssign_sys[i].res!=lt) |
---|
| 1299 | && (dAssign_sys[i].res!=0)) i++; |
---|
| 1300 | while (dAssign_sys[i].res==lt) |
---|
| 1301 | { |
---|
| 1302 | Werror("expected `%s` = `%s`" |
---|
| 1303 | ,Tok2Cmdname(lt),Tok2Cmdname(dAssign_sys[i].arg)); |
---|
| 1304 | i++; |
---|
| 1305 | } |
---|
| 1306 | } |
---|
| 1307 | } |
---|
| 1308 | } |
---|
| 1309 | return TRUE; |
---|
| 1310 | } |
---|
| 1311 | static BOOLEAN jiA_INTVEC_L(leftv l,leftv r) |
---|
| 1312 | { |
---|
| 1313 | /* right side is intvec, left side is list (of int)*/ |
---|
| 1314 | BOOLEAN nok; |
---|
| 1315 | int i=0; |
---|
| 1316 | leftv l1=l; |
---|
| 1317 | leftv h; |
---|
| 1318 | sleftv t; |
---|
| 1319 | intvec *iv=(intvec *)r->Data(); |
---|
| 1320 | memset(&t,0,sizeof(sleftv)); |
---|
| 1321 | t.rtyp=INT_CMD; |
---|
| 1322 | while ((i<iv->length())&&(l!=NULL)) |
---|
| 1323 | { |
---|
[e2202ee] | 1324 | t.data=(char *)(long)(*iv)[i]; |
---|
[a53ae5] | 1325 | h=l->next; |
---|
| 1326 | l->next=NULL; |
---|
[4a74cc] | 1327 | nok=jiAssign_1(l,&t,TRUE); |
---|
[628418] | 1328 | l->next=h; |
---|
[a53ae5] | 1329 | if (nok) return TRUE; |
---|
| 1330 | i++; |
---|
| 1331 | l=h; |
---|
| 1332 | } |
---|
| 1333 | l1->CleanUp(); |
---|
| 1334 | r->CleanUp(); |
---|
| 1335 | return FALSE; |
---|
| 1336 | } |
---|
| 1337 | static BOOLEAN jiA_VECTOR_L(leftv l,leftv r) |
---|
| 1338 | { |
---|
| 1339 | /* right side is vector, left side is list (of poly)*/ |
---|
| 1340 | BOOLEAN nok; |
---|
| 1341 | leftv l1=l; |
---|
| 1342 | ideal I=idVec2Ideal((poly)r->Data()); |
---|
| 1343 | leftv h; |
---|
| 1344 | sleftv t; |
---|
| 1345 | int i=0; |
---|
| 1346 | while (l!=NULL) |
---|
| 1347 | { |
---|
| 1348 | memset(&t,0,sizeof(sleftv)); |
---|
| 1349 | t.rtyp=POLY_CMD; |
---|
| 1350 | if (i>=IDELEMS(I)) |
---|
| 1351 | { |
---|
| 1352 | t.data=NULL; |
---|
| 1353 | } |
---|
| 1354 | else |
---|
| 1355 | { |
---|
| 1356 | t.data=(char *)I->m[i]; |
---|
| 1357 | I->m[i]=NULL; |
---|
| 1358 | } |
---|
| 1359 | h=l->next; |
---|
| 1360 | l->next=NULL; |
---|
[4a74cc] | 1361 | nok=jiAssign_1(l,&t,TRUE); |
---|
[628418] | 1362 | l->next=h; |
---|
[a53ae5] | 1363 | t.CleanUp(); |
---|
| 1364 | if (nok) |
---|
| 1365 | { |
---|
| 1366 | idDelete(&I); |
---|
| 1367 | return TRUE; |
---|
| 1368 | } |
---|
| 1369 | i++; |
---|
| 1370 | l=h; |
---|
| 1371 | } |
---|
| 1372 | idDelete(&I); |
---|
| 1373 | l1->CleanUp(); |
---|
| 1374 | r->CleanUp(); |
---|
[ac00e2f] | 1375 | //if (TEST_V_QRING && (currRing->qideal!=NULL)) jjNormalizeQRingP(l); |
---|
[a53ae5] | 1376 | return FALSE; |
---|
| 1377 | } |
---|
| 1378 | static BOOLEAN jjA_L_LIST(leftv l, leftv r) |
---|
| 1379 | /* left side: list/def, has to be a "real" variable |
---|
| 1380 | * right side: expression list |
---|
| 1381 | */ |
---|
| 1382 | { |
---|
| 1383 | int sl = r->listLength(); |
---|
| 1384 | lists L=(lists)omAllocBin(slists_bin); |
---|
| 1385 | lists oldL; |
---|
| 1386 | leftv h=NULL,o_r=r; |
---|
| 1387 | int i; |
---|
| 1388 | int rt; |
---|
| 1389 | |
---|
| 1390 | L->Init(sl); |
---|
| 1391 | for (i=0;i<sl;i++) |
---|
| 1392 | { |
---|
| 1393 | if (h!=NULL) { /* e.g. not in the first step: |
---|
| 1394 | * h is the pointer to the old sleftv, |
---|
| 1395 | * r is the pointer to the next sleftv |
---|
| 1396 | * (in this moment) */ |
---|
| 1397 | h->next=r; |
---|
| 1398 | } |
---|
| 1399 | h=r; |
---|
| 1400 | r=r->next; |
---|
| 1401 | h->next=NULL; |
---|
| 1402 | rt=h->Typ(); |
---|
| 1403 | if ((rt==0)||(rt==NONE)||(rt==DEF_CMD)) |
---|
| 1404 | { |
---|
| 1405 | L->Clean(); |
---|
| 1406 | Werror("`%s` is undefined",h->Fullname()); |
---|
| 1407 | //listall(); |
---|
| 1408 | goto err; |
---|
| 1409 | } |
---|
[d2fc5c5] | 1410 | //if (rt==RING_CMD) |
---|
[a53ae5] | 1411 | //{ |
---|
| 1412 | // L->m[i].rtyp=rt; |
---|
| 1413 | // L->m[i].data=h->Data(); |
---|
| 1414 | // ((ring)L->m[i].data)->ref++; |
---|
| 1415 | //} |
---|
| 1416 | //else |
---|
| 1417 | L->m[i].CleanUp(); |
---|
| 1418 | L->m[i].Copy(h); |
---|
| 1419 | if(errorreported) |
---|
| 1420 | { |
---|
| 1421 | L->Clean(); |
---|
| 1422 | goto err; |
---|
| 1423 | } |
---|
| 1424 | } |
---|
| 1425 | oldL=(lists)l->Data(); |
---|
| 1426 | if (oldL!=NULL) oldL->Clean(); |
---|
| 1427 | if (l->rtyp==IDHDL) |
---|
| 1428 | { |
---|
| 1429 | IDLIST((idhdl)l->data)=L; |
---|
| 1430 | IDTYP((idhdl)l->data)=LIST_CMD; // was possibly DEF_CMD |
---|
[91c0af] | 1431 | if (lRingDependend(L)) ipMoveId((idhdl)l->data); |
---|
[a53ae5] | 1432 | } |
---|
| 1433 | else |
---|
| 1434 | { |
---|
| 1435 | l->LData()->data=L; |
---|
| 1436 | if ((l->e!=NULL) && (l->rtyp==DEF_CMD)) |
---|
| 1437 | l->rtyp=LIST_CMD; |
---|
| 1438 | } |
---|
| 1439 | err: |
---|
| 1440 | o_r->CleanUp(); |
---|
| 1441 | return errorreported; |
---|
| 1442 | } |
---|
| 1443 | static BOOLEAN jjA_L_INTVEC(leftv l,leftv r,intvec *iv) |
---|
| 1444 | { |
---|
| 1445 | /* left side is intvec/intmat, right side is list (of int,intvec,intmat)*/ |
---|
| 1446 | leftv hh=r; |
---|
| 1447 | int i = 0; |
---|
| 1448 | while (hh!=NULL) |
---|
| 1449 | { |
---|
[fc8d35] | 1450 | if (i>=iv->length()) |
---|
| 1451 | { |
---|
[a97ac0] | 1452 | if (traceit&TRACE_ASSIGN) |
---|
[fc8d35] | 1453 | { |
---|
| 1454 | Warn("expression list length(%d) does not match intmat size(%d)", |
---|
[8a5c49] | 1455 | iv->length()+exprlist_length(hh),iv->length()); |
---|
[fc8d35] | 1456 | } |
---|
| 1457 | break; |
---|
| 1458 | } |
---|
[a53ae5] | 1459 | if (hh->Typ() == INT_CMD) |
---|
| 1460 | { |
---|
| 1461 | (*iv)[i++] = (int)((long)(hh->Data())); |
---|
| 1462 | } |
---|
| 1463 | else if ((hh->Typ() == INTVEC_CMD) |
---|
| 1464 | ||(hh->Typ() == INTMAT_CMD)) |
---|
| 1465 | { |
---|
| 1466 | intvec *ivv = (intvec *)(hh->Data()); |
---|
| 1467 | int ll = 0,l = si_min(ivv->length(),iv->length()); |
---|
| 1468 | for (; l>0; l--) |
---|
| 1469 | { |
---|
| 1470 | (*iv)[i++] = (*ivv)[ll++]; |
---|
| 1471 | } |
---|
| 1472 | } |
---|
| 1473 | else |
---|
| 1474 | { |
---|
| 1475 | delete iv; |
---|
| 1476 | return TRUE; |
---|
| 1477 | } |
---|
| 1478 | hh = hh->next; |
---|
| 1479 | } |
---|
[e40145] | 1480 | if (l->rtyp==IDHDL) |
---|
| 1481 | { |
---|
| 1482 | if (IDINTVEC((idhdl)l->data)!=NULL) delete IDINTVEC((idhdl)l->data); |
---|
| 1483 | IDINTVEC((idhdl)l->data)=iv; |
---|
| 1484 | } |
---|
| 1485 | else |
---|
| 1486 | { |
---|
| 1487 | if (l->data!=NULL) delete ((intvec*)l->data); |
---|
| 1488 | l->data=(char*)iv; |
---|
| 1489 | } |
---|
[a53ae5] | 1490 | return FALSE; |
---|
| 1491 | } |
---|
[75f10d] | 1492 | static BOOLEAN jjA_L_BIGINTMAT(leftv l,leftv r,bigintmat *bim) |
---|
| 1493 | { |
---|
| 1494 | /* left side is bigintmat, right side is list (of int,intvec,intmat)*/ |
---|
| 1495 | leftv hh=r; |
---|
| 1496 | int i = 0; |
---|
[ebbb9c] | 1497 | if (bim->length()==0) { WerrorS("bigintmat is 1x0"); delete bim; return TRUE; } |
---|
[75f10d] | 1498 | while (hh!=NULL) |
---|
| 1499 | { |
---|
| 1500 | if (i>=bim->cols()*bim->rows()) |
---|
| 1501 | { |
---|
[a97ac0] | 1502 | if (traceit&TRACE_ASSIGN) |
---|
[75f10d] | 1503 | { |
---|
| 1504 | Warn("expression list length(%d) does not match bigintmat size(%d x %d)", |
---|
| 1505 | exprlist_length(hh),bim->rows(),bim->cols()); |
---|
| 1506 | } |
---|
| 1507 | break; |
---|
| 1508 | } |
---|
| 1509 | if (hh->Typ() == INT_CMD) |
---|
| 1510 | { |
---|
| 1511 | number tp = n_Init((int)((long)(hh->Data())), coeffs_BIGINT); |
---|
| 1512 | bim->set(i++, tp); |
---|
| 1513 | n_Delete(&tp, coeffs_BIGINT); |
---|
| 1514 | } |
---|
| 1515 | else if (hh->Typ() == BIGINT_CMD) |
---|
| 1516 | { |
---|
| 1517 | bim->set(i++, (number)(hh->Data())); |
---|
[ebbb9c] | 1518 | } |
---|
[75f10d] | 1519 | /* |
---|
| 1520 | ((hh->Typ() == INTVEC_CMD) |
---|
| 1521 | ||(hh->Typ() == INTMAT_CMD)) |
---|
| 1522 | { |
---|
| 1523 | intvec *ivv = (intvec *)(hh->Data()); |
---|
| 1524 | int ll = 0,l = si_min(ivv->length(),iv->length()); |
---|
| 1525 | for (; l>0; l--) |
---|
| 1526 | { |
---|
| 1527 | (*iv)[i++] = (*ivv)[ll++]; |
---|
| 1528 | } |
---|
| 1529 | }*/ |
---|
| 1530 | else |
---|
| 1531 | { |
---|
| 1532 | delete bim; |
---|
| 1533 | return TRUE; |
---|
| 1534 | } |
---|
| 1535 | hh = hh->next; |
---|
| 1536 | } |
---|
| 1537 | if (IDBIMAT((idhdl)l->data)!=NULL) delete IDBIMAT((idhdl)l->data); |
---|
| 1538 | IDBIMAT((idhdl)l->data)=bim; |
---|
| 1539 | return FALSE; |
---|
| 1540 | } |
---|
[a53ae5] | 1541 | static BOOLEAN jjA_L_STRING(leftv l,leftv r) |
---|
| 1542 | { |
---|
| 1543 | /* left side is string, right side is list of string*/ |
---|
| 1544 | leftv hh=r; |
---|
| 1545 | int sl = 1; |
---|
| 1546 | char *s; |
---|
| 1547 | char *t; |
---|
| 1548 | int tl; |
---|
| 1549 | /* find the length */ |
---|
| 1550 | while (hh!=NULL) |
---|
| 1551 | { |
---|
| 1552 | if (hh->Typ()!= STRING_CMD) |
---|
| 1553 | { |
---|
| 1554 | return TRUE; |
---|
| 1555 | } |
---|
| 1556 | sl += strlen((char *)hh->Data()); |
---|
| 1557 | hh = hh->next; |
---|
| 1558 | } |
---|
| 1559 | s = (char * )omAlloc(sl); |
---|
| 1560 | sl=0; |
---|
| 1561 | hh = r; |
---|
| 1562 | while (hh!=NULL) |
---|
| 1563 | { |
---|
| 1564 | t=(char *)hh->Data(); |
---|
| 1565 | tl=strlen(t); |
---|
| 1566 | memcpy(s+sl,t,tl); |
---|
| 1567 | sl+=tl; |
---|
| 1568 | hh = hh->next; |
---|
| 1569 | } |
---|
| 1570 | s[sl]='\0'; |
---|
| 1571 | omFree((ADDRESS)IDDATA((idhdl)(l->data))); |
---|
| 1572 | IDDATA((idhdl)(l->data))=s; |
---|
| 1573 | return FALSE; |
---|
| 1574 | } |
---|
| 1575 | static BOOLEAN jiA_MATRIX_L(leftv l,leftv r) |
---|
| 1576 | { |
---|
| 1577 | /* right side is matrix, left side is list (of poly)*/ |
---|
| 1578 | BOOLEAN nok=FALSE; |
---|
| 1579 | int i; |
---|
| 1580 | matrix m=(matrix)r->CopyD(MATRIX_CMD); |
---|
| 1581 | leftv h; |
---|
| 1582 | leftv ol=l; |
---|
| 1583 | leftv o_r=r; |
---|
| 1584 | sleftv t; |
---|
| 1585 | memset(&t,0,sizeof(sleftv)); |
---|
| 1586 | t.rtyp=POLY_CMD; |
---|
| 1587 | int mxn=MATROWS(m)*MATCOLS(m); |
---|
| 1588 | loop |
---|
| 1589 | { |
---|
| 1590 | i=0; |
---|
| 1591 | while ((i<mxn /*MATROWS(m)*MATCOLS(m)*/)&&(l!=NULL)) |
---|
| 1592 | { |
---|
| 1593 | t.data=(char *)m->m[i]; |
---|
| 1594 | m->m[i]=NULL; |
---|
| 1595 | h=l->next; |
---|
| 1596 | l->next=NULL; |
---|
[91c0af] | 1597 | idhdl hh=NULL; |
---|
| 1598 | if ((l->rtyp==IDHDL)&&(l->Typ()==DEF_CMD)) hh=(idhdl)l->data; |
---|
[4a74cc] | 1599 | nok=jiAssign_1(l,&t,TRUE); |
---|
[91c0af] | 1600 | if (hh!=NULL) { ipMoveId(hh);hh=NULL;} |
---|
[a53ae5] | 1601 | l->next=h; |
---|
| 1602 | if (nok) |
---|
| 1603 | { |
---|
| 1604 | idDelete((ideal *)&m); |
---|
| 1605 | goto ende; |
---|
| 1606 | } |
---|
| 1607 | i++; |
---|
| 1608 | l=h; |
---|
| 1609 | } |
---|
| 1610 | idDelete((ideal *)&m); |
---|
| 1611 | h=r; |
---|
| 1612 | r=r->next; |
---|
| 1613 | if (l==NULL) |
---|
| 1614 | { |
---|
| 1615 | if (r!=NULL) |
---|
| 1616 | { |
---|
| 1617 | Warn("list length mismatch in assign (l>r)"); |
---|
| 1618 | nok=TRUE; |
---|
| 1619 | } |
---|
| 1620 | break; |
---|
| 1621 | } |
---|
| 1622 | else if (r==NULL) |
---|
| 1623 | { |
---|
| 1624 | Warn("list length mismatch in assign (l<r)"); |
---|
| 1625 | nok=TRUE; |
---|
| 1626 | break; |
---|
| 1627 | } |
---|
| 1628 | if ((r->Typ()==IDEAL_CMD)||(r->Typ()==MATRIX_CMD)) |
---|
| 1629 | { |
---|
| 1630 | m=(matrix)r->CopyD(MATRIX_CMD); |
---|
| 1631 | mxn=MATROWS(m)*MATCOLS(m); |
---|
| 1632 | } |
---|
| 1633 | else if (r->Typ()==POLY_CMD) |
---|
| 1634 | { |
---|
| 1635 | m=mpNew(1,1); |
---|
| 1636 | MATELEM(m,1,1)=(poly)r->CopyD(POLY_CMD); |
---|
| 1637 | pNormalize(MATELEM(m,1,1)); |
---|
| 1638 | mxn=1; |
---|
| 1639 | } |
---|
| 1640 | else |
---|
| 1641 | { |
---|
| 1642 | nok=TRUE; |
---|
| 1643 | break; |
---|
| 1644 | } |
---|
| 1645 | } |
---|
| 1646 | ende: |
---|
| 1647 | o_r->CleanUp(); |
---|
| 1648 | ol->CleanUp(); |
---|
| 1649 | return nok; |
---|
| 1650 | } |
---|
| 1651 | static BOOLEAN jiA_STRING_L(leftv l,leftv r) |
---|
| 1652 | { |
---|
| 1653 | /*left side are strings, right side is a string*/ |
---|
| 1654 | /*e.g. s[2..3]="12" */ |
---|
| 1655 | /*the case s=t[1..4] is handled in iiAssign, |
---|
| 1656 | * the case s[2..3]=t[3..4] is handled in iiAssgn_rec*/ |
---|
| 1657 | BOOLEAN nok=FALSE; |
---|
| 1658 | sleftv t; |
---|
| 1659 | leftv h,l1=l; |
---|
| 1660 | int i=0; |
---|
| 1661 | char *ss; |
---|
| 1662 | char *s=(char *)r->Data(); |
---|
| 1663 | int sl=strlen(s); |
---|
| 1664 | |
---|
| 1665 | memset(&t,0,sizeof(sleftv)); |
---|
| 1666 | t.rtyp=STRING_CMD; |
---|
| 1667 | while ((i<sl)&&(l!=NULL)) |
---|
| 1668 | { |
---|
| 1669 | ss=(char *)omAlloc(2); |
---|
| 1670 | ss[1]='\0'; |
---|
| 1671 | ss[0]=s[i]; |
---|
| 1672 | t.data=ss; |
---|
| 1673 | h=l->next; |
---|
| 1674 | l->next=NULL; |
---|
[4a74cc] | 1675 | nok=jiAssign_1(l,&t,TRUE); |
---|
[a53ae5] | 1676 | if (nok) |
---|
| 1677 | { |
---|
| 1678 | break; |
---|
| 1679 | } |
---|
| 1680 | i++; |
---|
| 1681 | l=h; |
---|
| 1682 | } |
---|
| 1683 | r->CleanUp(); |
---|
| 1684 | l1->CleanUp(); |
---|
| 1685 | return nok; |
---|
| 1686 | } |
---|
| 1687 | static BOOLEAN jiAssign_list(leftv l, leftv r) |
---|
| 1688 | { |
---|
| 1689 | int i=l->e->start-1; |
---|
| 1690 | if (i<0) |
---|
| 1691 | { |
---|
| 1692 | Werror("index[%d] must be positive",i+1); |
---|
| 1693 | return TRUE; |
---|
| 1694 | } |
---|
| 1695 | if(l->attribute!=NULL) |
---|
| 1696 | { |
---|
| 1697 | atKillAll((idhdl)l); |
---|
| 1698 | l->attribute=NULL; |
---|
| 1699 | } |
---|
| 1700 | l->flag=0; |
---|
| 1701 | lists li; |
---|
| 1702 | if (l->rtyp==IDHDL) |
---|
| 1703 | { |
---|
| 1704 | li=IDLIST((idhdl)l->data); |
---|
| 1705 | } |
---|
| 1706 | else |
---|
| 1707 | { |
---|
| 1708 | li=(lists)l->data; |
---|
| 1709 | } |
---|
| 1710 | if (i>li->nr) |
---|
| 1711 | { |
---|
[0d0313] | 1712 | if (TEST_V_ALLWARN) |
---|
| 1713 | { |
---|
| 1714 | Warn("increase list %d -> %d in %s",li->nr,i,my_yylinebuf); |
---|
| 1715 | } |
---|
[a53ae5] | 1716 | li->m=(leftv)omreallocSize(li->m,(li->nr+1)*sizeof(sleftv),(i+1)*sizeof(sleftv)); |
---|
| 1717 | memset(&(li->m[li->nr+1]),0,(i-li->nr)*sizeof(sleftv)); |
---|
| 1718 | int j=li->nr+1; |
---|
| 1719 | for(;j<=i;j++) |
---|
| 1720 | li->m[j].rtyp=DEF_CMD; |
---|
| 1721 | li->nr=i; |
---|
| 1722 | } |
---|
| 1723 | leftv ld=&(li->m[i]); |
---|
| 1724 | ld->e=l->e->next; |
---|
| 1725 | BOOLEAN b; |
---|
| 1726 | if (/*(ld->rtyp!=LIST_CMD) |
---|
| 1727 | &&*/(ld->e==NULL) |
---|
[e40145] | 1728 | && (ld->Typ()!=r->Typ())) |
---|
[a53ae5] | 1729 | { |
---|
| 1730 | sleftv tmp; |
---|
| 1731 | memset(&tmp,0,sizeof(sleftv)); |
---|
| 1732 | tmp.rtyp=DEF_CMD; |
---|
[4a74cc] | 1733 | b=iiAssign(&tmp,r,FALSE); |
---|
[a53ae5] | 1734 | ld->CleanUp(); |
---|
| 1735 | memcpy(ld,&tmp,sizeof(sleftv)); |
---|
| 1736 | } |
---|
[e40145] | 1737 | else if ((ld->e==NULL) |
---|
| 1738 | && (ld->Typ()==r->Typ()) |
---|
| 1739 | && (ld->Typ()<MAX_TOK)) |
---|
| 1740 | { |
---|
| 1741 | sleftv tmp; |
---|
| 1742 | memset(&tmp,0,sizeof(sleftv)); |
---|
| 1743 | tmp.rtyp=r->Typ(); |
---|
| 1744 | tmp.data=(char*)idrecDataInit(r->Typ()); |
---|
[4a74cc] | 1745 | b=iiAssign(&tmp,r,FALSE); |
---|
[e40145] | 1746 | ld->CleanUp(); |
---|
| 1747 | memcpy(ld,&tmp,sizeof(sleftv)); |
---|
| 1748 | } |
---|
[a53ae5] | 1749 | else |
---|
| 1750 | { |
---|
[4a74cc] | 1751 | b=iiAssign(ld,r,FALSE); |
---|
[a53ae5] | 1752 | if (l->e!=NULL) l->e->next=ld->e; |
---|
| 1753 | ld->e=NULL; |
---|
| 1754 | } |
---|
| 1755 | return b; |
---|
| 1756 | } |
---|
| 1757 | static BOOLEAN jiAssign_rec(leftv l, leftv r) |
---|
| 1758 | { |
---|
| 1759 | leftv l1=l; |
---|
| 1760 | leftv r1=r; |
---|
| 1761 | leftv lrest; |
---|
| 1762 | leftv rrest; |
---|
| 1763 | BOOLEAN b; |
---|
| 1764 | do |
---|
| 1765 | { |
---|
| 1766 | lrest=l->next; |
---|
| 1767 | rrest=r->next; |
---|
| 1768 | l->next=NULL; |
---|
| 1769 | r->next=NULL; |
---|
| 1770 | b=iiAssign(l,r); |
---|
| 1771 | l->next=lrest; |
---|
| 1772 | r->next=rrest; |
---|
| 1773 | l=lrest; |
---|
| 1774 | r=rrest; |
---|
| 1775 | } while ((!b)&&(l!=NULL)); |
---|
| 1776 | l1->CleanUp(); |
---|
| 1777 | r1->CleanUp(); |
---|
| 1778 | return b; |
---|
| 1779 | } |
---|
[4a74cc] | 1780 | BOOLEAN iiAssign(leftv l, leftv r, BOOLEAN toplevel) |
---|
[a53ae5] | 1781 | { |
---|
| 1782 | if (errorreported) return TRUE; |
---|
| 1783 | int ll=l->listLength(); |
---|
| 1784 | int rl; |
---|
| 1785 | int lt=l->Typ(); |
---|
| 1786 | int rt=NONE; |
---|
| 1787 | BOOLEAN b; |
---|
| 1788 | if (l->rtyp==ALIAS_CMD) |
---|
| 1789 | { |
---|
| 1790 | Werror("`%s` is read-only",l->Name()); |
---|
| 1791 | } |
---|
| 1792 | |
---|
[6c22988] | 1793 | if (l->rtyp==IDHDL) |
---|
[a53ae5] | 1794 | { |
---|
[6c22988] | 1795 | atKillAll((idhdl)l->data); |
---|
[a53ae5] | 1796 | IDFLAG((idhdl)l->data)=0; |
---|
[6c22988] | 1797 | l->attribute=NULL; |
---|
[4a74cc] | 1798 | toplevel=FALSE; |
---|
[a53ae5] | 1799 | } |
---|
[6c22988] | 1800 | else if (l->attribute!=NULL) |
---|
| 1801 | atKillAll((idhdl)l); |
---|
[a53ae5] | 1802 | l->flag=0; |
---|
| 1803 | if (ll==1) |
---|
| 1804 | { |
---|
| 1805 | /* l[..] = ... */ |
---|
[8db6c3] | 1806 | if(l->e!=NULL) |
---|
[a53ae5] | 1807 | { |
---|
[8db6c3] | 1808 | BOOLEAN like_lists=0; |
---|
| 1809 | blackbox *bb=NULL; |
---|
| 1810 | int bt; |
---|
| 1811 | if (((bt=l->rtyp)>MAX_TOK) |
---|
| 1812 | || ((l->rtyp==IDHDL) && ((bt=IDTYP((idhdl)l->data))>MAX_TOK))) |
---|
| 1813 | { |
---|
| 1814 | bb=getBlackboxStuff(bt); |
---|
[8357e21] | 1815 | like_lists=BB_LIKE_LIST(bb); // bb like a list |
---|
[8db6c3] | 1816 | } |
---|
| 1817 | else if (((l->rtyp==IDHDL) && (IDTYP((idhdl)l->data)==LIST_CMD)) |
---|
| 1818 | || (l->rtyp==LIST_CMD)) |
---|
| 1819 | { |
---|
[8357e21] | 1820 | like_lists=2; // bb in a list |
---|
[8db6c3] | 1821 | } |
---|
| 1822 | if(like_lists) |
---|
| 1823 | { |
---|
[88615db] | 1824 | if (traceit&TRACE_ASSIGN) PrintS("assign list[..]=...or similar\n"); |
---|
[8357e21] | 1825 | if (like_lists==1) |
---|
| 1826 | { |
---|
| 1827 | // check blackbox/newtype type: |
---|
| 1828 | if(bb->blackbox_CheckAssign(bb,l,r)) return TRUE; |
---|
| 1829 | } |
---|
[8db6c3] | 1830 | b=jiAssign_list(l,r); |
---|
| 1831 | if((!b) && (like_lists==2)) |
---|
| 1832 | { |
---|
| 1833 | //Print("jjA_L_LIST: - 2 \n"); |
---|
| 1834 | if((l->rtyp==IDHDL) && (l->data!=NULL)) |
---|
| 1835 | { |
---|
| 1836 | ipMoveId((idhdl)l->data); |
---|
| 1837 | l->attribute=IDATTR((idhdl)l->data); |
---|
| 1838 | l->flag=IDFLAG((idhdl)l->data); |
---|
| 1839 | } |
---|
| 1840 | } |
---|
| 1841 | r->CleanUp(); |
---|
| 1842 | Subexpr h; |
---|
| 1843 | while (l->e!=NULL) |
---|
| 1844 | { |
---|
| 1845 | h=l->e->next; |
---|
| 1846 | omFreeBin((ADDRESS)l->e, sSubexpr_bin); |
---|
| 1847 | l->e=h; |
---|
| 1848 | } |
---|
| 1849 | return b; |
---|
| 1850 | } |
---|
[a53ae5] | 1851 | } |
---|
[4a4593a] | 1852 | if (lt>MAX_TOK) |
---|
| 1853 | { |
---|
| 1854 | blackbox *bb=getBlackboxStuff(lt); |
---|
| 1855 | #ifdef BLACKBOX_DEVEL |
---|
| 1856 | Print("bb-assign: bb=%lx\n",bb); |
---|
| 1857 | #endif |
---|
| 1858 | return (bb==NULL) || bb->blackbox_Assign(l,r); |
---|
| 1859 | } |
---|
[88615db] | 1860 | // end of handling elems of list and similar |
---|
[a53ae5] | 1861 | rl=r->listLength(); |
---|
| 1862 | if (rl==1) |
---|
[fc8d35] | 1863 | { |
---|
[a53ae5] | 1864 | /* system variables = ... */ |
---|
| 1865 | if(((l->rtyp>=VECHO)&&(l->rtyp<=VPRINTLEVEL)) |
---|
| 1866 | ||((l->rtyp>=VALTVARS)&&(l->rtyp<=VMINPOLY))) |
---|
| 1867 | { |
---|
| 1868 | b=iiAssign_sys(l,r); |
---|
| 1869 | r->CleanUp(); |
---|
| 1870 | //l->CleanUp(); |
---|
| 1871 | return b; |
---|
| 1872 | } |
---|
| 1873 | rt=r->Typ(); |
---|
| 1874 | /* a = ... */ |
---|
| 1875 | if ((lt!=MATRIX_CMD) |
---|
[de8505] | 1876 | &&(lt!=BIGINTMAT_CMD) |
---|
| 1877 | &&(lt!=CMATRIX_CMD) |
---|
[a53ae5] | 1878 | &&(lt!=INTMAT_CMD) |
---|
| 1879 | &&((lt==rt)||(lt!=LIST_CMD))) |
---|
| 1880 | { |
---|
[4a74cc] | 1881 | b=jiAssign_1(l,r,toplevel); |
---|
[a53ae5] | 1882 | if (l->rtyp==IDHDL) |
---|
| 1883 | { |
---|
| 1884 | if ((lt==DEF_CMD)||(lt==LIST_CMD)) |
---|
| 1885 | { |
---|
| 1886 | ipMoveId((idhdl)l->data); |
---|
| 1887 | } |
---|
| 1888 | l->attribute=IDATTR((idhdl)l->data); |
---|
| 1889 | l->flag=IDFLAG((idhdl)l->data); |
---|
| 1890 | l->CleanUp(); |
---|
| 1891 | } |
---|
| 1892 | r->CleanUp(); |
---|
| 1893 | return b; |
---|
| 1894 | } |
---|
| 1895 | if (((lt!=LIST_CMD) |
---|
| 1896 | &&((rt==MATRIX_CMD) |
---|
[97181f8] | 1897 | ||(rt==BIGINTMAT_CMD) |
---|
| 1898 | ||(rt==CMATRIX_CMD) |
---|
[a53ae5] | 1899 | ||(rt==INTMAT_CMD) |
---|
| 1900 | ||(rt==INTVEC_CMD) |
---|
| 1901 | ||(rt==MODUL_CMD))) |
---|
| 1902 | ||((lt==LIST_CMD) |
---|
| 1903 | &&(rt==RESOLUTION_CMD)) |
---|
| 1904 | ) |
---|
| 1905 | { |
---|
[4a74cc] | 1906 | b=jiAssign_1(l,r,toplevel); |
---|
[a53ae5] | 1907 | if((l->rtyp==IDHDL)&&(l->data!=NULL)) |
---|
| 1908 | { |
---|
| 1909 | if ((lt==DEF_CMD) || (lt==LIST_CMD)) |
---|
| 1910 | { |
---|
| 1911 | //Print("ipAssign - 3.0\n"); |
---|
| 1912 | ipMoveId((idhdl)l->data); |
---|
| 1913 | } |
---|
| 1914 | l->attribute=IDATTR((idhdl)l->data); |
---|
| 1915 | l->flag=IDFLAG((idhdl)l->data); |
---|
| 1916 | } |
---|
| 1917 | r->CleanUp(); |
---|
| 1918 | Subexpr h; |
---|
| 1919 | while (l->e!=NULL) |
---|
| 1920 | { |
---|
| 1921 | h=l->e->next; |
---|
| 1922 | omFreeBin((ADDRESS)l->e, sSubexpr_bin); |
---|
| 1923 | l->e=h; |
---|
| 1924 | } |
---|
| 1925 | return b; |
---|
| 1926 | } |
---|
| 1927 | } |
---|
| 1928 | if (rt==NONE) rt=r->Typ(); |
---|
| 1929 | } |
---|
| 1930 | else if (ll==(rl=r->listLength())) |
---|
| 1931 | { |
---|
| 1932 | b=jiAssign_rec(l,r); |
---|
| 1933 | return b; |
---|
| 1934 | } |
---|
| 1935 | else |
---|
| 1936 | { |
---|
| 1937 | if (rt==NONE) rt=r->Typ(); |
---|
| 1938 | if (rt==INTVEC_CMD) |
---|
| 1939 | return jiA_INTVEC_L(l,r); |
---|
| 1940 | else if (rt==VECTOR_CMD) |
---|
| 1941 | return jiA_VECTOR_L(l,r); |
---|
| 1942 | else if ((rt==IDEAL_CMD)||(rt==MATRIX_CMD)) |
---|
| 1943 | return jiA_MATRIX_L(l,r); |
---|
| 1944 | else if ((rt==STRING_CMD)&&(rl==1)) |
---|
| 1945 | return jiA_STRING_L(l,r); |
---|
| 1946 | Werror("length of lists in assignment does not match (l:%d,r:%d)", |
---|
| 1947 | ll,rl); |
---|
| 1948 | return TRUE; |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | leftv hh=r; |
---|
| 1952 | BOOLEAN nok=FALSE; |
---|
| 1953 | BOOLEAN map_assign=FALSE; |
---|
| 1954 | switch (lt) |
---|
| 1955 | { |
---|
| 1956 | case INTVEC_CMD: |
---|
| 1957 | nok=jjA_L_INTVEC(l,r,new intvec(exprlist_length(r))); |
---|
| 1958 | break; |
---|
| 1959 | case INTMAT_CMD: |
---|
| 1960 | { |
---|
| 1961 | nok=jjA_L_INTVEC(l,r,new intvec(IDINTVEC((idhdl)l->data))); |
---|
| 1962 | break; |
---|
| 1963 | } |
---|
[75f10d] | 1964 | case BIGINTMAT_CMD: |
---|
| 1965 | { |
---|
| 1966 | nok=jjA_L_BIGINTMAT(l, r, new bigintmat(IDBIMAT((idhdl)l->data))); |
---|
| 1967 | break; |
---|
| 1968 | } |
---|
[a53ae5] | 1969 | case MAP_CMD: |
---|
| 1970 | { |
---|
| 1971 | // first element in the list sl (r) must be a ring |
---|
[d2fc5c5] | 1972 | if ((rt == RING_CMD)&&(r->e==NULL)) |
---|
[a53ae5] | 1973 | { |
---|
| 1974 | omFree((ADDRESS)IDMAP((idhdl)l->data)->preimage); |
---|
| 1975 | IDMAP((idhdl)l->data)->preimage = omStrDup (r->Fullname()); |
---|
| 1976 | /* advance the expressionlist to get the next element after the ring */ |
---|
| 1977 | hh = r->next; |
---|
| 1978 | //r=hh; |
---|
| 1979 | } |
---|
| 1980 | else |
---|
| 1981 | { |
---|
| 1982 | WerrorS("expected ring-name"); |
---|
| 1983 | nok=TRUE; |
---|
| 1984 | break; |
---|
| 1985 | } |
---|
| 1986 | if (hh==NULL) /* map-assign: map f=r; */ |
---|
| 1987 | { |
---|
| 1988 | WerrorS("expected image ideal"); |
---|
| 1989 | nok=TRUE; |
---|
| 1990 | break; |
---|
| 1991 | } |
---|
| 1992 | if ((hh->next==NULL)&&(hh->Typ()==IDEAL_CMD)) |
---|
[4a74cc] | 1993 | return jiAssign_1(l,hh,toplevel); /* map-assign: map f=r,i; */ |
---|
[a53ae5] | 1994 | //no break, handle the rest like an ideal: |
---|
| 1995 | map_assign=TRUE; |
---|
| 1996 | } |
---|
| 1997 | case MATRIX_CMD: |
---|
| 1998 | case IDEAL_CMD: |
---|
| 1999 | case MODUL_CMD: |
---|
| 2000 | { |
---|
| 2001 | sleftv t; |
---|
| 2002 | matrix olm = (matrix)l->Data(); |
---|
[49c9a13] | 2003 | int rk; |
---|
[a53ae5] | 2004 | char *pr=((map)olm)->preimage; |
---|
| 2005 | BOOLEAN module_assign=(/*l->Typ()*/ lt==MODUL_CMD); |
---|
| 2006 | matrix lm ; |
---|
| 2007 | int num; |
---|
| 2008 | int j,k; |
---|
| 2009 | int i=0; |
---|
| 2010 | int mtyp=MATRIX_CMD; /*Type of left side object*/ |
---|
| 2011 | int etyp=POLY_CMD; /*Type of elements of left side object*/ |
---|
| 2012 | |
---|
| 2013 | if (lt /*l->Typ()*/==MATRIX_CMD) |
---|
| 2014 | { |
---|
[49c9a13] | 2015 | rk=olm->rows(); |
---|
| 2016 | num=olm->cols()*rk /*olm->rows()*/; |
---|
[a53ae5] | 2017 | lm=mpNew(olm->rows(),olm->cols()); |
---|
[fc8d35] | 2018 | int el; |
---|
[a97ac0] | 2019 | if ((traceit&TRACE_ASSIGN) && (num!=(el=exprlist_length(hh)))) |
---|
[fc8d35] | 2020 | { |
---|
| 2021 | Warn("expression list length(%d) does not match matrix size(%d)",el,num); |
---|
| 2022 | } |
---|
[a53ae5] | 2023 | } |
---|
| 2024 | else /* IDEAL_CMD or MODUL_CMD */ |
---|
| 2025 | { |
---|
| 2026 | num=exprlist_length(hh); |
---|
| 2027 | lm=(matrix)idInit(num,1); |
---|
| 2028 | if (module_assign) |
---|
| 2029 | { |
---|
[70be3a] | 2030 | rk=0; |
---|
[a53ae5] | 2031 | mtyp=MODUL_CMD; |
---|
| 2032 | etyp=VECTOR_CMD; |
---|
| 2033 | } |
---|
[70be3a] | 2034 | else |
---|
| 2035 | rk=1; |
---|
[a53ae5] | 2036 | } |
---|
| 2037 | |
---|
| 2038 | int ht; |
---|
| 2039 | loop |
---|
| 2040 | { |
---|
| 2041 | if (hh==NULL) |
---|
| 2042 | break; |
---|
| 2043 | else |
---|
| 2044 | { |
---|
| 2045 | matrix rm; |
---|
| 2046 | ht=hh->Typ(); |
---|
| 2047 | if ((j=iiTestConvert(ht,etyp))!=0) |
---|
| 2048 | { |
---|
| 2049 | nok=iiConvert(ht,etyp,j,hh,&t); |
---|
| 2050 | hh->next=t.next; |
---|
| 2051 | if (nok) break; |
---|
| 2052 | lm->m[i]=(poly)t.CopyD(etyp); |
---|
| 2053 | pNormalize(lm->m[i]); |
---|
| 2054 | if (module_assign) rk=si_max(rk,(int)pMaxComp(lm->m[i])); |
---|
| 2055 | i++; |
---|
| 2056 | } |
---|
| 2057 | else |
---|
| 2058 | if ((j=iiTestConvert(ht,mtyp))!=0) |
---|
| 2059 | { |
---|
| 2060 | nok=iiConvert(ht,mtyp,j,hh,&t); |
---|
| 2061 | hh->next=t.next; |
---|
| 2062 | if (nok) break; |
---|
| 2063 | rm = (matrix)t.CopyD(mtyp); |
---|
| 2064 | if (module_assign) |
---|
| 2065 | { |
---|
| 2066 | j = si_min(num,rm->cols()); |
---|
| 2067 | rk=si_max(rk,(int)rm->rank); |
---|
| 2068 | } |
---|
| 2069 | else |
---|
| 2070 | j = si_min(num-i,rm->rows() * rm->cols()); |
---|
| 2071 | for(k=0;k<j;k++,i++) |
---|
| 2072 | { |
---|
| 2073 | lm->m[i]=rm->m[k]; |
---|
| 2074 | pNormalize(lm->m[i]); |
---|
| 2075 | rm->m[k]=NULL; |
---|
| 2076 | } |
---|
| 2077 | idDelete((ideal *)&rm); |
---|
| 2078 | } |
---|
| 2079 | else |
---|
| 2080 | { |
---|
| 2081 | nok=TRUE; |
---|
| 2082 | break; |
---|
| 2083 | } |
---|
| 2084 | t.next=NULL;t.CleanUp(); |
---|
| 2085 | if (i==num) break; |
---|
| 2086 | hh=hh->next; |
---|
| 2087 | } |
---|
| 2088 | } |
---|
| 2089 | if (nok) |
---|
| 2090 | idDelete((ideal *)&lm); |
---|
| 2091 | else |
---|
| 2092 | { |
---|
| 2093 | idDelete((ideal *)&olm); |
---|
| 2094 | if (module_assign) lm->rank=rk; |
---|
| 2095 | else if (map_assign) ((map)lm)->preimage=pr; |
---|
| 2096 | l=l->LData(); |
---|
| 2097 | if (l->rtyp==IDHDL) |
---|
| 2098 | IDMATRIX((idhdl)l->data)=lm; |
---|
| 2099 | else |
---|
| 2100 | l->data=(char *)lm; |
---|
| 2101 | } |
---|
| 2102 | break; |
---|
| 2103 | } |
---|
| 2104 | case STRING_CMD: |
---|
| 2105 | nok=jjA_L_STRING(l,r); |
---|
| 2106 | break; |
---|
[ef99cd] | 2107 | //case DEF_CMD: |
---|
[a53ae5] | 2108 | case LIST_CMD: |
---|
| 2109 | nok=jjA_L_LIST(l,r); |
---|
| 2110 | break; |
---|
| 2111 | case NONE: |
---|
| 2112 | case 0: |
---|
| 2113 | Werror("cannot assign to %s",l->Fullname()); |
---|
| 2114 | nok=TRUE; |
---|
| 2115 | break; |
---|
| 2116 | default: |
---|
| 2117 | WerrorS("assign not impl."); |
---|
| 2118 | nok=TRUE; |
---|
| 2119 | break; |
---|
| 2120 | } /* end switch: typ */ |
---|
| 2121 | if (nok && (!errorreported)) WerrorS("incompatible type in list assignment"); |
---|
| 2122 | r->CleanUp(); |
---|
| 2123 | return nok; |
---|
| 2124 | } |
---|
| 2125 | void jjNormalizeQRingId(leftv I) |
---|
| 2126 | { |
---|
[ac00e2f] | 2127 | if ((currRing->qideal!=NULL) && (!hasFlag(I,FLAG_QRING))) |
---|
[a53ae5] | 2128 | { |
---|
| 2129 | if (I->e==NULL) |
---|
| 2130 | { |
---|
| 2131 | ideal I0=(ideal)I->Data(); |
---|
[3e7095] | 2132 | switch (I->Typ()) |
---|
[a53ae5] | 2133 | { |
---|
[3e7095] | 2134 | case IDEAL_CMD: |
---|
[52d480] | 2135 | case MODUL_CMD: |
---|
[3e7095] | 2136 | { |
---|
| 2137 | ideal F=idInit(1,1); |
---|
[ac00e2f] | 2138 | ideal II=kNF(F,currRing->qideal,I0); |
---|
[3e7095] | 2139 | idDelete(&F); |
---|
| 2140 | if (I->rtyp!=IDHDL) |
---|
| 2141 | { |
---|
| 2142 | idDelete((ideal*)&(I0)); |
---|
| 2143 | I->data=II; |
---|
| 2144 | } |
---|
| 2145 | else |
---|
| 2146 | { |
---|
| 2147 | idhdl h=(idhdl)I->data; |
---|
| 2148 | idDelete((ideal*)&IDIDEAL(h)); |
---|
| 2149 | IDIDEAL(h)=II; |
---|
| 2150 | setFlag(h,FLAG_QRING); |
---|
| 2151 | } |
---|
| 2152 | break; |
---|
| 2153 | } |
---|
| 2154 | default: break; |
---|
[a53ae5] | 2155 | } |
---|
| 2156 | setFlag(I,FLAG_QRING); |
---|
| 2157 | } |
---|
| 2158 | } |
---|
| 2159 | } |
---|
[75214e] | 2160 | void jjNormalizeQRingP(poly &p) |
---|
[a53ae5] | 2161 | { |
---|
[75214e] | 2162 | if((p!=NULL) && (currRing->qideal!=NULL)) |
---|
| 2163 | { |
---|
| 2164 | ideal F=idInit(1,1); |
---|
| 2165 | poly p2=kNF(F,currRing->qideal,p); |
---|
| 2166 | pNormalize(p2); |
---|
| 2167 | idDelete(&F); |
---|
| 2168 | pDelete(&p); |
---|
| 2169 | p=p2; |
---|
[a53ae5] | 2170 | } |
---|
| 2171 | } |
---|
[d30a399] | 2172 | BOOLEAN jjIMPORTFROM(leftv, leftv u, leftv v) |
---|
[a53ae5] | 2173 | { |
---|
| 2174 | //Print("importfrom %s::%s ->.\n",v->Name(),u->Name() ); |
---|
| 2175 | assume(u->Typ()==PACKAGE_CMD); |
---|
| 2176 | char *vn=(char *)v->Name(); |
---|
| 2177 | idhdl h=((package)(u->Data()))->idroot->get(vn /*v->Name()*/, myynest); |
---|
| 2178 | if (h!=NULL) |
---|
| 2179 | { |
---|
| 2180 | //check for existence |
---|
| 2181 | if (((package)(u->Data()))==basePack) |
---|
| 2182 | { |
---|
| 2183 | WarnS("source and destination packages are identical"); |
---|
| 2184 | return FALSE; |
---|
| 2185 | } |
---|
| 2186 | idhdl t=basePack->idroot->get(vn /*v->Name()*/, myynest); |
---|
| 2187 | if (t!=NULL) |
---|
| 2188 | { |
---|
[586e00] | 2189 | Warn("redefining %s (%s)",vn,my_yylinebuf); |
---|
[a53ae5] | 2190 | killhdl(t); |
---|
| 2191 | } |
---|
| 2192 | sleftv tmp_expr; |
---|
| 2193 | if (iiDeclCommand(&tmp_expr,v,myynest,DEF_CMD,&IDROOT)) return TRUE; |
---|
| 2194 | sleftv h_expr; |
---|
| 2195 | memset(&h_expr,0,sizeof(h_expr)); |
---|
| 2196 | h_expr.rtyp=IDHDL; |
---|
| 2197 | h_expr.data=h; |
---|
| 2198 | h_expr.name=vn; |
---|
| 2199 | return iiAssign(&tmp_expr,&h_expr); |
---|
| 2200 | } |
---|
| 2201 | else |
---|
| 2202 | { |
---|
| 2203 | Werror("`%s` not found in `%s`",v->Name(), u->Name()); |
---|
| 2204 | return TRUE; |
---|
| 2205 | } |
---|
| 2206 | return FALSE; |
---|
| 2207 | } |
---|