Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BaseExpression.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <iosfwd>
5#include <map>
6#include <memory>
7#include <set>
8
12
13namespace boost {
14class any;
15}
16
17namespace storm {
18namespace expressions {
19// Forward-declare expression classes.
21class Variable;
22class Expression;
23class Valuation;
25enum struct OperatorType;
26
38
42class BaseExpression : public std::enable_shared_from_this<BaseExpression> {
43 public:
49 BaseExpression(ExpressionManager const& manager, Type const& type);
50
51 // Create default versions of constructors and assignments.
52 BaseExpression(BaseExpression const&) = default;
56
57 // Make the destructor virtual (to allow destruction via base class pointer) and default it.
58 virtual ~BaseExpression() = default;
59
64
73 virtual bool evaluateAsBool(Valuation const* valuation = nullptr) const;
74
83 virtual int_fast64_t evaluateAsInt(Valuation const* valuation = nullptr) const;
84
93 virtual double evaluateAsDouble(Valuation const* valuation = nullptr) const;
94
102 virtual storm::RationalNumber evaluateAsRational() const;
103
109 virtual uint_fast64_t getArity() const;
110
117 virtual std::shared_ptr<BaseExpression const> getOperand(uint_fast64_t operandIndex) const;
118
125 virtual std::string const& getIdentifier() const;
126
133 virtual OperatorType getOperator() const;
134
140 virtual bool containsVariables() const;
141
147 virtual bool isLiteral() const;
148
154 virtual bool isVariable() const;
155
161 virtual bool isTrue() const;
162
168 virtual bool isFalse() const;
169
175 virtual bool isFunctionApplication() const;
176
182 virtual void gatherVariables(std::set<storm::expressions::Variable>& variables) const = 0;
183
189 virtual std::shared_ptr<BaseExpression const> simplify() const = 0;
190
196 std::shared_ptr<BaseExpression const> reduceNesting() const;
197
203 virtual boost::any accept(ExpressionVisitor& visitor, boost::any const& data) const = 0;
204
210 bool hasNumericalType() const;
211
217 bool hasIntegerType() const;
218
224 bool hasBitVectorType() const;
225
231 bool hasBooleanType() const;
232
238 bool hasRationalType() const;
239
245 std::shared_ptr<BaseExpression const> getSharedPointer() const;
246
252 ExpressionManager const& getManager() const;
253
259 Type const& getType() const;
260
261 friend std::ostream& operator<<(std::ostream& stream, BaseExpression const& expression);
262
263 virtual bool isIfThenElseExpression() const;
265
266 virtual bool isBinaryBooleanFunctionExpression() const;
268
269 virtual bool isBinaryNumericalFunctionExpression() const;
271
272 virtual bool isBinaryRelationExpression() const;
274
275 virtual bool isBooleanLiteralExpression() const;
277
278 virtual bool isIntegerLiteralExpression() const;
280
281 virtual bool isRationalLiteralExpression() const;
283
284 virtual bool isUnaryBooleanFunctionExpression() const;
286
287 virtual bool isUnaryNumericalFunctionExpression() const;
289
290 virtual bool isVariableExpression() const;
292
293 virtual bool isPredicateExpression() const;
295
296 protected:
302 virtual void printToStream(std::ostream& stream) const = 0;
303
304 private:
305 // The manager responsible for this expression.
306 ExpressionManager const& manager;
307
308 // The return type of this expression.
309 Type type;
310};
311} // namespace expressions
312} // namespace storm
BinaryNumericalFunctionExpression const & asBinaryNumericalFunctionExpression() const
bool hasBooleanType() const
Retrieves whether the expression has a boolean type.
virtual bool isUnaryBooleanFunctionExpression() const
virtual storm::RationalNumber evaluateAsRational() const
Evaluates the expression and returns the resulting rational number.
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const =0
Accepts the given visitor by calling its visit method.
virtual bool isBinaryRelationExpression() const
virtual bool isBooleanLiteralExpression() const
Expression toExpression() const
Converts the base expression to a proper expression.
BaseExpression & operator=(BaseExpression &&)=delete
virtual std::string const & getIdentifier() const
Retrieves the identifier associated with this expression.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const =0
Retrieves the set of all variables that appear in the expression.
BaseExpression(BaseExpression const &)=default
friend std::ostream & operator<<(std::ostream &stream, BaseExpression const &expression)
virtual bool isFunctionApplication() const
Checks if the expression is a function application (of any sort).
virtual std::shared_ptr< BaseExpression const > simplify() const =0
Simplifies the expression according to some simple rules.
BooleanLiteralExpression const & asBooleanLiteralExpression() const
virtual bool isFalse() const
Checks if the expression is equal to the boolean literal false.
virtual bool isBinaryBooleanFunctionExpression() const
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
virtual double evaluateAsDouble(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
IntegerLiteralExpression const & asIntegerLiteralExpression() const
virtual bool isBinaryNumericalFunctionExpression() const
BaseExpression & operator=(BaseExpression const &)=delete
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const
Retrieves the given operand from the expression.
std::shared_ptr< BaseExpression const > reduceNesting() const
Tries to flatten the syntax tree of the expression, e.g., 1 + (2 + (3 + 4)) becomes (1 + 2) + (3 + 4)...
virtual bool isVariable() const
Retrieves whether the expression is a variable.
bool hasIntegerType() const
Retrieves whether the expression has an integer type.
bool hasBitVectorType() const
Retrieves whether the expression has a bitvector type.
virtual bool isIfThenElseExpression() const
virtual bool evaluateAsBool(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
virtual bool isLiteral() const
Retrieves whether the expression is a literal.
bool hasRationalType() const
Retrieves whether the expression has a rational return type.
RationalLiteralExpression const & asRationalLiteralExpression() const
virtual bool isVariableExpression() const
virtual bool isUnaryNumericalFunctionExpression() const
bool hasNumericalType() const
Retrieves whether the expression has a numerical type, i.e., integer or double.
virtual bool isTrue() const
Checks if the expression is equal to the boolean literal true.
VariableExpression const & asVariableExpression() const
Type const & getType() const
Retrieves the type of the expression.
IfThenElseExpression const & asIfThenElseExpression() const
BinaryBooleanFunctionExpression const & asBinaryBooleanFunctionExpression() const
virtual bool isPredicateExpression() const
std::shared_ptr< BaseExpression const > getSharedPointer() const
Retrieves a shared pointer to this expression.
UnaryBooleanFunctionExpression const & asUnaryBooleanFunctionExpression() const
BinaryRelationExpression const & asBinaryRelationExpression() const
virtual uint_fast64_t getArity() const
Returns the arity of the expression.
BaseExpression(ExpressionManager const &manager, Type const &type)
Constructs a base expression with the given return type.
virtual void printToStream(std::ostream &stream) const =0
Prints the expression to the given stream.
BaseExpression(BaseExpression &&)=default
virtual bool containsVariables() const
Retrieves whether the expression contains a variable.
virtual OperatorType getOperator() const
Retrieves the operator of a function application.
UnaryNumericalFunctionExpression const & asUnaryNumericalFunctionExpression() const
virtual int_fast64_t evaluateAsInt(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
virtual bool isRationalLiteralExpression() const
PredicateExpression const & asPredicateExpression() const
virtual bool isIntegerLiteralExpression() const
This class is responsible for managing a set of typed variables and all expressions using these varia...
The base class of all binary expressions.
The base class of all valuations of variables.
Definition Valuation.h:15