25 #ifndef PPL_Partially_Reduced_Product_templates_hh
26 #define PPL_Partially_Reduced_Product_templates_hh 1
36 template <
typename D1,
typename D2,
typename R>
42 s <<
"PPL::Partially_Reduced_Product::" << method <<
":" << std::endl
44 throw std::length_error(s.str());
47 template <
typename D1,
typename D2,
typename R>
54 cs_end = cs1.
end(); i != cs_end; ++i) {
60 template <
typename D1,
typename D2,
typename R>
67 cs_end = cs1.
end(); i != cs_end; ++i) {
80 template <
typename D1,
typename D2,
typename R>
87 cgs_end = cgs1.
end(); i != cgs_end; ++i) {
93 template <
typename D1,
typename D2,
typename R>
100 cgs_end = cgs1.
end(); i != cgs_end; ++i) {
107 template <
typename D1,
typename D2,
typename R>
111 if (d1.can_recycle_constraint_systems()) {
112 d2.refine_with_constraints(cs);
113 d1.add_recycled_constraints(cs);
116 if (d2.can_recycle_constraint_systems()) {
117 d1.refine_with_constraints(cs);
118 d2.add_recycled_constraints(cs);
121 d1.add_constraints(cs);
122 d2.add_constraints(cs);
125 clear_reduced_flag();
128 template <
typename D1,
typename D2,
typename R>
132 if (d1.can_recycle_congruence_systems()) {
133 d2.refine_with_congruences(cgs);
134 d1.add_recycled_congruences(cgs);
137 if (d2.can_recycle_congruence_systems()) {
138 d1.refine_with_congruences(cgs);
139 d2.add_recycled_congruences(cgs);
142 d1.add_congruences(cgs);
143 d2.add_congruences(cgs);
146 clear_reduced_flag();
149 template <
typename D1,
typename D2,
typename R>
163 template <
typename D1,
typename D2,
typename R>
195 template <
typename D1,
typename D2,
typename R>
227 template <
typename D1,
typename D2,
typename R>
233 bool& maximum)
const {
246 bool r1 = d1.maximize(expr, sup1_n, sup1_d, maximum1);
247 bool r2 = d2.maximize(expr, sup2_n, sup2_d, maximum2);
267 if (sup2_d * sup1_n >= sup1_d * sup2_n) {
280 template <
typename D1,
typename D2,
typename R>
286 bool& minimum)
const {
300 bool r1 = d1.minimize(expr, inf1_n, inf1_d, minimum1);
301 bool r2 = d2.minimize(expr, inf2_n, inf2_d, minimum2);
321 if (inf2_d * inf1_n <= inf1_d * inf2_n) {
334 template <
typename D1,
typename D2,
typename R>
357 bool r1 = d1.maximize(expr, sup1_n, sup1_d, maximum1, g1);
358 bool r2 = d2.maximize(expr, sup2_n, sup2_d, maximum2, g2);
380 if (sup2_d * sup1_n >= sup1_d * sup2_n) {
395 template <
typename D1,
typename D2,
typename R>
418 bool r1 = d1.minimize(expr, inf1_n, inf1_d, minimum1, g1);
419 bool r2 = d2.minimize(expr, inf2_n, inf2_d, minimum2, g2);
441 if (inf2_d * inf1_n <= inf1_d * inf2_n) {
456 template <
typename D1,
typename D2,
typename R>
469 return d1.OK() && d2.OK();
472 template <
typename D1,
typename D2,
typename R>
475 const char yes =
'+';
478 if (!(s >> str) || str !=
"Partially_Reduced_Product") {
482 || (str[0] != yes && str[0] != no)
483 || str.substr(1) !=
"reduced") {
486 reduced = (str[0] ==
yes);
487 if (!(s >> str) || str !=
"Domain") {
490 if (!(s >> str) || str !=
"1:") {
493 if (!d1.ascii_load(s)) {
496 if (!(s >> str) || str !=
"Domain") {
499 if (!(s >> str) || str !=
"2:") {
502 return d2.ascii_load(s);
505 template <
typename D1,
typename D2>
509 if (!d1.is_empty()) {
510 D1 new_d1(d1.space_dimension(),
EMPTY);
514 else if (d1.is_empty()) {
515 D2 new_d2(d2.space_dimension(),
EMPTY);
520 template <
typename D1,
typename D2>
522 if (d1.is_empty() || d2.is_empty()) {
531 d1.refine_with_constraints(d2.minimized_constraints());
533 D2 new_d2(space_dim,
EMPTY);
537 d2.refine_with_constraints(d1.minimized_constraints());
539 D1 new_d1(space_dim,
EMPTY);
550 template <
typename D1,
typename D2>
566 if (d2.maximize(e, max_numer, max_denom, max_included)) {
568 if (d2.minimize(e, min_numer, min_denom, min_included)) {
570 max_numer *= min_denom;
571 min_numer *= max_denom;
574 denom = max_denom * min_denom;
582 if (max_numer - min_numer < mod2
583 || (max_numer - min_numer == mod2 && (!max_included || !min_included)))
589 shrink_amount = max_numer % mod;
590 if (!max_included && shrink_amount == 0) {
593 if (shrink_amount < 0) {
594 shrink_amount += mod;
596 max_decreased = max_numer - shrink_amount;
598 shrink_amount = min_numer % mod;
599 if (!min_included && shrink_amount == 0) {
600 shrink_amount = - mod;
602 if (shrink_amount > 0) {
603 shrink_amount -= mod;
605 min_increased = min_numer - shrink_amount;
606 if (max_decreased == min_increased) {
610 d1.refine_with_constraint(new_c);
611 d2.refine_with_constraint(new_c);
615 if (max_decreased < min_increased) {
619 D1 new_d1(d1.space_dimension(),
EMPTY);
621 D2 new_d2(d2.space_dimension(),
EMPTY);
632 template <
typename D1,
typename D2>
635 if (d1.is_empty() || d2.is_empty()) {
644 cgs_end = cgs1.
end(); i != cgs_end; ++i) {
647 d2.refine_with_congruence(cg1);
660 cgs_end = cgs2.
end(); i != cgs_end; ++i) {
663 d1.refine_with_congruence(cg2);
675 template <
typename D1,
typename D2>
694 cs_end = cs.
end(); i != cs_end; ++i) {
702 if (!d1.frequency(
le, freq_n, freq_d, val_n, val_d)) {
713 val_n = val_n*freq_d + val_d*freq_n;
720 d2.refine_with_constraints(refining_cs);
723 cs = d1.minimized_constraints();
726 cs_end = cs.
end(); i != cs_end; ++i) {
735 if (!d2.frequency(
le, freq_n, freq_d, val_n, val_d)) {
746 val_n = val_n*freq_d + val_d*freq_n;
753 d1.refine_with_constraints(refining_cs);
763 #endif // !defined(PPL_Partially_Reduced_Product_templates_hh)
An iterator over a system of constraints.
The partially reduced product of two abstractions.
The empty element, i.e., the empty set.
static Poly_Con_Relation is_disjoint()
The polyhedron and the set of points satisfying the constraint are disjoint.
static Poly_Gen_Relation subsumes()
Adding the generator would not change the polyhedron.
Congruence_System congruences() const
Returns a system of congruences which approximates *this.
Coefficient_traits::const_reference modulus() const
Returns a const reference to the modulus of *this.
A linear equality or inequality.
bool is_equality() const
Returns true if and only if *this is an equality constraint.
void swap(CO_Tree &x, CO_Tree &y)
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
static bool implies(flags_t x, flags_t y)
True if and only if the conjunction x implies the conjunction y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void insert(const Congruence &cg)
Inserts in *this a copy of the congruence cg, increasing the number of space dimensions if needed...
A line, ray, point or closure point.
void product_reduce(D1 &d1, D2 &d2)
The congruences reduction operator for detect emptiness or any equalities implied by each of the cong...
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
Poly_Con_Relation relation_with(const Constraint &c) const
Returns the relations holding between *this and c.
void product_reduce(D1 &d1, D2 &d2)
The constraints reduction operator for sharing constraints between the domains.
void clear_reduced_flag() const
Clears the reduced flag.
void insert(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
const_iterator end() const
Returns the past-the-end const_iterator.
static Poly_Con_Relation is_included()
The polyhedron is included in the set of points satisfying the constraint.
bool minimize(const Linear_Expression &expr, Coefficient &inf_n, Coefficient &inf_d, bool &minimum) const
Returns true if and only if *this is not empty and expr is bounded from below i *this, in which case the infimum value is computed.
expr_type expression() const
Partial read access to the (adapted) internal expression.
Congruence_System minimized_congruences() const
Returns a system of congruences which approximates *this, in reduced form.
void clear()
Removes all the constraints from the constraint system and sets its space dimension to 0...
This class provides the reduction method for the Constraints_Product domain.
static Poly_Con_Relation saturates()
The polyhedron is included in the set of points saturating the constraint.
const_iterator begin() const
Returns the const_iterator pointing to the first constraint, if *this is not empty; otherwise...
This class provides the reduction method for the Congruences_Product domain.
Constraint_System minimized_constraints() const
Returns a system of constraints which approximates *this, in reduced form.
void add_recycled_constraints(Constraint_System &cs)
Adds the constraint system in cs to *this.
void product_reduce(D1 &d1, D2 &d2)
The congruences reduction operator for detect emptiness or any equalities implied by each of the cong...
bool is_equality() const
Returns true if *this is an equality.
bool maximize(const Linear_Expression &expr, Coefficient &sup_n, Coefficient &sup_d, bool &maximum) const
Returns true if and only if *this is not empty and expr is bounded from above in *this, in which case the supremum value is computed.
const_iterator end() const
Returns the past-the-end const_iterator.
const Congruence_System & minimized_congruences() const
Returns the system of congruences in minimal form.
bool shrink_to_congruence_no_check(D1 &d1, D2 &d2, const Congruence &cg)
A not necessarily closed convex polyhedron.
A closed convex polyhedron.
const_iterator begin() const
Returns the const_iterator pointing to the first congruence, if this is not empty; otherwise...
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
The entire library is confined to this namespace.
An iterator over a system of congruences.
Constraint_System constraints() const
Returns a system of constraints which approximates *this.
void add_recycled_congruences(Congruence_System &cgs)
Adds the congruences in cgs to *this.
bool reduce() const
Reduce.
void product_reduce(D1 &d1, D2 &d2)
The smash reduction operator for propagating emptiness between the domain elements d1 and d2...
This class provides the reduction method for the Smash_Product domain.
expr_type expression() const
Partial read access to the (adapted) internal expression.
const Constraint_System & minimized_constraints() const
Returns the system of constraints, with no redundant constraint.
static Poly_Con_Relation nothing()
The assertion that says nothing.
static Poly_Gen_Relation nothing()
The assertion that says nothing.
bool le(Boundary_Type type1, const T1 &x1, const Info1 &info1, Boundary_Type type2, const T2 &x2, const Info2 &info2)
The relation between a polyhedron and a generator.
The relation between a polyhedron and a constraint.
void throw_space_dimension_overflow(const char *method, const char *reason)
bool has_strict_inequalities() const
Returns true if and only if *this contains one or more strict inequality constraints.