source: git/dyn_modules/syzextra/mod_main.cc @ 9f7665

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