24 #ifndef PPL_Polyhedron_templates_hh
25 #define PPL_Polyhedron_templates_hh 1
38 template <
typename Interval>
42 : con_sys(topol, default_con_sys_repr),
43 gen_sys(topol, default_gen_sys_repr),
73 bool l_closed =
false;
76 bool u_closed =
false;
80 if (l_bounded && u_bounded
81 && l_closed && u_closed
82 && l_n == u_n && l_d == u_d) {
103 bool l_closed =
false;
106 bool u_closed =
false;
110 if (l_bounded && u_bounded
111 && l_closed && u_closed
112 && l_n == u_n && l_d == u_d) {
148 PPL_ASSERT_HEAVY(
OK());
151 template <
typename Partial_Function>
172 PPL_ASSERT_HEAVY(
OK());
184 std::vector<Variable> cycle;
200 if (!pfunc.
maps(j, k)) {
202 " pfunc is inconsistent");
211 }
while (!visited[j]);
229 PPL_ASSERT_HEAVY(
OK());
243 PPL_ASSERT_HEAVY(
OK());
251 if (pfunc.
maps(j, pfunc_j)) {
252 pfunc_maps[j] = pfunc_j;
258 old_gensys_end = old_gensys.
end(); i != old_gensys_end; ++i) {
263 bool all_zeroes =
true;
265 j_end = old_e.
end(); j != j_end; ++j) {
272 switch (old_g.
type()) {
275 new_gensys.
insert(line(expr));
280 new_gensys.
insert(ray(expr));
295 PPL_ASSERT_HEAVY(
OK(
true));
298 template <
typename FP_Format,
typename Interval_Info>
303 const bool is_strict) {
307 "Polyhedron::refine_with_linear_form_inequality:"
308 " FP_Format not a floating point type.");
316 "refine_with_linear_form_inequality(l1, l2, s)",
"l1", left);
322 "refine_with_linear_form_inequality(l1, l2, s)",
"l2", right);
342 FP_Linear_Form left_minus_right(left);
343 left_minus_right -= right;
345 overflows(left_minus_right)) {
350 FP_Linear_Form lf_approx;
353 overflows(lf_approx)) {
370 template <
typename FP_Format,
typename Interval_Info>
377 "Polyhedron::affine_form_image:"
378 " FP_Format not a floating point type.");
406 FP_Linear_Form lf_approx;
410 overflows(lf_approx)) {
421 lo_coeff, hi_coeff, denominator);
428 template <
typename FP_Format,
typename Interval_Info>
437 "Polyhedron::overapproximate_linear_form:"
438 " FP_Format not a floating point type.");
447 result = FP_Linear_Form(lf.inhomogeneous_term());
449 const FP_Interval_Type aux_divisor1(static_cast<FP_Format>(0.5));
450 FP_Interval_Type aux_divisor2(aux_divisor1);
451 aux_divisor2.lower() =
static_cast<FP_Format
>(-0.5);
455 const FP_Interval_Type& curr_coeff = lf.coefficient(curr_var);
456 PPL_ASSERT(curr_coeff.is_bounded());
457 FP_Format curr_lb = curr_coeff.lower();
458 FP_Format curr_ub = curr_coeff.upper();
459 if (curr_lb != 0 || curr_ub != 0) {
460 const FP_Interval_Type& curr_int = box.
get_interval(curr_var);
461 FP_Interval_Type curr_addend(curr_ub - curr_lb);
462 curr_addend *= aux_divisor2;
463 curr_addend *= curr_int;
464 result += curr_addend;
465 curr_addend = FP_Interval_Type(curr_lb + curr_ub);
466 curr_addend *= aux_divisor1;
467 FP_Linear_Form curr_addend_lf(curr_var);
468 curr_addend_lf *= curr_addend;
469 result += curr_addend_lf;
474 template <
typename FP_Format,
typename Interval_Info>
483 std::vector<Coefficient> numerators(lf_dimension+1);
484 std::vector<Coefficient> denominators(lf_dimension+1);
490 const FP_Interval_Type& b = lf.inhomogeneous_term();
493 denominators[lf_dimension]);
494 if (numerators[lf_dimension] != 0) {
495 lcm_assign(lcm, lcm, denominators[lf_dimension]);
499 const FP_Interval_Type& curr_int = lf.coefficient(
Variable(i));
500 numer_denom(curr_int.lower(), numerators[i], denominators[i]);
501 if (numerators[i] != 0) {
507 if (numerators[i] != 0) {
509 numerators[i] *= denominators[i];
510 result += numerators[i] *
Variable(i);
514 if (numerators[lf_dimension] != 0) {
516 lcm, denominators[lf_dimension]);
517 numerators[lf_dimension] *= denominators[lf_dimension];
518 result += numerators[lf_dimension];
522 template <
typename FP_Format,
typename Interval_Info>
532 std::vector<Coefficient> numerators(lf_dimension+2);
533 std::vector<Coefficient> denominators(lf_dimension+2);
539 const FP_Interval_Type& b = lf.inhomogeneous_term();
540 numer_denom(b.lower(), numerators[lf_dimension], denominators[lf_dimension]);
542 if (numerators[lf_dimension] != 0) {
543 lcm_assign(lcm, lcm, denominators[lf_dimension]);
547 denominators[lf_dimension+1]);
548 if (numerators[lf_dimension+1] != 0) {
549 lcm_assign(lcm, lcm, denominators[lf_dimension+1]);
553 const FP_Interval_Type& curr_int = lf.coefficient(
Variable(i));
554 numer_denom(curr_int.lower(), numerators[i], denominators[i]);
555 if (numerators[i] != 0) {
561 if (numerators[i] != 0) {
563 numerators[i] *= denominators[i];
568 if (numerators[lf_dimension] != 0) {
570 lcm, denominators[lf_dimension]);
571 numerators[lf_dimension] *= denominators[lf_dimension];
572 res_low_coeff = numerators[lf_dimension];
578 if (numerators[lf_dimension+1] != 0) {
580 lcm, denominators[lf_dimension+1]);
581 numerators[lf_dimension+1] *= denominators[lf_dimension+1];
582 res_hi_coeff = numerators[lf_dimension+1];
589 template <
typename C>
597 template <
typename Input>
602 const char* reason) {
605 topol, method, reason);
611 #endif // !defined(PPL_Polyhedron_templates_hh)
bool has_pending_constraints() const
Returns true if there are pending constraints.
bool marked_empty() const
Returns true if the polyhedron is known to be empty.
The empty element, i.e., the empty set.
void map_space_dimensions(const Partial_Function &pfunc)
Remaps the dimensions of the vector space according to a partial function.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
An iterator over a system of generators.
bool remove_pending_to_obtain_generators() const
Lazily integrates the pending descriptions of the polyhedron to obtain a generator system without pen...
size_t dimension_type
An unsigned integral type for representing space dimensions.
void set_space_dimension(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
Enable_If< Is_Native_Or_Checked< T >::value, void >::type numer_denom(const T &from, Coefficient &numer, Coefficient &denom)
Extract the numerator and denominator components of from.
Generator_System gen_sys
The system of generators.
A line, ray, point or closure point.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
dimension_type not_a_dimension()
Returns a value that does not designate a valid dimension.
void bounded_affine_image(Variable var, const Linear_Expression &lb_expr, const Linear_Expression &ub_expr, Coefficient_traits::const_reference denominator=Coefficient_one())
Assigns to *this the image of *this with respect to the bounded affine relation . ...
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
bool is_empty() const
Returns true if and only if *this is an empty box.
void insert(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
bool update_generators() const
Updates generators starting from constraints and minimizes them.
expr_type expression() const
Partial read access to the (adapted) internal expression.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the matrix.
void set_constraints_up_to_date()
Sets status to express that constraints are up-to-date.
void lcm_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
void throw_dimension_incompatible(const char *method, const char *other_name, dimension_type other_dim) const
void clear()
Removes all the constraints from the constraint system and sets its space dimension to 0...
bool has_empty_codomain() const
Returns true if and only if the represented partial function has an empty codomain (i...
Polyhedron(Topology topol, dimension_type num_dimensions, Degenerate_Element kind)
Builds a polyhedron having the specified properties.
static Object & check_obj_space_dimension_overflow(Object &input, Topology topol, const char *method, const char *reason)
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
void refine_with_linear_form_inequality(const Linear_Form< Interval< FP_Format, Interval_Info > > &left, const Linear_Form< Interval< FP_Format, Interval_Info > > &right, bool is_strict=false)
Refines *this with the constraint expressed by left right if is_strict is set, with the constraint l...
dimension_type id() const
Returns the index of the Cartesian axis associated to the variable.
void refine_with_constraint(const Constraint &c)
Uses a copy of constraint c to refine *this.
A dimension of the vector space.
Complexity_Class
Complexity pseudo-classes.
The base class for convex polyhedra.
void affine_form_image(Variable var, const Linear_Form< Interval< FP_Format, Interval_Info > > &lf)
Topology topology() const
Returns the topological kind of the polyhedron.
bool generators_are_up_to_date() const
Returns true if the system of generators is up-to-date.
void throw_invalid_argument(const char *method, const char *reason) const
Constraint_System con_sys
The system of constraints.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the matrix.
static void convert_to_integer_expressions(const Linear_Form< Interval< FP_Format, Interval_Info > > &lf, const dimension_type lf_dimension, Linear_Expression &res, Coefficient &res_low_coeff, Coefficient &res_hi_coeff, Coefficient &denominator)
Normalization helper function.
#define PPL_COMPILE_TIME_CHECK(e, msg)
Produces a compilation error if the compile-time constant e does not evaluate to true ...
static dimension_type check_space_dimension_overflow(dimension_type dim, dimension_type max, const Topology topol, const char *method, const char *reason)
Type type() const
Returns the generator type of *this.
bool constraints_are_up_to_date() const
Returns true if the system of constraints is up-to-date.
static dimension_type max_space_dimension()
Returns the maximum space dimension all kinds of Polyhedron can handle.
const_iterator end() const
Iterator pointing after the last nonzero variable coefficient.
const Generator_System & generators() const
Returns the system of generators.
bool has_upper_bound(Variable var, Coefficient &n, Coefficient &d, bool &closed) const
If the space dimension of var is unbounded above, return false. Otherwise return true and set n...
A not necessarily closed, iso-oriented hyperrectangle.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
The universe element, i.e., the whole vector space.
A generic, not necessarily closed, possibly restricted interval.
dimension_type max_in_codomain() const
If the codomain is not empty, returns the maximum value in it.
bool has_lower_bound(Variable var, Coefficient &n, Coefficient &d, bool &closed) const
If the space dimension of var is unbounded below, return false. Otherwise return true and set n...
void set_empty()
Sets status to express that the polyhedron is empty, clearing all corresponding matrices.
The entire library is confined to this namespace.
static void convert_to_integer_expression(const Linear_Form< Interval< FP_Format, Interval_Info > > &lf, const dimension_type lf_dimension, Linear_Expression &result)
Helper function that makes result become a Linear_Expression obtained by normalizing the denominators...
dimension_type space_dim
The number of dimensions of the enclosing vector space.
const ITV & get_interval(Variable var) const
Returns a reference the interval that bounds var.
bool is_necessarily_closed() const
Returns true if and only if the polyhedron is necessarily closed.
const_iterator end() const
Returns the past-the-end const_iterator.
const_iterator begin() const
Returns the const_iterator pointing to the first generator, if *this is not empty; otherwise...
bool OK(bool check_not_empty=false) const
Checks if all the invariants are satisfied.
base_type::const_iterator const_iterator
The type of const iterators on coefficients.
void overapproximate_linear_form(const Linear_Form< Interval< FP_Format, Interval_Info > > &lf, const dimension_type lf_dimension, Linear_Form< Interval< FP_Format, Interval_Info > > &result)
Helper function that overapproximates an interval linear form.
void add_low_level_constraints()
Adds low-level constraints to the constraint system.
bool maps(dimension_type i, dimension_type &j) const
If *this maps i to a value k, assigns k to j and returns true; otherwise, j is unchanged and false is...
Coefficient_traits::const_reference divisor() const
If *this is either a point or a closure point, returns its divisor.
const_iterator begin() const
Iterator pointing to the first nonzero variable coefficient.
void insert(const Generator &g)
Inserts in *this a copy of the generator g, increasing the number of space dimensions if needed...
An adapter for Linear_Expression that maybe hides the last coefficient.
void m_swap(Polyhedron &y)
Swaps *this with polyhedron y. (*this and y can be dimension-incompatible.)
void set_zero_dim_univ()
Sets status to express that the polyhedron is the universe 0-dimension vector space, clearing all corresponding matrices.
Topology
Kinds of polyhedra domains.