Developer documentation

solver_univariate_glue.hpp
Go to the documentation of this file.
1 //#include <basix/glue.hpp>
2 #include <basix/vector.hpp>
3 #include <basix/vector_sort.hpp>
4 #include <numerix/kernel.hpp>
5 #include <realroot/Seq.hpp>
11 
12 
13 #define TMPL template<class C>
14 #define RING ring<C,MonomialTensor>
15 #define POLYNOMIAL polynomial< C, with<MonomialTensor> >
16 
17 namespace mmx {
18 
19  template<typename FT, typename RT, typename Poly>
20  struct as_helper<interval<FT>,IntervalData<RT,Poly> > {
21  static inline interval<FT>
23  FT left, right;
24  if ( I.c == RT(0))
25  left = sign(I.a) * bound_root( I.p, Cauchy<FT>());
26  else
27  left = FT(I.a)/I.c;
28 
29  if ( I.d == RT(0))
30  right = sign(I.b) * bound_root( I.p, Cauchy<FT>());
31  else
32  right = FT(I.b)/I.d;
33  // std::cout << I.a<<"/"<<I.c<<", "<<I.b<<"/"<<I.d<<std::endl;
34  return interval<FT>(left, right);
35  }
36  };
37 
38  TMPL vector<generic>
39  solver_univariate_contfrac_prec(const POLYNOMIAL & p, const int& prec) {
40  typedef Numerix kernel;
41  typedef typename kernel::integer Integer;
42  typedef typename kernel::rational Rational;
43  typedef typename kernel::interval_rational interval_rational;
45 
46  vector<interval_rational> sol;
47  Solver::set_precision(prec);
48  Solver::solve(sol,p);
49  sort(sol);
50 
51  vector<generic> r;
52  for(unsigned i=0;i<sol.size();i++)
53  r <<as<generic>(interval< Rational > (lower(sol[i]),upper(sol[i])));
54  //r <<as<generic>(sol[i]);
55  return r;
56  }
57 
58  //--------------------------------------------------------------------
59  TMPL vector<generic> solver_univariate_contfrac(const POLYNOMIAL & p) {
60  return solver_univariate_contfrac_prec(p,mmx_bit_precision);
61  }
62 
63  //--------------------------------------------------------------------
64  TMPL vector<generic>
65  solver_univariate_contfrac(const POLYNOMIAL & p, const interval<rational>& D) {
66  typedef Numerix kernel;
67  typedef typename kernel::integer Integer;
68  //typedef typename kernel::rational Rational;
69  typedef typename kernel::interval_rational interval_rational;
71 
72  vector<interval_rational> sol;
73  Solver::set_precision(mmx_bit_precision);
74  Solver::solve(sol,p,lower(D),upper(D));
75  sort(sol);
76  vector<generic> r;
77  for(unsigned i=0;i<N(sol);i++)
78  r <<as<generic>(interval< rational > (lower(sol[i]),upper(sol[i])));
79  return r;
80  }
81  //--------------------------------------------------------------------
82 
83 
84  TMPL vector<generic>
85  solver_univariate_contfrac_approx_prec(const POLYNOMIAL & p, const int& prec) {
86  typedef Numerix kernel;
87  typedef typename kernel::integer Integer;
88  //typedef typename kernel::rational rational;
89  typedef typename kernel::interval_rational interval_rational;
90  typedef solver<Integer,ContFrac<Approximate> > Solver;
91 
92 
93  Solver::set_precision(prec);
94 
95  vector<interval_rational> sol;
96  Solver::solve(sol,p);
97  sort(sol);
98  long int old_prec = mmx_bit_precision;
99  vector<generic> r;
100  mmx_bit_precision = prec;
101  for(unsigned i=0;i<sol.size();i++) {
102  r << as<generic>(as<floating<> >((lower(sol[i])+upper(sol[i]))/2));
103  }
104  mmx_bit_precision = old_prec;
105  return r;
106  }
107  //--------------------------------------------------------------------
108  TMPL vector<generic>
110  return solver_univariate_contfrac_approx_prec(p,mmx_bit_precision);
111  }
112  //--------------------------------------------------------------------
113  TMPL vector<generic>
115  typedef Numerix kernel;
116  //typedef typename kernel::integer Integer;
117  //typedef typename kernel::rational rational;
118  typedef typename kernel::interval_rational interval_rational;
119  typedef kernel::interval_rational interval_rational;
122  vector<generic> r;
123  for(unsigned i=0;i<sol.size();i++) r << as<generic>(sol[i]);
124  return r;
125  }
126  //--------------------------------------------------------------------
127  TMPL interval<floating<> >
128  solver_univariate_newton(const POLYNOMIAL & p, const interval<floating<> >& I) {
129  typedef interval<floating<> > interval_t;
131  Seq<interval_t> sol =solve(p,Nwt);
132 
133  return sol[0];
134  }
135 
136 } // namespace mmx
137 //--------------------------------------------------------------------
138 #undef TMPL
139 #undef RING
140 #undef POLYNOMIAL
141 
142 
Cauchy bound.
Definition: univariate_bounds.hpp:163
Sequence of terms with reference counter.
Definition: Seq.hpp:28
TMPL vector< generic > solver_univariate_contfrac_approx(const POLYNOMIAL &p)
Definition: solver_univariate_glue.hpp:109
const Interval & I
Definition: Interval_glue.hpp:49
Definition: assign.hpp:48
T upper(const Interval< T, r > &x)
Definition: Interval_fcts.hpp:89
FT bound_root(const POLY &p, const Cauchy< FT > &m)
Definition: univariate_bounds.hpp:325
RT a
Definition: contfrac_intervaldata.hpp:22
TMPL vector< generic > solver_univariate_sleeve(const POLYNOMIAL &p)
Definition: solver_univariate_glue.hpp:114
TMPL int N(const MONOMIAL &v)
Definition: monomial_glue.hpp:60
Seq< typename ContFrac< NT, LB >::root_t > solve(const typename ContFrac< NT >::Poly &f, ContFrac< NT, LB >)
Definition: contfrac.hpp:164
static interval< FT > cv(const IntervalData< RT, Poly > &I)
Definition: solver_univariate_glue.hpp:22
RT b
Definition: contfrac_intervaldata.hpp:22
RT c
Definition: contfrac_intervaldata.hpp:22
TMPL vector< generic > solver_univariate_contfrac_prec(const POLYNOMIAL &p, const int &prec)
Definition: solver_univariate_glue.hpp:39
Definition: contfrac_intervaldata.hpp:17
Definition: texp_kernelof.hpp:14
size_type size() const
Definition: Seq.hpp:166
TMPL vector< generic > solver_univariate_contfrac_approx_prec(const POLYNOMIAL &p, const int &prec)
Definition: solver_univariate_glue.hpp:85
RT d
Definition: contfrac_intervaldata.hpp:22
Definition: solver.hpp:68
TMPL POLYNOMIAL
Definition: polynomial_operators.hpp:148
TMPL vector< generic > solver_univariate_contfrac(const POLYNOMIAL &p)
Definition: solver_univariate_glue.hpp:59
T lower(const Interval< T, r > &x)
Definition: Interval_fcts.hpp:87
mplib::integer integer
Definition: texp_kernelof.hpp:16
#define TMPL
Definition: solver_univariate_glue.hpp:13
mplib::rational rational
Definition: texp_kernelof.hpp:17
Poly p
Definition: contfrac_intervaldata.hpp:23
TMPL interval< floating<> > solver_univariate_newton(const POLYNOMIAL &p, const interval< floating<> > &I)
Definition: solver_univariate_glue.hpp:128
int sign(const QQ &a)
Definition: GMP.hpp:60
Definition: solver_uv_interval_newton.hpp:232
Definition: array.hpp:12
Home