source: git/dyn_modules/syzextra/mod_main.cc @ 59f97c

spielwiese
Last change on this file since 59f97c was 084393, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
Added DebugPrinting for numbers Note/Update: StringUpdate => StringEnd
  • Property mode set to 100644
File size: 24.3 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() == NUMBER_CMD)
252  {
253    number n = (number)h->Data(); 
254
255    const ring r = currRing;
256
257#ifdef LDEBUG
258    r->cf->cfDBTest(n,__FILE__,__LINE__,r->cf);
259#endif
260
261    StringSetS("");
262    n_Write(n, r->cf);
263    PrintS(StringEndS());
264    PrintLn();
265
266    return FALSE;
267  }
268 
269  if( h->Typ() == RING_CMD)
270  {
271    const ring r = (const ring)h->Data();
272    rWrite(r, TRUE);
273    PrintLn();
274#ifdef RDEBUG
275    rDebugPrint(r);
276#endif
277    return FALSE;
278  }
279
280  if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD)
281  {
282    const poly p = (const poly)h->Data(); h = h->Next();
283
284    dPrint(p, currRing, currRing, getOptionalInteger(h, 3));
285
286    return FALSE;
287  }
288
289  if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD)
290  {
291    const ideal id = (const ideal)h->Data(); h = h->Next(); 
292
293    dPrint(id, currRing, currRing, getOptionalInteger(h, 3));
294   
295    return FALSE;           
296  }
297
298  if( h->Typ() == RESOLUTION_CMD )
299  {
300    const syStrategy syzstr = reinterpret_cast<const syStrategy>(h->Data());
301
302    h = h->Next();
303
304    int nTerms = getOptionalInteger(h, 1);
305
306
307    Print("RESOLUTION_CMD(%p): ", reinterpret_cast<const void*>(syzstr)); PrintLn();
308
309    const ring save = currRing;
310    const ring r = syzstr->syRing;
311    const ring rr = (r != NULL) ? r: save;
312
313
314    const int iLength = syzstr->length;
315
316    Print("int 'length': %d", iLength); PrintLn();
317    Print("int 'regularity': %d", syzstr->regularity); PrintLn();
318    Print("short 'list_length': %hd", syzstr->list_length); PrintLn();
319    Print("short 'references': %hd", syzstr->references); PrintLn();
320
321
322#define PRINT_pINTVECTOR(s, v) Print("intvec '%10s'(%p)", #v, reinterpret_cast<const void*>((s)->v)); \
323if( (s)->v != NULL ){ PrintS(": "); view((s)->v); }; \
324PrintLn();
325
326    PRINT_pINTVECTOR(syzstr, resolution);
327    PRINT_pINTVECTOR(syzstr, betti);
328    PRINT_pINTVECTOR(syzstr, Tl);
329    PRINT_pINTVECTOR(syzstr, cw);
330#undef PRINT_pINTVECTOR
331
332    if (r == NULL)
333      Print("ring '%10s': NULL", "syRing");
334    else 
335      if (r == currRing)
336        Print("ring '%10s': currRing", "syRing");
337      else
338        if (r != NULL && r != save)
339        {
340          Print("ring '%10s': ", "syRing");
341          rWrite(r);
342#ifdef RDEBUG
343          //              rDebugPrint(r);
344#endif
345          // rChangeCurrRing(r);
346        }           
347    PrintLn();
348
349    const SRes rP = syzstr->resPairs;
350    Print("SRes 'resPairs': %p", reinterpret_cast<const void*>(rP)); PrintLn();
351
352    if (rP != NULL)
353      for (int iLevel = 0; (iLevel < iLength) && (rP[iLevel] != NULL) && ((*syzstr->Tl)[iLevel] >= 0); iLevel++)
354      {
355        int n = 0;
356        const int iTl = (*syzstr->Tl)[iLevel];
357        for (int j = 0; (j < iTl) && ((rP[iLevel][j].lcm!=NULL) || (rP[iLevel][j].syz!=NULL)); j++)
358        {
359          if (rP[iLevel][j].isNotMinimal==NULL)
360            n++;
361        }
362        Print("minimal-resPairs-Size[1+%d]: %d", iLevel, n); PrintLn();
363      }
364
365
366    //  const ring rrr = (iLevel > 0) ? rr : save; ?
367#define PRINT_RESOLUTION(s, v) Print("resolution '%12s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn(); \
368if ((s)->v != NULL) \
369  for (int iLevel = 0; (iLevel < iLength) && ( ((s)->v)[iLevel] != NULL ); iLevel++) \
370  { \
371    /* const ring rrr = (iLevel > 0) ? save : save; */ \
372    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)*/ ); \
373    PrintLn(); \
374  } \
375  PrintLn();
376
377    // resolvente:
378    PRINT_RESOLUTION(syzstr, minres);
379    PRINT_RESOLUTION(syzstr, fullres);
380
381    assume (id_RankFreeModule (syzstr->res[1], rr) == syzstr->res[1]->rank);
382
383    PRINT_RESOLUTION(syzstr, res);
384    PRINT_RESOLUTION(syzstr, orderedRes);
385#undef PRINT_RESOLUTION
386
387#define PRINT_POINTER(s, v) Print("pointer '%17s': %p", #v, reinterpret_cast<const void*>((s)->v)); PrintLn();
388    // 2d arrays:
389    PRINT_POINTER(syzstr, truecomponents);
390    PRINT_POINTER(syzstr, ShiftedComponents);
391    PRINT_POINTER(syzstr, backcomponents);
392    PRINT_POINTER(syzstr, Howmuch);
393    PRINT_POINTER(syzstr, Firstelem);
394    PRINT_POINTER(syzstr, elemLength);
395    PRINT_POINTER(syzstr, sev);
396
397    // arrays of intvects:
398    PRINT_POINTER(syzstr, weights);
399    PRINT_POINTER(syzstr, hilb_coeffs);
400#undef PRINT_POINTER
401
402
403    if (syzstr->fullres==NULL)
404    {
405      PrintS("resolution 'fullres': (NULL) => resolution not computed yet");
406      PrintLn();
407    } else
408    {
409      Print("resolution 'fullres': (%p) => resolution seems to be computed already", reinterpret_cast<const void*>(syzstr->fullres));
410      PrintLn();
411      dPrint(*syzstr->fullres, save, save, nTerms);
412    }
413
414
415
416
417    if (syzstr->minres==NULL)
418    {
419      PrintS("resolution 'minres': (NULL) => resolution not minimized yet");
420      PrintLn();
421    } else
422    {
423      Print("resolution 'minres': (%p) => resolution seems to be minimized already", reinterpret_cast<const void*>(syzstr->minres));
424      PrintLn();
425      dPrint(*syzstr->minres, save, save, nTerms);
426    }
427
428
429
430
431    /*
432    int ** truecomponents;
433    long** ShiftedComponents;
434    int ** backcomponents;
435    int ** Howmuch;
436    int ** Firstelem;
437    int ** elemLength;
438    unsigned long ** sev;
439
440    intvec ** weights;
441    intvec ** hilb_coeffs;
442
443    SRes resPairs;               //polynomial data for internal use only
444
445    resolvente fullres;
446    resolvente minres;
447    resolvente res;              //polynomial data for internal use only
448    resolvente orderedRes;       //polynomial data for internal use only
449*/
450
451    //            if( currRing != save ) rChangeCurrRing(save);
452  }
453
454
455  return FALSE;
456}
457
458
459
460
461
462
463static BOOLEAN Tail(leftv res, leftv h)
464{
465  NoReturn(res);
466
467  if( h == NULL )
468  {
469    WarnS("Tail needs an argument...");
470    return TRUE;
471  }
472
473  assume( h != NULL );
474
475  if( h->Typ() == POLY_CMD || h->Typ() == VECTOR_CMD)
476  {
477    const poly p = (const poly)h->Data();
478
479    res->rtyp = h->Typ();
480
481    if( p == NULL)
482      res->data = NULL;
483    else
484      res->data = p_Copy( pNext(p), currRing );
485
486    h = h->Next(); assume (h == NULL);
487   
488    return FALSE;
489  }
490
491  if( h->Typ() == IDEAL_CMD || h->Typ() == MODUL_CMD)
492  {
493    const ideal id = (const ideal)h->Data();
494
495    res->rtyp = h->Typ();
496
497    if( id == NULL)
498      res->data = NULL;
499    else
500    {
501      const ideal newid = idInit(IDELEMS(id),id->rank);
502      for (int i=IDELEMS(id) - 1; i >= 0; i--)
503        if( id->m[i] != NULL )
504          newid->m[i] = p_Copy(pNext(id->m[i]), currRing);
505        else
506          newid->m[i] = NULL;
507     
508      res->data = newid; 
509    }
510   
511    h = h->Next(); assume (h == NULL);
512   
513    return FALSE;
514  }
515
516  WarnS("Tail needs a single poly/vector/ideal/module argument...");
517  return TRUE;
518}
519
520
521
522/// Get leading term without a module component
523static BOOLEAN leadmonom(leftv res, leftv h)
524{
525  NoReturn(res);
526
527  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL))
528  {
529    const ring r = currRing;
530    const poly p = (poly)(h->Data());
531
532    poly m = NULL;
533
534    if( p != NULL )
535    {
536      assume( p != NULL );
537      assume( p_LmTest(p, r) );
538
539      m = p_LmInit(p, r);
540      p_SetCoeff0(m, n_Copy(p_GetCoeff(p, r), r), r);
541
542      //            if( p_GetComp(m, r) != 0 )
543      //            {
544      p_SetComp(m, 0, r);
545      p_Setm(m, r);
546      //            }
547
548      assume( p_GetComp(m, r) == 0 );
549      assume( m != NULL );
550      assume( p_LmTest(m, r) );
551    }
552
553    res->rtyp = POLY_CMD;
554    res->data = reinterpret_cast<void *>(m);
555
556    return FALSE;
557  }
558
559  WerrorS("`leadmonom(<poly/vector>)` expected");
560  return TRUE;
561}
562
563/// Get leading component
564static BOOLEAN leadcomp(leftv res, leftv h)
565{
566  NoReturn(res);
567
568  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD))
569  {
570    const ring r = currRing;
571
572    const poly p = (poly)(h->Data());
573
574    if (p != NULL )
575    {
576      assume( p != NULL );
577      assume( p_LmTest(p, r) );
578
579      const unsigned long iComp = p_GetComp(p, r);
580
581  //    assume( iComp > 0 ); // p is a vector
582
583      res->data = reinterpret_cast<void *>(jjLONG2N(iComp));
584    } else
585      res->data = reinterpret_cast<void *>(jjLONG2N(0));
586     
587
588    res->rtyp = BIGINT_CMD;
589    return FALSE;
590  }
591
592  WerrorS("`leadcomp(<poly/vector>)` expected");
593  return TRUE;
594}
595
596
597
598
599/// Get raw leading exponent vector
600static BOOLEAN leadrawexp(leftv res, leftv h)
601{
602  NoReturn(res);
603
604  if ((h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) && (h->Data() != NULL))
605  {
606    const ring r = currRing;
607    const poly p = (poly)(h->Data());
608
609    assume( p != NULL );
610    assume( p_LmTest(p, r) );
611
612    const int iExpSize = r->ExpL_Size;
613
614//    intvec *iv = new intvec(iExpSize);
615
616    lists l=(lists)omAllocBin(slists_bin);
617    l->Init(iExpSize);
618
619    for(int i = iExpSize-1; i >= 0; i--)
620    {
621      l->m[i].rtyp = BIGINT_CMD;
622      l->m[i].data = reinterpret_cast<void *>(jjLONG2N(p->exp[i])); // longs...
623    }
624
625    res->rtyp = LIST_CMD; // list of bigints
626    res->data = reinterpret_cast<void *>(l);
627    return FALSE;
628  }
629
630  WerrorS("`leadrawexp(<poly/vector>)` expected");
631  return TRUE;
632}
633
634
635/// Endowe the current ring with additional (leading) Syz-component ordering
636static BOOLEAN MakeSyzCompOrdering(leftv res, leftv /*h*/)
637{
638
639  NoReturn(res);
640
641  //    res->data = rCurrRingAssure_SyzComp(); // changes current ring! :(
642  res->data = reinterpret_cast<void *>(rAssure_SyzComp(currRing, TRUE));
643  res->rtyp = RING_CMD; // return new ring!
644  // QRING_CMD?
645
646  return FALSE;
647}
648
649
650/// Same for Induced Schreyer ordering (ordering on components is defined by sign!)
651static BOOLEAN MakeInducedSchreyerOrdering(leftv res, leftv h)
652{
653
654  NoReturn(res);
655
656  int sign = 1;
657  if ((h!=NULL) && (h->Typ()==INT_CMD))
658  {
659    const int s = (int)((long)(h->Data()));
660
661    if( s != -1 && s != 1 )
662    {
663      WerrorS("`MakeInducedSchreyerOrdering(<int>)` called with wrong integer argument (must be +-1)!");
664      return TRUE;
665    }
666
667    sign = s;           
668  }
669
670  assume( sign == 1 || sign == -1 );
671  res->data = reinterpret_cast<void *>(rAssure_InducedSchreyerOrdering(currRing, TRUE, sign));
672  res->rtyp = RING_CMD; // return new ring!
673  // QRING_CMD?
674  return FALSE;
675}
676
677
678/// Returns old SyzCompLimit, can set new limit
679static BOOLEAN SetSyzComp(leftv res, leftv h)
680{
681  NoReturn(res);
682
683  const ring r = currRing;
684
685  if( !rIsSyzIndexRing(r) )
686  {
687    WerrorS("`SetSyzComp(<int>)` called on incompatible ring (not created by 'MakeSyzCompOrdering'!)");
688    return TRUE;
689  }
690
691  res->rtyp = INT_CMD;
692  res->data = reinterpret_cast<void *>(rGetCurrSyzLimit(r)); // return old syz limit
693
694  if ((h!=NULL) && (h->Typ()==INT_CMD))
695  {
696    const int iSyzComp = (int)reinterpret_cast<long>(h->Data());
697    assume( iSyzComp > 0 );
698    rSetSyzComp(iSyzComp, currRing);
699  }
700
701  return FALSE;
702}
703
704/// ?
705static BOOLEAN GetInducedData(leftv res, leftv h)
706{
707  NoReturn(res);
708
709  const ring r = currRing;
710
711  int p = 0; // which IS-block? p^th!
712
713  if ((h!=NULL) && (h->Typ()==INT_CMD))
714  {
715    p = (int)((long)(h->Data())); h=h->next;
716    assume(p >= 0);
717  }
718
719  const int pos = rGetISPos(p, r);
720
721  if(  /*(*/ -1 == pos /*)*/  )
722  {
723    WerrorS("`GetInducedData([int])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
724    return TRUE;
725  }
726
727
728  const int iLimit = r->typ[pos].data.is.limit;
729  const ideal F = r->typ[pos].data.is.F;
730  ideal FF = id_Copy(F, r);
731
732  lists l=(lists)omAllocBin(slists_bin);
733  l->Init(2);
734
735  l->m[0].rtyp = INT_CMD;
736  l->m[0].data = reinterpret_cast<void *>(iLimit);
737
738
739  //        l->m[1].rtyp = MODUL_CMD;
740
741  if( idIsModule(FF, r) )
742  {
743    l->m[1].rtyp = MODUL_CMD;
744
745    //          Print("before: %d\n", FF->nrows);
746    //          FF->nrows = id_RankFreeModule(FF, r); // ???
747    //          Print("after: %d\n", FF->nrows);
748  }
749  else
750    l->m[1].rtyp = IDEAL_CMD;
751
752  l->m[1].data = reinterpret_cast<void *>(FF);
753
754  res->rtyp = LIST_CMD; // list of int/module
755  res->data = reinterpret_cast<void *>(l);
756
757  return FALSE;
758
759}
760
761
762/// Returns old SyzCompLimit, can set new limit
763static BOOLEAN SetInducedReferrence(leftv res, leftv h)
764{
765  NoReturn(res);
766
767  const ring r = currRing;
768
769  if( !( (h!=NULL) && ( (h->Typ()==IDEAL_CMD) || (h->Typ()==MODUL_CMD))) )
770  {
771    WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` expected");
772    return TRUE;
773  }
774
775  const ideal F = (ideal)h->Data(); ; // No copy!
776  h=h->next;
777
778  int rank = 0;
779
780  if ((h!=NULL) && (h->Typ()==INT_CMD))
781  {
782    rank = (int)((long)(h->Data())); h=h->next;
783    assume(rank >= 0);
784  } else
785    rank = id_RankFreeModule(F, r); // Starting syz-comp (1st: i+1)
786
787  int p = 0; // which IS-block? p^th!
788
789  if ((h!=NULL) && (h->Typ()==INT_CMD))
790  {
791    p = (int)((long)(h->Data())); h=h->next;
792    assume(p >= 0);
793  }
794
795  const int posIS = rGetISPos(p, r);
796
797  if(  /*(*/ -1 == posIS /*)*/  )
798  {
799    WerrorS("`SetInducedReferrence(<ideal/module>, [int[, int]])` called on incompatible ring (not created by 'MakeInducedSchreyerOrdering'!)");
800    return TRUE;
801  }
802
803
804
805  // F & componentWeights belong to that ordering block of currRing now:
806  rSetISReference(r, F, rank, p); // F will be copied!
807  return FALSE;
808}
809
810
811//    F = ISUpdateComponents( F, V, MIN );
812//    // replace gen(i) -> gen(MIN + V[i-MIN]) for all i > MIN in all terms from F!
813static BOOLEAN ISUpdateComponents(leftv res, leftv h)
814{
815  NoReturn(res);
816
817  PrintS("ISUpdateComponents:.... \n");
818
819  if ((h!=NULL) && (h->Typ()==MODUL_CMD))
820  {
821    ideal F = (ideal)h->Data(); ; // No copy!
822    h=h->next;
823
824    if ((h!=NULL) && (h->Typ()==INTVEC_CMD))
825    {
826      const intvec* const V = (const intvec* const) h->Data();
827      h=h->next;
828
829      if ((h!=NULL) && (h->Typ()==INT_CMD))
830      {
831        const int MIN = (int)((long)(h->Data()));
832
833        pISUpdateComponents(F, V, MIN, currRing);
834        return FALSE;
835      }
836    }
837  }
838
839  WerrorS("`ISUpdateComponents(<module>, intvec, int)` expected");
840  return TRUE;
841}
842
843
844/// NF using length
845static BOOLEAN reduce_syz(leftv res, leftv h)
846{
847  // const ring r = currRing;
848
849  if ( !( (h!=NULL) && (h->Typ()==VECTOR_CMD || h->Typ()==POLY_CMD) ) )
850  {
851    WerrorS("`reduce_syz(<poly/vector>!, <ideal/module>, <int>, [int])` expected");
852    return TRUE;
853  }
854
855  res->rtyp = h->Typ();
856  const poly v = reinterpret_cast<poly>(h->Data());
857  h=h->next;
858
859  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD || h->Typ()==IDEAL_CMD ) ) )
860  {
861    WerrorS("`reduce_syz(<poly/vector>, <ideal/module>!, <int>, [int])` expected");
862    return TRUE;
863  }
864
865  assumeStdFlag(h);
866  const ideal M = reinterpret_cast<ideal>(h->Data()); h=h->next;
867
868
869  if ( !( (h!=NULL) && (h->Typ()== INT_CMD)  ) )
870  {
871    WerrorS("`reduce_syz(<poly/vector>, <ideal/module>, <int>!, [int])` expected");
872    return TRUE;
873  }
874
875  const int iSyzComp = (int)((long)(h->Data())); h=h->next;
876
877  int iLazyReduce = 0;
878
879  if ( ( (h!=NULL) && (h->Typ()== INT_CMD)  ) )
880    iLazyReduce = (int)((long)(h->Data())); 
881
882  res->data = (void *)kNFLength(M, currQuotient, v, iSyzComp, iLazyReduce);
883  return FALSE;
884}
885
886
887/// Get raw syzygies (idPrepare)
888static BOOLEAN idPrepare(leftv res, leftv h)
889{
890  //        extern int rGetISPos(const int p, const ring r);
891
892  const ring r = currRing;
893
894  const bool isSyz = rIsSyzIndexRing(r);
895  const int posIS = rGetISPos(0, r);
896
897
898  if ( !( (h!=NULL) && (h->Typ()==MODUL_CMD) && (h->Data() != NULL) ) )
899  {
900    WerrorS("`idPrepare(<module>)` expected");
901    return TRUE;
902  }
903
904  const ideal I = reinterpret_cast<ideal>(h->Data());
905
906  assume( I != NULL );
907  idTest(I);
908
909  int iComp = -1;
910
911  h=h->next;
912  if ( (h!=NULL) && (h->Typ()==INT_CMD) )
913  {
914    iComp = (int)((long)(h->Data()));
915  } else
916  {
917      if( (!isSyz) && (-1 == posIS) )
918      {
919        WerrorS("`idPrepare(<...>)` called on incompatible ring (not created by 'MakeSyzCompOrdering' or 'MakeInducedSchreyerOrdering'!)");
920        return TRUE;
921      }
922
923    if( isSyz )
924      iComp = rGetCurrSyzLimit(r);
925    else
926      iComp = id_RankFreeModule(r->typ[posIS].data.is.F, r); // ;
927  }
928 
929  assume(iComp >= 0);
930
931
932  intvec* w = reinterpret_cast<intvec *>(atGet(h, "isHomog", INTVEC_CMD));
933  tHomog hom = testHomog;
934
935  //           int add_row_shift = 0;
936  //
937  if (w!=NULL)
938  {
939    w = ivCopy(w);
940  //             add_row_shift = ww->min_in();
941  //
942  //             (*ww) -= add_row_shift;
943  //             
944  //             if (idTestHomModule(I, currQuotient, ww))
945  //             {
946    hom = isHomog;
947  //               w = ww;
948  //             }
949  //             else
950  //             {
951  //               //WarnS("wrong weights");
952  //               delete ww;
953  //               w = NULL;
954  //               hom=testHomog;
955  //             }
956  }
957
958
959  // computes syzygies of h1,
960  // works always in a ring with ringorder_s
961  // NOTE: rSetSyzComp(syzcomp) should better be called beforehand
962  //        ideal idPrepare (ideal  h1, tHomog hom, int syzcomp, intvec **w);
963
964  ideal J = // idPrepare( I, hom, iComp, &w);
965           kStd(I, currQuotient, hom, &w, NULL, iComp);
966
967  idTest(J);
968
969  if (w!=NULL)
970    atSet(res, omStrDup("isHomog"), w, INTVEC_CMD);
971  //             if (w!=NULL) delete w;
972
973  res->rtyp = MODUL_CMD;
974  res->data = reinterpret_cast<void *>(J);
975  return FALSE;
976}
977
978/// Get raw syzygies (idPrepare)
979static BOOLEAN _p_Content(leftv res, leftv h)
980{
981  if ( !( (h!=NULL) && (h->Typ()==POLY_CMD) && (h->Data() != NULL) ) )
982  {
983    WerrorS("`p_Content(<poly-var>)` expected");
984    return TRUE;
985  }
986
987
988  const poly p = reinterpret_cast<poly>(h->Data());
989
990 
991  pTest(p);  pWrite(p); PrintLn();
992
993 
994  p_Content( p, currRing);     
995
996  pTest(p);
997  pWrite(p); PrintLn();
998 
999  NoReturn(res);
1000  return false;
1001}
1002
1003static BOOLEAN _m2_end(leftv res, leftv h)
1004{
1005  int ret = 0;
1006 
1007  if ( (h!=NULL) && (h->Typ()!=INT_CMD) )
1008  {
1009    WerrorS("`m2_end([<int>])` expected");
1010    return TRUE;
1011  }
1012  ret = (int)(long)(h->Data());
1013
1014  m2_end( ret );
1015
1016  NoReturn(res);
1017  return FALSE;
1018}
1019
1020   
1021
1022END_NAMESPACE
1023
1024
1025int SI_MOD_INIT(syzextra)(SModulFunctions* psModulFunctions) 
1026{
1027#define ADD0(A,B,C,D,E) A(B, (char*)C, D, E)
1028// #define ADD(A,B,C,D,E) ADD0(iiAddCproc, "", C, D, E)
1029  #define ADD(A,B,C,D,E) ADD0(A->iiAddCproc, B, C, D, E)
1030  ADD(psModulFunctions, currPack->libname, "ClearContent", FALSE, _ClearContent);
1031  ADD(psModulFunctions, currPack->libname, "ClearDenominators", FALSE, _ClearDenominators);
1032
1033  ADD(psModulFunctions, currPack->libname, "DetailedPrint", FALSE, DetailedPrint);
1034  ADD(psModulFunctions, currPack->libname, "leadmonomial", FALSE, leadmonom);
1035  ADD(psModulFunctions, currPack->libname, "leadcomp", FALSE, leadcomp);
1036  ADD(psModulFunctions, currPack->libname, "leadrawexp", FALSE, leadrawexp);
1037
1038  ADD(psModulFunctions, currPack->libname, "Tail", FALSE, Tail);
1039
1040  ADD(psModulFunctions, currPack->libname, "ISUpdateComponents", FALSE, ISUpdateComponents);
1041  ADD(psModulFunctions, currPack->libname, "SetInducedReferrence", FALSE, SetInducedReferrence);
1042  ADD(psModulFunctions, currPack->libname, "GetInducedData", FALSE, GetInducedData);
1043  ADD(psModulFunctions, currPack->libname, "SetSyzComp", FALSE, SetSyzComp);
1044  ADD(psModulFunctions, currPack->libname, "MakeInducedSchreyerOrdering", FALSE, MakeInducedSchreyerOrdering);
1045  ADD(psModulFunctions, currPack->libname, "MakeSyzCompOrdering", FALSE, MakeSyzCompOrdering);
1046
1047  ADD(psModulFunctions, currPack->libname, "ProfilerStart", FALSE, _ProfilerStart); ADD(psModulFunctions, currPack->libname, "ProfilerStop",  FALSE, _ProfilerStop );
1048 
1049  ADD(psModulFunctions, currPack->libname, "noop", FALSE, noop);
1050  ADD(psModulFunctions, currPack->libname, "idPrepare", FALSE, idPrepare);
1051  ADD(psModulFunctions, currPack->libname, "reduce_syz", FALSE, reduce_syz);
1052
1053  ADD(psModulFunctions, currPack->libname, "p_Content", FALSE, _p_Content);
1054
1055  ADD(psModulFunctions, currPack->libname, "m2_end", FALSE, _m2_end);
1056  //  ADD(psModulFunctions, currPack->libname, "", FALSE, );
1057#undef ADD 
1058  return 0;
1059}
1060
1061#ifndef EMBED_PYTHON
1062extern "C" { 
1063int mod_init(SModulFunctions* psModulFunctions)
1064{ 
1065  return SI_MOD_INIT(syzextra)(psModulFunctions); 
1066}
1067}
1068#endif
Note: See TracBrowser for help on using the repository browser.