1 | #include <kernel/mod2.h> |
---|
2 | |
---|
3 | #include <omalloc/omalloc.h> |
---|
4 | |
---|
5 | #include <misc/intvec.h> |
---|
6 | |
---|
7 | #include <coeffs/coeffs.h> |
---|
8 | |
---|
9 | #include <polys/monomials/p_polys.h> |
---|
10 | #include <polys/monomials/ring.h> |
---|
11 | // #include <kernel/longrat.h> |
---|
12 | #include <kernel/kstd1.h> |
---|
13 | |
---|
14 | #include <kernel/polys.h> |
---|
15 | |
---|
16 | #include <kernel/syz.h> |
---|
17 | |
---|
18 | #include <Singular/tok.h> |
---|
19 | #include <Singular/ipid.h> |
---|
20 | #include <Singular/lists.h> |
---|
21 | #include <Singular/attrib.h> |
---|
22 | |
---|
23 | #include <Singular/ipid.h> |
---|
24 | #include <Singular/ipshell.h> // For iiAddCproc |
---|
25 | |
---|
26 | // extern coeffs coeffs_BIGINT |
---|
27 | |
---|
28 | #include "singularxx_defs.h" |
---|
29 | #include "DebugPrint.h" |
---|
30 | #include "myNF.h" |
---|
31 | |
---|
32 | extern void pISUpdateComponents(ideal F, const intvec *const V, const int MIN, const ring r); |
---|
33 | // extern ring rCurrRingAssure_SyzComp(); |
---|
34 | extern ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sign); |
---|
35 | extern int rGetISPos(const int p, const ring r); |
---|
36 | |
---|
37 | |
---|
38 | USING_NAMESPACE( SINGULARXXNAME :: DEBUG ) |
---|
39 | USING_NAMESPACE( SINGULARXXNAME :: NF ) |
---|
40 | |
---|
41 | BEGIN_NAMESPACE_NONAME |
---|
42 | static inline void NoReturn(leftv& res) |
---|
43 | { |
---|
44 | res->rtyp = NONE; |
---|
45 | res->data = NULL; |
---|
46 | } |
---|
47 | |
---|
48 | /// try to get an optional (simple) integer argument out of h |
---|
49 | /// or return the default value |
---|
50 | static int getOptionalInteger(const leftv& h, const int _n) |
---|
51 | { |
---|
52 | if( h!= NULL && h->Typ() == INT_CMD ) |
---|
53 | { |
---|
54 | int n = (int)(long)(h->Data()); |
---|
55 | |
---|
56 | if( n < 0 ) |
---|
57 | Warn("Negative (%d) optional integer argument", n); |
---|
58 | |
---|
59 | return (n); |
---|
60 | } |
---|
61 | |
---|
62 | return (_n); |
---|
63 | } |
---|
64 | |
---|
65 | BOOLEAN noop(leftv __res, leftv /*__v*/) |
---|
66 | { |
---|
67 | NoReturn(__res); |
---|
68 | return FALSE; |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | static inline number jjLONG2N(long d) |
---|
73 | { |
---|
74 | return n_Init(d, coeffs_BIGINT); |
---|
75 | } |
---|
76 | |
---|
77 | static inline void view(const intvec* v) |
---|
78 | { |
---|
79 | #ifndef NDEBUG |
---|
80 | v->view(); |
---|
81 | #else |
---|
82 | // This code duplication is only due to Hannes's #ifndef NDEBUG! |
---|
83 | Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length()); |
---|
84 | |
---|
85 | for (int i = 0; i < v->rows(); i++) |
---|
86 | { |
---|
87 | Print ("Row[%3d]:", i); |
---|
88 | for (int j = 0; j < v->cols(); j++) |
---|
89 | Print (" %5d", (*v)[j + i * (v->cols())] ); |
---|
90 | PrintLn (); |
---|
91 | } |
---|
92 | PrintS ("}\n"); |
---|
93 | #endif |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | static BOOLEAN DetailedPrint(leftv __res, leftv h) |
---|
100 | { |
---|
101 | NoReturn(__res); |
---|
102 | |
---|
103 | if( h == NULL ) |
---|
104 | { |
---|
105 | WarnS("DetailedPrint needs an argument..."); |
---|
106 | return TRUE; |
---|
107 | } |
---|
108 | |
---|
109 | if( h->Typ() == RING_CMD) |
---|
110 | { |
---|
111 | const ring r = (const ring)h->Data(); |
---|
112 | rWrite(r, TRUE); |
---|
113 | PrintLn(); |
---|
114 | #ifdef RDEBUG |
---|
115 | rDebugPrint(r); |
---|
116 | #endif |
---|
117 | return FALSE; |
---|
118 | } |
---|
119 | |
---|
120 | if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) |
---|
121 | { |
---|
122 | const poly p = (const poly)h->Data(); h = h->Next(); |
---|
123 | |
---|
124 | dPrint(p, currRing, currRing, getOptionalInteger(h, 3)); |
---|
125 | |
---|
126 | return FALSE; |
---|
127 | } |
---|
128 | |
---|
129 | if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD) |
---|
130 | { |
---|
131 | const ideal id = (const ideal)h->Data(); h = h->Next(); |
---|
132 | |
---|
133 | dPrint(id, currRing, currRing, getOptionalInteger(h, 3)); |
---|
134 | |
---|
135 | return FALSE; |
---|
136 | } |
---|
137 | |
---|
138 | if( h->Typ() == RESOLUTION_CMD ) |
---|
139 | { |
---|
140 | const syStrategy syzstr = reinterpret_cast<const syStrategy>(h->Data()); |
---|
141 | |
---|
142 | h = h->Next(); |
---|
143 | |
---|
144 | int nTerms = getOptionalInteger(h, 1); |
---|
145 | |
---|
146 | |
---|
147 | Print("RESOLUTION_CMD(%p): ", reinterpret_cast<const void*>(syzstr)); PrintLn(); |
---|
148 | |
---|
149 | const ring save = currRing; |
---|
150 | const ring r = syzstr->syRing; |
---|
151 | const ring rr = (r != NULL) ? r: save; |
---|
152 | |
---|
153 | |
---|
154 | const int iLength = syzstr->length; |
---|
155 | |
---|
156 | Print("int 'length': %d", iLength); PrintLn(); |
---|
157 | Print("int 'regularity': %d", syzstr->regularity); PrintLn(); |
---|
158 | Print("short 'list_length': %hd", syzstr->list_length); PrintLn(); |
---|
159 | Print("short 'references': %hd", syzstr->references); PrintLn(); |
---|
160 | |
---|
161 | |
---|
162 | #define PRINT_pINTVECTOR(s, v) Print("intvec '%10s'(%p)", #v, reinterpret_cast<const void*>((s)->v)); \ |
---|
163 | if( (s)->v != NULL ){ PrintS(": "); view((s)->v); }; \ |
---|
164 | PrintLn(); |
---|
165 | |
---|
166 | PRINT_pINTVECTOR(syzstr, resolution); |
---|
167 | PRINT_pINTVECTOR(syzstr, betti); |
---|
168 | PRINT_pINTVECTOR(syzstr, Tl); |
---|
169 | PRINT_pINTVECTOR(syzstr, cw); |
---|
170 | #undef PRINT_pINTVECTOR |
---|
171 | |
---|
172 | if (r == NULL) |
---|
173 | Print("ring '%10s': NULL", "syRing"); |
---|
174 | else |
---|
175 | if (r == currRing) |
---|
176 | Print("ring '%10s': currRing", "syRing"); |
---|
177 | else |
---|
178 | if (r != NULL && r != save) |
---|
179 | { |
---|
180 | Print("ring '%10s': ", "syRing"); |
---|
181 | rWrite(r); |
---|
182 | #ifdef RDEBUG |
---|
183 | // rDebugPrint(r); |
---|
184 | #endif |
---|
185 | // rChangeCurrRing(r); |
---|
186 | } |
---|
187 | PrintLn(); |
---|
188 | |
---|
189 | const SRes rP = syzstr->resPairs; |
---|
190 | Print("SRes 'resPairs': %p", reinterpret_cast<const void*>(rP)); PrintLn(); |
---|
191 | |
---|
192 | if (rP != NULL) |
---|
193 | for (int iLevel = 0; (iLevel < iLength) && (rP[iLevel] != NULL) && ((*syzstr->Tl)[iLevel] >= 0); iLevel++) |
---|
194 | { |
---|
195 | int n = 0; |
---|
196 | const int iTl = (*syzstr->Tl)[iLevel]; |
---|
197 | for (int j = 0; (j < iTl) && ((rP[iLevel][j].lcm!=NULL) || (rP[iLevel][j].syz!=NULL)); j++) |
---|
198 | { |
---|
199 | if (rP[iLevel][j].isNotMinimal==NULL) |
---|
200 | n++; |
---|
201 | } |
---|
202 | Print("minimal-resPairs-Size[1+%d]: %d", iLevel, n); PrintLn(); |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | // const ring rrr = (iLevel > 0) ? rr : save; ? |
---|
207 | #define PRINT_RESOLUTION(s, v) Print("resolution '%12s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn(); \ |
---|
208 | if ((s)->v != NULL) \ |
---|
209 | for (int iLevel = 0; (iLevel < iLength) && ( ((s)->v)[iLevel] != NULL ); iLevel++) \ |
---|
210 | { \ |
---|
211 | /* const ring rrr = (iLevel > 0) ? save : save; */ \ |
---|
212 | 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)*/ ); \ |
---|
213 | PrintLn(); \ |
---|
214 | } \ |
---|
215 | PrintLn(); |
---|
216 | |
---|
217 | // resolvente: |
---|
218 | PRINT_RESOLUTION(syzstr, minres); |
---|
219 | PRINT_RESOLUTION(syzstr, fullres); |
---|
220 | |
---|
221 | assume (id_RankFreeModule (syzstr->res[1], rr) == syzstr->res[1]->rank); |
---|
222 | |
---|
223 | PRINT_RESOLUTION(syzstr, res); |
---|
224 | PRINT_RESOLUTION(syzstr, orderedRes); |
---|
225 | #undef PRINT_RESOLUTION |
---|
226 | |
---|
227 | #define PRINT_POINTER(s, v) Print("pointer '%17s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn(); |
---|
228 | // 2d arrays: |
---|
229 | PRINT_POINTER(syzstr, truecomponents); |
---|
230 | PRINT_POINTER(syzstr, ShiftedComponents); |
---|
231 | PRINT_POINTER(syzstr, backcomponents); |
---|
232 | PRINT_POINTER(syzstr, Howmuch); |
---|
233 | PRINT_POINTER(syzstr, Firstelem); |
---|
234 | PRINT_POINTER(syzstr, elemLength); |
---|
235 | PRINT_POINTER(syzstr, sev); |
---|
236 | |
---|
237 | // arrays of intvects: |
---|
238 | PRINT_POINTER(syzstr, weights); |
---|
239 | PRINT_POINTER(syzstr, hilb_coeffs); |
---|
240 | #undef PRINT_POINTER |
---|
241 | |
---|
242 | |
---|
243 | if (syzstr->fullres==NULL) |
---|
244 | { |
---|
245 | PrintS("resolution 'fullres': (NULL) => resolution not computed yet"); |
---|
246 | PrintLn(); |
---|
247 | } else |
---|
248 | { |
---|
249 | Print("resolution 'fullres': (%p) => resolution seems to be computed already", reinterpret_cast<const void*>(syzstr->fullres)); |
---|
250 | PrintLn(); |
---|
251 | dPrint(*syzstr->fullres, save, save, nTerms); |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | if (syzstr->minres==NULL) |
---|
258 | { |
---|
259 | PrintS("resolution 'minres': (NULL) => resolution not minimized yet"); |
---|
260 | PrintLn(); |
---|
261 | } else |
---|
262 | { |
---|
263 | Print("resolution 'minres': (%p) => resolution seems to be minimized already", reinterpret_cast<const void*>(syzstr->minres)); |
---|
264 | PrintLn(); |
---|
265 | dPrint(*syzstr->minres, save, save, nTerms); |
---|
266 | } |
---|
267 | |
---|
268 | |
---|
269 | |
---|
270 | |
---|
271 | /* |
---|
272 | int ** truecomponents; |
---|
273 | long** ShiftedComponents; |
---|
274 | int ** backcomponents; |
---|
275 | int ** Howmuch; |
---|
276 | int ** Firstelem; |
---|
277 | int ** elemLength; |
---|
278 | unsigned long ** sev; |
---|
279 | |
---|
280 | intvec ** weights; |
---|
281 | intvec ** hilb_coeffs; |
---|
282 | |
---|
283 | SRes resPairs; //polynomial data for internal use only |
---|
284 | |
---|
285 | resolvente fullres; |
---|
286 | resolvente minres; |
---|
287 | resolvente res; //polynomial data for internal use only |
---|
288 | resolvente orderedRes; //polynomial data for internal use only |
---|
289 | */ |
---|
290 | |
---|
291 | // if( currRing != save ) rChangeCurrRing(save); |
---|
292 | } |
---|
293 | |
---|
294 | |
---|
295 | return FALSE; |
---|
296 | } |
---|
297 | |
---|
298 | |
---|
299 | |
---|
300 | /// Get leading monom (no module component) |
---|
301 | static BOOLEAN leadmonom(leftv res, leftv h) |
---|
302 | { |
---|
303 | NoReturn(res); |
---|
304 | |
---|
305 | if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL)) |
---|
306 | { |
---|
307 | const ring r = currRing; |
---|
308 | const poly p = (poly)(h->Data()); |
---|
309 | |
---|
310 | poly m = NULL; |
---|
311 | |
---|
312 | if( p != NULL ) |
---|
313 | { |
---|
314 | assume( p != NULL ); |
---|
315 | assume( p_LmTest(p, r) ); |
---|
316 | |
---|
317 | m = p_LmInit(p, r); |
---|
318 | p_SetCoeff0(m, n_Init(1, r), r); |
---|
319 | |
---|
320 | // if( p_GetComp(m, r) != 0 ) |
---|
321 | // { |
---|
322 | p_SetComp(m, 0, r); |
---|
323 | p_Setm(m, r); |
---|
324 | // } |
---|
325 | |
---|
326 | assume( p_GetComp(m, r) == 0 ); |
---|
327 | assume( m != NULL ); |
---|
328 | assume( p_LmTest(m, r) ); |
---|
329 | } |
---|
330 | |
---|
331 | res->rtyp = POLY_CMD; |
---|
332 | res->data = reinterpret_cast<void *>(m); |
---|
333 | |
---|
334 | return FALSE; |
---|
335 | } |
---|
336 | |
---|
337 | WerrorS("`leadmonom(<poly/vector>)` expected"); |
---|
338 | return TRUE; |
---|
339 | } |
---|
340 | |
---|
341 | /// Get leading component |
---|
342 | static BOOLEAN leadcomp(leftv res, leftv h) |
---|
343 | { |
---|
344 | NoReturn(res); |
---|
345 | |
---|
346 | if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL)) |
---|
347 | { |
---|
348 | const ring r = currRing; |
---|
349 | |
---|
350 | const poly p = (poly)(h->Data()); |
---|
351 | |
---|
352 | assume( p != NULL ); |
---|
353 | assume( p_LmTest(p, r) ); |
---|
354 | |
---|
355 | const unsigned long iComp = p_GetComp(p, r); |
---|
356 | |
---|
357 | assume( iComp > 0 ); // p is a vector |
---|
358 | |
---|
359 | res->rtyp = BIGINT_CMD; |
---|
360 | res->data = reinterpret_cast<void *>(jjLONG2N(iComp)); |
---|
361 | |
---|
362 | return FALSE; |
---|
363 | } |
---|
364 | |
---|
365 | WerrorS("`leadcomp(<poly/vector>)` expected"); |
---|
366 | return TRUE; |
---|
367 | } |
---|
368 | |
---|
369 | |
---|
370 | |
---|
371 | |
---|
372 | /// Get raw leading exponent vector |
---|
373 | static BOOLEAN leadrawexp(leftv res, leftv h) |
---|
374 | { |
---|
375 | NoReturn(res); |
---|
376 | |
---|
377 | if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL)) |
---|
378 | { |
---|
379 | const ring r = currRing; |
---|
380 | const poly p = (poly)(h->Data()); |
---|
381 | |
---|
382 | assume( p != NULL ); |
---|
383 | assume( p_LmTest(p, r) ); |
---|
384 | |
---|
385 | const int iExpSize = r->ExpL_Size; |
---|
386 | |
---|
387 | // intvec *iv = new intvec(iExpSize); |
---|
388 | |
---|
389 | lists l=(lists)omAllocBin(slists_bin); |
---|
390 | l->Init(iExpSize); |
---|
391 | |
---|
392 | for(int i = iExpSize-1; i >= 0; i--) |
---|
393 | { |
---|
394 | l->m[i].rtyp = BIGINT_CMD; |
---|
395 | l->m[i].data = reinterpret_cast<void *>(jjLONG2N(p->exp[i])); // longs... |
---|
396 | } |
---|
397 | |
---|
398 | res->rtyp = LIST_CMD; // list of bigints |
---|
399 | res->data = reinterpret_cast<void *>(l); |
---|
400 | return FALSE; |
---|
401 | } |
---|
402 | |
---|
403 | WerrorS("`leadrawexp(<poly/vector>)` expected"); |
---|
404 | return TRUE; |
---|
405 | } |
---|
406 | |
---|
407 | |
---|
408 | /// Endowe the current ring with additional (leading) Syz-component ordering |
---|
409 | static BOOLEAN MakeSyzCompOrdering(leftv res, leftv /*h*/) |
---|
410 | { |
---|
411 | |
---|
412 | NoReturn(res); |
---|
413 | |
---|
414 | // res->data = rCurrRingAssure_SyzComp(); // changes current ring! :( |
---|
415 | res->data = reinterpret_cast<void *>(rAssure_SyzComp(currRing, TRUE)); |
---|
416 | res->rtyp = RING_CMD; // return new ring! |
---|
417 | // QRING_CMD? |
---|
418 | |
---|
419 | return FALSE; |
---|
420 | } |
---|
421 | |
---|
422 | |
---|
423 | /// Same for Induced Schreyer ordering (ordering on components is defined by sign!) |
---|
424 | static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h) |
---|
425 | { |
---|
426 | |
---|
427 | NoReturn(res); |
---|
428 | |
---|
429 | int sign = 1; |
---|
430 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
431 | { |
---|
432 | const int s = (int)((long)(h->Data())); |
---|
433 | |
---|
434 | if( s != -1 && s != 1 ) |
---|
435 | { |
---|
436 | WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!"); |
---|
437 | return TRUE; |
---|
438 | } |
---|
439 | |
---|
440 | sign = s; |
---|
441 | } |
---|
442 | |
---|
443 | assume( sign == 1 || sign == -1 ); |
---|
444 | res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign)); |
---|
445 | res->rtyp = RING_CMD; // return new ring! |
---|
446 | // QRING_CMD? |
---|
447 | return FALSE; |
---|
448 | } |
---|
449 | |
---|
450 | |
---|
451 | /// Returns old SyzCompLimit, can set new limit |
---|
452 | static BOOLEAN SetSyzComp(leftv res, leftv h) |
---|
453 | { |
---|
454 | NoReturn(res); |
---|
455 | |
---|
456 | const ring r = currRing; |
---|
457 | |
---|
458 | if( !rIsSyzIndexRing(r) ) |
---|
459 | { |
---|
460 | WerrorS("`SetSyzComp(<int>)` called on incompatible ring (not created by 'MakeSyzCompOrdering'!)"); |
---|
461 | return TRUE; |
---|
462 | } |
---|
463 | |
---|
464 | res->rtyp = INT_CMD; |
---|
465 | res->data = reinterpret_cast<void *>(rGetCurrSyzLimit(r)); // return old syz limit |
---|
466 | |
---|
467 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
468 | { |
---|
469 | const int iSyzComp = (int)reinterpret_cast<long>(h->Data()); |
---|
470 | assume( iSyzComp > 0 ); |
---|
471 | rSetSyzComp(iSyzComp, currRing); |
---|
472 | } |
---|
473 | |
---|
474 | return FALSE; |
---|
475 | } |
---|
476 | |
---|
477 | /// ? |
---|
478 | static BOOLEAN GetInducedData(leftv res, leftv h) |
---|
479 | { |
---|
480 | NoReturn(res); |
---|
481 | |
---|
482 | const ring r = currRing; |
---|
483 | |
---|
484 | int p = 0; // which IS-block? p^th! |
---|
485 | |
---|
486 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
487 | { |
---|
488 | p = (int)((long)(h->Data())); h=h->next; |
---|
489 | assume(p >= 0); |
---|
490 | } |
---|
491 | |
---|
492 | const int pos = rGetISPos(p, r); |
---|
493 | |
---|
494 | if( (-1 == pos) ) |
---|
495 | { |
---|
496 | WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)"); |
---|
497 | return TRUE; |
---|
498 | } |
---|
499 | |
---|
500 | |
---|
501 | const int iLimit = r->typ[pos].data.is.limit; |
---|
502 | const ideal F = r->typ[pos].data.is.F; |
---|
503 | ideal FF = id_Copy(F, r); |
---|
504 | |
---|
505 | lists l=(lists)omAllocBin(slists_bin); |
---|
506 | l->Init(2); |
---|
507 | |
---|
508 | l->m[0].rtyp = INT_CMD; |
---|
509 | l->m[0].data = reinterpret_cast<void *>(iLimit); |
---|
510 | |
---|
511 | |
---|
512 | // l->m[1].rtyp = MODUL_CMD; |
---|
513 | |
---|
514 | if( idIsModule(FF, r) ) |
---|
515 | { |
---|
516 | l->m[1].rtyp = MODUL_CMD; |
---|
517 | |
---|
518 | // Print("before: %d\n", FF->nrows); |
---|
519 | // FF->nrows = id_RankFreeModule(FF, r); // ??? |
---|
520 | // Print("after: %d\n", FF->nrows); |
---|
521 | } |
---|
522 | else |
---|
523 | l->m[1].rtyp = IDEAL_CMD; |
---|
524 | |
---|
525 | l->m[1].data = reinterpret_cast<void *>(FF); |
---|
526 | |
---|
527 | res->rtyp = LIST_CMD; // list of int/module |
---|
528 | res->data = reinterpret_cast<void *>(l); |
---|
529 | |
---|
530 | return FALSE; |
---|
531 | |
---|
532 | } |
---|
533 | |
---|
534 | |
---|
535 | /// Returns old SyzCompLimit, can set new limit |
---|
536 | static BOOLEAN SetInducedReferrence(leftv res, leftv h) |
---|
537 | { |
---|
538 | NoReturn(res); |
---|
539 | |
---|
540 | const ring r = currRing; |
---|
541 | |
---|
542 | if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) ) |
---|
543 | { |
---|
544 | WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected"); |
---|
545 | return TRUE; |
---|
546 | } |
---|
547 | |
---|
548 | const ideal F = (ideal)h->Data(); ; // No copy! |
---|
549 | h=h->next; |
---|
550 | |
---|
551 | int rank = 0; |
---|
552 | |
---|
553 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
554 | { |
---|
555 | rank = (int)((long)(h->Data())); h=h->next; |
---|
556 | assume(rank >= 0); |
---|
557 | } else |
---|
558 | rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1) |
---|
559 | |
---|
560 | int p = 0; // which IS-block? p^th! |
---|
561 | |
---|
562 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
563 | { |
---|
564 | p = (int)((long)(h->Data())); h=h->next; |
---|
565 | assume(p >= 0); |
---|
566 | } |
---|
567 | |
---|
568 | const int posIS = rGetISPos(p, r); |
---|
569 | |
---|
570 | if( (-1 == posIS) ) |
---|
571 | { |
---|
572 | WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)"); |
---|
573 | return TRUE; |
---|
574 | } |
---|
575 | |
---|
576 | |
---|
577 | |
---|
578 | // F & componentWeights belong to that ordering block of currRing now: |
---|
579 | rSetISReference(r, F, rank, p); // F will be copied! |
---|
580 | return FALSE; |
---|
581 | } |
---|
582 | |
---|
583 | |
---|
584 | // F = ISUpdateComponents( F, V, MIN ); |
---|
585 | // // replace gen(i) -> gen(MIN + V[i-MIN]) for all i > MIN in all terms from F! |
---|
586 | static BOOLEAN ISUpdateComponents(leftv res, leftv h) |
---|
587 | { |
---|
588 | NoReturn(res); |
---|
589 | |
---|
590 | PrintS("ISUpdateComponents:.... \n"); |
---|
591 | |
---|
592 | if ((h!=NULL) && (h->Typ()==MODUL_CMD)) |
---|
593 | { |
---|
594 | ideal F = (ideal)h->Data(); ; // No copy! |
---|
595 | h=h->next; |
---|
596 | |
---|
597 | if ((h!=NULL) && (h->Typ()==INTVEC_CMD)) |
---|
598 | { |
---|
599 | const intvec* const V = (const intvec* const) h->Data(); |
---|
600 | h=h->next; |
---|
601 | |
---|
602 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
603 | { |
---|
604 | const int MIN = (int)((long)(h->Data())); |
---|
605 | |
---|
606 | pISUpdateComponents(F, V, MIN, currRing); |
---|
607 | return FALSE; |
---|
608 | } |
---|
609 | } |
---|
610 | } |
---|
611 | |
---|
612 | WerrorS("`ISUpdateComponents(<module>, intvec, int)` expected"); |
---|
613 | return TRUE; |
---|
614 | } |
---|
615 | |
---|
616 | |
---|
617 | /// NF using length |
---|
618 | static BOOLEAN reduce_syz(leftv res, leftv h) |
---|
619 | { |
---|
620 | const ring r = currRing; |
---|
621 | |
---|
622 | if ( !( (h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) ) ) |
---|
623 | { |
---|
624 | WerrorS("`reduce_syz(<poly/vector>!, <ideal/module>, <int>, [int])` expected"); |
---|
625 | return TRUE; |
---|
626 | } |
---|
627 | |
---|
628 | res->rtyp = h->Typ(); |
---|
629 | const poly v = reinterpret_cast<poly>(h->Data()); |
---|
630 | h=h->next; |
---|
631 | |
---|
632 | if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD || h->Typ()==IDEAL_CMD ) ) ) |
---|
633 | { |
---|
634 | WerrorS("`reduce_syz(<poly/vector>, <ideal/module>!, <int>, [int])` expected"); |
---|
635 | return TRUE; |
---|
636 | } |
---|
637 | |
---|
638 | assumeStdFlag(h); |
---|
639 | const ideal M = reinterpret_cast<ideal>(h->Data()); h=h->next; |
---|
640 | |
---|
641 | |
---|
642 | if ( !( (h!=NULL) && (h->Typ()== INT_CMD) ) ) |
---|
643 | { |
---|
644 | WerrorS("`reduce_syz(<poly/vector>, <ideal/module>, <int>!, [int])` expected"); |
---|
645 | return TRUE; |
---|
646 | } |
---|
647 | |
---|
648 | const int iSyzComp = (int)((long)(h->Data())); h=h->next; |
---|
649 | |
---|
650 | int iLazyReduce = 0; |
---|
651 | |
---|
652 | if ( ( (h!=NULL) && (h->Typ()== INT_CMD) ) ) |
---|
653 | iLazyReduce = (int)((long)(h->Data())); |
---|
654 | |
---|
655 | res->data = (void *)kNFLength(M, currQuotient, v, iSyzComp, iLazyReduce); |
---|
656 | return FALSE; |
---|
657 | } |
---|
658 | |
---|
659 | |
---|
660 | /// Get raw syzygies (idPrepare) |
---|
661 | static BOOLEAN idPrepare(leftv res, leftv h) |
---|
662 | { |
---|
663 | // extern int rGetISPos(const int p, const ring r); |
---|
664 | |
---|
665 | const ring r = currRing; |
---|
666 | |
---|
667 | const bool isSyz = rIsSyzIndexRing(r); |
---|
668 | const int posIS = rGetISPos(0, r); |
---|
669 | |
---|
670 | |
---|
671 | if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) ) |
---|
672 | { |
---|
673 | WerrorS("`idPrepare(<module>)` expected"); |
---|
674 | return TRUE; |
---|
675 | } |
---|
676 | |
---|
677 | const ideal I = reinterpret_cast<ideal>(h->Data()); |
---|
678 | |
---|
679 | assume( I != NULL ); |
---|
680 | idTest(I); |
---|
681 | |
---|
682 | int iComp = -1; |
---|
683 | |
---|
684 | h=h->next; |
---|
685 | if ( (h!=NULL) && (h->Typ()==INT_CMD) ) |
---|
686 | { |
---|
687 | iComp = (int)((long)(h->Data())); |
---|
688 | } else |
---|
689 | { |
---|
690 | if( (!isSyz) && (-1 == posIS) ) |
---|
691 | { |
---|
692 | WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)"); |
---|
693 | return TRUE; |
---|
694 | } |
---|
695 | |
---|
696 | if( isSyz ) |
---|
697 | iComp = rGetCurrSyzLimit(r); |
---|
698 | else |
---|
699 | iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ; |
---|
700 | } |
---|
701 | |
---|
702 | assume(iComp >= 0); |
---|
703 | |
---|
704 | |
---|
705 | tHomog hom=testHomog; |
---|
706 | intvec *w; // = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD)); |
---|
707 | |
---|
708 | // int add_row_shift = 0; |
---|
709 | // |
---|
710 | // if (w!=NULL) |
---|
711 | // { |
---|
712 | // intvec * ww = ivCopy(w); |
---|
713 | // |
---|
714 | // add_row_shift = ww->min_in(); |
---|
715 | // |
---|
716 | // (*ww) -= add_row_shift; |
---|
717 | // |
---|
718 | // if (idTestHomModule(I, currQuotient, ww)) |
---|
719 | // { |
---|
720 | // hom = isHomog; |
---|
721 | // w = ww; |
---|
722 | // } |
---|
723 | // else |
---|
724 | // { |
---|
725 | // //WarnS("wrong weights"); |
---|
726 | // delete ww; |
---|
727 | // w = NULL; |
---|
728 | // hom=testHomog; |
---|
729 | // } |
---|
730 | // } |
---|
731 | |
---|
732 | |
---|
733 | // computes syzygies of h1, |
---|
734 | // works always in a ring with ringorder_s |
---|
735 | // NOTE: rSetSyzComp(syzcomp) should better be called beforehand |
---|
736 | // ideal idPrepare (ideal h1, tHomog hom, int syzcomp, intvec **w); |
---|
737 | |
---|
738 | ideal J = // idPrepare( I, hom, iComp, &w); |
---|
739 | kStd(I, currQuotient, hom, &w, NULL, iComp); |
---|
740 | |
---|
741 | idTest(J); |
---|
742 | |
---|
743 | if (w!=NULL) delete w; |
---|
744 | // if (w!=NULL) |
---|
745 | // atSet(res, omStrDup("isHomog"), w, INTVEC_CMD); |
---|
746 | |
---|
747 | res->rtyp = MODUL_CMD; |
---|
748 | res->data = reinterpret_cast<void *>(J); |
---|
749 | return FALSE; |
---|
750 | } |
---|
751 | |
---|
752 | /// Get raw syzygies (idPrepare) |
---|
753 | static BOOLEAN _p_Content(leftv res, leftv h) |
---|
754 | { |
---|
755 | if ( !( (h!=NULL) && (h->Typ()==POLY_CMD) && (h->Data() != NULL) ) ) |
---|
756 | { |
---|
757 | WerrorS("`p_Content(<poly-var>)` expected"); |
---|
758 | return TRUE; |
---|
759 | } |
---|
760 | |
---|
761 | |
---|
762 | const poly p = reinterpret_cast<poly>(h->Data()); |
---|
763 | |
---|
764 | |
---|
765 | pTest(p); pWrite(p); PrintLn(); |
---|
766 | |
---|
767 | |
---|
768 | p_Content( p, currRing); |
---|
769 | |
---|
770 | pTest(p); |
---|
771 | pWrite(p); PrintLn(); |
---|
772 | |
---|
773 | NoReturn(res); |
---|
774 | } |
---|
775 | |
---|
776 | END_NAMESPACE |
---|
777 | |
---|
778 | extern "C" |
---|
779 | { |
---|
780 | |
---|
781 | int mod_init(SModulFunctions* psModulFunctions) |
---|
782 | { |
---|
783 | #define ADD0(A,B,C,D,E) A(B, (char*)C, D, E) |
---|
784 | // #define ADD(A,B,C,D,E) ADD0(iiAddCproc, "", C, D, E) |
---|
785 | #define ADD(A,B,C,D,E) ADD0(A->iiAddCproc, B, C, D, E) |
---|
786 | ADD(psModulFunctions, currPack->libname, "DetailedPrint", FALSE, DetailedPrint); |
---|
787 | ADD(psModulFunctions, currPack->libname, "leadmonom", FALSE, leadmonom); |
---|
788 | ADD(psModulFunctions, currPack->libname, "leadcomp", FALSE, leadcomp); |
---|
789 | ADD(psModulFunctions, currPack->libname, "leadrawexp", FALSE, leadrawexp); |
---|
790 | |
---|
791 | |
---|
792 | ADD(psModulFunctions, currPack->libname, "ISUpdateComponents", FALSE, ISUpdateComponents); |
---|
793 | ADD(psModulFunctions, currPack->libname, "SetInducedReferrence", FALSE, SetInducedReferrence); |
---|
794 | ADD(psModulFunctions, currPack->libname, "GetInducedData", FALSE, GetInducedData); |
---|
795 | ADD(psModulFunctions, currPack->libname, "SetSyzComp", FALSE, SetSyzComp); |
---|
796 | ADD(psModulFunctions, currPack->libname, "MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering); |
---|
797 | ADD(psModulFunctions, currPack->libname, "MakeSyzCompOrdering", FALSE, MakeSyzCompOrdering); |
---|
798 | |
---|
799 | ADD(psModulFunctions, currPack->libname, "noop", FALSE, noop); |
---|
800 | |
---|
801 | ADD(psModulFunctions, currPack->libname, "idPrepare", FALSE, idPrepare); |
---|
802 | ADD(psModulFunctions, currPack->libname, "reduce_syz", FALSE, reduce_syz); |
---|
803 | |
---|
804 | ADD(psModulFunctions, currPack->libname, "p_Content", FALSE, _p_Content); |
---|
805 | |
---|
806 | // ADD(psModulFunctions, currPack->libname, "", FALSE, ); |
---|
807 | #undef ADD |
---|
808 | return 0; |
---|
809 | } |
---|
810 | } |
---|