# source:git/Singular/dyn_modules/gfanlib/groebnerCone.cc@9abcc6

spielwiese
Last change on this file since 9abcc6 was 9abcc6, checked in by Yue Ren <ren@…>, 10 years ago
status updated 11.03.
• Property mode set to `100644`
File size: 8.3 KB
Line
1#include <kernel/kstd1.h>
2#include <kernel/ideals.h>
3#include <Singular/ipid.h>
4
5#include <libpolys/polys/monomials/p_polys.h>
6#include <libpolys/polys/monomials/ring.h>
7#include <libpolys/polys/prCopy.h>
8
9#include <gfanlib/gfanlib.h>
10
11#include <callgfanlib_conversion.h>
12#include <groebnerCone.h>
13#include <initial.h>
14
15/***
16 * Computes the Groebner cone of a polynomial g in ring r containing w relatively.
17 * Assumes that r has a weighted ordering with weight in the said Groebner cone.
18 **/
19gfan::ZCone sloppyGroebnerCone(const poly g, const ring r, const gfan::ZVector w)
20{
21  int n = r->N;
22  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
23  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
24
25  int* expv = (int*) omAlloc((n+1)*sizeof(int));
26  p_GetExpV(g,expv,r);
28  long d = wDeg(g,r,w);
29
30  poly h=g->next;
31  for (; h && wDeg(h,r,w)==d; pIter(h))
32  {
33    p_GetExpV(h,expv,r);
35  }
36
37  for (; h; pIter(h))
38  {
39    p_GetExpV(h,expv,r);
41  }
42
43  omFreeSize(expv,(n+1)*sizeof(int));
44  return gfan::ZCone(inequalities,equations);
45}
46
47/***
48 * Computes the Groebner cone of an ideal I in ring r containing w relatively.
49 * Assumes that r has a weighted ordering with weight in the said Groebner cone.
50 **/
51gfan::ZCone sloppyGroebnerCone(const ideal I, const ring r, const gfan::ZVector w)
52{
53  int k = idSize(I);
54  gfan::ZCone zc = gfan::ZCone(r->N);
55  for (int i=0; i<k; i++)
56    zc = intersection(zc,sloppyGroebnerCone(I->m[i],r,w));
57  return zc;
58}
59
60/***
61 * Computes the Groebner cone of a polynomial g in ring r containing w relatively.
62 **/
63gfan::ZCone groebnerCone(const poly g, const ring r, const gfan::ZVector w)
64{
65  int n = r->N;
66  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
67  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
68
69  int* expv = (int*) omAlloc((n+1)*sizeof(int));
70  p_GetExpV(g,expv,r);
72  long d = wDeg(g,r,w);
73
74  for (poly h=g->next; h; pIter(h))
75  {
76    p_GetExpV(h,expv,r);
77    if (wDeg(h,r,w)<d)
79    else
81  }
82
83  omFreeSize(expv,(n+1)*sizeof(int));
84  return gfan::ZCone(inequalities,equations);
85}
86
87/***
88 * Computes the Groebner cone of an ideal I in ring r containing w relatively.
89 * Assumes that r has a weighted ordering with weight in the said Groebner cone.
90 **/
91gfan::ZCone groebnerCone(const ideal I, const ring r, const gfan::ZVector w)
92{
93  int k = idSize(I);
94  gfan::ZCone zc = gfan::ZCone(r->N);
95  for (int i=0; i<k; i++)
96    zc = intersection(zc,groebnerCone(I->m[i],r,w));
97  return zc;
98}
99
100gfan::ZCone fullGroebnerCone(const ideal &I, const ring &r)
101{
102  int n = rVar(r);
103  poly g = NULL;
104  int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
105  int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
107  gfan::ZVector tailexpw = gfan::ZVector(n);
108  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
109  for (int i=0; i<IDELEMS(I); i++)
110  {
111    g = (poly) I->m[i]; pGetExpV(g,leadexpv);
113    pIter(g);
114    while (g != NULL)
115    {
116      pGetExpV(g,tailexpv);
117      tailexpw = intStar2ZVector(n, tailexpv);
119      pIter(g);
120    }
121  }
123  omFreeSize(tailexpv,(n+1)*sizeof(int));
124  return gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
125}
126
127groebnerConeData::groebnerConeData():
128  I(NULL),
129  r(NULL),
130  c(gfan::ZCone(0)),
131  p(gfan::ZVector(0))
132{
133}
134
135groebnerConeData::groebnerConeData(const groebnerConeData &sigma):
136  I(id_Copy(sigma.getIdeal(),sigma.getRing())),
137  r(rCopy(sigma.getRing())),
138  c(gfan::ZCone(sigma.getCone())),
139  p(gfan::ZVector(sigma.getInteriorPoint()))
140{
141}
142
143groebnerConeData::groebnerConeData(const ideal &J, const ring &s, const gfan::ZCone &d, const gfan::ZVector &q):
144  I(J),
145  r(s),
146  c(d),
147  p(q)
148{
149}
150
151groebnerConeData::~groebnerConeData()
152{
153  // if (I!=NULL) id_Delete(&I,r);
154  // if (r!=NULL) rDelete(r);
155}
156
157
158groebnerConeData maximalGroebnerConeData(ideal I, const ring r)
159{
160  int n = rVar(r);
161  poly g = NULL;
162  int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
163  int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
165  gfan::ZVector tailexpw = gfan::ZVector(n);
166  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
167  for (int i=0; i<IDELEMS(I); i++)
168  {
169    g = (poly) I->m[i]; pGetExpV(g,leadexpv);
171    pIter(g);
172    while (g != NULL)
173    {
174      pGetExpV(g,tailexpv);
175      tailexpw = intStar2ZVector(n, tailexpv);
177      pIter(g);
178    }
179  }
181  omFreeSize(tailexpv,(n+1)*sizeof(int));
182  gfan::ZCone zc = gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
183  gfan::ZVector p = zc.getRelativeInteriorPoint();
184  return groebnerConeData(I,r,zc,p);
185}
186
187/***
188 * Given a general ring r with any ordering, changes the ordering to wp(-w)
189 **/
190void changeOrderingTo_wp(ring r, const gfan::ZVector w)
191{
192  omFree(r->order);
193  r->order  = (int*) omAlloc0(3*sizeof(int));
194  omFree(r->block0);
195  r->block0 = (int*) omAlloc0(3*sizeof(int));
196  omFree(r->block1);
197  r->block1 = (int*) omAlloc0(3*sizeof(int));
198  for (int i=0; r->wvhdl[i]; i++) omFree(r->wvhdl[i]);
199  omFree(r->wvhdl);
200  r->wvhdl  = (int**) omAlloc0(3*sizeof(int*));
201
202  bool ok = false;
203  r->order[0]  = ringorder_wp;
204  r->block0[0] = 1;
205  r->block1[0] = r->N;
206  r->wvhdl[0]  = ZVectorToIntStar(w,ok);
207  r->order[1]  = ringorder_C;
208  rComplete(r,1);
209}
210
211groebnerConeData::groebnerConeData(const ideal J, const ring s, const gfan::ZVector w)
212{
213  r = rCopy(s);
214  changeOrderingTo_wp(r,w);
215  rChangeCurrRing(r);
216
217  int k = idSize(J); I = idInit(k);
218  nMapFunc identityMap = n_SetMap(s->cf,r->cf);
219  for (int i=0; i<k; i++)
220    I->m[i] = p_PermPoly(J->m[i],NULL,s,r,identityMap,NULL,0);
221  intvec* nullVector = NULL;
222  I = kStd(I,currQuotient,testHomog,&nullVector);
223
224  c = sloppyGroebnerCone(I,r,w);
225  p = c.getRelativeInteriorPoint();
226}
227
228groebnerConeData::groebnerConeData(const ideal J, const ring s, const gfan::ZCone d)
229{
230  c = d;
231  p = d.getRelativeInteriorPoint();
232
233  r = rCopy(s);
234  changeOrderingTo_wp(r,p);
235  rChangeCurrRing(r);
236
237  int k = idSize(J); I = idInit(k);
238  nMapFunc identityMap = n_SetMap(s->cf,r->cf);
239  for (int i=0; i<k; i++)
240    I->m[i] = p_PermPoly(J->m[i],NULL,s,r,identityMap,NULL,0);
241  intvec* nullVector = NULL;
242  I = kStd(I,currQuotient,testHomog,&nullVector);
243}
244
245// /***
246//  * Given a general ring r with any ordering, changes the ordering to a(v),ws(-w)
247//  **/
248// bool changetoAWSRing(ring r, const gfan::ZVector v, const gfan::ZVector w)
249// {
250//   omFree(r->order);
251//   r->order  = (int*) omAlloc0(4*sizeof(int));
252//   omFree(r->block0);
253//   r->block0 = (int*) omAlloc0(4*sizeof(int));
254//   omFree(r->block1);
255//   r->block1 = (int*) omAlloc0(4*sizeof(int));
256//   for (int i=0; r->wvhdl[i]; i++)
257//   { omFree(r->wvhdl[i]); }
258//   omFree(r->wvhdl);
259//   r->wvhdl  = (int**) omAlloc0(4*sizeof(int*));
260
261//   bool ok = false;
262//   r->order[0]  = ringorder_a;
263//   r->block0[0] = 1;
264//   r->block1[0] = r->N;
265//   r->wvhdl[0]  = ZVectorToIntStar(v,ok);
266//   r->order[1]  = ringorder_ws;
267//   r->block0[1] = 1;
268//   r->block1[1] = r->N;
269//   r->wvhdl[1]  = ZVectorToIntStar(w,ok);
270//   r->order[2]  = ringorder_C;
271//   return ok;
272// }
273
274// groebnerConeData::groebnerConeData(const ideal J, const ring s, const gfan::ZVector w)
275// {
276//   r = rCopy(s);
277//   changeOrderingTo_wp(r,w);
278//   rChangeCurrRing(r);
279
280//   int k = idSize(J); I = idInit(k);
281//   nMapFunc identityMap = n_SetMap(s->cf,r->cf);
282//   for (int i=0; i<k; i++)
283//     I->m[i] = p_PermPoly(J->m[i],NULL,s,r,nMap,NULL,0);
284//   intvec* nullVector = NULL;
285//   I = kStd(I,currQuotient,testHomog,&nullVector);
286
287//   c = sloppyGroebnerCone(I,r,w);
288//   p = c.getRelativeInteriorPoint();
289// }
290
291gfan::ZFan* toFanStar(setOfGroebnerConeData setOfCones)
292{
293  if (setOfCones.size() > 0)
294  {
295    setOfGroebnerConeData::iterator cone = setOfCones.begin();
296    gfan::ZFan* zf = new gfan::ZFan(cone->getCone().ambientDimension());
297    for (; cone!=setOfCones.end(); cone++)
298      zf->insert(cone->getCone());
299    return zf;
300  }
301  else
302    return new gfan::ZFan(gfan::ZFan::fullFan(currRing->N));
303}
Note: See TracBrowser for help on using the repository browser.