adjustWeights.cc
Go to the documentation of this file.
1 #include <gfanlib/gfanlib_vector.h>
2 #include <kernel/mod2.h>
3 
4 
5 #ifndef NDEBUG
6 static bool checkForNonPositiveEntries(const gfan::ZVector &w)
7 {
8  for (unsigned i=0; i<w.size(); i++)
9  {
10  if (w[i].sign()<=0)
11  {
12  std::cout << "ERROR: non-positive weight in weight vector" << std::endl
13  << "weight: " << w << std::endl;
14  return false;
15  }
16  }
17  return true;
18 }
19 
20 static bool checkForNonPositiveLaterEntries(const gfan::ZVector &w)
21 {
22  for (unsigned i=1; i<w.size(); i++)
23  {
24  if (w[i].sign()<=0)
25  {
26  std::cout << "ERROR: non-positive weight in weight vector later entries" << std::endl
27  << "weight: " << w << std::endl;
28  return false;
29  }
30  }
31  return true;
32 }
33 #endif //NDEBUG
34 
35 /***
36  * Returns a strictly positive weight vector v with respect to whom
37  * any x-homogeneous element is homogeneous to
38  * if and only if it is homogeneous with respect to w.
39  **/
40 gfan::ZVector nonvalued_adjustWeightForHomogeneity(const gfan::ZVector &w)
41 {
42  /* find the smallest entry min of w */
43  gfan::Integer min=w[0];
44  for (unsigned i=1; i<w.size(); i++)
45  if (w[i]<min) min=w[i];
46 
47  if (min.sign()>0)
48  return w;
49 
50  /* compute w+(1-min)*(1,...,1) and return it */
51  gfan::ZVector v=gfan::ZVector(w.size());
52  for (unsigned i=0; i<w.size(); i++)
53  v[i]=w[i]-min+1;
55  return v;
56 }
57 
58 gfan::ZVector valued_adjustWeightForHomogeneity(const gfan::ZVector &w)
59 {
60  /* find the biggest entry max of w
61  * amongst the later entries w[1],...,w[n] */
62  gfan::Integer max=w[1];
63  for (unsigned i=2; i<w.size(); i++)
64  if (max<w[i]) max=w[i];
65 
66  /* compute -w+(1+max)*(0,1,...,1) and return it */
67  gfan::ZVector v=gfan::ZVector(w.size());
68  v[0]=-w[0];
69  for (unsigned i=1; i<w.size(); i++)
70  v[i]=-w[i]+max+1;
72  return v;
73 }
74 
75 /***
76  * Returns a weight vector v which coincides with a weight vector e
77  * on any set of x-homogeneous elements that are also homogeneous with respect to w,
78  * w containing only positive weights
79  **/
80 gfan::ZVector nonvalued_adjustWeightUnderHomogeneity(const gfan::ZVector &e, const gfan::ZVector &/*w*/)
81 {
82  /* since our ideal is homogeneous, we can basically do the same as before */
83  /* find the smallest entry min of w */
84  gfan::Integer min=e[0];
85  for (unsigned i=1; i<e.size(); i++)
86  if (e[i]<min) min=e[i];
87 
88  if (min.sign()>0)
89  return e;
90 
91  /* compute w+(1-min)*(1,...,1) and return it */
92  gfan::ZVector v=gfan::ZVector(e.size());
93  for (unsigned i=0; i<e.size(); i++)
94  v[i]=e[i]-min+1;
96  return v;
97 }
98 
99 gfan::ZVector valued_adjustWeightUnderHomogeneity(const gfan::ZVector &e, const gfan::ZVector &w)
100 {
102 
103  /* find k such that e+k*w is strictly positive,
104  * i.e. k such that e[i]+k*w[i] is strictly positive
105  * for all i=0,...,n */
106  gfan::Integer k((long)0);
107  if (e[0].sign()<=0 && w[0].sign()>0)
108  k = gfan::Integer((long)1)-(e[0]/w[0]);
109  for (unsigned i=1; i<e.size(); i++)
110  {
111  if (e[i].sign()<=0)
112  {
113  gfan::Integer kk = gfan::Integer((long)1)-(e[i]/w[i]);
114  if (k<kk)
115  k = kk;
116  }
117  }
118 
119  /* compute e+k*w, check it for correctness and return it */
120  gfan::ZVector v = e+k*w;
122  return v;
123 }
gfan::ZVector nonvalued_adjustWeightUnderHomogeneity(const gfan::ZVector &e, const gfan::ZVector &)
static int min(int a, int b)
Definition: fast_mult.cc:268
int k
Definition: cfEzgcd.cc:93
static int max(int a, int b)
Definition: fast_mult.cc:264
#define assume(x)
Definition: mod2.h:405
static bool checkForNonPositiveLaterEntries(const gfan::ZVector &w)
static bool checkForNonPositiveEntries(const gfan::ZVector &w)
Definition: adjustWeights.cc:6
int i
Definition: cfEzgcd.cc:123
gfan::ZVector valued_adjustWeightUnderHomogeneity(const gfan::ZVector &e, const gfan::ZVector &w)
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
gfan::ZVector nonvalued_adjustWeightForHomogeneity(const gfan::ZVector &w)
gfan::ZVector valued_adjustWeightForHomogeneity(const gfan::ZVector &w)
const CanonicalForm & w
Definition: facAbsFact.cc:55
static int sign(int x)
Definition: ring.cc:3413