realroot_doc 0.1.1
|
#include <solver_ucf.hpp>
Definition at line 210 of file solver_ucf.hpp.
solver_cffirst | ( | interval_rep< POL > | p | ) | [inline] |
Definition at line 215 of file solver_ucf.hpp.
References solver_cffirst< Real, POL >::eps, and solver_cffirst< Real, POL >::ir.
Seq< interval_rep< POL > > all_roots | ( | ) |
Definition at line 321 of file solver_ucf.hpp.
References mmx::let::assign(), BOX, mmx::lower(), AkritasBound< RT >::lower_bound(), N_ITER, and POL.
{ typedef interval_rep<POL> BOX; std::stack<BOX * > uboxes; typedef typename POL::scalar_t C; Real ev(0); Seq<interval_rep<POL> > sols; POL zero(0); Interval<Real> mid(0); BOX * b, * tmp; POL p; unsigned s, iters=0; Interval<Real> I; AkritasBound<C> lb; //HongBound<C> lb; //Kioustelidis<C> lb; //NISP<C> lb; //Cauchy<C> lb; C lower; b= new BOX(ir); uboxes.push (b); while ( !uboxes.empty() && iters++ < N_ITER ) { b = uboxes.top() ; p = b->poly() ; uboxes.pop(); if ( p==zero && (!uboxes.empty()) ) { sols<< *b;} I = b->template domain<Real>(); // Interval<Real> ev= p( I ) ; // if ( ev.m * ev.M > 0 ) continue; s = b->sign_var() ; if ( s==1 && (!uboxes.empty()) ) { sols << *b; continue; } if ( s > 0 ) { if ( (!uboxes.empty()) && b->template width<Real>() < eps*.1 ) {std::cout<< "all_roots: multiple root?"<<b->template domain<Real>() <<std::endl; std::cout<< b->poly()<<" , "<<b->template width<Real>()<<std::endl; std::cout<<"source: "<<ir.poly()<<std::endl; } else { lower= lb.lower_bound(p) ; if ( lower!=0 ) { let::assign(ev,lower); if ( p(ev) == 0 ) sols<< *b; tmp= new BOX( *b ) ; free(b); tmp->shift_box( lower ); uboxes.push (tmp); } else { // right box tmp = new BOX( *b ) ; tmp->shift_box( 1 ); uboxes.push ( tmp ); //middle if needed ev=1; if ( p( ev ) == Real(0) ) { tmp = new BOX(zero, b->hom() ) ; uboxes.push ( tmp ); } //left tmp = new BOX( *b ) ; tmp->reverse_and_shift_box( 1 ); tmp->reverse_box( 1 ); uboxes.push ( tmp ); free(b); } } } } return sols; }
Definition at line 519 of file solver_ucf.hpp.
References POL, and Seq< C, R >::size().
Referenced by solver< Ring, CFdecide >::solve(), and solver< Ring, CFallIsolate >::solve().
{ Seq<interval_rep<POL> > a( all_roots() ); Seq<Interval<Real> > s; typename POL::scalar_t t(1); for ( unsigned i=0; i<a.size(); ++i) if (a[i].poly()==POL(0) ) s<< Interval<Real>(a[i].template point<Real>(t) ); else s<< a[i].template domain<Real>(); return s; }
Seq< Real > all_roots_separate | ( | ) |
Definition at line 535 of file solver_ucf.hpp.
References Seq< C, R >::size().
Referenced by solver< Ring, CFseparate >::solve().
{ Seq< Interval<Real> > ints; Seq<Real> sep; ints= all_roots_isolate(); for (unsigned i=1; i<ints.size(); ++i) sep << (ints[i-1].M + ints[i].m)*Real(0.5) ; return sep; }
interval_rep< POL > first_root | ( | ) |
Definition at line 235 of file solver_ucf.hpp.
References BOX, mmx::lower(), AkritasBound< RT >::lower_bound(), N_ITER, and POL.
{ typedef interval_rep<POL> BOX; std::stack<BOX * > uboxes; typedef typename POL::scalar_t C; POL zero(0); Interval<Real> mid(0); BOX * b, * tmp; POL p; unsigned s, iters=0; Interval<Real> I; AkritasBound<C> lb; //HongBound<C> lb; //Kioustelidis<C> lb; //NISP<C> lb; //Cauchy<C> lb; C lower; b= new BOX(ir); uboxes.push (b); while ( !uboxes.empty() && iters++ < N_ITER ) { b = uboxes.top() ; p = b->poly() ; uboxes.pop(); if ( p==zero && (!uboxes.empty()) ) { return *b;} s = b->sign_var() ; I = b->template domain<Real>(); if ( s==1 && (!uboxes.empty()) ) { return *b;} if ( s > 0 ) { if ( b->template width<Real>() < eps ) {std::cout<< "first_root: multiple root?"<<b->template domain<Real>() <<std::endl;} else { lower= lb.lower_bound(p) ; if ( lower!=0 ) { if ( p( lower ) == 0 ) return *b; tmp= new BOX( *b ) ; free(b); tmp->shift_box( lower ); uboxes.push (tmp); } else { // right box tmp = new BOX( *b ) ; tmp->shift_box( 1 ); uboxes.push ( tmp ); //middle if needed if ( p( Real(1) ) == Real(0) ) { tmp = new BOX(zero, b->hom() ) ; uboxes.push ( tmp ); } //left tmp = new BOX( *b ) ; tmp->reverse_and_shift_box( 1 ); tmp->reverse_box( 1 ); uboxes.push ( tmp ); free(b); } } } } /* -1 = No positive root */ return BOX(-1); }
Real first_root_approximate | ( | ) |
Definition at line 430 of file solver_ucf.hpp.
Referenced by solver< Ring, CFfirstApproximate >::solve().
{ typedef interval_rep<POL> BOX; typedef typename POL::scalar_t C; BOX * l, * r= new BOX( first_root() ) ; C t(1); if ( r->poly()== POL(-1) ) return (0); else if (r->poly()==POL(0) ) return( r->template point<Real>(t) ); else { /* Approximate */ while ( r->template width<Real>() > eps ) { t= r->middle(); if ( r->poly()( t ) == 0 ) return( r->template point<Real>(t) ); l= new BOX( *r) ; l->shift_box( t ); if ( l->sign_var() ) { free(r); r=l; continue; } else { free(l); r->contract_box(t); r->reverse_and_shift_box(1); r->reverse_box(1); } } return ( r->template domain<Real>() ); } }
Real first_root_floor | ( | ) |
Definition at line 473 of file solver_ucf.hpp.
References BOX, Interval< T, r >::M, Interval< T, r >::m, POL, and mmx::rfloor().
Referenced by solver< Ring, CFfirstFloor >::solve().
{ typedef interval_rep<POL> BOX; typedef typename POL::scalar_t C; BOX * l, * r= new BOX( first_root() ) ; Interval<Real> I; C t(1); if ( r->poly()== POL(-1) ) return (0); else if (r->poly()==POL(0) ) return( r->template point<Real>(t) ); else { I= r->template domain<Real>(); if ( r->poly() == POL(0) ) return as<Real> (floor(as<double>(r->template point<Real>(t))) ); while ( rfloor(I.m)!=rfloor(I.M) ) { t= r->middle(); if ( r->poly()( t ) == 0 ) return as<Real>( floor(as<double>(r->template point<Real>(t))) ); l= new BOX( *r) ; l->shift_box( t ); if ( l->sign_var() ) { free(r); r=l; I= r->template domain<Real>(); continue; } else { free(l); r->reverse_and_shift_box(); r->reverse_box(); I= r->template domain<Real>(); } } } return as<Real>( floor(as<double>(I.m)) ); }/*first_root_floor*/
Interval< Real > first_root_isolate | ( | ) |
Definition at line 415 of file solver_ucf.hpp.
References POL, and interval_rep< POL >::poly().
Referenced by solver< Ring, CFfirstIsolate >::solve().
{ interval_rep<POL> a( first_root() ); typename POL::scalar_t t(1); if ( a.poly()== POL(-1) ) return (0); else if (a.poly()==POL(0) ) return( a.template point<Real>(t) ); else return ( a.template domain<Real>() ); }
Real eps |
Definition at line 213 of file solver_ucf.hpp.
Referenced by solver_cffirst< Real, POL >::solver_cffirst().
interval_rep<POL> ir |
Definition at line 212 of file solver_ucf.hpp.
Referenced by solver_cffirst< Real, POL >::solver_cffirst().