Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BaseExpression.h
Go to the documentation of this file.
1#ifndef STORM_STORAGE_EXPRESSIONS_BASEEXPRESSION_H_
2#define STORM_STORAGE_EXPRESSIONS_BASEEXPRESSION_H_
3
4#include <cstdint>
5#include <iosfwd>
6#include <map>
7#include <memory>
8#include <set>
9
13
14namespace boost {
15class any;
16}
17
18namespace storm {
19namespace expressions {
20// Forward-declare expression classes.
21class ExpressionManager;
22class Variable;
23class Expression;
24class Valuation;
25class ExpressionVisitor;
26enum struct OperatorType;
27
28class IfThenElseExpression;
29class BinaryBooleanFunctionExpression;
30class BinaryNumericalFunctionExpression;
31class BinaryRelationExpression;
32class BooleanLiteralExpression;
33class IntegerLiteralExpression;
34class RationalLiteralExpression;
35class UnaryBooleanFunctionExpression;
36class UnaryNumericalFunctionExpression;
37class VariableExpression;
38class PredicateExpression;
39
43class BaseExpression : public std::enable_shared_from_this<BaseExpression> {
44 public:
50 BaseExpression(ExpressionManager const& manager, Type const& type);
51
52 // Create default versions of constructors and assignments.
53 BaseExpression(BaseExpression const&) = default;
57
58 // Make the destructor virtual (to allow destruction via base class pointer) and default it.
59 virtual ~BaseExpression() = default;
60
65
74 virtual bool evaluateAsBool(Valuation const* valuation = nullptr) const;
75
84 virtual int_fast64_t evaluateAsInt(Valuation const* valuation = nullptr) const;
85
94 virtual double evaluateAsDouble(Valuation const* valuation = nullptr) const;
95
103 virtual storm::RationalNumber evaluateAsRational() const;
104
110 virtual uint_fast64_t getArity() const;
111
118 virtual std::shared_ptr<BaseExpression const> getOperand(uint_fast64_t operandIndex) const;
119
126 virtual std::string const& getIdentifier() const;
127
134 virtual OperatorType getOperator() const;
135
141 virtual bool containsVariables() const;
142
148 virtual bool isLiteral() const;
149
155 virtual bool isVariable() const;
156
162 virtual bool isTrue() const;
163
169 virtual bool isFalse() const;
170
176 virtual bool isFunctionApplication() const;
177
183 virtual void gatherVariables(std::set<storm::expressions::Variable>& variables) const = 0;
184
190 virtual std::shared_ptr<BaseExpression const> simplify() const = 0;
191
197 std::shared_ptr<BaseExpression const> reduceNesting() const;
198
204 virtual boost::any accept(ExpressionVisitor& visitor, boost::any const& data) const = 0;
205
211 bool hasNumericalType() const;
212
218 bool hasIntegerType() const;
219
225 bool hasBitVectorType() const;
226
232 bool hasBooleanType() const;
233
239 bool hasRationalType() const;
240
246 std::shared_ptr<BaseExpression const> getSharedPointer() const;
247
253 ExpressionManager const& getManager() const;
254
260 Type const& getType() const;
261
262 friend std::ostream& operator<<(std::ostream& stream, BaseExpression const& expression);
263
264 virtual bool isIfThenElseExpression() const;
266
267 virtual bool isBinaryBooleanFunctionExpression() const;
269
270 virtual bool isBinaryNumericalFunctionExpression() const;
272
273 virtual bool isBinaryRelationExpression() const;
275
276 virtual bool isBooleanLiteralExpression() const;
278
279 virtual bool isIntegerLiteralExpression() const;
281
282 virtual bool isRationalLiteralExpression() const;
284
285 virtual bool isUnaryBooleanFunctionExpression() const;
287
288 virtual bool isUnaryNumericalFunctionExpression() const;
290
291 virtual bool isVariableExpression() const;
293
294 virtual bool isPredicateExpression() const;
296
297 protected:
303 virtual void printToStream(std::ostream& stream) const = 0;
304
305 private:
306 // The manager responsible for this expression.
307 ExpressionManager const& manager;
308
309 // The return type of this expression.
310 Type type;
311};
312} // namespace expressions
313} // namespace storm
314
315#endif /* STORM_STORAGE_EXPRESSIONS_BASEEXPRESSION_H_ */
The base class of all expression classes.
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.
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:16
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
Definition parametric.h:41
LabParser.cpp.
Definition cli.cpp:18