4 #ifndef _realroot_SOLVER_FIRST_ROOT_CONFRAC_H
5 #define _realroot_SOLVER_FIRST_ROOT_CONFRAC_H
17 # define TMPL template<class POL>
18 # define TMPLR template<class Real, class POL>
49 typedef typename POL::scalar_t C;
94 if ( hg.
b!=0 && hg.
d!=0 )
95 l= as<Real>(hg.
b)/as<Real>(hg.
d);
101 l= as<Real>(hg.
a)/as<Real>(hg.
c) ;
103 if ( hg.
a!=0 && hg.
c!=0 )
104 r= as<Real>(hg.
a)/as<Real>(hg.
c);
110 r= as<Real>(hg.
b)/as<Real>(hg.
d);
129 return ( as<Real>(hg.
a)*as<Real>(t) + as<Real>(hg.
b) ) /
130 ( as<Real>(hg.
c)*as<Real>(t) + as<Real>(hg.
d) ) ;
152 int s, k,j, sz= f.size();
154 for ( s = sz, j = 0; j <= s-2; j++ )
155 for( k = s-2; k >= j; k-- )
167 for ( s = 0 ; s < sz; ++s )
177 unsigned s, l= f.size()-1;
179 for (s = 0 ; s <= l/2; s++ )
195 std::cout <<
"----------Interval---------------" <<
"\n" ;
196 std::cout <<
poly() <<
"\n" ;
197 std::cout<<
"("<<hg.
a <<
"x + " << hg.
b<<
")/("<<hg.
c<<
"x+ "<<hg.
d <<
")"<<
", sv:"<<
sign_var() <<std::endl;
198 std::cout <<
domain() <<
"\n" ;
199 std::cout <<
"-------------------------------" <<
"\n" ;
238 std::stack<BOX * > uboxes;
239 typedef typename POL::scalar_t
C;
258 while ( !uboxes.empty() && iters++ <
N_ITER )
265 if ( p==zero && (!uboxes.empty()) ) {
271 if ( s==1 && (!uboxes.empty()) ) {
276 if ( b->template width<Real>() < eps )
277 {std::cout<<
"first_root: multiple root?"<<b->template
domain<Real>() <<std::endl;}
283 if ( p( lower ) == 0 )
288 tmp->shift_box( lower );
294 tmp =
new BOX( *b ) ;
298 if ( p( Real(1) ) == Real(0) )
299 { tmp =
new BOX(zero, b->hom() ) ;
300 uboxes.push ( tmp ); }
302 tmp =
new BOX( *b ) ;
303 tmp->reverse_and_shift_box( 1 );
304 tmp->reverse_box( 1 );
324 std::stack<BOX * > uboxes;
325 typedef typename POL::scalar_t
C;
346 while ( !uboxes.empty() && iters++ <
N_ITER )
352 if ( p==zero && (!uboxes.empty()) ) {
359 if ( s==1 && (!uboxes.empty()) ) {
360 sols << *
b;
continue; }
364 if ( (!uboxes.empty()) && b->template width<Real>() < eps*.1 )
366 "all_roots: multiple root?"<<b->template
domain<Real>() <<std::endl;
367 std::cout<< b->poly()<<
" , "<<b->template width<Real>()<<std::endl;
368 std::cout<<
"source: "<<ir.poly()<<std::endl;
383 tmp->shift_box( lower );
389 tmp =
new BOX( *b ) ;
394 if ( p( ev ) == Real(0) )
395 { tmp =
new BOX(zero, b->hom() ) ;
396 uboxes.push ( tmp ); }
398 tmp =
new BOX( *b ) ;
399 tmp->reverse_and_shift_box( 1 );
400 tmp->reverse_box( 1 );
418 typename POL::scalar_t t(1);
424 return( a.template point<Real>(t) );
433 typedef typename POL::scalar_t
C;
434 BOX * l, * r=
new BOX( first_root() ) ;
437 if ( r->poly()==
POL(-1) )
440 if (r->poly()==
POL(0) )
441 return( r->template point<Real>(t) );
445 while ( r->template width<Real>() > eps )
449 if ( r->poly()( t ) == 0 )
return( r->template point<Real>(t) );
463 r->reverse_and_shift_box(1);
476 typedef typename POL::scalar_t
C;
478 BOX * l, * r=
new BOX( first_root() ) ;
481 if ( r->poly()==
POL(-1) )
484 if (r->poly()==
POL(0) )
485 return( r->template point<Real>(t) );
490 if ( r->poly() ==
POL(0) )
return as<Real> (floor(as<double>(r->template point<Real>(t))) );
494 if ( r->poly()( t ) == 0 )
return as<Real>( floor(as<double>(r->template point<Real>(t))) );
509 r->reverse_and_shift_box();
515 return as<Real>( floor(as<double>(I.
m)) );
523 typename POL::scalar_t t(1);
525 for (
unsigned i=0; i<a.
size(); ++i)
526 if (a[i].poly()==
POL(0) )
540 ints= all_roots_isolate();
541 for (
unsigned i=1; i<ints.
size(); ++i)
542 sep << (ints[i-1].M + ints[i].m)*Real(0.5) ;
554 solve(
const POL& p,
const base_t& u,
const base_t& v);
565 template<
class Real,
class POL>
581 template<
class Real,
class POL>
598 template<
class Real,
class POL>
static Real
599 solve(
const POL& p,
const base_t& u,
const base_t& v);
601 template<
class Real,
class POL>
static Real
610 template<
class Real,
class POL>
627 template<
class Real,
class POL>
644 template<
class Real,
class POL>
static Real
645 solve(
const POL& p,
const base_t& u,
const base_t& v);
647 template<
class Real,
class POL>
static Real
656 template<
class Real,
class POL>
671 template<
class Real,
class POL>
689 solve(
const POL& p,
const base_t& u,
const base_t& v);
699 template<
class Real,
class POL>
714 template<
class Real,
class POL>
731 template<
class Real,
class POL>
static Seq<Real>
732 solve(
const POL& p,
const base_t& u,
const base_t& v);
734 template<
class Real,
class POL>
static Seq<Real>
742 template<
class Real,
class POL>
757 template<
class Real,
class POL>
772 template<
class POL>
static bool
797 #endif // _realroot_SOLVER_FIRST_ROOT_CONFRAC_H
Real first_root_floor()
Definition: solver_ucf.hpp:473
void reciprocal_hom(const real &t)
Definition: homography.hpp:26
void reverse_box(const C &t=1)
Definition: solver_ucf.hpp:175
Sequence of terms with reference counter.
Definition: Seq.hpp:28
T pow(const T &a, int i)
Definition: binomials.hpp:12
Definition: solver_ucf.hpp:26
const C & b
Definition: Interval_glue.hpp:25
Definition: univariate_bounds.hpp:409
Definition: solver_ucf.hpp:24
#define BOX
Definition: solver_mv_monomial.hpp:35
Real width()
Definition: solver_ucf.hpp:120
C middle()
Definition: solver_ucf.hpp:133
const Interval & I
Definition: Interval_glue.hpp:49
static Solutions solve(const POL &p)
Definition: solver.hpp:75
MP swap(const MP &P, int var_i, int var_j)
Definition: sparse_monomials.hpp:988
interval_rep(const POL p, C u, C v)
Definition: solver_ucf.hpp:71
real a
Definition: homography.hpp:17
void shift_box(const C &t)
Definition: solver_ucf.hpp:150
Real eps
Definition: solver_ucf.hpp:213
void contract_box(const C &t)
Definition: solver_ucf.hpp:163
Ring::scalar_t base_t
Definition: solver_ucf.hpp:596
Definition: solver_ucf.hpp:23
void print()
Definition: solver_ucf.hpp:193
Definition: solver_ucf.hpp:28
Definition: fatarcs.hpp:23
Ring::Scalar base_t
Definition: solver_ucf.hpp:642
Definition: solver_ucf.hpp:47
Seq< Real > all_roots_separate()
Definition: solver_ucf.hpp:535
interval_rep(const POL p, homography< C > h)
Definition: solver_ucf.hpp:64
interval_rep(const POL p)
Definition: solver_ucf.hpp:58
#define TMPL
Definition: solver_ucf.hpp:17
real c
Definition: homography.hpp:17
size_type size() const
Definition: Seq.hpp:166
Seq< Interval< Real > > all_roots_isolate()
Definition: solver_ucf.hpp:519
Real point(C &t)
Definition: solver_ucf.hpp:127
Definition: solver_ucf.hpp:25
static RT lower_bound(const Poly &f)
Definition: univariate_bounds.hpp:413
homography< C > hom()
Definition: solver_ucf.hpp:85
Ring::Scalar base_t
Definition: solver_ucf.hpp:686
Definition: solver.hpp:68
Interval< Real > first_root_isolate()
Definition: solver_ucf.hpp:415
void contract_hom(const real &t)
Definition: homography.hpp:29
Ring::scalar_t base_t
Definition: solver_ucf.hpp:551
void shift_hom(const real &t)
Definition: homography.hpp:23
T lower(const Interval< T, r > &x)
Definition: Interval_fcts.hpp:87
TMPL POL
Definition: polynomial_dual.hpp:74
unsigned sign_var()
Definition: solver_ucf.hpp:143
Definition: solver_ucf.hpp:27
Seq< interval_rep< POL > > all_roots()
Definition: solver_ucf.hpp:321
Interval< Real > domain()
Definition: solver_ucf.hpp:89
#define Scalar
Definition: polynomial_operators.hpp:12
real b
Definition: homography.hpp:17
#define N_ITER
Definition: solver_ucf.hpp:19
Generic class for intervals.
Definition: Interval.hpp:44
T m
Definition: Interval.hpp:52
solver_cffirst(interval_rep< POL > p)
Definition: solver_ucf.hpp:215
interval_rep< POL > first_root()
Definition: solver_ucf.hpp:235
double C
Definition: solver_mv_fatarcs.cpp:16
Real first_root_approximate()
Definition: solver_ucf.hpp:430
unsigned sign_variation(Iterator b, Iterator e)
Definition: sign_variation.hpp:27
POL poly()
Definition: solver_ucf.hpp:83
Definition: solver_ucf.hpp:210
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Ring::Scalar base_t
Definition: solver_ucf.hpp:729
double rfloor(double x)
Definition: scalar.hpp:535
interval_rep()
Definition: solver_ucf.hpp:56
#define TMPLR
Definition: solver_ucf.hpp:18
real d
Definition: homography.hpp:17
interval_rep< POL > ir
Definition: solver_ucf.hpp:212
void reverse_and_shift_box(const C &t=1)
Definition: solver_ucf.hpp:187
T M
Definition: Interval.hpp:52