6#include "ExpressionEvaluator.h"
13#include "dlinear/libs/libgmp.h"
14#include "dlinear/symbolic/literal.h"
15#include "dlinear/util/exception.h"
25 return VisitExpression(e_, box);
29Interval ExpressionEvaluator::VisitVariable(
const Expression& e,
const Box& box)
const {
30 const Variable& var{get_variable(e)};
34Interval ExpressionEvaluator::VisitConstant(
const Expression& e,
const Box&)
const {
35 return Interval{get_constant_value(e)};
38Interval ExpressionEvaluator::VisitRealConstant(
const Expression&,
const Box&)
const {
39 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
42Interval ExpressionEvaluator::VisitAddition(
const Expression& e,
const Box& box)
const {
43 const mpq_class& c{get_constant_in_addition(e)};
44 const auto& expr_to_coeff_map = get_expr_to_coeff_map_in_addition(e);
45 return std::accumulate(expr_to_coeff_map.begin(), expr_to_coeff_map.end(), Interval{c},
46 [
this, &box](
const Interval& init,
const std::pair<const Expression, mpq_class>& p) {
47 return init + VisitExpression(p.first, box) * p.second;
51Interval ExpressionEvaluator::VisitMultiplication(
const Expression& e,
const Box& box)
const {
52 const mpq_class& c{get_constant_in_multiplication(e)};
53 const auto& base_to_exponent_map = get_base_to_exponent_map_in_multiplication(e);
54 return accumulate(base_to_exponent_map.begin(), base_to_exponent_map.end(), Interval{c},
55 [
this, &box](
const Interval& init,
const std::pair<const Expression, Expression>& p) {
56 return init * VisitPow(p.first, p.second, box);
60Interval ExpressionEvaluator::VisitDivision(
const Expression&,
const Box&)
const {
61 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
64Interval ExpressionEvaluator::VisitLog(
const Expression&,
const Box&)
const {
65 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
68Interval ExpressionEvaluator::VisitAbs(
const Expression&,
const Box&)
const {
69 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
72Interval ExpressionEvaluator::VisitExp(
const Expression&,
const Box&)
const {
73 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
76Interval ExpressionEvaluator::VisitSqrt(
const Expression&,
const Box&)
const {
77 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
80Interval ExpressionEvaluator::VisitPow(
const Expression& e,
const Box& box)
const {
81 return VisitPow(get_first_argument(e), get_second_argument(e), box);
84Interval ExpressionEvaluator::VisitPow(
const Expression&,
const Expression&,
const Box&)
const {
85 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
87 const Interval first{Visit(e1, box)};
88 const Interval second{Visit(e2, box)};
89 if (second.is_degenerated() && !second.is_empty()) {
90 DLINEAR_ASSERT(second.lb() == second.ub(),
"Interval must be a point.");
91 const double point{second.lb()};
92 if (is_integer(point)) {
96 return pow(first,
static_cast<int>(point));
99 return pow(first, point);
102 return pow(first, second);
107Interval ExpressionEvaluator::VisitSin(
const Expression&,
const Box&)
const {
108 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
111Interval ExpressionEvaluator::VisitCos(
const Expression&,
const Box&)
const {
112 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
115Interval ExpressionEvaluator::VisitTan(
const Expression&,
const Box&)
const {
116 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
119Interval ExpressionEvaluator::VisitAsin(
const Expression&,
const Box&)
const {
120 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
123Interval ExpressionEvaluator::VisitAcos(
const Expression&,
const Box&)
const {
124 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
127Interval ExpressionEvaluator::VisitAtan(
const Expression&,
const Box&)
const {
128 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
131Interval ExpressionEvaluator::VisitAtan2(
const Expression&,
const Box&)
const {
132 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
135Interval ExpressionEvaluator::VisitSinh(
const Expression&,
const Box&)
const {
136 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
139Interval ExpressionEvaluator::VisitCosh(
const Expression&,
const Box&)
const {
140 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
143Interval ExpressionEvaluator::VisitTanh(
const Expression&,
const Box&)
const {
144 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
147Interval ExpressionEvaluator::VisitMin(
const Expression&,
const Box&)
const {
148 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
151Interval ExpressionEvaluator::VisitMax(
const Expression&,
const Box&)
const {
152 DLINEAR_RUNTIME_ERROR(
"Operation is not supported yet.");
155Interval ExpressionEvaluator::VisitIfThenElse(
const Expression& ,
const Box& )
const {
156 DLINEAR_RUNTIME_ERROR(
"If-then-else expression is not supported yet.");
159Interval ExpressionEvaluator::VisitUninterpretedFunction(
const Expression& ,
161 DLINEAR_RUNTIME_ERROR(
"Uninterpreted function is not supported.");
164std::ostream& operator<<(std::ostream& os,
const ExpressionEvaluator& expression_evaluator) {
165 return os <<
"ExpressionEvaluator(" << expression_evaluator.expression() <<
")";
Collection of variables with associated intervals.
Simple dataclass used to store the configuration of the program.
ExpressionEvaluator(Expression e, const Config &config)
Construct a new ExpressionEvaluator object with the given expression and configuration.
Interval Process(const Box &box) const
Evaluates the expression with box.
Generic expression visitor implementing the visitor pattern.
const Config & config() const
void Increase()
Increase the iteration counter by one.
Timer & m_timer()
Get read-write access to the timer of the stats.
bool enabled() const
Check whether the stats is enabled.
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
Represents a symbolic form of an expression.
Global namespace for the dlinear library.