source: git/Singular/dyn_modules/gfanlib/initial.cc @ 296b78

fieker-DuValspielwiese
Last change on this file since 296b78 was 1d85871, checked in by Yue Ren <ren@…>, 9 years ago
new: functions for groebnerFans, groebnerComplexes
  • Property mode set to 100644
File size: 3.6 KB
Line 
1#include <kernel/ideals.h>
2#include <polys/monomials/p_polys.h>
3
4#include <gfanlib/gfanlib.h>
5
6#include <exception>
7
8long 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
23gfan::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
32poly 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
60ideal 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
68poly 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
96ideal 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
104void 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
143void 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
152void 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
191void 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}
Note: See TracBrowser for help on using the repository browser.