All Classes Functions Friends
regularchain.h
1 #ifndef _QREGULARCHAIN_H_
2 #define _QREGULARCHAIN_H_
3 
4 /**
5  * Data Structure for regular chains
6  * using univariate & multivariate rational polynomial
7  **/
8 
9 #include "../globals.h"
10 #include "../URPolynomial/urpolynomial.h"
11 #include "../MRPolynomial/mrpolynomial.h"
12 
14  private:
15  int var; // Number of variables
16  DenseUnivariateRationalPolynomial p; // Univariate
17  SparseMultivariateRationalPolynomial* mps; // Multivariates
18  std::string* names; // Variable names, names[0] < names[1] < ...
19 
20  /* Real Root Isolation */
21  int rcRealRootIsolation(Intervals*, lfixq, int);
22  void refineMultivariateInterval(Intervals*, lfixq, int);
23  void isolatePositiveMultivariateRealRoots(Intervals*, Intervals*, int, int, lfixq, int);
24  void isolateMultivariateRealRoots(Intervals*, Intervals*, int, lfixq, int ts);
25  public:
26  /**
27  * Default constructor
28  *
29  * @param
30  **/
31  RationalRegularChain () : var(0) {}
32  /**
33  * Constructor with number of variables and variable names
34  *
35  * @param v: Number of variables
36  * @param xs: Variable names
37  **/
38  RationalRegularChain (int v, std::string* xs) {
39  if (v > 0) {
40  var = v;
41  if (v > 1)
42  mps = new SparseMultivariateRationalPolynomial[var-1];
43  if (xs != NULL) {
44  names = new std::string[var];
45  for (int i = 0, j = var-1; i < v; ++i, --j)
46  names[j] = xs[i];
47  }
48  else {
49  std::cout << "BPAS: error, RationalRegularChain must be defined with variables." << std::endl;
50  exit(1);
51  }
52  }
53  else { var = 0; }
54  }
55  /**
56  * Copy constructor
57  *
58  * @param rc: A regular chain
59  **/
60  RationalRegularChain (const RationalRegularChain& rc) : var(rc.var), p(rc.p) {
61  mps = new SparseMultivariateRationalPolynomial[var-1];
62  std::copy(rc.mps, rc.mps+var-1, mps);
63  names = new std::string[var];
64  std::copy(rc.names, rc.names+var, names);
65  }
66  /**
67  * Destructor
68  *
69  * @param
70  **/
72  if (var > 1) { delete [] mps; }
73  if (names != NULL) { delete [] names; }
74  }
75  /**
76  * Number of variables
77  *
78  * @param
79  **/
81  return var;
82  }
83  /**
84  * Variables
85  *
86  * @param
87  **/
88  std::vector<std::string> variables() {
89  std::vector<std::string> xs;
90  for (int i = var-1; i > -1; --i)
91  xs.push_back(names[i]);
92  return xs;
93  }
94 
95  /**
96  * Overload operator =
97  *
98  * @param rc: A regular chain
99  **/
101  if (this != &rc) {
102  var = rc.var;
103  p = rc.p;
104  delete [] mps;
105  mps = new SparseMultivariateRationalPolynomial[var-1];
106  std::copy(rc.mps, rc.mps+var-1, mps); delete [] names;
107  names = new std::string[var];
108  std::copy(rc.names, rc.names+var, names);
109  }
110  return *this;
111  }
112 
113  /**
114  * Overload operator +
115  *
116  * @param up: A univariate polynomial
117  **/
119  RationalRegularChain r (*this);
120  return (r += up);
121  }
122  /**
123  * Overload operator +=
124  *
125  * @param up: A univariate polynomial
126  **/
128  /**
129  * Overload operator +
130  *
131  * @param mp: A multivariate polynomial
132  **/
134  RationalRegularChain r (*this);
135  return (r += mp);
136  }
137  /**
138  * Overload operator +=
139  *
140  * @param mp: A multivariate polynomial
141  **/
143 
144  /**
145  * Select a polynomial given the leading variable
146  *
147  * @param x: The leading variable name
148  **/
150 
151  /**
152  * The regular chain under a variable
153  *
154  * @param x: The variable name
155  **/
156  RationalRegularChain under (std::string x);
157 
158  /**
159  * The regular chain upper a variable
160  *
161  * @param x: The variable name
162  **/
163  inline RationalRegularChain upper (std::string x) {
164  return RationalRegularChain();
165  }
166 
167  /**
168  * Real root isolation
169  *
170  * @param width: The interval's width
171  * @param ts: Taylor Shift option
172  **/
173  inline Intervals realRootIsolate (mpq_class width, int ts=-1) {
174  Intervals pIs;
175  rcRealRootIsolation(&pIs, width, ts);
177  return pIs;
178  }
179 
180  /**
181  * Overload stream operator <<
182  *
183  * @param out: Stream object
184  * @param rc: A regular chain
185  **/
186  friend std::ostream& operator<< (std::ostream &out, RationalRegularChain& rc);
187 };
188 
189 /**
190  * Real root isolation on a vector of RationalRegularChain
191  *
192  * @param chains, defined as std::vector<RationalRegularChain> chains (<size>, RationalRegularChain(<# of variables>, <variable names>));
193  * @param width: Interval's width
194  * @param ts: Taylor shift option
195  **/
196 Intervals RealRootIsolation (std::vector<RationalRegularChain> chains, lfixq width, int ts=-1);
197 
198 #endif
199 /* This file is part of the BPAS library http://www.bpaslib.org
200 
201  BPAS is free software: you can redistribute it and/or modify
202  it under the terms of the GNU General Public License as published by
203  the Free Software Foundation, either version 3 of the License, or
204  (at your option) any later version.
205 
206  BPAS is distributed in the hope that it will be useful,
207  but WITHOUT ANY WARRANTY; without even the implied warranty of
208  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
209  GNU General Public License for more details.
210 
211  You should have received a copy of the GNU General Public License
212  along with BPAS. If not, see <http://www.gnu.org/licenses/>.
213 
214  Copyright: Changbo Chen <changbo.chen@hotmail.com>
215  Farnam Mansouri <mansouri.farnam@gmail.com>
216  Marc Moreno Maza <moreno@csd.uwo.ca>
217  Ning Xie <nxie6@csd.uwo.ca>
218  Yuzhen Xie <yuzhenxie@yahoo.ca>
219 
220 */
221 
222 
Definition: regularchain.h:13
RationalRegularChain & operator=(RationalRegularChain rc)
Definition: regularchain.h:100
friend std::ostream & operator<<(std::ostream &out, RationalRegularChain &rc)
Definition: mrpolynomial.h:27
Intervals realRootIsolate(mpq_class width, int ts=-1)
Definition: regularchain.h:173
~RationalRegularChain()
Definition: regularchain.h:71
void setVariableNames(std::vector< std::string > xs)
Definition: interval.h:191
Definition: urpolynomial.h:16
SparseMultivariateRationalPolynomial select(std::string x)
RationalRegularChain(const RationalRegularChain &rc)
Definition: regularchain.h:60
RationalRegularChain under(std::string x)
RationalRegularChain upper(std::string x)
Definition: regularchain.h:163
Definition: polynomial.h:107
RationalRegularChain()
Definition: regularchain.h:31
Definition: interval.h:35
RationalRegularChain operator+(DenseUnivariateRationalPolynomial up)
Definition: regularchain.h:118
RationalRegularChain & operator+=(DenseUnivariateRationalPolynomial up)
std::vector< std::string > variables()
Definition: regularchain.h:88
RationalRegularChain(int v, std::string *xs)
Definition: regularchain.h:38
int numberOfVariables()
Definition: regularchain.h:80