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