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