1 | #include <gfanlib/gfanlib_vector.h> |
---|
2 | #include <kernel/mod2.h> |
---|
3 | |
---|
4 | static bool checkForNonPositiveEntries(const gfan::ZVector w) |
---|
5 | { |
---|
6 | for (unsigned i=0; i<w.size(); i++) |
---|
7 | { |
---|
8 | if (w[i].sign()<=0) |
---|
9 | { |
---|
10 | std::cout << "ERROR: non-positive weight in weight vector" << std::endl |
---|
11 | << "weight: " << w << std::endl; |
---|
12 | return false; |
---|
13 | } |
---|
14 | } |
---|
15 | return true; |
---|
16 | } |
---|
17 | |
---|
18 | static bool checkForNonPositiveLaterEntries(const gfan::ZVector w) |
---|
19 | { |
---|
20 | if (w[0].sign()<0) |
---|
21 | { |
---|
22 | std::cout << "ERROR: negative weight in weight vector first entry" << std::endl |
---|
23 | << "weight: " << w << std::endl; |
---|
24 | return false; |
---|
25 | } |
---|
26 | for (unsigned i=1; i<w.size(); i++) |
---|
27 | { |
---|
28 | if (w[i].sign()<=0) |
---|
29 | { |
---|
30 | std::cout << "ERROR: non-positive weight in weight vector later entries" << std::endl |
---|
31 | << "weight: " << w << std::endl; |
---|
32 | return false; |
---|
33 | } |
---|
34 | } |
---|
35 | return true; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | /*** |
---|
40 | * Returns a strictly positive weight vector v with respect to whom |
---|
41 | * any x-homogeneous element is homogeneous to |
---|
42 | * if and only if it is homogeneous with respect to w. |
---|
43 | **/ |
---|
44 | gfan::ZVector nonvalued_adjustWeightForHomogeneity(const gfan::ZVector w) |
---|
45 | { |
---|
46 | /* find the smallest entry min of w */ |
---|
47 | gfan::Integer min=w[0]; |
---|
48 | for (unsigned i=1; i<w.size(); i++) |
---|
49 | if (w[i]<min) min=w[i]; |
---|
50 | /* compute w+(1-min)*(1,...,1) and return it */ |
---|
51 | gfan::ZVector v=gfan::ZVector(w.size()); |
---|
52 | if (min<1) |
---|
53 | { |
---|
54 | for (unsigned i=0; i<w.size(); i++) |
---|
55 | v[i]=w[i]-min+1; |
---|
56 | } |
---|
57 | assume(checkForNonPositiveEntries(v)); |
---|
58 | return v; |
---|
59 | } |
---|
60 | |
---|
61 | gfan::ZVector valued_adjustWeightForHomogeneity(const gfan::ZVector w) |
---|
62 | { |
---|
63 | /* find the biggest entry max of w |
---|
64 | * amongst the later entries w[1],...,w[n] */ |
---|
65 | gfan::Integer max=w[1]; |
---|
66 | for (unsigned i=2; i<w.size(); i++) |
---|
67 | if (max<w[i]) max=w[i]; |
---|
68 | /* compute -w+(1+max)*(0,1,...,1) and return it */ |
---|
69 | gfan::ZVector v=gfan::ZVector(w.size()); |
---|
70 | v[0]=-w[0]; |
---|
71 | for (unsigned i=1; i<w.size(); i++) |
---|
72 | v[i]=-w[i]+max+1; |
---|
73 | assume(checkForNonPositiveLaterEntries(v)); |
---|
74 | return v; |
---|
75 | } |
---|
76 | |
---|
77 | /*** |
---|
78 | * Returns a weight vector v which coincides with a weight vector e |
---|
79 | * on any set of x-homogeneous elements that are also homogeneous with respect to w, |
---|
80 | * w containing only positive weights |
---|
81 | **/ |
---|
82 | gfan::ZVector nonvalued_adjustWeightUnderHomogeneity(const gfan::ZVector e, const gfan::ZVector w) |
---|
83 | { |
---|
84 | assume(checkForNonPositiveEntries(w)); |
---|
85 | /* find k such that e+k*w is strictly positive, |
---|
86 | * i.e. k such that e[i]+k*w[i] is strictly positive |
---|
87 | * for all i=0,...,n |
---|
88 | * note that the division is rounded towards zero, |
---|
89 | * hence we increment the value by 1 */ |
---|
90 | gfan::Integer k((long)0); |
---|
91 | if (e[0].sign()<=0) |
---|
92 | k = gfan::Integer((long)1)-(e[0]/w[0]); |
---|
93 | for (unsigned i=1; i<e.size(); i++) |
---|
94 | { |
---|
95 | if (e[i].sign()<=0) |
---|
96 | { |
---|
97 | gfan::Integer kk = gfan::Integer((long)1)-(e[i]/w[i]); |
---|
98 | if (k<kk) |
---|
99 | k = kk; |
---|
100 | } |
---|
101 | } |
---|
102 | /* compute e+k*w, check it for correctness and return it */ |
---|
103 | gfan::ZVector v = e+k*w; |
---|
104 | assume(checkForNonPositiveEntries(v)); |
---|
105 | return v; |
---|
106 | } |
---|
107 | |
---|
108 | gfan::ZVector valued_adjustWeightUnderHomogeneity(const gfan::ZVector e, const gfan::ZVector w) |
---|
109 | { |
---|
110 | assume(checkForNonPositiveLaterEntries(w)); |
---|
111 | /* find k such that e+k*w is strictly positive, |
---|
112 | * i.e. k such that e[i]+k*w[i] is strictly positive |
---|
113 | * for all i=0,...,n */ |
---|
114 | gfan::Integer k((long)0); |
---|
115 | if (e[0].sign()<=0 && w[0].sign()>0) |
---|
116 | k = gfan::Integer((long)1)-(e[0]/w[0]); |
---|
117 | for (unsigned i=1; i<e.size(); i++) |
---|
118 | { |
---|
119 | if (e[i].sign()<=0) |
---|
120 | { |
---|
121 | gfan::Integer kk = gfan::Integer((long)1)-(e[i]/w[i]); |
---|
122 | if (k<kk) |
---|
123 | k = kk; |
---|
124 | } |
---|
125 | } |
---|
126 | /* compute e+k*w, check it for correctness and return it */ |
---|
127 | gfan::ZVector v = e+k*w; |
---|
128 | assume(checkForNonPositiveLaterEntries(v)); |
---|
129 | return v; |
---|
130 | } |
---|