Developer documentation

cell_mv_bernstein.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * M a t h e m a g i x
3  *****************************************************************************
4  * cell for bernstein systems
5  * 2010-02-16
6  *****************************************************************************
7  * Copyright (C) 2010 INRIA Sophia-Antipolis
8  *****************************************************************************
9  * Comments :
10  ****************************************************************************/
11 # ifndef realroot_cell_mv_bernstein_hpp
12 # define realroot_cell_mv_bernstein_hpp
13 
14 # include <realroot/Seq.hpp>
16 # include <realroot/Interval.hpp>
19 
20 # undef C
21 # define TMPL template<typename C>
22 # define SELF cell_mv_bernstein<C>
23 
24 //====================================================================
25 namespace mmx {
26 
27 
28 TMPL
30 
31 public:
32 
33  typedef C Scalar;
35 
36  cell_mv_bernstein(void) ;
37  cell_mv_bernstein(const Polynomial& p) {
38  m_doms<<Interval<double>(0,1);
39  m_equs<<p;
40  }
42  for(unsigned i=0;i<E.size();i++) m_doms<<Interval<double>(0,1);
43  for(unsigned i=0;i<E.size();i++) m_equs<<E[i];
44  }
45 
47  for(unsigned i=0;i<D.size();i++) m_doms<<D[i];
48  for(unsigned i=0;i<E.size();i++) m_equs<<E[i];
49  }
50 
51  template<class POL>
53  Seq<double> dmn;
54  for(unsigned i=0;i<D.size();i++) {
55  m_doms<<D[i];
56  dmn <<D[i].lower() <<D[i].upper();
57  }
58 
59  for(unsigned i=0;i<E.size();i++) {
60  Polynomial p;
61  let::assign(p,E[i],dmn);
62  m_equs<<p;
63  }
64  }
65 
66  ~cell_mv_bernstein(void) ;
67 
68  unsigned nbeq() const {return m_equs.size();}
69  unsigned nbeq() {return m_equs.size();}
70 
71  Polynomial equation(unsigned i) const {return m_equs[i];}
72  Polynomial& equation(unsigned i) {return m_equs[i];}
73 
74  unsigned nbvar() const {return m_doms.size();}
75  unsigned nbvar() {return m_doms.size();}
76 
77  Seq<Interval<double> > domain() const {return m_doms;}
78  Seq<Interval<double> >& domain() {return m_doms;}
79 
80  Interval<double> domain(unsigned i) const {return m_doms[i];}
81  Interval<double>& domain(unsigned i) {return m_doms[i];}
82 
83  C size(void) const {
84  C s=0;
85  for(unsigned i=0;i<m_doms.size();i++)
86  s=std::max(s,m_doms[i].upper()-m_doms[i].lower());
87  return s;
88  }
89 
90 
91 private:
92  Seq<Polynomial> m_equs;
93  Seq<Interval<double> > m_doms;
94 };
95 
96 //--------------------------------------------------------------------
97 TMPL
98 SELF::cell_mv_bernstein(void) {}
99 
100 TMPL
101 SELF::~cell_mv_bernstein(void) {}
102 
103 //--------------------------------------------------------------------
105 
106  static double m_eps;
107 
108  template<class Cell, class Stack>
109  static void subdivide(Cell* cl, Stack* stack);
110 
111  template<class Cell>
112  static bool reduce(Cell* cl);
113 
114  template<class Cell>
115  static bool regular(Cell* cl);
116 
117 } ;
118 
119 double binary_approx::m_eps=1e-6;
120 
121 template<class Cell, class Stack> void
123  //std::cout<<"Subdivide "<<cl->equation(0)<< " "<<cl->domain(0)<<std::endl;
124 
125  Cell* left = new Cell(*cl);
126  Cell* right = new Cell(*cl);
127 
128  unsigned v=0;
129  typename Cell::Scalar s=cl->domain(0).upper()-cl->domain(0).lower(),s0;
130  for (unsigned i=0;i<cl->nbvar();i++)
131  if((s0=cl->domain(i).upper()-cl->domain(i).lower())>s) {
132  s=s0;v=i;
133  }
134  typename Cell::Scalar m=(cl->domain(v).upper()+cl->domain(v).lower())/2;
135 
136  for (unsigned i=0;i<cl->nbeq();i++)
137  tensor::split(left->equation(i), right->equation(i), v);
138  left->domain(v).upper()=m;
139  right->domain(v).lower()=m;
140 
141  // std::cout<<"==> "<<left->equation(0)<< " "<<left->domain(0)<<std::endl;
142  // std::cout<<"==> "<<right->equation(0)<< " "<<right->domain(0)<<std::endl;
143  // std::cout<<std::endl;
144 
145  st->push(left);
146  st->push(right);
147 };
148 
149 template<class Cell> bool
151  if(cl->size() < m_eps) return false;
152  for(unsigned i=0;i<cl->nbeq();i++)
153  if(!has_sign_variation(cl->equation(i))) return false;
154  return true;
155 }
156 
157 template<class Cell> bool
159  for(unsigned i=0;i<cl->nbeq();i++)
160  if(!has_sign_variation(cl->equation(i))) return false;
161  return true;
162 }
163 
164 //--------------------------------------------------------------------
166 
167  template<class Cell>
168  static bool reduce(Cell* cl);
169 
170 } ;
171 
172 template<class Cell> bool
174  if(cl->size() < m_eps) return false;
175  std::cout<<"isolate"<<std::endl;
176  for(unsigned i=0;i<cl->nbeq();i++)
177  if(!has_sign_variation(cl->equation(i))) return false;
178 
179 
180  return true;
181 }
182 
183 //====================================================================
184 } // namespace mmx
185 //====================================================================
186 # undef TMPL
187 # undef SELF
188 # endif
Seq< Interval< double > > & domain()
Definition: cell_mv_bernstein.hpp:78
Sequence of terms with reference counter.
Definition: Seq.hpp:28
Definition: cell_mv_bernstein.hpp:29
Seq< Interval< double > > domain() const
Definition: cell_mv_bernstein.hpp:77
#define TMPL
Definition: cell_mv_bernstein.hpp:21
polynomial< C, with< Bernstein > > Polynomial
Definition: cell_mv_bernstein.hpp:34
cell_mv_bernstein(const Seq< Polynomial > &E, const Seq< Interval< double > > &D)
Definition: cell_mv_bernstein.hpp:46
T upper(const Interval< T, r > &x)
Definition: Interval_fcts.hpp:89
cell_mv_bernstein(const Seq< POL > &E, const Seq< Interval< double > > &D)
Definition: cell_mv_bernstein.hpp:52
static void subdivide(Cell *cl, Stack *stack)
Definition: cell_mv_bernstein.hpp:122
C size(void) const
Definition: cell_mv_bernstein.hpp:83
unsigned nbvar() const
Definition: cell_mv_bernstein.hpp:74
unsigned nbvar()
Definition: cell_mv_bernstein.hpp:75
static double m_eps
Definition: cell_mv_bernstein.hpp:106
size_type size() const
Definition: Seq.hpp:166
Definition: cell_mv_bernstein.hpp:165
unsigned nbeq() const
Definition: cell_mv_bernstein.hpp:68
Interval< double > domain(unsigned i) const
Definition: cell_mv_bernstein.hpp:80
Definition: polynomial.hpp:37
cell_mv_bernstein(const Polynomial &p)
Definition: cell_mv_bernstein.hpp:37
unsigned nbeq()
Definition: cell_mv_bernstein.hpp:69
TMPL void split(Polynomial &r, Polynomial &p, int v)
Definition: polynomial_fcts.hpp:193
#define Scalar
Definition: polynomial_operators.hpp:12
Polynomial & equation(unsigned i)
Definition: cell_mv_bernstein.hpp:72
static bool regular(Cell *cl)
Definition: cell_mv_bernstein.hpp:158
C Scalar
Definition: cell_mv_bernstein.hpp:33
double C
Definition: solver_mv_fatarcs.cpp:16
Definition: cell_mv_bernstein.hpp:104
static bool reduce(Cell *cl)
Definition: cell_mv_bernstein.hpp:150
#define Stack
Definition: subdivisor.hpp:19
Polynomial equation(unsigned i) const
Definition: cell_mv_bernstein.hpp:71
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
bool has_sign_variation(Iterator b, Iterator e)
Definition: sign_variation.hpp:84
Interval< T, r > max(const Interval< T, r > &a, const Interval< T, r > &b)
Definition: Interval_fcts.hpp:135
static bool reduce(Cell *cl)
Definition: cell_mv_bernstein.hpp:173
Definition: array.hpp:12
cell_mv_bernstein(const Seq< Polynomial > &E)
Definition: cell_mv_bernstein.hpp:41
Interval< double > & domain(unsigned i)
Definition: cell_mv_bernstein.hpp:81
Home