carl  24.04
Computer ARithmetic Library
Bound.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "BasicConstraint.h"
4 
5 namespace carl {
6 
7 /**
8  * @return true, if this constraint is a bound.
9  */
10 template<typename Pol>
11 bool is_bound(const BasicConstraint<Pol>& constr) {
12  auto vars = variables(constr);
13  if (vars.size() != 1 || constr.lhs().degree(*vars.begin()) != 1) return false;
14  return constr.relation() != Relation::NEQ;
15 }
16 
17 /**
18  * @return true, if this constraint is a lower bound.
19  */
20 template<typename Pol>
21 bool is_lower_bound(const BasicConstraint<Pol>& constr) {
22  if (is_bound(constr)) {
23  if (constr.relation() == Relation::EQ) return true;
24  const typename Pol::NumberType& coeff = constr.lhs().lterm().coeff();
25  if (coeff < 0)
26  return (constr.relation() == Relation::LEQ || constr.relation() == Relation::LESS);
27  else {
28  assert(coeff > 0);
29  return (constr.relation() == Relation::GEQ || constr.relation() == Relation::GREATER);
30  }
31  }
32  return false;
33 }
34 
35 /**
36  * @return true, if this constraint is an upper bound.
37  */
38 template<typename Pol>
39 bool is_upper_bound(const BasicConstraint<Pol>& constr) {
40  if (is_bound(constr)) {
41  if (constr.relation() == Relation::EQ) return true;
42  const typename Pol::NumberType& coeff = constr.lhs().lterm().coeff();
43  if (coeff > 0)
44  return (constr.relation() == Relation::LEQ || constr.relation() == Relation::LESS);
45  else {
46  assert(coeff < 0);
47  return (constr.relation() == Relation::GEQ || constr.relation() == Relation::GREATER);
48  }
49  }
50  return false;
51 }
52 
53 }
carl is the main namespace for the library.
bool is_bound(const BasicConstraint< Pol > &constr)
Definition: Bound.h:11
bool is_upper_bound(const BasicConstraint< Pol > &constr)
Definition: Bound.h:39
@ GREATER
Definition: SignCondition.h:15
bool is_lower_bound(const BasicConstraint< Pol > &constr)
Definition: Bound.h:21
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
Represent a polynomial (in)equality against zero.
const Pol & lhs() const
Relation relation() const