23 inline tcons0::tcons0(ap_tcons0_t& l) : l(l)
28 l = ap_tcons0_make(constyp, NULL, NULL);
31 inline tcons0::tcons0(ap_constyp_t constyp,
const texpr0::builder& t,
const scalar& modulo)
33 ap_texpr0_t* lt = ap_texpr0_copy(const_cast<ap_texpr0_t*>(t.get_ap_texpr0_t()));
34 ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(modulo.get_ap_scalar_t()));
35 l = ap_tcons0_make(constyp, lt, mmodulo);
38 inline tcons0::tcons0(ap_constyp_t constyp,
const texpr0::builder& t)
40 ap_texpr0_t* lt = ap_texpr0_copy(const_cast<ap_texpr0_t*>(t.get_ap_texpr0_t()));
41 l = ap_tcons0_make(constyp, lt, NULL);
46 l = ap_tcons0_copy(const_cast<ap_tcons0_t*>(&x.l));
51 l = ap_tcons0_make_unsat();
56 if (!x.l.texpr0)
throw std::invalid_argument(
"apron::tcons0::tcons0(const tcons0&, const dimchange&, bool) empty expression");
58 l = ap_tcons0_add_dimensions(const_cast<ap_tcons0_t*>(&x.l),
59 const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
61 l = ap_tcons0_remove_dimensions(const_cast<ap_tcons0_t*>(&x.l),
62 const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
67 if (!x.l.texpr0)
throw std::invalid_argument(
"apron::tcons0::tcons0(const tcons0&, const dimperm&) empty expression");
68 l = ap_tcons0_permute_dimensions(const_cast<ap_tcons0_t*>(&x.l),
69 const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
74 l = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x.get_ap_lincons0_t()));
83 ap_tcons0_clear(const_cast<ap_tcons0_t*>(&
l));
90 inline tcons0
operator>=(
const texpr0::builder& a,
const texpr0::builder& b)
92 if (b.is_zero())
return tcons0(AP_CONS_SUPEQ,a);
93 else if (a.is_zero())
return tcons0(AP_CONS_SUPEQ,-b);
94 else return tcons0(AP_CONS_SUPEQ,a-b);
97 inline tcons0
operator<=(
const texpr0::builder& a,
const texpr0::builder& b)
99 if (b.is_zero())
return tcons0(AP_CONS_SUPEQ,-a);
100 else if (a.is_zero())
return tcons0(AP_CONS_SUPEQ,b);
101 else return tcons0(AP_CONS_SUPEQ,b-a);
104 inline tcons0
operator> (
const texpr0::builder& a,
const texpr0::builder& b)
106 if (b.is_zero())
return tcons0(AP_CONS_SUP,a);
107 else if (a.is_zero())
return tcons0(AP_CONS_SUP,-b);
108 else return tcons0(AP_CONS_SUP,a-b);
111 inline tcons0
operator< (
const texpr0::builder& a,
const texpr0::builder& b)
113 if (b.is_zero())
return tcons0(AP_CONS_SUP,-a);
114 else if (a.is_zero())
return tcons0(AP_CONS_SUP,b);
115 else return tcons0(AP_CONS_SUP,b-a);
118 inline tcons0
operator==(
const texpr0::builder& a,
const texpr0::builder& b)
120 if (b.is_zero())
return tcons0(AP_CONS_EQ,a);
121 else if (a.is_zero())
return tcons0(AP_CONS_EQ,b);
122 else return tcons0(AP_CONS_EQ,a-b);
125 inline tcons0
operator!=(
const texpr0::builder& a,
const texpr0::builder& b)
127 if (b.is_zero())
return tcons0(AP_CONS_DISEQ,a);
128 else if (a.is_zero())
return tcons0(AP_CONS_DISEQ,b);
129 else return tcons0(AP_CONS_DISEQ,a-b);
140 l = ap_tcons0_copy(const_cast<ap_tcons0_t*>(&x.l));
148 l = ap_tcons0_make_unsat();
155 l = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x.get_ap_lincons0_t()));
165 if (!
l.texpr0)
throw std::invalid_argument(
"apron::tcons0::add_dimensions(const dimchange&) empty expression");
166 ap_tcons0_add_dimensions_with(&
l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
171 if (!
l.texpr0)
throw std::invalid_argument(
"apron::tcons0::remove_dimensions(const dimchange&) empty expression");
172 ap_tcons0_remove_dimensions_with(&
l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
177 if (!
l.texpr0)
throw std::invalid_argument(
"apron::tcons0::permute_dimensions(dimperm&) empty expression");
178 ap_tcons0_permute_dimensions_with(&
l, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
199 return l.scalar!=NULL;
204 return l.texpr0!=NULL;
209 if (!
l.scalar)
throw std::invalid_argument(
"apron::tcons0::get_modulo() empty scalar");
210 return reinterpret_cast<scalar&>(*
l.scalar);
215 if (!
l.scalar)
throw std::invalid_argument(
"apron::tcons0::get_modulo() empty scalar");
216 return reinterpret_cast<scalar&>(*
l.scalar);
221 if (!
l.scalar)
l.scalar = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(c.get_ap_scalar_t()));
222 else ap_scalar_set(
l.scalar, const_cast<ap_scalar_t*>(c.get_ap_scalar_t()));
228 throw std::invalid_argument(
"apron::tcons0::get_texpr() empty expression");
234 if (!
l.texpr0)
throw std::invalid_argument(
"apron::tcons0::get_texpr() empty expression");
240 ap_texpr0_t* cc = ap_texpr0_copy(const_cast<ap_texpr0_t*>(c.get_ap_texpr0_t()));
241 if (
l.texpr0) ap_texpr0_free(
l.texpr0);
249 inline std::ostream&
operator<< (std::ostream& os,
const tcons0& s)
252 switch (s.get_constyp()) {
253 case AP_CONS_EQ:
return os <<
" = 0";
254 case AP_CONS_SUPEQ:
return os <<
" >= 0";
255 case AP_CONS_SUP:
return os <<
" > 0";
256 case AP_CONS_EQMOD:
return os <<
" = 0 mod " << s.get_modulo();
257 case AP_CONS_DISEQ:
return os <<
" != 0";
258 default:
throw std::invalid_argument(
"apron::operator<<(ostream&, const tcons0&) invalid constraint type");
262 inline void tcons0::print(
char** name_of_dim, FILE* stream)
const 264 ap_tcons0_fprint(stream, const_cast<ap_tcons0_t*>(&
l), name_of_dim);
273 return ap_tcons0_is_interval_cst(const_cast<ap_tcons0_t*>(&
l));
278 return ap_tcons0_is_interval_linear(const_cast<ap_tcons0_t*>(&
l));
283 return ap_tcons0_is_interval_polynomial(const_cast<ap_tcons0_t*>(&
l));
288 return ap_tcons0_is_interval_polyfrac(const_cast<ap_tcons0_t*>(&
l));
293 return ap_tcons0_is_scalar(const_cast<ap_tcons0_t*>(&
l));
321 : a(ap_tcons0_array_make(size))
325 inline tcons0_array::tcons0_array(
const tcons0_array& x)
326 : a(ap_tcons0_array_make(x.a.size))
328 for (
size_t i=0; i<a.size; i++)
329 a.p[i] = ap_tcons0_copy(&x.a.p[i]);
332 inline tcons0_array::tcons0_array(
size_t size,
const tcons0 x[])
333 : a(ap_tcons0_array_make(size))
335 for (
size_t i=0; i<size; i++)
336 a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
339 inline tcons0_array::tcons0_array(
const std::vector<tcons0>& x)
340 : a(ap_tcons0_array_make(x.size()))
342 for (
size_t i=0; i<a.size; i++)
343 a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
346 inline tcons0_array::tcons0_array(
const tcons0_array& x,
const dimchange& d,
bool add)
349 a = ap_tcons0_array_add_dimensions(const_cast<ap_tcons0_array_t*>(&x.a),
350 const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
352 a = ap_tcons0_array_remove_dimensions(const_cast<ap_tcons0_array_t*>(&x.a),
353 const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
356 inline tcons0_array::tcons0_array(
const tcons0_array& x,
const dimperm& d)
358 a = ap_tcons0_array_permute_dimensions(const_cast<ap_tcons0_array_t*>(&x.a),
359 const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
362 inline tcons0_array::tcons0_array(
const lincons0_array& x)
363 : a(ap_tcons0_array_make(x.size()))
365 for (
size_t i=0; i<a.size; i++)
366 a.p[i] = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
373 inline tcons0_array::~tcons0_array()
375 ap_tcons0_array_clear(&a);
382 inline tcons0_array& tcons0_array::operator= (
const tcons0_array& x)
385 ap_tcons0_array_clear(&a);
386 a = ap_tcons0_array_make(x.a.size);
387 for (
size_t i=0; i<a.size; i++) a.p[i] = ap_tcons0_copy(&x.a.p[i]);
392 inline tcons0_array& tcons0_array::operator= (
const tcons0 x[])
394 size_t size = a.size;
395 ap_tcons0_array_clear(&a);
396 a = ap_tcons0_array_make(size);
397 for (
size_t i=0; i<size; i++)
398 a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
402 inline tcons0_array& tcons0_array::operator= (
const std::vector<tcons0>& x)
404 size_t size = x.size();
405 ap_tcons0_array_clear(&a);
406 a = ap_tcons0_array_make(size);
407 for (
size_t i=0; i<size; i++)
408 a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
412 inline tcons0_array& tcons0_array::operator= (
const lincons0_array& x)
414 size_t size = x.size();
415 ap_tcons0_array_clear(&a);
416 a = ap_tcons0_array_make(size);
417 for (
size_t i=0; i<size; i++)
418 a.p[i] = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
426 inline void tcons0_array::resize(
size_t size)
428 ap_tcons0_array_resize(&a, size);
433 ap_tcons0_array_add_dimensions_with(&a, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
438 ap_tcons0_array_remove_dimensions_with(&a, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
443 ap_tcons0_array_permute_dimensions_with(&a, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
450 inline size_t tcons0_array::size()
const 455 inline tcons0* tcons0_array::contents()
457 return reinterpret_cast<tcons0*>(a.p);
460 inline const tcons0* tcons0_array::contents()
const 462 return reinterpret_cast<tcons0*>(a.p);
465 inline tcons0& tcons0_array::operator[](
size_t i)
467 return reinterpret_cast<tcons0&>(a.p[i]);
470 inline const tcons0& tcons0_array::operator[](
size_t i)
const 472 return reinterpret_cast<tcons0&>(a.p[i]);
475 inline tcons0& tcons0_array::get(
size_t i)
477 if (i >= a.size)
throw std::out_of_range(
"apron::tcons0_array::get()");
478 return reinterpret_cast<tcons0&>(a.p[i]);
481 inline const tcons0& tcons0_array::get(
size_t i)
const 483 if (i >= a.size)
throw std::out_of_range(
"apron::tcons0_array::get()");
484 return reinterpret_cast<tcons0&>(a.p[i]);
491 inline tcons0_array::operator std::vector<tcons0>()
const 494 std::vector<tcons0> v = std::vector<tcons0>(sz);
495 for (
size_t i=0;i<sz;i++)
504 inline std::ostream&
operator<< (std::ostream& os,
const tcons0_array& s)
506 size_t size = s.size();
508 for (
size_t i=0;i<size;i++)
513 inline void tcons0_array::print(
char** name_of_dim, FILE* stream)
const 515 ap_tcons0_array_fprint(stream, const_cast<ap_tcons0_array_t*>(&a), name_of_dim);
522 inline bool tcons0_array::is_interval_linear()
const 524 return ap_tcons0_array_is_interval_linear(const_cast<ap_tcons0_array_t*>(&a));
530 inline const ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t()
const 535 inline ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t()
void permute_dimensions(const dimperm &d)
Applies a permutation to the underlying expression tree.
Definition: apxx_tcons0.hh:176
void remove_dimensions(const dimchange &d)
Removes dimensions to the underlying expression tree.
Definition: apxx_tcons0.hh:170
std::ostream & operator<<(std::ostream &os, const tcons0 &s)
Definition: apxx_tcons0_inline.hh:249
~tcons0()
Frees the constraint, including the embedded expression tree and optional modulo scalar.
Definition: apxx_tcons0.hh:82
void set_modulo(const scalar &c)
Sets the extra scalar modulo to c (copied).
Definition: apxx_tcons0.hh:220
abstract0 & remove_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d)
Definition: apxx_abstract0_inline.hh:1049
bool has_texpr() const
Whether the constraint contains a valid expression tree.
Definition: apxx_tcons0.hh:203
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
texpr0::iterator get_texpr()
Returns an iterator to the root of the underlying expression tree.
Definition: apxx_tcons0.hh:233
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
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition: apxx_abstract0.hh:293
bool is_interval_polyfrac() const
Whether the expression is a polynomial fraction and there is no rounding.
Definition: apxx_tcons0.hh:287
bool is_interval_linear() const
Whether the expression is linear and there is no rounding.
Definition: apxx_tcons0.hh:277
bool is_interval_polynomial() const
Whether the expression is polynomial and there is no rounding.
Definition: apxx_tcons0.hh:282
bool is_scalar() const
Whether all occurring constants are scalar.
Definition: apxx_tcons0.hh:292
abstract0 & add_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d, bool project=false)
Definition: apxx_abstract0_inline.hh:1037
bool is_interval_cst() const
Whether the expression is constant (i.e., has no dimension leaves).
Definition: apxx_tcons0.hh:272
bool operator==(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:410
tcons0(ap_tcons0_t &l)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition: apxx_tcons0.hh:24
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition: apxx_tcons0.hh:188
void set_texpr(const texpr0::builder &c)
Sets the underlying expression tree to c (copied).
Definition: apxx_tcons0.hh:239
bool operator>(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:434
tcons0 & operator=(const tcons0 &x)
(Deep) copy.
Definition: apxx_tcons0.hh:137
abstract0 & permute_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimperm &d)
Definition: apxx_abstract0_inline.hh:1060
bool operator>=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:429
bool operator!=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:417
void add_dimensions(const dimchange &d)
Adds dimensions to the underlying expression tree.
Definition: apxx_tcons0.hh:164
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
ap_tcons0_t l
Structure managed by APRON.
Definition: apxx_tcons0.hh:51
scalar & get_modulo()
Returns a (modifiable) reference to the extra scalar.
Definition: apxx_tcons0.hh:208
bool operator<=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:422
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_tcons0.hh:263
bool has_modulo() const
Returns whether the constraint has a valid extra scalar (used in modulo constraints).
Definition: apxx_tcons0.hh:198
bool operator<(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:439