OASIS
Open Algebra Software
Loading...
Searching...
No Matches
Negate.hpp
Go to the documentation of this file.
1//
2// Created by Matthew McCall on 3/29/24.
3//
4
5#ifndef OASIS_NEGATE_HPP
6#define OASIS_NEGATE_HPP
7
8#include "Multiply.hpp"
9#include "UnaryExpression.hpp"
10
11namespace Oasis {
12
13template <typename OperandT>
14class Negate final : public UnaryExpression<Negate, OperandT> {
15public:
16 Negate() = default;
17 Negate(const Negate& other)
18 : UnaryExpression<Negate, OperandT>(other)
19 {
20 }
21
22 explicit Negate(const OperandT& operand)
23 : UnaryExpression<Negate, OperandT>(operand)
24 {
25 }
26
27 [[nodiscard]] auto Simplify() const -> std::unique_ptr<Expression> override
28 {
29 return Multiply {
30 Real { -1.0 },
31 this->GetOperand()
32 }
33 .Simplify();
34 }
35
36 [[nodiscard]] auto Differentiate(const Expression& var) const -> std::unique_ptr<Expression> override
37 {
38 const std::unique_ptr<Expression> operandDerivative = this->GetOperand().Differentiate(var);
39 return Negate<Expression> {
40 *operandDerivative
41 }
42 .Simplify();
43 }
44
47};
48
49} // Oasis
50
51#endif // OASIS_NEGATE_HPP
#define EXPRESSION_CATEGORY(category)
Definition Expression.hpp:192
#define EXPRESSION_TYPE(type)
Definition Expression.hpp:181
An expression.
Definition Expression.hpp:56
virtual auto Simplify() const -> std::unique_ptr< Expression >
Simplifies this expression.
Definition Expression.cpp:244
The Multiply expression multiplies two expressions.
Definition Multiply.hpp:40
Definition Negate.hpp:14
Negate(const OperandT &operand)
Definition Negate.hpp:22
auto Differentiate(const Expression &var) const -> std::unique_ptr< Expression > override
Tries to differentiate this function.
Definition Negate.hpp:36
auto Simplify() const -> std::unique_ptr< Expression > override
Simplifies this expression.
Definition Negate.hpp:27
Negate()=default
Negate(const Negate &other)
Definition Negate.hpp:17
A real number.
Definition Real.hpp:15
Definition UnaryExpression.hpp:14
auto GetOperand() const -> const OperandT &
Definition UnaryExpression.hpp:62
Definition Add.hpp:11
@ UnExp
Definition Expression.hpp:46