-
Notifications
You must be signed in to change notification settings - Fork 29
Replaced uses of Simplify() with SimplifyVisitor{} #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
404Naz
wants to merge
16
commits into
open-algebra:master
Choose a base branch
from
404Naz:feature-visitor-simplify
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bf022c0
Replaced uses of Simplify() with SimplifyVisitor{}. This is to levera…
404Naz 686e73a
Merged and fixed cases.
404Naz fdc6d54
Tried to remove uses of simplify.
404Naz b3f0449
Tried to remove uses of simplify.
404Naz 986f687
Fixed issues and hopefully removed bad uses of simplify().
404Naz 579ea99
Fixed issues and hopefully removed bad uses of simplify().
404Naz 297f7ac
Updated readme with new visitor pattern.
404Naz c095399
Fixed WError warnings
404Naz 0503445
Fixed WError warnings
404Naz 9062df1
Fixed WError warnings (attempt 3?)
404Naz f1effe9
Fixed WError warnings (attempt 4)
404Naz 34fdd53
Fixed WError warnings (attempt 5)
404Naz 73c0e8f
[Actions] Format CMakeLists.txt
invalid-email-address 42896d8
Rerun Workflows
404Naz 795d45c
Clang-Format
404Naz 2ba3bac
Clang-Format
404Naz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // | ||
| // Created by Andrew Nazareth on 9/23/25. | ||
| // | ||
|
|
||
| #ifndef SIMPLIFYVISITOR_HPP | ||
| #define SIMPLIFYVISITOR_HPP | ||
|
|
||
| #include <format> | ||
| #include <string> | ||
|
|
||
| #include <gsl/gsl-lite.hpp> | ||
|
|
||
| #include "Oasis/Visit.hpp" | ||
|
|
||
| namespace Oasis { | ||
|
|
||
| struct SimplifyOpts { | ||
| enum class AngleUnits { | ||
| RADIANS, | ||
| DEGREES, | ||
| } angleUnits | ||
| = AngleUnits::RADIANS; | ||
| }; | ||
|
|
||
| class SimplifyVisitor final : public TypedVisitor<std::expected<gsl::not_null<std::unique_ptr<Expression>>, std::string>> { | ||
| public: | ||
| SimplifyVisitor(); | ||
| explicit SimplifyVisitor(SimplifyOpts& opts); | ||
|
|
||
| auto TypedVisit(const Real& real) -> RetT override; | ||
| auto TypedVisit(const Imaginary& imaginary) -> RetT override; | ||
| auto TypedVisit(const Variable& variable) -> RetT override; | ||
| auto TypedVisit(const Undefined& undefined) -> RetT override; | ||
| auto TypedVisit(const Add<Expression, Expression>& add) -> RetT override; | ||
| auto TypedVisit(const Subtract<Expression, Expression>& subtract) -> RetT override; | ||
| auto TypedVisit(const Multiply<Expression, Expression>& multiply) -> RetT override; | ||
| auto TypedVisit(const Divide<Expression, Expression>& divide) -> RetT override; | ||
| auto TypedVisit(const Exponent<Expression, Expression>& exponent) -> RetT override; | ||
| auto TypedVisit(const Log<Expression, Expression>& log) -> RetT override; | ||
| auto TypedVisit(const Negate<Expression>& negate) -> RetT override; | ||
| auto TypedVisit(const Sine<Expression>& sine) -> RetT override; | ||
| auto TypedVisit(const Derivative<Expression, Expression>& derivative) -> RetT override; | ||
| auto TypedVisit(const Integral<Expression, Expression>& integral) -> RetT override; | ||
| auto TypedVisit(const Matrix& matrix) -> RetT override; | ||
| auto TypedVisit(const EulerNumber&) -> RetT override; | ||
| auto TypedVisit(const Pi&) -> RetT override; | ||
| auto TypedVisit(const Magnitude<Expression>& magnitude) -> RetT override; | ||
|
|
||
| [[nodiscard]] SimplifyOpts GetOptions() const; | ||
|
|
||
| private: | ||
| SimplifyOpts options; | ||
| }; | ||
|
|
||
| } // Oasis | ||
|
|
||
| #endif // SIMPLIFYVISITOR_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // | ||
| // Created by Andrew Nazareth on 9/19/25. | ||
| // | ||
|
|
||
| #ifndef OASIS_SINE_HPP | ||
| #define OASIS_SINE_HPP | ||
|
|
||
| #include "UnaryExpression.hpp" | ||
|
|
||
| namespace Oasis { | ||
|
|
||
| template <IExpression OperandT> | ||
| class Sine; | ||
|
|
||
| template <> | ||
| class Sine<Expression> final : public UnaryExpression<Sine> { | ||
| public: | ||
| Sine() = default; | ||
| Sine(const Sine& other) | ||
| : UnaryExpression<Sine>(other) | ||
| { | ||
| } | ||
|
|
||
| explicit Sine(const Expression& operand) | ||
| : UnaryExpression<Sine>(operand) | ||
| { | ||
| } | ||
|
|
||
| [[deprecated]] [[nodiscard]] auto Simplify() const -> std::unique_ptr<Expression> override; | ||
|
|
||
| [[nodiscard]] auto Differentiate(const Expression& var) const -> std::unique_ptr<Expression> override; | ||
|
|
||
| [[nodiscard]] auto Integrate(const Expression& var) const -> std::unique_ptr<Expression> override; | ||
|
|
||
| EXPRESSION_TYPE(Sine) | ||
| EXPRESSION_CATEGORY(UnExp) | ||
| }; | ||
|
|
||
| } // Oasis | ||
|
|
||
| #endif // OASIS_SINE_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the
= 0from theSimplifymethod so that it is no longer pure virtual (i.e abstract). The default implementation should call the newSimplifyVisitor. This is so that new Expression types don't have to implement the now deprecatedSimplify.