My Project
Functions | Variables
weight.h File Reference
#include "polys/monomials/ring.h"

Go to the source code of this file.

Functions

void kEcartWeights (poly *s, int sl, short *eweight, const ring R)
 
long maxdegreeWecart (poly p, int *l, ring r)
 
long totaldegreeWecart (poly p, ring r)
 
long totaldegreeWecart_IV (poly p, ring r, const int *w)
 
int * iv2array (intvec *iv, const ring R)
 
double wFunctionalBuch (int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
 
void wCall (poly *s, int sl, int *x, double wNsqr, const ring R)
 

Variables

EXTERN_VAR short * ecartWeights
 
THREAD_VAR double(* wFunctional )(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
 

Function Documentation

◆ iv2array()

int* iv2array ( intvec iv,
const ring  R 
)

Definition at line 200 of file weight.cc.

201 {
202  int *s=(int *)omAlloc0((rVar(R)+1)*sizeof(int));
203  int len=0;
204  if(iv!=NULL)
205  len=si_min(iv->length(),rVar(R)); // usually: rVar(R)==length()
206  int i;
207  //for(i=pVariables;i>len;i--) s[i]=1;
208  for(i=len;i>0;i--) s[i]=(*iv)[i-1];
209  return s;
210 }
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
int i
Definition: cfEzgcd.cc:132
int length() const
Definition: intvec.h:94
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:593
#define R
Definition: sirandom.c:27

◆ kEcartWeights()

void kEcartWeights ( poly *  s,
int  sl,
short *  eweight,
const ring  R 
)

Definition at line 182 of file weight.cc.

183 {
184  int n, i;
185  int *x;
186 
187  *eweight = 0;
188  n = rVar(R);
191  else
193  x = (int * )omAlloc(2 * (n + 1) * sizeof(int));
194  wCall(s, sl, x, (double)2.0 / (double)n, R);
195  for (i = n; i!=0; i--)
196  eweight[i] = x[i + n + 1];
197  omFreeSize((ADDRESS)x, 2 * (n + 1) * sizeof(int));
198 }
void * ADDRESS
Definition: auxiliary.h:119
Variable x
Definition: cfModGcd.cc:4082
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:761
THREAD_VAR double(* wFunctional)(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition: weight.cc:20
void wCall(poly *s, int sl, int *x, double wNsqr, const ring R)
Definition: weight.cc:108
double wFunctionalBuch(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition: weight0.cc:78
double wFunctionalMora(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition: weight0.cc:34

◆ maxdegreeWecart()

long maxdegreeWecart ( poly  p,
int *  l,
ring  r 
)

Definition at line 247 of file weight.cc.

248 {
249  short k=p_GetComp(p, r);
250  int ll=1;
251  long t,max;
252 
253  max=totaldegreeWecart(p, r);
254  pIter(p);
255  while ((p!=NULL) && (p_GetComp(p, r)==k))
256  {
257  t=totaldegreeWecart(p, r);
258  if (t>max) max=t;
259  ll++;
260  pIter(p);
261  }
262  *l=ll;
263  return max;
264 }
int l
Definition: cfEzgcd.cc:100
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4078
static int max(int a, int b)
Definition: fast_mult.cc:264
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pIter(p)
Definition: monomials.h:37
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:217

◆ totaldegreeWecart()

long totaldegreeWecart ( poly  p,
ring  r 
)

Definition at line 217 of file weight.cc.

218 {
219  int i;
220  long j =0;
221 
222  for (i=rVar(r); i>0; i--)
223  j += (int)(p_GetExp(p,i,r) * ecartWeights[i]);
224  return j;
225 }
int j
Definition: facHensel.cc:110
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:469
EXTERN_VAR short * ecartWeights
Definition: weight.h:12

◆ totaldegreeWecart_IV()

long totaldegreeWecart_IV ( poly  p,
ring  r,
const int *  w 
)

Definition at line 231 of file weight.cc.

232 {
233  int i;
234  long j =0;
235 
236  for (i=rVar(r); i>0; i--)
237  j += (long)((int)(p_GetExp(p,i,r) * w[i]));
238  return j;
239 }
const CanonicalForm & w
Definition: facAbsFact.cc:51

◆ wCall()

void wCall ( poly *  s,
int  sl,
int *  x,
double  wNsqr,
const ring  R 
)

Definition at line 108 of file weight.cc.

109 {
110  int n, q, npol, mons, i;
111  int *A, *xopt, *lpol, *degw;
112  double f1, fx, eps, *rel;
113  void *adr;
114 
115  n = rVar(R);
116  lpol = (int * )omAlloc((sl + 1) * sizeof(int));
117  wDimensions(s, sl, lpol, &npol, &mons);
118  xopt = x + (n + 1);
119  for (i = n; i!=0; i--)
120  xopt[i] = 1;
121  if (mons==0)
122  {
123  omFreeSize((ADDRESS)lpol, (sl + 1) * sizeof(int));
124  return;
125  }
126  adr = (void * )omAllocAligned(npol * sizeof(double));
127  rel = (double*)adr;
128  q = (n + 1) * mons * sizeof(int);
129  A = (int * )omAlloc(q);
130  wInit(s, sl, mons, A, R);
131  degw = A + (n * mons);
132  memset(degw, 0, mons * sizeof(int));
133  for (i = n; i!=0; i--)
134  wAdd(A, mons, i, 1, rVar(R));
135  wNorm(degw, lpol, npol, rel);
136  f1 = (*wFunctional)(degw, lpol, npol, rel, (double)1.0, wNsqr);
137  if (TEST_OPT_PROT) Print("// %e\n",f1);
138  eps = f1;
139  fx = (double)2.0 * eps;
140  memset(x, 0, (n + 1) * sizeof(int));
141  wFirstSearch(A, x, mons, lpol, npol, rel, &fx, wNsqr, rVar(R));
142  if (TEST_OPT_PROT) Print("// %e\n",fx);
143  memcpy(x + 1, xopt + 1, n * sizeof(int));
144  memset(degw, 0, mons * sizeof(int));
145  for (i = n; i!=0; i--)
146  {
147  x[i] *= 16;
148  wAdd(A, mons, i, x[i], rVar(R));
149  }
150  wSecondSearch(A, x, lpol, npol, mons, rel, &fx, wNsqr, rVar(R));
151  if (TEST_OPT_PROT) Print("// %e\n",fx);
152  if (fx >= eps)
153  {
154  for (i = n; i!=0; i--)
155  xopt[i] = 1;
156  }
157  else
158  {
159  wGcd(xopt, n);
160 // if (BTEST1(22))
161 // {
162 // f1 = fx + (double)0.1 * (f1 - fx);
163 // wSimple(x, n);
164 // memset(degw, 0, mons * sizeof(int));
165 // for (i = n; i!=0; i--)
166 // wAdd(A, mons, i, x[i], rVar(R));
167 // eps = wPrWeight(x, n);
168 // fx = (*wFunctional)(degw, lpol, npol, rel, eps);
169 // if (fx < f1)
170 // {
171 // if (TEST_OPT_PROT) Print("// %e\n",fx);
172 // memcpy(xopt + 1, x + 1, n * sizeof(int));
173 // }
174 // }
175  }
176  omFreeSize((ADDRESS)A, q);
177  omFreeSize((ADDRESS)lpol, (sl + 1) * sizeof(int));
178  omFreeSize((ADDRESS)adr, npol * sizeof(double));
179 }
#define Print
Definition: emacs.cc:80
#define omAllocAligned
Definition: omAllocDecl.h:273
#define TEST_OPT_PROT
Definition: options.h:103
#define A
Definition: sirandom.c:24
void wFirstSearch(int *A, int *x, int mons, int *lpol, int npol, double *rel, double *fopt, double wNsqr, int rvar)
Definition: weight0.cc:152
void wSecondSearch(int *A, int *x, int *lpol, int npol, int mons, double *rel, double *fk, double wNsqr, int rvar)
Definition: weight0.cc:295
static void wDimensions(poly *s, int sl, int *lpol, int *npol, int *mons)
Definition: weight.cc:34
void wNorm(int *degw, int *lpol, int npol, double *rel)
Definition: weight0.cc:463
void wGcd(int *x, int n)
Definition: weight0.cc:352
static void wInit(poly *s, int sl, int mons, int *A, const ring R)
Definition: weight.cc:64
void wAdd(int *A, int mons, int kn, int xx, int rvar)
Definition: weight0.cc:132

◆ wFunctionalBuch()

double wFunctionalBuch ( int *  degw,
int *  lpol,
int  npol,
double *  rel,
double  wx,
double  wNsqr 
)

Definition at line 78 of file weight0.cc.

80 {
81  int i, j, ecl, ecu, ec;
82  int *ex;
83  double gfmax, ghom, pfmax;
84  double *r;
85 
86  ex = degw;
87  r = rel;
88  gfmax = (double)0.0;
89  ghom = (double)1.0;
90  for (i = 0; i < npol; i++)
91  {
92  ecu = ecl = *ex++;
93  for (j = lpol[i] - 1; j!=0 ; j--)
94  {
95  ec = *ex++;
96  if (ec < ecl)
97  ecl = ec;
98  else if (ec > ecu)
99  ecu = ec;
100  }
101  pfmax = (double)ecl / (double)ecu;
102  if (pfmax < ghom)
103  ghom = pfmax;
104  gfmax += (double)(ecu * ecu) * (*r++);
105  }
106  if (ghom > (double)0.5)
107  gfmax *= ((double)1.0 - (ghom * ghom)) / (double)0.75;
108  return gfmax / pow(wx, wNsqr);
109 }
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:411

Variable Documentation

◆ ecartWeights

EXTERN_VAR short* ecartWeights

Definition at line 12 of file weight.h.

◆ wFunctional

THREAD_VAR double(* wFunctional) (int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr) ( int *  degw,
int *  lpol,
int  npol,
double *  rel,
double  wx,
double  wNsqr 
)

Definition at line 26 of file weight.h.