source: git/dyn_modules/syzextra/mod_main.cc @ c81423

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