APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_tcons0.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_tcons0.hh
3 *
4 * APRON Library / C++ class wrappers
5 *
6 * Copyright (C) Antoine Mine' 2007
7 *
8 */
9/* This file is part of the APRON Library, released under LGPL license
10 with an exception allowing the redistribution of statically linked
11 executables.
12
13 Please read the COPYING file packaged in the distribution.
14*/
15
16#ifndef __APXX_TCONS0_HH
17#define __APXX_TCONS0_HH
18
19#include "ap_tcons0.h"
20#include "apxx_texpr0.hh"
21#include "apxx_lincons0.hh"
22
23
24namespace apron {
25
26/* ================================= */
27/* tcons0 */
28/* ================================= */
29
30
31
32 *
33 * A tcons0 represents a constraint of the form expr==0, expr>=0, expr>0, expr!=0, or expr==0 mod c
34 * where expr is an arbitrary expression tree.
35 * It stores and manages a texpr0, a constraint type (==, >=, >, !=, mod), and (for modulo constraint)
36 * an extra scalar (c).
37 *
38 * Constraints can be constructed using the >=, <=, >, <, ==, != operators on expression trees, or
39 * dedicated constructors:
40 * \code
41 * tcons0 x = dim(1) >= dim(2) * 5;
42 * tcons0 y = add(sqrt(dim(1),AP_RTYPE_FLOAT), dim(0), AP_RTYPE_FLOAT) != 10;
43 * tcons0 y = tcons0(AP_CONS_EQMOD, 3*dim(0)+2*dim(1), 5);
44 * \endcode
45 * See the documentation of the texpr0 class for more information on constructing expression trees.
46 */
47class tcons0 : public use_malloc {
48
49protected:
51 ap_tcons0_t l;
52
54 tcons0(ap_tcons0_t& l);
56 friend class abstract0;
57
58public:
59
60
61 /* constructors */
62 /* ============ */
63
65
72
73 tcons0(ap_constyp_t constyp=AP_CONS_SUPEQ);
74
77
80 tcons0(ap_constyp_t constyp, const texpr0::builder& t);
81
82 /*! \brief Creates a new constraint from an expression tree and a modulo scalar (both copied).
83 *
84 * \arg \c constyp can be \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ.
85 */
86 tcons0(ap_constyp_t constyp, const texpr0::builder& t, const scalar& modulo);
87
89 tcons0(const tcons0& x);
90
91 /*! \brief Makes a (deep) copy of a constraint, and applies a dimension change to the underlying expression.
92 *
93 * \arg \c add whether to add or remove dimensions.
94 */
95 tcons0(const tcons0& x, const dimchange& d, bool add=true);
96
97
98 tcons0(const tcons0& x, const dimperm& d);
99
101 tcons0(unsat x);
102
104
105 * Real-valued addition and multiplication operators are used (i.e., no rounding).
106 */
107 tcons0(const lincons0& x);
108
109
111
112 /* destructor */
113 /* ========== */
114
117
118
120
122
123 /* 'Intelligent' constructors */
124 /* ========================== */
125
126 /** @name 'Intelligent' constructors */
128
130 friend tcons0 operator>=(const texpr0::builder& a, const texpr0::builder& b);
131
132
133 friend tcons0 operator<=(const texpr0::builder& a, const texpr0::builder& b);
134
136 friend tcons0 operator> (const texpr0::builder& a, const texpr0::builder& b);
139 friend tcons0 operator< (const texpr0::builder& a, const texpr0::builder& b);
140
142 friend tcons0 operator==(const texpr0::builder& a, const texpr0::builder& b);
143
145 friend tcons0 operator!=(const texpr0::builder& a, const texpr0::builder& b);
148
149 /* assignment */
150 /* ========== */
151
152
153 //@{
154
156 tcons0& operator= (const tcons0& x);
157
160
164 */
165 tcons0& operator= (const lincons0& x);
166
169
170 * it is created.
171 */
172 void set_modulo(const scalar& c);
173
175
176 * Does not fail as get_texpr can: if the constraint was created without an underlying expression,
177 * it is created.
178 */
179 void set_texpr(const texpr0::builder& c);
180
181
182
183
184 /* dimension operations */
185 /* ==================== */
186
188 //@{
189
192
193 */
194 void add_dimensions(const dimchange& d);
195
197
198 * \throw std::invalid_argument if no valid expression tree has been defined.
199 */
200 void remove_dimensions(const dimchange& d);
201
202
204 * \throw std::invalid_argument if no valid expression tree has been defined.
205 */
206 void permute_dimensions(const dimperm& d);
207
208 //@}
209
210
211 /* access */
212 /* ====== */
213
214 /** @name Accesses */
216
217 /* get */
218
219
221 * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ.
222 */
223 ap_constyp_t& get_constyp();
224
225
227 * \return either \c AP_CONS_EQ, \c AP_CONS_SUPEQ, \c AP_CONS_SUP, \c AP_CONS_EQMOD, or \c AP_CONS_DISEQ.
228 */
229 const ap_constyp_t& get_constyp() const;
230
232 bool has_modulo() const;
235 bool has_texpr() const;
236
238
239 * \throw std::invalid_argument if no valid extra scalar has been defined.
240 */
242
245
247 const scalar& get_modulo() const;
248
251 * \throw std::invalid_argument if no valid expression tree has been defined.
252 */
254
260
262
264 /* print */
265 /* ===== */
266
267
269
272 * Variable naming can be configured through the varname stream modifier.
273 *
274 * \throw std::invalid_argument if the underlying expression is missing, or the
275 * extra scalar is missing (for modulo).
276 */
277 friend std::ostream& operator<< (std::ostream& os, const tcons0& s);
278
280 void print(char** name_of_dim=NULL, FILE* stream=stdout) const;
281
282 //@}
283
284 /* tests */
285 /* ===== */
286
287 /** @name Tests */
289
291
292 * \throw std::invalid_argument if no valid expression tree has been defined.
293 */
294 bool is_interval_cst() const;
295
296
300 bool is_interval_linear() const;
301
302 /*! \brief Whether the expression is polynomial and there is no rounding.
303 *
304 * \throw std::invalid_argument if no valid expression tree has been defined.
305 */
306 bool is_interval_polynomial() const;
311
312 bool is_interval_polyfrac() const;
313
318 bool is_scalar() const;
319
322
323 /* C-level compatibility */
324 /* ===================== */
325
326 /** @name C API compatibility */
328
330 const ap_tcons0_t* get_ap_tcons0_t() const;
331
332
333 ap_tcons0_t* get_ap_tcons0_t();
334
336
337};
338
339
341/* ================================= */
342/* tcons0_array */
343/* ================================= */
344
345
346
348 * A tcons0_array represents an array of constraints on arbitrary expressions.
349 */
350class tcons0_array : public use_malloc {
351
352protected:
353
354 ap_tcons0_array_t a;
355
357 tcons0_array(ap_tcons0_array_t& a) : a(a) {}
358
359 friend class abstract0;
360 friend class tcons1_array;
361
362public:
364 /* constructors */
365 /* ============ */
366
369
375
377 tcons0_array(const tcons0_array& x);
378
380 tcons0_array(const tcons0_array& x, const dimchange& d, bool add=true);
381
383 tcons0_array(const tcons0_array& x, const dimperm& d);
384
386 tcons0_array(size_t size, const tcons0 x[]);
387
389 tcons0_array(const std::vector<tcons0>& x);
390
392
393 * Real-valued addition and multiplication operators are used (i.e., no rounding).
394 */
396
398
399
400 /* destructor */
401 /* ========== */
402
403 /** @name Destructor */
405
408
410
411
412 /* assignment */
413 /* ========== */
414
417
420
422
425 tcons0_array& operator= (const tcons0 x[]);
426
427 //! Copies the constraints from the vector into the array, changing its size if needed.
428 tcons0_array& operator= (const std::vector<tcons0>& x);
429
431
432 * Real-valued addition and multiplication operators are used (i.e., no rounding).
433 */
435
436
438
439 /* dimension operations */
440 /* ==================== */
441
442 /** @name Dimension operations */
444
446 void resize(size_t size);
447
449 void add_dimensions(const dimchange& d);
450
451 //! Applies remove_dimensions to all constraints in the array.
452 void remove_dimensions(const dimchange& d);
453
455 void permute_dimensions(const dimperm& d);
458
459
460 /* access */
461 /* ====== */
462
465
466 //! Returns the size of the array.
467 size_t size() const;
468
470 tcons0* contents();
473 const tcons0* contents() const;
474
475
476 tcons0& operator[](size_t i);
477
479 const tcons0& operator[](size_t i) const;
480
481
483 * \throw std::out_of_range if the index is invalid.
484 */
485 tcons0& get(size_t i);
486
487
491 const tcons0& get(size_t i) const;
494
495
496 /* conversion */
497 /* ========== */
498
500
501
503 operator std::vector<tcons0>() const;
504
505 //@}
506
507
508 /* print */
509 /* ===== */
510
513
518
522 friend std::ostream& operator<< (std::ostream& os, const tcons0_array& s);
525 void print(char** name_of_dim = NULL, FILE* stream=stdout) const;
526
527
528
529
530 /* tests */
531 /* ===== */
532
535
536 //! Whether all constraints are linear.
537 bool is_interval_linear() const;
538
540
541
542 /* C-level compatibility */
543 /* ===================== */
544
547
549 const ap_tcons0_array_t* get_ap_tcons0_array_t() const;
550
552 ap_tcons0_array_t* get_ap_tcons0_array_t();
553
555};
556
557#include "apxx_tcons0_inline.hh"
558
559}
560
561#endif /* __APXX_TCONS0_HH */
Dimension change object (ap_dimchange_t wrapper).
Definition apxx_dimension.hh:102
Dimension permutation object (ap_dimperm_t wrapper).
Definition apxx_dimension.hh:292
Array of linear constraints (ap_lincons0_array_t wrapper).
Definition apxx_lincons0.hh:341
Level 0 linear constraint (ap_lincons0_t wrapper).
Definition apxx_lincons0.hh:43
Scalar (ap_scalar_t wrapper).
Definition apxx_scalar.hh:89
friend class abstract0
Definition apxx_tcons0.hh:359
tcons0_array & operator=(const tcons0_array &x)
(Deep) copy.
Definition apxx_tcons0.hh:383
bool is_interval_linear() const
Whether all constraints are linear.
Definition apxx_tcons0.hh:523
ap_tcons0_array_t a
Structure managed by APRON.
Definition apxx_tcons0.hh:354
void add_dimensions(const dimchange &d)
Applies add_dimensions to all constraints in the array.
Definition apxx_tcons0.hh:432
size_t size() const
Returns the size of the array.
Definition apxx_tcons0.hh:451
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_tcons0.hh:514
const ap_tcons0_array_t * get_ap_tcons0_array_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_tcons0.hh:531
tcons0_array(ap_tcons0_array_t &a)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition apxx_tcons0.hh:357
const tcons0 & get(size_t i) const
Returns a reference to an element (bound-checked).
Definition apxx_tcons0.hh:482
tcons0 & operator[](size_t i)
Returns a (modifiable) reference to an element, no bound checking.
Definition apxx_tcons0.hh:466
tcons0 & get(size_t i)
Returns a (modifiable) reference to an element (bound-checked).
Definition apxx_tcons0.hh:476
friend std::ostream & operator<<(std::ostream &os, const tcons0_array &s)
Printing.
Definition apxx_tcons0.hh:505
tcons0 * contents()
Returns a pointer to the start of the internal array holding the constraints.
Definition apxx_tcons0.hh:456
friend class tcons1_array
Definition apxx_tcons0.hh:360
void permute_dimensions(const dimperm &d)
Applies permute_dimensions to all constraints in the array.
Definition apxx_tcons0.hh:442
~tcons0_array()
Frees the space used by the array and all its constraints.
Definition apxx_tcons0.hh:374
void resize(size_t size)
Resizes the array.
Definition apxx_tcons0.hh:427
void remove_dimensions(const dimchange &d)
Applies remove_dimensions to all constraints in the array.
Definition apxx_tcons0.hh:437
ap_tcons0_array_t * get_ap_tcons0_array_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_tcons0.hh:536
Level 0 arbitrary constraint (ap_tcons0_t wrapper).
Definition apxx_tcons0.hh:47
tcons0(ap_tcons0_t &l)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition apxx_tcons0.hh:24
bool is_interval_polyfrac() const
Whether the expression is a polynomial fraction and there is no rounding.
Definition apxx_tcons0.hh:287
friend class abstract0
Definition apxx_tcons0.hh:56
ap_tcons0_t l
Structure managed by APRON.
Definition apxx_tcons0.hh:51
~tcons0()
Frees the constraint, including the embedded expression tree and optional modulo scalar.
Definition apxx_tcons0.hh:82
friend tcons0 operator!=(const texpr0::builder &a, const texpr0::builder &b)
Makes a constraint a-b != 0.
Definition apxx_tcons0.hh:126
bool is_interval_cst() const
Whether the expression is constant (i.e., has no dimension leaves).
Definition apxx_tcons0.hh:272
bool has_modulo() const
Returns whether the constraint has a valid extra scalar (used in modulo constraints).
Definition apxx_tcons0.hh:198
friend tcons0 operator>(const texpr0::builder &a, const texpr0::builder &b)
Makes a constraint a-b > 0.
Definition apxx_tcons0.hh:105
bool is_scalar() const
Whether all occurring constants are scalar.
Definition apxx_tcons0.hh:292
void remove_dimensions(const dimchange &d)
Removes dimensions to the underlying expression tree.
Definition apxx_tcons0.hh:170
bool is_interval_linear() const
Whether the expression is linear and there is no rounding.
Definition apxx_tcons0.hh:277
friend tcons0 operator<=(const texpr0::builder &a, const texpr0::builder &b)
Makes a constraint b-a >= 0.
Definition apxx_tcons0.hh:98
void set_texpr(const texpr0::builder &c)
Sets the underlying expression tree to c (copied).
Definition apxx_tcons0.hh:239
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition apxx_tcons0.hh:188
bool has_texpr() const
Whether the constraint contains a valid expression tree.
Definition apxx_tcons0.hh:203
void permute_dimensions(const dimperm &d)
Applies a permutation to the underlying expression tree.
Definition apxx_tcons0.hh:176
void set_modulo(const scalar &c)
Sets the extra scalar modulo to c (copied).
Definition apxx_tcons0.hh:220
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_tcons0.hh:263
friend tcons0 operator>=(const texpr0::builder &a, const texpr0::builder &b)
Makes a constraint a-b >= 0.
Definition apxx_tcons0.hh:91
texpr0::iterator get_texpr()
Returns an iterator to the root of the underlying expression tree.
Definition apxx_tcons0.hh:233
void add_dimensions(const dimchange &d)
Adds dimensions to the underlying expression tree.
Definition apxx_tcons0.hh:164
bool is_interval_polynomial() const
Whether the expression is polynomial and there is no rounding.
Definition apxx_tcons0.hh:282
const ap_tcons0_t * get_ap_tcons0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_tcons0.hh:302
friend tcons0 operator<(const texpr0::builder &a, const texpr0::builder &b)
Makes a constraint b-a > 0.
Definition apxx_tcons0.hh:112
tcons0 & operator=(const tcons0 &x)
(Deep) copy.
Definition apxx_tcons0.hh:137
friend tcons0 operator==(const texpr0::builder &a, const texpr0::builder &b)
Makes a constraint a-b == 0.
Definition apxx_tcons0.hh:119
friend std::ostream & operator<<(std::ostream &os, const tcons0 &s)
Printing.
Definition apxx_tcons0.hh:250
scalar & get_modulo()
Returns a (modifiable) reference to the extra scalar.
Definition apxx_tcons0.hh:208
Temporary expression nodes used when constructing a texpr0.
Definition apxx_texpr0.hh:581
Iterators to traverse a constant expression tree.
Definition apxx_texpr0.hh:211
Iterators to traverse and mutate an expression tree.
Definition apxx_texpr0.hh:413
Definition apxx_abstract0.hh:27
texpr0::builder add(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition apxx_texpr0.hh:772
Unsatisfiable constraint, to simplify initialisations and assignments.
Definition apxx_lincons0.hh:28
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69