source: git/Singular/dyn_modules/gfanlib/groebnerCone.cc @ c89014

spielwiese
Last change on this file since c89014 was c89014, checked in by Yue Ren <ren@…>, 10 years ago
status update 28.02.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1#include <kernel/polys.h>
2#include <Singular/ipid.h>
3
4#include <libpolys/polys/monomials/ring.h>
5#include <kernel/ideals.h>
6#include <gfanlib/gfanlib.h>
7
8#include <callgfanlib_conversion.h>
9#include <groebnerCone.h>
10#include <initial.h>
11
12/***
13 * Computes the Groebner cone of a polynomial g in ring r containing w relatively.
14 * Assumes that r has a weighted ordering with weight in the said Groebner cone.
15 **/
16gfan::ZCone sloppyGroebnerCone(const poly g, const ring r, const gfan::ZVector w)
17{
18  int n = r->N;
19  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
20  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
21
22  int* expv = (int*) omAlloc((n+1)*sizeof(int));
23  p_GetExpV(g,expv,r);
24  gfan::ZVector leadexp = intStar2ZVector(n,expv);
25  long d = wDeg(g,r,w);
26
27  poly h=g->next;
28  for (; h && wDeg(h,r,w)==d; pIter(h))
29  {
30    p_GetExpV(h,expv,r);
31    equations.appendRow(leadexp-intStar2ZVector(n,expv));
32  }
33
34  for (; h; pIter(h))
35  {
36    p_GetExpV(h,expv,r);
37    inequalities.appendRow(leadexp-intStar2ZVector(n,expv));
38  }
39
40  omFreeSize(expv,(n+1)*sizeof(int));
41  return gfan::ZCone(inequalities,equations);
42}
43
44/***
45 * Computes the Groebner cone of an ideal I in ring r containing w relatively.
46 * Assumes that r has a weighted ordering with weight in the said Groebner cone.
47 **/
48gfan::ZCone sloppyGroebnerCone(const ideal I, const ring r, const gfan::ZVector w)
49{
50  int k = idSize(I);
51  gfan::ZCone zc = gfan::ZCone(r->N);
52  for (int i=0; i<k; i++)
53    zc = intersection(zc,sloppyGroebnerCone(I->m[i],r,w));
54  return zc;
55}
56
57/***
58 * Computes the Groebner cone of a polynomial g in ring r containing w relatively.
59 **/
60gfan::ZCone groebnerCone(const poly g, const ring r, const gfan::ZVector w)
61{
62  int n = r->N;
63  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
64  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
65
66  int* expv = (int*) omAlloc((n+1)*sizeof(int));
67  p_GetExpV(g,expv,r);
68  gfan::ZVector leadexp = intStar2ZVector(n,expv);
69  long d = wDeg(g,r,w);
70
71  for (poly h=g->next; h; pIter(h))
72  {
73    p_GetExpV(h,expv,r);
74    if (wDeg(h,r,w)<d)
75      inequalities.appendRow(leadexp-intStar2ZVector(n,expv));
76    else
77      equations.appendRow(leadexp-intStar2ZVector(n,expv));
78  }
79
80  omFreeSize(expv,(n+1)*sizeof(int));
81  return gfan::ZCone(inequalities,equations);
82}
83
84/***
85 * Computes the Groebner cone of an ideal I in ring r containing w relatively.
86 * Assumes that r has a weighted ordering with weight in the said Groebner cone.
87 **/
88gfan::ZCone groebnerCone(const ideal I, const ring r, const gfan::ZVector w)
89{
90  int k = idSize(I);
91  gfan::ZCone zc = gfan::ZCone(r->N);
92  for (int i=0; i<k; i++)
93    zc = intersection(zc,groebnerCone(I->m[i],r,w));
94  return zc;
95}
96
97groebnerConeData::groebnerConeData():
98  I(NULL),
99  r(NULL),
100  c(gfan::ZCone(0)),
101  p(gfan::ZVector(0))
102{
103}
104
105groebnerConeData::groebnerConeData(const groebnerConeData &sigma):
106  I(id_Copy(sigma.getIdeal(),sigma.getRing())),
107  r(rCopy(sigma.getRing())),
108  c(gfan::ZCone(sigma.getCone())),
109  p(gfan::ZVector(sigma.getInteriorPoint()))
110{
111}
112
113groebnerConeData::groebnerConeData(const ideal &J, const ring &s, const gfan::ZCone &d, const gfan::ZVector &q):
114  I(J),
115  r(s),
116  c(d),
117  p(q)
118{
119}
120
121groebnerConeData::groebnerConeData(const ideal &J, const ring &s):
122  I(J),
123  r(s)
124{
125}
126
127groebnerConeData::~groebnerConeData()
128{
129  id_Delete(&I,r);
130  rDelete(r);
131}
132
133
134groebnerConeData maximalGroebnerConeData(ideal I, const ring r)
135{
136  int n = rVar(r);
137  poly g = NULL;
138  int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
139  int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
140  gfan::ZVector leadexpw = gfan::ZVector(n);
141  gfan::ZVector tailexpw = gfan::ZVector(n);
142  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
143  for (int i=0; i<IDELEMS(I); i++)
144  {
145    g = (poly) I->m[i]; pGetExpV(g,leadexpv);
146    leadexpw = intStar2ZVector(n, leadexpv);
147    pIter(g);
148    while (g != NULL)
149    {
150      pGetExpV(g,tailexpv);
151      tailexpw = intStar2ZVector(n, tailexpv);
152      inequalities.appendRow(leadexpw-tailexpw);
153      pIter(g);
154    }
155  }
156  omFreeSize(leadexpv,(n+1)*sizeof(int));
157  omFreeSize(tailexpv,(n+1)*sizeof(int));
158  gfan::ZCone zc = gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
159  gfan::ZVector p = zc.getRelativeInteriorPoint();
160  return groebnerConeData(I,r,zc,p);
161}
Note: See TracBrowser for help on using the repository browser.