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