1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | /* |
---|
6 | * ABSTRACT: table driven kernel interface, used by interpreter |
---|
7 | */ |
---|
8 | //long all_farey=0L; |
---|
9 | //long farey_cnt=0L; |
---|
10 | |
---|
11 | #include "kernel/mod2.h" |
---|
12 | |
---|
13 | #include "factory/factory.h" |
---|
14 | |
---|
15 | #include "coeffs/bigintmat.h" |
---|
16 | #include "coeffs/coeffs.h" |
---|
17 | #include "coeffs/numbers.h" |
---|
18 | |
---|
19 | #include "misc/options.h" |
---|
20 | #include "misc/intvec.h" |
---|
21 | #include "misc/sirandom.h" |
---|
22 | #include "misc/prime.h" |
---|
23 | |
---|
24 | #include "polys/matpol.h" |
---|
25 | #include "polys/monomials/maps.h" |
---|
26 | #include "polys/sparsmat.h" |
---|
27 | #include "polys/weight.h" |
---|
28 | #include "polys/ext_fields/transext.h" |
---|
29 | #include "polys/clapsing.h" |
---|
30 | |
---|
31 | #include "kernel/combinatorics/stairc.h" |
---|
32 | #include "kernel/combinatorics/hilb.h" |
---|
33 | |
---|
34 | #include "kernel/linear_algebra/interpolation.h" |
---|
35 | #include "kernel/linear_algebra/linearAlgebra.h" |
---|
36 | #include "kernel/linear_algebra/MinorInterface.h" |
---|
37 | |
---|
38 | #include "kernel/spectrum/GMPrat.h" |
---|
39 | #include "kernel/groebner_walk/walkProc.h" |
---|
40 | #include "kernel/oswrapper/timer.h" |
---|
41 | #include "kernel/fglm/fglm.h" |
---|
42 | |
---|
43 | #include "kernel/GBEngine/kstdfac.h" |
---|
44 | #include "kernel/GBEngine/syz.h" |
---|
45 | #include "kernel/GBEngine/kstd1.h" |
---|
46 | #include "kernel/GBEngine/units.h" |
---|
47 | #include "kernel/GBEngine/tgb.h" |
---|
48 | |
---|
49 | #include "kernel/preimage.h" |
---|
50 | #include "kernel/polys.h" |
---|
51 | #include "kernel/ideals.h" |
---|
52 | |
---|
53 | #include "Singular/mod_lib.h" |
---|
54 | #include "Singular/fevoices.h" |
---|
55 | #include "Singular/tok.h" |
---|
56 | #include "Singular/ipid.h" |
---|
57 | #include "Singular/sdb.h" |
---|
58 | #include "Singular/subexpr.h" |
---|
59 | #include "Singular/lists.h" |
---|
60 | #include "Singular/maps_ip.h" |
---|
61 | |
---|
62 | #include "Singular/ipconv.h" |
---|
63 | #include "Singular/ipprint.h" |
---|
64 | #include "Singular/attrib.h" |
---|
65 | #include "Singular/links/silink.h" |
---|
66 | #include "Singular/misc_ip.h" |
---|
67 | #include "Singular/linearAlgebra_ip.h" |
---|
68 | |
---|
69 | #include "Singular/number2.h" |
---|
70 | |
---|
71 | #include "Singular/fglm.h" |
---|
72 | |
---|
73 | #include "Singular/blackbox.h" |
---|
74 | #include "Singular/newstruct.h" |
---|
75 | #include "Singular/ipshell.h" |
---|
76 | //#include "kernel/mpr_inout.h" |
---|
77 | #include "reporter/si_signals.h" |
---|
78 | |
---|
79 | #include <ctype.h> |
---|
80 | |
---|
81 | // defaults for all commands: NO_NC | NO_RING | ALLOW_ZERODIVISOR |
---|
82 | |
---|
83 | #ifdef HAVE_PLURAL |
---|
84 | #include "kernel/GBEngine/ratgring.h" |
---|
85 | #include "kernel/GBEngine/nc.h" |
---|
86 | #include "polys/nc/nc.h" |
---|
87 | #include "polys/nc/sca.h" |
---|
88 | #define NC_MASK (3+64) |
---|
89 | #else /* HAVE_PLURAL */ |
---|
90 | #define NC_MASK 0 |
---|
91 | #endif /* HAVE_PLURAL */ |
---|
92 | |
---|
93 | #ifdef HAVE_RINGS |
---|
94 | #define RING_MASK 4 |
---|
95 | #define ZERODIVISOR_MASK 8 |
---|
96 | #else |
---|
97 | #define RING_MASK 0 |
---|
98 | #define ZERODIVISOR_MASK 0 |
---|
99 | #endif |
---|
100 | #define ALLOW_PLURAL 1 |
---|
101 | #define NO_NC 0 |
---|
102 | #define COMM_PLURAL 2 |
---|
103 | #define ALLOW_RING 4 |
---|
104 | #define NO_RING 0 |
---|
105 | #define NO_ZERODIVISOR 8 |
---|
106 | #define ALLOW_ZERODIVISOR 0 |
---|
107 | #define ALLOW_LP 64 |
---|
108 | #define ALLOW_NC ALLOW_LP|ALLOW_PLURAL |
---|
109 | |
---|
110 | #define ALLOW_ZZ (ALLOW_RING|NO_ZERODIVISOR) |
---|
111 | |
---|
112 | |
---|
113 | // bit 4 for warning, if used at toplevel |
---|
114 | #define WARN_RING 16 |
---|
115 | // bit 5: do no try automatic conversions |
---|
116 | #define NO_CONVERSION 32 |
---|
117 | |
---|
118 | static BOOLEAN check_valid(const int p, const int op); |
---|
119 | |
---|
120 | /*=============== types =====================*/ |
---|
121 | struct sValCmdTab |
---|
122 | { |
---|
123 | short cmd; |
---|
124 | short start; |
---|
125 | }; |
---|
126 | |
---|
127 | typedef sValCmdTab jjValCmdTab[]; |
---|
128 | |
---|
129 | struct _scmdnames |
---|
130 | { |
---|
131 | char *name; |
---|
132 | short alias; |
---|
133 | short tokval; |
---|
134 | short toktype; |
---|
135 | }; |
---|
136 | typedef struct _scmdnames cmdnames; |
---|
137 | |
---|
138 | struct sValCmd1 |
---|
139 | { |
---|
140 | proc1 p; |
---|
141 | short cmd; |
---|
142 | short res; |
---|
143 | short arg; |
---|
144 | short valid_for; |
---|
145 | }; |
---|
146 | |
---|
147 | typedef BOOLEAN (*proc2)(leftv,leftv,leftv); |
---|
148 | struct sValCmd2 |
---|
149 | { |
---|
150 | proc2 p; |
---|
151 | short cmd; |
---|
152 | short res; |
---|
153 | short arg1; |
---|
154 | short arg2; |
---|
155 | short valid_for; |
---|
156 | }; |
---|
157 | |
---|
158 | typedef BOOLEAN (*proc3)(leftv,leftv,leftv,leftv); |
---|
159 | struct sValCmd3 |
---|
160 | { |
---|
161 | proc3 p; |
---|
162 | short cmd; |
---|
163 | short res; |
---|
164 | short arg1; |
---|
165 | short arg2; |
---|
166 | short arg3; |
---|
167 | short valid_for; |
---|
168 | }; |
---|
169 | struct sValCmdM |
---|
170 | { |
---|
171 | proc1 p; |
---|
172 | short cmd; |
---|
173 | short res; |
---|
174 | short number_of_args; /* -1: any, -2: any >0, .. */ |
---|
175 | short valid_for; |
---|
176 | }; |
---|
177 | |
---|
178 | typedef struct |
---|
179 | { |
---|
180 | cmdnames *sCmds; /**< array of existing commands */ |
---|
181 | struct sValCmd1 *psValCmd1; |
---|
182 | struct sValCmd2 *psValCmd2; |
---|
183 | struct sValCmd3 *psValCmd3; |
---|
184 | struct sValCmdM *psValCmdM; |
---|
185 | unsigned nCmdUsed; /**< number of commands used */ |
---|
186 | unsigned nCmdAllocated; /**< number of commands-slots allocated */ |
---|
187 | unsigned nLastIdentifier; /**< valid indentifieres are slot 1..nLastIdentifier */ |
---|
188 | } SArithBase; |
---|
189 | |
---|
190 | /*---------------------------------------------------------------------* |
---|
191 | * File scope Variables (Variables share by several functions in |
---|
192 | * the same file ) |
---|
193 | * |
---|
194 | *---------------------------------------------------------------------*/ |
---|
195 | STATIC_VAR SArithBase sArithBase; /**< Base entry for arithmetic */ |
---|
196 | |
---|
197 | /*---------------------------------------------------------------------* |
---|
198 | * Extern Functions declarations |
---|
199 | * |
---|
200 | *---------------------------------------------------------------------*/ |
---|
201 | static int _gentable_sort_cmds(const void *a, const void *b); |
---|
202 | extern int iiArithRemoveCmd(char *szName); |
---|
203 | extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval, |
---|
204 | short nToktype, short nPos=-1); |
---|
205 | |
---|
206 | /*============= proc =======================*/ |
---|
207 | static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op); |
---|
208 | static Subexpr jjMakeSub(leftv e); |
---|
209 | |
---|
210 | /*============= vars ======================*/ |
---|
211 | EXTERN_VAR int cmdtok; |
---|
212 | EXTERN_VAR BOOLEAN expected_parms; |
---|
213 | |
---|
214 | #define ii_div_by_0 "div. by 0" |
---|
215 | |
---|
216 | VAR int iiOp; /* the current operation*/ |
---|
217 | |
---|
218 | /*=================== simple helpers =================*/ |
---|
219 | static int iin_Int(number &n,coeffs cf) |
---|
220 | { |
---|
221 | long l=n_Int(n,cf); |
---|
222 | int i=(int)l; |
---|
223 | if ((long)i==l) return l; |
---|
224 | return 0; |
---|
225 | } |
---|
226 | poly pHeadProc(poly p) |
---|
227 | { |
---|
228 | return pHead(p); |
---|
229 | } |
---|
230 | |
---|
231 | int iiTokType(int op) |
---|
232 | { |
---|
233 | for (unsigned i=0;i<sArithBase.nCmdUsed;i++) |
---|
234 | { |
---|
235 | if (sArithBase.sCmds[i].tokval==op) |
---|
236 | return sArithBase.sCmds[i].toktype; |
---|
237 | } |
---|
238 | return 0; |
---|
239 | } |
---|
240 | |
---|
241 | /*=================== operations with 2 args.: static proc =================*/ |
---|
242 | /* must be ordered: first operations for chars (infix ops), |
---|
243 | * then alphabetically */ |
---|
244 | |
---|
245 | static BOOLEAN jjOP_BIM_I(leftv res, leftv u, leftv v) |
---|
246 | { |
---|
247 | bigintmat* aa= (bigintmat *)u->Data(); |
---|
248 | int bb = (int)(long)(v->Data()); |
---|
249 | if (errorreported) return TRUE; |
---|
250 | bigintmat *cc=NULL; |
---|
251 | switch (iiOp) |
---|
252 | { |
---|
253 | case '+': cc=bimAdd(aa,bb); break; |
---|
254 | case '-': cc=bimSub(aa,bb); break; |
---|
255 | case '*': cc=bimMult(aa,bb); break; |
---|
256 | } |
---|
257 | res->data=(char *)cc; |
---|
258 | return cc==NULL; |
---|
259 | } |
---|
260 | static BOOLEAN jjOP_I_BIM(leftv res, leftv u, leftv v) |
---|
261 | { |
---|
262 | return jjOP_BIM_I(res, v, u); |
---|
263 | } |
---|
264 | static BOOLEAN jjOP_BIM_BI(leftv res, leftv u, leftv v) |
---|
265 | { |
---|
266 | bigintmat* aa= (bigintmat *)u->Data(); |
---|
267 | number bb = (number)(v->Data()); |
---|
268 | if (errorreported) return TRUE; |
---|
269 | bigintmat *cc=NULL; |
---|
270 | switch (iiOp) |
---|
271 | { |
---|
272 | case '*': cc=bimMult(aa,bb,coeffs_BIGINT); break; |
---|
273 | } |
---|
274 | res->data=(char *)cc; |
---|
275 | return cc==NULL; |
---|
276 | } |
---|
277 | static BOOLEAN jjOP_BI_BIM(leftv res, leftv u, leftv v) |
---|
278 | { |
---|
279 | return jjOP_BIM_BI(res, v, u); |
---|
280 | } |
---|
281 | static BOOLEAN jjOP_IV_I(leftv res, leftv u, leftv v) |
---|
282 | { |
---|
283 | intvec* aa= (intvec *)u->CopyD(INTVEC_CMD); |
---|
284 | int bb = (int)(long)(v->Data()); |
---|
285 | if (errorreported) return TRUE; |
---|
286 | switch (iiOp) |
---|
287 | { |
---|
288 | case '+': (*aa) += bb; break; |
---|
289 | case '-': (*aa) -= bb; break; |
---|
290 | case '*': (*aa) *= bb; break; |
---|
291 | case '/': |
---|
292 | case INTDIV_CMD: (*aa) /= bb; break; |
---|
293 | case '%': (*aa) %= bb; break; |
---|
294 | } |
---|
295 | res->data=(char *)aa; |
---|
296 | return FALSE; |
---|
297 | } |
---|
298 | static BOOLEAN jjOP_I_IV(leftv res, leftv u, leftv v) |
---|
299 | { |
---|
300 | return jjOP_IV_I(res,v,u); |
---|
301 | } |
---|
302 | static BOOLEAN jjOP_IM_I(leftv res, leftv u, leftv v) |
---|
303 | { |
---|
304 | intvec* aa= (intvec *)u->CopyD(INTVEC_CMD); |
---|
305 | int bb = (int)(long)(v->Data()); |
---|
306 | int i=si_min(aa->rows(),aa->cols()); |
---|
307 | switch (iiOp) |
---|
308 | { |
---|
309 | case '+': for (;i>0;i--) IMATELEM(*aa,i,i) += bb; |
---|
310 | break; |
---|
311 | case '-': for (;i>0;i--) IMATELEM(*aa,i,i) -= bb; |
---|
312 | break; |
---|
313 | } |
---|
314 | res->data=(char *)aa; |
---|
315 | return FALSE; |
---|
316 | } |
---|
317 | static BOOLEAN jjOP_I_IM(leftv res, leftv u, leftv v) |
---|
318 | { |
---|
319 | return jjOP_IM_I(res,v,u); |
---|
320 | } |
---|
321 | static BOOLEAN jjCOLON(leftv res, leftv u, leftv v) |
---|
322 | { |
---|
323 | int l=(int)(long)v->Data(); |
---|
324 | if (l>=0) |
---|
325 | { |
---|
326 | int d=(int)(long)u->Data(); |
---|
327 | intvec *vv=new intvec(l); |
---|
328 | int i; |
---|
329 | for(i=l-1;i>=0;i--) { (*vv)[i]=d; } |
---|
330 | res->data=(char *)vv; |
---|
331 | } |
---|
332 | return (l<0); |
---|
333 | } |
---|
334 | static BOOLEAN jjDOTDOT(leftv res, leftv u, leftv v) |
---|
335 | { |
---|
336 | res->data=(char *)new intvec((int)(long)u->Data(),(int)(long)v->Data()); |
---|
337 | return FALSE; |
---|
338 | } |
---|
339 | static void jjEQUAL_REST(leftv res,leftv u,leftv v); |
---|
340 | static BOOLEAN jjCOMPARE_IV(leftv res, leftv u, leftv v) |
---|
341 | { |
---|
342 | intvec* a = (intvec * )(u->Data()); |
---|
343 | intvec* b = (intvec * )(v->Data()); |
---|
344 | int r=a->compare(b); |
---|
345 | switch (iiOp) |
---|
346 | { |
---|
347 | case '<': |
---|
348 | res->data = (char *) (r<0); |
---|
349 | break; |
---|
350 | case '>': |
---|
351 | res->data = (char *) (r>0); |
---|
352 | break; |
---|
353 | case LE: |
---|
354 | res->data = (char *) (r<=0); |
---|
355 | break; |
---|
356 | case GE: |
---|
357 | res->data = (char *) (r>=0); |
---|
358 | break; |
---|
359 | case EQUAL_EQUAL: |
---|
360 | case NOTEQUAL: /* negation handled by jjEQUAL_REST */ |
---|
361 | res->data = (char *) (r==0); |
---|
362 | break; |
---|
363 | } |
---|
364 | jjEQUAL_REST(res,u,v); |
---|
365 | if(r==-2) { WerrorS("size incompatible"); return TRUE; } |
---|
366 | return FALSE; |
---|
367 | } |
---|
368 | static BOOLEAN jjCOMPARE_BIM(leftv res, leftv u, leftv v) |
---|
369 | { |
---|
370 | bigintmat* a = (bigintmat * )(u->Data()); |
---|
371 | bigintmat* b = (bigintmat * )(v->Data()); |
---|
372 | int r=a->compare(b); |
---|
373 | switch (iiOp) |
---|
374 | { |
---|
375 | case '<': |
---|
376 | res->data = (char *) (r<0); |
---|
377 | break; |
---|
378 | case '>': |
---|
379 | res->data = (char *) (r>0); |
---|
380 | break; |
---|
381 | case LE: |
---|
382 | res->data = (char *) (r<=0); |
---|
383 | break; |
---|
384 | case GE: |
---|
385 | res->data = (char *) (r>=0); |
---|
386 | break; |
---|
387 | case EQUAL_EQUAL: |
---|
388 | case NOTEQUAL: /* negation handled by jjEQUAL_REST */ |
---|
389 | res->data = (char *) (r==0); |
---|
390 | break; |
---|
391 | } |
---|
392 | jjEQUAL_REST(res,u,v); |
---|
393 | if(r==-2) { WerrorS("size incompatible"); return TRUE; } |
---|
394 | return FALSE; |
---|
395 | } |
---|
396 | static BOOLEAN jjCOMPARE_IV_I(leftv res, leftv u, leftv v) |
---|
397 | { |
---|
398 | intvec* a = (intvec * )(u->Data()); |
---|
399 | int b = (int)(long)(v->Data()); |
---|
400 | int r=a->compare(b); |
---|
401 | switch (iiOp) |
---|
402 | { |
---|
403 | case '<': |
---|
404 | res->data = (char *) (r<0); |
---|
405 | break; |
---|
406 | case '>': |
---|
407 | res->data = (char *) (r>0); |
---|
408 | break; |
---|
409 | case LE: |
---|
410 | res->data = (char *) (r<=0); |
---|
411 | break; |
---|
412 | case GE: |
---|
413 | res->data = (char *) (r>=0); |
---|
414 | break; |
---|
415 | case EQUAL_EQUAL: |
---|
416 | case NOTEQUAL: /* negation handled by jjEQUAL_REST */ |
---|
417 | res->data = (char *) (r==0); |
---|
418 | break; |
---|
419 | } |
---|
420 | jjEQUAL_REST(res,u,v); |
---|
421 | return FALSE; |
---|
422 | } |
---|
423 | static BOOLEAN jjCOMPARE_MA(leftv res, leftv u, leftv v) |
---|
424 | { |
---|
425 | //Print("in: >>%s<<\n",my_yylinebuf); |
---|
426 | matrix a=(matrix)u->Data(); |
---|
427 | matrix b=(matrix)v->Data(); |
---|
428 | int r=mp_Compare(a,b,currRing); |
---|
429 | switch (iiOp) |
---|
430 | { |
---|
431 | case '<': |
---|
432 | res->data = (char *) (long)(r < 0); |
---|
433 | break; |
---|
434 | case '>': |
---|
435 | res->data = (char *) (long)(r > 0); |
---|
436 | break; |
---|
437 | case LE: |
---|
438 | res->data = (char *) (long)(r <= 0); |
---|
439 | break; |
---|
440 | case GE: |
---|
441 | res->data = (char *) (long)(r >= 0); |
---|
442 | break; |
---|
443 | case EQUAL_EQUAL: |
---|
444 | case NOTEQUAL: /* negation handled by jjEQUAL_REST */ |
---|
445 | res->data = (char *)(long) (r == 0); |
---|
446 | break; |
---|
447 | } |
---|
448 | jjEQUAL_REST(res,u,v); |
---|
449 | return FALSE; |
---|
450 | } |
---|
451 | static BOOLEAN jjCOMPARE_P(leftv res, leftv u, leftv v) |
---|
452 | { |
---|
453 | poly p=(poly)u->Data(); |
---|
454 | poly q=(poly)v->Data(); |
---|
455 | int r=p_Compare(p,q,currRing); |
---|
456 | switch (iiOp) |
---|
457 | { |
---|
458 | case '<': |
---|
459 | res->data = (char *) (r < 0); |
---|
460 | break; |
---|
461 | case '>': |
---|
462 | res->data = (char *) (r > 0); |
---|
463 | break; |
---|
464 | case LE: |
---|
465 | res->data = (char *) (r <= 0); |
---|
466 | break; |
---|
467 | case GE: |
---|
468 | res->data = (char *) (r >= 0); |
---|
469 | break; |
---|
470 | //case EQUAL_EQUAL: |
---|
471 | //case NOTEQUAL: /* negation handled by jjEQUAL_REST */ |
---|
472 | // res->data = (char *) (r == 0); |
---|
473 | // break; |
---|
474 | } |
---|
475 | jjEQUAL_REST(res,u,v); |
---|
476 | return FALSE; |
---|
477 | } |
---|
478 | static BOOLEAN jjCOMPARE_S(leftv res, leftv u, leftv v) |
---|
479 | { |
---|
480 | char* a = (char * )(u->Data()); |
---|
481 | char* b = (char * )(v->Data()); |
---|
482 | int result = strcmp(a,b); |
---|
483 | switch (iiOp) |
---|
484 | { |
---|
485 | case '<': |
---|
486 | res->data = (char *) (result < 0); |
---|
487 | break; |
---|
488 | case '>': |
---|
489 | res->data = (char *) (result > 0); |
---|
490 | break; |
---|
491 | case LE: |
---|
492 | res->data = (char *) (result <= 0); |
---|
493 | break; |
---|
494 | case GE: |
---|
495 | res->data = (char *) (result >= 0); |
---|
496 | break; |
---|
497 | case EQUAL_EQUAL: |
---|
498 | case NOTEQUAL: /* negation handled by jjEQUAL_REST */ |
---|
499 | res->data = (char *) (result == 0); |
---|
500 | break; |
---|
501 | } |
---|
502 | jjEQUAL_REST(res,u,v); |
---|
503 | return FALSE; |
---|
504 | } |
---|
505 | static BOOLEAN jjOP_REST(leftv res, leftv u, leftv v) |
---|
506 | { |
---|
507 | if (u->Next()!=NULL) |
---|
508 | { |
---|
509 | u=u->next; |
---|
510 | res->next = (leftv)omAllocBin(sleftv_bin); |
---|
511 | return iiExprArith2(res->next,u,iiOp,v); |
---|
512 | } |
---|
513 | else if (v->Next()!=NULL) |
---|
514 | { |
---|
515 | v=v->next; |
---|
516 | res->next = (leftv)omAllocBin(sleftv_bin); |
---|
517 | return iiExprArith2(res->next,u,iiOp,v); |
---|
518 | } |
---|
519 | return FALSE; |
---|
520 | } |
---|
521 | static BOOLEAN jjPOWER_I(leftv res, leftv u, leftv v) |
---|
522 | { |
---|
523 | int b=(int)(long)u->Data(); |
---|
524 | int e=(int)(long)v->Data(); |
---|
525 | int rc = 1; |
---|
526 | BOOLEAN overflow=FALSE; |
---|
527 | if (e >= 0) |
---|
528 | { |
---|
529 | if (b==0) |
---|
530 | { |
---|
531 | rc=(e==0); |
---|
532 | } |
---|
533 | else if ((e==0)||(b==1)) |
---|
534 | { |
---|
535 | rc= 1; |
---|
536 | } |
---|
537 | else if (b== -1) |
---|
538 | { |
---|
539 | if (e&1) rc= -1; |
---|
540 | else rc= 1; |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | int oldrc; |
---|
545 | while ((e--)!=0) |
---|
546 | { |
---|
547 | oldrc=rc; |
---|
548 | rc *= b; |
---|
549 | if (!overflow) |
---|
550 | { |
---|
551 | if(rc/b!=oldrc) overflow=TRUE; |
---|
552 | } |
---|
553 | } |
---|
554 | if (overflow) |
---|
555 | WarnS("int overflow(^), result may be wrong"); |
---|
556 | } |
---|
557 | res->data = (char *)((long)rc); |
---|
558 | if (u!=NULL) return jjOP_REST(res,u,v); |
---|
559 | return FALSE; |
---|
560 | } |
---|
561 | else |
---|
562 | { |
---|
563 | WerrorS("exponent must be non-negative"); |
---|
564 | return TRUE; |
---|
565 | } |
---|
566 | } |
---|
567 | static BOOLEAN jjPOWER_BI(leftv res, leftv u, leftv v) |
---|
568 | { |
---|
569 | int e=(int)(long)v->Data(); |
---|
570 | number n=(number)u->Data(); |
---|
571 | if (e>=0) |
---|
572 | { |
---|
573 | n_Power(n,e,(number*)&res->data,coeffs_BIGINT); |
---|
574 | } |
---|
575 | else |
---|
576 | { |
---|
577 | WerrorS("exponent must be non-negative"); |
---|
578 | return TRUE; |
---|
579 | } |
---|
580 | if (u!=NULL) return jjOP_REST(res,u,v); |
---|
581 | return FALSE; |
---|
582 | } |
---|
583 | static BOOLEAN jjPOWER_N(leftv res, leftv u, leftv v) |
---|
584 | { |
---|
585 | int e=(int)(long)v->Data(); |
---|
586 | number n=(number)u->Data(); |
---|
587 | int d=0; |
---|
588 | if (e<0) |
---|
589 | { |
---|
590 | n=nInvers(n); |
---|
591 | e=-e; |
---|
592 | d=1; |
---|
593 | } |
---|
594 | number r; |
---|
595 | nPower(n,e,(number*)&r); |
---|
596 | res->data=(char*)r; |
---|
597 | if (d) nDelete(&n); |
---|
598 | if (u!=NULL) return jjOP_REST(res,u,v); |
---|
599 | return FALSE; |
---|
600 | } |
---|
601 | static BOOLEAN jjPOWER_P(leftv res, leftv u, leftv v) |
---|
602 | { |
---|
603 | int v_i=(int)(long)v->Data(); |
---|
604 | if (v_i<0) |
---|
605 | { |
---|
606 | WerrorS("exponent must be non-negative"); |
---|
607 | return TRUE; |
---|
608 | } |
---|
609 | poly u_p=(poly)u->CopyD(POLY_CMD); |
---|
610 | if ((u_p!=NULL) |
---|
611 | #ifdef HAVE_SHIFTBBA |
---|
612 | && (!rIsLPRing(currRing)) |
---|
613 | #endif |
---|
614 | && ((v_i!=0) && |
---|
615 | ((long)pTotaldegree(u_p) > (signed long)currRing->bitmask / (signed long)v_i/2))) |
---|
616 | { |
---|
617 | Werror("OVERFLOW in power(d=%ld, e=%d, max=%ld)", |
---|
618 | pTotaldegree(u_p),v_i,currRing->bitmask/2); |
---|
619 | pDelete(&u_p); |
---|
620 | return TRUE; |
---|
621 | } |
---|
622 | res->data = (char *)pPower(u_p,v_i); |
---|
623 | if (u!=NULL) return jjOP_REST(res,u,v); |
---|
624 | return errorreported; /* pPower may set errorreported via Werror */ |
---|
625 | } |
---|
626 | static BOOLEAN jjPOWER_ID(leftv res, leftv u, leftv v) |
---|
627 | { |
---|
628 | res->data = (char *)id_Power((ideal)(u->Data()),(int)(long)(v->Data()), currRing); |
---|
629 | if (u!=NULL) return jjOP_REST(res,u,v); |
---|
630 | return FALSE; |
---|
631 | } |
---|
632 | static BOOLEAN jjPLUSMINUS_Gen(leftv res, leftv u, leftv v) |
---|
633 | { |
---|
634 | u=u->next; |
---|
635 | v=v->next; |
---|
636 | if (u==NULL) |
---|
637 | { |
---|
638 | if (v==NULL) return FALSE; /* u==NULL, v==NULL */ |
---|
639 | if (iiOp=='-') /* u==NULL, v<>NULL, iiOp=='-'*/ |
---|
640 | { |
---|
641 | do |
---|
642 | { |
---|
643 | if (res->next==NULL) |
---|
644 | res->next = (leftv)omAlloc0Bin(sleftv_bin); |
---|
645 | leftv tmp_v=v->next; |
---|
646 | v->next=NULL; |
---|
647 | BOOLEAN b=iiExprArith1(res->next,v,'-'); |
---|
648 | v->next=tmp_v; |
---|
649 | if (b) |
---|
650 | return TRUE; |
---|
651 | v=tmp_v; |
---|
652 | res=res->next; |
---|
653 | } while (v!=NULL); |
---|
654 | return FALSE; |
---|
655 | } |
---|
656 | loop /* u==NULL, v<>NULL, iiOp=='+' */ |
---|
657 | { |
---|
658 | res->next = (leftv)omAlloc0Bin(sleftv_bin); |
---|
659 | res=res->next; |
---|
660 | res->data = v->CopyD(); |
---|
661 | res->rtyp = v->Typ(); |
---|
662 | v=v->next; |
---|
663 | if (v==NULL) return FALSE; |
---|
664 | } |
---|
665 | } |
---|
666 | if (v!=NULL) /* u<>NULL, v<>NULL */ |
---|
667 | { |
---|
668 | do |
---|
669 | { |
---|
670 | res->next = (leftv)omAlloc0Bin(sleftv_bin); |
---|
671 | leftv tmp_u=u->next; u->next=NULL; |
---|
672 | leftv tmp_v=v->next; v->next=NULL; |
---|
673 | BOOLEAN b=iiExprArith2(res->next,u,iiOp,v); |
---|
674 | u->next=tmp_u; |
---|
675 | v->next=tmp_v; |
---|
676 | if (b) |
---|
677 | return TRUE; |
---|
678 | u=tmp_u; |
---|
679 | v=tmp_v; |
---|
680 | res=res->next; |
---|
681 | } while ((u!=NULL) && (v!=NULL)); |
---|
682 | return FALSE; |
---|
683 | } |
---|
684 | loop /* u<>NULL, v==NULL */ |
---|
685 | { |
---|
686 | res->next = (leftv)omAlloc0Bin(sleftv_bin); |
---|
687 | res=res->next; |
---|
688 | res->data = u->CopyD(); |
---|
689 | res->rtyp = u->Typ(); |
---|
690 | u=u->next; |
---|
691 | if (u==NULL) return FALSE; |
---|
692 | } |
---|
693 | } |
---|
694 | static BOOLEAN jjCOLCOL(leftv res, leftv u, leftv v) |
---|
695 | { |
---|
696 | switch(u->Typ()) |
---|
697 | { |
---|
698 | case 0: |
---|
699 | { |
---|
700 | int name_err=0; |
---|
701 | if(isupper(u->name[0])) |
---|
702 | { |
---|
703 | const char *c=u->name+1; |
---|
704 | while((*c!='\0')&&(islower(*c)||(isdigit(*c))||(*c=='_'))) c++; |
---|
705 | if (*c!='\0') |
---|
706 | name_err=1; |
---|
707 | else |
---|
708 | { |
---|
709 | Print("%s of type 'ANY'. Trying load.\n", u->name); |
---|
710 | if(iiTryLoadLib(u, u->name)) |
---|
711 | { |
---|
712 | Werror("'%s' no such package", u->name); |
---|
713 | return TRUE; |
---|
714 | } |
---|
715 | syMake(u,u->name,NULL); |
---|
716 | } |
---|
717 | } |
---|
718 | else name_err=1; |
---|
719 | if(name_err) |
---|
720 | { Werror("'%s' is an invalid package name",u->name);return TRUE;} |
---|
721 | // and now, after the loading: use next case !!! no break !!! |
---|
722 | } |
---|
723 | case PACKAGE_CMD: |
---|
724 | { |
---|
725 | package pa=(package)u->Data(); |
---|
726 | if (u->rtyp==IDHDL) pa=IDPACKAGE((idhdl)u->data); |
---|
727 | if((!pa->loaded) |
---|
728 | && (pa->language > LANG_TOP)) |
---|
729 | { |
---|
730 | Werror("'%s' not loaded", u->name); |
---|
731 | return TRUE; |
---|
732 | } |
---|
733 | if(v->rtyp == IDHDL) |
---|
734 | { |
---|
735 | v->name = omStrDup(v->name); |
---|
736 | } |
---|
737 | else if (v->rtyp!=0) |
---|
738 | { |
---|
739 | WerrorS("reserved name with ::"); |
---|
740 | return TRUE; |
---|
741 | } |
---|
742 | v->req_packhdl=pa; |
---|
743 | syMake(v, v->name, pa); |
---|
744 | memcpy(res, v, sizeof(sleftv)); |
---|
745 | memset(v, 0, sizeof(sleftv)); |
---|
746 | } |
---|
747 | break; |
---|
748 | case DEF_CMD: |
---|
749 | break; |
---|
750 | default: |
---|
751 | WerrorS("<package>::<id> expected"); |
---|
752 | return TRUE; |
---|
753 | } |
---|
754 | return FALSE; |
---|
755 | } |
---|
756 | static BOOLEAN jjPLUS_I(leftv res, leftv u, leftv v) |
---|
757 | { |
---|
758 | unsigned int a=(unsigned int)(unsigned long)u->Data(); |
---|
759 | unsigned int b=(unsigned int)(unsigned long)v->Data(); |
---|
760 | unsigned int c=a+b; |
---|
761 | res->data = (char *)((long)c); |
---|
762 | if (((Sy_bit(31)&a)==(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c))) |
---|
763 | { |
---|
764 | WarnS("int overflow(+), result may be wrong"); |
---|
765 | } |
---|
766 | return jjPLUSMINUS_Gen(res,u,v); |
---|
767 | } |
---|
768 | static BOOLEAN jjPLUS_BI(leftv res, leftv u, leftv v) |
---|
769 | { |
---|
770 | res->data = (char *)(n_Add((number)u->Data(), (number)v->Data(),coeffs_BIGINT)); |
---|
771 | return jjPLUSMINUS_Gen(res,u,v); |
---|
772 | } |
---|
773 | static BOOLEAN jjPLUS_N(leftv res, leftv u, leftv v) |
---|
774 | { |
---|
775 | res->data = (char *)(nAdd((number)u->Data(), (number)v->Data())); |
---|
776 | return jjPLUSMINUS_Gen(res,u,v); |
---|
777 | } |
---|
778 | static BOOLEAN jjPLUS_V(leftv res, leftv u, leftv v) |
---|
779 | { |
---|
780 | res->data = (char *)(pAdd((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD))); |
---|
781 | return jjPLUSMINUS_Gen(res,u,v); |
---|
782 | } |
---|
783 | static BOOLEAN jjPLUS_B(leftv res, leftv u, leftv v) |
---|
784 | { |
---|
785 | //res->data = (char *)(pAdd((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD))); |
---|
786 | sBucket_pt b=sBucketCreate(currRing); |
---|
787 | poly p=(poly)u->CopyD(POLY_CMD); |
---|
788 | int l=pLength(p); |
---|
789 | sBucket_Add_p(b,p,l); |
---|
790 | p= (poly)v->CopyD(POLY_CMD); |
---|
791 | l=pLength(p); |
---|
792 | sBucket_Add_p(b,p,l); |
---|
793 | res->data=(void*)b; |
---|
794 | return jjPLUSMINUS_Gen(res,u,v); |
---|
795 | } |
---|
796 | static BOOLEAN jjPLUS_B_P(leftv res, leftv u, leftv v) |
---|
797 | { |
---|
798 | sBucket_pt b=(sBucket_pt)u->CopyD(BUCKET_CMD); |
---|
799 | poly p= (poly)v->CopyD(POLY_CMD); |
---|
800 | int l=pLength(p); |
---|
801 | sBucket_Add_p(b,p,l); |
---|
802 | res->data=(void*)b; |
---|
803 | return jjPLUSMINUS_Gen(res,u,v); |
---|
804 | } |
---|
805 | static BOOLEAN jjPLUS_IV(leftv res, leftv u, leftv v) |
---|
806 | { |
---|
807 | res->data = (char *)ivAdd((intvec*)(u->Data()), (intvec*)(v->Data())); |
---|
808 | if (res->data==NULL) |
---|
809 | { |
---|
810 | WerrorS("intmat size not compatible"); |
---|
811 | return TRUE; |
---|
812 | } |
---|
813 | return jjPLUSMINUS_Gen(res,u,v); |
---|
814 | } |
---|
815 | static BOOLEAN jjPLUS_BIM(leftv res, leftv u, leftv v) |
---|
816 | { |
---|
817 | res->data = (char *)bimAdd((bigintmat*)(u->Data()), (bigintmat*)(v->Data())); |
---|
818 | if (res->data==NULL) |
---|
819 | { |
---|
820 | WerrorS("bigintmat/cmatrix not compatible"); |
---|
821 | return TRUE; |
---|
822 | } |
---|
823 | return jjPLUSMINUS_Gen(res,u,v); |
---|
824 | } |
---|
825 | static BOOLEAN jjPLUS_MA(leftv res, leftv u, leftv v) |
---|
826 | { |
---|
827 | matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data(); |
---|
828 | res->data = (char *)(mp_Add(A , B, currRing)); |
---|
829 | if (res->data==NULL) |
---|
830 | { |
---|
831 | Werror("matrix size not compatible(%dx%d, %dx%d)", |
---|
832 | MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B)); |
---|
833 | return TRUE; |
---|
834 | } |
---|
835 | return jjPLUSMINUS_Gen(res,u,v); |
---|
836 | } |
---|
837 | static BOOLEAN jjPLUS_SM(leftv res, leftv u, leftv v) |
---|
838 | { |
---|
839 | ideal A=(ideal)u->Data(); ideal B=(ideal)v->Data(); |
---|
840 | res->data = (char *)(sm_Add(A , B, currRing)); |
---|
841 | if (res->data==NULL) |
---|
842 | { |
---|
843 | Werror("matrix size not compatible(%dx%d, %dx%d)", |
---|
844 | (int)A->rank,IDELEMS(A),(int)B->rank,IDELEMS(B)); |
---|
845 | return TRUE; |
---|
846 | } |
---|
847 | return jjPLUSMINUS_Gen(res,u,v); |
---|
848 | } |
---|
849 | static BOOLEAN jjPLUS_MA_P(leftv res, leftv u, leftv v) |
---|
850 | { |
---|
851 | matrix m=(matrix)u->Data(); |
---|
852 | matrix p= mp_InitP(m->nrows,m->ncols,(poly)(v->CopyD(POLY_CMD)),currRing); |
---|
853 | if (iiOp=='+') |
---|
854 | res->data = (char *)mp_Add(m , p,currRing); |
---|
855 | else |
---|
856 | res->data = (char *)mp_Sub(m , p,currRing); |
---|
857 | idDelete((ideal *)&p); |
---|
858 | return jjPLUSMINUS_Gen(res,u,v); |
---|
859 | } |
---|
860 | static BOOLEAN jjPLUS_P_MA(leftv res, leftv u, leftv v) |
---|
861 | { |
---|
862 | return jjPLUS_MA_P(res,v,u); |
---|
863 | } |
---|
864 | static BOOLEAN jjPLUS_S(leftv res, leftv u, leftv v) |
---|
865 | { |
---|
866 | char* a = (char * )(u->Data()); |
---|
867 | char* b = (char * )(v->Data()); |
---|
868 | char* r = (char * )omAlloc(strlen(a) + strlen(b) + 1); |
---|
869 | strcpy(r,a); |
---|
870 | strcat(r,b); |
---|
871 | res->data=r; |
---|
872 | return jjPLUSMINUS_Gen(res,u,v); |
---|
873 | } |
---|
874 | static BOOLEAN jjPLUS_ID(leftv res, leftv u, leftv v) |
---|
875 | { |
---|
876 | res->data = (char *)idAdd((ideal)u->Data(),(ideal)v->Data()); |
---|
877 | return jjPLUSMINUS_Gen(res,u,v); |
---|
878 | } |
---|
879 | static BOOLEAN jjMINUS_I(leftv res, leftv u, leftv v) |
---|
880 | { |
---|
881 | void *ap=u->Data(); void *bp=v->Data(); |
---|
882 | int aa=(int)(long)ap; |
---|
883 | int bb=(int)(long)bp; |
---|
884 | int cc=aa-bb; |
---|
885 | unsigned int a=(unsigned int)(unsigned long)ap; |
---|
886 | unsigned int b=(unsigned int)(unsigned long)bp; |
---|
887 | unsigned int c=a-b; |
---|
888 | if (((Sy_bit(31)&a)!=(Sy_bit(31)&b))&&((Sy_bit(31)&a)!=(Sy_bit(31)&c))) |
---|
889 | { |
---|
890 | WarnS("int overflow(-), result may be wrong"); |
---|
891 | } |
---|
892 | res->data = (char *)((long)cc); |
---|
893 | return jjPLUSMINUS_Gen(res,u,v); |
---|
894 | } |
---|
895 | static BOOLEAN jjMINUS_BI(leftv res, leftv u, leftv v) |
---|
896 | { |
---|
897 | res->data = (char *)(n_Sub((number)u->Data(), (number)v->Data(),coeffs_BIGINT)); |
---|
898 | return jjPLUSMINUS_Gen(res,u,v); |
---|
899 | } |
---|
900 | static BOOLEAN jjMINUS_N(leftv res, leftv u, leftv v) |
---|
901 | { |
---|
902 | res->data = (char *)(nSub((number)u->Data(), (number)v->Data())); |
---|
903 | return jjPLUSMINUS_Gen(res,u,v); |
---|
904 | } |
---|
905 | static BOOLEAN jjMINUS_V(leftv res, leftv u, leftv v) |
---|
906 | { |
---|
907 | res->data = (char *)(pSub((poly)u->CopyD(POLY_CMD) , (poly)v->CopyD(POLY_CMD))); |
---|
908 | return jjPLUSMINUS_Gen(res,u,v); |
---|
909 | } |
---|
910 | static BOOLEAN jjMINUS_B_P(leftv res, leftv u, leftv v) |
---|
911 | { |
---|
912 | sBucket_pt b=(sBucket_pt)u->CopyD(BUCKET_CMD); |
---|
913 | poly p= (poly)v->CopyD(POLY_CMD); |
---|
914 | int l=pLength(p); |
---|
915 | p=p_Neg(p,currRing); |
---|
916 | sBucket_Add_p(b,p,l); |
---|
917 | res->data=(void*)b; |
---|
918 | return jjPLUSMINUS_Gen(res,u,v); |
---|
919 | } |
---|
920 | static BOOLEAN jjMINUS_B(leftv res, leftv u, leftv v) |
---|
921 | { |
---|
922 | sBucket_pt b=sBucketCreate(currRing); |
---|
923 | poly p=(poly)u->CopyD(POLY_CMD); |
---|
924 | int l=pLength(p); |
---|
925 | sBucket_Add_p(b,p,l); |
---|
926 | p= (poly)v->CopyD(POLY_CMD); |
---|
927 | p=p_Neg(p,currRing); |
---|
928 | l=pLength(p); |
---|
929 | sBucket_Add_p(b,p,l); |
---|
930 | res->data=(void*)b; |
---|
931 | return jjPLUSMINUS_Gen(res,u,v); |
---|
932 | } |
---|
933 | static BOOLEAN jjMINUS_IV(leftv res, leftv u, leftv v) |
---|
934 | { |
---|
935 | res->data = (char *)ivSub((intvec*)(u->Data()), (intvec*)(v->Data())); |
---|
936 | if (res->data==NULL) |
---|
937 | { |
---|
938 | WerrorS("intmat size not compatible"); |
---|
939 | return TRUE; |
---|
940 | } |
---|
941 | return jjPLUSMINUS_Gen(res,u,v); |
---|
942 | } |
---|
943 | static BOOLEAN jjMINUS_BIM(leftv res, leftv u, leftv v) |
---|
944 | { |
---|
945 | res->data = (char *)bimSub((bigintmat*)(u->Data()), (bigintmat*)(v->Data())); |
---|
946 | if (res->data==NULL) |
---|
947 | { |
---|
948 | WerrorS("bigintmat/cmatrix not compatible"); |
---|
949 | return TRUE; |
---|
950 | } |
---|
951 | return jjPLUSMINUS_Gen(res,u,v); |
---|
952 | } |
---|
953 | static BOOLEAN jjMINUS_MA(leftv res, leftv u, leftv v) |
---|
954 | { |
---|
955 | matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data(); |
---|
956 | res->data = (char *)(mp_Sub(A , B, currRing)); |
---|
957 | if (res->data==NULL) |
---|
958 | { |
---|
959 | Werror("matrix size not compatible(%dx%d, %dx%d)", |
---|
960 | MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B)); |
---|
961 | return TRUE; |
---|
962 | } |
---|
963 | return jjPLUSMINUS_Gen(res,u,v); |
---|
964 | return FALSE; |
---|
965 | } |
---|
966 | static BOOLEAN jjMINUS_SM(leftv res, leftv u, leftv v) |
---|
967 | { |
---|
968 | ideal A=(ideal)u->Data(); ideal B=(ideal)v->Data(); |
---|
969 | res->data = (char *)(sm_Sub(A , B, currRing)); |
---|
970 | if (res->data==NULL) |
---|
971 | { |
---|
972 | Werror("matrix size not compatible(%dx%d, %dx%d)", |
---|
973 | (int)A->rank,IDELEMS(A),(int)B->rank,IDELEMS(B)); |
---|
974 | return TRUE; |
---|
975 | } |
---|
976 | return jjPLUSMINUS_Gen(res,u,v); |
---|
977 | return FALSE; |
---|
978 | } |
---|
979 | static BOOLEAN jjTIMES_I(leftv res, leftv u, leftv v) |
---|
980 | { |
---|
981 | int a=(int)(long)u->Data(); |
---|
982 | int b=(int)(long)v->Data(); |
---|
983 | int64 c=(int64)a * (int64)b; |
---|
984 | if ((c>INT_MAX)||(c<INT_MIN)) |
---|
985 | WarnS("int overflow(*), result may be wrong"); |
---|
986 | res->data = (char *)((long)((int)c)); |
---|
987 | if ((u->Next()!=NULL) || (v->Next()!=NULL)) |
---|
988 | return jjOP_REST(res,u,v); |
---|
989 | return FALSE; |
---|
990 | } |
---|
991 | static BOOLEAN jjTIMES_BI(leftv res, leftv u, leftv v) |
---|
992 | { |
---|
993 | res->data = (char *)(n_Mult( (number)u->Data(), (number)v->Data(),coeffs_BIGINT)); |
---|
994 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
995 | return jjOP_REST(res,u,v); |
---|
996 | return FALSE; |
---|
997 | } |
---|
998 | static BOOLEAN jjTIMES_N(leftv res, leftv u, leftv v) |
---|
999 | { |
---|
1000 | res->data = (char *)(nMult( (number)u->Data(), (number)v->Data())); |
---|
1001 | number n=(number)res->data; |
---|
1002 | nNormalize(n); |
---|
1003 | res->data=(char *)n; |
---|
1004 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
1005 | return jjOP_REST(res,u,v); |
---|
1006 | return FALSE; |
---|
1007 | } |
---|
1008 | static BOOLEAN jjTIMES_P(leftv res, leftv u, leftv v) |
---|
1009 | { |
---|
1010 | poly a; |
---|
1011 | poly b; |
---|
1012 | if (v->next==NULL) |
---|
1013 | { |
---|
1014 | if (u->next==NULL) |
---|
1015 | { |
---|
1016 | a=(poly)u->Data(); // works also for VECTOR_CMD |
---|
1017 | b=(poly)v->Data(); // works also for VECTOR_CMD |
---|
1018 | if ((a!=NULL) && (b!=NULL) |
---|
1019 | && ((long)pTotaldegree(a)>si_max((long)rVar(currRing),(long)currRing->bitmask/2)-(long)pTotaldegree(b))) |
---|
1020 | { |
---|
1021 | Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)", |
---|
1022 | pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2); |
---|
1023 | } |
---|
1024 | res->data = (char *)(pp_Mult_qq( a, b, currRing)); |
---|
1025 | pNormalize((poly)res->data); |
---|
1026 | return FALSE; |
---|
1027 | } |
---|
1028 | // u->next exists: copy v |
---|
1029 | a=(poly)u->CopyD(POLY_CMD); // works also for VECTOR_CMD |
---|
1030 | b=pCopy((poly)v->Data()); |
---|
1031 | if ((a!=NULL) && (b!=NULL) |
---|
1032 | && (pTotaldegree(a)+pTotaldegree(b)>si_max((long)rVar(currRing),(long)currRing->bitmask/2))) |
---|
1033 | { |
---|
1034 | Warn("possible OVERFLOW in mult(d=%ld, d=%ld, max=%ld)", |
---|
1035 | pTotaldegree(a),pTotaldegree(b),currRing->bitmask/2); |
---|
1036 | } |
---|
1037 | res->data = (char *)(pMult( a, b)); |
---|
1038 | pNormalize((poly)res->data); |
---|
1039 | return jjOP_REST(res,u,v); |
---|
1040 | } |
---|
1041 | // v->next exists: copy u |
---|
1042 | a=pCopy((poly)u->Data()); |
---|
1043 | b=(poly)v->CopyD(POLY_CMD); // works also for VECTOR_CMD |
---|
1044 | if ((a!=NULL) && (b!=NULL) |
---|
1045 | && ((unsigned long)(pTotaldegree(a)+pTotaldegree(b))>=currRing->bitmask/2)) |
---|
1046 | { |
---|
1047 | pDelete(&a); |
---|
1048 | pDelete(&b); |
---|
1049 | WerrorS("OVERFLOW"); |
---|
1050 | return TRUE; |
---|
1051 | } |
---|
1052 | res->data = (char *)(pMult( a, b)); |
---|
1053 | pNormalize((poly)res->data); |
---|
1054 | return jjOP_REST(res,u,v); |
---|
1055 | } |
---|
1056 | static BOOLEAN jjTIMES_ID(leftv res, leftv u, leftv v) |
---|
1057 | { |
---|
1058 | res->data = (char *)idMult((ideal)u->Data(),(ideal)v->Data()); |
---|
1059 | id_Normalize((ideal)res->data,currRing); |
---|
1060 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
1061 | return jjOP_REST(res,u,v); |
---|
1062 | return FALSE; |
---|
1063 | } |
---|
1064 | static BOOLEAN jjTIMES_IV(leftv res, leftv u, leftv v) |
---|
1065 | { |
---|
1066 | res->data = (char *)ivMult((intvec*)(u->Data()), (intvec*)(v->Data())); |
---|
1067 | if (res->data==NULL) |
---|
1068 | { |
---|
1069 | WerrorS("intmat size not compatible"); |
---|
1070 | return TRUE; |
---|
1071 | } |
---|
1072 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
1073 | return jjOP_REST(res,u,v); |
---|
1074 | return FALSE; |
---|
1075 | } |
---|
1076 | static BOOLEAN jjTIMES_BIM(leftv res, leftv u, leftv v) |
---|
1077 | { |
---|
1078 | res->data = (char *)bimMult((bigintmat*)(u->Data()), (bigintmat*)(v->Data())); |
---|
1079 | if (res->data==NULL) |
---|
1080 | { |
---|
1081 | WerrorS("bigintmat/cmatrix not compatible"); |
---|
1082 | return TRUE; |
---|
1083 | } |
---|
1084 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
1085 | return jjOP_REST(res,u,v); |
---|
1086 | return FALSE; |
---|
1087 | } |
---|
1088 | static BOOLEAN jjTIMES_MA_BI1(leftv res, leftv u, leftv v) |
---|
1089 | { |
---|
1090 | nMapFunc nMap=n_SetMap(coeffs_BIGINT,currRing->cf); |
---|
1091 | if (nMap==NULL) return TRUE; |
---|
1092 | number n=nMap((number)v->Data(),coeffs_BIGINT,currRing->cf); |
---|
1093 | poly p=pNSet(n); |
---|
1094 | ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing); |
---|
1095 | res->data = (char *)I; |
---|
1096 | return FALSE; |
---|
1097 | } |
---|
1098 | static BOOLEAN jjTIMES_MA_BI2(leftv res, leftv u, leftv v) |
---|
1099 | { |
---|
1100 | return jjTIMES_MA_BI1(res,v,u); |
---|
1101 | } |
---|
1102 | static BOOLEAN jjTIMES_MA_P1(leftv res, leftv u, leftv v) |
---|
1103 | { |
---|
1104 | poly p=(poly)v->CopyD(POLY_CMD); |
---|
1105 | int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/ |
---|
1106 | ideal I= (ideal)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing); |
---|
1107 | if (r>0) I->rank=r; |
---|
1108 | id_Normalize(I,currRing); |
---|
1109 | res->data = (char *)I; |
---|
1110 | return FALSE; |
---|
1111 | } |
---|
1112 | static BOOLEAN jjTIMES_MA_P2(leftv res, leftv u, leftv v) |
---|
1113 | { |
---|
1114 | poly p=(poly)u->CopyD(POLY_CMD); |
---|
1115 | int r=pMaxComp(p);/* recompute the rank for the case ideal*vector*/ |
---|
1116 | ideal I= (ideal)pMultMp(p,(matrix)v->CopyD(MATRIX_CMD),currRing); |
---|
1117 | if (r>0) I->rank=r; |
---|
1118 | id_Normalize(I,currRing); |
---|
1119 | res->data = (char *)I; |
---|
1120 | return FALSE; |
---|
1121 | } |
---|
1122 | static BOOLEAN jjTIMES_MA_N1(leftv res, leftv u, leftv v) |
---|
1123 | { |
---|
1124 | number n=(number)v->CopyD(NUMBER_CMD); |
---|
1125 | poly p=pNSet(n); |
---|
1126 | res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),p,currRing); |
---|
1127 | id_Normalize((ideal)res->data,currRing); |
---|
1128 | return FALSE; |
---|
1129 | } |
---|
1130 | static BOOLEAN jjTIMES_MA_N2(leftv res, leftv u, leftv v) |
---|
1131 | { |
---|
1132 | return jjTIMES_MA_N1(res,v,u); |
---|
1133 | } |
---|
1134 | static BOOLEAN jjTIMES_MA_I1(leftv res, leftv u, leftv v) |
---|
1135 | { |
---|
1136 | res->data = (char *)mp_MultI((matrix)u->CopyD(MATRIX_CMD),(int)(long)v->Data(),currRing); |
---|
1137 | id_Normalize((ideal)res->data,currRing); |
---|
1138 | return FALSE; |
---|
1139 | } |
---|
1140 | static BOOLEAN jjTIMES_MA_I2(leftv res, leftv u, leftv v) |
---|
1141 | { |
---|
1142 | return jjTIMES_MA_I1(res,v,u); |
---|
1143 | } |
---|
1144 | static BOOLEAN jjTIMES_MA(leftv res, leftv u, leftv v) |
---|
1145 | { |
---|
1146 | matrix A=(matrix)u->Data(); matrix B=(matrix)v->Data(); |
---|
1147 | res->data = (char *)mp_Mult(A,B,currRing); |
---|
1148 | if (res->data==NULL) |
---|
1149 | { |
---|
1150 | Werror("matrix size not compatible(%dx%d, %dx%d) in *", |
---|
1151 | MATROWS(A),MATCOLS(A),MATROWS(B),MATCOLS(B)); |
---|
1152 | return TRUE; |
---|
1153 | } |
---|
1154 | id_Normalize((ideal)res->data,currRing); |
---|
1155 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
1156 | return jjOP_REST(res,u,v); |
---|
1157 | return FALSE; |
---|
1158 | } |
---|
1159 | static BOOLEAN jjTIMES_SM(leftv res, leftv u, leftv v) |
---|
1160 | { |
---|
1161 | ideal A=(ideal)u->Data(); ideal B=(ideal)v->Data(); |
---|
1162 | res->data = (char *)sm_Mult(A,B,currRing); |
---|
1163 | if (res->data==NULL) |
---|
1164 | { |
---|
1165 | Werror("matrix size not compatible(%dx%d, %dx%d) in *", |
---|
1166 | (int)A->rank,IDELEMS(A),(int)B->rank,IDELEMS(B)); |
---|
1167 | return TRUE; |
---|
1168 | } |
---|
1169 | id_Normalize((ideal)res->data,currRing); |
---|
1170 | if ((v->next!=NULL) || (u->next!=NULL)) |
---|
1171 | return jjOP_REST(res,u,v); |
---|
1172 | return FALSE; |
---|
1173 | } |
---|
1174 | static BOOLEAN jjGE_BI(leftv res, leftv u, leftv v) |
---|
1175 | { |
---|
1176 | number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT); |
---|
1177 | res->data = (char *) (n_GreaterZero(h,coeffs_BIGINT)||(n_IsZero(h,coeffs_BIGINT))); |
---|
1178 | n_Delete(&h,coeffs_BIGINT); |
---|
1179 | return FALSE; |
---|
1180 | } |
---|
1181 | static BOOLEAN jjGE_I(leftv res, leftv u, leftv v) |
---|
1182 | { |
---|
1183 | res->data = (char *)(long)((int)((long)u->Data()) >= (int)((long)v->Data())); |
---|
1184 | return FALSE; |
---|
1185 | } |
---|
1186 | static BOOLEAN jjGE_N(leftv res, leftv u, leftv v) |
---|
1187 | { |
---|
1188 | res->data = (char *)(long) (nGreater((number)u->Data(),(number)v->Data()) |
---|
1189 | || nEqual((number)u->Data(),(number)v->Data())); |
---|
1190 | return FALSE; |
---|
1191 | } |
---|
1192 | static BOOLEAN jjGT_BI(leftv res, leftv u, leftv v) |
---|
1193 | { |
---|
1194 | number h=n_Sub((number)u->Data(),(number)v->Data(),coeffs_BIGINT); |
---|
1195 | res->data = (char *)(long) (n_GreaterZero(h,coeffs_BIGINT)&&(!n_IsZero(h,coeffs_BIGINT))); |
---|
1196 | n_Delete(&h,coeffs_BIGINT); |
---|
1197 | return FALSE; |
---|
1198 | } |
---|
1199 | static BOOLEAN jjGT_I(leftv res, leftv u, leftv v) |
---|
1200 | { |
---|
1201 | res->data = (char *)(long)((int)((long)u->Data()) > (int)((long)v->Data())); |
---|
1202 | return FALSE; |
---|
1203 | } |
---|
1204 | static BOOLEAN jjGT_N(leftv res, leftv u, leftv v) |
---|
1205 | { |
---|
1206 | res->data = (char *)(long)(nGreater((number)u->Data(),(number)v->Data())); |
---|
1207 | return FALSE; |
---|
1208 | } |
---|
1209 | static BOOLEAN jjLE_BI(leftv res, leftv u, leftv v) |
---|
1210 | { |
---|
1211 | return jjGE_BI(res,v,u); |
---|
1212 | } |
---|
1213 | static BOOLEAN jjLE_I(leftv res, leftv u, leftv v) |
---|
1214 | { |
---|
1215 | res->data = (char *)(long)((int)((long)u->Data()) <= (int)((long)v->Data())); |
---|
1216 | return FALSE; |
---|
1217 | } |
---|
1218 | static BOOLEAN jjLE_N(leftv res, leftv u, leftv v) |
---|
1219 | { |
---|
1220 | return jjGE_N(res,v,u); |
---|
1221 | } |
---|
1222 | static BOOLEAN jjLT_BI(leftv res, leftv u, leftv v) |
---|
1223 | { |
---|
1224 | return jjGT_BI(res,v,u); |
---|
1225 | } |
---|
1226 | static BOOLEAN jjLT_I(leftv res, leftv u, leftv v) |
---|
1227 | { |
---|
1228 | res->data = (char *)(long)((int)((long)u->Data()) < (int)((long)v->Data())); |
---|
1229 | return FALSE; |
---|
1230 | } |
---|
1231 | static BOOLEAN jjLT_N(leftv res, leftv u, leftv v) |
---|
1232 | { |
---|
1233 | return jjGT_N(res,v,u); |
---|
1234 | } |
---|
1235 | static BOOLEAN jjDIVMOD_I(leftv res, leftv u, leftv v) |
---|
1236 | { |
---|
1237 | if (iiOp=='/') Warn("int division with `/`: use `div` instead in line >>%s<<",my_yylinebuf); |
---|
1238 | int a= (int)(long)u->Data(); |
---|
1239 | int b= (int)(long)v->Data(); |
---|
1240 | if (b==0) |
---|
1241 | { |
---|
1242 | WerrorS(ii_div_by_0); |
---|
1243 | return TRUE; |
---|
1244 | } |
---|
1245 | int c=a%b; |
---|
1246 | int r=0; |
---|
1247 | switch (iiOp) |
---|
1248 | { |
---|
1249 | case '%': |
---|
1250 | r=c; break; |
---|
1251 | case '/': |
---|
1252 | case INTDIV_CMD: |
---|
1253 | r=((a-c) /b); break; |
---|
1254 | } |
---|
1255 | res->data=(void *)((long)r); |
---|
1256 | return FALSE; |
---|
1257 | } |
---|
1258 | static BOOLEAN jjDIV_BI(leftv res, leftv u, leftv v) |
---|
1259 | { |
---|
1260 | number q=(number)v->Data(); |
---|
1261 | if (n_IsZero(q,coeffs_BIGINT)) |
---|
1262 | { |
---|
1263 | WerrorS(ii_div_by_0); |
---|
1264 | return TRUE; |
---|
1265 | } |
---|
1266 | q = n_Div((number)u->Data(),q,coeffs_BIGINT); |
---|
1267 | n_Normalize(q,coeffs_BIGINT); |
---|
1268 | res->data = (char *)q; |
---|
1269 | return FALSE; |
---|
1270 | } |
---|
1271 | static BOOLEAN jjDIV_N(leftv res, leftv u, leftv v) |
---|
1272 | { |
---|
1273 | number q=(number)v->Data(); |
---|
1274 | if (nIsZero(q)) |
---|
1275 | { |
---|
1276 | WerrorS(ii_div_by_0); |
---|
1277 | return TRUE; |
---|
1278 | } |
---|
1279 | q = nDiv((number)u->Data(),q); |
---|
1280 | nNormalize(q); |
---|
1281 | res->data = (char *)q; |
---|
1282 | return FALSE; |
---|
1283 | } |
---|
1284 | static BOOLEAN jjDIV_P(leftv res, leftv u, leftv v) |
---|
1285 | { |
---|
1286 | poly q=(poly)v->Data(); |
---|
1287 | poly p=(poly)(u->Data()); |
---|
1288 | res->data=(void*)(pp_Divide(p /*(poly)(u->Data())*/ , |
---|
1289 | q /*(poly)(v->Data())*/ ,currRing)); |
---|
1290 | if (res->data!=NULL) pNormalize((poly)res->data); |
---|
1291 | return errorreported; /*there may be errors in p_Divide: div. ny 0, etc.*/ |
---|
1292 | } |
---|
1293 | static BOOLEAN jjDIV_Ma(leftv res, leftv u, leftv v) |
---|
1294 | { |
---|
1295 | poly q=(poly)v->Data(); |
---|
1296 | if (q==NULL) |
---|
1297 | { |
---|
1298 | WerrorS(ii_div_by_0); |
---|
1299 | return TRUE; |
---|
1300 | } |
---|
1301 | matrix m=(matrix)(u->Data()); |
---|
1302 | int r=m->rows(); |
---|
1303 | int c=m->cols(); |
---|
1304 | matrix mm=mpNew(r,c); |
---|
1305 | unsigned i,j; |
---|
1306 | for(i=r;i>0;i--) |
---|
1307 | { |
---|
1308 | for(j=c;j>0;j--) |
---|
1309 | { |
---|
1310 | if (pNext(q)!=NULL) |
---|
1311 | { |
---|
1312 | MATELEM(mm,i,j) = singclap_pdivide( MATELEM(m,i,j) , |
---|
1313 | q /*(poly)(v->Data())*/, currRing ); |
---|
1314 | } |
---|
1315 | else |
---|
1316 | MATELEM(mm,i,j) = pp_DivideM(MATELEM(m,i,j),q,currRing); |
---|
1317 | } |
---|
1318 | } |
---|
1319 | id_Normalize((ideal)mm,currRing); |
---|
1320 | res->data=(char *)mm; |
---|
1321 | return FALSE; |
---|
1322 | } |
---|
1323 | static BOOLEAN jjEQUAL_BI(leftv res, leftv u, leftv v) |
---|
1324 | { |
---|
1325 | res->data = (char *)((long)n_Equal((number)u->Data(),(number)v->Data(),coeffs_BIGINT)); |
---|
1326 | jjEQUAL_REST(res,u,v); |
---|
1327 | return FALSE; |
---|
1328 | } |
---|
1329 | static BOOLEAN jjEQUAL_I(leftv res, leftv u, leftv v) |
---|
1330 | { |
---|
1331 | res->data = (char *)((int)((long)u->Data()) == (int)((long)v->Data())); |
---|
1332 | jjEQUAL_REST(res,u,v); |
---|
1333 | return FALSE; |
---|
1334 | } |
---|
1335 | static BOOLEAN jjEQUAL_Ma(leftv res, leftv u, leftv v) |
---|
1336 | { |
---|
1337 | res->data = (char *)((long)mp_Equal((matrix)u->Data(),(matrix)v->Data(),currRing)); |
---|
1338 | jjEQUAL_REST(res,u,v); |
---|
1339 | return FALSE; |
---|
1340 | } |
---|
1341 | static BOOLEAN jjEQUAL_SM(leftv res, leftv u, leftv v) |
---|
1342 | { |
---|
1343 | res->data = (char *)((long)sm_Equal((ideal)u->Data(),(ideal)v->Data(),currRing)); |
---|
1344 | jjEQUAL_REST(res,u,v); |
---|
1345 | return FALSE; |
---|
1346 | } |
---|
1347 | static BOOLEAN jjEQUAL_R(leftv res, leftv u, leftv v) |
---|
1348 | { |
---|
1349 | res->data = (char *)(long)(u->Data()==v->Data()); |
---|
1350 | jjEQUAL_REST(res,u,v); |
---|
1351 | return FALSE; |
---|
1352 | } |
---|
1353 | static BOOLEAN jjEQUAL_N(leftv res, leftv u, leftv v) |
---|
1354 | { |
---|
1355 | res->data = (char *)((long)nEqual((number)u->Data(),(number)v->Data())); |
---|
1356 | jjEQUAL_REST(res,u,v); |
---|
1357 | return FALSE; |
---|
1358 | } |
---|
1359 | static BOOLEAN jjEQUAL_P(leftv res, leftv u, leftv v) |
---|
1360 | { |
---|
1361 | poly p=(poly)u->Data(); |
---|
1362 | poly q=(poly)v->Data(); |
---|
1363 | res->data = (char *) ((long)pEqualPolys(p,q)); |
---|
1364 | jjEQUAL_REST(res,u,v); |
---|
1365 | return FALSE; |
---|
1366 | } |
---|
1367 | static void jjEQUAL_REST(leftv res,leftv u,leftv v) |
---|
1368 | { |
---|
1369 | if ((res->data) && (u->next!=NULL) && (v->next!=NULL)) |
---|
1370 | { |
---|
1371 | int save_iiOp=iiOp; |
---|
1372 | if (iiOp==NOTEQUAL) |
---|
1373 | iiExprArith2(res,u->next,EQUAL_EQUAL,v->next); |
---|
1374 | else |
---|
1375 | iiExprArith2(res,u->next,iiOp,v->next); |
---|
1376 | iiOp=save_iiOp; |
---|
1377 | } |
---|
1378 | if (iiOp==NOTEQUAL) res->data=(char *)(!(long)res->data); |
---|
1379 | } |
---|
1380 | static BOOLEAN jjAND_I(leftv res, leftv u, leftv v) |
---|
1381 | { |
---|
1382 | res->data = (char *)((long)u->Data() && (long)v->Data()); |
---|
1383 | return FALSE; |
---|
1384 | } |
---|
1385 | static BOOLEAN jjOR_I(leftv res, leftv u, leftv v) |
---|
1386 | { |
---|
1387 | res->data = (char *)((long)u->Data() || (long)v->Data()); |
---|
1388 | return FALSE; |
---|
1389 | } |
---|
1390 | static BOOLEAN jjINDEX_I(leftv res, leftv u, leftv v) |
---|
1391 | { |
---|
1392 | res->rtyp=u->rtyp; u->rtyp=0; |
---|
1393 | res->data=u->data; u->data=NULL; |
---|
1394 | res->name=u->name; u->name=NULL; |
---|
1395 | res->e=u->e; u->e=NULL; |
---|
1396 | if (res->e==NULL) res->e=jjMakeSub(v); |
---|
1397 | else |
---|
1398 | { |
---|
1399 | Subexpr sh=res->e; |
---|
1400 | while (sh->next != NULL) sh=sh->next; |
---|
1401 | sh->next=jjMakeSub(v); |
---|
1402 | } |
---|
1403 | if (u->next!=NULL) |
---|
1404 | { |
---|
1405 | leftv rn=(leftv)omAlloc0Bin(sleftv_bin); |
---|
1406 | BOOLEAN bo=iiExprArith2(rn,u->next,iiOp,v); |
---|
1407 | res->next=rn; |
---|
1408 | return bo; |
---|
1409 | } |
---|
1410 | return FALSE; |
---|
1411 | } |
---|
1412 | static BOOLEAN jjINDEX_IV(leftv res, leftv u, leftv v) |
---|
1413 | { |
---|
1414 | if ((u->rtyp!=IDHDL)||(u->e!=NULL)) |
---|
1415 | { |
---|
1416 | WerrorS("indexed object must have a name"); |
---|
1417 | return TRUE; |
---|
1418 | } |
---|
1419 | intvec * iv=(intvec *)v->Data(); |
---|
1420 | leftv p=NULL; |
---|
1421 | int i; |
---|
1422 | sleftv t; |
---|
1423 | memset(&t,0,sizeof(t)); |
---|
1424 | t.rtyp=INT_CMD; |
---|
1425 | for (i=0;i<iv->length(); i++) |
---|
1426 | { |
---|
1427 | t.data=(char *)((long)(*iv)[i]); |
---|
1428 | if (p==NULL) |
---|
1429 | { |
---|
1430 | p=res; |
---|
1431 | } |
---|
1432 | else |
---|
1433 | { |
---|
1434 | p->next=(leftv)omAlloc0Bin(sleftv_bin); |
---|
1435 | p=p->next; |
---|
1436 | } |
---|
1437 | p->rtyp=IDHDL; |
---|
1438 | p->data=u->data; |
---|
1439 | p->name=u->name; |
---|
1440 | p->flag=u->flag; |
---|
1441 | p->e=jjMakeSub(&t); |
---|
1442 | } |
---|
1443 | u->rtyp=0; |
---|
1444 | u->data=NULL; |
---|
1445 | u->name=NULL; |
---|
1446 | return FALSE; |
---|
1447 | } |
---|
1448 | static BOOLEAN jjINDEX_P(leftv res, leftv u, leftv v) |
---|
1449 | { |
---|
1450 | poly p=(poly)u->Data(); |
---|
1451 | int i=(int)(long)v->Data(); |
---|
1452 | int j=0; |
---|
1453 | while (p!=NULL) |
---|
1454 | { |
---|
1455 | j++; |
---|
1456 | if (j==i) |
---|
1457 | { |
---|
1458 | res->data=(char *)pHead(p); |
---|
1459 | return FALSE; |
---|
1460 | } |
---|
1461 | pIter(p); |
---|
1462 | } |
---|
1463 | return FALSE; |
---|
1464 | } |
---|
1465 | static BOOLEAN jjINDEX_PBu(leftv res, leftv u, leftv v) |
---|
1466 | { |
---|
1467 | sBucket_pt b=(sBucket_pt)u->CopyD(); |
---|
1468 | sBucketCanonicalize(b); |
---|
1469 | int l; poly p,pp; |
---|
1470 | sBucketDestroyAdd(b, &pp, &l); |
---|
1471 | int i=(int)(long)v->Data(); |
---|
1472 | int j=0; |
---|
1473 | p=pp; |
---|
1474 | while (p!=NULL) |
---|
1475 | { |
---|
1476 | j++; |
---|
1477 | if (j==i) |
---|
1478 | { |
---|
1479 | res->data=(char *)pHead(p); |
---|
1480 | p_Delete(&pp,currRing); |
---|
1481 | return FALSE; |
---|
1482 | } |
---|
1483 | pIter(p); |
---|
1484 | } |
---|
1485 | p_Delete(&pp,currRing); |
---|
1486 | return FALSE; |
---|
1487 | } |
---|
1488 | static BOOLEAN jjINDEX_P_IV(leftv res, leftv u, leftv v) |
---|
1489 | { |
---|
1490 | poly p=(poly)u->Data(); |
---|
1491 | poly r=NULL; |
---|
1492 | intvec *iv=(intvec *)v->CopyD(INTVEC_CMD); |
---|
1493 | int i; |
---|
1494 | int sum=0; |
---|
1495 | for(i=iv->length()-1;i>=0;i--) |
---|
1496 | sum+=(*iv)[i]; |
---|
1497 | int j=0; |
---|
1498 | while ((p!=NULL) && (sum>0)) |
---|
1499 | { |
---|
1500 | j++; |
---|
1501 | for(i=iv->length()-1;i>=0;i--) |
---|
1502 | { |
---|
1503 | if (j==(*iv)[i]) |
---|
1504 | { |
---|
1505 | r=pAdd(r,pHead(p)); |
---|
1506 | sum-=j; |
---|
1507 | (*iv)[i]=0; |
---|
1508 | break; |
---|
1509 | } |
---|
1510 | } |
---|
1511 | pIter(p); |
---|
1512 | } |
---|
1513 | delete iv; |
---|
1514 | res->data=(char *)r; |
---|
1515 | return FALSE; |
---|
1516 | } |
---|
1517 | static BOOLEAN jjINDEX_V(leftv res, leftv u, leftv v) |
---|
1518 | { |
---|
1519 | poly p=(poly)u->Data(); |
---|
1520 | int i=(int)(long)v->Data(); |
---|
1521 | res->data=(char *)p_Vec2Poly(p,i,currRing); |
---|
1522 | return FALSE; |
---|
1523 | } |
---|
1524 | static BOOLEAN jjINDEX_V_IV(leftv res, leftv u, leftv v) |
---|
1525 | { |
---|
1526 | poly p=(poly)u->CopyD(VECTOR_CMD); |
---|
1527 | if (p!=NULL) |
---|
1528 | { |
---|
1529 | poly r=pOne(); |
---|
1530 | poly hp=r; |
---|
1531 | intvec *iv=(intvec *)v->Data(); |
---|
1532 | int i; |
---|
1533 | loop |
---|
1534 | { |
---|
1535 | for(i=0;i<iv->length();i++) |
---|
1536 | { |
---|
1537 | if (((int)pGetComp(p))==(*iv)[i]) |
---|
1538 | { |
---|
1539 | poly h; |
---|
1540 | pSplit(p,&h); |
---|
1541 | pNext(hp)=p; |
---|
1542 | p=h; |
---|
1543 | pIter(hp); |
---|
1544 | break; |
---|
1545 | } |
---|
1546 | } |
---|
1547 | if (p==NULL) break; |
---|
1548 | if (i==iv->length()) |
---|
1549 | { |
---|
1550 | pLmDelete(&p); |
---|
1551 | if (p==NULL) break; |
---|
1552 | } |
---|
1553 | } |
---|
1554 | pLmDelete(&r); |
---|
1555 | res->data=(char *)r; |
---|
1556 | } |
---|
1557 | return FALSE; |
---|
1558 | } |
---|
1559 | static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v); |
---|
1560 | static BOOLEAN jjKLAMMER(leftv res, leftv u, leftv v) |
---|
1561 | { |
---|
1562 | if(u->name==NULL) return TRUE; |
---|
1563 | char * nn = (char *)omAlloc(strlen(u->name) + 14); |
---|
1564 | sprintf(nn,"%s(%d)",u->name,(int)(long)v->Data()); |
---|
1565 | omFree((ADDRESS)u->name); |
---|
1566 | u->name=NULL; |
---|
1567 | char *n=omStrDup(nn); |
---|
1568 | omFree((ADDRESS)nn); |
---|
1569 | syMake(res,n); |
---|
1570 | if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v); |
---|
1571 | return FALSE; |
---|
1572 | } |
---|
1573 | static BOOLEAN jjKLAMMER_IV(leftv res, leftv u, leftv v) |
---|
1574 | { |
---|
1575 | intvec * iv=(intvec *)v->Data(); |
---|
1576 | leftv p=NULL; |
---|
1577 | int i; |
---|
1578 | long slen = strlen(u->name) + 14; |
---|
1579 | char *n = (char*) omAlloc(slen); |
---|
1580 | |
---|
1581 | for (i=0;i<iv->length(); i++) |
---|
1582 | { |
---|
1583 | if (p==NULL) |
---|
1584 | { |
---|
1585 | p=res; |
---|
1586 | } |
---|
1587 | else |
---|
1588 | { |
---|
1589 | p->next=(leftv)omAlloc0Bin(sleftv_bin); |
---|
1590 | p=p->next; |
---|
1591 | } |
---|
1592 | sprintf(n,"%s(%d)",u->name,(*iv)[i]); |
---|
1593 | syMake(p,omStrDup(n)); |
---|
1594 | } |
---|
1595 | omFree((ADDRESS)u->name); |
---|
1596 | u->name = NULL; |
---|
1597 | omFreeSize(n, slen); |
---|
1598 | if (u->next!=NULL) return jjKLAMMER_rest(res,u->next,v); |
---|
1599 | return FALSE; |
---|
1600 | } |
---|
1601 | static BOOLEAN jjKLAMMER_rest(leftv res, leftv u, leftv v) |
---|
1602 | { |
---|
1603 | leftv tmp=(leftv)omAllocBin(sleftv_bin); |
---|
1604 | memset(tmp,0,sizeof(sleftv)); |
---|
1605 | BOOLEAN b; |
---|
1606 | if (v->Typ()==INTVEC_CMD) |
---|
1607 | b=jjKLAMMER_IV(tmp,u,v); |
---|
1608 | else |
---|
1609 | b=jjKLAMMER(tmp,u,v); |
---|
1610 | if (b) |
---|
1611 | { |
---|
1612 | omFreeBin(tmp,sleftv_bin); |
---|
1613 | return TRUE; |
---|
1614 | } |
---|
1615 | leftv h=res; |
---|
1616 | while (h->next!=NULL) h=h->next; |
---|
1617 | h->next=tmp; |
---|
1618 | return FALSE; |
---|
1619 | } |
---|
1620 | BOOLEAN jjPROC(leftv res, leftv u, leftv v) |
---|
1621 | { |
---|
1622 | void *d; |
---|
1623 | Subexpr e; |
---|
1624 | int typ; |
---|
1625 | BOOLEAN t=FALSE; |
---|
1626 | idhdl tmp_proc=NULL; |
---|
1627 | if ((u->rtyp!=IDHDL)||(u->e!=NULL)) |
---|
1628 | { |
---|
1629 | tmp_proc=(idhdl)omAlloc0(sizeof(idrec)); |
---|
1630 | tmp_proc->id="_auto"; |
---|
1631 | tmp_proc->typ=PROC_CMD; |
---|
1632 | tmp_proc->data.pinf=(procinfo *)u->Data(); |
---|
1633 | tmp_proc->ref=1; |
---|
1634 | d=u->data; u->data=(void *)tmp_proc; |
---|
1635 | e=u->e; u->e=NULL; |
---|
1636 | t=TRUE; |
---|
1637 | typ=u->rtyp; u->rtyp=IDHDL; |
---|
1638 | } |
---|
1639 | BOOLEAN sl; |
---|
1640 | if (u->req_packhdl==currPack) |
---|
1641 | sl = iiMake_proc((idhdl)u->data,NULL,v); |
---|
1642 | else |
---|
1643 | sl = iiMake_proc((idhdl)u->data,u->req_packhdl,v); |
---|
1644 | if (t) |
---|
1645 | { |
---|
1646 | u->rtyp=typ; |
---|
1647 | u->data=d; |
---|
1648 | u->e=e; |
---|
1649 | omFreeSize(tmp_proc,sizeof(idrec)); |
---|
1650 | } |
---|
1651 | if (sl) return TRUE; |
---|
1652 | memcpy(res,&iiRETURNEXPR,sizeof(sleftv)); |
---|
1653 | iiRETURNEXPR.Init(); |
---|
1654 | return FALSE; |
---|
1655 | } |
---|
1656 | static BOOLEAN jjMAP(leftv res, leftv u, leftv v) |
---|
1657 | { |
---|
1658 | //Print("try to map %s with %s\n",$3.Name(),$1.Name()); |
---|
1659 | leftv sl=NULL; |
---|
1660 | if ((v->e==NULL)&&(v->name!=NULL)) |
---|
1661 | { |
---|
1662 | map m=(map)u->Data(); |
---|
1663 | sl=iiMap(m,v->name); |
---|
1664 | } |
---|
1665 | else |
---|
1666 | { |
---|
1667 | Werror("%s(<name>) expected",u->Name()); |
---|
1668 | } |
---|
1669 | if (sl==NULL) return TRUE; |
---|
1670 | memcpy(res,sl,sizeof(sleftv)); |
---|
1671 | omFreeBin((ADDRESS)sl, sleftv_bin); |
---|
1672 | return FALSE; |
---|
1673 | } |
---|
1674 | static BOOLEAN jjRING_1(leftv res, leftv u, leftv v) |
---|
1675 | { |
---|
1676 | u->next=(leftv)omAlloc(sizeof(sleftv)); |
---|
1677 | memcpy(u->next,v,sizeof(sleftv)); |
---|
1678 | memset(v,0,sizeof(sleftv)); |
---|
1679 | BOOLEAN bo=iiExprArithM(res,u,'['); |
---|
1680 | u->next=NULL; |
---|
1681 | return bo; |
---|
1682 | } |
---|
1683 | static BOOLEAN jjCHINREM_BI(leftv res, leftv u, leftv v) |
---|
1684 | { |
---|
1685 | intvec *c=(intvec*)u->Data(); |
---|
1686 | intvec* p=(intvec*)v->Data(); |
---|
1687 | int rl=p->length(); |
---|
1688 | number *x=(number *)omAlloc(rl*sizeof(number)); |
---|
1689 | number *q=(number *)omAlloc(rl*sizeof(number)); |
---|
1690 | int i; |
---|
1691 | for(i=rl-1;i>=0;i--) |
---|
1692 | { |
---|
1693 | q[i]=n_Init((*p)[i], coeffs_BIGINT); |
---|
1694 | x[i]=n_Init((*c)[i], coeffs_BIGINT); |
---|
1695 | } |
---|
1696 | CFArray iv(rl); |
---|
1697 | number n=n_ChineseRemainderSym(x,q,rl,FALSE,iv,coeffs_BIGINT); |
---|
1698 | for(i=rl-1;i>=0;i--) |
---|
1699 | { |
---|
1700 | n_Delete(&(q[i]),coeffs_BIGINT); |
---|
1701 | n_Delete(&(x[i]),coeffs_BIGINT); |
---|
1702 | } |
---|
1703 | omFree(x); omFree(q); |
---|
1704 | res->data=(char *)n; |
---|
1705 | return FALSE; |
---|
1706 | } |
---|
1707 | #if 0 |
---|
1708 | static BOOLEAN jjCHINREM_P(leftv res, leftv u, leftv v) |
---|
1709 | { |
---|
1710 | lists c=(lists)u->CopyD(); // list of poly |
---|
1711 | intvec* p=(intvec*)v->Data(); |
---|
1712 | int rl=p->length(); |
---|
1713 | poly r=NULL,h, result=NULL; |
---|
1714 | number *x=(number *)omAlloc(rl*sizeof(number)); |
---|
1715 | number *q=(number *)omAlloc(rl*sizeof(number)); |
---|
1716 | int i; |
---|
1717 | for(i=rl-1;i>=0;i--) |
---|
1718 | { |
---|
1719 | q[i]=nlInit((*p)[i]); |
---|
1720 | } |
---|
1721 | loop |
---|
1722 | { |
---|
1723 | for(i=rl-1;i>=0;i--) |
---|
1724 | { |
---|
1725 | if (c->m[i].Typ()!=POLY_CMD) |
---|
1726 | { |
---|
1727 | Werror("poly expected at pos %d",i+1); |
---|
1728 | for(i=rl-1;i>=0;i--) |
---|
1729 | { |
---|
1730 | nlDelete(&(q[i]),currRing); |
---|
1731 | } |
---|
1732 | omFree(x); omFree(q); // delete c |
---|
1733 | return TRUE; |
---|
1734 | } |
---|
1735 | h=((poly)c->m[i].Data()); |
---|
1736 | if (r==NULL) r=h; |
---|
1737 | else if (pLmCmp(r,h)==-1) r=h; |
---|
1738 | } |
---|
1739 | if (r==NULL) break; |
---|
1740 | for(i=rl-1;i>=0;i--) |
---|
1741 | { |
---|
1742 | h=((poly)c->m[i].Data()); |
---|
1743 | if (pLmCmp(r,h)==0) |
---|
1744 | { |
---|
1745 | x[i]=pGetCoeff(h); |
---|
1746 | h=pLmFreeAndNext(h); |
---|
1747 | c->m[i].data=(char*)h; |
---|
1748 | } |
---|
1749 | else |
---|
1750 | x[i]=nlInit(0); |
---|
1751 | } |
---|
1752 | number n=n_ChineseRemainder(x,q,rl,currRing->cf); |
---|
1753 | for(i=rl-1;i>=0;i--) |
---|
1754 | { |
---|
1755 | nlDelete(&(x[i]),currRing); |
---|
1756 | } |
---|
1757 | h=pHead(r); |
---|
1758 | pSetCoeff(h,n); |
---|
1759 | result=pAdd(result,h); |
---|
1760 | } |
---|
1761 | for(i=rl-1;i>=0;i--) |
---|
1762 | { |
---|
1763 | nlDelete(&(q[i]),currRing); |
---|
1764 | } |
---|
1765 | omFree(x); omFree(q); |
---|
1766 | res->data=(char *)result; |
---|
1767 | return FALSE; |
---|
1768 | } |
---|
1769 | #endif |
---|
1770 | static BOOLEAN jjALIGN_V(leftv res, leftv u, leftv v) |
---|
1771 | { |
---|
1772 | poly p=(poly)u->CopyD(); |
---|
1773 | int s=(int)(long)v->Data(); |
---|
1774 | if (s+p_MinComp(p,currRing)<=0) |
---|
1775 | { p_Delete(&p,currRing);return TRUE;} |
---|
1776 | p_Shift(&p,s,currRing); |
---|
1777 | res->data=p; |
---|
1778 | return FALSE; |
---|
1779 | } |
---|
1780 | static BOOLEAN jjALIGN_M(leftv res, leftv u, leftv v) |
---|
1781 | { |
---|
1782 | ideal M=(ideal)u->CopyD(); |
---|
1783 | int s=(int)(long)v->Data(); |
---|
1784 | for(int i=IDELEMS(M)-1; i>=0;i--) |
---|
1785 | { |
---|
1786 | if (s+p_MinComp(M->m[i],currRing)<=0) |
---|
1787 | { id_Delete(&M,currRing);return TRUE;} |
---|
1788 | } |
---|
1789 | id_Shift(M,s,currRing); |
---|
1790 | res->data=M; |
---|
1791 | return FALSE; |
---|
1792 | } |
---|
1793 | static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v); |
---|
1794 | static BOOLEAN jjCOEF(leftv res, leftv u, leftv v) |
---|
1795 | { |
---|
1796 | poly p=(poly)v->Data(); |
---|
1797 | if ((p==NULL)||(pNext(p)!=NULL)) return TRUE; |
---|
1798 | res->data=(char *)mp_CoeffProc((poly)u->Data(),p /*(poly)v->Data()*/,currRing); |
---|
1799 | return FALSE; |
---|
1800 | } |
---|
1801 | static BOOLEAN jjCOEF_Id(leftv res, leftv u, leftv v) |
---|
1802 | { |
---|
1803 | poly p=(poly)v->Data(); |
---|
1804 | if ((p==NULL)||(pNext(p)!=NULL)) return TRUE; |
---|
1805 | res->data=(char *)mp_CoeffProcId((ideal)u->Data(),p /*(poly)v->Data()*/,currRing); |
---|
1806 | return FALSE; |
---|
1807 | } |
---|
1808 | static BOOLEAN jjCOEFFS_Id(leftv res, leftv u, leftv v) |
---|
1809 | { |
---|
1810 | int i=pVar((poly)v->Data()); |
---|
1811 | if (i==0) |
---|
1812 | { |
---|
1813 | WerrorS("ringvar expected"); |
---|
1814 | return TRUE; |
---|
1815 | } |
---|
1816 | res->data=(char *)mp_Coeffs((ideal)u->CopyD(),i,currRing); |
---|
1817 | return FALSE; |
---|
1818 | } |
---|
1819 | static BOOLEAN jjCOEFFS2_KB(leftv res, leftv u, leftv v) |
---|
1820 | { |
---|
1821 | poly p = pInit(); |
---|
1822 | int i; |
---|
1823 | for (i=1; i<=currRing->N; i++) |
---|
1824 | { |
---|
1825 | pSetExp(p, i, 1); |
---|
1826 | } |
---|
1827 | pSetm(p); |
---|
1828 | res->data = (void*)idCoeffOfKBase((ideal)(u->Data()), |
---|
1829 | (ideal)(v->Data()), p); |
---|
1830 | pLmFree(&p); |
---|
1831 | return FALSE; |
---|
1832 | } |
---|
1833 | static BOOLEAN jjCONTRACT(leftv res, leftv u, leftv v) |
---|
1834 | { |
---|
1835 | res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data(),FALSE); |
---|
1836 | return FALSE; |
---|
1837 | } |
---|
1838 | static BOOLEAN jjDEG_M_IV(leftv res, leftv u, leftv v) |
---|
1839 | { |
---|
1840 | short *iv=iv2array((intvec *)v->Data(),currRing); |
---|
1841 | ideal I=(ideal)u->Data(); |
---|
1842 | int d=-1; |
---|
1843 | int i; |
---|
1844 | for(i=IDELEMS(I);i>=0;i--) d=si_max(d,(int)p_DegW(I->m[i],iv,currRing)); |
---|
1845 | omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) ); |
---|
1846 | res->data = (char *)((long)d); |
---|
1847 | return FALSE; |
---|
1848 | } |
---|
1849 | static BOOLEAN jjDEG_IV(leftv res, leftv u, leftv v) |
---|
1850 | { |
---|
1851 | poly p=(poly)u->Data(); |
---|
1852 | if (p!=NULL) |
---|
1853 | { |
---|
1854 | short *iv=iv2array((intvec *)v->Data(),currRing); |
---|
1855 | const long d = p_DegW(p,iv,currRing); |
---|
1856 | omFreeSize( (ADDRESS)iv, (rVar(currRing)+1)*sizeof(short) ); |
---|
1857 | res->data = (char *)(d); |
---|
1858 | } |
---|
1859 | else |
---|
1860 | res->data=(char *)(long)(-1); |
---|
1861 | return FALSE; |
---|
1862 | } |
---|
1863 | static BOOLEAN jjDelete_IV(leftv res, leftv u, leftv v) |
---|
1864 | { |
---|
1865 | int pos=(int)(long)v->Data(); |
---|
1866 | intvec *iv=(intvec*)u->Data(); |
---|
1867 | res->data=(void*)iv->delete_pos(pos-1); |
---|
1868 | return res->data==NULL; |
---|
1869 | } |
---|
1870 | static BOOLEAN jjDelete_ID(leftv res, leftv u, leftv v) |
---|
1871 | { |
---|
1872 | int pos=(int)(long)v->Data(); |
---|
1873 | ideal I=(ideal)u->Data(); |
---|
1874 | res->data=(void*)id_Delete_Pos(I,pos-1,currRing); |
---|
1875 | return res->data==NULL; |
---|
1876 | } |
---|
1877 | static BOOLEAN jjDET2(leftv res, leftv u, leftv v) |
---|
1878 | { |
---|
1879 | matrix m=(matrix)u->Data(); |
---|
1880 | DetVariant d=mp_GetAlgorithmDet((char*)v->Data()); |
---|
1881 | res ->data = mp_Det(m,currRing,d); |
---|
1882 | return FALSE; |
---|
1883 | } |
---|
1884 | static BOOLEAN jjDET2_S(leftv res, leftv u, leftv v) |
---|
1885 | { |
---|
1886 | DetVariant d=mp_GetAlgorithmDet((char*)v->Data()); |
---|
1887 | ideal m=(ideal)u->Data(); |
---|
1888 | res ->data = sm_Det(m,currRing,d); |
---|
1889 | return FALSE; |
---|
1890 | } |
---|
1891 | static BOOLEAN jjDIFF_P(leftv res, leftv u, leftv v) |
---|
1892 | { |
---|
1893 | int i=pVar((poly)v->Data()); |
---|
1894 | if (i==0) |
---|
1895 | { |
---|
1896 | WerrorS("ringvar expected"); |
---|
1897 | return TRUE; |
---|
1898 | } |
---|
1899 | res->data=(char *)pDiff((poly)(u->Data()),i); |
---|
1900 | return FALSE; |
---|
1901 | } |
---|
1902 | static BOOLEAN jjDIFF_ID(leftv res, leftv u, leftv v) |
---|
1903 | { |
---|
1904 | int i=pVar((poly)v->Data()); |
---|
1905 | if (i==0) |
---|
1906 | { |
---|
1907 | WerrorS("ringvar expected"); |
---|
1908 | return TRUE; |
---|
1909 | } |
---|
1910 | res->data=(char *)idDiff((matrix)(u->Data()),i); |
---|
1911 | return FALSE; |
---|
1912 | } |
---|
1913 | static BOOLEAN jjDIFF_ID_ID(leftv res, leftv u, leftv v) |
---|
1914 | { |
---|
1915 | res->data=(char *)idDiffOp((ideal)u->Data(),(ideal)v->Data()); |
---|
1916 | return FALSE; |
---|
1917 | } |
---|
1918 | static BOOLEAN jjDIM2(leftv res, leftv v, leftv w) |
---|
1919 | { |
---|
1920 | assumeStdFlag(v); |
---|
1921 | if (rHasMixedOrdering(currRing)) |
---|
1922 | { |
---|
1923 | Warn("dim(%s,...) may be wrong because the mixed monomial ordering",v->Name()); |
---|
1924 | } |
---|
1925 | #ifdef HAVE_RINGS |
---|
1926 | if (rField_is_Ring(currRing)) |
---|
1927 | { |
---|
1928 | ideal vid = (ideal)v->Data(); |
---|
1929 | int i = idPosConstant(vid); |
---|
1930 | if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf))) |
---|
1931 | { /* ideal v contains unit; dim = -1 */ |
---|
1932 | res->data = (char *)-1; |
---|
1933 | return FALSE; |
---|
1934 | } |
---|
1935 | ideal vv = id_Copy(vid, currRing); |
---|
1936 | ideal ww = id_Copy((ideal)w->Data(), currRing); |
---|
1937 | /* drop degree zero generator from vv (if any) */ |
---|
1938 | if (i != -1) pDelete(&vv->m[i]); |
---|
1939 | long d = (long)scDimInt(vv, ww); |
---|
1940 | if (rField_is_Z(currRing) && (i == -1)) d++; |
---|
1941 | res->data = (char *)d; |
---|
1942 | idDelete(&vv); idDelete(&ww); |
---|
1943 | return FALSE; |
---|
1944 | } |
---|
1945 | #endif |
---|
1946 | if(currRing->qideal==NULL) |
---|
1947 | res->data = (char *)((long)scDimInt((ideal)(v->Data()),(ideal)w->Data())); |
---|
1948 | else |
---|
1949 | { |
---|
1950 | ideal q=idSimpleAdd(currRing->qideal,(ideal)w->Data()); |
---|
1951 | res->data = (char *)((long)scDimInt((ideal)(v->Data()),q)); |
---|
1952 | idDelete(&q); |
---|
1953 | } |
---|
1954 | return FALSE; |
---|
1955 | } |
---|
1956 | static BOOLEAN jjDIVISION(leftv res, leftv u, leftv v) |
---|
1957 | { |
---|
1958 | ideal vi=(ideal)v->Data(); |
---|
1959 | int vl= IDELEMS(vi); |
---|
1960 | ideal ui=(ideal)u->Data(); |
---|
1961 | unsigned ul= IDELEMS(ui); |
---|
1962 | ideal R; matrix U; |
---|
1963 | ideal m = idLift(vi,ui,&R, FALSE,hasFlag(v,FLAG_STD),TRUE,&U); |
---|
1964 | if (m==NULL) return TRUE; |
---|
1965 | // now make sure that all matrices have the corect size: |
---|
1966 | matrix T = id_Module2formatedMatrix(m,vl,ul,currRing); |
---|
1967 | int i; |
---|
1968 | if (MATCOLS(U) != (int)ul) |
---|
1969 | { |
---|
1970 | unsigned mul=si_min(ul,MATCOLS(U)); |
---|
1971 | matrix UU=mpNew(ul,ul); |
---|
1972 | unsigned j; |
---|
1973 | for(i=mul;i>0;i--) |
---|
1974 | { |
---|
1975 | for(j=mul;j>0;j--) |
---|
1976 | { |
---|
1977 | MATELEM(UU,i,j)=MATELEM(U,i,j); |
---|
1978 | MATELEM(U,i,j)=NULL; |
---|
1979 | } |
---|
1980 | } |
---|
1981 | idDelete((ideal *)&U); |
---|
1982 | U=UU; |
---|
1983 | } |
---|
1984 | // make sure that U is a diagonal matrix of units |
---|
1985 | for(i=ul;i>0;i--) |
---|
1986 | { |
---|
1987 | if(MATELEM(U,i,i)==NULL) MATELEM(U,i,i)=pOne(); |
---|
1988 | } |
---|
1989 | lists L=(lists)omAllocBin(slists_bin); |
---|
1990 | L->Init(3); |
---|
1991 | L->m[0].rtyp=MATRIX_CMD; L->m[0].data=(void *)T; |
---|
1992 | L->m[1].rtyp=u->Typ(); L->m[1].data=(void *)R; |
---|
1993 | L->m[2].rtyp=MATRIX_CMD; L->m[2].data=(void *)U; |
---|
1994 | res->data=(char *)L; |
---|
1995 | return FALSE; |
---|
1996 | } |
---|
1997 | static BOOLEAN jjELIMIN(leftv res, leftv u, leftv v) |
---|
1998 | { |
---|
1999 | res->data=(char *)idElimination((ideal)u->Data(),(poly)v->Data()); |
---|
2000 | //setFlag(res,FLAG_STD); |
---|
2001 | return v->next!=NULL; //do not allow next like in eliminate(I,a(1..4)) |
---|
2002 | } |
---|
2003 | static BOOLEAN jjELIMIN_IV(leftv res, leftv u, leftv v) |
---|
2004 | { |
---|
2005 | poly p=pOne(); |
---|
2006 | intvec *iv=(intvec*)v->Data(); |
---|
2007 | for(int i=iv->length()-1; i>=0; i--) |
---|
2008 | { |
---|
2009 | pSetExp(p,(*iv)[i],1); |
---|
2010 | } |
---|
2011 | pSetm(p); |
---|
2012 | res->data=(char *)idElimination((ideal)u->Data(),p); |
---|
2013 | pLmDelete(&p); |
---|
2014 | //setFlag(res,FLAG_STD); |
---|
2015 | return FALSE; |
---|
2016 | } |
---|
2017 | static BOOLEAN jjEXPORTTO(leftv, leftv u, leftv v) |
---|
2018 | { |
---|
2019 | //Print("exportto %s -> %s\n",v->Name(),u->Name() ); |
---|
2020 | return iiExport(v,0,IDPACKAGE((idhdl)u->data)); |
---|
2021 | } |
---|
2022 | static BOOLEAN jjERROR(leftv, leftv u) |
---|
2023 | { |
---|
2024 | WerrorS((char *)u->Data()); |
---|
2025 | EXTERN_VAR int inerror; |
---|
2026 | inerror=3; |
---|
2027 | return TRUE; |
---|
2028 | } |
---|
2029 | static BOOLEAN jjEXTGCD_BI(leftv res, leftv u, leftv v) |
---|
2030 | { |
---|
2031 | number uu=(number)u->Data();number vv=(number)v->Data(); |
---|
2032 | lists L=(lists)omAllocBin(slists_bin); |
---|
2033 | number a,b; |
---|
2034 | number p0=n_ExtGcd(uu,vv,&a,&b,coeffs_BIGINT); |
---|
2035 | L->Init(3); |
---|
2036 | L->m[0].rtyp=BIGINT_CMD; L->m[0].data=(void *)p0; |
---|
2037 | L->m[1].rtyp=BIGINT_CMD; L->m[1].data=(void *)a; |
---|
2038 | L->m[2].rtyp=BIGINT_CMD; L->m[2].data=(void *)b; |
---|
2039 | res->rtyp=LIST_CMD; |
---|
2040 | res->data=(char *)L; |
---|
2041 | return FALSE; |
---|
2042 | } |
---|
2043 | static BOOLEAN jjEXTGCD_I(leftv res, leftv u, leftv v) |
---|
2044 | { |
---|
2045 | int uu=(int)(long)u->Data();int vv=(int)(long)v->Data(); |
---|
2046 | int p0=ABS(uu),p1=ABS(vv); |
---|
2047 | int f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r; |
---|
2048 | |
---|
2049 | while ( p1!=0 ) |
---|
2050 | { |
---|
2051 | q=p0 / p1; |
---|
2052 | r=p0 % p1; |
---|
2053 | p0 = p1; p1 = r; |
---|
2054 | r = g0 - g1 * q; |
---|
2055 | g0 = g1; g1 = r; |
---|
2056 | r = f0 - f1 * q; |
---|
2057 | f0 = f1; f1 = r; |
---|
2058 | } |
---|
2059 | int a = f0; |
---|
2060 | int b = g0; |
---|
2061 | if ( uu /*(int)(long)u->Data()*/ < 0 ) a=-a; |
---|
2062 | if ( vv /*(int)(long)v->Data()*/ < 0 ) b=-b; |
---|
2063 | lists L=(lists)omAllocBin(slists_bin); |
---|
2064 | L->Init(3); |
---|
2065 | L->m[0].rtyp=INT_CMD; L->m[0].data=(void *)(long)p0; |
---|
2066 | L->m[1].rtyp=INT_CMD; L->m[1].data=(void *)(long)a; |
---|
2067 | L->m[2].rtyp=INT_CMD; L->m[2].data=(void *)(long)b; |
---|
2068 | res->rtyp=LIST_CMD; |
---|
2069 | res->data=(char *)L; |
---|
2070 | return FALSE; |
---|
2071 | } |
---|
2072 | static BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v) |
---|
2073 | { |
---|
2074 | poly r,pa,pb; |
---|
2075 | BOOLEAN ret=singclap_extgcd((poly)u->Data(),(poly)v->Data(),r,pa,pb,currRing); |
---|
2076 | if (ret) return TRUE; |
---|
2077 | lists L=(lists)omAllocBin(slists_bin); |
---|
2078 | L->Init(3); |
---|
2079 | res->data=(char *)L; |
---|
2080 | L->m[0].data=(void *)r; |
---|
2081 | L->m[0].rtyp=POLY_CMD; |
---|
2082 | L->m[1].data=(void *)pa; |
---|
2083 | L->m[1].rtyp=POLY_CMD; |
---|
2084 | L->m[2].data=(void *)pb; |
---|
2085 | L->m[2].rtyp=POLY_CMD; |
---|
2086 | return FALSE; |
---|
2087 | } |
---|
2088 | EXTERN_VAR int singclap_factorize_retry; |
---|
2089 | static BOOLEAN jjFAC_P2(leftv res, leftv u,leftv dummy) |
---|
2090 | { |
---|
2091 | intvec *v=NULL; |
---|
2092 | int sw=(int)(long)dummy->Data(); |
---|
2093 | int fac_sw=sw; |
---|
2094 | if ((sw<0)||(sw>2)) fac_sw=1; |
---|
2095 | singclap_factorize_retry=0; |
---|
2096 | ideal f=singclap_factorize((poly)(u->CopyD()), &v, fac_sw,currRing); |
---|
2097 | if (f==NULL) |
---|
2098 | return TRUE; |
---|
2099 | switch(sw) |
---|
2100 | { |
---|
2101 | case 0: |
---|
2102 | case 2: |
---|
2103 | { |
---|
2104 | lists l=(lists)omAllocBin(slists_bin); |
---|
2105 | l->Init(2); |
---|
2106 | l->m[0].rtyp=IDEAL_CMD; |
---|
2107 | l->m[0].data=(void *)f; |
---|
2108 | l->m[1].rtyp=INTVEC_CMD; |
---|
2109 | l->m[1].data=(void *)v; |
---|
2110 | res->data=(void *)l; |
---|
2111 | res->rtyp=LIST_CMD; |
---|
2112 | return FALSE; |
---|
2113 | } |
---|
2114 | case 1: |
---|
2115 | res->data=(void *)f; |
---|
2116 | return FALSE; |
---|
2117 | case 3: |
---|
2118 | { |
---|
2119 | poly p=f->m[0]; |
---|
2120 | int i=IDELEMS(f); |
---|
2121 | f->m[0]=NULL; |
---|
2122 | while(i>1) |
---|
2123 | { |
---|
2124 | i--; |
---|
2125 | p=pMult(p,f->m[i]); |
---|
2126 | f->m[i]=NULL; |
---|
2127 | } |
---|
2128 | res->data=(void *)p; |
---|
2129 | res->rtyp=POLY_CMD; |
---|
2130 | } |
---|
2131 | return FALSE; |
---|
2132 | } |
---|
2133 | WerrorS("invalid switch"); |
---|
2134 | return TRUE; |
---|
2135 | } |
---|
2136 | static BOOLEAN jjFACSTD2(leftv res, leftv v, leftv w) |
---|
2137 | { |
---|
2138 | ideal_list p,h; |
---|
2139 | h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL,(ideal)w->Data()); |
---|
2140 | p=h; |
---|
2141 | int l=0; |
---|
2142 | while (p!=NULL) { p=p->next;l++; } |
---|
2143 | lists L=(lists)omAllocBin(slists_bin); |
---|
2144 | L->Init(l); |
---|
2145 | l=0; |
---|
2146 | while(h!=NULL) |
---|
2147 | { |
---|
2148 | L->m[l].data=(char *)h->d; |
---|
2149 | L->m[l].rtyp=IDEAL_CMD; |
---|
2150 | p=h->next; |
---|
2151 | omFreeSize(h,sizeof(*h)); |
---|
2152 | h=p; |
---|
2153 | l++; |
---|
2154 | } |
---|
2155 | res->data=(void *)L; |
---|
2156 | return FALSE; |
---|
2157 | } |
---|
2158 | static BOOLEAN jjFAREY_BI(leftv res, leftv u, leftv v) |
---|
2159 | { |
---|
2160 | if (rField_is_Q(currRing)) |
---|
2161 | { |
---|
2162 | number uu=(number)u->Data(); |
---|
2163 | number vv=(number)v->Data(); |
---|
2164 | res->data=(char *)n_Farey(uu,vv,currRing->cf); |
---|
2165 | return FALSE; |
---|
2166 | } |
---|
2167 | else return TRUE; |
---|
2168 | } |
---|
2169 | static BOOLEAN jjFAREY_ID(leftv res, leftv u, leftv v) |
---|
2170 | { |
---|
2171 | ideal uu=(ideal)u->Data(); |
---|
2172 | number vv=(number)v->Data(); |
---|
2173 | //timespec buf1,buf2; |
---|
2174 | //clock_gettime(CLOCK_THREAD_CPUTIME_ID,&buf1); |
---|
2175 | res->data=(void*)id_Farey(uu,vv,currRing); |
---|
2176 | //clock_gettime(CLOCK_THREAD_CPUTIME_ID,&buf2); |
---|
2177 | //const unsigned long SEC = 1000L*1000L*1000L; |
---|
2178 | //all_farey+=((buf2.tv_sec-buf1.tv_sec)*SEC+ |
---|
2179 | // buf2.tv_nsec-buf1.tv_nsec); |
---|
2180 | //farey_cnt++; |
---|
2181 | return FALSE; |
---|
2182 | } |
---|
2183 | static BOOLEAN jjFAREY_LI(leftv res, leftv u, leftv v); |
---|
2184 | static BOOLEAN jjFETCH(leftv res, leftv u, leftv v) |
---|
2185 | { |
---|
2186 | ring r=(ring)u->Data(); |
---|
2187 | idhdl w; |
---|
2188 | int op=iiOp; |
---|
2189 | nMapFunc nMap; |
---|
2190 | |
---|
2191 | if ((w=r->idroot->get(v->Name(),myynest))!=NULL) |
---|
2192 | { |
---|
2193 | int *perm=NULL; |
---|
2194 | int *par_perm=NULL; |
---|
2195 | int par_perm_size=0; |
---|
2196 | BOOLEAN bo; |
---|
2197 | if ((nMap=n_SetMap(r->cf,currRing->cf))==NULL) |
---|
2198 | { |
---|
2199 | // Allow imap/fetch to be make an exception only for: |
---|
2200 | if (nCoeff_is_Extension(r->cf) && // Q(a..) -> Q(a..) || Q || Zp || Zp(a) |
---|
2201 | ((n_SetMap(r->cf->extRing->cf,currRing->cf)!=NULL) |
---|
2202 | || (nCoeff_is_Extension(currRing->cf) && (n_SetMap(r->cf->extRing->cf,currRing->cf->extRing->cf)!=NULL)))) |
---|
2203 | { |
---|
2204 | par_perm_size=rPar(r); |
---|
2205 | } |
---|
2206 | else |
---|
2207 | { |
---|
2208 | goto err_fetch; |
---|
2209 | } |
---|
2210 | } |
---|
2211 | if ((iiOp!=FETCH_CMD) || (r->N!=currRing->N) || (rPar(r)!=rPar(currRing))) |
---|
2212 | { |
---|
2213 | perm=(int *)omAlloc0((r->N+1)*sizeof(int)); |
---|
2214 | if (par_perm_size!=0) |
---|
2215 | par_perm=(int *)omAlloc0(par_perm_size*sizeof(int)); |
---|
2216 | op=IMAP_CMD; |
---|
2217 | if (iiOp==IMAP_CMD) |
---|
2218 | { |
---|
2219 | int r_par=0; |
---|
2220 | char ** r_par_names=NULL; |
---|
2221 | if (r->cf->extRing!=NULL) |
---|
2222 | { |
---|
2223 | r_par=r->cf->extRing->N; |
---|
2224 | r_par_names=r->cf->extRing->names; |
---|
2225 | } |
---|
2226 | int c_par=0; |
---|
2227 | char ** c_par_names=NULL; |
---|
2228 | if (currRing->cf->extRing!=NULL) |
---|
2229 | { |
---|
2230 | c_par=currRing->cf->extRing->N; |
---|
2231 | c_par_names=currRing->cf->extRing->names; |
---|
2232 | } |
---|
2233 | if (!rIsLPRing(r)) |
---|
2234 | { |
---|
2235 | maFindPerm(r->names, r->N, r_par_names, r_par, |
---|
2236 | currRing->names,currRing->N,c_par_names, c_par, |
---|
2237 | perm,par_perm, currRing->cf->type); |
---|
2238 | } |
---|
2239 | #ifdef HAVE_SHIFTBBA |
---|
2240 | else |
---|
2241 | { |
---|
2242 | maFindPermLP(r->names, r->N, r_par_names, r_par, |
---|
2243 | currRing->names,currRing->N,c_par_names, c_par, |
---|
2244 | perm,par_perm, currRing->cf->type,r->isLPring); |
---|
2245 | } |
---|
2246 | #endif |
---|
2247 | } |
---|
2248 | else |
---|
2249 | { |
---|
2250 | unsigned i; |
---|
2251 | if (par_perm_size!=0) |
---|
2252 | for(i=si_min(rPar(r),rPar(currRing));i>0;i--) par_perm[i-1]=-i; |
---|
2253 | for(i=si_min(r->N,currRing->N);i>0;i--) perm[i]=i; |
---|
2254 | } |
---|
2255 | } |
---|
2256 | if ((iiOp==FETCH_CMD) &&(BVERBOSE(V_IMAP))) |
---|
2257 | { |
---|
2258 | unsigned i; |
---|
2259 | for(i=0;i<(unsigned)si_min(r->N,currRing->N);i++) |
---|
2260 | { |
---|
2261 | Print("// var nr %d: %s -> %s\n",i,r->names[i],currRing->names[i]); |
---|
2262 | } |
---|
2263 | for(i=0;i<(unsigned)si_min(rPar(r),rPar(currRing));i++) // possibly empty loop |
---|
2264 | { |
---|
2265 | Print("// par nr %d: %s -> %s\n", |
---|
2266 | i,rParameter(r)[i],rParameter(currRing)[i]); |
---|
2267 | } |
---|
2268 | } |
---|
2269 | if (IDTYP(w)==ALIAS_CMD) w=(idhdl)IDDATA(w); |
---|
2270 | sleftv tmpW; |
---|
2271 | memset(&tmpW,0,sizeof(sleftv)); |
---|
2272 | tmpW.rtyp=IDTYP(w); |
---|
2273 | tmpW.data=IDDATA(w); |
---|
2274 | if ((bo=maApplyFetch(op,NULL,res,&tmpW, r, |
---|
2275 | perm,par_perm,par_perm_size,nMap))) |
---|
2276 | { |
---|
2277 | Werror("cannot map %s of type %s(%d)",v->name, Tok2Cmdname(w->typ),w->typ); |
---|
2278 | } |
---|
2279 | if (perm!=NULL) |
---|
2280 | omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int)); |
---|
2281 | if (par_perm!=NULL) |
---|
2282 | omFreeSize((ADDRESS)par_perm,par_perm_size*sizeof(int)); |
---|
2283 | return bo; |
---|
2284 | } |
---|
2285 | else |
---|
2286 | { |
---|
2287 | Werror("identifier %s not found in %s",v->Fullname(),u->Fullname()); |
---|
2288 | } |
---|
2289 | return TRUE; |
---|
2290 | err_fetch: |
---|
2291 | char *s1=nCoeffString(r->cf); |
---|
2292 | char *s2=nCoeffString(currRing->cf); |
---|
2293 | Werror("no identity map from %s (%s -> %s)",u->Fullname(),s1,s2); |
---|
2294 | omFree(s2); omFree(s1); |
---|
2295 | return TRUE; |
---|
2296 | } |
---|
2297 | static BOOLEAN jjFIND2(leftv res, leftv u, leftv v) |
---|
2298 | { |
---|
2299 | /*4 |
---|
2300 | * look for the substring what in the string where |
---|
2301 | * return the position of the first char of what in where |
---|
2302 | * or 0 |
---|
2303 | */ |
---|
2304 | char *where=(char *)u->Data(); |
---|
2305 | char *what=(char *)v->Data(); |
---|
2306 | char *found = strstr(where,what); |
---|
2307 | if (found != NULL) |
---|
2308 | { |
---|
2309 | res->data=(char *)((found-where)+1); |
---|
2310 | } |
---|
2311 | /*else res->data=NULL;*/ |
---|
2312 | return FALSE; |
---|
2313 | } |
---|
2314 | |
---|
2315 | static BOOLEAN jjFRES3(leftv res, leftv u, leftv v, leftv w) |
---|
2316 | { |
---|
2317 | assumeStdFlag(u); |
---|
2318 | ideal id = (ideal)u->Data(); |
---|
2319 | int max_length = (int)(long)v->Data(); |
---|
2320 | if (max_length < 0) |
---|
2321 | { |
---|
2322 | WerrorS("length for fres must not be negative"); |
---|
2323 | return TRUE; |
---|
2324 | } |
---|
2325 | if (max_length == 0) |
---|
2326 | { |
---|
2327 | max_length = currRing->N+1; |
---|
2328 | if (currRing->qideal != NULL) |
---|
2329 | { |
---|
2330 | Warn("full resolution in a qring may be infinite, " |
---|
2331 | "setting max length to %d", max_length); |
---|
2332 | } |
---|
2333 | } |
---|
2334 | char *method = (char *)w->Data(); |
---|
2335 | /* For the moment, only "complete" (default), "frame", or "extended frame" |
---|
2336 | * are allowed. Another useful option would be "linear strand". |
---|
2337 | */ |
---|
2338 | if (strcmp(method, "complete") != 0 |
---|
2339 | && strcmp(method, "frame") != 0 |
---|
2340 | && strcmp(method, "extended frame") != 0 |
---|
2341 | && strcmp(method, "single module") != 0) |
---|
2342 | { |
---|
2343 | WerrorS("wrong optional argument for fres"); |
---|
2344 | return TRUE; |
---|
2345 | } |
---|
2346 | syStrategy r = syFrank(id, max_length, method); |
---|
2347 | assume(r->fullres != NULL); |
---|
2348 | res->data = (void *)r; |
---|
2349 | return FALSE; |
---|
2350 | } |
---|
2351 | |
---|
2352 | static BOOLEAN jjFRES(leftv res, leftv u, leftv v) |
---|
2353 | { |
---|
2354 | leftv w = (leftv)omAlloc0(sizeof(sleftv)); |
---|
2355 | w->rtyp = STRING_CMD; |
---|
2356 | w->data = (char *)"complete"; // default |
---|
2357 | BOOLEAN RES = jjFRES3(res, u, v, w); |
---|
2358 | omFree(w); |
---|
2359 | return RES; |
---|
2360 | } |
---|
2361 | |
---|
2362 | static BOOLEAN jjFWALK(leftv res, leftv u, leftv v) |
---|
2363 | { |
---|
2364 | res->data=(char *)fractalWalkProc(u,v); |
---|
2365 | setFlag( res, FLAG_STD ); |
---|
2366 | return FALSE; |
---|
2367 | } |
---|
2368 | static BOOLEAN jjGCD_I(leftv res, leftv u, leftv v) |
---|
2369 | { |
---|
2370 | int uu=(int)(long)u->Data();int vv=(int)(long)v->Data(); |
---|
2371 | int p0=ABS(uu),p1=ABS(vv); |
---|
2372 | int r; |
---|
2373 | while ( p1!=0 ) |
---|
2374 | { |
---|
2375 | r=p0 % p1; |
---|
2376 | p0 = p1; p1 = r; |
---|
2377 | } |
---|
2378 | res->rtyp=INT_CMD; |
---|
2379 | res->data=(char *)(long)p0; |
---|
2380 | return FALSE; |
---|
2381 | } |
---|
2382 | static BOOLEAN jjGCD_BI(leftv res, leftv u, leftv v) |
---|
2383 | { |
---|
2384 | number n1 = (number) u->Data(); |
---|
2385 | number n2 = (number) v->Data(); |
---|
2386 | res->data = n_Gcd(n1,n2,coeffs_BIGINT); |
---|
2387 | return FALSE; |
---|
2388 | } |
---|
2389 | static BOOLEAN jjGCD_N(leftv res, leftv u, leftv v) |
---|
2390 | { |
---|
2391 | number a=(number) u->Data(); |
---|
2392 | number b=(number) v->Data(); |
---|
2393 | if (nIsZero(a)) |
---|
2394 | { |
---|
2395 | if (nIsZero(b)) res->data=(char *)nInit(1); |
---|
2396 | else res->data=(char *)nCopy(b); |
---|
2397 | } |
---|
2398 | else |
---|
2399 | { |
---|
2400 | if (nIsZero(b)) res->data=(char *)nCopy(a); |
---|
2401 | //else res->data=(char *)n_Gcd(a, b, currRing->cf); |
---|
2402 | else res->data=(char *)n_SubringGcd(a, b, currRing->cf); |
---|
2403 | } |
---|
2404 | return FALSE; |
---|
2405 | } |
---|
2406 | static BOOLEAN jjGCD_P(leftv res, leftv u, leftv v) |
---|
2407 | { |
---|
2408 | res->data=(void *)singclap_gcd((poly)(u->CopyD(POLY_CMD)), |
---|
2409 | (poly)(v->CopyD(POLY_CMD)),currRing); |
---|
2410 | return FALSE; |
---|
2411 | } |
---|
2412 | static BOOLEAN jjHILBERT2(leftv res, leftv u, leftv v) |
---|
2413 | { |
---|
2414 | #ifdef HAVE_RINGS |
---|
2415 | if (rField_is_Z(currRing)) |
---|
2416 | { |
---|
2417 | PrintS("// NOTE: computation of Hilbert series etc. is being\n"); |
---|
2418 | PrintS("// performed for generic fibre, that is, over Q\n"); |
---|
2419 | } |
---|
2420 | #endif |
---|
2421 | assumeStdFlag(u); |
---|
2422 | intvec *module_w=(intvec*)atGet(u,"isHomog",INTVEC_CMD); |
---|
2423 | intvec *iv=hFirstSeries((ideal)u->Data(),module_w,currRing->qideal); |
---|
2424 | if (errorreported) return TRUE; |
---|
2425 | |
---|
2426 | switch((int)(long)v->Data()) |
---|
2427 | { |
---|
2428 | case 1: |
---|
2429 | res->data=(void *)iv; |
---|
2430 | return FALSE; |
---|
2431 | case 2: |
---|
2432 | res->data=(void *)hSecondSeries(iv); |
---|
2433 | delete iv; |
---|
2434 | return FALSE; |
---|
2435 | } |
---|
2436 | delete iv; |
---|
2437 | WerrorS(feNotImplemented); |
---|
2438 | return TRUE; |
---|
2439 | } |
---|
2440 | static BOOLEAN jjHOMOG_P(leftv res, leftv u, leftv v) |
---|
2441 | { |
---|
2442 | int i=pVar((poly)v->Data()); |
---|
2443 | if (i==0) |
---|
2444 | { |
---|
2445 | WerrorS("ringvar expected"); |
---|
2446 | return TRUE; |
---|
2447 | } |
---|
2448 | poly p=pOne(); pSetExp(p,i,1); pSetm(p); |
---|
2449 | int d=pWTotaldegree(p); |
---|
2450 | pLmDelete(p); |
---|
2451 | if (d==1) |
---|
2452 | res->data = (char *)p_Homogen((poly)u->Data(), i, currRing); |
---|
2453 | else |
---|
2454 | WerrorS("variable must have weight 1"); |
---|
2455 | return (d!=1); |
---|
2456 | } |
---|
2457 | static BOOLEAN jjHOMOG_ID(leftv res, leftv u, leftv v) |
---|
2458 | { |
---|
2459 | int i=pVar((poly)v->Data()); |
---|
2460 | if (i==0) |
---|
2461 | { |
---|
2462 | WerrorS("ringvar expected"); |
---|
2463 | return TRUE; |
---|
2464 | } |
---|
2465 | pFDegProc deg; |
---|
2466 | if (currRing->pLexOrder && (currRing->order[0]==ringorder_lp)) |
---|
2467 | deg=p_Totaldegree; |
---|
2468 | else |
---|
2469 | deg=currRing->pFDeg; |
---|
2470 | poly p=pOne(); pSetExp(p,i,1); pSetm(p); |
---|
2471 | int d=deg(p,currRing); |
---|
2472 | pLmDelete(p); |
---|
2473 | if (d==1) |
---|
2474 | res->data = (char *)id_Homogen((ideal)u->Data(), i, currRing); |
---|
2475 | else |
---|
2476 | WerrorS("variable must have weight 1"); |
---|
2477 | return (d!=1); |
---|
2478 | } |
---|
2479 | static BOOLEAN jjHOMOG1_W(leftv res, leftv v, leftv u) |
---|
2480 | { |
---|
2481 | intvec *w=new intvec(rVar(currRing)); |
---|
2482 | intvec *vw=(intvec*)u->Data(); |
---|
2483 | ideal v_id=(ideal)v->Data(); |
---|
2484 | pFDegProc save_FDeg=currRing->pFDeg; |
---|
2485 | pLDegProc save_LDeg=currRing->pLDeg; |
---|
2486 | BOOLEAN save_pLexOrder=currRing->pLexOrder; |
---|
2487 | currRing->pLexOrder=FALSE; |
---|
2488 | kHomW=vw; |
---|
2489 | kModW=w; |
---|
2490 | pSetDegProcs(currRing,kHomModDeg); |
---|
2491 | res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w); |
---|
2492 | currRing->pLexOrder=save_pLexOrder; |
---|
2493 | kHomW=NULL; |
---|
2494 | kModW=NULL; |
---|
2495 | pRestoreDegProcs(currRing,save_FDeg,save_LDeg); |
---|
2496 | if (w!=NULL) delete w; |
---|
2497 | return FALSE; |
---|
2498 | } |
---|
2499 | static BOOLEAN jjINDEPSET2(leftv res, leftv u, leftv v) |
---|
2500 | { |
---|
2501 | assumeStdFlag(u); |
---|
2502 | res->data=(void *)scIndIndset((ideal)(u->Data()),(int)(long)(v->Data()), |
---|
2503 | currRing->qideal); |
---|
2504 | return FALSE; |
---|
2505 | } |
---|
2506 | static BOOLEAN jjINTERSECT(leftv res, leftv u, leftv v) |
---|
2507 | { |
---|
2508 | res->data=(char *)idSect((ideal)u->Data(),(ideal)v->Data()); |
---|
2509 | if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD); |
---|
2510 | return FALSE; |
---|
2511 | } |
---|
2512 | static BOOLEAN jjINTERPOLATION (leftv res, leftv l, leftv v) |
---|
2513 | { |
---|
2514 | const lists L = (lists)l->Data(); |
---|
2515 | const int n = L->nr; assume (n >= 0); |
---|
2516 | std::vector<ideal> V(n + 1); |
---|
2517 | |
---|
2518 | for(int i = n; i >= 0; i--) V[i] = (ideal)(L->m[i].Data()); |
---|
2519 | |
---|
2520 | res->data=interpolation(V, (intvec*)v->Data()); |
---|
2521 | setFlag(res,FLAG_STD); |
---|
2522 | return errorreported; |
---|
2523 | } |
---|
2524 | static BOOLEAN jjJanetBasis2(leftv res, leftv u, leftv v) |
---|
2525 | { |
---|
2526 | extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag); |
---|
2527 | return jjStdJanetBasis(res,u,(int)(long)v->Data()); |
---|
2528 | } |
---|
2529 | |
---|
2530 | static BOOLEAN jjJanetBasis(leftv res, leftv v) |
---|
2531 | { |
---|
2532 | extern BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag); |
---|
2533 | return jjStdJanetBasis(res,v,0); |
---|
2534 | } |
---|
2535 | static BOOLEAN jjJET_P(leftv res, leftv u, leftv v) |
---|
2536 | { |
---|
2537 | res->data = (char *)pJet((poly)u->CopyD(), (int)(long)v->Data()); |
---|
2538 | return FALSE; |
---|
2539 | } |
---|
2540 | static BOOLEAN jjJET_ID(leftv res, leftv u, leftv v) |
---|
2541 | { |
---|
2542 | res->data = (char *)id_Jet((ideal)u->Data(),(int)(long)v->Data(),currRing); |
---|
2543 | return FALSE; |
---|
2544 | } |
---|
2545 | static BOOLEAN jjKBASE2(leftv res, leftv u, leftv v) |
---|
2546 | { |
---|
2547 | assumeStdFlag(u); |
---|
2548 | intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
2549 | res->data = (char *)scKBase((int)(long)v->Data(), |
---|
2550 | (ideal)(u->Data()),currRing->qideal, w_u); |
---|
2551 | if (w_u!=NULL) |
---|
2552 | { |
---|
2553 | atSet(res,omStrDup("isHomog"),ivCopy(w_u),INTVEC_CMD); |
---|
2554 | } |
---|
2555 | return FALSE; |
---|
2556 | } |
---|
2557 | static BOOLEAN jjPREIMAGE(leftv res, leftv u, leftv v, leftv w); |
---|
2558 | static BOOLEAN jjKERNEL(leftv res, leftv u, leftv v) |
---|
2559 | { |
---|
2560 | return jjPREIMAGE(res,u,v,NULL); |
---|
2561 | } |
---|
2562 | static BOOLEAN jjKoszul(leftv res, leftv u, leftv v) |
---|
2563 | { |
---|
2564 | return mpKoszul(res, u,v,NULL); |
---|
2565 | } |
---|
2566 | static BOOLEAN jjKoszul_Id(leftv res, leftv u, leftv v) |
---|
2567 | { |
---|
2568 | sleftv h; |
---|
2569 | memset(&h,0,sizeof(sleftv)); |
---|
2570 | h.rtyp=INT_CMD; |
---|
2571 | h.data=(void *)(long)IDELEMS((ideal)v->Data()); |
---|
2572 | return mpKoszul(res, u, &h, v); |
---|
2573 | } |
---|
2574 | static BOOLEAN jjLIFT(leftv res, leftv u, leftv v) |
---|
2575 | { |
---|
2576 | int ul= IDELEMS((ideal)u->Data()); |
---|
2577 | int vl= IDELEMS((ideal)v->Data()); |
---|
2578 | ideal m = idLift((ideal)u->Data(),(ideal)v->Data(),NULL,FALSE, |
---|
2579 | hasFlag(u,FLAG_STD)); |
---|
2580 | if (m==NULL) return TRUE; |
---|
2581 | res->data = (char *)id_Module2formatedMatrix(m,ul,vl,currRing); |
---|
2582 | return FALSE; |
---|
2583 | } |
---|
2584 | static BOOLEAN jjLIFTSTD(leftv res, leftv u, leftv v) |
---|
2585 | { |
---|
2586 | if ((v->rtyp!=IDHDL)||(v->e!=NULL)) return TRUE; |
---|
2587 | idhdl h=(idhdl)v->data; |
---|
2588 | // CopyD for IDEAL_CMD and MODUL_CMD are identical: |
---|
2589 | res->data = (char *)idLiftStd((ideal)u->Data(), |
---|
2590 | &(h->data.umatrix),testHomog); |
---|
2591 | setFlag(res,FLAG_STD); v->flag=0; |
---|
2592 | return FALSE; |
---|
2593 | } |
---|
2594 | static BOOLEAN jjLOAD2(leftv /*res*/, leftv/* LIB */ , leftv v) |
---|
2595 | { |
---|
2596 | return jjLOAD((char*)v->Data(),TRUE); |
---|
2597 | } |
---|
2598 | static BOOLEAN jjLOAD_E(leftv /*res*/, leftv v, leftv u) |
---|
2599 | { |
---|
2600 | char * s=(char *)u->Data(); |
---|
2601 | if(strcmp(s, "with")==0) |
---|
2602 | return jjLOAD((char*)v->Data(), TRUE); |
---|
2603 | if (strcmp(s,"try")==0) |
---|
2604 | return jjLOAD_TRY((char*)v->Data()); |
---|
2605 | WerrorS("invalid second argument"); |
---|
2606 | WerrorS("load(\"libname\" [,option]);"); |
---|
2607 | return TRUE; |
---|
2608 | } |
---|
2609 | static BOOLEAN jjMODULO(leftv res, leftv u, leftv v) |
---|
2610 | { |
---|
2611 | intvec *w_u=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
2612 | tHomog hom=testHomog; |
---|
2613 | if (w_u!=NULL) |
---|
2614 | { |
---|
2615 | //PrintS("modulo: wu:");w_u->show(INTVEC_CMD);PrintLn(); |
---|
2616 | w_u=ivCopy(w_u); |
---|
2617 | hom=isHomog; |
---|
2618 | } |
---|
2619 | //else PrintS("modulo: wu:none\n"); |
---|
2620 | intvec *w_v=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
2621 | if (w_v!=NULL) |
---|
2622 | { |
---|
2623 | //PrintS("modulo: wv:");w_v->show(INTVEC_CMD);PrintLn(); |
---|
2624 | w_v=ivCopy(w_v); |
---|
2625 | hom=isHomog; |
---|
2626 | } |
---|
2627 | //else PrintS("modulo: wv:none\n"); |
---|
2628 | if ((w_u!=NULL) && (w_v==NULL)) |
---|
2629 | w_v=ivCopy(w_u); |
---|
2630 | if ((w_v!=NULL) && (w_u==NULL)) |
---|
2631 | w_u=ivCopy(w_v); |
---|
2632 | ideal u_id=(ideal)u->Data(); |
---|
2633 | ideal v_id=(ideal)v->Data(); |
---|
2634 | if (w_u!=NULL) |
---|
2635 | { |
---|
2636 | if ((*w_u).compare((w_v))!=0) |
---|
2637 | { |
---|
2638 | WarnS("incompatible weights"); |
---|
2639 | delete w_u; w_u=NULL; |
---|
2640 | hom=testHomog; |
---|
2641 | } |
---|
2642 | else |
---|
2643 | { |
---|
2644 | if ((!idTestHomModule(u_id,currRing->qideal,w_v)) |
---|
2645 | || (!idTestHomModule(v_id,currRing->qideal,w_v))) |
---|
2646 | { |
---|
2647 | WarnS("wrong weights"); |
---|
2648 | delete w_u; w_u=NULL; |
---|
2649 | hom=testHomog; |
---|
2650 | } |
---|
2651 | } |
---|
2652 | } |
---|
2653 | res->data = (char *)idModulo(u_id,v_id ,hom,&w_u); |
---|
2654 | if (w_u!=NULL) |
---|
2655 | { |
---|
2656 | atSet(res,omStrDup("isHomog"),w_u,INTVEC_CMD); |
---|
2657 | } |
---|
2658 | delete w_v; |
---|
2659 | //if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD); |
---|
2660 | return FALSE; |
---|
2661 | } |
---|
2662 | static BOOLEAN jjMOD_BI(leftv res, leftv u, leftv v) |
---|
2663 | { |
---|
2664 | number q=(number)v->Data(); |
---|
2665 | if (n_IsZero(q,coeffs_BIGINT)) |
---|
2666 | { |
---|
2667 | WerrorS(ii_div_by_0); |
---|
2668 | return TRUE; |
---|
2669 | } |
---|
2670 | res->data =(char *) n_IntMod((number)u->Data(),q,coeffs_BIGINT); |
---|
2671 | return FALSE; |
---|
2672 | } |
---|
2673 | static BOOLEAN jjMOD_N(leftv res, leftv u, leftv v) |
---|
2674 | { |
---|
2675 | number q=(number)v->Data(); |
---|
2676 | if (nIsZero(q)) |
---|
2677 | { |
---|
2678 | WerrorS(ii_div_by_0); |
---|
2679 | return TRUE; |
---|
2680 | } |
---|
2681 | res->data =(char *) n_IntMod((number)u->Data(),q,currRing->cf); |
---|
2682 | return FALSE; |
---|
2683 | } |
---|
2684 | static BOOLEAN jjMOD_P(leftv res, leftv u, leftv v) |
---|
2685 | { |
---|
2686 | poly q=(poly)v->Data(); |
---|
2687 | if (q==NULL) |
---|
2688 | { |
---|
2689 | WerrorS(ii_div_by_0); |
---|
2690 | return TRUE; |
---|
2691 | } |
---|
2692 | poly p=(poly)(u->Data()); |
---|
2693 | if (p==NULL) |
---|
2694 | { |
---|
2695 | res->data=NULL; |
---|
2696 | return FALSE; |
---|
2697 | } |
---|
2698 | res->data=(void*)(singclap_pmod(p /*(poly)(u->Data())*/ , |
---|
2699 | q /*(poly)(v->Data())*/ ,currRing)); |
---|
2700 | return FALSE; |
---|
2701 | } |
---|
2702 | static BOOLEAN jjMONITOR2(leftv res, leftv u,leftv v); |
---|
2703 | static BOOLEAN jjMONITOR1(leftv res, leftv v) |
---|
2704 | { |
---|
2705 | return jjMONITOR2(res,v,NULL); |
---|
2706 | } |
---|
2707 | static BOOLEAN jjMONITOR2(leftv, leftv u,leftv v) |
---|
2708 | { |
---|
2709 | #if 0 |
---|
2710 | char *opt=(char *)v->Data(); |
---|
2711 | int mode=0; |
---|
2712 | while(*opt!='\0') |
---|
2713 | { |
---|
2714 | if (*opt=='i') mode |= SI_PROT_I; |
---|
2715 | else if (*opt=='o') mode |= SI_PROT_O; |
---|
2716 | opt++; |
---|
2717 | } |
---|
2718 | monitor((char *)(u->Data()),mode); |
---|
2719 | #else |
---|
2720 | si_link l=(si_link)u->Data(); |
---|
2721 | if (slOpen(l,SI_LINK_WRITE,u)) return TRUE; |
---|
2722 | if(strcmp(l->m->type,"ASCII")!=0) |
---|
2723 | { |
---|
2724 | Werror("ASCII link required, not `%s`",l->m->type); |
---|
2725 | slClose(l); |
---|
2726 | return TRUE; |
---|
2727 | } |
---|
2728 | SI_LINK_SET_CLOSE_P(l); // febase handles the FILE* |
---|
2729 | if ( l->name[0]!='\0') // "" is the stop condition |
---|
2730 | { |
---|
2731 | const char *opt; |
---|
2732 | int mode=0; |
---|
2733 | if (v==NULL) opt=(const char*)"i"; |
---|
2734 | else opt=(const char *)v->Data(); |
---|
2735 | while(*opt!='\0') |
---|
2736 | { |
---|
2737 | if (*opt=='i') mode |= SI_PROT_I; |
---|
2738 | else if (*opt=='o') mode |= SI_PROT_O; |
---|
2739 | opt++; |
---|
2740 | } |
---|
2741 | monitor((FILE *)l->data,mode); |
---|
2742 | } |
---|
2743 | else |
---|
2744 | monitor(NULL,0); |
---|
2745 | return FALSE; |
---|
2746 | #endif |
---|
2747 | } |
---|
2748 | static BOOLEAN jjMONOM(leftv res, leftv v) |
---|
2749 | { |
---|
2750 | intvec *iv=(intvec *)v->Data(); |
---|
2751 | poly p=pOne(); |
---|
2752 | int e; |
---|
2753 | BOOLEAN err=FALSE; |
---|
2754 | for(unsigned i=si_min(currRing->N,iv->length()); i>0; i--) |
---|
2755 | { |
---|
2756 | e=(*iv)[i-1]; |
---|
2757 | if (e>=0) pSetExp(p,i,e); |
---|
2758 | else err=TRUE; |
---|
2759 | } |
---|
2760 | if (iv->length()==(currRing->N+1)) |
---|
2761 | { |
---|
2762 | res->rtyp=VECTOR_CMD; |
---|
2763 | e=(*iv)[currRing->N]; |
---|
2764 | if (e>=0) pSetComp(p,e); |
---|
2765 | else err=TRUE; |
---|
2766 | } |
---|
2767 | pSetm(p); |
---|
2768 | res->data=(char*)p; |
---|
2769 | if(err) { pDelete(&p); WerrorS("no negative exponent allowed"); } |
---|
2770 | return err; |
---|
2771 | } |
---|
2772 | static BOOLEAN jjNEWSTRUCT2(leftv, leftv u, leftv v) |
---|
2773 | { |
---|
2774 | // u: the name of the new type |
---|
2775 | // v: the elements |
---|
2776 | const char *s=(const char *)u->Data(); |
---|
2777 | newstruct_desc d=NULL; |
---|
2778 | if (strlen(s)>=2) |
---|
2779 | { |
---|
2780 | d=newstructFromString((const char *)v->Data()); |
---|
2781 | if (d!=NULL) newstruct_setup(s,d); |
---|
2782 | } |
---|
2783 | else WerrorS("name of newstruct must be longer than 1 character"); |
---|
2784 | return d==NULL; |
---|
2785 | } |
---|
2786 | static BOOLEAN jjPARSTR2(leftv res, leftv u, leftv v) |
---|
2787 | { |
---|
2788 | idhdl h=(idhdl)u->data; |
---|
2789 | int i=(int)(long)v->Data(); |
---|
2790 | int p=0; |
---|
2791 | if ((0<i) |
---|
2792 | && (rParameter(IDRING(h))!=NULL) |
---|
2793 | && (i<=(p=rPar(IDRING(h))))) |
---|
2794 | res->data=omStrDup(rParameter(IDRING(h))[i-1]); |
---|
2795 | else |
---|
2796 | { |
---|
2797 | Werror("par number %d out of range 1..%d",i,p); |
---|
2798 | return TRUE; |
---|
2799 | } |
---|
2800 | return FALSE; |
---|
2801 | } |
---|
2802 | #ifdef HAVE_PLURAL |
---|
2803 | static BOOLEAN jjPlural_num_poly(leftv res, leftv a, leftv b) |
---|
2804 | { |
---|
2805 | if( currRing->qideal != NULL ) |
---|
2806 | { |
---|
2807 | WerrorS("basering must NOT be a qring!"); |
---|
2808 | return TRUE; |
---|
2809 | } |
---|
2810 | |
---|
2811 | if (iiOp==NCALGEBRA_CMD) |
---|
2812 | { |
---|
2813 | return nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),currRing,false,true,false,currRing); |
---|
2814 | } |
---|
2815 | else |
---|
2816 | { |
---|
2817 | ring r=rCopy(currRing); |
---|
2818 | BOOLEAN result=nc_CallPlural(NULL,NULL,(poly)a->Data(),(poly)b->Data(),r,false,true,false,currRing); |
---|
2819 | res->data=r; |
---|
2820 | return result; |
---|
2821 | } |
---|
2822 | } |
---|
2823 | static BOOLEAN jjPlural_num_mat(leftv res, leftv a, leftv b) |
---|
2824 | { |
---|
2825 | if( currRing->qideal != NULL ) |
---|
2826 | { |
---|
2827 | WerrorS("basering must NOT be a qring!"); |
---|
2828 | return TRUE; |
---|
2829 | } |
---|
2830 | |
---|
2831 | if (iiOp==NCALGEBRA_CMD) |
---|
2832 | { |
---|
2833 | return nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,currRing,false,true,false,currRing); |
---|
2834 | } |
---|
2835 | else |
---|
2836 | { |
---|
2837 | ring r=rCopy(currRing); |
---|
2838 | BOOLEAN result=nc_CallPlural(NULL,(matrix)b->Data(),(poly)a->Data(),NULL,r,false,true,false,currRing); |
---|
2839 | res->data=r; |
---|
2840 | return result; |
---|
2841 | } |
---|
2842 | } |
---|
2843 | static BOOLEAN jjPlural_mat_poly(leftv res, leftv a, leftv b) |
---|
2844 | { |
---|
2845 | if( currRing->qideal != NULL ) |
---|
2846 | { |
---|
2847 | WerrorS("basering must NOT be a qring!"); |
---|
2848 | return TRUE; |
---|
2849 | } |
---|
2850 | |
---|
2851 | if (iiOp==NCALGEBRA_CMD) |
---|
2852 | { |
---|
2853 | return nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),currRing,false,true,false,currRing); |
---|
2854 | } |
---|
2855 | else |
---|
2856 | { |
---|
2857 | ring r=rCopy(currRing); |
---|
2858 | BOOLEAN result=nc_CallPlural((matrix)a->Data(),NULL,NULL,(poly)b->Data(),r,false,true,false,currRing); |
---|
2859 | res->data=r; |
---|
2860 | return result; |
---|
2861 | } |
---|
2862 | } |
---|
2863 | static BOOLEAN jjPlural_mat_mat(leftv res, leftv a, leftv b) |
---|
2864 | { |
---|
2865 | if( currRing->qideal != NULL ) |
---|
2866 | { |
---|
2867 | WerrorS("basering must NOT be a qring!"); |
---|
2868 | return TRUE; |
---|
2869 | } |
---|
2870 | |
---|
2871 | if (iiOp==NCALGEBRA_CMD) |
---|
2872 | { |
---|
2873 | return nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,currRing,false,true,false,currRing); |
---|
2874 | } |
---|
2875 | else |
---|
2876 | { |
---|
2877 | ring r=rCopy(currRing); |
---|
2878 | BOOLEAN result=nc_CallPlural((matrix)a->Data(),(matrix)b->Data(),NULL,NULL,r,false,true,false,currRing); |
---|
2879 | res->data=r; |
---|
2880 | return result; |
---|
2881 | } |
---|
2882 | } |
---|
2883 | static BOOLEAN jjBRACKET(leftv res, leftv a, leftv b) |
---|
2884 | { |
---|
2885 | res->data=NULL; |
---|
2886 | |
---|
2887 | if (rIsPluralRing(currRing) || rIsLPRing(currRing)) |
---|
2888 | { |
---|
2889 | const poly q = (poly)b->Data(); |
---|
2890 | |
---|
2891 | if( q != NULL ) |
---|
2892 | { |
---|
2893 | if( (poly)a->Data() != NULL ) |
---|
2894 | { |
---|
2895 | if (rIsPluralRing(currRing)) |
---|
2896 | { |
---|
2897 | poly p = (poly)a->CopyD(POLY_CMD); // p = copy! |
---|
2898 | res->data = nc_p_Bracket_qq(p,q, currRing); // p will be destroyed! |
---|
2899 | } |
---|
2900 | else if (rIsLPRing(currRing)) |
---|
2901 | { |
---|
2902 | const poly p = (poly)a->Data(); |
---|
2903 | res->data = pAdd(ppMult_qq(p,q), pNeg(ppMult_qq(q,p))); |
---|
2904 | } |
---|
2905 | } |
---|
2906 | } |
---|
2907 | } |
---|
2908 | return FALSE; |
---|
2909 | } |
---|
2910 | static BOOLEAN jjBRACKET_REC(leftv res, leftv a, leftv b, leftv c) |
---|
2911 | { |
---|
2912 | res->data=NULL; |
---|
2913 | |
---|
2914 | if (rIsLPRing(currRing) || rIsPluralRing(currRing)) |
---|
2915 | { |
---|
2916 | const poly q = (poly)b->Data(); |
---|
2917 | if(q != NULL) |
---|
2918 | { |
---|
2919 | if((poly)a->Data() != NULL) |
---|
2920 | { |
---|
2921 | const poly p = (poly)a->Data(); |
---|
2922 | int k=(int)(long)c->Data(); |
---|
2923 | if (k > 0) |
---|
2924 | { |
---|
2925 | poly qq = pCopy(q); |
---|
2926 | for (int i = 0; i < k; i++) |
---|
2927 | { |
---|
2928 | poly qq_ref = qq; |
---|
2929 | if (rIsLPRing(currRing)) |
---|
2930 | { |
---|
2931 | qq = pAdd(ppMult_qq(p,qq), pNeg(ppMult_qq(qq,p))); |
---|
2932 | } |
---|
2933 | else if (rIsPluralRing(currRing)) |
---|
2934 | { |
---|
2935 | qq = nc_p_Bracket_qq(pCopy(p), qq, currRing); |
---|
2936 | } |
---|
2937 | pDelete(&qq_ref); |
---|
2938 | if (qq == NULL) break; |
---|
2939 | } |
---|
2940 | res->data = qq; |
---|
2941 | } |
---|
2942 | else |
---|
2943 | { |
---|
2944 | Werror("invalid number of iterations"); |
---|
2945 | } |
---|
2946 | } |
---|
2947 | } |
---|
2948 | } |
---|
2949 | return FALSE; |
---|
2950 | } |
---|
2951 | static BOOLEAN jjOPPOSE(leftv res, leftv a, leftv b) |
---|
2952 | { |
---|
2953 | /* number, poly, vector, ideal, module, matrix */ |
---|
2954 | ring r = (ring)a->Data(); |
---|
2955 | if (r == currRing) |
---|
2956 | { |
---|
2957 | res->data = b->Data(); |
---|
2958 | res->rtyp = b->rtyp; |
---|
2959 | return FALSE; |
---|
2960 | } |
---|
2961 | if (!rIsLikeOpposite(currRing, r)) |
---|
2962 | { |
---|
2963 | Werror("%s is not an opposite ring to current ring",a->Fullname()); |
---|
2964 | return TRUE; |
---|
2965 | } |
---|
2966 | idhdl w; |
---|
2967 | if( ((w=r->idroot->get(b->Name(),myynest))!=NULL) && (b->e==NULL)) |
---|
2968 | { |
---|
2969 | int argtype = IDTYP(w); |
---|
2970 | switch (argtype) |
---|
2971 | { |
---|
2972 | case NUMBER_CMD: |
---|
2973 | { |
---|
2974 | /* since basefields are equal, we can apply nCopy */ |
---|
2975 | res->data = nCopy((number)IDDATA(w)); |
---|
2976 | res->rtyp = argtype; |
---|
2977 | break; |
---|
2978 | } |
---|
2979 | case POLY_CMD: |
---|
2980 | case VECTOR_CMD: |
---|
2981 | { |
---|
2982 | poly q = (poly)IDDATA(w); |
---|
2983 | res->data = pOppose(r,q,currRing); |
---|
2984 | res->rtyp = argtype; |
---|
2985 | break; |
---|
2986 | } |
---|
2987 | case IDEAL_CMD: |
---|
2988 | case MODUL_CMD: |
---|
2989 | { |
---|
2990 | ideal Q = (ideal)IDDATA(w); |
---|
2991 | res->data = idOppose(r,Q,currRing); |
---|
2992 | res->rtyp = argtype; |
---|
2993 | break; |
---|
2994 | } |
---|
2995 | case MATRIX_CMD: |
---|
2996 | { |
---|
2997 | ring save = currRing; |
---|
2998 | rChangeCurrRing(r); |
---|
2999 | matrix m = (matrix)IDDATA(w); |
---|
3000 | ideal Q = id_Matrix2Module(mp_Copy(m, currRing),currRing); |
---|
3001 | rChangeCurrRing(save); |
---|
3002 | ideal S = idOppose(r,Q,currRing); |
---|
3003 | id_Delete(&Q, r); |
---|
3004 | res->data = id_Module2Matrix(S,currRing); |
---|
3005 | res->rtyp = argtype; |
---|
3006 | break; |
---|
3007 | } |
---|
3008 | default: |
---|
3009 | { |
---|
3010 | WerrorS("unsupported type in oppose"); |
---|
3011 | return TRUE; |
---|
3012 | } |
---|
3013 | } |
---|
3014 | } |
---|
3015 | else |
---|
3016 | { |
---|
3017 | Werror("identifier %s not found in %s",b->Fullname(),a->Fullname()); |
---|
3018 | return TRUE; |
---|
3019 | } |
---|
3020 | return FALSE; |
---|
3021 | } |
---|
3022 | #endif /* HAVE_PLURAL */ |
---|
3023 | |
---|
3024 | static BOOLEAN jjQUOT(leftv res, leftv u, leftv v) |
---|
3025 | { |
---|
3026 | res->data = (char *)idQuot((ideal)u->Data(),(ideal)v->Data(), |
---|
3027 | hasFlag(u,FLAG_STD),u->Typ()==v->Typ()); |
---|
3028 | id_DelMultiples((ideal)(res->data),currRing); |
---|
3029 | if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD); |
---|
3030 | return FALSE; |
---|
3031 | } |
---|
3032 | static BOOLEAN jjRANDOM(leftv res, leftv u, leftv v) |
---|
3033 | { |
---|
3034 | int i=(int)(long)u->Data(); |
---|
3035 | int j=(int)(long)v->Data(); |
---|
3036 | if (j-i <0) {WerrorS("invalid range for random"); return TRUE;} |
---|
3037 | res->data =(char *)(long)((i > j) ? i : (siRand() % (j-i+1)) + i); |
---|
3038 | return FALSE; |
---|
3039 | } |
---|
3040 | static BOOLEAN jjRANK2(leftv res, leftv u, leftv v) |
---|
3041 | { |
---|
3042 | matrix m =(matrix)u->Data(); |
---|
3043 | int isRowEchelon = (int)(long)v->Data(); |
---|
3044 | if (isRowEchelon != 1) isRowEchelon = 0; |
---|
3045 | int rank = luRank(m, isRowEchelon); |
---|
3046 | res->data =(char *)(long)rank; |
---|
3047 | return FALSE; |
---|
3048 | } |
---|
3049 | static BOOLEAN jjREAD2(leftv res, leftv u, leftv v) |
---|
3050 | { |
---|
3051 | si_link l=(si_link)u->Data(); |
---|
3052 | leftv r=slRead(l,v); |
---|
3053 | if (r==NULL) |
---|
3054 | { |
---|
3055 | const char *s; |
---|
3056 | if ((l!=NULL)&&(l->name!=NULL)) s=l->name; |
---|
3057 | else s=sNoName_fe; |
---|
3058 | Werror("cannot read from `%s`",s); |
---|
3059 | return TRUE; |
---|
3060 | } |
---|
3061 | memcpy(res,r,sizeof(sleftv)); |
---|
3062 | omFreeBin((ADDRESS)r, sleftv_bin); |
---|
3063 | return FALSE; |
---|
3064 | } |
---|
3065 | static BOOLEAN jjREDUCE_P(leftv res, leftv u, leftv v) |
---|
3066 | { |
---|
3067 | ideal vi=(ideal)v->Data(); |
---|
3068 | if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing)) |
---|
3069 | assumeStdFlag(v); |
---|
3070 | res->data = (char *)kNF(vi,currRing->qideal,(poly)u->Data()); |
---|
3071 | return FALSE; |
---|
3072 | } |
---|
3073 | static BOOLEAN jjREDUCE_ID(leftv res, leftv u, leftv v) |
---|
3074 | { |
---|
3075 | ideal ui=(ideal)u->Data(); |
---|
3076 | ideal vi=(ideal)v->Data(); |
---|
3077 | if (currRing->qideal!=NULL || vi->ncols>1 || rIsPluralRing(currRing)) |
---|
3078 | assumeStdFlag(v); |
---|
3079 | res->data = (char *)kNF(vi,currRing->qideal,ui); |
---|
3080 | return FALSE; |
---|
3081 | } |
---|
3082 | static BOOLEAN jjRES(leftv res, leftv u, leftv v) |
---|
3083 | { |
---|
3084 | int maxl=(int)(long)v->Data(); |
---|
3085 | if (maxl<0) |
---|
3086 | { |
---|
3087 | WerrorS("length for res must not be negative"); |
---|
3088 | return TRUE; |
---|
3089 | } |
---|
3090 | syStrategy r; |
---|
3091 | intvec *weights=NULL; |
---|
3092 | int wmaxl=maxl; |
---|
3093 | ideal u_id=(ideal)u->Data(); |
---|
3094 | |
---|
3095 | maxl--; |
---|
3096 | if (/*(*/ maxl==-1 /*)*/) /*&& (iiOp!=MRES_CMD)*/ |
---|
3097 | { |
---|
3098 | maxl = currRing->N-1+2*(iiOp==MRES_CMD); |
---|
3099 | if (currRing->qideal!=NULL) |
---|
3100 | { |
---|
3101 | Warn( |
---|
3102 | "full resolution in a qring may be infinite, setting max length to %d", |
---|
3103 | maxl+1); |
---|
3104 | } |
---|
3105 | } |
---|
3106 | weights=(intvec*)atGet(u,"isHomog",INTVEC_CMD); |
---|
3107 | if (weights!=NULL) |
---|
3108 | { |
---|
3109 | if (!idTestHomModule(u_id,currRing->qideal,weights)) |
---|
3110 | { |
---|
3111 | WarnS("wrong weights given:");weights->show();PrintLn(); |
---|
3112 | weights=NULL; |
---|
3113 | } |
---|
3114 | } |
---|
3115 | intvec *ww=NULL; |
---|
3116 | int add_row_shift=0; |
---|
3117 | if (weights!=NULL) |
---|
3118 | { |
---|
3119 | ww=ivCopy(weights); |
---|
3120 | add_row_shift = ww->min_in(); |
---|
3121 | (*ww) -= add_row_shift; |
---|
3122 | } |
---|
3123 | if ((iiOp == RES_CMD) || (iiOp == MRES_CMD)) |
---|
3124 | { |
---|
3125 | r=syResolution(u_id,maxl, ww, iiOp==MRES_CMD); |
---|
3126 | } |
---|
3127 | else if (iiOp==SRES_CMD) |
---|
3128 | // r=sySchreyerResolvente(u_id,maxl+1,&l); |
---|
3129 | r=sySchreyer(u_id,maxl+1); |
---|
3130 | else if (iiOp == LRES_CMD) |
---|
3131 | { |
---|
3132 | int dummy; |
---|
3133 | if((currRing->qideal!=NULL)|| |
---|
3134 | (!idHomIdeal (u_id,NULL))) |
---|
3135 | { |
---|
3136 | WerrorS |
---|
3137 | ("`lres` not implemented for inhomogeneous input or qring"); |
---|
3138 | return TRUE; |
---|
3139 | } |
---|
3140 | if(currRing->N == 1) |
---|
3141 | WarnS("the current implementation of `lres` may not work in the case of a single variable"); |
---|
3142 | r=syLaScala3(u_id,&dummy); |
---|
3143 | } |
---|
3144 | else if (iiOp == KRES_CMD) |
---|
3145 | { |
---|
3146 | int dummy; |
---|
3147 | if((currRing->qideal!=NULL)|| |
---|
3148 | (!idHomIdeal (u_id,NULL))) |
---|
3149 | { |
---|
3150 | WerrorS |
---|
3151 | ("`kres` not implemented for inhomogeneous input or qring"); |
---|
3152 | return TRUE; |
---|
3153 | } |
---|
3154 | r=syKosz(u_id,&dummy); |
---|
3155 | } |
---|
3156 | else |
---|
3157 | { |
---|
3158 | int dummy; |
---|
3159 | if((currRing->qideal!=NULL)|| |
---|
3160 | (!idHomIdeal (u_id,NULL))) |
---|
3161 | { |
---|
3162 | WerrorS |
---|
3163 | ("`hres` not implemented for inhomogeneous input or qring"); |
---|
3164 | return TRUE; |
---|
3165 | } |
---|
3166 | ideal u_id_copy=idCopy(u_id); |
---|
3167 | idSkipZeroes(u_id_copy); |
---|
3168 | r=syHilb(u_id_copy,&dummy); |
---|
3169 | idDelete(&u_id_copy); |
---|
3170 | } |
---|
3171 | if (r==NULL) return TRUE; |
---|
3172 | if (r->list_length>wmaxl) |
---|
3173 | { |
---|
3174 | for(int i=wmaxl-1;i>=r->list_length;i--) |
---|
3175 | { |
---|
3176 | if (r->fullres[i]!=NULL) id_Delete(&r->fullres[i],currRing); |
---|
3177 | if (r->minres[i]!=NULL) id_Delete(&r->minres[i],currRing); |
---|
3178 | } |
---|
3179 | } |
---|
3180 | r->list_length=wmaxl; |
---|
3181 | res->data=(void *)r; |
---|
3182 | if ((weights!=NULL) && (ww!=NULL)) { delete ww; ww=NULL; } |
---|
3183 | if ((r->weights!=NULL) && (r->weights[0]!=NULL)) |
---|
3184 | { |
---|
3185 | ww=ivCopy(r->weights[0]); |
---|
3186 | if (weights!=NULL) (*ww) += add_row_shift; |
---|
3187 | atSet(res,omStrDup("isHomog"),ww,INTVEC_CMD); |
---|
3188 | } |
---|
3189 | else |
---|
3190 | { |
---|
3191 | if (weights!=NULL) |
---|
3192 | { |
---|
3193 | atSet(res,omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD); |
---|
3194 | } |
---|
3195 | } |
---|
3196 | |
---|
3197 | // test the La Scala case' output |
---|
3198 | assume( ((iiOp == LRES_CMD) || (iiOp == HRES_CMD)) == (r->syRing != NULL) ); |
---|
3199 | assume( (r->syRing != NULL) == (r->resPairs != NULL) ); |
---|
3200 | |
---|
3201 | if(iiOp != HRES_CMD) |
---|
3202 | assume( (r->minres != NULL) || (r->fullres != NULL) ); // is wrong for HRES_CMD... |
---|
3203 | else |
---|
3204 | assume( (r->orderedRes != NULL) || (r->res != NULL) ); // analog for hres... |
---|
3205 | |
---|
3206 | return FALSE; |
---|
3207 | } |
---|
3208 | static BOOLEAN jjPFAC2(leftv res, leftv u, leftv v) |
---|
3209 | { |
---|
3210 | number n1; int i; |
---|
3211 | |
---|
3212 | if ((u->Typ() == BIGINT_CMD) || |
---|
3213 | ((u->Typ() == NUMBER_CMD) && rField_is_Q(currRing))) |
---|
3214 | { |
---|
3215 | n1 = (number)u->CopyD(); |
---|
3216 | } |
---|
3217 | else if (u->Typ() == INT_CMD) |
---|
3218 | { |
---|
3219 | i = (int)(long)u->Data(); |
---|
3220 | n1 = n_Init(i, coeffs_BIGINT); |
---|
3221 | } |
---|
3222 | else |
---|
3223 | { |
---|
3224 | return TRUE; |
---|
3225 | } |
---|
3226 | |
---|
3227 | i = (int)(long)v->Data(); |
---|
3228 | |
---|
3229 | lists l = primeFactorisation(n1, i); |
---|
3230 | n_Delete(&n1, coeffs_BIGINT); |
---|
3231 | res->data = (char*)l; |
---|
3232 | return FALSE; |
---|
3233 | } |
---|
3234 | static BOOLEAN jjRMINUS(leftv res, leftv u, leftv v) |
---|
3235 | { |
---|
3236 | ring r=rMinusVar((ring)u->Data(),(char*)v->Data()); |
---|
3237 | res->data = (char *)r; |
---|
3238 | return r==NULL; |
---|
3239 | } |
---|
3240 | static BOOLEAN jjRPLUS(leftv res, leftv u, leftv v) |
---|
3241 | { |
---|
3242 | int left; |
---|
3243 | if (u->Typ()==RING_CMD) left=0; |
---|
3244 | else |
---|
3245 | { |
---|
3246 | leftv h=u;u=v;v=h; |
---|
3247 | left=1; |
---|
3248 | } |
---|
3249 | ring r=rPlusVar((ring)u->Data(),(char*)v->Data(),left); |
---|
3250 | res->data = (char *)r; |
---|
3251 | return r==NULL; |
---|
3252 | } |
---|
3253 | static BOOLEAN jjRSUM(leftv res, leftv u, leftv v) |
---|
3254 | { |
---|
3255 | ring r; |
---|
3256 | int i=rSum((ring)u->Data(),(ring)v->Data(),r); |
---|
3257 | res->data = (char *)r; |
---|
3258 | return (i==-1); |
---|
3259 | } |
---|
3260 | #define SIMPL_NORMALIZE 64 |
---|
3261 | #define SIMPL_LMDIV 32 |
---|
3262 | #define SIMPL_LMEQ 16 |
---|
3263 | #define SIMPL_MULT 8 |
---|
3264 | #define SIMPL_EQU 4 |
---|
3265 | #define SIMPL_NULL 2 |
---|
3266 | #define SIMPL_NORM 1 |
---|
3267 | static BOOLEAN jjSIMPL_ID(leftv res, leftv u, leftv v) |
---|
3268 | { |
---|
3269 | int sw = (int)(long)v->Data(); |
---|
3270 | // CopyD for IDEAL_CMD and MODUL_CMD are identical: |
---|
3271 | ideal id = (ideal)u->CopyD(IDEAL_CMD); |
---|
3272 | if (sw & SIMPL_LMDIV) |
---|
3273 | { |
---|
3274 | id_DelDiv(id,currRing); |
---|
3275 | } |
---|
3276 | if (sw & SIMPL_LMEQ) |
---|
3277 | { |
---|
3278 | id_DelLmEquals(id,currRing); |
---|
3279 | } |
---|
3280 | if (sw & SIMPL_MULT) |
---|
3281 | { |
---|
3282 | id_DelMultiples(id,currRing); |
---|
3283 | } |
---|
3284 | else if(sw & SIMPL_EQU) |
---|
3285 | { |
---|
3286 | id_DelEquals(id,currRing); |
---|
3287 | } |
---|
3288 | if (sw & SIMPL_NULL) |
---|
3289 | { |
---|
3290 | idSkipZeroes(id); |
---|
3291 | } |
---|
3292 | if (sw & SIMPL_NORM) |
---|
3293 | { |
---|
3294 | id_Norm(id,currRing); |
---|
3295 | } |
---|
3296 | if (sw & SIMPL_NORMALIZE) |
---|
3297 | { |
---|
3298 | id_Normalize(id,currRing); |
---|
3299 | } |
---|
3300 | res->data = (char * )id; |
---|
3301 | return FALSE; |
---|
3302 | } |
---|
3303 | EXTERN_VAR int singclap_factorize_retry; |
---|
3304 | static BOOLEAN jjSQR_FREE2(leftv res, leftv u, leftv dummy) |
---|
3305 | { |
---|
3306 | intvec *v=NULL; |
---|
3307 | int sw=(int)(long)dummy->Data(); |
---|
3308 | int fac_sw=sw; |
---|
3309 | if (sw<0) fac_sw=1; |
---|
3310 | singclap_factorize_retry=0; |
---|
3311 | ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, fac_sw, currRing); |
---|
3312 | if (f==NULL) |
---|
3313 | return TRUE; |
---|
3314 | switch(sw) |
---|
3315 | { |
---|
3316 | case 0: |
---|
3317 | case 2: |
---|
3318 | { |
---|
3319 | lists l=(lists)omAllocBin(slists_bin); |
---|
3320 | l->Init(2); |
---|
3321 | l->m[0].rtyp=IDEAL_CMD; |
---|
3322 | l->m[0].data=(void *)f; |
---|
3323 | l->m[1].rtyp=INTVEC_CMD; |
---|
3324 | l->m[1].data=(void *)v; |
---|
3325 | res->data=(void *)l; |
---|
3326 | res->rtyp=LIST_CMD; |
---|
3327 | return FALSE; |
---|
3328 | } |
---|
3329 | case 1: |
---|
3330 | res->data=(void *)f; |
---|
3331 | return FALSE; |
---|
3332 | case 3: |
---|
3333 | { |
---|
3334 | poly p=f->m[0]; |
---|
3335 | int i=IDELEMS(f); |
---|
3336 | f->m[0]=NULL; |
---|
3337 | while(i>1) |
---|
3338 | { |
---|
3339 | i--; |
---|
3340 | p=pMult(p,f->m[i]); |
---|
3341 | f->m[i]=NULL; |
---|
3342 | } |
---|
3343 | res->data=(void *)p; |
---|
3344 | res->rtyp=POLY_CMD; |
---|
3345 | } |
---|
3346 | return FALSE; |
---|
3347 | } |
---|
3348 | WerrorS("invalid switch"); |
---|
3349 | return FALSE; |
---|
3350 | } |
---|
3351 | static BOOLEAN jjSTATUS2(leftv res, leftv u, leftv v) |
---|
3352 | { |
---|
3353 | res->data = omStrDup(slStatus((si_link) u->Data(), (char *) v->Data())); |
---|
3354 | return FALSE; |
---|
3355 | } |
---|
3356 | static BOOLEAN jjSTATUS2L(leftv res, leftv u, leftv v) |
---|
3357 | { |
---|
3358 | res->data = (void *)(long)slStatusSsiL((lists) u->Data(), (int)(long) v->Data()); |
---|
3359 | //return (res->data== (void*)(long)-2); |
---|
3360 | return FALSE; |
---|
3361 | } |
---|
3362 | static BOOLEAN jjSIMPL_P(leftv res, leftv u, leftv v) |
---|
3363 | { |
---|
3364 | int sw = (int)(long)v->Data(); |
---|
3365 | // CopyD for POLY_CMD and VECTOR_CMD are identical: |
---|
3366 | poly p = (poly)u->CopyD(POLY_CMD); |
---|
3367 | if (sw & SIMPL_NORM) |
---|
3368 | { |
---|
3369 | pNorm(p); |
---|
3370 | } |
---|
3371 | if (sw & SIMPL_NORMALIZE) |
---|
3372 | { |
---|
3373 | p_Normalize(p,currRing); |
---|
3374 | } |
---|
3375 | res->data = (char * )p; |
---|
3376 | return FALSE; |
---|
3377 | } |
---|
3378 | static BOOLEAN jjSTD_HILB(leftv res, leftv u, leftv v) |
---|
3379 | { |
---|
3380 | ideal result; |
---|
3381 | intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
3382 | tHomog hom=testHomog; |
---|
3383 | ideal u_id=(ideal)(u->Data()); |
---|
3384 | if (w!=NULL) |
---|
3385 | { |
---|
3386 | if (!idTestHomModule(u_id,currRing->qideal,w)) |
---|
3387 | { |
---|
3388 | WarnS("wrong weights:");w->show();PrintLn(); |
---|
3389 | w=NULL; |
---|
3390 | } |
---|
3391 | else |
---|
3392 | { |
---|
3393 | w=ivCopy(w); |
---|
3394 | hom=isHomog; |
---|
3395 | } |
---|
3396 | } |
---|
3397 | result=kStd(u_id,currRing->qideal,hom,&w,(intvec *)v->Data()); |
---|
3398 | idSkipZeroes(result); |
---|
3399 | res->data = (char *)result; |
---|
3400 | setFlag(res,FLAG_STD); |
---|
3401 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
3402 | return FALSE; |
---|
3403 | } |
---|
3404 | static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v) |
---|
3405 | { |
---|
3406 | ideal result; |
---|
3407 | assumeStdFlag(u); |
---|
3408 | ideal i1=(ideal)(u->Data()); |
---|
3409 | int ii1=idElem(i1); /* size of i1 */ |
---|
3410 | ideal i0; |
---|
3411 | int r=v->Typ(); |
---|
3412 | if ((/*v->Typ()*/r==POLY_CMD) ||(r==VECTOR_CMD)) |
---|
3413 | { |
---|
3414 | poly p=(poly)v->Data(); |
---|
3415 | i0=idInit(1,i1->rank); |
---|
3416 | i0->m[0]=p; |
---|
3417 | i1=idSimpleAdd(i1,i0); // |
---|
3418 | memset(i0->m,0,sizeof(poly)*IDELEMS(i0)); |
---|
3419 | idDelete(&i0); |
---|
3420 | intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
3421 | tHomog hom=testHomog; |
---|
3422 | |
---|
3423 | if (w!=NULL) |
---|
3424 | { |
---|
3425 | if (!idTestHomModule(i1,currRing->qideal,w)) |
---|
3426 | { |
---|
3427 | // no warnung: this is legal, if i in std(i,p) |
---|
3428 | // is homogeneous, but p not |
---|
3429 | w=NULL; |
---|
3430 | } |
---|
3431 | else |
---|
3432 | { |
---|
3433 | w=ivCopy(w); |
---|
3434 | hom=isHomog; |
---|
3435 | } |
---|
3436 | } |
---|
3437 | BITSET save1; |
---|
3438 | SI_SAVE_OPT1(save1); |
---|
3439 | si_opt_1|=Sy_bit(OPT_SB_1); |
---|
3440 | /* ii1 appears to be the position of the first element of il that |
---|
3441 | does not belong to the old SB ideal */ |
---|
3442 | result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii1); |
---|
3443 | SI_RESTORE_OPT1(save1); |
---|
3444 | idDelete(&i1); |
---|
3445 | idSkipZeroes(result); |
---|
3446 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
3447 | res->data = (char *)result; |
---|
3448 | } |
---|
3449 | else /*IDEAL/MODULE*/ |
---|
3450 | { |
---|
3451 | i0=(ideal)v->CopyD(); |
---|
3452 | i1=idSimpleAdd(i1,i0); // |
---|
3453 | memset(i0->m,0,sizeof(poly)*IDELEMS(i0)); |
---|
3454 | idDelete(&i0); |
---|
3455 | intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
3456 | tHomog hom=testHomog; |
---|
3457 | |
---|
3458 | if (w!=NULL) |
---|
3459 | { |
---|
3460 | if (!idTestHomModule(i1,currRing->qideal,w)) |
---|
3461 | { |
---|
3462 | // no warnung: this is legal, if i in std(i,p) |
---|
3463 | // is homogeneous, but p not |
---|
3464 | w=NULL; |
---|
3465 | hom=isNotHomog; |
---|
3466 | } |
---|
3467 | else |
---|
3468 | { |
---|
3469 | w=ivCopy(w); |
---|
3470 | hom=isHomog; |
---|
3471 | } |
---|
3472 | } |
---|
3473 | BITSET save1; |
---|
3474 | SI_SAVE_OPT1(save1); |
---|
3475 | si_opt_1|=Sy_bit(OPT_SB_1); |
---|
3476 | /* ii1 appears to be the position of the first element of i1 that |
---|
3477 | does not belong to the old SB ideal */ |
---|
3478 | result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii1); |
---|
3479 | SI_RESTORE_OPT1(save1); |
---|
3480 | idDelete(&i1); |
---|
3481 | idSkipZeroes(result); |
---|
3482 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
3483 | res->data = (char *)result; |
---|
3484 | } |
---|
3485 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
3486 | return FALSE; |
---|
3487 | } |
---|
3488 | static BOOLEAN jjSYZ_2(leftv res, leftv u, leftv v) |
---|
3489 | { |
---|
3490 | // see jjSYZYGY |
---|
3491 | intvec *ww=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
3492 | intvec *w=NULL; |
---|
3493 | tHomog hom=testHomog; |
---|
3494 | ideal I=(ideal)u->Data(); |
---|
3495 | GbVariant alg=syGetAlgorithm((char*)v->Data(),currRing,I); |
---|
3496 | if (ww!=NULL) |
---|
3497 | { |
---|
3498 | if (idTestHomModule(I,currRing->qideal,ww)) |
---|
3499 | { |
---|
3500 | w=ivCopy(ww); |
---|
3501 | int add_row_shift=w->min_in(); |
---|
3502 | (*w)-=add_row_shift; |
---|
3503 | hom=isHomog; |
---|
3504 | } |
---|
3505 | else |
---|
3506 | { |
---|
3507 | //WarnS("wrong weights"); |
---|
3508 | delete ww; ww=NULL; |
---|
3509 | hom=testHomog; |
---|
3510 | } |
---|
3511 | } |
---|
3512 | else |
---|
3513 | { |
---|
3514 | if (u->Typ()==IDEAL_CMD) |
---|
3515 | if (idHomIdeal(I,currRing->qideal)) |
---|
3516 | hom=isHomog; |
---|
3517 | } |
---|
3518 | ideal S=idSyzygies(I,hom,&w,TRUE,FALSE,NULL,alg); |
---|
3519 | if (w!=NULL) delete w; |
---|
3520 | res->data = (char *)S; |
---|
3521 | if (hom==isHomog) |
---|
3522 | { |
---|
3523 | int vl=S->rank; |
---|
3524 | intvec *vv=new intvec(vl); |
---|
3525 | if ((u->Typ()==IDEAL_CMD)||(ww==NULL)) |
---|
3526 | { |
---|
3527 | for(int i=0;i<vl;i++) |
---|
3528 | { |
---|
3529 | if (I->m[i]!=NULL) |
---|
3530 | (*vv)[i]=p_Deg(I->m[i],currRing); |
---|
3531 | } |
---|
3532 | } |
---|
3533 | else |
---|
3534 | { |
---|
3535 | p_SetModDeg(ww, currRing); |
---|
3536 | for(int i=0;i<vl;i++) |
---|
3537 | { |
---|
3538 | if (I->m[i]!=NULL) |
---|
3539 | (*vv)[i]=currRing->pFDeg(I->m[i],currRing); |
---|
3540 | } |
---|
3541 | p_SetModDeg(NULL, currRing); |
---|
3542 | } |
---|
3543 | if (idTestHomModule(S,currRing->qideal,vv)) |
---|
3544 | atSet(res,omStrDup("isHomog"),vv,INTVEC_CMD); |
---|
3545 | else |
---|
3546 | delete vv; |
---|
3547 | } |
---|
3548 | if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD); |
---|
3549 | return FALSE; |
---|
3550 | } |
---|
3551 | static BOOLEAN jjTENSOR(leftv res, leftv u, leftv v) |
---|
3552 | { |
---|
3553 | ideal A=(ideal)u->Data(); |
---|
3554 | ideal B=(ideal)v->Data(); |
---|
3555 | res->data = (char *)sm_Tensor(A,B,currRing); |
---|
3556 | return FALSE; |
---|
3557 | } |
---|
3558 | static BOOLEAN jjTENSOR_Ma(leftv res, leftv u, leftv v) |
---|
3559 | { |
---|
3560 | sleftv tmp_u,tmp_v,tmp_res; |
---|
3561 | int index=iiTestConvert(MATRIX_CMD,SMATRIX_CMD,dConvertTypes); |
---|
3562 | iiConvert(MATRIX_CMD,SMATRIX_CMD,index,u,&tmp_u,dConvertTypes); |
---|
3563 | iiConvert(MATRIX_CMD,SMATRIX_CMD,index,v,&tmp_v,dConvertTypes); |
---|
3564 | tmp_res.Init(); |
---|
3565 | tmp_res.rtyp=SMATRIX_CMD; |
---|
3566 | BOOLEAN bo=jjTENSOR(&tmp_res,&tmp_u,&tmp_v); |
---|
3567 | if (!bo) |
---|
3568 | { |
---|
3569 | index=iiTestConvert(SMATRIX_CMD,MATRIX_CMD,dConvertTypes); |
---|
3570 | iiConvert(SMATRIX_CMD,MATRIX_CMD,index,&tmp_res,res,dConvertTypes); |
---|
3571 | } |
---|
3572 | tmp_u.CleanUp(); |
---|
3573 | tmp_v.CleanUp(); |
---|
3574 | tmp_res.CleanUp(); |
---|
3575 | return bo; |
---|
3576 | } |
---|
3577 | static BOOLEAN jjVARSTR2(leftv res, leftv u, leftv v) |
---|
3578 | { |
---|
3579 | idhdl h=(idhdl)u->data; |
---|
3580 | int i=(int)(long)v->Data(); |
---|
3581 | if ((0<i) && (i<=IDRING(h)->N)) |
---|
3582 | res->data=omStrDup(IDRING(h)->names[i-1]); |
---|
3583 | else |
---|
3584 | { |
---|
3585 | Werror("var number %d out of range 1..%d",i,IDRING(h)->N); |
---|
3586 | return TRUE; |
---|
3587 | } |
---|
3588 | return FALSE; |
---|
3589 | } |
---|
3590 | static BOOLEAN jjWAIT1ST2(leftv res, leftv u, leftv v) |
---|
3591 | { |
---|
3592 | // input: u: a list with links of type |
---|
3593 | // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch |
---|
3594 | // v: timeout for select in milliseconds |
---|
3595 | // or 0 for polling |
---|
3596 | // returns: ERROR (via Werror): timeout negative |
---|
3597 | // -1: the read state of all links is eof |
---|
3598 | // 0: timeout (or polling): none ready |
---|
3599 | // i>0: (at least) L[i] is ready |
---|
3600 | lists Lforks = (lists)u->Data(); |
---|
3601 | int t = (int)(long)v->Data(); |
---|
3602 | if(t < 0) |
---|
3603 | { |
---|
3604 | WerrorS("negative timeout"); return TRUE; |
---|
3605 | } |
---|
3606 | int i = slStatusSsiL(Lforks, t*1000); |
---|
3607 | if(i == -2) /* error */ |
---|
3608 | { |
---|
3609 | return TRUE; |
---|
3610 | } |
---|
3611 | res->data = (void*)(long)i; |
---|
3612 | return FALSE; |
---|
3613 | } |
---|
3614 | static BOOLEAN jjWAITALL2(leftv res, leftv u, leftv v) |
---|
3615 | { |
---|
3616 | // input: u: a list with links of type |
---|
3617 | // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch |
---|
3618 | // v: timeout for select in milliseconds |
---|
3619 | // or 0 for polling |
---|
3620 | // returns: ERROR (via Werror): timeout negative |
---|
3621 | // -1: the read state of all links is eof |
---|
3622 | // 0: timeout (or polling): none ready |
---|
3623 | // 1: all links are ready |
---|
3624 | // (caution: at least one is ready, but some maybe dead) |
---|
3625 | lists Lforks = (lists)u->CopyD(); |
---|
3626 | int timeout = 1000*(int)(long)v->Data(); |
---|
3627 | if(timeout < 0) |
---|
3628 | { |
---|
3629 | WerrorS("negative timeout"); return TRUE; |
---|
3630 | } |
---|
3631 | int t = getRTimer()/TIMER_RESOLUTION; // in seconds |
---|
3632 | int i; |
---|
3633 | int ret = -1; |
---|
3634 | for(unsigned nfinished = 0; nfinished < ((unsigned)Lforks->nr)+1; nfinished++) |
---|
3635 | { |
---|
3636 | i = slStatusSsiL(Lforks, timeout); |
---|
3637 | if(i > 0) /* Lforks[i] is ready */ |
---|
3638 | { |
---|
3639 | ret = 1; |
---|
3640 | Lforks->m[i-1].CleanUp(); |
---|
3641 | Lforks->m[i-1].rtyp=DEF_CMD; |
---|
3642 | Lforks->m[i-1].data=NULL; |
---|
3643 | timeout = si_max(0,timeout - 1000*(getRTimer()/TIMER_RESOLUTION - t)); |
---|
3644 | } |
---|
3645 | else /* terminate the for loop */ |
---|
3646 | { |
---|
3647 | if(i == -2) /* error */ |
---|
3648 | { |
---|
3649 | return TRUE; |
---|
3650 | } |
---|
3651 | if(i == 0) /* timeout */ |
---|
3652 | { |
---|
3653 | ret = 0; |
---|
3654 | } |
---|
3655 | break; |
---|
3656 | } |
---|
3657 | } |
---|
3658 | Lforks->Clean(); |
---|
3659 | res->data = (void*)(long)ret; |
---|
3660 | return FALSE; |
---|
3661 | } |
---|
3662 | static BOOLEAN jjWEDGE(leftv res, leftv u, leftv v) |
---|
3663 | { |
---|
3664 | res->data = (char *)mp_Wedge((matrix)u->Data(),(int)(long)v->Data(),currRing); |
---|
3665 | return FALSE; |
---|
3666 | } |
---|
3667 | #define jjWRONG2 (proc2)jjWRONG |
---|
3668 | #define jjWRONG3 (proc3)jjWRONG |
---|
3669 | static BOOLEAN jjWRONG(leftv, leftv) |
---|
3670 | { |
---|
3671 | return TRUE; |
---|
3672 | } |
---|
3673 | |
---|
3674 | /*=================== operations with 1 arg.: static proc =================*/ |
---|
3675 | /* must be ordered: first operations for chars (infix ops), |
---|
3676 | * then alphabetically */ |
---|
3677 | |
---|
3678 | static BOOLEAN jjDUMMY(leftv res, leftv u) |
---|
3679 | { |
---|
3680 | // res->data = (char *)u->CopyD(); |
---|
3681 | // also copy attributes: |
---|
3682 | res->Copy(u); |
---|
3683 | return FALSE; |
---|
3684 | } |
---|
3685 | static BOOLEAN jjNULL(leftv, leftv) |
---|
3686 | { |
---|
3687 | return FALSE; |
---|
3688 | } |
---|
3689 | //static BOOLEAN jjPLUSPLUS(leftv res, leftv u) |
---|
3690 | //{ |
---|
3691 | // res->data = (char *)((int)(long)u->Data()+1); |
---|
3692 | // return FALSE; |
---|
3693 | //} |
---|
3694 | //static BOOLEAN jjMINUSMINUS(leftv res, leftv u) |
---|
3695 | //{ |
---|
3696 | // res->data = (char *)((int)(long)u->Data()-1); |
---|
3697 | // return FALSE; |
---|
3698 | //} |
---|
3699 | static BOOLEAN jjPLUSPLUS(leftv, leftv u) |
---|
3700 | { |
---|
3701 | if (IDTYP((idhdl)u->data)==INT_CMD) |
---|
3702 | { |
---|
3703 | int i=IDINT((idhdl)u->data); |
---|
3704 | if (iiOp==PLUSPLUS) i++; |
---|
3705 | else i--; |
---|
3706 | IDDATA((idhdl)u->data)=(char *)(long)i; |
---|
3707 | return FALSE; |
---|
3708 | } |
---|
3709 | return TRUE; |
---|
3710 | } |
---|
3711 | static BOOLEAN jjUMINUS_BI(leftv res, leftv u) |
---|
3712 | { |
---|
3713 | number n=(number)u->CopyD(BIGINT_CMD); |
---|
3714 | n=n_InpNeg(n,coeffs_BIGINT); |
---|
3715 | res->data = (char *)n; |
---|
3716 | return FALSE; |
---|
3717 | } |
---|
3718 | static BOOLEAN jjUMINUS_I(leftv res, leftv u) |
---|
3719 | { |
---|
3720 | res->data = (char *)(-(long)u->Data()); |
---|
3721 | return FALSE; |
---|
3722 | } |
---|
3723 | static BOOLEAN jjUMINUS_N(leftv res, leftv u) |
---|
3724 | { |
---|
3725 | number n=(number)u->CopyD(NUMBER_CMD); |
---|
3726 | n=nInpNeg(n); |
---|
3727 | res->data = (char *)n; |
---|
3728 | return FALSE; |
---|
3729 | } |
---|
3730 | static BOOLEAN jjUMINUS_P(leftv res, leftv u) |
---|
3731 | { |
---|
3732 | res->data = (char *)pNeg((poly)u->CopyD(POLY_CMD)); |
---|
3733 | return FALSE; |
---|
3734 | } |
---|
3735 | static BOOLEAN jjUMINUS_MA(leftv res, leftv u) |
---|
3736 | { |
---|
3737 | poly m1=pISet(-1); |
---|
3738 | res->data = (char *)mp_MultP((matrix)u->CopyD(MATRIX_CMD),m1,currRing); |
---|
3739 | return FALSE; |
---|
3740 | } |
---|
3741 | static BOOLEAN jjUMINUS_IV(leftv res, leftv u) |
---|
3742 | { |
---|
3743 | intvec *iv=(intvec *)u->CopyD(INTVEC_CMD); |
---|
3744 | (*iv)*=(-1); |
---|
3745 | res->data = (char *)iv; |
---|
3746 | return FALSE; |
---|
3747 | } |
---|
3748 | static BOOLEAN jjUMINUS_BIM(leftv res, leftv u) |
---|
3749 | { |
---|
3750 | bigintmat *bim=(bigintmat *)u->CopyD(BIGINTMAT_CMD); |
---|
3751 | (*bim)*=(-1); |
---|
3752 | res->data = (char *)bim; |
---|
3753 | return FALSE; |
---|
3754 | } |
---|
3755 | // dummy for python_module.so and similiar |
---|
3756 | static BOOLEAN jjSetRing(leftv, leftv u) |
---|
3757 | { |
---|
3758 | if (u->rtyp==IDHDL) rSetHdl((idhdl)u->data); |
---|
3759 | else |
---|
3760 | { |
---|
3761 | ring r=(ring)u->Data(); |
---|
3762 | idhdl h=rFindHdl(r,NULL); |
---|
3763 | if (h==NULL) |
---|
3764 | { |
---|
3765 | char name_buffer[100]; |
---|
3766 | STATIC_VAR int ending=1000000; |
---|
3767 | ending++; |
---|
3768 | sprintf(name_buffer, "PYTHON_RING_VAR%d",ending); |
---|
3769 | h=enterid(name_buffer,0,RING_CMD,&IDROOT); |
---|
3770 | IDRING(h)=r; |
---|
3771 | r->ref++; |
---|
3772 | } |
---|
3773 | rSetHdl(h); |
---|
3774 | } |
---|
3775 | return FALSE; |
---|
3776 | } |
---|
3777 | static BOOLEAN jjPROC1(leftv res, leftv u) |
---|
3778 | { |
---|
3779 | return jjPROC(res,u,NULL); |
---|
3780 | } |
---|
3781 | static BOOLEAN jjBAREISS(leftv res, leftv v) |
---|
3782 | { |
---|
3783 | //matrix m=(matrix)v->Data(); |
---|
3784 | //lists l=mpBareiss(m,FALSE); |
---|
3785 | intvec *iv; |
---|
3786 | ideal m; |
---|
3787 | sm_CallBareiss((ideal)v->Data(),0,0,m,&iv, currRing); |
---|
3788 | lists l=(lists)omAllocBin(slists_bin); |
---|
3789 | l->Init(2); |
---|
3790 | l->m[0].rtyp=MODUL_CMD; |
---|
3791 | l->m[1].rtyp=INTVEC_CMD; |
---|
3792 | l->m[0].data=(void *)m; |
---|
3793 | l->m[1].data=(void *)iv; |
---|
3794 | res->data = (char *)l; |
---|
3795 | return FALSE; |
---|
3796 | } |
---|
3797 | //static BOOLEAN jjBAREISS_IM(leftv res, leftv v) |
---|
3798 | //{ |
---|
3799 | // intvec *m=(intvec *)v->CopyD(INTMAT_CMD); |
---|
3800 | // ivTriangMat(m); |
---|
3801 | // res->data = (char *)m; |
---|
3802 | // return FALSE; |
---|
3803 | //} |
---|
3804 | static BOOLEAN jjBAREISS_BIM(leftv res, leftv v) |
---|
3805 | { |
---|
3806 | bigintmat *b=(bigintmat*)v->CopyD(BIGINTMAT_CMD); |
---|
3807 | b->hnf(); |
---|
3808 | res->data=(char*)b; |
---|
3809 | return FALSE; |
---|
3810 | } |
---|
3811 | static BOOLEAN jjBI2N(leftv res, leftv u) |
---|
3812 | { |
---|
3813 | BOOLEAN bo=FALSE; |
---|
3814 | number n=(number)u->CopyD(); |
---|
3815 | nMapFunc nMap=n_SetMap(coeffs_BIGINT,currRing->cf); |
---|
3816 | if (nMap!=NULL) |
---|
3817 | res->data=nMap(n,coeffs_BIGINT,currRing->cf); |
---|
3818 | else |
---|
3819 | { |
---|
3820 | Werror("cannot convert bigint to cring %s", nCoeffName(currRing->cf)); |
---|
3821 | bo=TRUE; |
---|
3822 | } |
---|
3823 | n_Delete(&n,coeffs_BIGINT); |
---|
3824 | return bo; |
---|
3825 | } |
---|
3826 | static BOOLEAN jjBI2IM(leftv res, leftv u) |
---|
3827 | { |
---|
3828 | bigintmat *b=(bigintmat*)u->Data(); |
---|
3829 | res->data=(void *)bim2iv(b); |
---|
3830 | return FALSE; |
---|
3831 | } |
---|
3832 | static BOOLEAN jjBI2P(leftv res, leftv u) |
---|
3833 | { |
---|
3834 | sleftv tmp; |
---|
3835 | BOOLEAN bo=jjBI2N(&tmp,u); |
---|
3836 | if (!bo) |
---|
3837 | { |
---|
3838 | number n=(number) tmp.data; |
---|
3839 | if (nIsZero(n)) { res->data=NULL;nDelete(&n); } |
---|
3840 | else |
---|
3841 | { |
---|
3842 | res->data=(void *)pNSet(n); |
---|
3843 | } |
---|
3844 | } |
---|
3845 | return bo; |
---|
3846 | } |
---|
3847 | static BOOLEAN jjCALL1MANY(leftv res, leftv u) |
---|
3848 | { |
---|
3849 | return iiExprArithM(res,u,iiOp); |
---|
3850 | } |
---|
3851 | static BOOLEAN jjCHAR(leftv res, leftv v) |
---|
3852 | { |
---|
3853 | res->data = (char *)(long)rChar((ring)v->Data()); |
---|
3854 | return FALSE; |
---|
3855 | } |
---|
3856 | static BOOLEAN jjCOLS(leftv res, leftv v) |
---|
3857 | { |
---|
3858 | res->data = (char *)(long)MATCOLS((matrix)(v->Data())); |
---|
3859 | return FALSE; |
---|
3860 | } |
---|
3861 | static BOOLEAN jjCOLS_BIM(leftv res, leftv v) |
---|
3862 | { |
---|
3863 | res->data = (char *)(long)((bigintmat*)(v->Data()))->cols(); |
---|
3864 | return FALSE; |
---|
3865 | } |
---|
3866 | static BOOLEAN jjCOLS_IV(leftv res, leftv v) |
---|
3867 | { |
---|
3868 | res->data = (char *)(long)((intvec*)(v->Data()))->cols(); |
---|
3869 | return FALSE; |
---|
3870 | } |
---|
3871 | static BOOLEAN jjCONTENT(leftv res, leftv v) |
---|
3872 | { |
---|
3873 | // CopyD for POLY_CMD and VECTOR_CMD are identical: |
---|
3874 | poly p=(poly)v->CopyD(POLY_CMD); |
---|
3875 | if (p!=NULL) p_Cleardenom(p, currRing); |
---|
3876 | res->data = (char *)p; |
---|
3877 | return FALSE; |
---|
3878 | } |
---|
3879 | static BOOLEAN jjCOUNT_BI(leftv res, leftv v) |
---|
3880 | { |
---|
3881 | res->data = (char *)(long)n_Size((number)v->Data(),coeffs_BIGINT); |
---|
3882 | return FALSE; |
---|
3883 | } |
---|
3884 | static BOOLEAN jjCOUNT_BIM(leftv res, leftv v) |
---|
3885 | { |
---|
3886 | bigintmat* aa= (bigintmat *)v->Data(); |
---|
3887 | res->data = (char *)(long)(aa->rows()*aa->cols()); |
---|
3888 | return FALSE; |
---|
3889 | } |
---|
3890 | static BOOLEAN jjCOUNT_N(leftv res, leftv v) |
---|
3891 | { |
---|
3892 | res->data = (char *)(long)nSize((number)v->Data()); |
---|
3893 | return FALSE; |
---|
3894 | } |
---|
3895 | static BOOLEAN jjCOUNT_L(leftv res, leftv v) |
---|
3896 | { |
---|
3897 | lists l=(lists)v->Data(); |
---|
3898 | res->data = (char *)(long)(lSize(l)+1); |
---|
3899 | return FALSE; |
---|
3900 | } |
---|
3901 | static BOOLEAN jjCOUNT_M(leftv res, leftv v) |
---|
3902 | { |
---|
3903 | matrix m=(matrix)v->Data(); |
---|
3904 | res->data = (char *)(long)(MATROWS(m)*MATCOLS(m)); |
---|
3905 | return FALSE; |
---|
3906 | } |
---|
3907 | static BOOLEAN jjCOUNT_IV(leftv res, leftv v) |
---|
3908 | { |
---|
3909 | res->data = (char *)(long)((intvec*)(v->Data()))->length(); |
---|
3910 | return FALSE; |
---|
3911 | } |
---|
3912 | static BOOLEAN jjCOUNT_RG(leftv res, leftv v) |
---|
3913 | { |
---|
3914 | ring r=(ring)v->Data(); |
---|
3915 | int elems=-1; |
---|
3916 | if (rField_is_Zp(r)) elems=r->cf->ch; |
---|
3917 | else if (rField_is_GF(r)) elems=r->cf->m_nfCharQ; |
---|
3918 | else if (rField_is_Zp_a(r) && (r->cf->type==n_algExt)) |
---|
3919 | { |
---|
3920 | extern int ipower ( int b, int n ); /* factory/cf_util */ |
---|
3921 | elems=ipower(r->cf->ch,r->cf->extRing->pFDeg(r->cf->extRing->qideal->m[0],r->cf->extRing)); |
---|
3922 | } |
---|
3923 | res->data = (char *)(long)elems; |
---|
3924 | return FALSE; |
---|
3925 | } |
---|
3926 | static BOOLEAN jjDEG(leftv res, leftv v) |
---|
3927 | { |
---|
3928 | int dummy; |
---|
3929 | poly p=(poly)v->Data(); |
---|
3930 | if (p!=NULL) res->data = (char *)currRing->pLDeg(p,&dummy,currRing); |
---|
3931 | else res->data=(char *)-1; |
---|
3932 | return FALSE; |
---|
3933 | } |
---|
3934 | static BOOLEAN jjDEG_M(leftv res, leftv u) |
---|
3935 | { |
---|
3936 | ideal I=(ideal)u->Data(); |
---|
3937 | int d=-1; |
---|
3938 | int dummy; |
---|
3939 | int i; |
---|
3940 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
3941 | if (I->m[i]!=NULL) d=si_max(d,(int)currRing->pLDeg(I->m[i],&dummy,currRing)); |
---|
3942 | res->data = (char *)(long)d; |
---|
3943 | return FALSE; |
---|
3944 | } |
---|
3945 | static BOOLEAN jjDEGREE(leftv res, leftv v) |
---|
3946 | { |
---|
3947 | SPrintStart(); |
---|
3948 | #ifdef HAVE_RINGS |
---|
3949 | if (rField_is_Z(currRing)) |
---|
3950 | { |
---|
3951 | PrintS("// NOTE: computation of degree is being performed for\n"); |
---|
3952 | PrintS("// generic fibre, that is, over Q\n"); |
---|
3953 | } |
---|
3954 | #endif |
---|
3955 | assumeStdFlag(v); |
---|
3956 | intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD); |
---|
3957 | scDegree((ideal)v->Data(),module_w,currRing->qideal); |
---|
3958 | char *s=SPrintEnd(); |
---|
3959 | int l=strlen(s)-1; |
---|
3960 | s[l]='\0'; |
---|
3961 | res->data=(void*)s; |
---|
3962 | return FALSE; |
---|
3963 | } |
---|
3964 | static BOOLEAN jjDEFINED(leftv res, leftv v) |
---|
3965 | { |
---|
3966 | if ((v->rtyp==IDHDL) |
---|
3967 | && ((myynest==IDLEV((idhdl)v->data))||(0==IDLEV((idhdl)v->data)))) |
---|
3968 | { |
---|
3969 | res->data=(void *)(long)(IDLEV((idhdl)v->data)+1); |
---|
3970 | } |
---|
3971 | else if (v->rtyp!=0) res->data=(void *)(-1); |
---|
3972 | return FALSE; |
---|
3973 | } |
---|
3974 | |
---|
3975 | /// Return the denominator of the input number |
---|
3976 | /// NOTE: the input number is normalized as a side effect |
---|
3977 | static BOOLEAN jjDENOMINATOR(leftv res, leftv v) |
---|
3978 | { |
---|
3979 | number n = reinterpret_cast<number>(v->Data()); |
---|
3980 | res->data = reinterpret_cast<void*>(n_GetDenom(n, currRing->cf)); |
---|
3981 | return FALSE; |
---|
3982 | } |
---|
3983 | |
---|
3984 | /// Return the numerator of the input number |
---|
3985 | /// NOTE: the input number is normalized as a side effect |
---|
3986 | static BOOLEAN jjNUMERATOR(leftv res, leftv v) |
---|
3987 | { |
---|
3988 | number n = reinterpret_cast<number>(v->Data()); |
---|
3989 | res->data = reinterpret_cast<void*>(n_GetNumerator(n, currRing->cf)); |
---|
3990 | return FALSE; |
---|
3991 | } |
---|
3992 | |
---|
3993 | static BOOLEAN jjDET(leftv res, leftv v) |
---|
3994 | { |
---|
3995 | matrix m=(matrix)v->Data(); |
---|
3996 | res ->data = mp_Det(m,currRing); |
---|
3997 | return FALSE; |
---|
3998 | } |
---|
3999 | static BOOLEAN jjDET_BI(leftv res, leftv v) |
---|
4000 | { |
---|
4001 | bigintmat * m=(bigintmat*)v->Data(); |
---|
4002 | int i,j; |
---|
4003 | i=m->rows();j=m->cols(); |
---|
4004 | if(i==j) |
---|
4005 | res->data = (char *)(long)singclap_det_bi(m,coeffs_BIGINT); |
---|
4006 | else |
---|
4007 | { |
---|
4008 | Werror("det of %d x %d bigintmat",i,j); |
---|
4009 | return TRUE; |
---|
4010 | } |
---|
4011 | return FALSE; |
---|
4012 | } |
---|
4013 | #ifdef SINGULAR_4_2 |
---|
4014 | static BOOLEAN jjDET_N2(leftv res, leftv v) |
---|
4015 | { |
---|
4016 | bigintmat * m=(bigintmat*)v->Data(); |
---|
4017 | number2 r=(number2)omAlloc0(sizeof(*r)); |
---|
4018 | int i,j; |
---|
4019 | i=m->rows();j=m->cols(); |
---|
4020 | if(i==j) |
---|
4021 | { |
---|
4022 | r->n=m->det(); |
---|
4023 | r->cf=m->basecoeffs(); |
---|
4024 | } |
---|
4025 | else |
---|
4026 | { |
---|
4027 | omFreeSize(r,sizeof(*r)); |
---|
4028 | Werror("det of %d x %d cmatrix",i,j); |
---|
4029 | return TRUE; |
---|
4030 | } |
---|
4031 | res->data=(void*)r; |
---|
4032 | return FALSE; |
---|
4033 | } |
---|
4034 | #endif |
---|
4035 | static BOOLEAN jjDET_I(leftv res, leftv v) |
---|
4036 | { |
---|
4037 | intvec * m=(intvec*)v->Data(); |
---|
4038 | int i,j; |
---|
4039 | i=m->rows();j=m->cols(); |
---|
4040 | if(i==j) |
---|
4041 | res->data = (char *)(long)singclap_det_i(m,currRing); |
---|
4042 | else |
---|
4043 | { |
---|
4044 | Werror("det of %d x %d intmat",i,j); |
---|
4045 | return TRUE; |
---|
4046 | } |
---|
4047 | return FALSE; |
---|
4048 | } |
---|
4049 | static BOOLEAN jjDET_S(leftv res, leftv v) |
---|
4050 | { |
---|
4051 | ideal I=(ideal)v->Data(); |
---|
4052 | res->data=(char*)sm_Det(I,currRing); |
---|
4053 | return FALSE; |
---|
4054 | } |
---|
4055 | static BOOLEAN jjDIM(leftv res, leftv v) |
---|
4056 | { |
---|
4057 | assumeStdFlag(v); |
---|
4058 | if (rHasMixedOrdering(currRing)) |
---|
4059 | { |
---|
4060 | Warn("dim(%s) may be wrong because the mixed monomial ordering",v->Name()); |
---|
4061 | } |
---|
4062 | #ifdef HAVE_RINGS |
---|
4063 | if (rField_is_Ring(currRing)) |
---|
4064 | { |
---|
4065 | ideal vid = (ideal)v->Data(); |
---|
4066 | int i = idPosConstant(vid); |
---|
4067 | if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf))) |
---|
4068 | { /* ideal v contains unit; dim = -1 */ |
---|
4069 | res->data = (char *)-1L; |
---|
4070 | return FALSE; |
---|
4071 | } |
---|
4072 | ideal vv = id_Head(vid,currRing); |
---|
4073 | idSkipZeroes(vv); |
---|
4074 | int j = idPosConstant(vv); |
---|
4075 | long d; |
---|
4076 | if(j == -1) |
---|
4077 | { |
---|
4078 | d = (long)scDimInt(vv, currRing->qideal); |
---|
4079 | if(rField_is_Z(currRing)) |
---|
4080 | d++; |
---|
4081 | } |
---|
4082 | else |
---|
4083 | { |
---|
4084 | if(n_IsUnit(pGetCoeff(vv->m[j]),currRing->cf)) |
---|
4085 | d = -1; |
---|
4086 | else |
---|
4087 | d = (long)scDimInt(vv, currRing->qideal); |
---|
4088 | } |
---|
4089 | //Anne's Idea for std(4,2x) = 0 bug |
---|
4090 | long dcurr = d; |
---|
4091 | for(unsigned ii=0;ii<(unsigned)IDELEMS(vv);ii++) |
---|
4092 | { |
---|
4093 | if(vv->m[ii] != NULL && !n_IsUnit(pGetCoeff(vv->m[ii]),currRing->cf)) |
---|
4094 | { |
---|
4095 | ideal vc = idCopy(vv); |
---|
4096 | poly c = pInit(); |
---|
4097 | pSetCoeff0(c,nCopy(pGetCoeff(vv->m[ii]))); |
---|
4098 | idInsertPoly(vc,c); |
---|
4099 | idSkipZeroes(vc); |
---|
4100 | for(unsigned jj = 0;jj<(unsigned)IDELEMS(vc)-1;jj++) |
---|
4101 | { |
---|
4102 | if((vc->m[jj]!=NULL) |
---|
4103 | && (n_DivBy(pGetCoeff(vc->m[jj]),pGetCoeff(c),currRing->cf))) |
---|
4104 | { |
---|
4105 | pDelete(&vc->m[jj]); |
---|
4106 | } |
---|
4107 | } |
---|
4108 | idSkipZeroes(vc); |
---|
4109 | j = idPosConstant(vc); |
---|
4110 | if (j != -1) pDelete(&vc->m[j]); |
---|
4111 | dcurr = (long)scDimInt(vc, currRing->qideal); |
---|
4112 | // the following assumes the ground rings to be either zero- or one-dimensional |
---|
4113 | if((j==-1) && rField_is_Z(currRing)) |
---|
4114 | { |
---|
4115 | // should also be activated for other euclidean domains as groundfield |
---|
4116 | dcurr++; |
---|
4117 | } |
---|
4118 | idDelete(&vc); |
---|
4119 | } |
---|
4120 | if(dcurr > d) |
---|
4121 | d = dcurr; |
---|
4122 | } |
---|
4123 | res->data = (char *)d; |
---|
4124 | idDelete(&vv); |
---|
4125 | return FALSE; |
---|
4126 | } |
---|
4127 | #endif |
---|
4128 | res->data = (char *)(long)scDimInt((ideal)(v->Data()),currRing->qideal); |
---|
4129 | return FALSE; |
---|
4130 | } |
---|
4131 | static BOOLEAN jjDUMP(leftv, leftv v) |
---|
4132 | { |
---|
4133 | si_link l = (si_link)v->Data(); |
---|
4134 | if (slDump(l)) |
---|
4135 | { |
---|
4136 | const char *s; |
---|
4137 | if ((l!=NULL)&&(l->name!=NULL)) s=l->name; |
---|
4138 | else s=sNoName_fe; |
---|
4139 | Werror("cannot dump to `%s`",s); |
---|
4140 | return TRUE; |
---|
4141 | } |
---|
4142 | else |
---|
4143 | return FALSE; |
---|
4144 | } |
---|
4145 | static BOOLEAN jjE(leftv res, leftv v) |
---|
4146 | { |
---|
4147 | res->data = (char *)pOne(); |
---|
4148 | int co=(int)(long)v->Data(); |
---|
4149 | if (co>0) |
---|
4150 | { |
---|
4151 | pSetComp((poly)res->data,co); |
---|
4152 | pSetm((poly)res->data); |
---|
4153 | } |
---|
4154 | else WerrorS("argument of gen must be positive"); |
---|
4155 | return (co<=0); |
---|
4156 | } |
---|
4157 | static BOOLEAN jjEXECUTE(leftv, leftv v) |
---|
4158 | { |
---|
4159 | char * d = (char *)v->Data(); |
---|
4160 | char * s = (char *)omAlloc(strlen(d) + 13); |
---|
4161 | strcpy( s, (char *)d); |
---|
4162 | strcat( s, "\n;RETURN();\n"); |
---|
4163 | newBuffer(s,BT_execute); |
---|
4164 | return yyparse(); |
---|
4165 | } |
---|
4166 | static BOOLEAN jjFACSTD(leftv res, leftv v) |
---|
4167 | { |
---|
4168 | lists L=(lists)omAllocBin(slists_bin); |
---|
4169 | if (currRing->cf->convSingNFactoryN!=ndConvSingNFactoryN) /* conversion to factory*/ |
---|
4170 | { |
---|
4171 | ideal_list p,h; |
---|
4172 | h=kStdfac((ideal)v->Data(),NULL,testHomog,NULL); |
---|
4173 | if (h==NULL) |
---|
4174 | { |
---|
4175 | L->Init(1); |
---|
4176 | L->m[0].data=(char *)idInit(1); |
---|
4177 | L->m[0].rtyp=IDEAL_CMD; |
---|
4178 | } |
---|
4179 | else |
---|
4180 | { |
---|
4181 | p=h; |
---|
4182 | int l=0; |
---|
4183 | while (p!=NULL) { p=p->next;l++; } |
---|
4184 | L->Init(l); |
---|
4185 | l=0; |
---|
4186 | while(h!=NULL) |
---|
4187 | { |
---|
4188 | L->m[l].data=(char *)h->d; |
---|
4189 | L->m[l].rtyp=IDEAL_CMD; |
---|
4190 | p=h->next; |
---|
4191 | omFreeSize(h,sizeof(*h)); |
---|
4192 | h=p; |
---|
4193 | l++; |
---|
4194 | } |
---|
4195 | } |
---|
4196 | } |
---|
4197 | else |
---|
4198 | { |
---|
4199 | WarnS("no factorization implemented"); |
---|
4200 | L->Init(1); |
---|
4201 | iiExprArith1(&(L->m[0]),v,STD_CMD); |
---|
4202 | } |
---|
4203 | res->data=(void *)L; |
---|
4204 | return FALSE; |
---|
4205 | } |
---|
4206 | static BOOLEAN jjFAC_P(leftv res, leftv u) |
---|
4207 | { |
---|
4208 | intvec *v=NULL; |
---|
4209 | singclap_factorize_retry=0; |
---|
4210 | ideal f=singclap_factorize((poly)(u->CopyD()), &v, 0,currRing); |
---|
4211 | if (f==NULL) return TRUE; |
---|
4212 | ivTest(v); |
---|
4213 | lists l=(lists)omAllocBin(slists_bin); |
---|
4214 | l->Init(2); |
---|
4215 | l->m[0].rtyp=IDEAL_CMD; |
---|
4216 | l->m[0].data=(void *)f; |
---|
4217 | l->m[1].rtyp=INTVEC_CMD; |
---|
4218 | l->m[1].data=(void *)v; |
---|
4219 | res->data=(void *)l; |
---|
4220 | return FALSE; |
---|
4221 | } |
---|
4222 | static BOOLEAN jjGETDUMP(leftv, leftv v) |
---|
4223 | { |
---|
4224 | si_link l = (si_link)v->Data(); |
---|
4225 | if (slGetDump(l)) |
---|
4226 | { |
---|
4227 | const char *s; |
---|
4228 | if ((l!=NULL)&&(l->name!=NULL)) s=l->name; |
---|
4229 | else s=sNoName_fe; |
---|
4230 | Werror("cannot get dump from `%s`",s); |
---|
4231 | return TRUE; |
---|
4232 | } |
---|
4233 | else |
---|
4234 | return FALSE; |
---|
4235 | } |
---|
4236 | static BOOLEAN jjHIGHCORNER(leftv res, leftv v) |
---|
4237 | { |
---|
4238 | assumeStdFlag(v); |
---|
4239 | ideal I=(ideal)v->Data(); |
---|
4240 | res->data=(void *)iiHighCorner(I,0); |
---|
4241 | return FALSE; |
---|
4242 | } |
---|
4243 | static BOOLEAN jjHIGHCORNER_M(leftv res, leftv v) |
---|
4244 | { |
---|
4245 | assumeStdFlag(v); |
---|
4246 | intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD); |
---|
4247 | BOOLEAN delete_w=FALSE; |
---|
4248 | ideal I=(ideal)v->Data(); |
---|
4249 | int i; |
---|
4250 | poly p=NULL,po=NULL; |
---|
4251 | int rk=id_RankFreeModule(I,currRing); |
---|
4252 | if (w==NULL) |
---|
4253 | { |
---|
4254 | w = new intvec(rk); |
---|
4255 | delete_w=TRUE; |
---|
4256 | } |
---|
4257 | for(i=rk;i>0;i--) |
---|
4258 | { |
---|
4259 | p=iiHighCorner(I,i); |
---|
4260 | if (p==NULL) |
---|
4261 | { |
---|
4262 | WerrorS("module must be zero-dimensional"); |
---|
4263 | if (delete_w) delete w; |
---|
4264 | return TRUE; |
---|
4265 | } |
---|
4266 | if (po==NULL) |
---|
4267 | { |
---|
4268 | po=p; |
---|
4269 | } |
---|
4270 | else |
---|
4271 | { |
---|
4272 | // now po!=NULL, p!=NULL |
---|
4273 | int d=(currRing->pFDeg(po,currRing)-(*w)[pGetComp(po)-1] - currRing->pFDeg(p,currRing)+(*w)[i-1]); |
---|
4274 | if (d==0) |
---|
4275 | d=pLmCmp(po,p); |
---|
4276 | if (d > 0) |
---|
4277 | { |
---|
4278 | pDelete(&p); |
---|
4279 | } |
---|
4280 | else // (d < 0) |
---|
4281 | { |
---|
4282 | pDelete(&po); po=p; |
---|
4283 | } |
---|
4284 | } |
---|
4285 | } |
---|
4286 | if (delete_w) delete w; |
---|
4287 | res->data=(void *)po; |
---|
4288 | return FALSE; |
---|
4289 | } |
---|
4290 | static BOOLEAN jjHILBERT(leftv, leftv v) |
---|
4291 | { |
---|
4292 | #ifdef HAVE_RINGS |
---|
4293 | if (rField_is_Z(currRing)) |
---|
4294 | { |
---|
4295 | PrintS("// NOTE: computation of Hilbert series etc. is being\n"); |
---|
4296 | PrintS("// performed for generic fibre, that is, over Q\n"); |
---|
4297 | } |
---|
4298 | #endif |
---|
4299 | assumeStdFlag(v); |
---|
4300 | intvec *module_w=(intvec*)atGet(v,"isHomog",INTVEC_CMD); |
---|
4301 | //scHilbertPoly((ideal)v->Data(),currRing->qideal); |
---|
4302 | hLookSeries((ideal)v->Data(),module_w,currRing->qideal); |
---|
4303 | return FALSE; |
---|
4304 | } |
---|
4305 | static BOOLEAN jjHILBERT_IV(leftv res, leftv v) |
---|
4306 | { |
---|
4307 | #ifdef HAVE_RINGS |
---|
4308 | if (rField_is_Z(currRing)) |
---|
4309 | { |
---|
4310 | PrintS("// NOTE: computation of Hilbert series etc. is being\n"); |
---|
4311 | PrintS("// performed for generic fibre, that is, over Q\n"); |
---|
4312 | } |
---|
4313 | #endif |
---|
4314 | res->data=(void *)hSecondSeries((intvec *)v->Data()); |
---|
4315 | return FALSE; |
---|
4316 | } |
---|
4317 | static BOOLEAN jjHOMOG1(leftv res, leftv v) |
---|
4318 | { |
---|
4319 | intvec *w=(intvec*)atGet(v,"isHomog",INTVEC_CMD); |
---|
4320 | ideal v_id=(ideal)v->Data(); |
---|
4321 | if (w==NULL) |
---|
4322 | { |
---|
4323 | res->data=(void *)(long)idHomModule(v_id,currRing->qideal,&w); |
---|
4324 | if (res->data!=NULL) |
---|
4325 | { |
---|
4326 | if (v->rtyp==IDHDL) |
---|
4327 | { |
---|
4328 | char *s_isHomog=omStrDup("isHomog"); |
---|
4329 | if (v->e==NULL) |
---|
4330 | atSet((idhdl)(v->data),s_isHomog,w,INTVEC_CMD); |
---|
4331 | else |
---|
4332 | atSet((idhdl)(v->LData()),s_isHomog,w,INTVEC_CMD); |
---|
4333 | } |
---|
4334 | else if (w!=NULL) delete w; |
---|
4335 | } // if res->data==NULL then w==NULL |
---|
4336 | } |
---|
4337 | else |
---|
4338 | { |
---|
4339 | res->data=(void *)(long)idTestHomModule(v_id,currRing->qideal,w); |
---|
4340 | if((res->data==NULL) && (v->rtyp==IDHDL)) |
---|
4341 | { |
---|
4342 | if (v->e==NULL) |
---|
4343 | atKill((idhdl)(v->data),"isHomog"); |
---|
4344 | else |
---|
4345 | atKill((idhdl)(v->LData()),"isHomog"); |
---|
4346 | } |
---|
4347 | } |
---|
4348 | return FALSE; |
---|
4349 | } |
---|
4350 | static BOOLEAN jjidMaxIdeal(leftv res, leftv v) |
---|
4351 | { |
---|
4352 | #ifdef HAVE_SHIFTBBA |
---|
4353 | if (currRing->isLPring) |
---|
4354 | { |
---|
4355 | int deg = (int)(long)v->Data(); |
---|
4356 | if (deg > currRing->N/currRing->isLPring) { |
---|
4357 | WerrorS("degree bound of Letterplace ring is to small"); |
---|
4358 | return TRUE; |
---|
4359 | } |
---|
4360 | } |
---|
4361 | #endif |
---|
4362 | res->data = (char *)idMaxIdeal((int)(long)v->Data()); |
---|
4363 | setFlag(res,FLAG_STD); |
---|
4364 | return FALSE; |
---|
4365 | } |
---|
4366 | static BOOLEAN jjIDEAL_Ma(leftv res, leftv v) |
---|
4367 | { |
---|
4368 | matrix mat=(matrix)v->CopyD(MATRIX_CMD); |
---|
4369 | IDELEMS((ideal)mat)=MATCOLS(mat)*MATROWS(mat); |
---|
4370 | if (IDELEMS((ideal)mat)==0) |
---|
4371 | { |
---|
4372 | idDelete((ideal *)&mat); |
---|
4373 | mat=(matrix)idInit(1,1); |
---|
4374 | } |
---|
4375 | else |
---|
4376 | { |
---|
4377 | MATROWS(mat)=1; |
---|
4378 | mat->rank=1; |
---|
4379 | idTest((ideal)mat); |
---|
4380 | } |
---|
4381 | res->data=(char *)mat; |
---|
4382 | return FALSE; |
---|
4383 | } |
---|
4384 | static BOOLEAN jjIDEAL_Map(leftv res, leftv v) |
---|
4385 | { |
---|
4386 | map m=(map)v->CopyD(MAP_CMD); |
---|
4387 | omFree((ADDRESS)m->preimage); |
---|
4388 | m->preimage=NULL; |
---|
4389 | ideal I=(ideal)m; |
---|
4390 | I->rank=1; |
---|
4391 | res->data=(char *)I; |
---|
4392 | return FALSE; |
---|
4393 | } |
---|
4394 | static BOOLEAN jjIDEAL_R(leftv res, leftv v) |
---|
4395 | { |
---|
4396 | if (currRing!=NULL) |
---|
4397 | { |
---|
4398 | ring q=(ring)v->Data(); |
---|
4399 | if (rSamePolyRep(currRing, q)) |
---|
4400 | { |
---|
4401 | if (q->qideal==NULL) |
---|
4402 | res->data=(char *)idInit(1,1); |
---|
4403 | else |
---|
4404 | res->data=(char *)idCopy(q->qideal); |
---|
4405 | return FALSE; |
---|
4406 | } |
---|
4407 | } |
---|
4408 | WerrorS("can only get ideal from identical qring"); |
---|
4409 | return TRUE; |
---|
4410 | } |
---|
4411 | static BOOLEAN jjIm2Iv(leftv res, leftv v) |
---|
4412 | { |
---|
4413 | intvec *iv = (intvec *)v->CopyD(INTMAT_CMD); |
---|
4414 | iv->makeVector(); |
---|
4415 | res->data = iv; |
---|
4416 | return FALSE; |
---|
4417 | } |
---|
4418 | static BOOLEAN jjIMPART(leftv res, leftv v) |
---|
4419 | { |
---|
4420 | res->data = (char *)n_ImPart((number)v->Data(),currRing->cf); |
---|
4421 | return FALSE; |
---|
4422 | } |
---|
4423 | static BOOLEAN jjINDEPSET(leftv res, leftv v) |
---|
4424 | { |
---|
4425 | assumeStdFlag(v); |
---|
4426 | res->data=(void *)scIndIntvec((ideal)(v->Data()),currRing->qideal); |
---|
4427 | return FALSE; |
---|
4428 | } |
---|
4429 | static BOOLEAN jjINTERRED(leftv res, leftv v) |
---|
4430 | { |
---|
4431 | ideal result=kInterRed((ideal)(v->Data()), currRing->qideal); |
---|
4432 | #ifdef HAVE_RINGS |
---|
4433 | if(rField_is_Ring(currRing)) |
---|
4434 | WarnS("interred: this command is experimental over the integers"); |
---|
4435 | #endif |
---|
4436 | if (TEST_OPT_PROT) { PrintLn(); mflush(); } |
---|
4437 | res->data = result; |
---|
4438 | return FALSE; |
---|
4439 | } |
---|
4440 | static BOOLEAN jjIS_RINGVAR_P(leftv res, leftv v) |
---|
4441 | { |
---|
4442 | res->data = (char *)(long)pVar((poly)v->Data()); |
---|
4443 | return FALSE; |
---|
4444 | } |
---|
4445 | static BOOLEAN jjIS_RINGVAR_S(leftv res, leftv v) |
---|
4446 | { |
---|
4447 | res->data = (char *)(long)(r_IsRingVar((char *)v->Data(), currRing->names, |
---|
4448 | currRing->N)+1); |
---|
4449 | return FALSE; |
---|
4450 | } |
---|
4451 | static BOOLEAN jjIS_RINGVAR0(leftv res, leftv) |
---|
4452 | { |
---|
4453 | res->data = (char *)0; |
---|
4454 | return FALSE; |
---|
4455 | } |
---|
4456 | static BOOLEAN jjJACOB_P(leftv res, leftv v) |
---|
4457 | { |
---|
4458 | ideal i=idInit(currRing->N,1); |
---|
4459 | int k; |
---|
4460 | poly p=(poly)(v->Data()); |
---|
4461 | for (k=currRing->N;k>0;k--) |
---|
4462 | { |
---|
4463 | i->m[k-1]=pDiff(p,k); |
---|
4464 | } |
---|
4465 | res->data = (char *)i; |
---|
4466 | return FALSE; |
---|
4467 | } |
---|
4468 | static BOOLEAN jjDIFF_COEF(leftv res, leftv u, leftv v) |
---|
4469 | { |
---|
4470 | if (!nCoeff_is_transExt(currRing->cf)) |
---|
4471 | { |
---|
4472 | WerrorS("differentiation not defined in the coefficient ring"); |
---|
4473 | return TRUE; |
---|
4474 | } |
---|
4475 | number n = (number) u->Data(); |
---|
4476 | number k = (number) v->Data(); |
---|
4477 | res->data = ntDiff(n,k,currRing->cf); |
---|
4478 | return FALSE; |
---|
4479 | } |
---|
4480 | /*2 |
---|
4481 | * compute Jacobi matrix of a module/matrix |
---|
4482 | * Jacobi(M) := ( diff(Mt,var(1))|, ... ,| diff(Mt,var(currRing->N)) ), |
---|
4483 | * where Mt := transpose(M) |
---|
4484 | * Note that this is consistent with the current conventions for jacob in Singular, |
---|
4485 | * whereas M2 computes its transposed. |
---|
4486 | */ |
---|
4487 | static BOOLEAN jjJACOB_M(leftv res, leftv a) |
---|
4488 | { |
---|
4489 | ideal id = (ideal)a->Data(); |
---|
4490 | id = id_Transp(id,currRing); |
---|
4491 | int W = IDELEMS(id); |
---|
4492 | |
---|
4493 | ideal result = idInit(W * currRing->N, id->rank); |
---|
4494 | poly *p = result->m; |
---|
4495 | |
---|
4496 | for( int v = 1; v <= currRing->N; v++ ) |
---|
4497 | { |
---|
4498 | poly* q = id->m; |
---|
4499 | for( int i = 0; i < W; i++, p++, q++ ) |
---|
4500 | *p = pDiff( *q, v ); |
---|
4501 | } |
---|
4502 | idDelete(&id); |
---|
4503 | |
---|
4504 | res->data = (char *)result; |
---|
4505 | return FALSE; |
---|
4506 | } |
---|
4507 | |
---|
4508 | static BOOLEAN jjKBASE(leftv res, leftv v) |
---|
4509 | { |
---|
4510 | assumeStdFlag(v); |
---|
4511 | res->data = (char *)scKBase(-1,(ideal)(v->Data()),currRing->qideal); |
---|
4512 | return FALSE; |
---|
4513 | } |
---|
4514 | static BOOLEAN jjL2R(leftv res, leftv v) |
---|
4515 | { |
---|
4516 | res->data=(char *)syConvList((lists)v->Data()); |
---|
4517 | if (res->data != NULL) |
---|
4518 | return FALSE; |
---|
4519 | else |
---|
4520 | return TRUE; |
---|
4521 | } |
---|
4522 | static BOOLEAN jjLEADCOEF(leftv res, leftv v) |
---|
4523 | { |
---|
4524 | poly p=(poly)v->Data(); |
---|
4525 | if (p==NULL) |
---|
4526 | { |
---|
4527 | res->data=(char *)nInit(0); |
---|
4528 | } |
---|
4529 | else |
---|
4530 | { |
---|
4531 | res->data=(char *)nCopy(pGetCoeff(p)); |
---|
4532 | } |
---|
4533 | return FALSE; |
---|
4534 | } |
---|
4535 | static BOOLEAN jjLEADEXP(leftv res, leftv v) |
---|
4536 | { |
---|
4537 | poly p=(poly)v->Data(); |
---|
4538 | int s=currRing->N; |
---|
4539 | if (v->Typ()==VECTOR_CMD) s++; |
---|
4540 | intvec *iv=new intvec(s); |
---|
4541 | if (p!=NULL) |
---|
4542 | { |
---|
4543 | for(int i = currRing->N;i;i--) |
---|
4544 | { |
---|
4545 | (*iv)[i-1]=pGetExp(p,i); |
---|
4546 | } |
---|
4547 | if (s!=currRing->N) |
---|
4548 | (*iv)[currRing->N]=pGetComp(p); |
---|
4549 | } |
---|
4550 | res->data=(char *)iv; |
---|
4551 | return FALSE; |
---|
4552 | } |
---|
4553 | static BOOLEAN jjLEADMONOM(leftv res, leftv v) |
---|
4554 | { |
---|
4555 | poly p=(poly)v->Data(); |
---|
4556 | if (p == NULL) |
---|
4557 | { |
---|
4558 | res->data = (char*) NULL; |
---|
4559 | } |
---|
4560 | else |
---|
4561 | { |
---|
4562 | poly lm = pLmInit(p); |
---|
4563 | pSetCoeff0(lm, nInit(1)); |
---|
4564 | res->data = (char*) lm; |
---|
4565 | } |
---|
4566 | return FALSE; |
---|
4567 | } |
---|
4568 | static BOOLEAN jjLOAD1(leftv /*res*/, leftv v) |
---|
4569 | { |
---|
4570 | return jjLOAD((char*)v->Data(),FALSE); |
---|
4571 | } |
---|
4572 | static BOOLEAN jjLISTRING(leftv res, leftv v) |
---|
4573 | { |
---|
4574 | lists l=(lists)v->Data(); |
---|
4575 | long mm=(long)atGet(v,"maxExp",INT_CMD); |
---|
4576 | if (mm==0) mm=0x7fff; |
---|
4577 | int isLetterplace=(int)(long)atGet(v,"isLetterplaceRing",INT_CMD); |
---|
4578 | ring r=rCompose(l,TRUE,mm,isLetterplace); |
---|
4579 | res->data=(char *)r; |
---|
4580 | return (r==NULL); |
---|
4581 | } |
---|
4582 | static BOOLEAN jjPFAC1(leftv res, leftv v) |
---|
4583 | { |
---|
4584 | /* call method jjPFAC2 with second argument = 0 (meaning that no |
---|
4585 | valid bound for the prime factors has been given) */ |
---|
4586 | sleftv tmp; |
---|
4587 | memset(&tmp, 0, sizeof(tmp)); |
---|
4588 | tmp.rtyp = INT_CMD; |
---|
4589 | return jjPFAC2(res, v, &tmp); |
---|
4590 | } |
---|
4591 | static BOOLEAN jjLU_DECOMP(leftv res, leftv v) |
---|
4592 | { |
---|
4593 | /* computes the LU-decomposition of a matrix M; |
---|
4594 | i.e., M = P * L * U, where |
---|
4595 | - P is a row permutation matrix, |
---|
4596 | - L is in lower triangular form, |
---|
4597 | - U is in upper row echelon form |
---|
4598 | Then, we also have P * M = L * U. |
---|
4599 | A list [P, L, U] is returned. */ |
---|
4600 | matrix mat = (const matrix)v->Data(); |
---|
4601 | if (!idIsConstant((ideal)mat)) |
---|
4602 | { |
---|
4603 | WerrorS("matrix must be constant"); |
---|
4604 | return TRUE; |
---|
4605 | } |
---|
4606 | matrix pMat; |
---|
4607 | matrix lMat; |
---|
4608 | matrix uMat; |
---|
4609 | |
---|
4610 | luDecomp(mat, pMat, lMat, uMat); |
---|
4611 | |
---|
4612 | lists ll = (lists)omAllocBin(slists_bin); |
---|
4613 | ll->Init(3); |
---|
4614 | ll->m[0].rtyp=MATRIX_CMD; ll->m[0].data=(void *)pMat; |
---|
4615 | ll->m[1].rtyp=MATRIX_CMD; ll->m[1].data=(void *)lMat; |
---|
4616 | ll->m[2].rtyp=MATRIX_CMD; ll->m[2].data=(void *)uMat; |
---|
4617 | res->data=(char*)ll; |
---|
4618 | |
---|
4619 | return FALSE; |
---|
4620 | } |
---|
4621 | static BOOLEAN jjMEMORY(leftv res, leftv v) |
---|
4622 | { |
---|
4623 | // clean out "_": |
---|
4624 | sLastPrinted.CleanUp(); |
---|
4625 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
4626 | // collect all info: |
---|
4627 | omUpdateInfo(); |
---|
4628 | switch(((int)(long)v->Data())) |
---|
4629 | { |
---|
4630 | case 0: |
---|
4631 | res->data=(char *)n_Init(om_Info.UsedBytes,coeffs_BIGINT); |
---|
4632 | break; |
---|
4633 | case 1: |
---|
4634 | res->data = (char *)n_Init(om_Info.CurrentBytesSystem,coeffs_BIGINT); |
---|
4635 | break; |
---|
4636 | case 2: |
---|
4637 | res->data = (char *)n_Init(om_Info.MaxBytesSystem,coeffs_BIGINT); |
---|
4638 | break; |
---|
4639 | default: |
---|
4640 | omPrintStats(stdout); |
---|
4641 | omPrintInfo(stdout); |
---|
4642 | omPrintBinStats(stdout); |
---|
4643 | res->data = (char *)0; |
---|
4644 | res->rtyp = NONE; |
---|
4645 | } |
---|
4646 | return FALSE; |
---|
4647 | res->data = (char *)0; |
---|
4648 | return FALSE; |
---|
4649 | } |
---|
4650 | //static BOOLEAN jjMONITOR1(leftv res, leftv v) |
---|
4651 | //{ |
---|
4652 | // return jjMONITOR2(res,v,NULL); |
---|
4653 | //} |
---|
4654 | static BOOLEAN jjMSTD(leftv res, leftv v) |
---|
4655 | { |
---|
4656 | int t=v->Typ(); |
---|
4657 | ideal r,m; |
---|
4658 | r=kMin_std((ideal)v->Data(),currRing->qideal,testHomog,NULL,m); |
---|
4659 | lists l=(lists)omAllocBin(slists_bin); |
---|
4660 | l->Init(2); |
---|
4661 | l->m[0].rtyp=t; |
---|
4662 | l->m[0].data=(char *)r; |
---|
4663 | setFlag(&(l->m[0]),FLAG_STD); |
---|
4664 | l->m[1].rtyp=t; |
---|
4665 | l->m[1].data=(char *)m; |
---|
4666 | res->data=(char *)l; |
---|
4667 | return FALSE; |
---|
4668 | } |
---|
4669 | static BOOLEAN jjMULT(leftv res, leftv v) |
---|
4670 | { |
---|
4671 | assumeStdFlag(v); |
---|
4672 | res->data = (char *)(long)scMultInt((ideal)(v->Data()),currRing->qideal); |
---|
4673 | return FALSE; |
---|
4674 | } |
---|
4675 | static BOOLEAN jjMINRES_R(leftv res, leftv v) |
---|
4676 | { |
---|
4677 | intvec *weights=(intvec*)atGet(v,"isHomog",INTVEC_CMD); |
---|
4678 | |
---|
4679 | syStrategy tmp=(syStrategy)v->Data(); |
---|
4680 | tmp = syMinimize(tmp); // enrich itself! |
---|
4681 | |
---|
4682 | res->data=(char *)tmp; |
---|
4683 | |
---|
4684 | if (weights!=NULL) |
---|
4685 | atSet(res, omStrDup("isHomog"),ivCopy(weights),INTVEC_CMD); |
---|
4686 | |
---|
4687 | return FALSE; |
---|
4688 | } |
---|
4689 | static BOOLEAN jjN2BI(leftv res, leftv v) |
---|
4690 | { |
---|
4691 | number n,i; i=(number)v->Data(); |
---|
4692 | nMapFunc nMap=n_SetMap(currRing->cf,coeffs_BIGINT); |
---|
4693 | if (nMap!=NULL) |
---|
4694 | n=nMap(i,currRing->cf,coeffs_BIGINT); |
---|
4695 | else goto err; |
---|
4696 | res->data=(void *)n; |
---|
4697 | return FALSE; |
---|
4698 | err: |
---|
4699 | WerrorS("cannot convert to bigint"); return TRUE; |
---|
4700 | } |
---|
4701 | static BOOLEAN jjNAMEOF(leftv res, leftv v) |
---|
4702 | { |
---|
4703 | if ((v->rtyp==IDHDL)||(v->rtyp==ALIAS_CMD)) |
---|
4704 | res->data=omStrDup(v->name); |
---|
4705 | else if (v->name==NULL) |
---|
4706 | res->data=omStrDup(""); |
---|
4707 | else |
---|
4708 | { |
---|
4709 | res->data = (char *)v->name; |
---|
4710 | v->name=NULL; |
---|
4711 | } |
---|
4712 | return FALSE; |
---|
4713 | } |
---|
4714 | static BOOLEAN jjNAMES(leftv res, leftv v) |
---|
4715 | { |
---|
4716 | res->data=ipNameList(((ring)v->Data())->idroot); |
---|
4717 | return FALSE; |
---|
4718 | } |
---|
4719 | static BOOLEAN jjNAMES_I(leftv res, leftv v) |
---|
4720 | { |
---|
4721 | res->data=ipNameListLev((IDROOT),(int)(long)v->Data()); |
---|
4722 | return FALSE; |
---|
4723 | } |
---|
4724 | static BOOLEAN jjNOT(leftv res, leftv v) |
---|
4725 | { |
---|
4726 | res->data=(char*)(long)((long)v->Data()==0 ? 1 : 0); |
---|
4727 | return FALSE; |
---|
4728 | } |
---|
4729 | static BOOLEAN jjNVARS(leftv res, leftv v) |
---|
4730 | { |
---|
4731 | res->data = (char *)(long)(((ring)(v->Data()))->N); |
---|
4732 | return FALSE; |
---|
4733 | } |
---|
4734 | static BOOLEAN jjOpenClose(leftv, leftv v) |
---|
4735 | { |
---|
4736 | si_link l=(si_link)v->Data(); |
---|
4737 | if (iiOp==OPEN_CMD) return slOpen(l, SI_LINK_OPEN,v); |
---|
4738 | else { slPrepClose(l); return slClose(l);} |
---|
4739 | } |
---|
4740 | static BOOLEAN jjORD(leftv res, leftv v) |
---|
4741 | { |
---|
4742 | poly p=(poly)v->Data(); |
---|
4743 | res->data=(char *)( p==NULL ? -1 : currRing->pFDeg(p,currRing) ); |
---|
4744 | return FALSE; |
---|
4745 | } |
---|
4746 | static BOOLEAN jjPAR1(leftv res, leftv v) |
---|
4747 | { |
---|
4748 | int i=(int)(long)v->Data(); |
---|
4749 | int p=0; |
---|
4750 | p=rPar(currRing); |
---|
4751 | if ((0<i) && (i<=p)) |
---|
4752 | { |
---|
4753 | res->data=(char *)n_Param(i,currRing); |
---|
4754 | } |
---|
4755 | else |
---|
4756 | { |
---|
4757 | Werror("par number %d out of range 1..%d",i,p); |
---|
4758 | return TRUE; |
---|
4759 | } |
---|
4760 | return FALSE; |
---|
4761 | } |
---|
4762 | static BOOLEAN jjPARDEG(leftv res, leftv v) |
---|
4763 | { |
---|
4764 | number nn=(number)v->Data(); |
---|
4765 | res->data = (char *)(long)n_ParDeg(nn, currRing->cf); |
---|
4766 | return FALSE; |
---|
4767 | } |
---|
4768 | static BOOLEAN jjPARSTR1(leftv res, leftv v) |
---|
4769 | { |
---|
4770 | if (currRing==NULL) |
---|
4771 | { |
---|
4772 | WerrorS("no ring active (1)"); |
---|
4773 | return TRUE; |
---|
4774 | } |
---|
4775 | int i=(int)(long)v->Data(); |
---|
4776 | int p=0; |
---|
4777 | if ((0<i) && (rParameter(currRing)!=NULL) && (i<=(p=rPar(currRing)))) |
---|
4778 | res->data=omStrDup(rParameter(currRing)[i-1]); |
---|
4779 | else |
---|
4780 | { |
---|
4781 | Werror("par number %d out of range 1..%d",i,p); |
---|
4782 | return TRUE; |
---|
4783 | } |
---|
4784 | return FALSE; |
---|
4785 | } |
---|
4786 | static BOOLEAN jjP2BI(leftv res, leftv v) |
---|
4787 | { |
---|
4788 | poly p=(poly)v->Data(); |
---|
4789 | if (p==NULL) { res->data=(char *)n_Init(0,coeffs_BIGINT); return FALSE; } |
---|
4790 | if ((pNext(p)!=NULL)|| (!pIsConstant(p))) |
---|
4791 | { |
---|
4792 | WerrorS("poly must be constant"); |
---|
4793 | return TRUE; |
---|
4794 | } |
---|
4795 | number i=pGetCoeff(p); |
---|
4796 | number n; |
---|
4797 | nMapFunc nMap=n_SetMap(currRing->cf,coeffs_BIGINT); |
---|
4798 | if (nMap!=NULL) |
---|
4799 | n=nMap(i,currRing->cf,coeffs_BIGINT); |
---|
4800 | else goto err; |
---|
4801 | res->data=(void *)n; |
---|
4802 | return FALSE; |
---|
4803 | err: |
---|
4804 | WerrorS("cannot convert to bigint"); return TRUE; |
---|
4805 | } |
---|
4806 | static BOOLEAN jjP2I(leftv res, leftv v) |
---|
4807 | { |
---|
4808 | poly p=(poly)v->Data(); |
---|
4809 | if (p==NULL) { /*res->data=(char *)0;*/ return FALSE; } |
---|
4810 | if ((pNext(p)!=NULL)|| (!pIsConstant(p))) |
---|
4811 | { |
---|
4812 | WerrorS("poly must be constant"); |
---|
4813 | return TRUE; |
---|
4814 | } |
---|
4815 | res->data = (char *)(long)iin_Int(pGetCoeff(p),currRing->cf); |
---|
4816 | return FALSE; |
---|
4817 | } |
---|
4818 | static BOOLEAN jjPREIMAGE_R(leftv res, leftv v) |
---|
4819 | { |
---|
4820 | map mapping=(map)v->Data(); |
---|
4821 | syMake(res,omStrDup(mapping->preimage)); |
---|
4822 | return FALSE; |
---|
4823 | } |
---|
4824 | static BOOLEAN jjPRIME(leftv res, leftv v) |
---|
4825 | { |
---|
4826 | int i = IsPrime((int)(long)(v->Data())); |
---|
4827 | res->data = (char *)(long)(i > 1 ? i : 2); |
---|
4828 | return FALSE; |
---|
4829 | } |
---|
4830 | static BOOLEAN jjPRUNE(leftv res, leftv v) |
---|
4831 | { |
---|
4832 | intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
4833 | ideal v_id=(ideal)v->Data(); |
---|
4834 | if (w!=NULL) |
---|
4835 | { |
---|
4836 | if (!idTestHomModule(v_id,currRing->qideal,w)) |
---|
4837 | { |
---|
4838 | WarnS("wrong weights"); |
---|
4839 | w=NULL; |
---|
4840 | // and continue at the non-homog case below |
---|
4841 | } |
---|
4842 | else |
---|
4843 | { |
---|
4844 | w=ivCopy(w); |
---|
4845 | intvec **ww=&w; |
---|
4846 | res->data = (char *)idMinEmbedding(v_id,FALSE,ww); |
---|
4847 | atSet(res,omStrDup("isHomog"),*ww,INTVEC_CMD); |
---|
4848 | return FALSE; |
---|
4849 | } |
---|
4850 | } |
---|
4851 | res->data = (char *)idMinEmbedding(v_id); |
---|
4852 | return FALSE; |
---|
4853 | } |
---|
4854 | static BOOLEAN jjP2N(leftv res, leftv v) |
---|
4855 | { |
---|
4856 | number n; |
---|
4857 | poly p; |
---|
4858 | if (((p=(poly)v->Data())!=NULL) |
---|
4859 | && (pIsConstant(p))) |
---|
4860 | { |
---|
4861 | n=nCopy(pGetCoeff(p)); |
---|
4862 | } |
---|
4863 | else |
---|
4864 | { |
---|
4865 | n=nInit(0); |
---|
4866 | } |
---|
4867 | res->data = (char *)n; |
---|
4868 | return FALSE; |
---|
4869 | } |
---|
4870 | static BOOLEAN jjRESERVEDNAME(leftv res, leftv v) |
---|
4871 | { |
---|
4872 | char *s= (char *)v->Data(); |
---|
4873 | // try system keywords |
---|
4874 | for(unsigned i=0; i<sArithBase.nCmdUsed; i++) |
---|
4875 | { |
---|
4876 | //Print("test %d, >>%s<<, tab:>>%s<<\n",i,s,sArithBase.sCmds[i].name); |
---|
4877 | if (strcmp(s, sArithBase.sCmds[i].name) == 0) |
---|
4878 | { |
---|
4879 | res->data = (char *)1; |
---|
4880 | return FALSE; |
---|
4881 | } |
---|
4882 | } |
---|
4883 | // try blackbox names |
---|
4884 | int id; |
---|
4885 | blackboxIsCmd(s,id); |
---|
4886 | if (id>0) |
---|
4887 | { |
---|
4888 | res->data = (char *)1; |
---|
4889 | } |
---|
4890 | return FALSE; |
---|
4891 | } |
---|
4892 | static BOOLEAN jjRANK1(leftv res, leftv v) |
---|
4893 | { |
---|
4894 | matrix m =(matrix)v->Data(); |
---|
4895 | int rank = luRank(m, 0); |
---|
4896 | res->data =(char *)(long)rank; |
---|
4897 | return FALSE; |
---|
4898 | } |
---|
4899 | static BOOLEAN jjREAD(leftv res, leftv v) |
---|
4900 | { |
---|
4901 | return jjREAD2(res,v,NULL); |
---|
4902 | } |
---|
4903 | static BOOLEAN jjREGULARITY(leftv res, leftv v) |
---|
4904 | { |
---|
4905 | res->data = (char *)(long)iiRegularity((lists)v->Data()); |
---|
4906 | return FALSE; |
---|
4907 | } |
---|
4908 | static BOOLEAN jjREPART(leftv res, leftv v) |
---|
4909 | { |
---|
4910 | res->data = (char *)n_RePart((number)v->Data(),currRing->cf); |
---|
4911 | return FALSE; |
---|
4912 | } |
---|
4913 | static BOOLEAN jjRINGLIST(leftv res, leftv v) |
---|
4914 | { |
---|
4915 | ring r=(ring)v->Data(); |
---|
4916 | if (r!=NULL) |
---|
4917 | { |
---|
4918 | res->data = (char *)rDecompose((ring)v->Data()); |
---|
4919 | if (res->data!=NULL) |
---|
4920 | { |
---|
4921 | long mm=r->bitmask/2; |
---|
4922 | if (mm>MAX_INT_VAL) mm=MAX_INT_VAL; |
---|
4923 | atSet(res,omStrDup("maxExp"),(void*)mm,INT_CMD); |
---|
4924 | return FALSE; |
---|
4925 | } |
---|
4926 | } |
---|
4927 | return TRUE; |
---|
4928 | } |
---|
4929 | static BOOLEAN jjRINGLIST_C(leftv res, leftv v) |
---|
4930 | { |
---|
4931 | coeffs r=(coeffs)v->Data(); |
---|
4932 | if (r!=NULL) |
---|
4933 | return rDecompose_CF(res,r); |
---|
4934 | return TRUE; |
---|
4935 | } |
---|
4936 | static BOOLEAN jjRING_LIST(leftv res, leftv v) |
---|
4937 | { |
---|
4938 | ring r=(ring)v->Data(); |
---|
4939 | if (r!=NULL) |
---|
4940 | res->data = (char *)rDecompose_list_cf((ring)v->Data()); |
---|
4941 | return (r==NULL)||(res->data==NULL); |
---|
4942 | } |
---|
4943 | static BOOLEAN jjROWS(leftv res, leftv v) |
---|
4944 | { |
---|
4945 | ideal i = (ideal)v->Data(); |
---|
4946 | res->data = (char *)i->rank; |
---|
4947 | return FALSE; |
---|
4948 | } |
---|
4949 | static BOOLEAN jjROWS_BIM(leftv res, leftv v) |
---|
4950 | { |
---|
4951 | res->data = (char *)(long)((bigintmat*)(v->Data()))->rows(); |
---|
4952 | return FALSE; |
---|
4953 | } |
---|
4954 | static BOOLEAN jjROWS_IV(leftv res, leftv v) |
---|
4955 | { |
---|
4956 | res->data = (char *)(long)((intvec*)(v->Data()))->rows(); |
---|
4957 | return FALSE; |
---|
4958 | } |
---|
4959 | static BOOLEAN jjRPAR(leftv res, leftv v) |
---|
4960 | { |
---|
4961 | res->data = (char *)(long)rPar(((ring)v->Data())); |
---|
4962 | return FALSE; |
---|
4963 | } |
---|
4964 | static BOOLEAN jjS2I(leftv res, leftv v) |
---|
4965 | { |
---|
4966 | res->data = (char *)(long)atoi((char*)v->Data()); |
---|
4967 | return FALSE; |
---|
4968 | } |
---|
4969 | static BOOLEAN jjSLIM_GB(leftv res, leftv u) |
---|
4970 | { |
---|
4971 | const bool bIsSCA = rIsSCA(currRing); |
---|
4972 | |
---|
4973 | if ((currRing->qideal!=NULL) && !bIsSCA) |
---|
4974 | { |
---|
4975 | WerrorS("qring not supported by slimgb at the moment"); |
---|
4976 | return TRUE; |
---|
4977 | } |
---|
4978 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
4979 | { |
---|
4980 | WerrorS("ordering must be global for slimgb"); |
---|
4981 | return TRUE; |
---|
4982 | } |
---|
4983 | if (rField_is_numeric(currRing)) |
---|
4984 | WarnS("groebner base computations with inexact coefficients can not be trusted due to rounding errors"); |
---|
4985 | intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD); |
---|
4986 | // tHomog hom=testHomog; |
---|
4987 | ideal u_id=(ideal)u->Data(); |
---|
4988 | if (w!=NULL) |
---|
4989 | { |
---|
4990 | if (!idTestHomModule(u_id,currRing->qideal,w)) |
---|
4991 | { |
---|
4992 | WarnS("wrong weights"); |
---|
4993 | w=NULL; |
---|
4994 | } |
---|
4995 | else |
---|
4996 | { |
---|
4997 | w=ivCopy(w); |
---|
4998 | // hom=isHomog; |
---|
4999 | } |
---|
5000 | } |
---|
5001 | |
---|
5002 | assume(u_id->rank>=id_RankFreeModule(u_id, currRing)); |
---|
5003 | res->data=(char *)t_rep_gb(currRing, |
---|
5004 | u_id,u_id->rank); |
---|
5005 | //res->data=(char *)t_rep_gb(currRing, u_id); |
---|
5006 | |
---|
5007 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5008 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
5009 | return FALSE; |
---|
5010 | } |
---|
5011 | static BOOLEAN jjSBA(leftv res, leftv v) |
---|
5012 | { |
---|
5013 | ideal result; |
---|
5014 | ideal v_id=(ideal)v->Data(); |
---|
5015 | intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
5016 | tHomog hom=testHomog; |
---|
5017 | if (w!=NULL) |
---|
5018 | { |
---|
5019 | if (!idTestHomModule(v_id,currRing->qideal,w)) |
---|
5020 | { |
---|
5021 | WarnS("wrong weights"); |
---|
5022 | w=NULL; |
---|
5023 | } |
---|
5024 | else |
---|
5025 | { |
---|
5026 | hom=isHomog; |
---|
5027 | w=ivCopy(w); |
---|
5028 | } |
---|
5029 | } |
---|
5030 | result=kSba(v_id,currRing->qideal,hom,&w,1,0); |
---|
5031 | idSkipZeroes(result); |
---|
5032 | res->data = (char *)result; |
---|
5033 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5034 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
5035 | return FALSE; |
---|
5036 | } |
---|
5037 | static BOOLEAN jjSBA_1(leftv res, leftv v, leftv u) |
---|
5038 | { |
---|
5039 | ideal result; |
---|
5040 | ideal v_id=(ideal)v->Data(); |
---|
5041 | intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
5042 | tHomog hom=testHomog; |
---|
5043 | if (w!=NULL) |
---|
5044 | { |
---|
5045 | if (!idTestHomModule(v_id,currRing->qideal,w)) |
---|
5046 | { |
---|
5047 | WarnS("wrong weights"); |
---|
5048 | w=NULL; |
---|
5049 | } |
---|
5050 | else |
---|
5051 | { |
---|
5052 | hom=isHomog; |
---|
5053 | w=ivCopy(w); |
---|
5054 | } |
---|
5055 | } |
---|
5056 | result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),0); |
---|
5057 | idSkipZeroes(result); |
---|
5058 | res->data = (char *)result; |
---|
5059 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5060 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
5061 | return FALSE; |
---|
5062 | } |
---|
5063 | static BOOLEAN jjSBA_2(leftv res, leftv v, leftv u, leftv t) |
---|
5064 | { |
---|
5065 | ideal result; |
---|
5066 | ideal v_id=(ideal)v->Data(); |
---|
5067 | intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
5068 | tHomog hom=testHomog; |
---|
5069 | if (w!=NULL) |
---|
5070 | { |
---|
5071 | if (!idTestHomModule(v_id,currRing->qideal,w)) |
---|
5072 | { |
---|
5073 | WarnS("wrong weights"); |
---|
5074 | w=NULL; |
---|
5075 | } |
---|
5076 | else |
---|
5077 | { |
---|
5078 | hom=isHomog; |
---|
5079 | w=ivCopy(w); |
---|
5080 | } |
---|
5081 | } |
---|
5082 | result=kSba(v_id,currRing->qideal,hom,&w,(int)(long)u->Data(),(int)(long)t->Data()); |
---|
5083 | idSkipZeroes(result); |
---|
5084 | res->data = (char *)result; |
---|
5085 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5086 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
5087 | return FALSE; |
---|
5088 | } |
---|
5089 | static BOOLEAN jjSTD(leftv res, leftv v) |
---|
5090 | { |
---|
5091 | if (rField_is_numeric(currRing)) |
---|
5092 | WarnS("groebner base computations with inexact coefficients can not be trusted due to rounding errors"); |
---|
5093 | ideal result; |
---|
5094 | ideal v_id=(ideal)v->Data(); |
---|
5095 | intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
5096 | tHomog hom=testHomog; |
---|
5097 | if (w!=NULL) |
---|
5098 | { |
---|
5099 | if (!idTestHomModule(v_id,currRing->qideal,w)) |
---|
5100 | { |
---|
5101 | WarnS("wrong weights"); |
---|
5102 | w=NULL; |
---|
5103 | } |
---|
5104 | else |
---|
5105 | { |
---|
5106 | hom=isHomog; |
---|
5107 | w=ivCopy(w); |
---|
5108 | } |
---|
5109 | } |
---|
5110 | result=kStd(v_id,currRing->qideal,hom,&w); |
---|
5111 | idSkipZeroes(result); |
---|
5112 | res->data = (char *)result; |
---|
5113 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5114 | if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); |
---|
5115 | return FALSE; |
---|
5116 | } |
---|
5117 | static BOOLEAN jjSort_Id(leftv res, leftv v) |
---|
5118 | { |
---|
5119 | res->data = (char *)idSort((ideal)v->Data()); |
---|
5120 | return FALSE; |
---|
5121 | } |
---|
5122 | static BOOLEAN jjSQR_FREE(leftv res, leftv u) |
---|
5123 | { |
---|
5124 | singclap_factorize_retry=0; |
---|
5125 | intvec *v=NULL; |
---|
5126 | ideal f=singclap_sqrfree((poly)(u->CopyD()), &v, 0, currRing); |
---|
5127 | if (f==NULL) return TRUE; |
---|
5128 | ivTest(v); |
---|
5129 | lists l=(lists)omAllocBin(slists_bin); |
---|
5130 | l->Init(2); |
---|
5131 | l->m[0].rtyp=IDEAL_CMD; |
---|
5132 | l->m[0].data=(void *)f; |
---|
5133 | l->m[1].rtyp=INTVEC_CMD; |
---|
5134 | l->m[1].data=(void *)v; |
---|
5135 | res->data=(void *)l; |
---|
5136 | return FALSE; |
---|
5137 | } |
---|
5138 | #if 0 |
---|
5139 | static BOOLEAN jjSYZYGY(leftv res, leftv v) |
---|
5140 | { |
---|
5141 | intvec *w=NULL; |
---|
5142 | res->data = (char *)idSyzygies((ideal)v->Data(),testHomog,&w); |
---|
5143 | if (w!=NULL) delete w; |
---|
5144 | if (TEST_OPT_RETURN_SB) setFlag(res,FLAG_STD); |
---|
5145 | return FALSE; |
---|
5146 | } |
---|
5147 | #else |
---|
5148 | // activate, if idSyz handle module weights correctly ! |
---|
5149 | static BOOLEAN jjSYZYGY(leftv res, leftv v) |
---|
5150 | { |
---|
5151 | intvec *ww=(intvec *)atGet(v,"isHomog",INTVEC_CMD); |
---|
5152 | intvec *w=NULL; |
---|
5153 | ideal v_id=(ideal)v->Data(); |
---|
5154 | tHomog hom=testHomog; |
---|
5155 | #ifdef HAVE_SHIFTBBA |
---|
5156 | if (rIsLPRing(currRing)) |
---|
5157 | { |
---|
5158 | if (currRing->LPncGenCount < IDELEMS(v_id)) |
---|
5159 | { |
---|
5160 | Werror("At least %d ncgen variables are needed for this computation.", IDELEMS(v_id)); |
---|
5161 | return TRUE; |
---|
5162 | } |
---|
5163 | } |
---|
5164 | #endif |
---|
5165 | if (ww!=NULL) |
---|
5166 | { |
---|
5167 | if (idTestHomModule(v_id,currRing->qideal,ww)) |
---|
5168 | { |
---|
5169 | w=ivCopy(ww); |
---|
5170 | int add_row_shift=w->min_in(); |
---|
5171 | (*w)-=add_row_shift; |
---|
5172 | hom=isHomog; |
---|
5173 | } |
---|
5174 | else |
---|
5175 | { |
---|
5176 | //WarnS("wrong weights"); |
---|
5177 | delete ww; ww=NULL; |
---|
5178 | hom=testHomog; |
---|
5179 | } |
---|
5180 | } |
---|
5181 | else |
---|
5182 | { |
---|
5183 | if (v->Typ()==IDEAL_CMD) |
---|
5184 | if (idHomIdeal(v_id,currRing->qideal)) |
---|
5185 | hom=isHomog; |
---|
5186 | } |
---|
5187 | ideal S=idSyzygies(v_id,hom,&w); |
---|
5188 | res->data = (char *)S; |
---|
5189 | if (hom==isHomog) |
---|
5190 | { |
---|
5191 | int vl=S->rank; |
---|
5192 | intvec *vv=new intvec(vl); |
---|
5193 | if ((v->Typ()==IDEAL_CMD)||(ww==NULL)) |
---|
5194 | { |
---|
5195 | for(int i=0;i<vl;i++) |
---|
5196 | { |
---|
5197 | if (v_id->m[i]!=NULL) |
---|
5198 | (*vv)[i]=p_Deg(v_id->m[i],currRing); |
---|
5199 | } |
---|
5200 | } |
---|
5201 | else |
---|
5202 | { |
---|
5203 | p_SetModDeg(ww, currRing); |
---|
5204 | for(int i=0;i<vl;i++) |
---|
5205 | { |
---|
5206 | if (v_id->m[i]!=NULL) |
---|
5207 | (*vv)[i]=currRing->pFDeg(v_id->m[i],currRing); |
---|
5208 | } |
---|
5209 | p_SetModDeg(NULL, currRing); |
---|
5210 | } |
---|
5211 | if (idTestHomModule(S,currRing->qideal,vv)) |
---|
5212 | atSet(res,omStrDup("isHomog"),vv,INTVEC_CMD); |
---|
5213 | else |
---|
5214 | delete vv; |
---|
5215 | } |
---|
5216 | if (w!=NULL) delete w; |
---|
5217 | return FALSE; |
---|
5218 | } |
---|
5219 | #endif |
---|
5220 | static BOOLEAN jjTRACE_IV(leftv res, leftv v) |
---|
5221 | { |
---|
5222 | res->data = (char *)(long)ivTrace((intvec*)(v->Data())); |
---|
5223 | return FALSE; |
---|
5224 | } |
---|
5225 | static BOOLEAN jjTRANSP_BIM(leftv res, leftv v) |
---|
5226 | { |
---|
5227 | res->data = (char *)(((bigintmat*)(v->Data()))->transpose()); |
---|
5228 | return FALSE; |
---|
5229 | } |
---|
5230 | static BOOLEAN jjTRANSP_IV(leftv res, leftv v) |
---|
5231 | { |
---|
5232 | res->data = (char *)ivTranp((intvec*)(v->Data())); |
---|
5233 | return FALSE; |
---|
5234 | } |
---|
5235 | #ifdef HAVE_PLURAL |
---|
5236 | static BOOLEAN jjOPPOSITE(leftv res, leftv a) |
---|
5237 | { |
---|
5238 | ring r = (ring)a->Data(); |
---|
5239 | //if (rIsPluralRing(r)) |
---|
5240 | if (r->OrdSgn==1) |
---|
5241 | { |
---|
5242 | res->data = rOpposite(r); |
---|
5243 | } |
---|
5244 | else |
---|
5245 | { |
---|
5246 | WarnS("opposite only for global orderings"); |
---|
5247 | res->data = rCopy(r); |
---|
5248 | } |
---|
5249 | return FALSE; |
---|
5250 | } |
---|
5251 | static BOOLEAN jjENVELOPE(leftv res, leftv a) |
---|
5252 | { |
---|
5253 | ring r = (ring)a->Data(); |
---|
5254 | if (rIsPluralRing(r)) |
---|
5255 | { |
---|
5256 | ring s = rEnvelope(r); |
---|
5257 | res->data = s; |
---|
5258 | } |
---|
5259 | else res->data = rCopy(r); |
---|
5260 | return FALSE; |
---|
5261 | } |
---|
5262 | static BOOLEAN jjTWOSTD(leftv res, leftv a) |
---|
5263 | { |
---|
5264 | ideal result; |
---|
5265 | ideal v_id=(ideal)a->Data(); |
---|
5266 | if (rIsPluralRing(currRing)) |
---|
5267 | result=(ideal)twostd(v_id); |
---|
5268 | else /*commutative or shiftalgebra*/ |
---|
5269 | { |
---|
5270 | return jjSTD(res,a); |
---|
5271 | } |
---|
5272 | res->data = (char *)result; |
---|
5273 | setFlag(res,FLAG_STD); |
---|
5274 | setFlag(res,FLAG_TWOSTD); |
---|
5275 | return FALSE; |
---|
5276 | } |
---|
5277 | #endif |
---|
5278 | #if defined(HAVE_SHIFTBBA) || defined(HAVE_PLURAL)// do not place above jjSTD in this file because we need to reference it |
---|
5279 | static BOOLEAN jjRIGHTSTD(leftv res, leftv v) |
---|
5280 | { |
---|
5281 | if (rIsLPRing(currRing)) |
---|
5282 | { |
---|
5283 | if (rField_is_numeric(currRing)) |
---|
5284 | WarnS("groebner base computations with inexact coefficients can not be trusted due to rounding errors"); |
---|
5285 | ideal result; |
---|
5286 | ideal v_id=(ideal)v->Data(); |
---|
5287 | /* intvec *w=(intvec *)atGet(v,"isHomog",INTVEC_CMD); */ |
---|
5288 | /* tHomog hom=testHomog; */ |
---|
5289 | /* if (w!=NULL) */ |
---|
5290 | /* { */ |
---|
5291 | /* if (!idTestHomModule(v_id,currRing->qideal,w)) */ |
---|
5292 | /* { */ |
---|
5293 | /* WarnS("wrong weights"); */ |
---|
5294 | /* w=NULL; */ |
---|
5295 | /* } */ |
---|
5296 | /* else */ |
---|
5297 | /* { */ |
---|
5298 | /* hom=isHomog; */ |
---|
5299 | /* w=ivCopy(w); */ |
---|
5300 | /* } */ |
---|
5301 | /* } */ |
---|
5302 | /* result=kStd(v_id,currRing->qideal,hom,&w); */ |
---|
5303 | result = rightgb(v_id, currRing->qideal); |
---|
5304 | idSkipZeroes(result); |
---|
5305 | res->data = (char *)result; |
---|
5306 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5307 | /* if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD); */ |
---|
5308 | return FALSE; |
---|
5309 | } |
---|
5310 | else if (rIsPluralRing(currRing)) |
---|
5311 | { |
---|
5312 | ideal I=(ideal)v->Data(); |
---|
5313 | |
---|
5314 | ring A = currRing; |
---|
5315 | ring Aopp = rOpposite(A); |
---|
5316 | currRing = Aopp; |
---|
5317 | ideal Iopp = idOppose(A, I, Aopp); |
---|
5318 | ideal Jopp = kStd(Iopp,currRing->qideal,testHomog,NULL); |
---|
5319 | currRing = A; |
---|
5320 | ideal J = idOppose(Aopp, Jopp, A); |
---|
5321 | |
---|
5322 | id_Delete(&Iopp, Aopp); |
---|
5323 | id_Delete(&Jopp, Aopp); |
---|
5324 | rDelete(Aopp); |
---|
5325 | |
---|
5326 | idSkipZeroes(J); |
---|
5327 | res->data = (char *)J; |
---|
5328 | if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD); |
---|
5329 | return FALSE; |
---|
5330 | } |
---|
5331 | else |
---|
5332 | { |
---|
5333 | return jjSTD(res, v); |
---|
5334 | } |
---|
5335 | } |
---|
5336 | #endif |
---|
5337 | static BOOLEAN jjTYPEOF(leftv res, leftv v) |
---|
5338 | { |
---|
5339 | int t=(int)(long)v->data; |
---|
5340 | switch (t) |
---|
5341 | { |
---|
5342 | case CRING_CMD: |
---|
5343 | case INT_CMD: |
---|
5344 | case POLY_CMD: |
---|
5345 | case VECTOR_CMD: |
---|
5346 | case STRING_CMD: |
---|
5347 | case INTVEC_CMD: |
---|
5348 | case IDEAL_CMD: |
---|
5349 | case MATRIX_CMD: |
---|
5350 | case MODUL_CMD: |
---|
5351 | case MAP_CMD: |
---|
5352 | case PROC_CMD: |
---|
5353 | case RING_CMD: |
---|
5354 | case SMATRIX_CMD: |
---|
5355 | //case QRING_CMD: |
---|
5356 | case INTMAT_CMD: |
---|
5357 | case BIGINTMAT_CMD: |
---|
5358 | case NUMBER_CMD: |
---|
5359 | #ifdef SINGULAR_4_2 |
---|
5360 | case CNUMBER_CMD: |
---|
5361 | #endif |
---|
5362 | case BIGINT_CMD: |
---|
5363 | case BUCKET_CMD: |
---|
5364 | case LIST_CMD: |
---|
5365 | case PACKAGE_CMD: |
---|
5366 | case LINK_CMD: |
---|
5367 | case RESOLUTION_CMD: |
---|
5368 | res->data=omStrDup(Tok2Cmdname(t)); break; |
---|
5369 | case DEF_CMD: |
---|
5370 | case NONE: res->data=omStrDup("none"); break; |
---|
5371 | default: |
---|
5372 | { |
---|
5373 | if (t>MAX_TOK) |
---|
5374 | res->data=omStrDup(getBlackboxName(t)); |
---|
5375 | else |
---|
5376 | res->data=omStrDup("?unknown type?"); |
---|
5377 | break; |
---|
5378 | } |
---|
5379 | } |
---|
5380 | return FALSE; |
---|
5381 | } |
---|
5382 | static BOOLEAN jjUNIVARIATE(leftv res, leftv v) |
---|
5383 | { |
---|
5384 | res->data=(char *)(long)pIsUnivariate((poly)v->Data()); |
---|
5385 | return FALSE; |
---|
5386 | } |
---|
5387 | static BOOLEAN jjVAR1(leftv res, leftv v) |
---|
5388 | { |
---|
5389 | int i=(int)(long)v->Data(); |
---|
5390 | if ((0<i) && (i<=currRing->N)) |
---|
5391 | { |
---|
5392 | poly p=pOne(); |
---|
5393 | pSetExp(p,i,1); |
---|
5394 | pSetm(p); |
---|
5395 | res->data=(char *)p; |
---|
5396 | } |
---|
5397 | else |
---|
5398 | { |
---|
5399 | Werror("var number %d out of range 1..%d",i,currRing->N); |
---|
5400 | return TRUE; |
---|
5401 | } |
---|
5402 | return FALSE; |
---|
5403 | } |
---|
5404 | static BOOLEAN jjVARSTR1(leftv res, leftv v) |
---|
5405 | { |
---|
5406 | if (currRing==NULL) |
---|
5407 | { |
---|
5408 | WerrorS("no ring active (2)"); |
---|
5409 | return TRUE; |
---|
5410 | } |
---|
5411 | int i=(int)(long)v->Data(); |
---|
5412 | if ((0<i) && (i<=currRing->N)) |
---|
5413 | res->data=omStrDup(currRing->names[i-1]); |
---|
5414 | else |
---|
5415 | { |
---|
5416 | Werror("var number %d out of range 1..%d",i,currRing->N); |
---|
5417 | return TRUE; |
---|
5418 | } |
---|
5419 | return FALSE; |
---|
5420 | } |
---|
5421 | static BOOLEAN jjVDIM(leftv res, leftv v) |
---|
5422 | { |
---|
5423 | assumeStdFlag(v); |
---|
5424 | res->data = (char *)(long)scMult0Int((ideal)v->Data(),currRing->qideal); |
---|
5425 | return FALSE; |
---|
5426 | } |
---|
5427 | BOOLEAN jjWAIT1ST1(leftv res, leftv u) |
---|
5428 | { |
---|
5429 | // input: u: a list with links of type |
---|
5430 | // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch |
---|
5431 | // returns: -1: the read state of all links is eof |
---|
5432 | // i>0: (at least) u[i] is ready |
---|
5433 | lists Lforks = (lists)u->Data(); |
---|
5434 | int i = slStatusSsiL(Lforks, -1); |
---|
5435 | if(i == -2) /* error */ |
---|
5436 | { |
---|
5437 | return TRUE; |
---|
5438 | } |
---|
5439 | res->data = (void*)(long)i; |
---|
5440 | return FALSE; |
---|
5441 | } |
---|
5442 | BOOLEAN jjWAITALL1(leftv res, leftv u) |
---|
5443 | { |
---|
5444 | // input: u: a list with links of type |
---|
5445 | // ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch |
---|
5446 | // returns: -1: the read state of all links is eof |
---|
5447 | // 1: all links are ready |
---|
5448 | // (caution: at least one is ready, but some maybe dead) |
---|
5449 | lists Lforks = (lists)u->CopyD(); |
---|
5450 | int i; |
---|
5451 | int j = -1; |
---|
5452 | for(int nfinished = 0; nfinished < Lforks->nr+1; nfinished++) |
---|
5453 | { |
---|
5454 | i = slStatusSsiL(Lforks, -1); |
---|
5455 | if(i == -2) /* error */ |
---|
5456 | { |
---|
5457 | return TRUE; |
---|
5458 | } |
---|
5459 | if(i == -1) |
---|
5460 | { |
---|
5461 | break; |
---|
5462 | } |
---|
5463 | j = 1; |
---|
5464 | Lforks->m[i-1].CleanUp(); |
---|
5465 | Lforks->m[i-1].rtyp=DEF_CMD; |
---|
5466 | Lforks->m[i-1].data=NULL; |
---|
5467 | } |
---|
5468 | res->data = (void*)(long)j; |
---|
5469 | Lforks->Clean(); |
---|
5470 | return FALSE; |
---|
5471 | } |
---|
5472 | |
---|
5473 | BOOLEAN jjLOAD(const char *s, BOOLEAN autoexport) |
---|
5474 | { |
---|
5475 | char libnamebuf[1024]; |
---|
5476 | lib_types LT = type_of_LIB(s, libnamebuf); |
---|
5477 | |
---|
5478 | #ifdef HAVE_DYNAMIC_LOADING |
---|
5479 | extern BOOLEAN load_modules(const char *newlib, char *fullpath, BOOLEAN autoexport); |
---|
5480 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
5481 | switch(LT) |
---|
5482 | { |
---|
5483 | default: |
---|
5484 | case LT_NONE: |
---|
5485 | Werror("%s: unknown type", s); |
---|
5486 | break; |
---|
5487 | case LT_NOTFOUND: |
---|
5488 | Werror("cannot open %s", s); |
---|
5489 | break; |
---|
5490 | |
---|
5491 | case LT_SINGULAR: |
---|
5492 | { |
---|
5493 | char *plib = iiConvName(s); |
---|
5494 | idhdl pl = IDROOT->get_level(plib,0); |
---|
5495 | if (pl==NULL) |
---|
5496 | { |
---|
5497 | pl = enterid( plib,0, PACKAGE_CMD, &(basePack->idroot), TRUE ); |
---|
5498 | IDPACKAGE(pl)->language = LANG_SINGULAR; |
---|
5499 | IDPACKAGE(pl)->libname=omStrDup(s); |
---|
5500 | } |
---|
5501 | else if (IDTYP(pl)!=PACKAGE_CMD) |
---|
5502 | { |
---|
5503 | Werror("can not create package `%s`",plib); |
---|
5504 | omFree(plib); |
---|
5505 | return TRUE; |
---|
5506 | } |
---|
5507 | else /* package */ |
---|
5508 | { |
---|
5509 | package pa=IDPACKAGE(pl); |
---|
5510 | if ((pa->language==LANG_C) |
---|
5511 | || (pa->language==LANG_MIX)) |
---|
5512 | { |
---|
5513 | Werror("can not create package `%s` - binaries exists",plib); |
---|
5514 | omfree(plib); |
---|
5515 | return TRUE; |
---|
5516 | } |
---|
5517 | } |
---|
5518 | omFree(plib); |
---|
5519 | package savepack=currPack; |
---|
5520 | currPack=IDPACKAGE(pl); |
---|
5521 | IDPACKAGE(pl)->loaded=TRUE; |
---|
5522 | char libnamebuf[1024]; |
---|
5523 | FILE * fp = feFopen( s, "r", libnamebuf, TRUE ); |
---|
5524 | BOOLEAN bo=iiLoadLIB(fp, libnamebuf, s, pl, autoexport, TRUE); |
---|
5525 | currPack=savepack; |
---|
5526 | IDPACKAGE(pl)->loaded=(!bo); |
---|
5527 | return bo; |
---|
5528 | } |
---|
5529 | case LT_BUILTIN: |
---|
5530 | SModulFunc_t iiGetBuiltinModInit(const char*); |
---|
5531 | return load_builtin(s,autoexport, iiGetBuiltinModInit(s)); |
---|
5532 | case LT_MACH_O: |
---|
5533 | case LT_ELF: |
---|
5534 | case LT_HPUX: |
---|
5535 | #ifdef HAVE_DYNAMIC_LOADING |
---|
5536 | return load_modules(s, libnamebuf, autoexport); |
---|
5537 | #else /* HAVE_DYNAMIC_LOADING */ |
---|
5538 | WerrorS("Dynamic modules are not supported by this version of Singular"); |
---|
5539 | break; |
---|
5540 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
5541 | } |
---|
5542 | return TRUE; |
---|
5543 | } |
---|
5544 | STATIC_VAR int WerrorS_dummy_cnt=0; |
---|
5545 | static void WerrorS_dummy(const char *) |
---|
5546 | { |
---|
5547 | WerrorS_dummy_cnt++; |
---|
5548 | } |
---|
5549 | BOOLEAN jjLOAD_TRY(const char *s) |
---|
5550 | { |
---|
5551 | if (!iiGetLibStatus(s)) |
---|
5552 | { |
---|
5553 | void (*WerrorS_save)(const char *s) = WerrorS_callback; |
---|
5554 | WerrorS_callback=WerrorS_dummy; |
---|
5555 | WerrorS_dummy_cnt=0; |
---|
5556 | BOOLEAN bo=jjLOAD(s,TRUE); |
---|
5557 | if (TEST_OPT_PROT && (bo || (WerrorS_dummy_cnt>0))) |
---|
5558 | Print("loading of >%s< failed\n",s); |
---|
5559 | WerrorS_callback=WerrorS_save; |
---|
5560 | errorreported=0; |
---|
5561 | } |
---|
5562 | return FALSE; |
---|
5563 | } |
---|
5564 | |
---|
5565 | static BOOLEAN jjstrlen(leftv res, leftv v) |
---|
5566 | { |
---|
5567 | res->data = (char *)strlen((char *)v->Data()); |
---|
5568 | return FALSE; |
---|
5569 | } |
---|
5570 | static BOOLEAN jjpLength(leftv res, leftv v) |
---|
5571 | { |
---|
5572 | res->data = (char *)(long)pLength((poly)v->Data()); |
---|
5573 | return FALSE; |
---|
5574 | } |
---|
5575 | static BOOLEAN jjidElem(leftv res, leftv v) |
---|
5576 | { |
---|
5577 | res->data = (char *)(long)idElem((ideal)v->Data()); |
---|
5578 | return FALSE; |
---|
5579 | } |
---|
5580 | static BOOLEAN jjidFreeModule(leftv res, leftv v) |
---|
5581 | { |
---|
5582 | res->data = (char *)id_FreeModule((int)(long)v->Data(), currRing); |
---|
5583 | return FALSE; |
---|
5584 | } |
---|
5585 | static BOOLEAN jjidVec2Ideal(leftv res, leftv v) |
---|
5586 | { |
---|
5587 | res->data = (char *)id_Vec2Ideal((poly)v->Data(), currRing); |
---|
5588 | return FALSE; |
---|
5589 | } |
---|
5590 | static BOOLEAN jjrCharStr(leftv res, leftv v) |
---|
5591 | { |
---|
5592 | res->data = rCharStr((ring)v->Data()); |
---|
5593 | return FALSE; |
---|
5594 | } |
---|
5595 | static BOOLEAN jjpHead(leftv res, leftv v) |
---|
5596 | { |
---|
5597 | res->data = (char *)pHead((poly)v->Data()); |
---|
5598 | return FALSE; |
---|
5599 | } |
---|
5600 | static BOOLEAN jjidHead(leftv res, leftv v) |
---|
5601 | { |
---|
5602 | res->data = (char *)id_Head((ideal)v->Data(),currRing); |
---|
5603 | setFlag(res,FLAG_STD); |
---|
5604 | return FALSE; |
---|
5605 | } |
---|
5606 | static BOOLEAN jjidMinBase(leftv res, leftv v) |
---|
5607 | { |
---|
5608 | res->data = (char *)idMinBase((ideal)v->Data()); |
---|
5609 | return FALSE; |
---|
5610 | } |
---|
5611 | #if 0 // unused |
---|
5612 | static BOOLEAN jjsyMinBase(leftv res, leftv v) |
---|
5613 | { |
---|
5614 | res->data = (char *)syMinBase((ideal)v->Data()); |
---|
5615 | return FALSE; |
---|
5616 | } |
---|
5617 | #endif |
---|
5618 | static BOOLEAN jjpMaxComp(leftv res, leftv v) |
---|
5619 | { |
---|
5620 | res->data = (char *)pMaxComp((poly)v->Data()); |
---|
5621 | return FALSE; |
---|
5622 | } |
---|
5623 | static BOOLEAN jjmpTrace(leftv res, leftv v) |
---|
5624 | { |
---|
5625 | res->data = (char *)mp_Trace((matrix)v->Data(),currRing); |
---|
5626 | return FALSE; |
---|
5627 | } |
---|
5628 | static BOOLEAN jjmpTransp(leftv res, leftv v) |
---|
5629 | { |
---|
5630 | res->data = (char *)mp_Transp((matrix)v->Data(),currRing); |
---|
5631 | return FALSE; |
---|
5632 | } |
---|
5633 | static BOOLEAN jjrOrdStr(leftv res, leftv v) |
---|
5634 | { |
---|
5635 | res->data = rOrdStr((ring)v->Data()); |
---|
5636 | return FALSE; |
---|
5637 | } |
---|
5638 | static BOOLEAN jjrVarStr(leftv res, leftv v) |
---|
5639 | { |
---|
5640 | res->data = rVarStr((ring)v->Data()); |
---|
5641 | return FALSE; |
---|
5642 | } |
---|
5643 | static BOOLEAN jjrParStr(leftv res, leftv v) |
---|
5644 | { |
---|
5645 | res->data = rParStr((ring)v->Data()); |
---|
5646 | return FALSE; |
---|
5647 | } |
---|
5648 | static BOOLEAN jjCOUNT_RES(leftv res, leftv v) |
---|
5649 | { |
---|
5650 | res->data=(char *)(long)sySize((syStrategy)v->Data()); |
---|
5651 | return FALSE; |
---|
5652 | } |
---|
5653 | static BOOLEAN jjDIM_R(leftv res, leftv v) |
---|
5654 | { |
---|
5655 | res->data = (char *)(long)syDim((syStrategy)v->Data()); |
---|
5656 | return FALSE; |
---|
5657 | } |
---|
5658 | static BOOLEAN jjidTransp(leftv res, leftv v) |
---|
5659 | { |
---|
5660 | res->data = (char *)id_Transp((ideal)v->Data(),currRing); |
---|
5661 | return FALSE; |
---|
5662 | } |
---|
5663 | static BOOLEAN jjnInt(leftv res, leftv u) |
---|
5664 | { |
---|
5665 | number n=(number)u->CopyD(); // n_Int may call n_Normalize |
---|
5666 | res->data=(char *)(long)iin_Int(n,currRing->cf); |
---|
5667 | n_Delete(&n,currRing->cf); |
---|
5668 | return FALSE; |
---|
5669 | } |
---|
5670 | static BOOLEAN jjnlInt(leftv res, leftv u) |
---|
5671 | { |
---|
5672 | number n=(number)u->Data(); |
---|
5673 | res->data=(char *)(long)iin_Int(n,coeffs_BIGINT ); |
---|
5674 | return FALSE; |
---|
5675 | } |
---|
5676 | /*=================== operations with 3 args.: static proc =================*/ |
---|
5677 | /* must be ordered: first operations for chars (infix ops), |
---|
5678 | * then alphabetically */ |
---|
5679 | static BOOLEAN jjBRACK_S(leftv res, leftv u, leftv v,leftv w) |
---|
5680 | { |
---|
5681 | char *s= (char *)u->Data(); |
---|
5682 | int r = (int)(long)v->Data(); |
---|
5683 | int c = (int)(long)w->Data(); |
---|
5684 | int l = strlen(s); |
---|
5685 | |
---|
5686 | if ( (r<1) || (r>l) || (c<0) ) |
---|
5687 | { |
---|
5688 | Werror("wrong range[%d,%d] in string %s",r,c,u->Fullname()); |
---|
5689 | return TRUE; |
---|
5690 | } |
---|
5691 | res->data = (char *)omAlloc((long)(c+1)); |
---|
5692 | sprintf((char *)res->data,"%-*.*s",c,c,s+r-1); |
---|
5693 | return FALSE; |
---|
5694 | } |
---|
5695 | static BOOLEAN jjBRACK_Im(leftv res, leftv u, leftv v,leftv w) |
---|
5696 | { |
---|
5697 | intvec *iv = (intvec *)u->Data(); |
---|
5698 | int r = (int)(long)v->Data(); |
---|
5699 | int c = (int)(long)w->Data(); |
---|
5700 | if ((r<1)||(r>iv->rows())||(c<1)||(c>iv->cols())) |
---|
5701 | { |
---|
5702 | Werror("wrong range[%d,%d] in intmat %s(%d x %d)", |
---|
5703 | r,c,u->Fullname(),iv->rows(),iv->cols()); |
---|
5704 | return TRUE; |
---|
5705 | } |
---|
5706 | res->data=u->data; u->data=NULL; |
---|
5707 | res->rtyp=u->rtyp; u->rtyp=0; |
---|
5708 | res->name=u->name; u->name=NULL; |
---|
5709 | Subexpr e=jjMakeSub(v); |
---|
5710 | e->next=jjMakeSub(w); |
---|
5711 | if (u->e==NULL) res->e=e; |
---|
5712 | else |
---|
5713 | { |
---|
5714 | Subexpr h=u->e; |
---|
5715 | while (h->next!=NULL) h=h->next; |
---|
5716 | h->next=e; |
---|
5717 | res->e=u->e; |
---|
5718 | u->e=NULL; |
---|
5719 | } |
---|
5720 | return FALSE; |
---|
5721 | } |
---|
5722 | static BOOLEAN jjBRACK_Bim(leftv res, leftv u, leftv v, leftv w) |
---|
5723 | { |
---|
5724 | bigintmat *bim = (bigintmat *)u->Data(); |
---|
5725 | int r = (int)(long)v->Data(); |
---|
5726 | int c = (int)(long)w->Data(); |
---|
5727 | if ((r<1)||(r>bim->rows())||(c<1)||(c>bim->cols())) |
---|
5728 | { |
---|
5729 | Werror("wrong range[%d,%d] in bigintmat %s(%d x %d)", |
---|
5730 | r,c,u->Fullname(),bim->rows(),bim->cols()); |
---|
5731 | return TRUE; |
---|
5732 | } |
---|
5733 | res->data=u->data; u->data=NULL; |
---|
5734 | res->rtyp=u->rtyp; u->rtyp=0; |
---|
5735 | res->name=u->name; u->name=NULL; |
---|
5736 | Subexpr e=jjMakeSub(v); |
---|
5737 | e->next=jjMakeSub(w); | <
---|