1#ifndef OASIS_EXPRESSION_HPP
2#define OASIS_EXPRESSION_HPP
9#include <boost/any/unique_any.hpp>
15using any = boost::anys::unique_any;
101 [[nodiscard]] virtual auto
GetCategory() const -> uint32_t;
142 [[nodiscard]]
bool Is()
const
144 return GetType() == T::GetStaticType();
147 template <
template <
typename>
typename T>
149 [[nodiscard]]
bool Is()
const
151 return GetType() == T<Expression>::GetStaticType();
154 template <
template <
typename,
typename>
typename T>
156 [[nodiscard]]
bool Is()
const
158 return GetType() == T<Expression, Expression>::GetStaticType();
182 auto
Accept(T& visitor) const ->
std::expected<typename T::RetT,
std::string_view>;
186 auto
Accept(T& visitor) const -> typename T::RetT;
203 return boost::any_cast<typename T::RetT>(this->
AcceptInternal(visitor));
204 }
catch (boost::bad_any_cast& e) {
215 }
catch (boost::bad_any_cast& e) {
220#define EXPRESSION_TYPE(type) \
221 auto GetType() const -> ExpressionType override \
223 return ExpressionType::type; \
226 static auto GetStaticType() -> ExpressionType \
228 return ExpressionType::type; \
231#define EXPRESSION_CATEGORY(category) \
232 auto GetCategory() const -> uint32_t override \
237 constexpr static auto GetStaticCategory() -> uint32_t \
std::unique_ptr< Oasis::Expression > operator+(const std::unique_ptr< Oasis::Expression > &lhs, const std::unique_ptr< Oasis::Expression > &rhs)
Definition Expression.cpp:260
std::unique_ptr< Oasis::Expression > operator*(const std::unique_ptr< Oasis::Expression > &lhs, const std::unique_ptr< Oasis::Expression > &rhs)
Definition Expression.cpp:284
std::unique_ptr< Oasis::Expression > operator/(const std::unique_ptr< Oasis::Expression > &lhs, const std::unique_ptr< Oasis::Expression > &rhs)
Definition Expression.cpp:296
std::unique_ptr< Oasis::Expression > operator-(const std::unique_ptr< Oasis::Expression > &lhs, const std::unique_ptr< Oasis::Expression > &rhs)
Definition Expression.cpp:272
An expression.
Definition Expression.hpp:63
virtual auto Copy() const -> std::unique_ptr< Expression >=0
Copies this expression.
virtual auto StructurallyEquivalent(const Expression &other) const -> bool=0
Checks whether this expression is structurally equivalent to another expression.
virtual auto Integrate(const Expression &) const -> std::unique_ptr< Expression >
Attempts to integrate this expression using integration rules.
Definition Expression.cpp:239
virtual any AcceptInternal(Visitor &visitor) const =0
This function serializes the expression object.
virtual auto GetCategory() const -> uint32_t
Gets the category of this expression.
Definition Expression.cpp:219
auto FindZeros() const -> std::vector< std::unique_ptr< Expression > >
The FindZeros function finds all rational real zeros, and up to 2 irrational/complex zeros of a polyn...
Definition Expression.cpp:50
bool Is() const
Gets whether this expression is of a specific type.
Definition Expression.hpp:142
auto Accept(T &visitor) const -> std::expected< typename T::RetT, std::string_view >
Definition Expression.hpp:200
bool Is() const
Definition Expression.hpp:149
virtual auto GetType() const -> ExpressionType
Gets the type of this expression.
Definition Expression.cpp:229
virtual auto IntegrateWithBounds(const Expression &, const Expression &, const Expression &) -> std::unique_ptr< Expression >
Attempts to integrate this expression using integration rules.
Definition Expression.cpp:246
auto Simplify() const -> std::unique_ptr< Expression >
Simplifies this expression.
Definition Expression.cpp:254
virtual auto Differentiate(const Expression &) const -> std::unique_ptr< Expression >
Tries to differentiate this function.
Definition Expression.cpp:224
bool Is() const
Definition Expression.hpp:156
virtual auto Substitute(const Expression &var, const Expression &val) -> std::unique_ptr< Expression >=0
virtual auto Generalize() const -> std::unique_ptr< Expression >
Converts this expression to a more general expression.
Definition Expression.cpp:234
virtual auto Equals(const Expression &other) const -> bool=0
Compares this expression to another expression for equality.
Definition FwdDecls.hpp:44
Definition Concepts.hpp:56
Definition Concepts.hpp:61
Definition Concepts.hpp:72
An expression concept.
Definition Concepts.hpp:30
Definition Concepts.hpp:66
boost::anys::unique_any any
Definition Expression.hpp:15
ExpressionCategory
The category of an expression.
Definition Expression.hpp:48
@ UnExp
Definition Expression.hpp:53
@ None
Definition Expression.hpp:49
@ Commutative
Definition Expression.hpp:51
@ Associative
Definition Expression.hpp:50
@ BinExp
Definition Expression.hpp:52
ExpressionType
The type of an expression.
Definition Expression.hpp:22