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