6 #ifndef realroot_solver_sleeve_hpp
7 #define realroot_solver_sleeve_hpp
69 # define TMPL template<class C, class V>
70 # define SOLVER solver<C, Sleeve<V> >
87 template<
class C,
class D>
void
92 for(
unsigned i=0;i<f.
size();i++) f.
up[i]=as<C>(p[i]);
96 for(
unsigned i=0;i<f.
size();i++) f.
dw[i]=as<C>(p[i]);
99 template<
class C,
class D>
void
108 for(
unsigned i=0;i< p.size();i++) {
114 rational mx = (p[ip]>-p[
in]?as<rational>(p[ip]):as<rational>(-p[
in]));
118 for (
int i = 0; i <= d; i ++ ) {
119 c = as<rational>(p[i])/(mx*bn(d,i));
125 for (
int i = 0; i <= d; i ++ ) {
126 c = as<rational>(p[i])/(mx*bn(d,i));
144 template<
class output,
class real>
static inline
145 void get(output& sol,
const real& first = 0,
const real& last =1)
147 typedef typename output::value_type root_t;
152 real
scale = last-first;
153 for (
unsigned i = 0; i < data.
nb_sol(); i ++ )
161 template<
class output,
class real>
static inline
164 typedef typename output::value_type root_t;
165 typedef root_t as_root;
166 typedef typename root_t::value_type bound_t;
169 real dt= H.a*H.d-H.b*H.c;
171 for (
unsigned i = 0; i < data.
nb_sol(); i ++ )
178 for (
int i = data.
nb_sol()-1; i >=0 ; i --)
199 template<
class C>
static inline C as_root(
const C& a,
const C&
b) {
return (a+b)/2;}
201 template<
class output,
class real>
static inline
202 void get(output& sol,
const real& first = 0,
const real& last =1)
204 typedef typename output::value_type root;
206 real
scale= last-first;
207 for (
unsigned i = 0; i < data.
nb_sol(); i ++ )
215 template<
class output,
class real>
static inline
216 void get(output& sol, std::vector<int>& mults,
const real& first = 0,
const real& last =1)
218 get(sol, first, last);
219 for (
unsigned i = 0; i < data.
nb_sol(); i ++ )
220 mults.push_back(data.
m_res[i].sv);
223 template<
class output,
class real>
static inline
229 std::vector<real> u(s);
231 real dt=H.a*H.d-H.b*H.c;
237 for (
unsigned i = 0; i < s; i ++ )
242 for (
unsigned i = 0; i < s; i ++ ) {
244 sol << as_root(u[i],v);
252 for (
int i = s-1; i >=0; i -- )
257 for (
int i = s-1; i >=0; i -- ) {
259 sol << as_root(v,u[i]);
288 static inline void alloc( sz_t s, sz_t deep )
290 K::data.alloc(s,2*s,deep);
298 std::cout << _bar << std::endl;
301 static void writebounds( creal_t * pup, creal_t * pdw,
unsigned s )
308 bool glue( sz_t cup, sz_t cdw,
int d )
310 if ( K::data.bckb() == K::data.m_dmn[d] )
312 K::data.bckb() = K::data.m_dmn[d];
313 K::data.bckb().m += 1;
314 if ( cup ) K::data.m_cup = cup;
315 if ( cdw ) K::data.m_cdw = cdw;
324 if ( K::data.m_res.size() == 0 || !
glue(cup,cdw,d) )
326 K::data.mstore(d,
std::max(cup,cdw));
336 void dwsplit( creal_t * r, creal_t * l, sz_t s )
343 void upsplit( creal_t * r, creal_t * l, sz_t s )
349 static void Loop(
bool isole =
true ) {
352 creal_t * pup, * pdw;
357 pup = K::data.m_data;
358 pdw = K::data.m_data + s;
359 K::data.m_dmn[0].m = 0;
360 K::data.m_dmn[0].e = 0;
361 for( a = 0, d = 0; d >= 0; d--, a -= 2*s )
367 if ( isole && cup == cdw && cup == 1 ){
372 if ( K::data.m_dmn[d].e == K::data.m_limit-1 ) {
374 if ( cup == cdw && cup == 1 )
389 for ( k = 0; k < K::data.m_s; k ++ ) {
390 if ( ( pup[a+k] > 0 ) != ( pdw[a+k] > 0 ) ) {
405 template<
class input>
static
409 alloc(in.size(),prec);
410 std::copy(in.begin(),in.end(),K::data.m_data);
411 std::copy(in.begin(),in.end(),K::data.m_data+K::data.m_s);
415 const Domain_t&
operator[](
int i )
const {
return K::data.m_res[i]; };
419 template<
class output,
class input>
static inline
424 template<
class VECT,
class POL,
class Q>
static inline
425 void init_pol(VECT& ubp, VECT& dbp,
const POL& r,
unsigned sz,
const Q& u,
const Q&v);
428 template<
class input>
static inline
429 void run(
const input&
in,
const creal_t& eps)
435 template<
class C>
static void
444 template<
class input>
static
445 void run(
const input& up,
const input& dw) {
446 assert(up.size()==dw.size());
448 alloc(up.size(),prec);
449 std::copy(up.begin(),up.end(),K::data.m_data);
450 std::copy(dw.begin(),dw.end(),K::data.m_data+K::data.m_s);
459 template <
typename output,
typename POL,
typename Q>
static
460 void solve(output& sol,
const POL& r,
const Q& u,
const Q& v);
463 template<
class output,
class input,
class real,
class MTH>
static inline
465 const input& up,
const input& dw,
466 const real& u,
const real& v,
const MTH& mth)
468 K::data.isole=mth.isole;
480 template <
typename output,
typename POL ,
typename real,
typename MTH>
static
486 unsigned sz= r.size();
487 std::vector<creal_t> ubp( sz ), dbp( sz );
490 for(
unsigned i=0;i<sz;i++) ubp[i] =as<creal_t>(r[i]);
494 for(
unsigned i=0;i<sz;i++) dbp[i] =as<creal_t>(r[i]);
496 K::data.isole=mth.isole;
504 template<
class VECT,
class POL,
class Q>
515 std::vector<rational> bp(sz);
526 for (
unsigned i = 0; i < sz; i ++ ) ubp[i]=as<creal_t>(bp[i]);
530 for (
unsigned i = 0; i < sz; i ++ ) dbp[i]=as<creal_t>(bp[i]);
543 BEZIER::monomial_to_bezier(ubp,r,r.size(),ud,vd);
547 BEZIER::monomial_to_bezier(dbp,r,r.size(),ud,vd);
550 for (
unsigned i= 0; i < ubp.size(); i ++ )
551 if ( dbp[i] > ubp[i] ) {
559 template <
typename output,
typename POL ,
typename Q>
562 unsigned sz= r.size();
563 std::vector<double> ubp(sz), dbp(sz);
564 init_pol(ubp,dbp,r,sz,u,v);
580 template<
class POL>
static void
581 solve(Solutions& sol,
const POL& p);
583 template<
class POL,
class T>
static void
584 solve(Solutions& sol,
const POL& p,
const T& u,
const T& v);
586 template<
class T,
class U,
class VRT>
static void
589 template<
class T,
class U,
class VRT>
static void
592 template<
class U,
class VRT>
static void
604 template<
class POL>
void
606 typedef typename K::ieee real_t;
607 sleeve_rep<real_t> f(
degree(p)+1);
610 for(
unsigned i=1;i< f.size();i+=2) {
611 c=f.up[i];f.up[i]=-f.dw[i];f.dw[i]=-
c;
615 homography<real_t> H(1,0,1,-1);
616 base_t::data.root_bound = -
bound_root(p,Cauchy<real_t>());
619 for(
unsigned i=1;i< f.size();i+=2) {
620 c=f.up[i];f.up[i]=-f.dw[i];f.dw[i]=-
c;
623 base_t::data.root_bound = - base_t::data.root_bound;
629 template<
class T,
class U,
class VRT>
void
631 const polynomial<U,VRT>& pl,
const polynomial<U,VRT>& pu,
632 const T& u,
const T& v) {
634 base_t::get(sol,u,v);
639 template<
class T,
class U,
class VRT>
void
641 const polynomial<U,VRT>& pl,
const polynomial<U,VRT>& pu,
642 const T& u,
const T& v) {
644 base_t::get(sol,mult,u,v);
648 template<
class U,
class VRT>
void
650 const polynomial<U,VRT>& pl,
const polynomial<U,VRT>& pu) {
652 base_t::get(sol,0,1);
657 template<
class POL,
class T>
void
659 const T& u,
const T& v) {
661 typedef typename SOLVER::base_t base_t;
663 unsigned sz= p.size();
664 std::vector<double> ubp(sz), dbp(sz);
665 base_t::init_pol(ubp,dbp,p,sz,u,v);
666 base_t::run(ubp,dbp);
667 base_t::get(sol,u,v);
672 template<
class POL,
class M,
class B>
673 typename solver<B, Sleeve<M> >::Solutions
676 typedef typename Solver::Solutions Solutions;
682 template<
class POL,
class M>
683 typename solver<typename POL::Scalar, Sleeve<M> >::Solutions
698 #endif //realroot_solver_sleeve_hpp
Definition: solver_uv_sleeve.hpp:272
static void run_loop(const input &in, const creal_t &eps, const texp::true_t &)
Definition: solver_uv_sleeve.hpp:406
static void run(const sleeve_rep< C > &p)
Definition: solver_uv_sleeve.hpp:436
static void convert(real &a, const bound &b, const real &first=0, const real &scale=1)
Definition: solver_binary.hpp:218
Sequence of terms with reference counter.
Definition: Seq.hpp:28
Definition: solver_uv_sleeve.hpp:73
void fill(C *a, unsigned n, int s, const C &x)
Definition: tensor_vctops.hpp:152
const C & b
Definition: Interval_glue.hpp:25
K::integer integer
Definition: solver_uv_sleeve.hpp:193
dynamic_exp< E >::degree_t degree(const dynamic_exp< E > &t)
Definition: dynamicexp.hpp:191
unsigned sz_t
Definition: solver_uv_sleeve.hpp:280
structure defining a the empty list
Definition: texp_bool.hpp:11
const Domain_t & operator[](int i) const
Definition: solver_uv_sleeve.hpp:415
static Solutions solve(const POL &p)
Definition: solver.hpp:75
binary_subdivision< K > Base_t
Definition: solver_uv_sleeve.hpp:281
static void init_pol(VECT &ubp, VECT &dbp, const POL &r, unsigned sz, const Q &u, const Q &v)
Definition: solver_uv_sleeve.hpp:505
static void run(const input &in, const creal_t &eps)
Definition: solver_uv_sleeve.hpp:429
MP swap(const MP &P, int var_i, int var_j)
Definition: sparse_monomials.hpp:988
void scale(IntervalData< RT, Poly > &ID, const RT &a)
Definition: contfrac_intervaldata.hpp:221
FT bound_root(const POLY &p, const Cauchy< FT > &m)
Definition: univariate_bounds.hpp:325
static void upsplit(creal_t *r, creal_t *l, sz_t s)
Definition: solver_uv_sleeve.hpp:343
Definition: solver_uv_sleeve.hpp:76
solver< typename POL::Scalar, Sleeve< M > >::Solutions solve(const POL &p, const Sleeve< M > &slv)
Definition: solver_uv_sleeve.hpp:684
kernelof< C >::T K
Definition: solver_uv_sleeve.hpp:574
static void run(const input &up, const input &dw)
Definition: solver_uv_sleeve.hpp:445
Seq< typename ContFrac< NT, LB >::root_t > solve(const typename ContFrac< NT >::Poly &f, ContFrac< NT, LB >)
Definition: contfrac.hpp:164
static void print(creal_t *p, sz_t n)
Definition: solver_binary.hpp:315
static void set_precision(unsigned p)
Definition: solver_uv_sleeve.hpp:597
Seq< typename K::ieee > Solutions
Definition: solver_uv_sleeve.hpp:192
Definition: rounding_mode.hpp:71
Definition: solver.hpp:95
Base_t::unsigned_t unsigned_t
Definition: solver_uv_sleeve.hpp:282
Definition: solver_uv_sleeve.hpp:137
structure defining a positive answer
Definition: texp_bool.hpp:7
static void solve_bernstein(output &out, const input &in)
Definition: solver_uv_sleeve.hpp:420
unsigned size() const
Definition: solver_uv_sleeve.hpp:81
static data_t data
Definition: solver_uv_sleeve.hpp:142
void assign(double &r, const scalar< MPF > &z)
Definition: scalar_floating.hpp:537
TMPL void copy(Polynomial &r, const Polynomial &a)
Copy of a in r.
Definition: sparse_monomials.hpp:613
static void writebounds(creal_t *pup, creal_t *pdw, unsigned s)
Definition: solver_uv_sleeve.hpp:301
static void solve_bernstein(output &sol, const POL &r, const real &u, const real &v, const MTH &mth)
Definition: solver_uv_sleeve.hpp:481
static bool glue(sz_t cup, sz_t cdw, int d)
Definition: solver_uv_sleeve.hpp:308
bool in(const T &x, const Interval< T, r > &y)
Definition: Interval_fcts.hpp:100
C * up
Definition: solver_uv_sleeve.hpp:77
sleeve_rep(unsigned n)
Definition: solver_uv_sleeve.hpp:80
static data_t data
Definition: solver_uv_sleeve.hpp:194
Definition: solver.hpp:68
Definition: polynomial.hpp:37
Seq< Interval< typename K::ieee > > Solutions
Definition: solver_uv_sleeve.hpp:141
static void mstore(sz_t cup, sz_t cdw, int d)
Definition: solver_uv_sleeve.hpp:322
int binomial(int n, int p)
Definition: fatarcs_fcts.hpp:154
static integer binomial(const integer &n, const integer &p)
Definition: solver_uv_sleeve.hpp:197
static void alloc(sz_t s, sz_t deep)
Definition: solver_uv_sleeve.hpp:288
TMPL POL
Definition: polynomial_dual.hpp:74
Definition: homography.hpp:15
Definition: solver_binary.hpp:76
static void Loop(bool isole=true)
Definition: solver_uv_sleeve.hpp:349
res_t Domain_t
Definition: solver_uv_sleeve.hpp:283
Definition: binomials.hpp:68
#define Scalar
Definition: polynomial_operators.hpp:12
Definition: solver_binary.hpp:83
sz_t nb_sol()
Definition: solver_binary.hpp:198
unsigned bitprec(const T &e, const T &l=T(1.0))
Definition: numerics_hdwi.hpp:29
Generic class for intervals.
Definition: Interval.hpp:44
unsigned unsigned_t
Definition: solver_uv_sleeve.hpp:191
Definition: solver_binary.hpp:263
const C & c
Definition: Interval_glue.hpp:45
static void solve(output &sol, const POL &r, const Q &u, const Q &v)
Definition: solver_uv_sleeve.hpp:560
double C
Definition: solver_mv_fatarcs.cpp:16
binary_convert< K, V >::Solutions Solutions
Definition: solver_uv_sleeve.hpp:575
K::integer integer
Definition: solver_uv_sleeve.hpp:274
static C as_root(const C &a, const C &b)
Definition: solver_uv_sleeve.hpp:199
structure defining a negative answer
Definition: texp_bool.hpp:9
void convertm2b(T &bz, const P &p, unsigned size, const C &a, const C &b)
Definition: univariate.hpp:847
static sz_t sgncnt(creal_t const *b, sz_t sz)
Definition: solver_binary.hpp:294
binary_sleeve_subdivision< binary_convert< K, V > > base_t
Definition: solver_uv_sleeve.hpp:577
static void dwsplit(creal_t *r, creal_t *l, sz_t s)
Definition: solver_uv_sleeve.hpp:336
Definition: scalar_bigunsigned.hpp:11
void div(V &a, const W &c)
Inplace scalar division.
Definition: array.hpp:334
std::vector< res_t > m_res
Definition: solver_binary.hpp:96
unsigned m_sz
Definition: solver_uv_sleeve.hpp:78
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Domain_t & operator[](int i)
Definition: solver_uv_sleeve.hpp:416
Definition: solver.hpp:91
C * dw
Definition: solver_uv_sleeve.hpp:77
double creal_t
Definition: solver_uv_sleeve.hpp:279
return the arithmetic kernel from which the type X comes from.
Definition: texp_kernelof.hpp:30
static void barre(char c, unsigned n)
Definition: solver_uv_sleeve.hpp:293
Interval< T, r > max(const Interval< T, r > &a, const Interval< T, r > &b)
Definition: Interval_fcts.hpp:135
Definition: polynomial.hpp:40
R::value_type max_abs(const R &v)
Definition: array.hpp:387
K::rational rational
Definition: solver_uv_sleeve.hpp:275
static void split(creal_t *r, creal_t *l, sz_t sz)
Definition: solver_binary.hpp:281
static void solve_bernstein(output &sol, const input &up, const input &dw, const real &u, const real &v, const MTH &mth)
Definition: solver_uv_sleeve.hpp:464
#define TMPL
Definition: solver_uv_sleeve.hpp:69
#define assert(expr, msg)
Definition: shared_object.hpp:57