This class represents the result of parsing an expression. More...
#include <ParsedExpression.h>
Public Member Functions | |
ParsedExpression () | |
Create an uninitialized ParsedExpression. More... | |
ParsedExpression (const ExpressionTreeNode &rootNode) | |
Create a ParsedExpression. More... | |
CompiledExpression | createCompiledExpression () const |
Create a CompiledExpression that represents the same calculation as this expression. More... | |
ExpressionProgram | createProgram () const |
Create an ExpressionProgram that represents the same calculation as this expression. More... | |
ParsedExpression | differentiate (const std::string &variable) const |
Create a new ParsedExpression which is the analytic derivative of this expression with respect to a particular variable. More... | |
double | evaluate () const |
Evaluate the expression. More... | |
double | evaluate (const std::map< std::string, double > &variables) const |
Evaluate the expression. More... | |
const ExpressionTreeNode & | getRootNode () const |
Get the root node of the expression's abstract syntax tree. More... | |
ParsedExpression | optimize () const |
Create a new ParsedExpression which produces the same result as this one, but is faster to evaluate. More... | |
ParsedExpression | optimize (const std::map< std::string, double > &variables) const |
Create a new ParsedExpression which produces the same result as this one, but is faster to evaluate. More... | |
ParsedExpression | renameVariables (const std::map< std::string, std::string > &replacements) const |
Create a new ParsedExpression which is identical to this one, except that the names of some variables have been changed. More... | |
Static Private Member Functions | |
static ExpressionTreeNode | differentiate (const ExpressionTreeNode &node, const std::string &variable, std::map< int, ExpressionTreeNode > &nodeCache) |
static double | evaluate (const ExpressionTreeNode &node, const std::map< std::string, double > &variables) |
static double | getConstantValue (const ExpressionTreeNode &node) |
static bool | isConstant (const ExpressionTreeNode &node) |
static ExpressionTreeNode | precalculateConstantSubexpressions (const ExpressionTreeNode &node, std::map< int, ExpressionTreeNode > &nodeCache) |
static ExpressionTreeNode | preevaluateVariables (const ExpressionTreeNode &node, const std::map< std::string, double > &variables) |
static ExpressionTreeNode | renameNodeVariables (const ExpressionTreeNode &node, const std::map< std::string, std::string > &replacements) |
static ExpressionTreeNode | substituteSimplerExpression (const ExpressionTreeNode &node, std::map< int, ExpressionTreeNode > &nodeCache) |
Private Attributes | |
ExpressionTreeNode | rootNode |
This class represents the result of parsing an expression.
It provides methods for working with the expression in various ways, such as evaluating it, getting the tree representation of the expresson, etc.
PLMD::ParsedExpression::ParsedExpression | ( | ) |
Create an uninitialized ParsedExpression.
This exists so that ParsedExpressions can be put in STL containers. Doing anything with it will produce an exception.
PLMD::ParsedExpression::ParsedExpression | ( | const ExpressionTreeNode & | rootNode | ) |
Create a ParsedExpression.
Normally you will not call this directly. Instead, use the Parser class to parse expression.
CompiledExpression PLMD::ParsedExpression::createCompiledExpression | ( | ) | const |
Create a CompiledExpression that represents the same calculation as this expression.
ExpressionProgram PLMD::ParsedExpression::createProgram | ( | ) | const |
Create an ExpressionProgram that represents the same calculation as this expression.
|
staticprivate |
ParsedExpression PLMD::ParsedExpression::differentiate | ( | const std::string & | variable | ) | const |
Create a new ParsedExpression which is the analytic derivative of this expression with respect to a particular variable.
variable | the variable with respect to which the derivate should be taken |
double PLMD::ParsedExpression::evaluate | ( | ) | const |
Evaluate the expression.
If the expression involves any variables, this method will throw an exception.
|
staticprivate |
double PLMD::ParsedExpression::evaluate | ( | const std::map< std::string, double > & | variables | ) | const |
Evaluate the expression.
variables | a map specifying the values of all variables that appear in the expression. If any variable appears in the expression but is not included in this map, an exception will be thrown. |
|
staticprivate |
const ExpressionTreeNode & PLMD::ParsedExpression::getRootNode | ( | ) | const |
Get the root node of the expression's abstract syntax tree.
|
staticprivate |
ParsedExpression PLMD::ParsedExpression::optimize | ( | ) | const |
Create a new ParsedExpression which produces the same result as this one, but is faster to evaluate.
ParsedExpression PLMD::ParsedExpression::optimize | ( | const std::map< std::string, double > & | variables | ) | const |
Create a new ParsedExpression which produces the same result as this one, but is faster to evaluate.
variables | a map specifying values for a subset of variables that appear in the expression. All occurrences of these variables in the expression are replaced with the values specified. |
|
staticprivate |
|
staticprivate |
|
staticprivate |
ParsedExpression PLMD::ParsedExpression::renameVariables | ( | const std::map< std::string, std::string > & | replacements | ) | const |
Create a new ParsedExpression which is identical to this one, except that the names of some variables have been changed.
replacements | a map whose keys are the names of variables, and whose values are the new names to replace them with |
|
staticprivate |
|
private |
Hosted by GitHub | 1.8.17 |