source: git/dyn_modules/syzextra/mod_main.cc @ 1a4c343

spielwiese
Last change on this file since 1a4c343 was 1cf13b, checked in by Oleksandr Motsak <motsak@…>, 10 years ago
Traverse API redesign + avoid multiplication as far as possible add/chg: TraverseNF similar to SchreyerSyzygyNF add/chg: use TraverseTail(mult, int tail_index) everywhere add: usage of CReducerFinder::FindReducer controlled by NOPRODUCT macro define add: _p_LmDivisibleByNoComp, CReducerFinder::FindReducer for products NOTE: needs p_GetShortExpVector for 'products'
  • Property mode set to 100644
File size: 42.7 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,
855                               (syz_2!=NULL)? p_Copy(syz_2, r): syz_2, L, T, LS, attributes);
856
857  if( __DEBUG__ )
858  {
859    PrintS("SchreyerSyzygyNF::Output: ");
860
861    dPrint((poly)res->data, r, r, 2);
862  }
863
864
865  return FALSE;
866}
867
868
869
870/// proc SSReduceTerm(poly m, def t, def syzterm, def L, def T, list #)
871static BOOLEAN _ReduceTerm(leftv res, leftv h)
872{
873  const SchreyerSyzygyComputationFlags attributes(currRingHdl);
874
875  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
876//  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
877//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
878//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
879  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
880
881  const char* usage = "`ReduceTerm(<poly>, <poly/vector>, <vector/0>, <ideal/module>, <ideal/module>[,<module>])` expected";
882  const ring r = attributes.m_rBaseRing;
883
884  NoReturn(res);
885
886  if ((h==NULL) || (h->Typ() !=POLY_CMD) || (h->Data() == NULL))
887  {
888    WerrorS(usage);
889    return TRUE;   
890  }
891
892  const poly multiplier = (poly) h->Data(); assume (multiplier != NULL);
893
894 
895  h = h->Next();
896  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL))
897  {
898    WerrorS(usage);
899    return TRUE;   
900  }
901
902  const poly term4reduction = (poly) h->Data(); assume( term4reduction != NULL );
903
904 
905  poly syztermCheck = NULL;
906 
907  h = h->Next();
908  if ((h==NULL) || !((h->Typ()==VECTOR_CMD) || (h->Data() == NULL)) )
909  {
910    WerrorS(usage);
911    return TRUE;   
912  }
913
914  if(h->Typ()==VECTOR_CMD) 
915    syztermCheck = (poly) h->Data();
916
917 
918  h = h->Next();
919  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
920  {
921    WerrorS(usage);
922    return TRUE;   
923  }
924
925  const ideal L = (ideal) h->Data(); assume( IDELEMS(L) > 0 );
926
927 
928  h = h->Next();
929  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
930  {
931    WerrorS(usage);
932    return TRUE;   
933  }
934
935  const ideal T = (ideal) h->Data();
936
937  assume( IDELEMS(L) == IDELEMS(T) );
938
939  ideal LS = NULL;
940
941  h = h->Next();
942  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
943  {
944    LS = (ideal)h->Data();
945    h = h->Next();
946  }
947
948  if( __TAILREDSYZ__ )
949    assume (LS != NULL);
950
951  assume( h == NULL );
952
953  if( __DEBUG__ )
954  {
955    PrintS("ReduceTerm(m, t, syzterm, L, T, #)::Input: \n");
956
957    PrintS("m: "); dPrint(multiplier, r, r, 2);
958    PrintS("t: "); dPrint(term4reduction, r, r, 2);
959    PrintS("syzterm: "); dPrint(syztermCheck, r, r, 2);
960   
961    PrintS("L: "); dPrint(L, r, r, 0);
962    PrintS("T: "); dPrint(T, r, r, 0);
963
964    if( LS == NULL )
965      PrintS("LS: NULL\n");
966    else
967    {
968      PrintS("LS: "); dPrint(LS, r, r, 0);
969    }
970  }
971
972
973  if (__DEBUG__ && syztermCheck != NULL)
974  {
975    const int c = p_GetComp(syztermCheck, r) - 1;
976    assume( c >= 0 && c < IDELEMS(L) );
977   
978    const poly p = L->m[c];
979    assume( p != NULL ); assume( pNext(p) == NULL );   
980
981    assume( p_EqualPolys(term4reduction, p, r) ); // assume? TODO
982
983
984    poly m = leadmonom(syztermCheck, r);
985    assume( m != NULL ); assume( pNext(m) == NULL );
986
987    assume( p_EqualPolys(multiplier, m, r) ); // assume? TODO
988
989    p_Delete(&m, r);   
990   
991// NOTE:   leadmonomial(syzterm) == m &&  L[leadcomp(syzterm)] == t
992  }
993
994  res->rtyp = VECTOR_CMD;
995  res->data = ReduceTerm(multiplier, term4reduction, syztermCheck, L, T, LS, attributes);
996
997
998  if( __DEBUG__ )
999  {
1000    PrintS("ReduceTerm::Output: ");
1001
1002    dPrint((poly)res->data, r, r, 2);
1003  }
1004 
1005 
1006  return FALSE;
1007}
1008
1009
1010
1011
1012// proc SSTraverseTail(poly m, def @tail, def L, def T, list #)
1013static BOOLEAN _TraverseTail(leftv res, leftv h)
1014{
1015  const SchreyerSyzygyComputationFlags attributes(currRingHdl);
1016
1017  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
1018//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
1019//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
1020//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
1021  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
1022
1023  const char* usage = "`TraverseTail(<poly>, <poly/vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
1024  const ring r = attributes.m_rBaseRing;
1025
1026  NoReturn(res);
1027
1028  if ((h==NULL) || (h->Typ() !=POLY_CMD) || (h->Data() == NULL))
1029  {
1030    WerrorS(usage);
1031    return TRUE;   
1032  }
1033
1034  const poly multiplier = (poly) h->Data(); assume (multiplier != NULL);
1035
1036  h = h->Next();
1037  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD))
1038  {
1039    WerrorS(usage);
1040    return TRUE;   
1041  }
1042
1043  const poly tail = (poly) h->Data(); 
1044
1045  h = h->Next();
1046
1047  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
1048  {
1049    WerrorS(usage);
1050    return TRUE;   
1051  }
1052
1053  const ideal L = (ideal) h->Data();
1054
1055  assume( IDELEMS(L) > 0 );
1056
1057  h = h->Next();
1058  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
1059  {
1060    WerrorS(usage);
1061    return TRUE;   
1062  }
1063
1064  const ideal T = (ideal) h->Data();
1065
1066  assume( IDELEMS(L) == IDELEMS(T) );
1067
1068  h = h->Next();
1069 
1070  ideal LS = NULL;
1071
1072  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
1073  {
1074    LS = (ideal)h->Data();
1075    h = h->Next();
1076  }
1077
1078  if( __TAILREDSYZ__ )
1079    assume (LS != NULL);
1080
1081  assume( h == NULL );
1082
1083  if( __DEBUG__ )
1084  {
1085    PrintS("TraverseTail(m, t, L, T, #)::Input: \n");
1086
1087    PrintS("m: "); dPrint(multiplier, r, r, 2);
1088    PrintS("t: "); dPrint(tail, r, r, 10);
1089
1090    PrintS("L: "); dPrint(L, r, r, 0);
1091    PrintS("T: "); dPrint(T, r, r, 0);
1092
1093    if( LS == NULL )
1094      PrintS("LS: NULL\n");
1095    else
1096    {
1097      PrintS("LS: "); dPrint(LS, r, r, 0);
1098    }
1099  }
1100
1101  res->rtyp = VECTOR_CMD;
1102  res->data = TraverseTail(multiplier, tail, L, T, LS, attributes);
1103
1104
1105  if( __DEBUG__ )
1106  {
1107    PrintS("TraverseTail::Output: ");
1108    dPrint((poly)res->data, r, r, 2);
1109  }
1110
1111  return FALSE;
1112}
1113
1114
1115/// module (LL, TT) = SSComputeSyzygy(L, T);
1116/// Compute Syz(L ++ T) = N = LL ++ TT
1117// proc SSComputeSyzygy(def L, def T)
1118static BOOLEAN _ComputeSyzygy(leftv res, leftv h)
1119{
1120  const SchreyerSyzygyComputationFlags attributes(currRingHdl);
1121
1122  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
1123//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
1124//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
1125//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
1126//   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
1127
1128  const char* usage = "`ComputeSyzygy(<ideal/module>, <ideal/module>])` expected";
1129  const ring r = attributes.m_rBaseRing;
1130
1131  NoReturn(res);
1132
1133  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
1134  {
1135    WerrorS(usage);
1136    return TRUE;   
1137  }
1138
1139  const ideal L = (ideal) h->Data();
1140
1141  assume( IDELEMS(L) > 0 );
1142
1143  h = h->Next();
1144  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
1145  {
1146    WerrorS(usage);
1147    return TRUE;   
1148  }
1149
1150  const ideal T = (ideal) h->Data();
1151  assume( IDELEMS(L) == IDELEMS(T) );
1152
1153
1154  h = h->Next(); assume( h == NULL ); 
1155
1156  if( __DEBUG__ )
1157  {
1158    PrintS("ComputeSyzygy(L, T)::Input: \n");
1159
1160    PrintS("L: "); dPrint(L, r, r, 0);
1161    PrintS("T: "); dPrint(T, r, r, 0);
1162  }
1163
1164  ideal LL, TT;
1165
1166  ComputeSyzygy(L, T, LL, TT, attributes);
1167
1168  lists l = (lists)omAllocBin(slists_bin); l->Init(2);
1169
1170  l->m[0].rtyp = MODUL_CMD; l->m[0].data = reinterpret_cast<void *>(LL);
1171
1172  l->m[1].rtyp = MODUL_CMD; l->m[1].data = reinterpret_cast<void *>(TT);
1173 
1174  res->data = l; res->rtyp = LIST_CMD;
1175 
1176  if( __DEBUG__ )
1177  {
1178    PrintS("ComputeSyzygy::Output: ");
1179    dPrint(LL, r, r, 0);
1180    dPrint(TT, r, r, 0);
1181  }
1182
1183  return FALSE;
1184
1185}
1186
1187/// Get leading term without a module component
1188static BOOLEAN _leadmonom(leftv res, leftv h)
1189{
1190  NoReturn(res);
1191
1192  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL))
1193  {
1194    const ring r = currRing;
1195    const poly p = (poly)(h->Data());
1196
1197    res->data = reinterpret_cast<void *>(  leadmonom(p, r) );
1198    res->rtyp = POLY_CMD;
1199
1200    return FALSE;
1201  }
1202
1203  WerrorS("`leadmonom(<poly/vector>)` expected");
1204  return TRUE;
1205}
1206
1207/// Get leading component
1208static BOOLEAN leadcomp(leftv res, leftv h)
1209{
1210  NoReturn(res);
1211
1212  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
1213  {
1214    const ring r = currRing;
1215
1216    const poly p = (poly)(h->Data());
1217
1218    if (p != NULL )
1219    {
1220      assume( p != NULL );
1221      assume( p_LmTest(p, r) );
1222
1223      const unsigned long iComp = p_GetComp(p, r);
1224
1225  //    assume( iComp > 0 ); // p is a vector
1226
1227      res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
1228    } else
1229      res->data = reinterpret_cast<void *>(jjLONG2N(0));
1230     
1231
1232    res->rtyp = BIGINT_CMD;
1233    return FALSE;
1234  }
1235
1236  WerrorS("`leadcomp(<poly/vector>)` expected");
1237  return TRUE;
1238}
1239
1240
1241
1242
1243/// Get raw leading exponent vector
1244static BOOLEAN leadrawexp(leftv res, leftv h)
1245{
1246  NoReturn(res);
1247
1248  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL))
1249  {
1250    const ring r = currRing;
1251    const poly p = (poly)(h->Data());
1252
1253    assume( p != NULL );
1254    assume( p_LmTest(p, r) );
1255
1256    const int iExpSize = r->ExpL_Size;
1257
1258//    intvec *iv = new intvec(iExpSize);
1259
1260    lists l=(lists)omAllocBin(slists_bin);
1261    l->Init(iExpSize);
1262
1263    for(int i = iExpSize-1; i >= 0; i--)
1264    {
1265      l->m[i].rtyp = BIGINT_CMD;
1266      l->m[i].data = reinterpret_cast<void *>(jjLONG2N(p->exp[i])); // longs...
1267    }
1268
1269    res->rtyp = LIST_CMD; // list of bigints
1270    res->data = reinterpret_cast<void *>(l);
1271    return FALSE;
1272  }
1273
1274  WerrorS("`leadrawexp(<poly/vector>)` expected");
1275  return TRUE;
1276}
1277
1278
1279/// Endowe the current ring with additional (leading) Syz-component ordering
1280static BOOLEAN MakeSyzCompOrdering(leftv res, leftv /*h*/)
1281{
1282
1283  NoReturn(res);
1284
1285  //    res->data = rCurrRingAssure_SyzComp(); // changes current ring! :(
1286  res->data = reinterpret_cast<void *>(rAssure_SyzComp(currRing, TRUE));
1287  res->rtyp = RING_CMD; // return new ring!
1288  // QRING_CMD?
1289
1290  return FALSE;
1291}
1292
1293
1294/// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
1295static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
1296{
1297
1298  NoReturn(res);
1299
1300  int sign = 1;
1301  if ((h!=NULL) && (h->Typ()==INT_CMD))
1302  {
1303    const int s = (int)((long)(h->Data()));
1304
1305    if( s != -1 && s != 1 )
1306    {
1307      WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
1308      return TRUE;
1309    }
1310
1311    sign = s;           
1312  }
1313
1314  assume( sign == 1 || sign == -1 );
1315  res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
1316  res->rtyp = RING_CMD; // return new ring!
1317  // QRING_CMD?
1318  return FALSE;
1319}
1320
1321
1322/// Returns old SyzCompLimit, can set new limit
1323static BOOLEAN SetSyzComp(leftv res, leftv h)
1324{
1325  NoReturn(res);
1326
1327  const ring r = currRing;
1328
1329  if( !rIsSyzIndexRing(r) )
1330  {
1331    WerrorS("`SetSyzComp(<int>)` called on incompatible ring (not created by 'MakeSyzCompOrdering'!)");
1332    return TRUE;
1333  }
1334
1335  res->rtyp = INT_CMD;
1336  res->data = reinterpret_cast<void *>(rGetCurrSyzLimit(r)); // return old syz limit
1337
1338  if ((h!=NULL) && (h->Typ()==INT_CMD))
1339  {
1340    const int iSyzComp = (int)reinterpret_cast<long>(h->Data());
1341    assume( iSyzComp > 0 );
1342    rSetSyzComp(iSyzComp, currRing);
1343  }
1344
1345  return FALSE;
1346}
1347
1348/// ?
1349static BOOLEAN GetInducedData(leftv res, leftv h)
1350{
1351  NoReturn(res);
1352
1353  const ring r = currRing;
1354
1355  int p = 0; // which IS-block? p^th!
1356
1357  if ((h!=NULL) && (h->Typ()==INT_CMD))
1358  {
1359    p = (int)((long)(h->Data())); h=h->next;
1360    assume(p >= 0);
1361  }
1362
1363  const int pos = rGetISPos(p, r);
1364
1365  if(  /*(*/ -1 == pos /*)*/  )
1366  {
1367    WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
1368    return TRUE;
1369  }
1370
1371
1372  const int iLimit = r->typ[pos].data.is.limit;
1373  const ideal F = r->typ[pos].data.is.F;
1374  ideal FF = id_Copy(F, r);
1375
1376
1377 
1378  lists l=(lists)omAllocBin(slists_bin);
1379  l->Init(2);
1380
1381  l->m[0].rtyp = INT_CMD;
1382  l->m[0].data = reinterpret_cast<void *>(iLimit);
1383
1384
1385  //        l->m[1].rtyp = MODUL_CMD;
1386
1387  if( idIsModule(FF, r) )
1388  {
1389    l->m[1].rtyp = MODUL_CMD;
1390
1391    //          Print("before: %d\n", FF->nrows);
1392    //          FF->nrows = id_RankFreeModule(FF, r); // ???
1393    //          Print("after: %d\n", FF->nrows);
1394  }
1395  else
1396    l->m[1].rtyp = IDEAL_CMD;
1397
1398  l->m[1].data = reinterpret_cast<void *>(FF);
1399
1400  res->rtyp = LIST_CMD; // list of int/module
1401  res->data = reinterpret_cast<void *>(l);
1402
1403  return FALSE;
1404
1405}
1406
1407
1408/* // the following turned out to be unnecessary...   
1409/// Finds p^th AM ordering, and returns its position in r->typ[] AND
1410/// corresponding &r->wvhdl[]
1411/// returns FALSE if something went wrong!
1412/// p - starts with 0!
1413BOOLEAN rGetAMPos(const ring r, const int p, int &typ_pos, int &wvhdl_pos, const BOOLEAN bSearchWvhdl = FALSE)
1414{
1415#if MYTEST
1416  Print("rGetAMPos(p: %d...)\nF:", p);
1417  PrintLn();
1418#endif
1419  typ_pos = -1;
1420  wvhdl_pos = -1;
1421
1422  if (r->typ==NULL)
1423    return FALSE;
1424
1425
1426  int j = p; // Which IS record to use...
1427  for( int pos = 0; pos < r->OrdSize; pos++ )
1428    if( r->typ[pos].ord_typ == ro_am)
1429      if( j-- == 0 )
1430      {
1431        typ_pos = pos;
1432
1433        if( bSearchWvhdl )
1434        {
1435          const int nblocks = rBlocks(r) - 1;
1436          const int* w = r->typ[pos].data.am.weights; // ?
1437
1438          for( pos = 0; pos <= nblocks; pos ++ )
1439            if (r->order[pos] == ringorder_am)
1440              if( r->wvhdl[pos] == w )
1441              {
1442                wvhdl_pos = pos;
1443                break;
1444              }
1445          if (wvhdl_pos < 0)
1446            return FALSE;
1447
1448          assume(wvhdl_pos >= 0);
1449        }
1450        assume(typ_pos >= 0);
1451        return TRUE;
1452      }
1453
1454  return FALSE;
1455}
1456
1457// // ?
1458// static BOOLEAN GetAMData(leftv res, leftv h)
1459// {
1460//   NoReturn(res);
1461//
1462//   const ring r = currRing;
1463//
1464//   int p = 0; // which IS-block? p^th!
1465//
1466//   if ((h!=NULL) && (h->Typ()==INT_CMD))
1467//     p = (int)((long)(h->Data())); h=h->next;
1468//
1469//   assume(p >= 0);
1470//
1471//   int d, w;
1472//   
1473//   if( !rGetAMPos(r, p, d, w, TRUE) )
1474//   {
1475//     Werror("`GetAMData([int])`: no %d^th _am block-ordering!", p);
1476//     return TRUE;
1477//   }
1478//
1479//   assume( r->typ[d].ord_typ == ro_am );
1480//   assume( r->order[w] == ringorder_am );
1481//
1482//
1483//   const short start = r->typ[d].data.am.start;  // bounds of ordering (in E)
1484//   const short end = r->typ[d].data.am.end;
1485//   const short len_gen = r->typ[d].data.am.len_gen; // i>len_gen: weight(gen(i)):=0
1486//   const int *weights = r->typ[d].data.am.weights; // pointers into wvhdl field of length (end-start+1) + len_gen
1487//   // contents w_1,... w_n, len, mod_w_1, .. mod_w_len, 0
1488//
1489//   assume( weights == r->wvhdl[w] );
1490//
1491//   
1492//   lists l=(lists)omAllocBin(slists_bin);
1493//   l->Init(2);
1494//
1495//   const short V = end-start+1;
1496//   intvec* ww_vars = new intvec(V);
1497//   intvec* ww_gens = new intvec(len_gen);
1498//
1499//   for (int i = 0; i < V; i++ )
1500//     (*ww_vars)[i] = weights[i];
1501//
1502//   assume( weights[V] == len_gen );
1503//
1504//   for (int i = 0; i < len_gen; i++ )
1505//     (*ww_gens)[i] = weights[i - V - 1];
1506//   
1507//
1508//   l->m[0].rtyp = INTVEC_CMD;
1509//   l->m[0].data = reinterpret_cast<void *>(ww_vars);
1510//
1511//   l->m[1].rtyp = INTVEC_CMD;
1512//   l->m[1].data = reinterpret_cast<void *>(ww_gens);
1513//
1514//
1515//   return FALSE;
1516//
1517// }
1518*/
1519
1520/// Returns old SyzCompLimit, can set new limit
1521static BOOLEAN SetInducedReferrence(leftv res, leftv h)
1522{
1523  NoReturn(res);
1524
1525  const ring r = currRing;
1526
1527  if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
1528  {
1529    WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
1530    return TRUE;
1531  }
1532
1533  const ideal F = (ideal)h->Data(); ; // No copy!
1534  h=h->next;
1535
1536  int rank = 0;
1537
1538  if ((h!=NULL) && (h->Typ()==INT_CMD))
1539  {
1540    rank = (int)((long)(h->Data())); h=h->next;
1541    assume(rank >= 0);
1542  } else
1543    rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
1544
1545  int p = 0; // which IS-block? p^th!
1546
1547  if ((h!=NULL) && (h->Typ()==INT_CMD))
1548  {
1549    p = (int)((long)(h->Data())); h=h->next;
1550    assume(p >= 0);
1551  }
1552
1553  const int posIS = rGetISPos(p, r);
1554
1555  if(  /*(*/ -1 == posIS /*)*/  )
1556  {
1557    WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
1558    return TRUE;
1559  }
1560
1561
1562
1563  // F & componentWeights belong to that ordering block of currRing now:
1564  rSetISReference(r, F, rank, p); // F will be copied!
1565  return FALSE;
1566}
1567
1568
1569//    F = ISUpdateComponents( F, V, MIN );
1570//    // replace gen(i) -> gen(MIN + V[i-MIN]) for all i > MIN in all terms from F!
1571static BOOLEAN ISUpdateComponents(leftv res, leftv h)
1572{
1573  NoReturn(res);
1574
1575  PrintS("ISUpdateComponents:.... \n");
1576
1577  if ((h!=NULL) && (h->Typ()==MODUL_CMD))
1578  {
1579    ideal F = (ideal)h->Data(); ; // No copy!
1580    h=h->next;
1581
1582    if ((h!=NULL) && (h->Typ()==INTVEC_CMD))
1583    {
1584      const intvec* const V = (const intvec* const) h->Data();
1585      h=h->next;
1586
1587      if ((h!=NULL) && (h->Typ()==INT_CMD))
1588      {
1589        const int MIN = (int)((long)(h->Data()));
1590
1591        pISUpdateComponents(F, V, MIN, currRing);
1592        return FALSE;
1593      }
1594    }
1595  }
1596
1597  WerrorS("`ISUpdateComponents(<module>, intvec, int)` expected");
1598  return TRUE;
1599}
1600
1601
1602/// NF using length
1603static BOOLEAN reduce_syz(leftv res, leftv h)
1604{
1605  // const ring r = currRing;
1606
1607  if ( !( (h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) ) )
1608  {
1609    WerrorS("`reduce_syz(<poly/vector>!, <ideal/module>, <int>, [int])` expected");
1610    return TRUE;
1611  }
1612
1613  res->rtyp = h->Typ();
1614  const poly v = reinterpret_cast<poly>(h->Data());
1615  h=h->next;
1616
1617  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD || h->Typ()==IDEAL_CMD ) ) )
1618  {
1619    WerrorS("`reduce_syz(<poly/vector>, <ideal/module>!, <int>, [int])` expected");
1620    return TRUE;
1621  }
1622
1623  assumeStdFlag(h);
1624  const ideal M = reinterpret_cast<ideal>(h->Data()); h=h->next;
1625
1626
1627  if ( !( (h!=NULL) && (h->Typ()== INT_CMD)  ) )
1628  {
1629    WerrorS("`reduce_syz(<poly/vector>, <ideal/module>, <int>!, [int])` expected");
1630    return TRUE;
1631  }
1632
1633  const int iSyzComp = (int)((long)(h->Data())); h=h->next;
1634
1635  int iLazyReduce = 0;
1636
1637  if ( ( (h!=NULL) && (h->Typ()== INT_CMD)  ) )
1638    iLazyReduce = (int)((long)(h->Data())); 
1639
1640  res->data = (void *)kNFLength(M, currQuotient, v, iSyzComp, iLazyReduce); // NOTE: currRing :(
1641  return FALSE;
1642}
1643
1644
1645/// Get raw syzygies (idPrepare)
1646static BOOLEAN idPrepare(leftv res, leftv h)
1647{
1648  //        extern int rGetISPos(const int p, const ring r);
1649
1650  const ring r = currRing;
1651
1652  const bool isSyz = rIsSyzIndexRing(r);
1653  const int posIS = rGetISPos(0, r);
1654
1655
1656  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
1657  {
1658    WerrorS("`idPrepare(<module>)` expected");
1659    return TRUE;
1660  }
1661
1662  const ideal I = reinterpret_cast<ideal>(h->Data());
1663
1664  assume( I != NULL );
1665  idTest(I);
1666
1667  int iComp = -1;
1668
1669  h=h->next;
1670  if ( (h!=NULL) && (h->Typ()==INT_CMD) )
1671  {
1672    iComp = (int)((long)(h->Data()));
1673  } else
1674  {
1675      if( (!isSyz) && (-1 == posIS) )
1676      {
1677        WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
1678        return TRUE;
1679      }
1680
1681    if( isSyz )
1682      iComp = rGetCurrSyzLimit(r);
1683    else
1684      iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
1685  }
1686 
1687  assume(iComp >= 0);
1688
1689
1690  intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
1691  tHomog hom = testHomog;
1692
1693  //           int add_row_shift = 0;
1694  //
1695  if (w!=NULL)
1696  {
1697    w = ivCopy(w);
1698  //             add_row_shift = ww->min_in();
1699  //
1700  //             (*ww) -= add_row_shift;
1701  //             
1702  //             if (idTestHomModule(I, currQuotient, ww))
1703  //             {
1704    hom = isHomog;
1705  //               w = ww;
1706  //             }
1707  //             else
1708  //             {
1709  //               //WarnS("wrong weights");
1710  //               delete ww;
1711  //               w = NULL;
1712  //               hom=testHomog;
1713  //             }
1714  }
1715
1716
1717  // computes syzygies of h1,
1718  // works always in a ring with ringorder_s
1719  // NOTE: rSetSyzComp(syzcomp) should better be called beforehand
1720  //        ideal idPrepare (ideal  h1, tHomog hom, int syzcomp, intvec **w);
1721
1722  ideal J = // idPrepare( I, hom, iComp, &w);
1723           kStd(I, currQuotient, hom, &w, NULL, iComp);
1724
1725  idTest(J);
1726
1727  if (w!=NULL)
1728    atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
1729  //             if (w!=NULL) delete w;
1730
1731  res->rtyp = MODUL_CMD;
1732  res->data = reinterpret_cast<void *>(J);
1733  return FALSE;
1734}
1735
1736/// Get raw syzygies (idPrepare)
1737static BOOLEAN _p_Content(leftv res, leftv h)
1738{
1739  if ( !( (h!=NULL) && (h->Typ()==POLY_CMD) && (h->Data() != NULL) ) )
1740  {
1741    WerrorS("`p_Content(<poly-var>)` expected");
1742    return TRUE;
1743  }
1744
1745
1746  const poly p = reinterpret_cast<poly>(h->Data());
1747
1748 
1749  pTest(p);  pWrite(p); PrintLn();
1750
1751 
1752  p_Content( p, currRing);     
1753
1754  pTest(p);
1755  pWrite(p); PrintLn();
1756 
1757  NoReturn(res);
1758  return FALSE;
1759}
1760
1761static BOOLEAN _m2_end(leftv res, leftv h)
1762{
1763  int ret = 0;
1764 
1765  if ( (h!=NULL) && (h->Typ()!=INT_CMD) )
1766  {
1767    WerrorS("`m2_end([<int>])` expected");
1768    return TRUE;
1769  }
1770  ret = (int)(long)(h->Data());
1771
1772  m2_end( ret );
1773
1774  NoReturn(res);
1775  return FALSE;
1776}
1777
1778   
1779
1780END_NAMESPACE
1781
1782
1783int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions) 
1784{
1785#define ADD0(A,B,C,D,E) A(B, (char*)C, D, E)
1786// #define ADD(A,B,C,D,E) ADD0(iiAddCproc, "", C, D, E)
1787  #define ADD(A,B,C,D,E) ADD0(A->iiAddCproc, B, C, D, E)
1788  ADD(psModulFunctions, currPack->libname, "ClearContent", FALSE, _ClearContent);
1789  ADD(psModulFunctions, currPack->libname, "ClearDenominators", FALSE, _ClearDenominators);
1790
1791  ADD(psModulFunctions, currPack->libname, "m2_end", FALSE, _m2_end);
1792
1793  ADD(psModulFunctions, currPack->libname, "DetailedPrint", FALSE, DetailedPrint);
1794  ADD(psModulFunctions, currPack->libname, "leadmonomial", FALSE, _leadmonom);
1795  ADD(psModulFunctions, currPack->libname, "leadcomp", FALSE, leadcomp);
1796  ADD(psModulFunctions, currPack->libname, "leadrawexp", FALSE, leadrawexp);
1797
1798  ADD(psModulFunctions, currPack->libname, "ISUpdateComponents", FALSE, ISUpdateComponents);
1799  ADD(psModulFunctions, currPack->libname, "SetInducedReferrence", FALSE, SetInducedReferrence);
1800  ADD(psModulFunctions, currPack->libname, "GetInducedData", FALSE, GetInducedData);
1801  ADD(psModulFunctions, currPack->libname, "SetSyzComp", FALSE, SetSyzComp);
1802  ADD(psModulFunctions, currPack->libname, "MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
1803  ADD(psModulFunctions, currPack->libname, "MakeSyzCompOrdering", FALSE, MakeSyzCompOrdering);
1804
1805  ADD(psModulFunctions, currPack->libname, "ProfilerStart", FALSE, _ProfilerStart); ADD(psModulFunctions, currPack->libname, "ProfilerStop",  FALSE, _ProfilerStop );
1806 
1807  ADD(psModulFunctions, currPack->libname, "noop", FALSE, noop);
1808  ADD(psModulFunctions, currPack->libname, "idPrepare", FALSE, idPrepare);
1809  ADD(psModulFunctions, currPack->libname, "reduce_syz", FALSE, reduce_syz);
1810
1811  ADD(psModulFunctions, currPack->libname, "p_Content", FALSE, _p_Content);
1812
1813  ADD(psModulFunctions, currPack->libname, "Tail", FALSE, Tail);
1814 
1815  ADD(psModulFunctions, currPack->libname, "ComputeLeadingSyzygyTerms", FALSE, _ComputeLeadingSyzygyTerms);
1816  ADD(psModulFunctions, currPack->libname, "Compute2LeadingSyzygyTerms", FALSE, _Compute2LeadingSyzygyTerms);
1817 
1818  ADD(psModulFunctions, currPack->libname, "Sort_c_ds", FALSE, _Sort_c_ds);
1819  ADD(psModulFunctions, currPack->libname, "FindReducer", FALSE, _FindReducer);
1820
1821
1822  ADD(psModulFunctions, currPack->libname, "ReduceTerm", FALSE, _ReduceTerm);
1823  ADD(psModulFunctions, currPack->libname, "TraverseTail", FALSE, _TraverseTail);
1824
1825   
1826  ADD(psModulFunctions, currPack->libname, "SchreyerSyzygyNF", FALSE, _SchreyerSyzygyNF);
1827  ADD(psModulFunctions, currPack->libname, "ComputeSyzygy", FALSE, _ComputeSyzygy);
1828 
1829  //  ADD(psModulFunctions, currPack->libname, "GetAMData", FALSE, GetAMData);
1830
1831  //  ADD(psModulFunctions, currPack->libname, "", FALSE, );
1832
1833#undef ADD 
1834  return 0;
1835}
1836
1837#ifndef EMBED_PYTHON
1838extern "C" { 
1839int mod_init(SModulFunctions* psModulFunctions)
1840{ 
1841  return SI_MOD_INIT(syzextra)(psModulFunctions); 
1842}
1843}
1844#endif
Note: See TracBrowser for help on using the repository browser.