initial.cc
Go to the documentation of this file.
1 #include <kernel/ideals.h>
3 
4 #include <gfanlib/gfanlib.h>
5 
6 #include <exception>
7 
8 long wDeg(const poly p, const ring r, const gfan::ZVector w)
9 {
10  long d=0;
11  for (unsigned i=0; i<w.size(); i++)
12  {
13  if (!w[i].fitsInInt())
14  {
15  WerrorS("wDeg: overflow in weight vector");
16  throw 0; // weightOverflow;
17  }
18  d += p_GetExp(p,i+1,r)*w[i].toInt();
19  }
20  return d;
21 }
22 
23 gfan::ZVector WDeg(const poly p, const ring r, const gfan::ZVector w, const gfan::ZMatrix W)
24 {
25  gfan::ZVector d = gfan::ZVector(W.getHeight()+1);
26  d[0] = wDeg(p,r,w);
27  for (int i=0; i<W.getHeight(); i++)
28  d[i+1] = wDeg(p,r,W[i]);
29  return d;
30 }
31 
32 poly initial(const poly p, const ring r, const gfan::ZVector w)
33 {
34  if (p==NULL)
35  return NULL;
36 
37  poly q0 = p_Head(p,r);
38  poly q1 = q0;
39  long d = wDeg(p,r,w);
40  for (poly currentTerm = p->next; currentTerm; pIter(currentTerm))
41  {
42  long e = wDeg(currentTerm,r,w);
43  if (d<e)
44  {
45  p_Delete(&q0,r);
46  q0 = p_Head(currentTerm,r);
47  q1 = q0;
48  d = e;
49  }
50  else
51  if (e==d)
52  {
53  pNext(q1) = p_Head(currentTerm,r);
54  pIter(q1);
55  }
56  }
57  return q0;
58 }
59 
60 ideal initial(const ideal I, const ring r, const gfan::ZVector w)
61 {
62  int k = idSize(I); ideal inI = idInit(k);
63  for (int i=0; i<k; i++)
64  inI->m[i] = initial(I->m[i],r,w);
65  return inI;
66 }
67 
68 poly initial(const poly p, const ring r, const gfan::ZVector w, const gfan::ZMatrix W)
69 {
70  if (p==NULL)
71  return NULL;
72 
73  poly q0 = p_Head(p,r);
74  poly q1 = q0;
75  gfan::ZVector d = WDeg(p,r,w,W);
76  for (poly currentTerm = p->next; currentTerm; pIter(currentTerm))
77  {
78  gfan::ZVector e = WDeg(currentTerm,r,w,W);
79  if (d<e)
80  {
81  p_Delete(&q0,r);
82  q0 = p_Head(p,r);
83  q1 = q0;
84  d = e;
85  }
86  else
87  if (d==e)
88  {
89  pNext(q1) = p_Head(currentTerm,r);
90  pIter(q1);
91  }
92  }
93  return q0;
94 }
95 
96 ideal initial(const ideal I, const ring r, const gfan::ZVector w, const gfan::ZMatrix W)
97 {
98  int k = idSize(I); ideal inI = idInit(k);
99  for (int i=0; i<k; i++)
100  inI->m[i] = initial(I->m[i],r,w,W);
101  return inI;
102 }
103 
104 void initial(poly* pStar, const ring r, const gfan::ZVector w)
105 {
106  poly p = *pStar;
107  if (p==NULL)
108  return;
109 
110  long d = wDeg(p,r,w);
111  poly q0 = p;
112  poly q1 = q0;
113  pNext(q1) = NULL;
114  pIter(p);
115 
116  while(p)
117  {
118  long e = wDeg(p,r,w);
119  if (d<e)
120  {
121  p_Delete(&q0,r);
122  q0 = p;
123  q1 = q0;
124  pNext(q1) = NULL;
125  d = e;
126  pIter(p);
127  }
128  else
129  if (e==d)
130  {
131  pNext(q1) = p;
132  pIter(q1);
133  pNext(q1) = NULL;
134  pIter(p);
135  }
136  else
137  p = p_LmDeleteAndNext(p,r);
138  }
139  pStar = &q0;
140  return;
141 }
142 
143 void initial(ideal* IStar, const ring r, const gfan::ZVector w)
144 {
145  ideal I = *IStar;
146  int k = idSize(I);
147  for (int i=0; i<k; i++)
148  initial(&I->m[i],r,w);
149  return;
150 }
151 
152 void initial(poly* pStar, const ring r, const gfan::ZVector w, const gfan::ZMatrix W)
153 {
154  poly p = *pStar;
155  if (p==NULL)
156  return;
157 
158  gfan::ZVector d = WDeg(p,r,w,W);
159  poly q0 = p;
160  poly q1 = q0;
161  pNext(q1) = NULL;
162  pIter(p);
163 
164  while(p)
165  {
166  gfan::ZVector e = WDeg(p,r,w,W);
167  if (d<e)
168  {
169  p_Delete(&q0,r);
170  q0 = p;
171  q1 = q0;
172  pNext(q1) = NULL;
173  d = e;
174  pIter(p);
175  }
176  else
177  if (d==e)
178  {
179  pNext(q1) = p;
180  pIter(q1);
181  pNext(q1) = NULL;
182  pIter(p);
183  }
184  else
185  p = p_LmDeleteAndNext(p,r);
186  }
187  pStar = &q0;
188  return;
189 }
190 
191 void initial(ideal* IStar, const ring r, const gfan::ZVector w, const gfan::ZMatrix W)
192 {
193  ideal I = *IStar;
194  int k = idSize(I);
195  for (int i=0; i<k; i++)
196  initial(&I->m[i],r,w,W);
197  return;
198 }
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition: p_polys.h:721
return P p
Definition: myNF.cc:203
long wDeg(const poly p, const ring r, const gfan::ZVector w)
various functions to compute the initial form of polynomials and ideals
Definition: initial.cc:8
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:93
#define pIter(p)
Definition: monomials.h:44
poly initial(const poly p, const ring r, const gfan::ZVector w)
Returns the initial form of p with respect to w.
Definition: initial.cc:32
static poly p_Head(poly p, const ring r)
Definition: p_polys.h:819
const ring r
Definition: syzextra.cc:208
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
int i
Definition: cfEzgcd.cc:123
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
#define NULL
Definition: omList.c:10
const CanonicalForm & w
Definition: facAbsFact.cc:55
gfan::ZVector WDeg(const poly p, const ring r, const gfan::ZVector w, const gfan::ZMatrix W)
Returns the weighted multidegree of the leading term of p with respect to (w,W).
Definition: initial.cc:23
#define pNext(p)
Definition: monomials.h:43
static int idSize(const ideal id)
Count the effective size of an ideal (without the trailing allocated zero-elements) ...
Definition: ideals.h:43
polyrec * poly
Definition: hilb.h:10