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