#include <Equation.h>
Representation of mathematical statement
- Examples
- symb/TestSymbolic.cpp.
◆ Equation() [1/3]
empty default constructor
◆ Equation() [2/3]
Equation::Equation |
( |
const char * |
val | ) |
|
|
inlineexplicit |
default constructor for char* representation
- Parameters
-
◆ Equation() [3/3]
Equation::Equation |
( |
const std::string & |
val | ) |
|
|
inlineexplicit |
default constructor for string representation
- Parameters
-
◆ ApplyOperator()
std::shared_ptr< MathNode > Equation::ApplyOperator |
( |
const std::shared_ptr< MathNode > & |
node, |
|
|
const std::shared_ptr< Operator > & |
op, |
|
|
const double & |
val, |
|
|
bool |
isLeft |
|
) |
| const |
|
inlineprivate |
Applies numeric operation op like if isLeft: node (op) val else: val (op) node
- Parameters
-
node | target to apply op on |
op | operator to apply |
val | numerical value to apply |
isLeft | signalize node is left side of OP |
- Returns
- evaluated operator node
◆ Chain()
Connects left and right using op, this essentially takes both sides baseNode and connects both trees, then returns a new equation object. Dude! It even generates a unique set of symbols!
- Parameters
-
left | left equation |
right | right equation |
op | operator to connect with |
- Returns
- chained equation object
- Examples
- symb/TestSymbolic.cpp.
◆ GetDegree()
int Equation::GetDegree |
( |
const std::shared_ptr< MathNode > & |
node | ) |
|
|
inline |
◆ GetDepth()
size_t Equation::GetDepth |
( |
const std::shared_ptr< MathNode > & |
node, |
|
|
size_t & |
current_depth |
|
) |
| const |
|
inline |
Getter for max AST depth
- Parameters
-
node | to check depth of |
current_depth | counter for current depth level |
- Returns
- current depth if last node in branch, else max of left depth and right depth
◆ GetString()
std::string Equation::GetString |
( |
| ) |
const |
|
inline |
◆ operator()() [1/2]
double Equation::operator() |
( |
| ) |
|
|
inline |
Evaluate equation with preset values
- Returns
◆ operator()() [2/2]
template<typename... VArgs>
double Equation::operator() |
( |
VArgs... |
args | ) |
|
|
inline |
var arg method to evaluate equation using variable amount of symbols, yet if called with parameters, all parameters need to be present.
Needs to be called with number symbols as number parameters
- Template Parameters
-
VArgs | variable amount of arguments |
- Parameters
-
args | arguments passed for symbols, with index representing index of symbol in symbols |
- Returns
- Evaluation of equation
◆ Print()
void Equation::Print |
( |
std::ostream & |
ostr = std::cout | ) |
|
|
inline |
◆ PrintNode()
void Equation::PrintNode |
( |
const std::shared_ptr< MathNode > & |
node, |
|
|
std::vector< std::vector< std::string > > & |
levels, |
|
|
const size_t & |
row, |
|
|
const size_t & |
column |
|
) |
| const |
|
inline |
Generates left aligned string representation of node in tree leave form according to their connection types
- Parameters
-
◆ PrintTree() [1/2]
void Equation::PrintTree |
( |
| ) |
const |
|
inline |
Helper method to display ASTree.
Add padding to levels, count empty elements on right side, then append them on the left side
◆ PrintTree() [2/2]
void Equation::PrintTree |
( |
const std::shared_ptr< MathNode > & |
node, |
|
|
int & |
level, |
|
|
std::vector< std::string > & |
tree |
|
) |
| const |
|
inline |
Add representation string into tree of passed node
- Parameters
-
node | the current node to process |
level | current depth level |
tree | tree representation as array of lines, each line represents a depth level |
◆ resolveOP()
void Equation::resolveOP |
( |
std::shared_ptr< MathNode > & |
out, |
|
|
const std::shared_ptr< Operator > & |
op |
|
) |
| const |
|
inlineprivate |
resolves operator scope as far as possible
- Parameters
-
out | output node |
op | operator scope to resolve |
◆ SetSymbols() [1/3]
void Equation::SetSymbols |
( |
const int & |
index | ) |
|
|
inline |
empty method to stop va arg recursion
- Parameters
-
◆ SetSymbols() [2/3]
template<typename... VArgs>
void Equation::SetSymbols |
( |
const int & |
index, |
|
|
double |
val, |
|
|
VArgs... |
args |
|
) |
| |
|
inline |
var arg method to recursively set current values of symbols
- Template Parameters
-
VArgs | variable amount of arguments |
- Parameters
-
index | current index of symbol |
val | value for symbol with index index |
args | following arguments |
◆ SetSymbols() [3/3]
void Equation::SetSymbols |
( |
const std::vector< double > & |
values | ) |
|
|
inline |
Helper shortcut to check for existence of symbolic within equation setter for evaluation values for symbolic nodes using a vector of values
- Parameters
-
values | vector containing values for symbols |
◆ Simplify()
void Equation::Simplify |
( |
| ) |
|
|
inline |
◆ simplifyOP()
std::shared_ptr< MathNode > Equation::simplifyOP |
( |
const std::shared_ptr< MathNode > & |
node | ) |
const |
|
inlineprivate |
Simplifies operator scope
Within a scope the following rules are applied:
- Functions: Functions with numeric values as left hand nodes can be simplified to numeric nodes
- Operators: Numeric values can be combined.
- Parameters
-
node | operator node (-tree) to simplify |
- Returns
- simplified tree with [num_nodes_in >= num_nodes_out]
◆ SimplifyTree()
std::shared_ptr< MathNode > Equation::SimplifyTree |
( |
const std::shared_ptr< MathNode > & |
node | ) |
const |
|
inlineprivate |
Simplify equation tree given by node
- Parameters
-
- Returns
- simplified tree
◆ baseNode
std::shared_ptr<MathNode> Equation::baseNode = nullptr |
◆ degree
◆ symbols
std::vector<std::shared_ptr<Symbolic> > Equation::symbols |
storage for containing symbols
The documentation for this class was generated from the following file: