My Project
Loading...
Searching...
No Matches
mod_main.cc
Go to the documentation of this file.
1#include "kernel/mod2.h"
2
3#include "misc/intvec.h"
4#include "misc/options.h"
5
6#include "coeffs/coeffs.h"
7
9
12#include "polys/simpleideals.h"
13
15
16#include "kernel/polys.h"
17
18#include "kernel/GBEngine/syz.h"
19
20#include "Singular/tok.h"
21#include "Singular/ipid.h"
22#include "Singular/lists.h"
23#include "Singular/attrib.h"
24
25#include "Singular/ipid.h"
26#include "Singular/ipshell.h" // For iiAddCproc
27
28// extern coeffs coeffs_BIGINT
29
30#include "syzextra.h"
31
32#include "Singular/mod_lib.h"
33
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38
40
41
42static inline void NoReturn(leftv& res)
43{
44 res->rtyp = NONE;
45 res->data = NULL;
46}
47
48/// wrapper around n_ClearContent
50{
52
53 const char *usage = "'ClearContent' needs a (non-zero!) poly or vector argument...";
54
55 if( h == NULL )
56 {
57 WarnS(usage);
58 return TRUE;
59 }
60
61 assume( h != NULL );
62
63 if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
64 {
65 WarnS(usage);
66 return TRUE;
67 }
68
69 assume (h->Next() == NULL);
70
71 poly ph = reinterpret_cast<poly>(h->Data());
72
73 if( ph == NULL )
74 {
75 WarnS(usage);
76 return TRUE;
77 }
78
79 const ring r = currRing;
80 assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
81
82 number n;
83
84 // experimentall (recursive enumerator treatment) of alg. ext
86 n_ClearContent(itr, n, C);
87
88 res->data = n;
89 res->rtyp = NUMBER_CMD;
90
91 return FALSE;
92}
93
94/// wrapper around n_ClearDenominators
96{
98
99 const char *usage = "'ClearDenominators' needs a (non-zero!) poly or vector argument...";
100
101 if( h == NULL )
102 {
103 WarnS(usage);
104 return TRUE;
105 }
106
107 assume( h != NULL );
108
109 if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
110 {
111 WarnS(usage);
112 return TRUE;
113 }
114
115 assume (h->Next() == NULL);
116
117 poly ph = reinterpret_cast<poly>(h->Data());
118
119 if( ph == NULL )
120 {
121 WarnS(usage);
122 return TRUE;
123 }
124
125 const ring r = currRing;
126 assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
127
128 number n;
129
130 // experimentall (recursive enumerator treatment) of alg. ext.
131 CPolyCoeffsEnumerator itr(ph);
132 n_ClearDenominators(itr, n, C);
133
134 res->data = n;
135 res->rtyp = NUMBER_CMD;
136
137 return FALSE;
138}
139
140#if 0 // unused
141/// try to get an optional (simple) integer argument out of h
142/// or return the default value
143static int getOptionalInteger(const leftv& h, const int _n)
144{
145 if( h!= NULL && h->Typ() == INT_CMD )
146 {
147 int n = (int)(long)(h->Data());
148
149 if( n < 0 )
150 Warn("Negative (%d) optional integer argument", n);
151
152 return (n);
153 }
154
155 return (_n);
156}
157#endif
158
159static inline number jjLONG2N(long d)
160{
161 return n_Init(d, coeffs_BIGINT);
162}
163
164static inline void view(const intvec* v)
165{
166#ifndef SING_NDEBUG
167 v->view();
168#else
169 // This code duplication is only due to Hannes's #ifndef SING_NDEBUG!
170 Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length());
171
172 for (int i = 0; i < v->rows(); i++)
173 {
174 Print ("Row[%3d]:", i);
175 for (int j = 0; j < v->cols(); j++)
176 Print (" %5d", (*v)[j + i * (v->cols())] );
177 PrintLn ();
178 }
179 PrintS ("}\n");
180#endif
181
182}
183
184
185
186/// Get leading component
188{
189 if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
190 {
191 const ring r = currRing;
192
193 const poly p = (poly)(h->Data());
194
195 if (p != NULL )
196 {
197 assume( p != NULL );
198 p_LmTest(p, r);
199
200 const unsigned long iComp = p_GetComp(p, r);
201
202 // assume( iComp > 0 ); // p is a vector
203
204 res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
205 }
206 else
207 res->data = reinterpret_cast<void *>(jjLONG2N(0));
208
209
210 res->rtyp = BIGINT_CMD;
211 return FALSE;
212 }
213
214 WerrorS("`leadcomp(<poly/vector>)` expected");
215 return TRUE;
216}
217
218/// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
220{
221 int sign = 1;
222 if ((h!=NULL) && (h->Typ()==INT_CMD))
223 {
224 const int s = (int)((long)(h->Data()));
225
226 if( s != -1 && s != 1 )
227 {
228 WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
229 return TRUE;
230 }
231
232 sign = s;
233 }
234
235 assume( sign == 1 || sign == -1 );
236 res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
237 res->rtyp = RING_CMD; // return new ring!
238 // QRING_CMD?
239 return FALSE;
240}
241
242
243/// ?
245{
246 const ring r = currRing;
247
248 int p = 0; // which IS-block? p^th!
249
250 if ((h!=NULL) && (h->Typ()==INT_CMD))
251 {
252 p = (int)((long)(h->Data())); h=h->next;
253 assume(p >= 0);
254 }
255
256 const int pos = rGetISPos(p, r);
257
258 if( /*(*/ -1 == pos /*)*/ )
259 {
260 WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
261 return TRUE;
262 }
263
264
265 const int iLimit = r->typ[pos].data.is.limit;
266 const ideal F = r->typ[pos].data.is.F;
267
268 ideal FF = id_Copy(F, r);
269
271 l->Init(2);
272
273 l->m[0].rtyp = INT_CMD;
274 l->m[0].data = reinterpret_cast<void *>(iLimit);
275
276
277 // l->m[1].rtyp = MODUL_CMD;
278
279 if( id_IsModule(FF, r) ) // ???
280 {
281 l->m[1].rtyp = MODUL_CMD;
282
283 // Print("before: %d\n", FF->nrows);
284 // FF->nrows = id_RankFreeModule(FF, r); // ???
285 // Print("after: %d\n", FF->nrows);
286 }
287 else
288 l->m[1].rtyp = IDEAL_CMD;
289
290 l->m[1].data = reinterpret_cast<void *>(FF);
291
292 res->rtyp = LIST_CMD; // list of int/module
293 res->data = reinterpret_cast<void *>(l);
294
295 return FALSE;
296
297}
298
299/// Returns old SyzCompLimit, can set new limit
301{
302 res->Init();
303 NoReturn(res);
304
305 const ring r = currRing;
306
307 if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
308 {
309 WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
310 return TRUE;
311 }
312
313 const ideal F = (ideal)h->Data(); ; // No copy!
314 h=h->next;
315
316 int rank = 0;
317
318 if ((h!=NULL) && (h->Typ()==INT_CMD))
319 {
320 rank = (int)((long)(h->Data())); h=h->next;
321 assume(rank >= 0);
322 } else
323 rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
324
325 int p = 0; // which IS-block? p^th!
326
327 if ((h!=NULL) && (h->Typ()==INT_CMD))
328 {
329 p = (int)((long)(h->Data())); h=h->next;
330 assume(p >= 0);
331 }
332
333 const int posIS = rGetISPos(p, r);
334
335 if( /*(*/ -1 == posIS /*)*/ )
336 {
337 WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
338 return TRUE;
339 }
340
341 // F & componentWeights belong to that ordering block of currRing now:
342 rSetISReference(r, F, rank, p); // F will be copied!
343 return FALSE;
344}
345
346
347/// Get raw syzygies (idPrepare)
349{
350 // extern int rGetISPos(const int p, const ring r);
351
352 const ring r = currRing;
353
354 const bool isSyz = rIsSyzIndexRing(r);
355 const int posIS = rGetISPos(0, r);
356
357
358 if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
359 {
360 WerrorS("`idPrepare(<module>)` expected");
361 return TRUE;
362 }
363
364 const ideal I = reinterpret_cast<ideal>(h->Data());
365
366 assume( I != NULL );
367 idTest(I);
368
369 int iComp = -1;
370
371 h=h->next;
372 if ( (h!=NULL) && (h->Typ()==INT_CMD) )
373 {
374 iComp = (int)((long)(h->Data()));
375 }
376 else
377 {
378 if( (!isSyz) && (-1 == posIS) )
379 {
380 WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
381 return TRUE;
382 }
383
384 if( isSyz )
385 iComp = rGetCurrSyzLimit(r);
386 else
387 iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
388 }
389
390 assume(iComp >= 0);
391
392
393 intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
394 tHomog hom = testHomog;
395
396 // int add_row_shift = 0;
397 //
398 if (w!=NULL)
399 {
400 w = ivCopy(w);
401 // add_row_shift = ww->min_in();
402 //
403 // (*ww) -= add_row_shift;
404 //
405 // if (idTestHomModule(I, currRing->qideal, ww))
406 // {
407 hom = isHomog;
408 // w = ww;
409 // }
410 // else
411 // {
412 // //WarnS("wrong weights");
413 // delete ww;
414 // w = NULL;
415 // hom=testHomog;
416 // }
417 }
418
419
420 // computes syzygies of h1,
421 // works always in a ring with ringorder_s
422 // NOTE: rSetSyzComp(syzcomp) should better be called beforehand
423 // ideal idPrepare (ideal h1, tHomog hom, int syzcomp, intvec **w);
424
425 ideal J = // idPrepare( I, hom, iComp, &w);
426 kStd2(I, currRing->qideal, hom, &w, (bigintmat*)NULL, iComp);
427
428 idTest(J);
429
430 if (w!=NULL)
431 atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
432 // if (w!=NULL) delete w;
433
434 res->rtyp = MODUL_CMD;
435 res->data = reinterpret_cast<void *>(J);
436 return FALSE;
437}
438
439extern "C" int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions)
440{
441
442#define ADD(C,D,E) \
443 psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""), (char*)C, D, E);
444
445
446 ADD("ClearContent", FALSE, _ClearContent);
447 ADD("ClearDenominators", FALSE, _ClearDenominators);
448
449 ADD("leadcomp", FALSE, leadcomp);
450
451 ADD("SetInducedReferrence", FALSE, SetInducedReferrence);
452 ADD("GetInducedData", FALSE, GetInducedData);
453 ADD("MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
454
455 ADD("idPrepare", FALSE, idPrepare);
456
457#undef ADD
458 return MAX_TOK;
459}
Concrete implementation of enumerators over polynomials.
void atSet(idhdl root, char *name, void *data, int typ)
Definition attrib.cc:153
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition attrib.cc:132
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
This is a polynomial enumerator for simple iteration over coefficients of polynomials.
Matrices of numbers.
Definition bigintmat.h:51
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE void n_ClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &d, const coeffs r)
(inplace) Clears denominators on a collection of numbers number d is the LCM of all the coefficient d...
Definition coeffs.h:932
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:539
static FORCE_INLINE void n_ClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Computes the content and (inplace) divides it out on a collection of numbers number c is the content ...
Definition coeffs.h:925
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
const CanonicalForm & w
Definition facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
int j
Definition facHensel.cc:110
void WerrorS(const char *s)
Definition feFopen.cc:24
@ IDEAL_CMD
Definition grammar.cc:285
@ MODUL_CMD
Definition grammar.cc:288
@ VECTOR_CMD
Definition grammar.cc:293
@ NUMBER_CMD
Definition grammar.cc:289
@ POLY_CMD
Definition grammar.cc:290
@ RING_CMD
Definition grammar.cc:282
static ideal idPrepare(ideal h1, ideal h11, tHomog hom, int syzcomp, intvec **w, GbVariant alg)
Definition ideals.cc:613
ideal id_Copy(ideal h1, const ring r)
copy an ideal
#define idTest(id)
Definition ideals.h:47
intvec * ivCopy(const intvec *o)
Definition intvec.h:146
STATIC_VAR Poly * h
Definition janet.cc:971
ideal kStd2(ideal F, ideal Q, tHomog h, intvec **w, bigintmat *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
generic interface to GB/SB computations, large hilbert vectors
Definition kstd1.cc:2602
VAR omBin slists_bin
Definition lists.cc:23
#define assume(x)
Definition mod2.h:389
#define p_GetComp(p, r)
Definition monomials.h:64
slists * lists
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omStrDup(s)
#define omAllocBin(bin)
#define NULL
Definition omList.c:12
#define p_LmTest(p, r)
Definition p_polys.h:162
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
void PrintS(const char *s)
Definition reporter.cc:284
void PrintLn()
Definition reporter.cc:310
ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sgn)
Definition ring.cc:4989
int rGetISPos(const int p, const ring r)
Finds p^th IS ordering, and returns its position in r->typ[] returns -1 if something went wrong!...
Definition ring.cc:5144
BOOLEAN rSetISReference(const ring r, const ideal F, const int i, const int p)
Changes r by setting induced ordering parameters: limit and reference leading terms F belong to r,...
Definition ring.cc:5176
static int sign(int x)
Definition ring.cc:3503
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:729
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition ring.h:726
BOOLEAN id_IsModule(ideal A, const ring src)
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
sleftv * leftv
Definition structs.h:53
tHomog
Definition structs.h:31
@ isHomog
Definition structs.h:33
@ testHomog
Definition structs.h:34
static BOOLEAN GetInducedData(leftv res, leftv h)
?
Definition mod_main.cc:244
static BOOLEAN idPrepare(leftv res, leftv h)
Get raw syzygies (idPrepare)
Definition mod_main.cc:348
int SI_MOD_INIT syzextra(SModulFunctions *psModulFunctions)
Definition mod_main.cc:439
#define ADD(C, D, E)
static BOOLEAN leadcomp(leftv res, leftv h)
Get leading component.
Definition mod_main.cc:187
static void view(const intvec *v)
Definition mod_main.cc:164
static BOOLEAN _ClearDenominators(leftv res, leftv h)
wrapper around n_ClearDenominators
Definition mod_main.cc:95
static BOOLEAN SetInducedReferrence(leftv res, leftv h)
Returns old SyzCompLimit, can set new limit.
Definition mod_main.cc:300
static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
Same for Induced Schreyer ordering (ordering on components is defined by sign!)
Definition mod_main.cc:219
static BOOLEAN _ClearContent(leftv res, leftv h)
wrapper around n_ClearContent
Definition mod_main.cc:49
static void NoReturn(leftv &res)
Definition mod_main.cc:42
static number jjLONG2N(long d)
Definition mod_main.cc:159
Computation of Syzygies.
@ BIGINT_CMD
Definition tok.h:38
@ LIST_CMD
Definition tok.h:118
@ INTVEC_CMD
Definition tok.h:101
@ INT_CMD
Definition tok.h:96
@ MAX_TOK
Definition tok.h:220
#define NONE
Definition tok.h:223