My Project  UNKNOWN_GIT_VERSION
std_wrapper.cc
Go to the documentation of this file.
1 #include <vector>
2 
3 #include "Singular/libsingular.h"
4 
6 ideal gfanlib_kStd_wrapper(ideal I, ring r, tHomog h=testHomog)
7 {
8  ring origin = currRing;
9  if (origin != r)
10  rChangeCurrRing(r);
11 
12  intvec* nullVector = NULL;
13  ideal stdI = kStd(I,currRing->qideal,h,&nullVector); // there is still a memory leak here!!!
14  id_DelDiv(stdI,currRing);
15  idSkipZeroes(stdI);
16  if (nullVector!=NULL) delete nullVector;
17 
18  if (origin != r)
19  rChangeCurrRing(origin);
20 
21  return stdI;
22 }
23 
24 //------------------------------------------------------------------------
25 // routine that simplifies the new element by dividing it with the maximal possible
26 // partially saturating the ideal with respect to all variables doing so
28 {
29  BOOLEAN b = FALSE; // set b to TRUE, if spoly was changed,
30  // let it remain FALSE otherwise
31  if (strat->P.t_p==NULL)
32  {
33  poly p=strat->P.p;
34 
35  // iterate over all terms of p and
36  // compute the minimum mm of all exponent vectors
37  int *mm=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
38  int *m0=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
39  p_GetExpV(p,mm,currRing);
40  bool nonTrivialSaturationToBeDone=true;
41  for (p=pNext(p); p!=NULL; pIter(p))
42  {
43  nonTrivialSaturationToBeDone=false;
44  p_GetExpV(p,m0,currRing);
45  for (int i=gitfan_satstdSaturatingVariables.size()-1; i>=0; i--)
46  {
48  mm[li]=si_min(mm[li],m0[li]);
49  if (mm[li]>0) nonTrivialSaturationToBeDone=true;
50  }
51  // abort if the minimum is zero in each component
52  if (nonTrivialSaturationToBeDone==false) break;
53  }
54  if (nonTrivialSaturationToBeDone==true)
55  {
56  // std::cout << "simplifying!" << std::endl;
57  p=p_Copy(strat->P.p,currRing);
58  memset(&strat->P,0,sizeof(strat->P));
59  strat->P.tailRing = strat->tailRing;
60  strat->P.p=p;
61  while(p!=NULL)
62  {
63  for (int i=gitfan_satstdSaturatingVariables.size()-1; i>=0; i--)
64  {
66  p_SubExp(p,li,mm[li],currRing);
67  }
68  p_Setm(p,currRing);
69  pIter(p);
70  }
71  b = TRUE;
72  }
73  omFree(mm);
74  omFree(m0);
75  }
76  else
77  {
78  poly p=strat->P.t_p;
79 
80  // iterate over all terms of p and
81  // compute the minimum mm of all exponent vectors
82  int *mm=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
83  int *m0=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
84  p_GetExpV(p,mm,strat->tailRing);
85  bool nonTrivialSaturationToBeDone=true;
86  for (p = pNext(p); p!=NULL; pIter(p))
87  {
88  nonTrivialSaturationToBeDone=false;
89  p_GetExpV(p,m0,strat->tailRing);
90  for(int i=gitfan_satstdSaturatingVariables.size()-1; i>=0; i--)
91  {
93  mm[li]=si_min(mm[li],m0[li]);
94  if (mm[li]>0) nonTrivialSaturationToBeDone = true;
95  }
96  // abort if the minimum is zero in each component
97  if (!nonTrivialSaturationToBeDone) break;
98  }
99  if (nonTrivialSaturationToBeDone)
100  {
101  p=p_Copy(strat->P.t_p,strat->tailRing);
102  memset(&strat->P,0,sizeof(strat->P));
103  strat->P.tailRing = strat->tailRing;
104  strat->P.t_p=p;
105  while(p!=NULL)
106  {
107  for(int i=gitfan_satstdSaturatingVariables.size()-1; i>=0; i--)
108  {
110  p_SubExp(p,li,mm[li],strat->tailRing);
111  }
112  p_Setm(p,strat->tailRing);
113  pIter(p);
114  }
115  strat->P.GetP();
116  b = TRUE;
117  }
118  omFree(mm);
119  omFree(m0);
120  }
121  return b; // return TRUE if sp was changed, FALSE if not
122 }
123 
124 ideal gfanlib_satStd_wrapper(ideal I, ring r, tHomog h=testHomog)
125 {
126  ring origin = currRing;
127  if (origin != r)
128  rChangeCurrRing(r);
129 
130  int n = rVar(currRing);
131  gitfan_satstdSaturatingVariables = std::vector<int>(n);
132  for (int i=n-1; i>=0; i--)
134 
135  ideal stdI = kStd(I,currRing->qideal,h,NULL,NULL,0,0,NULL,sat_vars_sp);
136  id_DelDiv(stdI,currRing);
137  idSkipZeroes(stdI);
138 
139  if (origin != r)
140  rChangeCurrRing(origin);
141 
142  return stdI;
143 }
144 
146 {
147  BOOLEAN b = FALSE; // set b to TRUE, if spoly was changed,
148  // let it remain FALSE otherwise
149  if (strat->P.t_p==NULL)
150  {
151  poly p=strat->P.p;
152  if (pNext(p)==NULL)
153  {
154  while ((strat->Ll >= 0))
155  deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
156  return FALSE;
157  }
158  }
159  else
160  {
161  poly p=strat->P.t_p;
162  if (pNext(p)==NULL)
163  {
164  while ((strat->Ll >= 0))
165  deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
166  return FALSE;
167  }
168  }
169  return b; // return TRUE if sp was changed, FALSE if not
170 }
171 
173 {
174  ring origin = currRing;
175  if (origin != r)
176  rChangeCurrRing(r);
177 
178  ideal stdI = kStd(I,currRing->qideal,h,NULL,NULL,0,0,NULL,abort_if_monomial_sp);
179  id_DelDiv(stdI,currRing);
180  idSkipZeroes(stdI);
181 
182  if (origin != r)
183  rChangeCurrRing(origin);
184 
185  return stdI;
186 }
si_min
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
FALSE
#define FALSE
Definition: auxiliary.h:94
skStrategy
Definition: kutil.h:261
omFree
#define omFree(addr)
Definition: omAllocDecl.h:259
rChangeCurrRing
void rChangeCurrRing(ring r)
Definition: polys.cc:15
skStrategy::P
LObject P
Definition: kutil.h:292
skStrategy::L
LSet L
Definition: kutil.h:317
id_DelDiv
void id_DelDiv(ideal id, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., delete id[i], if LT(i) == coeff*mon*L...
Definition: simpleideals.cc:341
skStrategy::tailRing
ring tailRing
Definition: kutil.h:335
gfanlib_monomialabortStd_wrapper
ideal gfanlib_monomialabortStd_wrapper(ideal I, ring r, tHomog h=testHomog)
Definition: std_wrapper.cc:172
testHomog
Definition: structs.h:40
gfanlib_satStd_wrapper
ideal gfanlib_satStd_wrapper(ideal I, ring r, tHomog h=testHomog)
Definition: std_wrapper.cc:124
b
CanonicalForm b
Definition: cfModGcd.cc:4044
p_SubExp
static long p_SubExp(poly p, int v, long ee, ring r)
Definition: p_polys.h:602
tHomog
tHomog
Definition: structs.h:36
p_Copy
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:798
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
rVar
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:581
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
abort_if_monomial_sp
static BOOLEAN abort_if_monomial_sp(kStrategy strat)
Definition: std_wrapper.cc:145
idSkipZeroes
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
Definition: simpleideals.cc:171
h
static Poly * h
Definition: janet.cc:972
intvec
Definition: intvec.h:16
pIter
#define pIter(p)
Definition: monomials.h:35
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:208
gfanlib_kStd_wrapper
ideal gfanlib_kStd_wrapper(ideal I, ring r, tHomog h=testHomog)
Definition: std_wrapper.cc:6
p_GetExpV
static void p_GetExpV(poly p, int *ev, const ring r)
Definition: p_polys.h:1439
sat_vars_sp
static BOOLEAN sat_vars_sp(kStrategy strat)
Definition: std_wrapper.cc:27
skStrategy::Ll
int Ll
Definition: kutil.h:343
libsingular.h
NULL
#define NULL
Definition: omList.c:9
p_Setm
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:225
p
int p
Definition: cfModGcd.cc:4019
deleteInL
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1175
kStd
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2086
pNext
#define pNext(p)
Definition: monomials.h:34
gitfan_satstdSaturatingVariables
std::vector< int > gitfan_satstdSaturatingVariables
Definition: std_wrapper.cc:5