6 #ifndef realroot_SOLVE_SBDSLV_USOLVER_DESCARTES1D_HPP
7 #define realroot_SOLVE_SBDSLV_USOLVER_DESCARTES1D_HPP
17 template<
typename Prms >
24 template<
class real_t>
34 bsearch(
const In& bzrep,
unsigned sz ) : m_sz(sz)
36 m_data =
new real_t[ 2*sz ];
44 void reach( real_t * lbzrep, real_t& a, real_t&
b,
const real_t& eps )
47 if ( lbzrep[m_sz-1] > lbzrep[0] )
58 template<
class real_t>
67 m_data =
new real_t[ sz ];
73 void reach( real_t * lbzrep, real_t& a, real_t&
b,
const real_t& eps )
76 if ( lbzrep[m_sz-1] > lbzrep[0] )
78 if (
brnops::eval( m_data, m_sz, m = (a+b)/2.0 ) < 0 ) a = m;
else b = m;
82 if (
brnops::eval( m_data, m_sz, m = (a+b)/2.0 ) < 0 ) b = m;
else a = m;
87 template<
class real_t>
97 m_data =
new real_t[ 2*sz ];
100 std::copy( m_data, m_data + sz, m_mons );
106 void reach( real_t * lbzrep, real_t& a, real_t&
b,
const real_t& eps )
109 if ( lbzrep[m_sz-1] > lbzrep[0] )
116 if ( p < 0 ) a = m;
else b = m;
122 if ( x > a && x < b )
127 if ( xp < 0 ) a = x;
else b = x;
132 while( xp < 0 && x < b )
143 while( xp > 0 && x > a )
160 if ( p < 0 ) b = m;
else a = m;
164 if ( x > a && x < b )
167 if ( xp < 0 ) b = x;
else a = x;
171 while( xp < 0 && x > a )
182 while( xp > 0 && x < b )
197 template<
class real_t>
206 m_data =
new real_t[ 2*sz ];
208 m_mons = m_data + sz;
209 std::copy( m_data, m_data + sz, m_mons );
214 void reach( real_t * lbzrep, real_t& a, real_t&
b,
const real_t& eps )
217 if ( lbzrep[m_sz-1] > lbzrep[0] )
228 if ( p < 0 ) a = m;
else b = m;
242 if ( x > a && x < b )
248 if ( p > 0 ) b = x+eps;
254 if ( p < 0 ) a = x-eps/2;
266 if ( p < 0 ) b = m;
else a = m;
281 if ( x > a && x < b )
287 if ( p > 0 ) a = x-eps/2;
293 if ( p < 0 ) b = x-eps/2;
302 template<
class real_t,
class local_method = bsearch< real_t > >
312 void reset(
unsigned sz,
const real_t& prec )
314 if ( sz <= m_sz && prec >= m_prec )
320 m_sz = sz; m_prec = prec;
326 real_t * l = r+m_sz+2;
329 l[m_sz+1] = (r[
m_sz]+r[m_sz+1])/2.0;
353 std::cout << i0 <<
", " << (1.0-i1) << std::endl;
357 i0 = (1.0-i0)*nxt[m_sz] + i0*nxt[m_sz+1];
358 i1 = (1.0-i1)*nxt[m_sz] + i1*nxt[m_sz+1];
366 inline void set_sz(
unsigned sz ) { m_sz = sz;};
368 template<
class Prms >
inline
370 { prms.output( stck[m_sz], stck[m_sz+1], stck[0] > 0, stck[m_sz-1] > 0 ); };
371 template<
class Prms >
inline
373 { prms.output( stck[m_sz], stck[m_sz+1] ); };
375 template<
class Prms >
inline
379 template<
class Prms,
class In>
380 unsigned solve( Prms& prms,
const In&
in,
int option = 0 )
382 for (
unsigned i = 0; i <
m_sz; i ++ ) m_stck[i] = in[i];
383 m_stck[
m_sz] = 0.0; m_stck[m_sz+1] = 1.0;
385 const unsigned inc = m_sz+2;
387 real_t * stop = stck-inc;
398 if ( !option || (roots == option) )
400 if ( m_lmth == 0 ) m_lmth =
new local_method(in,m_sz);
401 m_lmth->reach( stck, stck[m_sz], stck[m_sz+1], m_prec );
410 if ( !option || (roots == option) )
output(prms,stck);
419 while( stck != stop );
420 if ( m_lmth ) {
delete m_lmth; m_lmth = 0; };
432 unsigned maxdeep = 1;
434 while ( ex > m_prec ) { ex/=2; maxdeep ++ ; };
438 unsigned tsz = maxdeep*(2+
m_sz);
439 m_stck =
new real_t[ tsz ];
bsearch_newton(const In &bzrep, unsigned sz)
Definition: system_descartes1d.hpp:95
void output(Prms &prms, real_t *stck)
Definition: system_descartes1d.hpp:376
real_t * m_mons
Definition: system_descartes1d.hpp:28
const C & b
Definition: Interval_glue.hpp:25
real_t eval(real_t const *const src, unsigned sz, const real_t &t, int st=1)
Definition: loops_brnops.hpp:47
bsearch(const In &bzrep, unsigned sz)
Definition: system_descartes1d.hpp:34
void output(Prms &prms, real_t *stck, const texp::true_t &)
Definition: system_descartes1d.hpp:369
unsigned sgncnt(real_t const *b, unsigned sz, int st=1)
Definition: loops_vctops.hpp:144
unsigned m_sz
Definition: system_descartes1d.hpp:62
void decasteljau(real_t *r, unsigned sz, const real_t &t, int str=1)
Definition: loops_brnops.hpp:23
void reach(real_t *lbzrep, real_t &a, real_t &b, const real_t &eps)
Definition: system_descartes1d.hpp:44
void reach(real_t *lbzrep, real_t &a, real_t &b, const real_t &eps)
Definition: system_descartes1d.hpp:73
real_t * m_data
Definition: system_descartes1d.hpp:90
real_t * m_data
Definition: system_descartes1d.hpp:200
Definition: system_descartes1d.hpp:88
unsigned m_sz
Definition: system_descartes1d.hpp:202
~bsearch()
Definition: system_descartes1d.hpp:42
unsigned m_sz
Definition: system_descartes1d.hpp:92
Definition: system_descartes1d.hpp:198
unsigned m_sz
Definition: system_descartes1d.hpp:306
real_t * m_mons
Definition: system_descartes1d.hpp:201
bsearch_newton2(const In &bzrep, unsigned sz)
Definition: system_descartes1d.hpp:204
unsigned m_sz
Definition: system_descartes1d.hpp:29
~bsearch_castel()
Definition: system_descartes1d.hpp:70
real_t * m_data
Definition: system_descartes1d.hpp:61
Definition: system_descartes1d.hpp:18
structure defining a positive answer
Definition: texp_bool.hpp:7
unsigned solve(Prms &prms, const In &in, int option=0)
Definition: system_descartes1d.hpp:380
TMPL void copy(Polynomial &r, const Polynomial &a)
Copy of a in r.
Definition: sparse_monomials.hpp:613
bool in(const T &x, const Interval< T, r > &y)
Definition: Interval_fcts.hpp:100
real_t * m_mons
Definition: system_descartes1d.hpp:91
int sgn(FT a)
Sign of a.
Definition: solver_mv_monomial_tests.hpp:416
Definition: system_descartes1d.hpp:25
void toMonoms(T *bzc, size_t sz, int st=1)
Definition: bernstein_bzenv.hpp:64
void reach(real_t *lbzrep, real_t &a, real_t &b, const real_t &eps)
Definition: system_descartes1d.hpp:214
~descartes_solver()
Definition: system_descartes1d.hpp:442
~bsearch_newton()
Definition: system_descartes1d.hpp:103
unsigned m_mxsz
Definition: system_descartes1d.hpp:30
real_t * m_stck
Definition: system_descartes1d.hpp:308
real_t precision(real_t *l)
Definition: system_descartes1d.hpp:332
void split(real_t *r)
Definition: system_descartes1d.hpp:324
void reset(unsigned sz, const real_t &prec)
Definition: system_descartes1d.hpp:312
Definition: system_descartes1d.hpp:59
~bsearch_newton2()
Definition: system_descartes1d.hpp:212
void reach(real_t *lbzrep, real_t &a, real_t &b, const real_t &eps)
Definition: system_descartes1d.hpp:106
void rockwoodcuts(real_t *nxt, real_t *prv, real_t *mid)
Definition: system_descartes1d.hpp:345
descartes_solver(unsigned sz, const real_t &eps=1e-12)
Definition: system_descartes1d.hpp:426
const C & c
Definition: Interval_glue.hpp:45
real_t m_prec
Definition: system_descartes1d.hpp:307
void output(Prms &prms, real_t *stck, const texp::false_t &)
Definition: system_descartes1d.hpp:372
structure defining a negative answer
Definition: texp_bool.hpp:9
texp::false_t result_t
Definition: system_descartes1d.hpp:18
Definition: bernstein_bzenv.hpp:17
bool precision_reached(real_t *l)
Definition: system_descartes1d.hpp:333
bsearch_castel(const In &bzrep, unsigned sz)
Definition: system_descartes1d.hpp:65
void set_sz(unsigned sz)
Definition: system_descartes1d.hpp:366
Definition: system_descartes1d.hpp:303
real_t * m_data
Definition: system_descartes1d.hpp:27
unsigned m_ssz
Definition: system_descartes1d.hpp:306
void horner(parm_t &res, coeff_t const *const mnms, unsigned sz, const parm_t &t, int st=1)
Definition: loops_upoldse.hpp:19
void dhorner(real_t &p, real_t &dp, real_t const *const mnms, unsigned sz, const real_t &t)
Definition: loops_upoldse.hpp:33
bool rockwood_cut(real_t &t, real_t const *b, unsigned sz, int st=1)
Definition: loops_brnops.hpp:155
local_method * m_lmth
Definition: system_descartes1d.hpp:309