OASIS
Open Algebra Software
Loading...
Searching...
No Matches
Oasis::Subtract< MinuendT, SubtrahendT > Class Template Reference

The Subtract expression subtracts two expressions. More...

#include <Oasis/Subtract.hpp>

Inheritance diagram for Oasis::Subtract< MinuendT, SubtrahendT >:
[legend]
Collaboration diagram for Oasis::Subtract< MinuendT, SubtrahendT >:
[legend]

Public Member Functions

 Subtract ()=default
 
 Subtract (const Subtract< MinuendT, SubtrahendT > &other)
 
 Subtract (const MinuendT &addend1, const SubtrahendT &addend2)
 
auto operator= (const Subtract &other) -> Subtract &=default
 
- Public Member Functions inherited from Oasis::BinaryExpression< DerivedT, MostSigOpT, LeastSigOpT >
 BinaryExpression ()=default
 
 BinaryExpression (const BinaryExpression &other)
 
 BinaryExpression (const MostSigOpT &mostSigOp, const LeastSigOpT &leastSigOp)
 
template<IExpression Op1T, IExpression Op2T, IExpression... OpsT>
 BinaryExpression (const Op1T &op1, const Op2T &op2, const OpsT &... ops)
 
auto Copy () const -> std::unique_ptr< Expression > final
 Copies this expression.
 
auto Differentiate (const Expression &differentiationVariable) const -> std::unique_ptr< Expression > override
 Tries to differentiate this function.
 
auto Equals (const Expression &other) const -> bool final
 Compares this expression to another expression for equality.
 
auto Generalize () const -> std::unique_ptr< Expression > final
 Converts this expression to a more general expression.
 
auto Integrate (const Expression &integrationVariable) const -> std::unique_ptr< Expression > override
 Attempts to integrate this expression using integration rules.
 
auto StructurallyEquivalent (const Expression &other) const -> bool final
 Checks whether this expression is structurally equivalent to another expression.
 
auto Flatten (std::vector< std::unique_ptr< Expression > > &out) const -> void
 Flattens this expression.
 
auto GetMostSigOp () const -> const MostSigOpT &
 Gets the most significant operand of this expression.
 
auto GetLeastSigOp () const -> const LeastSigOpT &
 Gets the least significant operand of this expression.
 
auto HasMostSigOp () const -> bool
 Gets whether this expression has a most significant operand.
 
auto HasLeastSigOp () const -> bool
 Gets whether this expression has a least significant operand.
 
template<typename T >
requires IsAnyOf<T, MostSigOpT, Expression>
auto SetMostSigOp (const T &op) -> bool
 Sets the most significant operand of this expression.
 
template<typename T >
requires IsAnyOf<T, LeastSigOpT, Expression>
auto SetLeastSigOp (const T &op) -> bool
 Sets the least significant operand of this expression.
 
auto Substitute (const Expression &var, const Expression &val) -> std::unique_ptr< Expression > override
 
auto SwapOperands () const -> DerivedT< LeastSigOpT, MostSigOpT >
 Swaps the operands of this expression.
 
auto operator= (const BinaryExpression &other) -> BinaryExpression &=default
 
auto AcceptInternal (Visitor &visitor) const -> any override
 This function serializes the expression object.
 
- Public Member Functions inherited from Oasis::Expression
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 polynomial.
 
virtual auto GetCategory () const -> uint32_t
 Gets the category of this expression.
 
virtual auto GetType () const -> ExpressionType
 Gets the type of this expression.
 
virtual auto IntegrateWithBounds (const Expression &, const Expression &, const Expression &) -> std::unique_ptr< Expression >
 Attempts to integrate this expression using integration rules.
 
template<IExpression T>
bool Is () const
 Gets whether this expression is of a specific type.
 
template<template< typename > typename T>
requires (DerivedFromUnaryExpression<T<Expression>> && !DerivedFromBinaryExpression<T<Expression>>)
bool Is () const
 
template<template< typename, typename > typename T>
requires DerivedFromBinaryExpression<T<Expression, Expression>>
bool Is () const
 
auto Simplify () const -> std::unique_ptr< Expression >
 Simplifies this expression.
 
template<IVisitor T>
requires ExpectedWithString<typename T::RetT>
auto Accept (T &visitor) const -> std::expected< typename T::RetT, std::string_view >
 
template<IVisitor T>
requires ExpectedWithString<typename T::RetT>
auto Accept (T &visitor) const -> typename T::RetT
 
virtual ~Expression ()=default
 

Additional Inherited Members

