dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
IfThenElseEliminator.h
1
8#pragma once
9
10#include <unordered_set>
11#include <vector>
12
13#include "dlinear/symbolic/FormulaVisitor.h"
14#include "dlinear/symbolic/GenericExpressionVisitor.h"
15#include "dlinear/symbolic/literal.h"
16#include "dlinear/symbolic/symbolic.h"
17#include "dlinear/util/Config.h"
18#include "dlinear/util/Stats.h"
19
20namespace dlinear {
28class IfThenElseEliminator : public FormulaVisitor<const Formula &>,
29 public GenericExpressionVisitor<Expression, const Formula &> {
30 public:
32
33 explicit IfThenElseEliminator(const Config &config)
34 : FormulaVisitor<const Formula &>{config, "IfThenElseEliminator"},
36 counter_{0} {}
42 [[nodiscard]] Formula Process(const Formula &f);
43 [[nodiscard]] std::pair<Expression, Formula> Process(const Expression &e);
44 [[nodiscard]] const std::unordered_map<Expression, Variable> &variables() const;
45
46 private:
47 // Handle expressions.
48 Expression VisitExpression(const Expression &e, const Formula &guard) const override;
49 Expression VisitVariable(const Expression &e, const Formula &guard) const override;
50 Expression VisitConstant(const Expression &e, const Formula &guard) const override;
51 Expression VisitAddition(const Expression &e, const Formula &guard) const override;
52 Expression VisitMultiplication(const Expression &e, const Formula &guard) const override;
53 Expression VisitDivision(const Expression &e, const Formula &guard) const override;
54 Expression VisitLog(const Expression &e, const Formula &guard) const override;
55 Expression VisitAbs(const Expression &e, const Formula &guard) const override;
56 Expression VisitExp(const Expression &e, const Formula &guard) const override;
57 Expression VisitSqrt(const Expression &e, const Formula &guard) const override;
58 Expression VisitPow(const Expression &e, const Formula &guard) const override;
59 Expression VisitSin(const Expression &e, const Formula &guard) const override;
60 Expression VisitCos(const Expression &e, const Formula &guard) const override;
61 Expression VisitTan(const Expression &e, const Formula &guard) const override;
62 Expression VisitAsin(const Expression &e, const Formula &guard) const override;
63 Expression VisitAcos(const Expression &e, const Formula &guard) const override;
64 Expression VisitAtan(const Expression &e, const Formula &guard) const override;
65 Expression VisitAtan2(const Expression &e, const Formula &guard) const override;
66 Expression VisitSinh(const Expression &e, const Formula &guard) const override;
67 Expression VisitCosh(const Expression &e, const Formula &guard) const override;
68 Expression VisitTanh(const Expression &e, const Formula &guard) const override;
69 Expression VisitMin(const Expression &e, const Formula &guard) const override;
70 Expression VisitMax(const Expression &e, const Formula &guard) const override;
71 Expression VisitIfThenElse(const Expression &e, const Formula &guard) const override;
72 Expression VisitUninterpretedFunction(const Expression &e, const Formula &guard) const override;
73
74 // Handle formula
75 Formula VisitFalse(const Formula &f, const Formula &guard) const override;
76 Formula VisitTrue(const Formula &f, const Formula &guard) const override;
77 Formula VisitVariable(const Formula &f, const Formula &guard) const override;
78 Formula VisitEqualTo(const Formula &f, const Formula &guard) const override;
79 Formula VisitNotEqualTo(const Formula &f, const Formula &guard) const override;
80 Formula VisitGreaterThan(const Formula &f, const Formula &guard) const override;
81 Formula VisitGreaterThanOrEqualTo(const Formula &f, const Formula &guard) const override;
82 Formula VisitLessThan(const Formula &f, const Formula &guard) const override;
83 Formula VisitLessThanOrEqualTo(const Formula &f, const Formula &guard) const override;
84 Formula VisitConjunction(const Formula &f, const Formula &guard) const override;
85 Formula VisitDisjunction(const Formula &f, const Formula &guard) const override;
86 Formula VisitNegation(const Formula &f, const Formula &guard) const override;
87 Formula VisitForall(const Formula &f, const Formula &guard) const override;
88
89 // ---------------
90 // Member fields
91 // ---------------
92
93 mutable std::vector<Formula> added_formulas_;
95 mutable std::unordered_set<Variable> ite_variables_;
96 mutable std::unordered_map<Expression, Variable>
98 mutable std::unordered_map<Variable, Formula>
100
101 mutable std::size_t counter_;
102};
103
104} // namespace dlinear
Simple dataclass used to store the configuration of the program.
Definition Config.h:38
This base class provides all the methods expected to visit the underlying formula and return a modifi...
Generic expression visitor implementing the visitor pattern.
IfThenElseEliminator class.
std::size_t counter_
Counter for the number of introduced variables.
Formula Process(const Formula &f)
Returns a equisatisfiable formula by eliminating if-then-expressions in f by introducing new variable...
std::unordered_map< Expression, Variable > ite_to_var_
Mapping from ITE to the corresponding variable obtained by ITE elimination.
std::vector< Formula > added_formulas_
The added formulas introduced by the elimination process.
std::unordered_set< Variable > ite_variables_
The variables introduced by the elimination process.
std::unordered_map< Variable, Formula > ite_var_to_formulas_
Mapping from ITE to the corresponding variable obtained by ITE elimination.
Represents a symbolic form of an expression.
Represents a symbolic form of a first-order logic formula.
Global namespace for the dlinear library.