Developer documentation

contfrac_lowerbound.hpp
Go to the documentation of this file.
1 
2 #ifndef _synaps_usolve_contfrac_lower_bound_h_
3 #define _synaps_usolve_contfrac_lower_bound_h_
4 
7 
8 namespace mmx {
9  // #define bit_size(a) mpz_sizeinbase(a.get_mpz_t(),2)
10 
11 //--------------------------------------------------------------------
20 {
21  template < typename Poly >
22  typename Poly::value_type lower_bound( const Poly& f)
23  {
24  //std::cout <<"Bezier"<<std::endl;
25  typedef typename Poly::value_type RT;
26  unsigned deg = degree(f);
27  tensor::bernstein<RT> bz(deg+1);
28  let::assign(bz, f);
29  // The Bernstein form of f w.r.t. the interval [0,\infinity]
30 
31  int sn = sign(bz[0]);
32  if(sn == 0) return 0;// That is, zero is a root, this should not be the case
33 
34  //std::cout << "bz[0] = "<< bz[0] << std::endl;
35 
36  RT lowerBoundN =-1, lowerBoundD=1;// Numerator and denominator of lower bound
37  //Now we find the least positive intersection of the convex hull.
38  for(int i=1; i <= deg; i++){
39  if(sn * sign(bz[i]) < 0){
40  /*
41  std::cout << "bz["<<i<<"] = "<< bz[i] << std::endl;
42  std::cout << "bz[0]*i "<< bz[0] * i << std::endl;
43  std::cout << "(deg*(bz[0]-bz[i]))" << (deg*(bz[0]-bz[i])) << std::endl;
44  */
45  if(lowerBoundN * deg *(bz[0]-bz[i]) > bz[0]*i*lowerBoundD
46  || lowerBoundN == -1){
47  lowerBoundN = bz[0]*i;
48  lowerBoundD = deg*(bz[0]-bz[i]);
49  }
50  }
51  }
52  lowerBoundD -= lowerBoundN;// Have to scale back the result to the orignial setting of [0, B]
53  long K = bit_size(lowerBoundN)- bit_size(lowerBoundD) -1;
54  if(K < 0)
55  return RT(0);
56  else if(lowerBoundN == lowerBoundD)
57  return 1;
58  else{// K > 0
59  return pow( RT(2), K);
60  }
61  }
62 };
63 
64 
65 
66 } //namespace mmx
67 #endif //_synaps_usolve_contfrac_lower_bound_h_
T pow(const T &a, int i)
Definition: binomials.hpp:12
dynamic_exp< E >::degree_t degree(const dynamic_exp< E > &t)
Definition: dynamicexp.hpp:191
Definition: contfrac_lowerbound.hpp:19
long int bit_size(const ZZ &z)
Definition: GMPXX.hpp:32
int sign(const QQ &a)
Definition: GMP.hpp:60
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Definition: array.hpp:12
Definition: tensor_bernstein.hpp:13
Poly::value_type lower_bound(const Poly &f)
Definition: contfrac_lowerbound.hpp:22
Home