- Public Attributes inherited from Oasis::BinaryExpression< DerivedT, MostSigOpT, LeastSigOpT >
std::unique_ptr< MostSigOpT > mostSigOp
 
std::unique_ptr< LeastSigOpT > leastSigOp
 

Detailed Description

template<typename MinuendT = Expression, typename SubtrahendT = MinuendT>
class Oasis::Subtract< MinuendT, SubtrahendT >

The Subtract expression subtracts two expressions.

Parameters

Template Parameters
MinuendTThe expression to be subtracted from.
SubtrahendTThe expression to subtract from the minuend.

Examples

The Subtract expression can take in a multitude of Oasis classes.

Subtracting two Real values from each other.

};
Oasis::InFixSerializer result;
auto resultant = sub.Simplify();
std::println("Result: {}", resultant->Accept(result).value());
// Will print: -1
auto Simplify() const -> std::unique_ptr< Expression >
Simplifies this expression.
Definition Expression.cpp:254
A real number.
Definition Real.hpp:15
The Subtract expression subtracts two expressions.
Definition Subtract.hpp:159
T is_same_v

Subtracting one Real value from a Variable expression:

};
Oasis::InFixSerializer result;
auto resultant = sub.Simplify();
std::println("Result: {}", resultant->Accept(result).value());
// Will print: x+-5
An algebraic variable.
Definition Variable.hpp:30

Adding two Variables together:

};
Oasis::InFixSerializer result;
auto resultant = sub.Simplify();
std::println("Result: {}", resultant->Accept(result).value());
// Will print: 0

Subtracting two variables from each other if they are different:

};
Oasis::InFixSerializer result;
auto resultant = sub.Simplify();
std::println("Result: {}", resultant->Accept(result).value());
// Will print: (x+(-1*y))

Subtracting two expressions from each other:

Note
As of right now, while Oasis will accept two expressions into its constructor, results may be inaccurate. For example, expressions containing more than two variables will produce inaccurate results. See Example 2 down below.

Example 1:

std::string exp1 = {"2y-15"};
std::string exp2 = {"4y-10"};
const auto preproc1 = Oasis::PreProcessInFix(exp1);
auto midResult1 = Oasis::FromInFix(preproc1);
const std::unique_ptr<Oasis::Expression> expression1 = std::move(midResult1).value();
const auto preproc2 = Oasis::PreProcessInFix(exp2);
auto midResult2 = Oasis::FromInFix(preproc2);
const std::unique_ptr<Oasis::Expression> expression2 = std::move(midResult2).value();
*expression1,
*expression2
};
Oasis::InFixSerializer result;
auto resultant = sub.Simplify();
std::println("Result: {}", resultant->Accept(result).value());
// Will print: ((-2*y)+-5)

Example 2 (Inaccurate Results):

std::string exp1 = {"4x+2y-15"};
std::string exp2 = {"2x+4y-10"};
const auto preproc1 = Oasis::PreProcessInFix(exp1);
auto midResult1 = Oasis::FromInFix(preproc1);
const std::unique_ptr<Oasis::Expression> expression1 = std::move(midResult1).value();
const auto preproc2 = Oasis::PreProcessInFix(exp2);
auto midResult2 = Oasis::FromInFix(preproc2);
const std::unique_ptr<Oasis::Expression> expression2 = std::move(midResult2).value();
*expression1,
*expression2
};
Oasis::InFixSerializer result;
auto resultant = sub.Simplify();
std::println("Result: {}", resultant->Accept(result).value());
// Will print: (((4*x)+(2*y))+-5)

Constructor & Destructor Documentation

◆ Subtract() [1/3]

template<typename MinuendT = Expression, typename SubtrahendT = MinuendT>
Oasis::Subtract< MinuendT, SubtrahendT >::Subtract ( )
default

◆ Subtract() [2/3]

template<typename MinuendT = Expression, typename SubtrahendT = MinuendT>
Oasis::Subtract< MinuendT, SubtrahendT >::Subtract ( const Subtract< MinuendT, SubtrahendT > & other)
inline

◆ Subtract() [3/3]

template<typename MinuendT = Expression, typename SubtrahendT = MinuendT>
Oasis::Subtract< MinuendT, SubtrahendT >::Subtract ( const MinuendT & addend1,
const SubtrahendT & addend2 )
inline

Member Function Documentation

◆ operator=()

template<typename MinuendT = Expression, typename SubtrahendT = MinuendT>
auto Oasis::Subtract< MinuendT, SubtrahendT >::operator= ( const Subtract< MinuendT, SubtrahendT > & other) -> Subtract &=default
default

The documentation for this class was generated from the following files: