source: git/dyn_modules/syzextra/mod_main.cc @ 6909cfb

spielwiese
Last change on this file since 6909cfb was 6909cfb, checked in by Yue Ren <ren@…>, 11 years ago
fix: -Wunused-variable warnings
  • Property mode set to 100644
File size: 23.9 KB
RevLine 
[383b2c8]1#include <kernel/mod2.h>
[4f7d76]2
3#include <omalloc/omalloc.h>
4
[0917a96]5#include <misc/intvec.h>
6
7#include <coeffs/coeffs.h>
8
[ff12c6]9#include <polys/PolyEnumerator.h>
10
[0917a96]11#include <polys/monomials/p_polys.h>
12#include <polys/monomials/ring.h>
13// #include <kernel/longrat.h>
[4f7d76]14#include <kernel/kstd1.h>
15
[f115489]16#include <kernel/polys.h>
17
[0917a96]18#include <kernel/syz.h>
19
[4f7d76]20#include <Singular/tok.h>
21#include <Singular/ipid.h>
22#include <Singular/lists.h>
23#include <Singular/attrib.h>
24
[0917a96]25#include <Singular/ipid.h> 
[986225e]26#include <Singular/ipshell.h> // For iiAddCproc
27
[0917a96]28// extern coeffs coeffs_BIGINT
29
[4f7d76]30#include "singularxx_defs.h"
31#include "DebugPrint.h"
32#include "myNF.h"
33
[f63b13]34#ifdef HAVE_GOOGLE_PROFILER
35#include <google/profiler.h>
36#endif // HAVE_GOOGLE_PROFILER 
37
38
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42
43
[4f7d76]44extern void pISUpdateComponents(ideal F, const intvec *const V, const int MIN, const ring r);
[0917a96]45// extern ring rCurrRingAssure_SyzComp();
[4f7d76]46extern ring rAssure_InducedSchreyerOrdering(const ring r, BOOLEAN complete, int sign);
47extern int rGetISPos(const int p, const ring r);
48
49
50USING_NAMESPACE( SINGULARXXNAME :: DEBUG )
51USING_NAMESPACE( SINGULARXXNAME :: NF )
52
53BEGIN_NAMESPACE_NONAME
54static inline void NoReturn(leftv& res)
55{
56  res->rtyp = NONE;
57  res->data = NULL;
58}
59
[ff12c6]60/// wrapper around n_ClearContent
61static BOOLEAN _ClearContent(leftv res, leftv h)
62{
63  NoReturn(res);
64
65  const char *usage = "'ClearContent' needs a (non-zero!) poly or vector argument...";
66 
67  if( h == NULL )
68  {
69    WarnS(usage);
70    return TRUE;
71  }
72
73  assume( h != NULL );
74
75  if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
76  {
77    WarnS(usage);
78    return TRUE;
79  }
80
81  assume (h->Next() == NULL);
82 
83  poly ph = reinterpret_cast<poly>(h->Data());
84 
85  if( ph == NULL )
86  {
87    WarnS(usage);
88    return TRUE;
89  }
90 
91  const ring r =  currRing;
92  assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
93
94  number n;
95
96  // experimentall (recursive enumerator treatment) of alg. ext
97  CPolyCoeffsEnumerator itr(ph);
98  n_ClearContent(itr, n, C);
99
100  res->data = n;
101  res->rtyp = NUMBER_CMD;
102
103  return FALSE;
104}
105
106/// wrapper around n_ClearDenominators
107static BOOLEAN _ClearDenominators(leftv res, leftv h)
108{
109  NoReturn(res);
110
111  const char *usage = "'ClearDenominators' needs a (non-zero!) poly or vector argument...";
112
113  if( h == NULL )
114  {
115    WarnS(usage);
116    return TRUE;
117  }
118
119  assume( h != NULL );
120
121  if( !( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD) )
122  {
123    WarnS(usage);
124    return TRUE;
125  }
126
127  assume (h->Next() == NULL);
128
129  poly ph = reinterpret_cast<poly>(h->Data());
130
131  if( ph == NULL )
132  {
133    WarnS(usage);
134    return TRUE;
135  }
136
137  const ring r =  currRing;
138  assume( r != NULL ); assume( r->cf != NULL ); const coeffs C = r->cf;
139
140  number n;
141
142  // experimentall (recursive enumerator treatment) of alg. ext.
143  CPolyCoeffsEnumerator itr(ph);
144  n_ClearDenominators(itr, n, C);
145
146  res->data = n;
147  res->rtyp = NUMBER_CMD;
148
149  return FALSE;
150}
151
152
[4f7d76]153/// try to get an optional (simple) integer argument out of h
154/// or return the default value
155static int getOptionalInteger(const leftv& h, const int _n)
156{
157  if( h!= NULL && h->Typ() == INT_CMD )
158  {
159    int n = (int)(long)(h->Data());
160
161    if( n < 0 )
162      Warn("Negative (%d) optional integer argument", n);
163
164    return (n);
165  }
166
167  return (_n); 
168}
169
[f63b13]170static BOOLEAN noop(leftv __res, leftv /*__v*/)
[4f7d76]171{
172  NoReturn(__res);
173  return FALSE;
174}
175
[f63b13]176static BOOLEAN _ProfilerStart(leftv __res, leftv h)
177{
178  NoReturn(__res);
179#ifdef HAVE_GOOGLE_PROFILER
180  if( h!= NULL && h->Typ() == STRING_CMD )
181  {
182    const char* name = (char*)(h->Data());
183    assume( name != NULL );   
184    ProfilerStart(name);
185  } else
186    WerrorS("ProfilerStart requires a string [name] argument"); 
187#else
188  WarnS("Sorry no google profiler support (undefined HAVE_GOOGLE_PROFILER)...");
189//  return TRUE; // ?
190#endif // #ifdef HAVE_GOOGLE_PROFILER
191  return FALSE;
192  (void)h;
193}
194static BOOLEAN _ProfilerStop(leftv __res, leftv /*__v*/)
195{
196  NoReturn(__res);
197#ifdef HAVE_GOOGLE_PROFILER
198  ProfilerStop();
199#else
200  WarnS("Sorry no google profiler support (undefined HAVE_GOOGLE_PROFILER)...");
201//  return TRUE; // ?
202#endif // #ifdef HAVE_GOOGLE_PROFILER
203  return FALSE;
204}
[4f7d76]205
206static inline number jjLONG2N(long d)
207{
[0917a96]208  return n_Init(d, coeffs_BIGINT);
[4f7d76]209}
210
[19764c6]211static inline void view(const intvec* v)
212{
213#ifndef NDEBUG
214  v->view();
215#else
216  // This code duplication is only due to Hannes's #ifndef NDEBUG!
217  Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", v->rows(), v->cols(), v->length());
218
219  for (int i = 0; i < v->rows(); i++)
220  {
221    Print ("Row[%3d]:", i);
222    for (int j = 0; j < v->cols(); j++)
223      Print (" %5d", (*v)[j + i * (v->cols())] );
224    PrintLn ();
225  }
226  PrintS ("}\n");
227#endif
228
229}
230
231                   
232
[4f7d76]233static BOOLEAN DetailedPrint(leftv __res, leftv h)
234{
235  NoReturn(__res);
236
237  if( h == NULL )
238  {
239    WarnS("DetailedPrint needs an argument...");
240    return TRUE;
241  }
242
243  if( h->Typ() == RING_CMD)
244  {
245    const ring r = (const ring)h->Data();
[5c0183]246    rWrite(r, TRUE);
[4f7d76]247    PrintLn();
248#ifdef RDEBUG
249    rDebugPrint(r);
250#endif
251    return FALSE;
252  }
253
254  if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD)
255  {
256    const poly p = (const poly)h->Data(); h = h->Next();
257
258    dPrint(p, currRing, currRing, getOptionalInteger(h, 3));
259
260    return FALSE;
261  }
262
263  if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD)
264  {
265    const ideal id = (const ideal)h->Data(); h = h->Next(); 
266
267    dPrint(id, currRing, currRing, getOptionalInteger(h, 3));
268   
269    return FALSE;           
270  }
271
272  if( h->Typ() == RESOLUTION_CMD )
273  {
[636c28]274    const syStrategy syzstr = reinterpret_cast<const syStrategy>(h->Data());
[4f7d76]275
276    h = h->Next();
277
278    int nTerms = getOptionalInteger(h, 1);
279
280
[636c28]281    Print("RESOLUTION_CMD(%p): ", reinterpret_cast<const void*>(syzstr)); PrintLn();
[4f7d76]282
283    const ring save = currRing;
284    const ring r = syzstr->syRing;
285    const ring rr = (r != NULL) ? r: save;
286
287
288    const int iLength = syzstr->length;
289
290    Print("int 'length': %d", iLength); PrintLn();
291    Print("int 'regularity': %d", syzstr->regularity); PrintLn();
292    Print("short 'list_length': %hd", syzstr->list_length); PrintLn();
293    Print("short 'references': %hd", syzstr->references); PrintLn();
294
295
[636c28]296#define PRINT_pINTVECTOR(s, v) Print("intvec '%10s'(%p)", #v, reinterpret_cast<const void*>((s)->v)); \
[19764c6]297if( (s)->v != NULL ){ PrintS(": "); view((s)->v); }; \
[4f7d76]298PrintLn();
299
300    PRINT_pINTVECTOR(syzstr, resolution);
301    PRINT_pINTVECTOR(syzstr, betti);
302    PRINT_pINTVECTOR(syzstr, Tl);
303    PRINT_pINTVECTOR(syzstr, cw);
304#undef PRINT_pINTVECTOR
305
306    if (r == NULL)
307      Print("ring '%10s': NULL", "syRing");
308    else 
309      if (r == currRing)
310        Print("ring '%10s': currRing", "syRing");
311      else
312        if (r != NULL && r != save)
313        {
314          Print("ring '%10s': ", "syRing");
315          rWrite(r);
316#ifdef RDEBUG
317          //              rDebugPrint(r);
318#endif
319          // rChangeCurrRing(r);
320        }           
321    PrintLn();
322
323    const SRes rP = syzstr->resPairs;
[636c28]324    Print("SRes 'resPairs': %p", reinterpret_cast<const void*>(rP)); PrintLn();
[4f7d76]325
326    if (rP != NULL)
327      for (int iLevel = 0; (iLevel < iLength) && (rP[iLevel] != NULL) && ((*syzstr->Tl)[iLevel] >= 0); iLevel++)
328      {
329        int n = 0;
330        const int iTl = (*syzstr->Tl)[iLevel];
331        for (int j = 0; (j < iTl) && ((rP[iLevel][j].lcm!=NULL) || (rP[iLevel][j].syz!=NULL)); j++)
332        {
333          if (rP[iLevel][j].isNotMinimal==NULL)
334            n++;
335        }
336        Print("minimal-resPairs-Size[1+%d]: %d", iLevel, n); PrintLn();
337      }
338
339
340    //  const ring rrr = (iLevel > 0) ? rr : save; ?
[636c28]341#define PRINT_RESOLUTION(s, v) Print("resolution '%12s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn(); \
[4f7d76]342if ((s)->v != NULL) \
343  for (int iLevel = 0; (iLevel < iLength) && ( ((s)->v)[iLevel] != NULL ); iLevel++) \
344  { \
[636c28]345    /* const ring rrr = (iLevel > 0) ? save : save; */ \
[0917a96]346    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)*/ ); \
[4f7d76]347    PrintLn(); \
348  } \
349  PrintLn();
350
351    // resolvente:
352    PRINT_RESOLUTION(syzstr, minres);
353    PRINT_RESOLUTION(syzstr, fullres);
354
[0917a96]355    assume (id_RankFreeModule (syzstr->res[1], rr) == syzstr->res[1]->rank);
[4f7d76]356
357    PRINT_RESOLUTION(syzstr, res);
358    PRINT_RESOLUTION(syzstr, orderedRes);
359#undef PRINT_RESOLUTION
360
[636c28]361#define PRINT_POINTER(s, v) Print("pointer '%17s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn();
[4f7d76]362    // 2d arrays:
363    PRINT_POINTER(syzstr, truecomponents);
364    PRINT_POINTER(syzstr, ShiftedComponents);
365    PRINT_POINTER(syzstr, backcomponents);
366    PRINT_POINTER(syzstr, Howmuch);
367    PRINT_POINTER(syzstr, Firstelem);
368    PRINT_POINTER(syzstr, elemLength);
369    PRINT_POINTER(syzstr, sev);
370
371    // arrays of intvects:
372    PRINT_POINTER(syzstr, weights);
373    PRINT_POINTER(syzstr, hilb_coeffs);
374#undef PRINT_POINTER
375
376
377    if (syzstr->fullres==NULL)
378    {
379      PrintS("resolution 'fullres': (NULL) => resolution not computed yet");
380      PrintLn();
381    } else
382    {
[636c28]383      Print("resolution 'fullres': (%p) => resolution seems to be computed already", reinterpret_cast<const void*>(syzstr->fullres));
[4f7d76]384      PrintLn();
385      dPrint(*syzstr->fullres, save, save, nTerms);
386    }
387
388
389
390
391    if (syzstr->minres==NULL)
392    {
393      PrintS("resolution 'minres': (NULL) => resolution not minimized yet");
394      PrintLn();
395    } else
396    {
[636c28]397      Print("resolution 'minres': (%p) => resolution seems to be minimized already", reinterpret_cast<const void*>(syzstr->minres));
[4f7d76]398      PrintLn();
399      dPrint(*syzstr->minres, save, save, nTerms);
400    }
401
402
403
404
405    /*
406    int ** truecomponents;
407    long** ShiftedComponents;
408    int ** backcomponents;
409    int ** Howmuch;
410    int ** Firstelem;
411    int ** elemLength;
412    unsigned long ** sev;
413
414    intvec ** weights;
415    intvec ** hilb_coeffs;
416
417    SRes resPairs;               //polynomial data for internal use only
418
419    resolvente fullres;
420    resolvente minres;
421    resolvente res;              //polynomial data for internal use only
422    resolvente orderedRes;       //polynomial data for internal use only
423*/
424
425    //            if( currRing != save ) rChangeCurrRing(save);
426  }
427
428
429  return FALSE;
430}
431
432
433
[e89ff5]434
435
436
437static BOOLEAN Tail(leftv res, leftv h)
438{
439  NoReturn(res);
440
441  if( h == NULL )
442  {
443    WarnS("Tail needs an argument...");
444    return TRUE;
445  }
446
447  assume( h != NULL );
448
449  if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD)
450  {
451    const poly p = (const poly)h->Data();
452
453    res->rtyp = h->Typ();
454
455    if( p == NULL)
456      res->data = NULL;
457    else
458      res->data = p_Copy( pNext(p), currRing );
459
460    h = h->Next(); assume (h == NULL);
461   
462    return FALSE;
463  }
464
465  if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD)
466  {
467    const ideal id = (const ideal)h->Data();
468
469    res->rtyp = h->Typ();
470
471    if( id == NULL)
472      res->data = NULL;
473    else
474    {
475      const ideal newid = idInit(IDELEMS(id),id->rank);
476      for (int i=IDELEMS(id) - 1; i >= 0; i--)
477        if( id->m[i] != NULL )
478          newid->m[i] = p_Copy(pNext(id->m[i]), currRing);
479        else
480          newid->m[i] = NULL;
481     
482      res->data = newid; 
483    }
484   
485    h = h->Next(); assume (h == NULL);
486   
487    return FALSE;
488  }
489
490  WarnS("Tail needs a single poly/vector/ideal/module argument...");
491  return TRUE;
492}
493
494
495
[4b2e47]496/// Get leading term without a module component
[4f7d76]497static BOOLEAN leadmonom(leftv res, leftv h)
498{
499  NoReturn(res);
500
501  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL))
502  {
503    const ring r = currRing;
504    const poly p = (poly)(h->Data());
505
506    poly m = NULL;
507
508    if( p != NULL )
509    {
510      assume( p != NULL );
511      assume( p_LmTest(p, r) );
512
513      m = p_LmInit(p, r);
[4b2e47]514      p_SetCoeff0(m, n_Copy(p_GetCoeff(p, r), r), r);
[4f7d76]515
516      //            if( p_GetComp(m, r) != 0 )
517      //            {
518      p_SetComp(m, 0, r);
519      p_Setm(m, r);
520      //            }
521
522      assume( p_GetComp(m, r) == 0 );
523      assume( m != NULL );
524      assume( p_LmTest(m, r) );
525    }
526
527    res->rtyp = POLY_CMD;
528    res->data = reinterpret_cast<void *>(m);
529
530    return FALSE;
531  }
532
[227b7e]533  WerrorS("`leadmonom(<poly/vector>)` expected");
[4f7d76]534  return TRUE;
535}
536
537/// Get leading component
538static BOOLEAN leadcomp(leftv res, leftv h)
539{
540  NoReturn(res);
541
[4b2e47]542  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
[4f7d76]543  {
544    const ring r = currRing;
545
546    const poly p = (poly)(h->Data());
547
[4b2e47]548    if (p != NULL )
549    {
550      assume( p != NULL );
551      assume( p_LmTest(p, r) );
[4f7d76]552
[4b2e47]553      const unsigned long iComp = p_GetComp(p, r);
[4f7d76]554
[4b2e47]555  //    assume( iComp > 0 ); // p is a vector
[4f7d76]556
[4b2e47]557      res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
558    } else
559      res->data = reinterpret_cast<void *>(jjLONG2N(0));
560     
[4f7d76]561
[4b2e47]562    res->rtyp = BIGINT_CMD;
[4f7d76]563    return FALSE;
564  }
565
[227b7e]566  WerrorS("`leadcomp(<poly/vector>)` expected");
[4f7d76]567  return TRUE;
568}
569
570
571
572
573/// Get raw leading exponent vector
574static BOOLEAN leadrawexp(leftv res, leftv h)
575{
576  NoReturn(res);
577
578  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL))
579  {
580    const ring r = currRing;
581    const poly p = (poly)(h->Data());
582
583    assume( p != NULL );
584    assume( p_LmTest(p, r) );
585
586    const int iExpSize = r->ExpL_Size;
587
[636c28]588//    intvec *iv = new intvec(iExpSize);
[4f7d76]589
590    lists l=(lists)omAllocBin(slists_bin);
591    l->Init(iExpSize);
592
593    for(int i = iExpSize-1; i >= 0; i--)
594    {
595      l->m[i].rtyp = BIGINT_CMD;
596      l->m[i].data = reinterpret_cast<void *>(jjLONG2N(p->exp[i])); // longs...
597    }
598
599    res->rtyp = LIST_CMD; // list of bigints
600    res->data = reinterpret_cast<void *>(l);
601    return FALSE;
602  }
603
[227b7e]604  WerrorS("`leadrawexp(<poly/vector>)` expected");
[4f7d76]605  return TRUE;
606}
607
608
609/// Endowe the current ring with additional (leading) Syz-component ordering
[636c28]610static BOOLEAN MakeSyzCompOrdering(leftv res, leftv /*h*/)
[4f7d76]611{
612
613  NoReturn(res);
614
615  //    res->data = rCurrRingAssure_SyzComp(); // changes current ring! :(
[0917a96]616  res->data = reinterpret_cast<void *>(rAssure_SyzComp(currRing, TRUE));
[4f7d76]617  res->rtyp = RING_CMD; // return new ring!
618  // QRING_CMD?
619
620  return FALSE;
621}
622
623
624/// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
625static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
626{
627
628  NoReturn(res);
629
630  int sign = 1;
631  if ((h!=NULL) && (h->Typ()==INT_CMD))
632  {
633    const int s = (int)((long)(h->Data()));
634
635    if( s != -1 && s != 1 )
636    {
[227b7e]637      WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
[4f7d76]638      return TRUE;
639    }
640
641    sign = s;           
642  }
643
644  assume( sign == 1 || sign == -1 );
645  res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
646  res->rtyp = RING_CMD; // return new ring!
647  // QRING_CMD?
648  return FALSE;
649}
650
651
652/// Returns old SyzCompLimit, can set new limit
653static BOOLEAN SetSyzComp(leftv res, leftv h)
654{
655  NoReturn(res);
656
657  const ring r = currRing;
658
659  if( !rIsSyzIndexRing(r) )
660  {
[227b7e]661    WerrorS("`SetSyzComp(<int>)` called on incompatible ring (not created by 'MakeSyzCompOrdering'!)");
[4f7d76]662    return TRUE;
663  }
664
665  res->rtyp = INT_CMD;
666  res->data = reinterpret_cast<void *>(rGetCurrSyzLimit(r)); // return old syz limit
667
668  if ((h!=NULL) && (h->Typ()==INT_CMD))
669  {
670    const int iSyzComp = (int)reinterpret_cast<long>(h->Data());
671    assume( iSyzComp > 0 );
[0917a96]672    rSetSyzComp(iSyzComp, currRing);
[4f7d76]673  }
674
675  return FALSE;
676}
677
678/// ?
679static BOOLEAN GetInducedData(leftv res, leftv h)
680{
681  NoReturn(res);
682
683  const ring r = currRing;
684
685  int p = 0; // which IS-block? p^th!
686
687  if ((h!=NULL) && (h->Typ()==INT_CMD))
688  {
689    p = (int)((long)(h->Data())); h=h->next;
690    assume(p >= 0);
691  }
692
693  const int pos = rGetISPos(p, r);
694
695  if( (-1 == pos) )
696  {
[227b7e]697    WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
[4f7d76]698    return TRUE;
699  }
700
701
702  const int iLimit = r->typ[pos].data.is.limit;
703  const ideal F = r->typ[pos].data.is.F;
704  ideal FF = id_Copy(F, r);
705
706  lists l=(lists)omAllocBin(slists_bin);
[f3461d]707  l->Init(2);
[4f7d76]708
709  l->m[0].rtyp = INT_CMD;
710  l->m[0].data = reinterpret_cast<void *>(iLimit);
711
712
713  //        l->m[1].rtyp = MODUL_CMD;
714
715  if( idIsModule(FF, r) )
716  {
717    l->m[1].rtyp = MODUL_CMD;
718
719    //          Print("before: %d\n", FF->nrows);
[0917a96]720    //          FF->nrows = id_RankFreeModule(FF, r); // ???
[4f7d76]721    //          Print("after: %d\n", FF->nrows);
722  }
723  else
724    l->m[1].rtyp = IDEAL_CMD;
725
[98c972]726  l->m[1].data = reinterpret_cast<void *>(FF);
727
[4f7d76]728  res->rtyp = LIST_CMD; // list of int/module
729  res->data = reinterpret_cast<void *>(l);
730
731  return FALSE;
732
733}
734
735
736/// Returns old SyzCompLimit, can set new limit
737static BOOLEAN SetInducedReferrence(leftv res, leftv h)
738{
739  NoReturn(res);
740
741  const ring r = currRing;
742
743  if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
744  {
[227b7e]745    WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
[4f7d76]746    return TRUE;
747  }
748
749  const ideal F = (ideal)h->Data(); ; // No copy!
750  h=h->next;
751
752  int rank = 0;
753
754  if ((h!=NULL) && (h->Typ()==INT_CMD))
755  {
756    rank = (int)((long)(h->Data())); h=h->next;
757    assume(rank >= 0);
758  } else
[0917a96]759    rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
[4f7d76]760
761  int p = 0; // which IS-block? p^th!
762
763  if ((h!=NULL) && (h->Typ()==INT_CMD))
764  {
765    p = (int)((long)(h->Data())); h=h->next;
766    assume(p >= 0);
767  }
768
769  const int posIS = rGetISPos(p, r);
770
771  if( (-1 == posIS) )
772  {
[227b7e]773    WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
[4f7d76]774    return TRUE;
775  }
776
777
778
779  // F & componentWeights belong to that ordering block of currRing now:
[f3461d]780  rSetISReference(r, F, rank, p); // F will be copied!
[4f7d76]781  return FALSE;
782}
783
784
[227b7e]785//    F = ISUpdateComponents( F, V, MIN );
[4f7d76]786//    // replace gen(i) -> gen(MIN + V[i-MIN]) for all i > MIN in all terms from F!
787static BOOLEAN ISUpdateComponents(leftv res, leftv h)
788{
789  NoReturn(res);
790
791  PrintS("ISUpdateComponents:.... \n");
792
793  if ((h!=NULL) && (h->Typ()==MODUL_CMD))
794  {
795    ideal F = (ideal)h->Data(); ; // No copy!
796    h=h->next;
797
798    if ((h!=NULL) && (h->Typ()==INTVEC_CMD))
799    {
800      const intvec* const V = (const intvec* const) h->Data();
801      h=h->next;
802
803      if ((h!=NULL) && (h->Typ()==INT_CMD))
804      {
805        const int MIN = (int)((long)(h->Data()));
806
807        pISUpdateComponents(F, V, MIN, currRing);
808        return FALSE;
809      }
810    }
811  }
812
[227b7e]813  WerrorS("`ISUpdateComponents(<module>, intvec, int)` expected");
[4f7d76]814  return TRUE;
815}
816
817
818/// NF using length
819static BOOLEAN reduce_syz(leftv res, leftv h)
820{
[6909cfb]821  // const ring r = currRing;
[4f7d76]822
823  if ( !( (h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) ) )
824  {
[227b7e]825    WerrorS("`reduce_syz(<poly/vector>!, <ideal/module>, <int>, [int])` expected");
[4f7d76]826    return TRUE;
827  }
828
829  res->rtyp = h->Typ();
830  const poly v = reinterpret_cast<poly>(h->Data());
831  h=h->next;
832
833  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD || h->Typ()==IDEAL_CMD ) ) )
834  {
[227b7e]835    WerrorS("`reduce_syz(<poly/vector>, <ideal/module>!, <int>, [int])` expected");
[4f7d76]836    return TRUE;
837  }
838
839  assumeStdFlag(h);
840  const ideal M = reinterpret_cast<ideal>(h->Data()); h=h->next;
841
842
843  if ( !( (h!=NULL) && (h->Typ()== INT_CMD)  ) )
844  {
[227b7e]845    WerrorS("`reduce_syz(<poly/vector>, <ideal/module>, <int>!, [int])` expected");
[4f7d76]846    return TRUE;
847  }
848
849  const int iSyzComp = (int)((long)(h->Data())); h=h->next;
850
851  int iLazyReduce = 0;
852
853  if ( ( (h!=NULL) && (h->Typ()== INT_CMD)  ) )
854    iLazyReduce = (int)((long)(h->Data())); 
855
856  res->data = (void *)kNFLength(M, currQuotient, v, iSyzComp, iLazyReduce);
857  return FALSE;
858}
859
860
861/// Get raw syzygies (idPrepare)
862static BOOLEAN idPrepare(leftv res, leftv h)
863{
864  //        extern int rGetISPos(const int p, const ring r);
865
866  const ring r = currRing;
867
868  const bool isSyz = rIsSyzIndexRing(r);
869  const int posIS = rGetISPos(0, r);
870
871
872  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
873  {
[227b7e]874    WerrorS("`idPrepare(<module>)` expected");
[4f7d76]875    return TRUE;
876  }
877
878  const ideal I = reinterpret_cast<ideal>(h->Data());
879
880  assume( I != NULL );
881  idTest(I);
882
883  int iComp = -1;
884
885  h=h->next;
886  if ( (h!=NULL) && (h->Typ()==INT_CMD) )
887  {
888    iComp = (int)((long)(h->Data()));
889  } else
890  {
[5c0183]891      if( (!isSyz) && (-1 == posIS) )
892      {
893        WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
894        return TRUE;
895      }
896
[4f7d76]897    if( isSyz )
898      iComp = rGetCurrSyzLimit(r);
899    else
[0917a96]900      iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
[4f7d76]901  }
[5c0183]902 
903  assume(iComp >= 0);
[4f7d76]904
905
906  tHomog hom=testHomog;
907  intvec *w; //  = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
908
909  //           int add_row_shift = 0;
910  //
911  //           if (w!=NULL)
912  //           {
913  //             intvec * ww = ivCopy(w);
914  //
915  //             add_row_shift = ww->min_in();
916  //
917  //             (*ww) -= add_row_shift;
918  //             
919  //             if (idTestHomModule(I, currQuotient, ww))
920  //             {
921  //               hom = isHomog;
922  //               w = ww;
923  //             }
924  //             else
925  //             {
926  //               //WarnS("wrong weights");
927  //               delete ww;
928  //               w = NULL;
929  //               hom=testHomog;
930  //             }
931  //           }
932
933
934  // computes syzygies of h1,
935  // works always in a ring with ringorder_s
936  // NOTE: rSetSyzComp(syzcomp) should better be called beforehand
937  //        ideal idPrepare (ideal  h1, tHomog hom, int syzcomp, intvec **w);
938
939  ideal J = // idPrepare( I, hom, iComp, &w);
940           kStd(I, currQuotient, hom, &w, NULL, iComp);
941
942  idTest(J);
943
944  if (w!=NULL) delete w;
945  //          if (w!=NULL)
946  //            atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
947
948  res->rtyp = MODUL_CMD;
949  res->data = reinterpret_cast<void *>(J);
950  return FALSE;
951}
[f115489]952
953/// Get raw syzygies (idPrepare)
954static BOOLEAN _p_Content(leftv res, leftv h)
955{
956  if ( !( (h!=NULL) && (h->Typ()==POLY_CMD) && (h->Data() != NULL) ) )
957  {
[227b7e]958    WerrorS("`p_Content(<poly-var>)` expected");
[f115489]959    return TRUE;
960  }
961
962
963  const poly p = reinterpret_cast<poly>(h->Data());
964
965 
966  pTest(p);  pWrite(p); PrintLn();
967
968 
969  p_Content( p, currRing);     
970
971  pTest(p);
972  pWrite(p); PrintLn();
973 
974  NoReturn(res);
[056089]975  return false;
[f115489]976}
977
[643877c]978static BOOLEAN _m2_end(leftv res, leftv h)
979{
980  int ret = 0;
981 
982  if ( (h!=NULL) && (h->Typ()!=INT_CMD) )
983  {
984    WerrorS("`m2_end([<int>])` expected");
985    return TRUE;
986  }
987  ret = (int)(long)(h->Data());
988
989  m2_end( ret );
990
991  NoReturn(res);
992  return FALSE;
993}
994
995   
996
[4f7d76]997END_NAMESPACE
998
999extern "C"
1000{
1001
1002int mod_init(SModulFunctions* psModulFunctions) 
1003{
[986225e]1004#define ADD0(A,B,C,D,E) A(B, (char*)C, D, E)
1005// #define ADD(A,B,C,D,E) ADD0(iiAddCproc, "", C, D, E)
1006  #define ADD(A,B,C,D,E) ADD0(A->iiAddCproc, B, C, D, E)
[ff12c6]1007  ADD(psModulFunctions, currPack->libname, "ClearContent", FALSE, _ClearContent);
1008  ADD(psModulFunctions, currPack->libname, "ClearDenominators", FALSE, _ClearDenominators);
1009
[986225e]1010  ADD(psModulFunctions, currPack->libname, "DetailedPrint", FALSE, DetailedPrint);
[4b2e47]1011  ADD(psModulFunctions, currPack->libname, "leadmonomial", FALSE, leadmonom);
[986225e]1012  ADD(psModulFunctions, currPack->libname, "leadcomp", FALSE, leadcomp);
1013  ADD(psModulFunctions, currPack->libname, "leadrawexp", FALSE, leadrawexp);
1014
[e89ff5]1015  ADD(psModulFunctions, currPack->libname, "Tail", FALSE, Tail);
1016
[986225e]1017  ADD(psModulFunctions, currPack->libname, "ISUpdateComponents", FALSE, ISUpdateComponents);
1018  ADD(psModulFunctions, currPack->libname, "SetInducedReferrence", FALSE, SetInducedReferrence);
1019  ADD(psModulFunctions, currPack->libname, "GetInducedData", FALSE, GetInducedData);
1020  ADD(psModulFunctions, currPack->libname, "SetSyzComp", FALSE, SetSyzComp);
1021  ADD(psModulFunctions, currPack->libname, "MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
1022  ADD(psModulFunctions, currPack->libname, "MakeSyzCompOrdering", FALSE, MakeSyzCompOrdering);
[f63b13]1023
1024  ADD(psModulFunctions, currPack->libname, "ProfilerStart", FALSE, _ProfilerStart); ADD(psModulFunctions, currPack->libname, "ProfilerStop",  FALSE, _ProfilerStop );
[4f7d76]1025 
[986225e]1026  ADD(psModulFunctions, currPack->libname, "noop", FALSE, noop);
1027  ADD(psModulFunctions, currPack->libname, "idPrepare", FALSE, idPrepare);
1028  ADD(psModulFunctions, currPack->libname, "reduce_syz", FALSE, reduce_syz);
[4f7d76]1029
[986225e]1030  ADD(psModulFunctions, currPack->libname, "p_Content", FALSE, _p_Content);
[f115489]1031
[643877c]1032  ADD(psModulFunctions, currPack->libname, "m2_end", FALSE, _m2_end);
[986225e]1033  //  ADD(psModulFunctions, currPack->libname, "", FALSE, );
1034#undef ADD 
[4f7d76]1035  return 0;
1036}
1037}
Note: See TracBrowser for help on using the repository browser.