OASIS
Open Algebra Software
Loading...
Searching...
No Matches
LeafExpression.hpp
Go to the documentation of this file.
1//
2// Created by Matthew McCall on 7/2/23.
3//
4
5#ifndef OASIS_LEAFEXPRESSION_HPP
6#define OASIS_LEAFEXPRESSION_HPP
7
8#include "Expression.hpp"
9#include "Serialization.hpp"
10
11namespace Oasis {
12
20template <typename DerivedT>
21class LeafExpression : public Expression {
22public:
23 [[nodiscard]] auto Copy() const -> std::unique_ptr<Expression> final
24 {
25 return std::make_unique<DerivedT>(*static_cast<const DerivedT*>(this));
26 }
27
28 [[nodiscard]] auto StructurallyEquivalent(const Expression& other) const -> bool final
29 {
30 return this->GetType() == other.GetType();
31 }
32
33 [[nodiscard]] auto Integrate(const Expression& integrationVariable) const -> std::unique_ptr<Expression> override
34 {
35 return Generalize()->Integrate(integrationVariable);
36 }
37
38 [[nodiscard]] auto Differentiate(const Expression& differentiationVariable) const -> std::unique_ptr<Expression> override
39 {
40 return Generalize()->Differentiate(differentiationVariable);
41 }
43 {
44 return this->Copy();
45 }
46
47 void Serialize(SerializationVisitor& visitor) const override
48 {
49 const auto generalized = Generalize();
50 const auto& derivedGeneralized = dynamic_cast<const DerivedT&>(*generalized);
51 visitor.Serialize(derivedGeneralized);
52 }
53};
54
55} // Oasis
56
57#endif // OASIS_LEAFEXPRESSION_HPP
An expression.
Definition Expression.hpp:56
virtual auto GetType() const -> ExpressionType
Gets the type of this expression.
Definition Expression.cpp:220
virtual auto Generalize() const -> std::unique_ptr< Expression >
Converts this expression to a more general expression.
Definition Expression.cpp:225
A leaf expression.
Definition LeafExpression.hpp:21
auto Copy() const -> std::unique_ptr< Expression > final
Copies this expression.
Definition LeafExpression.hpp:23
auto Substitute(const Expression &, const Expression &) -> std::unique_ptr< Expression > override
Definition LeafExpression.hpp:42
auto Differentiate(const Expression &differentiationVariable) const -> std::unique_ptr< Expression > override
Tries to differentiate this function.
Definition LeafExpression.hpp:38
auto Integrate(const Expression &integrationVariable) const -> std::unique_ptr< Expression > override
Attempts to integrate this expression using integration rules.
Definition LeafExpression.hpp:33
auto StructurallyEquivalent(const Expression &other) const -> bool final
Checks whether this expression is structurally equivalent to another expression.
Definition LeafExpression.hpp:28
void Serialize(SerializationVisitor &visitor) const override
This function serializes the expression object.
Definition LeafExpression.hpp:47
Definition Serialization.hpp:50
virtual void Serialize(const Real &real)=0
T is_same_v
Definition Add.hpp:11