1 | |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | #include <kernel/mod2.h> |
---|
6 | |
---|
7 | #include <omalloc/omalloc.h> |
---|
8 | |
---|
9 | #include <misc/intvec.h> |
---|
10 | #include <misc/options.h> |
---|
11 | |
---|
12 | #include <coeffs/coeffs.h> |
---|
13 | |
---|
14 | #include <polys/PolyEnumerator.h> |
---|
15 | |
---|
16 | #include <polys/monomials/p_polys.h> |
---|
17 | #include <polys/monomials/ring.h> |
---|
18 | // #include <kernel/longrat.h> |
---|
19 | #include <kernel/GBEngine/kstd1.h> |
---|
20 | |
---|
21 | #include <kernel/polys.h> |
---|
22 | |
---|
23 | #include <kernel/GBEngine/syz.h> |
---|
24 | |
---|
25 | #include <Singular/tok.h> |
---|
26 | #include <Singular/ipid.h> |
---|
27 | #include <Singular/lists.h> |
---|
28 | #include <Singular/attrib.h> |
---|
29 | |
---|
30 | #include <Singular/ipid.h> |
---|
31 | #include <Singular/ipshell.h> // For iiAddCproc |
---|
32 | |
---|
33 | // extern coeffs coeffs_BIGINT |
---|
34 | |
---|
35 | #include "singularxx_defs.h" |
---|
36 | #include "DebugPrint.h" |
---|
37 | #include "myNF.h" |
---|
38 | |
---|
39 | |
---|
40 | #include <Singular/mod_lib.h> |
---|
41 | |
---|
42 | |
---|
43 | #if GOOGLE_PROFILE_ENABLED |
---|
44 | #include <google/profiler.h> |
---|
45 | #endif // #if GOOGLE_PROFILE_ENABLED |
---|
46 | |
---|
47 | |
---|
48 | #include <stdio.h> |
---|
49 | #include <stdlib.h> |
---|
50 | #include <string.h> |
---|
51 | |
---|
52 | |
---|
53 | #ifdef _GNU_SOURCE |
---|
54 | #define qsort_my(m, s, ss, r, cmp) qsort_r(m, s, ss, cmp, r) |
---|
55 | #else |
---|
56 | #define qsort_my(m, s, ss, r, cmp) qsort_r(m, s, ss, cmp) |
---|
57 | #endif |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | extern void pISUpdateComponents(ideal F, const intvec *const V, const int MIN, const ring r); |
---|
62 | // extern ring rCurrRingAssure_SyzComp(); |
---|
63 | extern ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sign); |
---|
64 | extern int rGetISPos(const int p, const ring r); |
---|
65 | |
---|
66 | USING_NAMESPACE( SINGULARXXNAME :: DEBUG ) |
---|
67 | USING_NAMESPACE( SINGULARXXNAME :: NF ) |
---|
68 | |
---|
69 | |
---|
70 | BEGIN_NAMESPACE_NONAME |
---|
71 | |
---|
72 | |
---|
73 | static inline void NoReturn(leftv& res) |
---|
74 | { |
---|
75 | res->rtyp = NONE; |
---|
76 | res->data = NULL; |
---|
77 | } |
---|
78 | |
---|
79 | /// wrapper around n_ClearContent |
---|
80 | static BOOLEAN _ClearContent(leftv res, leftv h) |
---|
81 | { |
---|
82 | NoReturn(res); |
---|
83 | |
---|
84 | const char *usage = "'ClearContent' needs a (non-zero!) poly or vector argument..."; |
---|
85 | |
---|
86 | if( h == NULL ) |
---|
87 | { |
---|
88 | WarnS(usage); |
---|
89 | return TRUE; |
---|
90 | } |
---|
91 | |
---|
92 | assume( h != NULL ); |
---|
93 | |
---|
94 | if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) ) |
---|
95 | { |
---|
96 | WarnS(usage); |
---|
97 | return TRUE; |
---|
98 | } |
---|
99 | |
---|
100 | assume (h->Next() == NULL); |
---|
101 | |
---|
102 | poly ph = reinterpret_cast<poly>(h->Data()); |
---|
103 | |
---|
104 | if( ph == NULL ) |
---|
105 | { |
---|
106 | WarnS(usage); |
---|
107 | return TRUE; |
---|
108 | } |
---|
109 | |
---|
110 | const ring r = currRing; |
---|
111 | assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf; |
---|
112 | |
---|
113 | number n; |
---|
114 | |
---|
115 | // experimentall (recursive enumerator treatment) of alg. ext |
---|
116 | CPolyCoeffsEnumerator itr(ph); |
---|
117 | n_ClearContent(itr, n, C); |
---|
118 | |
---|
119 | res->data = n; |
---|
120 | res->rtyp = NUMBER_CMD; |
---|
121 | |
---|
122 | return FALSE; |
---|
123 | } |
---|
124 | |
---|
125 | /// wrapper around n_ClearDenominators |
---|
126 | static BOOLEAN _ClearDenominators(leftv res, leftv h) |
---|
127 | { |
---|
128 | NoReturn(res); |
---|
129 | |
---|
130 | const char *usage = "'ClearDenominators' needs a (non-zero!) poly or vector argument..."; |
---|
131 | |
---|
132 | if( h == NULL ) |
---|
133 | { |
---|
134 | WarnS(usage); |
---|
135 | return TRUE; |
---|
136 | } |
---|
137 | |
---|
138 | assume( h != NULL ); |
---|
139 | |
---|
140 | if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) ) |
---|
141 | { |
---|
142 | WarnS(usage); |
---|
143 | return TRUE; |
---|
144 | } |
---|
145 | |
---|
146 | assume (h->Next() == NULL); |
---|
147 | |
---|
148 | poly ph = reinterpret_cast<poly>(h->Data()); |
---|
149 | |
---|
150 | if( ph == NULL ) |
---|
151 | { |
---|
152 | WarnS(usage); |
---|
153 | return TRUE; |
---|
154 | } |
---|
155 | |
---|
156 | const ring r = currRing; |
---|
157 | assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf; |
---|
158 | |
---|
159 | number n; |
---|
160 | |
---|
161 | // experimentall (recursive enumerator treatment) of alg. ext. |
---|
162 | CPolyCoeffsEnumerator itr(ph); |
---|
163 | n_ClearDenominators(itr, n, C); |
---|
164 | |
---|
165 | res->data = n; |
---|
166 | res->rtyp = NUMBER_CMD; |
---|
167 | |
---|
168 | return FALSE; |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | /// try to get an optional (simple) integer argument out of h |
---|
173 | /// or return the default value |
---|
174 | static int getOptionalInteger(const leftv& h, const int _n) |
---|
175 | { |
---|
176 | if( h!= NULL && h->Typ() == INT_CMD ) |
---|
177 | { |
---|
178 | int n = (int)(long)(h->Data()); |
---|
179 | |
---|
180 | if( n < 0 ) |
---|
181 | Warn("Negative (%d) optional integer argument", n); |
---|
182 | |
---|
183 | return (n); |
---|
184 | } |
---|
185 | |
---|
186 | return (_n); |
---|
187 | } |
---|
188 | |
---|
189 | static BOOLEAN noop(leftv __res, leftv /*__v*/) |
---|
190 | { |
---|
191 | NoReturn(__res); |
---|
192 | return FALSE; |
---|
193 | } |
---|
194 | |
---|
195 | static BOOLEAN _ProfilerStart(leftv __res, leftv h) |
---|
196 | { |
---|
197 | NoReturn(__res); |
---|
198 | #if GOOGLE_PROFILE_ENABLED |
---|
199 | if( h!= NULL && h->Typ() == STRING_CMD ) |
---|
200 | { |
---|
201 | const char* name = (char*)(h->Data()); |
---|
202 | assume( name != NULL ); |
---|
203 | ProfilerStart(name); |
---|
204 | } else |
---|
205 | WerrorS("ProfilerStart requires a string [name] argument"); |
---|
206 | #else |
---|
207 | WarnS("Sorry no google profiler support (GOOGLE_PROFILE_ENABLE!=1)..."); |
---|
208 | // return TRUE; // ? |
---|
209 | #endif // #if GOOGLE_PROFILE_ENABLED |
---|
210 | return FALSE; |
---|
211 | (void)h; |
---|
212 | } |
---|
213 | static BOOLEAN _ProfilerStop(leftv __res, leftv /*__v*/) |
---|
214 | { |
---|
215 | NoReturn(__res); |
---|
216 | #if GOOGLE_PROFILE_ENABLED |
---|
217 | ProfilerStop(); |
---|
218 | #else |
---|
219 | WarnS("Sorry no google profiler support (GOOGLE_PROFILE_ENABLED!=1)..."); |
---|
220 | // return TRUE; // ? |
---|
221 | #endif // #if GOOGLE_PROFILE_ENABLED |
---|
222 | return FALSE; |
---|
223 | } |
---|
224 | |
---|
225 | static inline number jjLONG2N(long d) |
---|
226 | { |
---|
227 | return n_Init(d, coeffs_BIGINT); |
---|
228 | } |
---|
229 | |
---|
230 | static inline void view(const intvec* v) |
---|
231 | { |
---|
232 | #ifndef SING_NDEBUG |
---|
233 | v->view(); |
---|
234 | #else |
---|
235 | // This code duplication is only due to Hannes's #ifndef SING_NDEBUG! |
---|
236 | Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length()); |
---|
237 | |
---|
238 | for (int i = 0; i < v->rows(); i++) |
---|
239 | { |
---|
240 | Print ("Row[%3d]:", i); |
---|
241 | for (int j = 0; j < v->cols(); j++) |
---|
242 | Print (" %5d", (*v)[j + i * (v->cols())] ); |
---|
243 | PrintLn (); |
---|
244 | } |
---|
245 | PrintS ("}\n"); |
---|
246 | #endif |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | static BOOLEAN DetailedPrint(leftv __res, leftv h) |
---|
253 | { |
---|
254 | NoReturn(__res); |
---|
255 | |
---|
256 | if( h == NULL ) |
---|
257 | { |
---|
258 | WarnS("DetailedPrint needs an argument..."); |
---|
259 | return TRUE; |
---|
260 | } |
---|
261 | |
---|
262 | if( h->Typ() == NUMBER_CMD) |
---|
263 | { |
---|
264 | number n = (number)h->Data(); |
---|
265 | |
---|
266 | const ring r = currRing; |
---|
267 | |
---|
268 | #ifdef LDEBUG |
---|
269 | r->cf->cfDBTest(n,__FILE__,__LINE__,r->cf); |
---|
270 | #endif |
---|
271 | |
---|
272 | StringSetS(""); |
---|
273 | n_Write(n, r->cf); |
---|
274 | PrintS(StringEndS()); |
---|
275 | PrintLn(); |
---|
276 | |
---|
277 | return FALSE; |
---|
278 | } |
---|
279 | |
---|
280 | if( h->Typ() == RING_CMD) |
---|
281 | { |
---|
282 | const ring r = (const ring)h->Data(); |
---|
283 | rWrite(r, TRUE); |
---|
284 | PrintLn(); |
---|
285 | #ifdef RDEBUG |
---|
286 | rDebugPrint(r); |
---|
287 | #endif |
---|
288 | return FALSE; |
---|
289 | } |
---|
290 | |
---|
291 | if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) |
---|
292 | { |
---|
293 | const poly p = (const poly)h->Data(); h = h->Next(); |
---|
294 | |
---|
295 | dPrint(p, currRing, currRing, getOptionalInteger(h, 3)); |
---|
296 | |
---|
297 | return FALSE; |
---|
298 | } |
---|
299 | |
---|
300 | if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD) |
---|
301 | { |
---|
302 | const ideal id = (const ideal)h->Data(); h = h->Next(); |
---|
303 | |
---|
304 | dPrint(id, currRing, currRing, getOptionalInteger(h, 3)); |
---|
305 | |
---|
306 | return FALSE; |
---|
307 | } |
---|
308 | |
---|
309 | if( h->Typ() == RESOLUTION_CMD ) |
---|
310 | { |
---|
311 | const syStrategy syzstr = reinterpret_cast<const syStrategy>(h->Data()); |
---|
312 | |
---|
313 | h = h->Next(); |
---|
314 | |
---|
315 | int nTerms = getOptionalInteger(h, 1); |
---|
316 | |
---|
317 | |
---|
318 | Print("RESOLUTION_CMD(%p): ", reinterpret_cast<const void*>(syzstr)); PrintLn(); |
---|
319 | |
---|
320 | const ring save = currRing; |
---|
321 | const ring r = syzstr->syRing; |
---|
322 | const ring rr = (r != NULL) ? r: save; |
---|
323 | |
---|
324 | |
---|
325 | const int iLength = syzstr->length; |
---|
326 | |
---|
327 | Print("int 'length': %d", iLength); PrintLn(); |
---|
328 | Print("int 'regularity': %d", syzstr->regularity); PrintLn(); |
---|
329 | Print("short 'list_length': %hd", syzstr->list_length); PrintLn(); |
---|
330 | Print("short 'references': %hd", syzstr->references); PrintLn(); |
---|
331 | |
---|
332 | |
---|
333 | #define PRINT_pINTVECTOR(s, v) Print("intvec '%10s'(%p)", #v, reinterpret_cast<const void*>((s)->v)); \ |
---|
334 | if( (s)->v != NULL ){ PrintS(": "); view((s)->v); }; \ |
---|
335 | PrintLn(); |
---|
336 | |
---|
337 | PRINT_pINTVECTOR(syzstr, resolution); |
---|
338 | PRINT_pINTVECTOR(syzstr, betti); |
---|
339 | PRINT_pINTVECTOR(syzstr, Tl); |
---|
340 | PRINT_pINTVECTOR(syzstr, cw); |
---|
341 | #undef PRINT_pINTVECTOR |
---|
342 | |
---|
343 | if (r == NULL) |
---|
344 | Print("ring '%10s': NULL", "syRing"); |
---|
345 | else |
---|
346 | if (r == currRing) |
---|
347 | Print("ring '%10s': currRing", "syRing"); |
---|
348 | else |
---|
349 | if (r != NULL && r != save) |
---|
350 | { |
---|
351 | Print("ring '%10s': ", "syRing"); |
---|
352 | rWrite(r); |
---|
353 | #ifdef RDEBUG |
---|
354 | // rDebugPrint(r); |
---|
355 | #endif |
---|
356 | // rChangeCurrRing(r); |
---|
357 | } |
---|
358 | PrintLn(); |
---|
359 | |
---|
360 | const SRes rP = syzstr->resPairs; |
---|
361 | Print("SRes 'resPairs': %p", reinterpret_cast<const void*>(rP)); PrintLn(); |
---|
362 | |
---|
363 | if (rP != NULL) |
---|
364 | for (int iLevel = 0; (iLevel < iLength) && (rP[iLevel] != NULL) && ((*syzstr->Tl)[iLevel] >= 0); iLevel++) |
---|
365 | { |
---|
366 | int n = 0; |
---|
367 | const int iTl = (*syzstr->Tl)[iLevel]; |
---|
368 | for (int j = 0; (j < iTl) && ((rP[iLevel][j].lcm!=NULL) || (rP[iLevel][j].syz!=NULL)); j++) |
---|
369 | { |
---|
370 | if (rP[iLevel][j].isNotMinimal==NULL) |
---|
371 | n++; |
---|
372 | } |
---|
373 | Print("minimal-resPairs-Size[1+%d]: %d", iLevel, n); PrintLn(); |
---|
374 | } |
---|
375 | |
---|
376 | |
---|
377 | // const ring rrr = (iLevel > 0) ? rr : save; ? |
---|
378 | #define PRINT_RESOLUTION(s, v) Print("resolution '%12s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn(); \ |
---|
379 | if ((s)->v != NULL) \ |
---|
380 | for (int iLevel = 0; (iLevel < iLength) && ( ((s)->v)[iLevel] != NULL ); iLevel++) \ |
---|
381 | { \ |
---|
382 | /* const ring rrr = (iLevel > 0) ? save : save; */ \ |
---|
383 | Print("id '%10s'[%d]: (%p) ncols = %d / size: %d; nrows = %d, rank = %ld / rk: %ld", #v, iLevel, reinterpret_cast<const void*>(((s)->v)[iLevel]), ((s)->v)[iLevel]->ncols, idSize(((s)->v)[iLevel]), ((s)->v)[iLevel]->nrows, ((s)->v)[iLevel]->rank, -1L/*id_RankFreeModule(((s)->v)[iLevel], rrr)*/ ); \ |
---|
384 | PrintLn(); \ |
---|
385 | } \ |
---|
386 | PrintLn(); |
---|
387 | |
---|
388 | // resolvente: |
---|
389 | PRINT_RESOLUTION(syzstr, minres); |
---|
390 | PRINT_RESOLUTION(syzstr, fullres); |
---|
391 | |
---|
392 | assume (id_RankFreeModule (syzstr->res[1], rr) == syzstr->res[1]->rank); |
---|
393 | |
---|
394 | PRINT_RESOLUTION(syzstr, res); |
---|
395 | PRINT_RESOLUTION(syzstr, orderedRes); |
---|
396 | #undef PRINT_RESOLUTION |
---|
397 | |
---|
398 | #define PRINT_POINTER(s, v) Print("pointer '%17s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn(); |
---|
399 | // 2d arrays: |
---|
400 | PRINT_POINTER(syzstr, truecomponents); |
---|
401 | PRINT_POINTER(syzstr, ShiftedComponents); |
---|
402 | PRINT_POINTER(syzstr, backcomponents); |
---|
403 | PRINT_POINTER(syzstr, Howmuch); |
---|
404 | PRINT_POINTER(syzstr, Firstelem); |
---|
405 | PRINT_POINTER(syzstr, elemLength); |
---|
406 | PRINT_POINTER(syzstr, sev); |
---|
407 | |
---|
408 | // arrays of intvects: |
---|
409 | PRINT_POINTER(syzstr, weights); |
---|
410 | PRINT_POINTER(syzstr, hilb_coeffs); |
---|
411 | #undef PRINT_POINTER |
---|
412 | |
---|
413 | |
---|
414 | if (syzstr->fullres==NULL) |
---|
415 | { |
---|
416 | PrintS("resolution 'fullres': (NULL) => resolution not computed yet"); |
---|
417 | PrintLn(); |
---|
418 | } else |
---|
419 | { |
---|
420 | Print("resolution 'fullres': (%p) => resolution seems to be computed already", reinterpret_cast<const void*>(syzstr->fullres)); |
---|
421 | PrintLn(); |
---|
422 | dPrint(*syzstr->fullres, save, save, nTerms); |
---|
423 | } |
---|
424 | |
---|
425 | |
---|
426 | |
---|
427 | |
---|
428 | if (syzstr->minres==NULL) |
---|
429 | { |
---|
430 | PrintS("resolution 'minres': (NULL) => resolution not minimized yet"); |
---|
431 | PrintLn(); |
---|
432 | } else |
---|
433 | { |
---|
434 | Print("resolution 'minres': (%p) => resolution seems to be minimized already", reinterpret_cast<const void*>(syzstr->minres)); |
---|
435 | PrintLn(); |
---|
436 | dPrint(*syzstr->minres, save, save, nTerms); |
---|
437 | } |
---|
438 | |
---|
439 | |
---|
440 | |
---|
441 | |
---|
442 | /* |
---|
443 | int ** truecomponents; |
---|
444 | long** ShiftedComponents; |
---|
445 | int ** backcomponents; |
---|
446 | int ** Howmuch; |
---|
447 | int ** Firstelem; |
---|
448 | int ** elemLength; |
---|
449 | unsigned long ** sev; |
---|
450 | |
---|
451 | intvec ** weights; |
---|
452 | intvec ** hilb_coeffs; |
---|
453 | |
---|
454 | SRes resPairs; //polynomial data for internal use only |
---|
455 | |
---|
456 | resolvente fullres; |
---|
457 | resolvente minres; |
---|
458 | resolvente res; //polynomial data for internal use only |
---|
459 | resolvente orderedRes; //polynomial data for internal use only |
---|
460 | */ |
---|
461 | |
---|
462 | // if( currRing != save ) rChangeCurrRing(save); |
---|
463 | } |
---|
464 | |
---|
465 | |
---|
466 | return FALSE; |
---|
467 | } |
---|
468 | |
---|
469 | |
---|
470 | |
---|
471 | |
---|
472 | |
---|
473 | |
---|
474 | static BOOLEAN Tail(leftv res, leftv h) |
---|
475 | { |
---|
476 | NoReturn(res); |
---|
477 | |
---|
478 | if( h == NULL ) |
---|
479 | { |
---|
480 | WarnS("Tail needs an argument..."); |
---|
481 | return TRUE; |
---|
482 | } |
---|
483 | |
---|
484 | assume( h != NULL ); |
---|
485 | |
---|
486 | if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) |
---|
487 | { |
---|
488 | const poly p = (const poly)h->Data(); |
---|
489 | |
---|
490 | res->rtyp = h->Typ(); |
---|
491 | |
---|
492 | if( p == NULL) |
---|
493 | res->data = NULL; |
---|
494 | else |
---|
495 | res->data = p_Copy( pNext(p), currRing ); |
---|
496 | |
---|
497 | h = h->Next(); assume (h == NULL); |
---|
498 | |
---|
499 | return FALSE; |
---|
500 | } |
---|
501 | |
---|
502 | if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD) |
---|
503 | { |
---|
504 | const ideal id = (const ideal)h->Data(); |
---|
505 | |
---|
506 | res->rtyp = h->Typ(); |
---|
507 | |
---|
508 | if( id == NULL) |
---|
509 | res->data = NULL; |
---|
510 | else |
---|
511 | { |
---|
512 | const ideal newid = idInit(IDELEMS(id),id->rank); |
---|
513 | for (int i=IDELEMS(id) - 1; i >= 0; i--) |
---|
514 | if( id->m[i] != NULL ) |
---|
515 | newid->m[i] = p_Copy(pNext(id->m[i]), currRing); |
---|
516 | else |
---|
517 | newid->m[i] = NULL; |
---|
518 | |
---|
519 | res->data = newid; |
---|
520 | } |
---|
521 | |
---|
522 | h = h->Next(); assume (h == NULL); |
---|
523 | |
---|
524 | return FALSE; |
---|
525 | } |
---|
526 | |
---|
527 | WarnS("Tail needs a single poly/vector/ideal/module argument..."); |
---|
528 | return TRUE; |
---|
529 | } |
---|
530 | |
---|
531 | |
---|
532 | #ifdef _GNU_SOURCE |
---|
533 | static int cmp_c_ds(const void *p1, const void *p2, void *R) |
---|
534 | { |
---|
535 | #else |
---|
536 | static int cmp_c_ds(const void *p1, const void *p2) |
---|
537 | { |
---|
538 | void *R = currRing; |
---|
539 | #endif |
---|
540 | |
---|
541 | const int YES = 1; |
---|
542 | const int NO = -1; |
---|
543 | |
---|
544 | const ring r = (const ring) R; // TODO/NOTE: the structure is known: C, lp!!! |
---|
545 | |
---|
546 | assume( r == currRing ); |
---|
547 | |
---|
548 | const poly a = *(const poly*)p1; |
---|
549 | const poly b = *(const poly*)p2; |
---|
550 | |
---|
551 | assume( a != NULL ); |
---|
552 | assume( b != NULL ); |
---|
553 | |
---|
554 | assume( p_LmTest(a, r) ); |
---|
555 | assume( p_LmTest(b, r) ); |
---|
556 | |
---|
557 | |
---|
558 | const signed long iCompDiff = p_GetComp(a, r) - p_GetComp(b, r); |
---|
559 | |
---|
560 | // TODO: test this!!!!!!!!!!!!!!!! |
---|
561 | |
---|
562 | //return -( compare (c, qsorts) ) |
---|
563 | |
---|
564 | const int __DEBUG__ = 0; |
---|
565 | |
---|
566 | #ifndef NDEBUG |
---|
567 | if( __DEBUG__ ) |
---|
568 | { |
---|
569 | PrintS("cmp_c_ds: a, b: \np1: "); dPrint(a, r, r, 2); |
---|
570 | PrintS("b: "); dPrint(b, r, r, 2); |
---|
571 | PrintLn(); |
---|
572 | } |
---|
573 | #endif |
---|
574 | |
---|
575 | |
---|
576 | if( iCompDiff > 0 ) |
---|
577 | return YES; |
---|
578 | |
---|
579 | if( iCompDiff < 0 ) |
---|
580 | return NO; |
---|
581 | |
---|
582 | assume( iCompDiff == 0 ); |
---|
583 | |
---|
584 | const signed long iDegDiff = p_Totaldegree(a, r) - p_Totaldegree(b, r); |
---|
585 | |
---|
586 | if( iDegDiff > 0 ) |
---|
587 | return YES; |
---|
588 | |
---|
589 | if( iDegDiff < 0 ) |
---|
590 | return NO; |
---|
591 | |
---|
592 | assume( iDegDiff == 0 ); |
---|
593 | |
---|
594 | #ifndef NDEBUG |
---|
595 | if( __DEBUG__ ) |
---|
596 | { |
---|
597 | PrintS("cmp_c_ds: a & b have the same comp & deg! "); PrintLn(); |
---|
598 | } |
---|
599 | #endif |
---|
600 | |
---|
601 | for (int v = rVar(r); v > 0; v--) |
---|
602 | { |
---|
603 | assume( v > 0 ); |
---|
604 | assume( v <= rVar(r) ); |
---|
605 | |
---|
606 | const signed int d = p_GetExp(a, v, r) - p_GetExp(b, v, r); |
---|
607 | |
---|
608 | if( d > 0 ) |
---|
609 | return YES; |
---|
610 | |
---|
611 | if( d < 0 ) |
---|
612 | return NO; |
---|
613 | |
---|
614 | assume( d == 0 ); |
---|
615 | } |
---|
616 | |
---|
617 | return 0; |
---|
618 | } |
---|
619 | |
---|
620 | |
---|
621 | static BOOLEAN ComputeLeadingSyzygyTerms(leftv res, leftv h) |
---|
622 | { |
---|
623 | const ring r = currRing; |
---|
624 | NoReturn(res); |
---|
625 | |
---|
626 | if( h == NULL ) |
---|
627 | { |
---|
628 | WarnS("ComputeLeadingSyzygyTerms needs an argument..."); |
---|
629 | return TRUE; |
---|
630 | } |
---|
631 | |
---|
632 | assume( h != NULL ); |
---|
633 | |
---|
634 | #ifndef NDEBUG |
---|
635 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE))); |
---|
636 | #else |
---|
637 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE))); |
---|
638 | #endif |
---|
639 | |
---|
640 | if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD) |
---|
641 | { |
---|
642 | const ideal id = (const ideal)h->Data(); |
---|
643 | |
---|
644 | assume(id != NULL); |
---|
645 | |
---|
646 | if( __DEBUG__ ) |
---|
647 | { |
---|
648 | PrintS("ComputeLeadingSyzygyTerms::Input: \n"); |
---|
649 | |
---|
650 | const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0))); |
---|
651 | const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0))); |
---|
652 | const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0))); |
---|
653 | |
---|
654 | |
---|
655 | Print("\nSYZCHECK: \t%d", __SYZCHECK__); |
---|
656 | Print(", DEBUG: \t%d", __DEBUG__); |
---|
657 | Print(", LEAD2SYZ: \t%d", __LEAD2SYZ__); |
---|
658 | Print(", TAILREDSYZ: \t%d\n", __TAILREDSYZ__); |
---|
659 | |
---|
660 | dPrint(id, r, r, 1); |
---|
661 | |
---|
662 | assume( !__LEAD2SYZ__ ); |
---|
663 | } |
---|
664 | |
---|
665 | h = h->Next(); assume (h == NULL); |
---|
666 | |
---|
667 | // 1. set of components S? |
---|
668 | // 2. for each component c from S: set of indices of leading terms |
---|
669 | // with this component? |
---|
670 | // 3. short exp. vectors for each leading term? |
---|
671 | |
---|
672 | const int size = IDELEMS(id); |
---|
673 | |
---|
674 | if( size < 2 ) |
---|
675 | { |
---|
676 | const ideal newid = idInit(1, 0); // zero ideal... |
---|
677 | |
---|
678 | newid->m[0] = NULL; |
---|
679 | |
---|
680 | res->data = newid; |
---|
681 | res->rtyp = MODUL_CMD; |
---|
682 | |
---|
683 | return FALSE; |
---|
684 | } |
---|
685 | |
---|
686 | |
---|
687 | // TODO/NOTE: input is supposed to be (reverse-) sorted wrt "(c,ds)"!?? |
---|
688 | |
---|
689 | // components should come in groups: count elements in each group |
---|
690 | // && estimate the real size!!! |
---|
691 | |
---|
692 | |
---|
693 | // use just a vector instead??? |
---|
694 | const ideal newid = idInit( (size * (size-1))/2, size); // maximal size: ideal case! |
---|
695 | |
---|
696 | int k = 0; |
---|
697 | |
---|
698 | for (int j = 0; j < size; j++) |
---|
699 | { |
---|
700 | const poly p = id->m[j]; |
---|
701 | assume( p != NULL ); |
---|
702 | const int c = p_GetComp(p, r); |
---|
703 | |
---|
704 | for (int i = j - 1; i >= 0; i--) |
---|
705 | { |
---|
706 | const poly pp = id->m[i]; |
---|
707 | assume( pp != NULL ); |
---|
708 | const int cc = p_GetComp(pp, r); |
---|
709 | |
---|
710 | if( c != cc ) |
---|
711 | continue; |
---|
712 | |
---|
713 | const poly m = p_Init(r); // p_New??? |
---|
714 | |
---|
715 | // m = LCM(p, pp) / p! // TODO: optimize: knowing the ring structure: (C/lp)! |
---|
716 | for (int v = rVar(r); v > 0; v--) |
---|
717 | { |
---|
718 | assume( v > 0 ); |
---|
719 | assume( v <= rVar(r) ); |
---|
720 | |
---|
721 | const short e1 = p_GetExp(p , v, r); |
---|
722 | const short e2 = p_GetExp(pp, v, r); |
---|
723 | |
---|
724 | if( e1 >= e2 ) |
---|
725 | p_SetExp(m, v, 0, r); |
---|
726 | else |
---|
727 | p_SetExp(m, v, e2 - e1, r); |
---|
728 | |
---|
729 | } |
---|
730 | |
---|
731 | assume( (j > i) && (i >= 0) ); |
---|
732 | |
---|
733 | p_SetComp(m, j + 1, r); |
---|
734 | pNext(m) = NULL; |
---|
735 | p_SetCoeff0(m, n_Init(1, r->cf), r); // for later... |
---|
736 | |
---|
737 | p_Setm(m, r); // should not do anything!!! |
---|
738 | |
---|
739 | newid->m[k++] = m; |
---|
740 | } |
---|
741 | } |
---|
742 | |
---|
743 | if( __DEBUG__ && FALSE ) |
---|
744 | { |
---|
745 | PrintS("ComputeLeadingSyzygyTerms::Temp0: \n"); |
---|
746 | dPrint(newid, r, r, 1); |
---|
747 | } |
---|
748 | |
---|
749 | // the rest of newid is assumed to be zeroes... |
---|
750 | |
---|
751 | // simplify(newid, 2 + 32)?? |
---|
752 | // sort(newid, "C,ds")[1]??? |
---|
753 | id_DelDiv(newid, r); // #define SIMPL_LMDIV 32 |
---|
754 | |
---|
755 | if( __DEBUG__ && FALSE ) |
---|
756 | { |
---|
757 | PrintS("ComputeLeadingSyzygyTerms::Temp1: \n"); |
---|
758 | dPrint(newid, r, r, 1); |
---|
759 | } |
---|
760 | |
---|
761 | idSkipZeroes(newid); // #define SIMPL_NULL 2 |
---|
762 | |
---|
763 | if( __DEBUG__ ) |
---|
764 | { |
---|
765 | PrintS("ComputeLeadingSyzygyTerms::Output: \n"); |
---|
766 | dPrint(newid, r, r, 1); |
---|
767 | } |
---|
768 | |
---|
769 | const int sizeNew = IDELEMS(newid); |
---|
770 | |
---|
771 | if( sizeNew >= 2 ) |
---|
772 | qsort_my(newid->m, sizeNew, sizeof(poly), r, cmp_c_ds); |
---|
773 | |
---|
774 | if (IDELEMS(newid) == 0 || (IDELEMS(newid) == 1 && newid->m[0] == NULL) ) |
---|
775 | newid->rank = 1; |
---|
776 | |
---|
777 | // TODO: add sorting wrt <c,ds> & reversing... |
---|
778 | |
---|
779 | res->data = newid; |
---|
780 | res->rtyp = MODUL_CMD; |
---|
781 | |
---|
782 | return FALSE; |
---|
783 | } |
---|
784 | |
---|
785 | WarnS("ComputeLeadingSyzygyTerms needs a single ideal/module argument..."); |
---|
786 | return TRUE; |
---|
787 | } |
---|
788 | |
---|
789 | /// sorting wrt <c,ds> & reversing... |
---|
790 | /// change the input inplace!!! |
---|
791 | // TODO: use a ring with >_{c, ds}!??? |
---|
792 | static BOOLEAN Sort_c_ds(leftv res, leftv h) |
---|
793 | { |
---|
794 | NoReturn(res); |
---|
795 | |
---|
796 | const ring r = currRing; |
---|
797 | NoReturn(res); |
---|
798 | |
---|
799 | if( h == NULL ) |
---|
800 | { |
---|
801 | WarnS("Sort_c_ds needs an argument..."); |
---|
802 | return TRUE; |
---|
803 | } |
---|
804 | |
---|
805 | assume( h != NULL ); |
---|
806 | |
---|
807 | #ifndef NDEBUG |
---|
808 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE))); |
---|
809 | #else |
---|
810 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE))); |
---|
811 | #endif |
---|
812 | |
---|
813 | if( (h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD) |
---|
814 | && (h->rtyp == IDHDL) // must be a variable! |
---|
815 | && (h->e == NULL) // not a list element |
---|
816 | ) |
---|
817 | { |
---|
818 | const ideal id = (const ideal)h->Data(); |
---|
819 | |
---|
820 | assume(id != NULL); |
---|
821 | |
---|
822 | if( __DEBUG__ ) |
---|
823 | { |
---|
824 | PrintS("Sort_c_ds::Input: \n"); |
---|
825 | |
---|
826 | const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0))); |
---|
827 | const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0))); |
---|
828 | const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0))); |
---|
829 | |
---|
830 | Print("\nSYZCHECK: \t%d", __SYZCHECK__); |
---|
831 | Print(", DEBUG: \t%d", __DEBUG__); |
---|
832 | Print(", LEAD2SYZ: \t%d", __LEAD2SYZ__); |
---|
833 | Print(", TAILREDSYZ: \t%d\n", __TAILREDSYZ__); |
---|
834 | |
---|
835 | dPrint(id, r, r, 1); |
---|
836 | } |
---|
837 | |
---|
838 | assume (h->Next() == NULL); |
---|
839 | |
---|
840 | id_Test(id, r); |
---|
841 | |
---|
842 | const int size = IDELEMS(id); |
---|
843 | |
---|
844 | const ideal newid = id; // id_Copy(id, r); // copy??? |
---|
845 | |
---|
846 | if( size >= 2 ) |
---|
847 | qsort_my(newid->m, size, sizeof(poly), r, cmp_c_ds); |
---|
848 | |
---|
849 | // res->data = newid; |
---|
850 | // res->rtyp = h->Typ(); |
---|
851 | |
---|
852 | if( __DEBUG__ ) |
---|
853 | { |
---|
854 | PrintS("Sort_c_ds::Output: \n"); |
---|
855 | dPrint(newid, r, r, 1); |
---|
856 | } |
---|
857 | |
---|
858 | return FALSE; |
---|
859 | } |
---|
860 | |
---|
861 | WarnS("ComputeLeadingSyzygyTerms needs a single ideal/module argument (must be a variable!)..."); |
---|
862 | return TRUE; |
---|
863 | } |
---|
864 | |
---|
865 | |
---|
866 | |
---|
867 | static BOOLEAN Compute2LeadingSyzygyTerms(leftv res, leftv h) |
---|
868 | { |
---|
869 | const ring r = currRing; |
---|
870 | NoReturn(res); |
---|
871 | |
---|
872 | if( h == NULL ) |
---|
873 | { |
---|
874 | WarnS("Compute2LeadingSyzygyTerms needs an argument..."); |
---|
875 | return TRUE; |
---|
876 | } |
---|
877 | |
---|
878 | assume( h != NULL ); |
---|
879 | |
---|
880 | #ifndef NDEBUG |
---|
881 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE))); |
---|
882 | #else |
---|
883 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE))); |
---|
884 | #endif |
---|
885 | |
---|
886 | const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0))); |
---|
887 | const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0))); |
---|
888 | const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0))); |
---|
889 | |
---|
890 | |
---|
891 | assume( __LEAD2SYZ__ ); |
---|
892 | |
---|
893 | if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD) |
---|
894 | { |
---|
895 | const ideal id = (const ideal)h->Data(); |
---|
896 | |
---|
897 | assume(id != NULL); |
---|
898 | |
---|
899 | if( __DEBUG__ ) |
---|
900 | { |
---|
901 | PrintS("Compute2LeadingSyzygyTerms::Input: \n"); |
---|
902 | |
---|
903 | Print("\nSYZCHECK: \t%d", __SYZCHECK__); |
---|
904 | Print(", DEBUG: \t%d", __DEBUG__); |
---|
905 | Print(", LEAD2SYZ: \t%d", __LEAD2SYZ__); |
---|
906 | Print(", TAILREDSYZ: \t%d\n", __TAILREDSYZ__); |
---|
907 | |
---|
908 | dPrint(id, r, r, 1); |
---|
909 | } |
---|
910 | |
---|
911 | h = h->Next(); assume (h == NULL); |
---|
912 | |
---|
913 | // 1. set of components S? |
---|
914 | // 2. for each component c from S: set of indices of leading terms |
---|
915 | // with this component? |
---|
916 | // 3. short exp. vectors for each leading term? |
---|
917 | |
---|
918 | const int size = IDELEMS(id); |
---|
919 | |
---|
920 | if( size < 2 ) |
---|
921 | { |
---|
922 | const ideal newid = idInit(1, 1); // zero module... |
---|
923 | |
---|
924 | newid->m[0] = NULL; |
---|
925 | |
---|
926 | res->data = newid; |
---|
927 | res->rtyp = MODUL_CMD; |
---|
928 | |
---|
929 | return FALSE; |
---|
930 | } |
---|
931 | |
---|
932 | |
---|
933 | // TODO/NOTE: input is supposed to be sorted wrt "C,ds"!?? |
---|
934 | |
---|
935 | // components should come in groups: count elements in each group |
---|
936 | // && estimate the real size!!! |
---|
937 | |
---|
938 | |
---|
939 | // use just a vector instead??? |
---|
940 | ideal newid = idInit( (size * (size-1))/2, size); // maximal size: ideal case! |
---|
941 | |
---|
942 | int k = 0; |
---|
943 | |
---|
944 | for (int j = 0; j < size; j++) |
---|
945 | { |
---|
946 | const poly p = id->m[j]; |
---|
947 | assume( p != NULL ); |
---|
948 | const int c = p_GetComp(p, r); |
---|
949 | |
---|
950 | for (int i = j - 1; i >= 0; i--) |
---|
951 | { |
---|
952 | const poly pp = id->m[i]; |
---|
953 | assume( pp != NULL ); |
---|
954 | const int cc = p_GetComp(pp, r); |
---|
955 | |
---|
956 | if( c != cc ) |
---|
957 | continue; |
---|
958 | |
---|
959 | // allocate memory & zero it out! |
---|
960 | const poly m = p_Init(r); const poly mm = p_Init(r); |
---|
961 | |
---|
962 | |
---|
963 | // m = LCM(p, pp) / p! mm = LCM(p, pp) / pp! |
---|
964 | // TODO: optimize: knowing the ring structure: (C/lp)! |
---|
965 | |
---|
966 | for (int v = rVar(r); v > 0; v--) |
---|
967 | { |
---|
968 | assume( v > 0 ); |
---|
969 | assume( v <= rVar(r) ); |
---|
970 | |
---|
971 | const short e1 = p_GetExp(p , v, r); |
---|
972 | const short e2 = p_GetExp(pp, v, r); |
---|
973 | |
---|
974 | if( e1 >= e2 ) |
---|
975 | p_SetExp(mm, v, e1 - e2, r); // p_SetExp(m, v, 0, r); |
---|
976 | else |
---|
977 | p_SetExp(m, v, e2 - e1, r); // p_SetExp(mm, v, 0, r); |
---|
978 | |
---|
979 | } |
---|
980 | |
---|
981 | assume( (j > i) && (i >= 0) ); |
---|
982 | |
---|
983 | p_SetComp(m, j + 1, r); |
---|
984 | p_SetComp(mm, i + 1, r); |
---|
985 | |
---|
986 | const number& lc1 = p_GetCoeff(p , r); |
---|
987 | const number& lc2 = p_GetCoeff(pp, r); |
---|
988 | |
---|
989 | number g = n_Lcm( lc1, lc2, r ); |
---|
990 | |
---|
991 | p_SetCoeff0(m , n_Div(g, lc1, r), r); |
---|
992 | p_SetCoeff0(mm, n_Neg(n_Div(g, lc2, r), r), r); |
---|
993 | |
---|
994 | n_Delete(&g, r); |
---|
995 | |
---|
996 | p_Setm(m, r); // should not do anything!!! |
---|
997 | p_Setm(mm, r); // should not do anything!!! |
---|
998 | |
---|
999 | pNext(m) = mm; // pNext(mm) = NULL; |
---|
1000 | |
---|
1001 | newid->m[k++] = m; |
---|
1002 | } |
---|
1003 | } |
---|
1004 | |
---|
1005 | if( __DEBUG__ && FALSE ) |
---|
1006 | { |
---|
1007 | PrintS("Compute2LeadingSyzygyTerms::Temp0: \n"); |
---|
1008 | dPrint(newid, r, r, 1); |
---|
1009 | } |
---|
1010 | |
---|
1011 | if( !__TAILREDSYZ__ ) |
---|
1012 | { |
---|
1013 | // simplify(newid, 2 + 32)?? |
---|
1014 | // sort(newid, "C,ds")[1]??? |
---|
1015 | id_DelDiv(newid, r); // #define SIMPL_LMDIV 32 |
---|
1016 | |
---|
1017 | if( __DEBUG__ && FALSE ) |
---|
1018 | { |
---|
1019 | PrintS("Compute2LeadingSyzygyTerms::Temp1 (deldiv): \n"); |
---|
1020 | dPrint(newid, r, r, 1); |
---|
1021 | } |
---|
1022 | } |
---|
1023 | else |
---|
1024 | { |
---|
1025 | // option(redSB); option(redTail); |
---|
1026 | // TEST_OPT_REDSB |
---|
1027 | // TEST_OPT_REDTAIL |
---|
1028 | assume( r == currRing ); |
---|
1029 | BITSET _save_test = test; |
---|
1030 | test |= (Sy_bit(OPT_REDTAIL) | Sy_bit(OPT_REDSB)); |
---|
1031 | |
---|
1032 | intvec* w=new intvec(IDELEMS(newid)); |
---|
1033 | ideal tmp = kStd(newid, currQuotient, isHomog, &w); |
---|
1034 | delete w; |
---|
1035 | |
---|
1036 | test = _save_test; |
---|
1037 | |
---|
1038 | id_Delete(&newid, r); |
---|
1039 | newid = tmp; |
---|
1040 | |
---|
1041 | if( __DEBUG__ && FALSE ) |
---|
1042 | { |
---|
1043 | PrintS("Compute2LeadingSyzygyTerms::Temp1 (std): \n"); |
---|
1044 | dPrint(newid, r, r, 1); |
---|
1045 | } |
---|
1046 | |
---|
1047 | } |
---|
1048 | |
---|
1049 | idSkipZeroes(newid); |
---|
1050 | |
---|
1051 | const int sizeNew = IDELEMS(newid); |
---|
1052 | |
---|
1053 | if( sizeNew >= 2 ) |
---|
1054 | qsort_my(newid->m, sizeNew, sizeof(poly), r, cmp_c_ds); |
---|
1055 | |
---|
1056 | if (IDELEMS(newid) == 0 || (IDELEMS(newid) == 1 && newid->m[0] == NULL) ) |
---|
1057 | newid->rank = 1; |
---|
1058 | |
---|
1059 | // TODO: add sorting wrt <c,ds> & reversing... |
---|
1060 | |
---|
1061 | res->data = newid; |
---|
1062 | res->rtyp = MODUL_CMD; |
---|
1063 | |
---|
1064 | return FALSE; |
---|
1065 | } |
---|
1066 | |
---|
1067 | WarnS("Compute2LeadingSyzygyTerms needs a single ideal/module argument..."); |
---|
1068 | return TRUE; |
---|
1069 | } |
---|
1070 | |
---|
1071 | |
---|
1072 | /// return a new term: leading coeff * leading monomial of p |
---|
1073 | /// with 0 leading component! |
---|
1074 | static inline poly leadmonom(const poly p, const ring r) |
---|
1075 | { |
---|
1076 | poly m = NULL; |
---|
1077 | |
---|
1078 | if( p != NULL ) |
---|
1079 | { |
---|
1080 | assume( p != NULL ); |
---|
1081 | assume( p_LmTest(p, r) ); |
---|
1082 | |
---|
1083 | m = p_LmInit(p, r); |
---|
1084 | p_SetCoeff0(m, n_Copy(p_GetCoeff(p, r), r), r); |
---|
1085 | |
---|
1086 | p_SetComp(m, 0, r); |
---|
1087 | p_Setm(m, r); |
---|
1088 | |
---|
1089 | assume( p_GetComp(m, r) == 0 ); |
---|
1090 | assume( m != NULL ); |
---|
1091 | assume( pNext(m) == NULL ); |
---|
1092 | assume( p_LmTest(m, r) ); |
---|
1093 | } |
---|
1094 | |
---|
1095 | return m; |
---|
1096 | } |
---|
1097 | |
---|
1098 | |
---|
1099 | /// TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz? |
---|
1100 | /// proc SSFindReducer(def product, def syzterm, def L, def T, list #) |
---|
1101 | static BOOLEAN FindReducer(leftv res, leftv h) |
---|
1102 | { |
---|
1103 | const ring r = currRing; |
---|
1104 | |
---|
1105 | NoReturn(res); |
---|
1106 | |
---|
1107 | |
---|
1108 | #ifndef NDEBUG |
---|
1109 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE))); |
---|
1110 | #else |
---|
1111 | const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE))); |
---|
1112 | #endif |
---|
1113 | |
---|
1114 | const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0))); |
---|
1115 | const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0))); |
---|
1116 | const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0))); |
---|
1117 | |
---|
1118 | if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL)) |
---|
1119 | { |
---|
1120 | WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected"); |
---|
1121 | return TRUE; |
---|
1122 | } |
---|
1123 | |
---|
1124 | const poly product = (poly) h->Data(); h = h->Next(); |
---|
1125 | |
---|
1126 | assume (product != NULL); |
---|
1127 | |
---|
1128 | |
---|
1129 | if ((h==NULL) || (h->Typ()!=VECTOR_CMD)) |
---|
1130 | { |
---|
1131 | WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected"); |
---|
1132 | return TRUE; |
---|
1133 | } |
---|
1134 | |
---|
1135 | const poly syzterm = (poly) h->Data(); h = h->Next(); |
---|
1136 | |
---|
1137 | int c = 0; |
---|
1138 | |
---|
1139 | if (syzterm != NULL) |
---|
1140 | c = p_GetComp(syzterm, r) - 1; |
---|
1141 | |
---|
1142 | |
---|
1143 | if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL)) |
---|
1144 | { |
---|
1145 | WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected"); |
---|
1146 | return TRUE; |
---|
1147 | } |
---|
1148 | |
---|
1149 | const ideal L = (ideal) h->Data(); h = h->Next(); |
---|
1150 | |
---|
1151 | assume( IDELEMS(L) > 0 ); |
---|
1152 | assume( c >= 0 && c < IDELEMS(L) ); |
---|
1153 | |
---|
1154 | |
---|
1155 | /* |
---|
1156 | if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL)) |
---|
1157 | { |
---|
1158 | WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected"); |
---|
1159 | return TRUE; |
---|
1160 | } |
---|
1161 | |
---|
1162 | const ideal T = (ideal) h->Data(); h = h->Next(); |
---|
1163 | */ |
---|
1164 | |
---|
1165 | ideal LS = NULL; |
---|
1166 | |
---|
1167 | if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL)) |
---|
1168 | { |
---|
1169 | LS = (ideal)h->Data(); |
---|
1170 | h = h->Next(); |
---|
1171 | } |
---|
1172 | |
---|
1173 | if( __TAILREDSYZ__ ) |
---|
1174 | assume (LS != NULL); |
---|
1175 | |
---|
1176 | assume( h == NULL ); |
---|
1177 | |
---|
1178 | if( __DEBUG__ ) |
---|
1179 | { |
---|
1180 | PrintS("FindReducer(product, syzterm, L, T, #)::Input: \n"); |
---|
1181 | |
---|
1182 | PrintS("product: "); dPrint(product, r, r, 2); |
---|
1183 | PrintS("syzterm: "); dPrint(syzterm, r, r, 2); |
---|
1184 | PrintS("L: "); dPrint(L, r, r, 2); |
---|
1185 | // PrintS("T: "); dPrint(T, r, r, 4); |
---|
1186 | |
---|
1187 | if( LS == NULL ) |
---|
1188 | PrintS("LS: NULL\n"); |
---|
1189 | else |
---|
1190 | { |
---|
1191 | PrintS("LS: "); dPrint(LS, r, r, 2); |
---|
1192 | } |
---|
1193 | } |
---|
1194 | |
---|
1195 | |
---|
1196 | if (__SYZCHECK__ && syzterm != NULL) |
---|
1197 | { |
---|
1198 | const poly m = L->m[c]; |
---|
1199 | |
---|
1200 | assume( m != NULL ); assume( pNext(m) == NULL ); |
---|
1201 | |
---|
1202 | poly lm = p_Mult_mm(leadmonom(syzterm, r), m, r); |
---|
1203 | assume( p_EqualPolys(lm, product, r) ); |
---|
1204 | |
---|
1205 | // def @@c = leadcomp(syzterm); int @@r = int(@@c); |
---|
1206 | // def @@product = leadmonomial(syzterm) * L[@@r]; |
---|
1207 | |
---|
1208 | p_Delete(&lm, r); |
---|
1209 | } |
---|
1210 | |
---|
1211 | |
---|
1212 | res->rtyp = VECTOR_CMD; |
---|
1213 | |
---|
1214 | // looking for an appropriate diviser q = L[k]... |
---|
1215 | for( int k = IDELEMS(L)-1; k>= 0; k-- ) |
---|
1216 | { |
---|
1217 | const poly p = L->m[k]; |
---|
1218 | |
---|
1219 | // ... which divides the product, looking for the _1st_ appropriate one! |
---|
1220 | if( !p_LmDivisibleBy(p, product, r) ) |
---|
1221 | continue; |
---|
1222 | |
---|
1223 | |
---|
1224 | const poly q = p_New(r); |
---|
1225 | pNext(q) = NULL; |
---|
1226 | p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k])) |
---|
1227 | p_SetComp(q, k + 1, r); |
---|
1228 | p_Setm(q, r); |
---|
1229 | |
---|
1230 | // cannot allow something like: a*gen(i) - a*gen(i) |
---|
1231 | if (syzterm != NULL && (k == c)) |
---|
1232 | if (p_ExpVectorEqual(syzterm, q, r)) |
---|
1233 | { |
---|
1234 | if( __DEBUG__ ) |
---|
1235 | { |
---|
1236 | Print("FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: "); |
---|
1237 | dPrint(syzterm, r, r, 1); |
---|
1238 | } |
---|
1239 | |
---|
1240 | p_LmFree(q, r); |
---|
1241 | continue; |
---|
1242 | } |
---|
1243 | |
---|
1244 | // while the complement (the fraction) is not reducible by leading syzygies |
---|
1245 | if( LS != NULL ) |
---|
1246 | { |
---|
1247 | BOOLEAN ok = TRUE; |
---|
1248 | |
---|
1249 | for(int kk = IDELEMS(LS)-1; kk>= 0; kk-- ) |
---|
1250 | { |
---|
1251 | const poly pp = LS->m[kk]; |
---|
1252 | |
---|
1253 | if( p_LmDivisibleBy(pp, q, r) ) |
---|
1254 | { |
---|
1255 | if( __DEBUG__ ) |
---|
1256 | { |
---|
1257 | Print("FindReducer::Test LS: q is divisible by LS[%d] !:((, diviser is: ", kk+1); |
---|
1258 | dPrint(pp, r, r, 1); |
---|
1259 | } |
---|
1260 | |
---|
1261 | ok = FALSE; // q in <LS> :(( |
---|
1262 | break; |
---|
1263 | } |
---|
1264 | } |
---|
1265 | |
---|
1266 | if(!ok) |
---|
1267 | { |
---|
1268 | p_LmFree(q, r); |
---|
1269 | continue; |
---|
1270 | } |
---|
1271 | } |
---|
1272 | |
---|
1273 | p_SetCoeff0(q, n_Neg( n_Div( p_GetCoeff(product, r), p_GetCoeff(p, r), r), r), r); |
---|
1274 | |
---|
1275 | if( __DEBUG__ ) |
---|
1276 | { |
---|
1277 | PrintS("FindReducer::Output: \n"); |
---|
1278 | dPrint(q, r, r, 1); |
---|
1279 | } |
---|
1280 | |
---|
1281 | res->data = q; |
---|
1282 | return FALSE; |
---|
1283 | } |
---|
1284 | |
---|
1285 | res->data = NULL; |
---|
1286 | return FALSE; |
---|
1287 | |
---|
1288 | } |
---|
1289 | |
---|
1290 | |
---|
1291 | |
---|
1292 | /// Get leading term without a module component |
---|
1293 | static BOOLEAN leadmonom(leftv res, leftv h) |
---|
1294 | { |
---|
1295 | NoReturn(res); |
---|
1296 | |
---|
1297 | if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL)) |
---|
1298 | { |
---|
1299 | const ring r = currRing; |
---|
1300 | const poly p = (poly)(h->Data()); |
---|
1301 | |
---|
1302 | const poly m = leadmonom(p, r); |
---|
1303 | |
---|
1304 | res->rtyp = POLY_CMD; |
---|
1305 | res->data = reinterpret_cast<void *>(m); |
---|
1306 | |
---|
1307 | return FALSE; |
---|
1308 | } |
---|
1309 | |
---|
1310 | WerrorS("`leadmonom(<poly/vector>)` expected"); |
---|
1311 | return TRUE; |
---|
1312 | } |
---|
1313 | |
---|
1314 | /// Get leading component |
---|
1315 | static BOOLEAN leadcomp(leftv res, leftv h) |
---|
1316 | { |
---|
1317 | NoReturn(res); |
---|
1318 | |
---|
1319 | if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD)) |
---|
1320 | { |
---|
1321 | const ring r = currRing; |
---|
1322 | |
---|
1323 | const poly p = (poly)(h->Data()); |
---|
1324 | |
---|
1325 | if (p != NULL ) |
---|
1326 | { |
---|
1327 | assume( p != NULL ); |
---|
1328 | assume( p_LmTest(p, r) ); |
---|
1329 | |
---|
1330 | const unsigned long iComp = p_GetComp(p, r); |
---|
1331 | |
---|
1332 | // assume( iComp > 0 ); // p is a vector |
---|
1333 | |
---|
1334 | res->data = reinterpret_cast<void *>(jjLONG2N(iComp)); |
---|
1335 | } else |
---|
1336 | res->data = reinterpret_cast<void *>(jjLONG2N(0)); |
---|
1337 | |
---|
1338 | |
---|
1339 | res->rtyp = BIGINT_CMD; |
---|
1340 | return FALSE; |
---|
1341 | } |
---|
1342 | |
---|
1343 | WerrorS("`leadcomp(<poly/vector>)` expected"); |
---|
1344 | return TRUE; |
---|
1345 | } |
---|
1346 | |
---|
1347 | |
---|
1348 | |
---|
1349 | |
---|
1350 | /// Get raw leading exponent vector |
---|
1351 | static BOOLEAN leadrawexp(leftv res, leftv h) |
---|
1352 | { |
---|
1353 | NoReturn(res); |
---|
1354 | |
---|
1355 | if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL)) |
---|
1356 | { |
---|
1357 | const ring r = currRing; |
---|
1358 | const poly p = (poly)(h->Data()); |
---|
1359 | |
---|
1360 | assume( p != NULL ); |
---|
1361 | assume( p_LmTest(p, r) ); |
---|
1362 | |
---|
1363 | const int iExpSize = r->ExpL_Size; |
---|
1364 | |
---|
1365 | // intvec *iv = new intvec(iExpSize); |
---|
1366 | |
---|
1367 | lists l=(lists)omAllocBin(slists_bin); |
---|
1368 | l->Init(iExpSize); |
---|
1369 | |
---|
1370 | for(int i = iExpSize-1; i >= 0; i--) |
---|
1371 | { |
---|
1372 | l->m[i].rtyp = BIGINT_CMD; |
---|
1373 | l->m[i].data = reinterpret_cast<void *>(jjLONG2N(p->exp[i])); // longs... |
---|
1374 | } |
---|
1375 | |
---|
1376 | res->rtyp = LIST_CMD; // list of bigints |
---|
1377 | res->data = reinterpret_cast<void *>(l); |
---|
1378 | return FALSE; |
---|
1379 | } |
---|
1380 | |
---|
1381 | WerrorS("`leadrawexp(<poly/vector>)` expected"); |
---|
1382 | return TRUE; |
---|
1383 | } |
---|
1384 | |
---|
1385 | |
---|
1386 | /// Endowe the current ring with additional (leading) Syz-component ordering |
---|
1387 | static BOOLEAN MakeSyzCompOrdering(leftv res, leftv /*h*/) |
---|
1388 | { |
---|
1389 | |
---|
1390 | NoReturn(res); |
---|
1391 | |
---|
1392 | // res->data = rCurrRingAssure_SyzComp(); // changes current ring! :( |
---|
1393 | res->data = reinterpret_cast<void *>(rAssure_SyzComp(currRing, TRUE)); |
---|
1394 | res->rtyp = RING_CMD; // return new ring! |
---|
1395 | // QRING_CMD? |
---|
1396 | |
---|
1397 | return FALSE; |
---|
1398 | } |
---|
1399 | |
---|
1400 | |
---|
1401 | /// Same for Induced Schreyer ordering (ordering on components is defined by sign!) |
---|
1402 | static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h) |
---|
1403 | { |
---|
1404 | |
---|
1405 | NoReturn(res); |
---|
1406 | |
---|
1407 | int sign = 1; |
---|
1408 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1409 | { |
---|
1410 | const int s = (int)((long)(h->Data())); |
---|
1411 | |
---|
1412 | if( s != -1 && s != 1 ) |
---|
1413 | { |
---|
1414 | WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!"); |
---|
1415 | return TRUE; |
---|
1416 | } |
---|
1417 | |
---|
1418 | sign = s; |
---|
1419 | } |
---|
1420 | |
---|
1421 | assume( sign == 1 || sign == -1 ); |
---|
1422 | res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign)); |
---|
1423 | res->rtyp = RING_CMD; // return new ring! |
---|
1424 | // QRING_CMD? |
---|
1425 | return FALSE; |
---|
1426 | } |
---|
1427 | |
---|
1428 | |
---|
1429 | /// Returns old SyzCompLimit, can set new limit |
---|
1430 | static BOOLEAN SetSyzComp(leftv res, leftv h) |
---|
1431 | { |
---|
1432 | NoReturn(res); |
---|
1433 | |
---|
1434 | const ring r = currRing; |
---|
1435 | |
---|
1436 | if( !rIsSyzIndexRing(r) ) |
---|
1437 | { |
---|
1438 | WerrorS("`SetSyzComp(<int>)` called on incompatible ring (not created by 'MakeSyzCompOrdering'!)"); |
---|
1439 | return TRUE; |
---|
1440 | } |
---|
1441 | |
---|
1442 | res->rtyp = INT_CMD; |
---|
1443 | res->data = reinterpret_cast<void *>(rGetCurrSyzLimit(r)); // return old syz limit |
---|
1444 | |
---|
1445 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1446 | { |
---|
1447 | const int iSyzComp = (int)reinterpret_cast<long>(h->Data()); |
---|
1448 | assume( iSyzComp > 0 ); |
---|
1449 | rSetSyzComp(iSyzComp, currRing); |
---|
1450 | } |
---|
1451 | |
---|
1452 | return FALSE; |
---|
1453 | } |
---|
1454 | |
---|
1455 | /// ? |
---|
1456 | static BOOLEAN GetInducedData(leftv res, leftv h) |
---|
1457 | { |
---|
1458 | NoReturn(res); |
---|
1459 | |
---|
1460 | const ring r = currRing; |
---|
1461 | |
---|
1462 | int p = 0; // which IS-block? p^th! |
---|
1463 | |
---|
1464 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1465 | { |
---|
1466 | p = (int)((long)(h->Data())); h=h->next; |
---|
1467 | assume(p >= 0); |
---|
1468 | } |
---|
1469 | |
---|
1470 | const int pos = rGetISPos(p, r); |
---|
1471 | |
---|
1472 | if( /*(*/ -1 == pos /*)*/ ) |
---|
1473 | { |
---|
1474 | WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)"); |
---|
1475 | return TRUE; |
---|
1476 | } |
---|
1477 | |
---|
1478 | |
---|
1479 | const int iLimit = r->typ[pos].data.is.limit; |
---|
1480 | const ideal F = r->typ[pos].data.is.F; |
---|
1481 | ideal FF = id_Copy(F, r); |
---|
1482 | |
---|
1483 | lists l=(lists)omAllocBin(slists_bin); |
---|
1484 | l->Init(2); |
---|
1485 | |
---|
1486 | l->m[0].rtyp = INT_CMD; |
---|
1487 | l->m[0].data = reinterpret_cast<void *>(iLimit); |
---|
1488 | |
---|
1489 | |
---|
1490 | // l->m[1].rtyp = MODUL_CMD; |
---|
1491 | |
---|
1492 | if( idIsModule(FF, r) ) |
---|
1493 | { |
---|
1494 | l->m[1].rtyp = MODUL_CMD; |
---|
1495 | |
---|
1496 | // Print("before: %d\n", FF->nrows); |
---|
1497 | // FF->nrows = id_RankFreeModule(FF, r); // ??? |
---|
1498 | // Print("after: %d\n", FF->nrows); |
---|
1499 | } |
---|
1500 | else |
---|
1501 | l->m[1].rtyp = IDEAL_CMD; |
---|
1502 | |
---|
1503 | l->m[1].data = reinterpret_cast<void *>(FF); |
---|
1504 | |
---|
1505 | res->rtyp = LIST_CMD; // list of int/module |
---|
1506 | res->data = reinterpret_cast<void *>(l); |
---|
1507 | |
---|
1508 | return FALSE; |
---|
1509 | |
---|
1510 | } |
---|
1511 | |
---|
1512 | |
---|
1513 | /* // the following turned out to be unnecessary... |
---|
1514 | /// Finds p^th AM ordering, and returns its position in r->typ[] AND |
---|
1515 | /// corresponding &r->wvhdl[] |
---|
1516 | /// returns FALSE if something went wrong! |
---|
1517 | /// p - starts with 0! |
---|
1518 | BOOLEAN rGetAMPos(const ring r, const int p, int &typ_pos, int &wvhdl_pos, const BOOLEAN bSearchWvhdl = FALSE) |
---|
1519 | { |
---|
1520 | #if MYTEST |
---|
1521 | Print("rGetAMPos(p: %d...)\nF:", p); |
---|
1522 | PrintLn(); |
---|
1523 | #endif |
---|
1524 | typ_pos = -1; |
---|
1525 | wvhdl_pos = -1; |
---|
1526 | |
---|
1527 | if (r->typ==NULL) |
---|
1528 | return FALSE; |
---|
1529 | |
---|
1530 | |
---|
1531 | int j = p; // Which IS record to use... |
---|
1532 | for( int pos = 0; pos < r->OrdSize; pos++ ) |
---|
1533 | if( r->typ[pos].ord_typ == ro_am) |
---|
1534 | if( j-- == 0 ) |
---|
1535 | { |
---|
1536 | typ_pos = pos; |
---|
1537 | |
---|
1538 | if( bSearchWvhdl ) |
---|
1539 | { |
---|
1540 | const int nblocks = rBlocks(r) - 1; |
---|
1541 | const int* w = r->typ[pos].data.am.weights; // ? |
---|
1542 | |
---|
1543 | for( pos = 0; pos <= nblocks; pos ++ ) |
---|
1544 | if (r->order[pos] == ringorder_am) |
---|
1545 | if( r->wvhdl[pos] == w ) |
---|
1546 | { |
---|
1547 | wvhdl_pos = pos; |
---|
1548 | break; |
---|
1549 | } |
---|
1550 | if (wvhdl_pos < 0) |
---|
1551 | return FALSE; |
---|
1552 | |
---|
1553 | assume(wvhdl_pos >= 0); |
---|
1554 | } |
---|
1555 | assume(typ_pos >= 0); |
---|
1556 | return TRUE; |
---|
1557 | } |
---|
1558 | |
---|
1559 | return FALSE; |
---|
1560 | } |
---|
1561 | |
---|
1562 | // // ? |
---|
1563 | // static BOOLEAN GetAMData(leftv res, leftv h) |
---|
1564 | // { |
---|
1565 | // NoReturn(res); |
---|
1566 | // |
---|
1567 | // const ring r = currRing; |
---|
1568 | // |
---|
1569 | // int p = 0; // which IS-block? p^th! |
---|
1570 | // |
---|
1571 | // if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1572 | // p = (int)((long)(h->Data())); h=h->next; |
---|
1573 | // |
---|
1574 | // assume(p >= 0); |
---|
1575 | // |
---|
1576 | // int d, w; |
---|
1577 | // |
---|
1578 | // if( !rGetAMPos(r, p, d, w, TRUE) ) |
---|
1579 | // { |
---|
1580 | // Werror("`GetAMData([int])`: no %d^th _am block-ordering!", p); |
---|
1581 | // return TRUE; |
---|
1582 | // } |
---|
1583 | // |
---|
1584 | // assume( r->typ[d].ord_typ == ro_am ); |
---|
1585 | // assume( r->order[w] == ringorder_am ); |
---|
1586 | // |
---|
1587 | // |
---|
1588 | // const short start = r->typ[d].data.am.start; // bounds of ordering (in E) |
---|
1589 | // const short end = r->typ[d].data.am.end; |
---|
1590 | // const short len_gen = r->typ[d].data.am.len_gen; // i>len_gen: weight(gen(i)):=0 |
---|
1591 | // const int *weights = r->typ[d].data.am.weights; // pointers into wvhdl field of length (end-start+1) + len_gen |
---|
1592 | // // contents w_1,... w_n, len, mod_w_1, .. mod_w_len, 0 |
---|
1593 | // |
---|
1594 | // assume( weights == r->wvhdl[w] ); |
---|
1595 | // |
---|
1596 | // |
---|
1597 | // lists l=(lists)omAllocBin(slists_bin); |
---|
1598 | // l->Init(2); |
---|
1599 | // |
---|
1600 | // const short V = end-start+1; |
---|
1601 | // intvec* ww_vars = new intvec(V); |
---|
1602 | // intvec* ww_gens = new intvec(len_gen); |
---|
1603 | // |
---|
1604 | // for (int i = 0; i < V; i++ ) |
---|
1605 | // (*ww_vars)[i] = weights[i]; |
---|
1606 | // |
---|
1607 | // assume( weights[V] == len_gen ); |
---|
1608 | // |
---|
1609 | // for (int i = 0; i < len_gen; i++ ) |
---|
1610 | // (*ww_gens)[i] = weights[i - V - 1]; |
---|
1611 | // |
---|
1612 | // |
---|
1613 | // l->m[0].rtyp = INTVEC_CMD; |
---|
1614 | // l->m[0].data = reinterpret_cast<void *>(ww_vars); |
---|
1615 | // |
---|
1616 | // l->m[1].rtyp = INTVEC_CMD; |
---|
1617 | // l->m[1].data = reinterpret_cast<void *>(ww_gens); |
---|
1618 | // |
---|
1619 | // |
---|
1620 | // return FALSE; |
---|
1621 | // |
---|
1622 | // } |
---|
1623 | */ |
---|
1624 | |
---|
1625 | /// Returns old SyzCompLimit, can set new limit |
---|
1626 | static BOOLEAN SetInducedReferrence(leftv res, leftv h) |
---|
1627 | { |
---|
1628 | NoReturn(res); |
---|
1629 | |
---|
1630 | const ring r = currRing; |
---|
1631 | |
---|
1632 | if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) ) |
---|
1633 | { |
---|
1634 | WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected"); |
---|
1635 | return TRUE; |
---|
1636 | } |
---|
1637 | |
---|
1638 | const ideal F = (ideal)h->Data(); ; // No copy! |
---|
1639 | h=h->next; |
---|
1640 | |
---|
1641 | int rank = 0; |
---|
1642 | |
---|
1643 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1644 | { |
---|
1645 | rank = (int)((long)(h->Data())); h=h->next; |
---|
1646 | assume(rank >= 0); |
---|
1647 | } else |
---|
1648 | rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1) |
---|
1649 | |
---|
1650 | int p = 0; // which IS-block? p^th! |
---|
1651 | |
---|
1652 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1653 | { |
---|
1654 | p = (int)((long)(h->Data())); h=h->next; |
---|
1655 | assume(p >= 0); |
---|
1656 | } |
---|
1657 | |
---|
1658 | const int posIS = rGetISPos(p, r); |
---|
1659 | |
---|
1660 | if( /*(*/ -1 == posIS /*)*/ ) |
---|
1661 | { |
---|
1662 | WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)"); |
---|
1663 | return TRUE; |
---|
1664 | } |
---|
1665 | |
---|
1666 | |
---|
1667 | |
---|
1668 | // F & componentWeights belong to that ordering block of currRing now: |
---|
1669 | rSetISReference(r, F, rank, p); // F will be copied! |
---|
1670 | return FALSE; |
---|
1671 | } |
---|
1672 | |
---|
1673 | |
---|
1674 | // F = ISUpdateComponents( F, V, MIN ); |
---|
1675 | // // replace gen(i) -> gen(MIN + V[i-MIN]) for all i > MIN in all terms from F! |
---|
1676 | static BOOLEAN ISUpdateComponents(leftv res, leftv h) |
---|
1677 | { |
---|
1678 | NoReturn(res); |
---|
1679 | |
---|
1680 | PrintS("ISUpdateComponents:.... \n"); |
---|
1681 | |
---|
1682 | if ((h!=NULL) && (h->Typ()==MODUL_CMD)) |
---|
1683 | { |
---|
1684 | ideal F = (ideal)h->Data(); ; // No copy! |
---|
1685 | h=h->next; |
---|
1686 | |
---|
1687 | if ((h!=NULL) && (h->Typ()==INTVEC_CMD)) |
---|
1688 | { |
---|
1689 | const intvec* const V = (const intvec* const) h->Data(); |
---|
1690 | h=h->next; |
---|
1691 | |
---|
1692 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
1693 | { |
---|
1694 | const int MIN = (int)((long)(h->Data())); |
---|
1695 | |
---|
1696 | pISUpdateComponents(F, V, MIN, currRing); |
---|
1697 | return FALSE; |
---|
1698 | } |
---|
1699 | } |
---|
1700 | } |
---|
1701 | |
---|
1702 | WerrorS("`ISUpdateComponents(<module>, intvec, int)` expected"); |
---|
1703 | return TRUE; |
---|
1704 | } |
---|
1705 | |
---|
1706 | |
---|
1707 | /// NF using length |
---|
1708 | static BOOLEAN reduce_syz(leftv res, leftv h) |
---|
1709 | { |
---|
1710 | // const ring r = currRing; |
---|
1711 | |
---|
1712 | if ( !( (h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) ) ) |
---|
1713 | { |
---|
1714 | WerrorS("`reduce_syz(<poly/vector>!, <ideal/module>, <int>, [int])` expected"); |
---|
1715 | return TRUE; |
---|
1716 | } |
---|
1717 | |
---|
1718 | res->rtyp = h->Typ(); |
---|
1719 | const poly v = reinterpret_cast<poly>(h->Data()); |
---|
1720 | h=h->next; |
---|
1721 | |
---|
1722 | if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD || h->Typ()==IDEAL_CMD ) ) ) |
---|
1723 | { |
---|
1724 | WerrorS("`reduce_syz(<poly/vector>, <ideal/module>!, <int>, [int])` expected"); |
---|
1725 | return TRUE; |
---|
1726 | } |
---|
1727 | |
---|
1728 | assumeStdFlag(h); |
---|
1729 | const ideal M = reinterpret_cast<ideal>(h->Data()); h=h->next; |
---|
1730 | |
---|
1731 | |
---|
1732 | if ( !( (h!=NULL) && (h->Typ()== INT_CMD) ) ) |
---|
1733 | { |
---|
1734 | WerrorS("`reduce_syz(<poly/vector>, <ideal/module>, <int>!, [int])` expected"); |
---|
1735 | return TRUE; |
---|
1736 | } |
---|
1737 | |
---|
1738 | const int iSyzComp = (int)((long)(h->Data())); h=h->next; |
---|
1739 | |
---|
1740 | int iLazyReduce = 0; |
---|
1741 | |
---|
1742 | if ( ( (h!=NULL) && (h->Typ()== INT_CMD) ) ) |
---|
1743 | iLazyReduce = (int)((long)(h->Data())); |
---|
1744 | |
---|
1745 | res->data = (void *)kNFLength(M, currQuotient, v, iSyzComp, iLazyReduce); |
---|
1746 | return FALSE; |
---|
1747 | } |
---|
1748 | |
---|
1749 | |
---|
1750 | /// Get raw syzygies (idPrepare) |
---|
1751 | static BOOLEAN idPrepare(leftv res, leftv h) |
---|
1752 | { |
---|
1753 | // extern int rGetISPos(const int p, const ring r); |
---|
1754 | |
---|
1755 | const ring r = currRing; |
---|
1756 | |
---|
1757 | const bool isSyz = rIsSyzIndexRing(r); |
---|
1758 | const int posIS = rGetISPos(0, r); |
---|
1759 | |
---|
1760 | |
---|
1761 | if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) ) |
---|
1762 | { |
---|
1763 | WerrorS("`idPrepare(<module>)` expected"); |
---|
1764 | return TRUE; |
---|
1765 | } |
---|
1766 | |
---|
1767 | const ideal I = reinterpret_cast<ideal>(h->Data()); |
---|
1768 | |
---|
1769 | assume( I != NULL ); |
---|
1770 | idTest(I); |
---|
1771 | |
---|
1772 | int iComp = -1; |
---|
1773 | |
---|
1774 | h=h->next; |
---|
1775 | if ( (h!=NULL) && (h->Typ()==INT_CMD) ) |
---|
1776 | { |
---|
1777 | iComp = (int)((long)(h->Data())); |
---|
1778 | } else |
---|
1779 | { |
---|
1780 | if( (!isSyz) && (-1 == posIS) ) |
---|
1781 | { |
---|
1782 | WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)"); |
---|
1783 | return TRUE; |
---|
1784 | } |
---|
1785 | |
---|
1786 | if( isSyz ) |
---|
1787 | iComp = rGetCurrSyzLimit(r); |
---|
1788 | else |
---|
1789 | iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ; |
---|
1790 | } |
---|
1791 | |
---|
1792 | assume(iComp >= 0); |
---|
1793 | |
---|
1794 | |
---|
1795 | intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD)); |
---|
1796 | tHomog hom = testHomog; |
---|
1797 | |
---|
1798 | // int add_row_shift = 0; |
---|
1799 | // |
---|
1800 | if (w!=NULL) |
---|
1801 | { |
---|
1802 | w = ivCopy(w); |
---|
1803 | // add_row_shift = ww->min_in(); |
---|
1804 | // |
---|
1805 | // (*ww) -= add_row_shift; |
---|
1806 | // |
---|
1807 | // if (idTestHomModule(I, currQuotient, ww)) |
---|
1808 | // { |
---|
1809 | hom = isHomog; |
---|
1810 | // w = ww; |
---|
1811 | // } |
---|
1812 | // else |
---|
1813 | // { |
---|
1814 | // //WarnS("wrong weights"); |
---|
1815 | // delete ww; |
---|
1816 | // w = NULL; |
---|
1817 | // hom=testHomog; |
---|
1818 | // } |
---|
1819 | } |
---|
1820 | |
---|
1821 | |
---|
1822 | // computes syzygies of h1, |
---|
1823 | // works always in a ring with ringorder_s |
---|
1824 | // NOTE: rSetSyzComp(syzcomp) should better be called beforehand |
---|
1825 | // ideal idPrepare (ideal h1, tHomog hom, int syzcomp, intvec **w); |
---|
1826 | |
---|
1827 | ideal J = // idPrepare( I, hom, iComp, &w); |
---|
1828 | kStd(I, currQuotient, hom, &w, NULL, iComp); |
---|
1829 | |
---|
1830 | idTest(J); |
---|
1831 | |
---|
1832 | if (w!=NULL) |
---|
1833 | atSet(res, omStrDup("isHomog"), w, INTVEC_CMD); |
---|
1834 | // if (w!=NULL) delete w; |
---|
1835 | |
---|
1836 | res->rtyp = MODUL_CMD; |
---|
1837 | res->data = reinterpret_cast<void *>(J); |
---|
1838 | return FALSE; |
---|
1839 | } |
---|
1840 | |
---|
1841 | /// Get raw syzygies (idPrepare) |
---|
1842 | static BOOLEAN _p_Content(leftv res, leftv h) |
---|
1843 | { |
---|
1844 | if ( !( (h!=NULL) && (h->Typ()==POLY_CMD) && (h->Data() != NULL) ) ) |
---|
1845 | { |
---|
1846 | WerrorS("`p_Content(<poly-var>)` expected"); |
---|
1847 | return TRUE; |
---|
1848 | } |
---|
1849 | |
---|
1850 | |
---|
1851 | const poly p = reinterpret_cast<poly>(h->Data()); |
---|
1852 | |
---|
1853 | |
---|
1854 | pTest(p); pWrite(p); PrintLn(); |
---|
1855 | |
---|
1856 | |
---|
1857 | p_Content( p, currRing); |
---|
1858 | |
---|
1859 | pTest(p); |
---|
1860 | pWrite(p); PrintLn(); |
---|
1861 | |
---|
1862 | NoReturn(res); |
---|
1863 | return false; |
---|
1864 | } |
---|
1865 | |
---|
1866 | static BOOLEAN _m2_end(leftv res, leftv h) |
---|
1867 | { |
---|
1868 | int ret = 0; |
---|
1869 | |
---|
1870 | if ( (h!=NULL) && (h->Typ()!=INT_CMD) ) |
---|
1871 | { |
---|
1872 | WerrorS("`m2_end([<int>])` expected"); |
---|
1873 | return TRUE; |
---|
1874 | } |
---|
1875 | ret = (int)(long)(h->Data()); |
---|
1876 | |
---|
1877 | m2_end( ret ); |
---|
1878 | |
---|
1879 | NoReturn(res); |
---|
1880 | return FALSE; |
---|
1881 | } |
---|
1882 | |
---|
1883 | |
---|
1884 | |
---|
1885 | END_NAMESPACE |
---|
1886 | |
---|
1887 | |
---|
1888 | int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions) |
---|
1889 | { |
---|
1890 | #define ADD0(A,B,C,D,E) A(B, (char*)C, D, E) |
---|
1891 | // #define ADD(A,B,C,D,E) ADD0(iiAddCproc, "", C, D, E) |
---|
1892 | #define ADD(A,B,C,D,E) ADD0(A->iiAddCproc, B, C, D, E) |
---|
1893 | ADD(psModulFunctions, currPack->libname, "ClearContent", FALSE, _ClearContent); |
---|
1894 | ADD(psModulFunctions, currPack->libname, "ClearDenominators", FALSE, _ClearDenominators); |
---|
1895 | |
---|
1896 | ADD(psModulFunctions, currPack->libname, "m2_end", FALSE, _m2_end); |
---|
1897 | |
---|
1898 | ADD(psModulFunctions, currPack->libname, "DetailedPrint", FALSE, DetailedPrint); |
---|
1899 | ADD(psModulFunctions, currPack->libname, "leadmonomial", FALSE, leadmonom); |
---|
1900 | ADD(psModulFunctions, currPack->libname, "leadcomp", FALSE, leadcomp); |
---|
1901 | ADD(psModulFunctions, currPack->libname, "leadrawexp", FALSE, leadrawexp); |
---|
1902 | |
---|
1903 | ADD(psModulFunctions, currPack->libname, "ISUpdateComponents", FALSE, ISUpdateComponents); |
---|
1904 | ADD(psModulFunctions, currPack->libname, "SetInducedReferrence", FALSE, SetInducedReferrence); |
---|
1905 | ADD(psModulFunctions, currPack->libname, "GetInducedData", FALSE, GetInducedData); |
---|
1906 | ADD(psModulFunctions, currPack->libname, "SetSyzComp", FALSE, SetSyzComp); |
---|
1907 | ADD(psModulFunctions, currPack->libname, "MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering); |
---|
1908 | ADD(psModulFunctions, currPack->libname, "MakeSyzCompOrdering", FALSE, MakeSyzCompOrdering); |
---|
1909 | |
---|
1910 | ADD(psModulFunctions, currPack->libname, "ProfilerStart", FALSE, _ProfilerStart); ADD(psModulFunctions, currPack->libname, "ProfilerStop", FALSE, _ProfilerStop ); |
---|
1911 | |
---|
1912 | ADD(psModulFunctions, currPack->libname, "noop", FALSE, noop); |
---|
1913 | ADD(psModulFunctions, currPack->libname, "idPrepare", FALSE, idPrepare); |
---|
1914 | ADD(psModulFunctions, currPack->libname, "reduce_syz", FALSE, reduce_syz); |
---|
1915 | |
---|
1916 | ADD(psModulFunctions, currPack->libname, "p_Content", FALSE, _p_Content); |
---|
1917 | |
---|
1918 | ADD(psModulFunctions, currPack->libname, "Tail", FALSE, Tail); |
---|
1919 | |
---|
1920 | ADD(psModulFunctions, currPack->libname, "ComputeLeadingSyzygyTerms", FALSE, ComputeLeadingSyzygyTerms); |
---|
1921 | ADD(psModulFunctions, currPack->libname, "Compute2LeadingSyzygyTerms", FALSE, Compute2LeadingSyzygyTerms); |
---|
1922 | |
---|
1923 | ADD(psModulFunctions, currPack->libname, "Sort_c_ds", FALSE, Sort_c_ds); |
---|
1924 | ADD(psModulFunctions, currPack->libname, "FindReducer", FALSE, FindReducer); |
---|
1925 | |
---|
1926 | |
---|
1927 | // ADD(psModulFunctions, currPack->libname, "GetAMData", FALSE, GetAMData); |
---|
1928 | |
---|
1929 | // ADD(psModulFunctions, currPack->libname, "", FALSE, ); |
---|
1930 | |
---|
1931 | #undef ADD |
---|
1932 | return 0; |
---|
1933 | } |
---|
1934 | |
---|
1935 | #ifndef EMBED_PYTHON |
---|
1936 | extern "C" { |
---|
1937 | int mod_init(SModulFunctions* psModulFunctions) |
---|
1938 | { |
---|
1939 | return SI_MOD_INIT(syzextra)(psModulFunctions); |
---|
1940 | } |
---|
1941 | } |
---|
1942 | #endif |
---|