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