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... | |
const ExpressionTreeNode & | getRootNode () const |
Get the root node of the expression's abstract syntax tree. More... | |
double | evaluate () const |
Evaluate the expression. More... | |
double | evaluate (const std::map< std::string, double > &variables) const |
Evaluate the expression. 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 | 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... | |
ExpressionProgram | createProgram () const |
Create an ExpressionProgram that represents the same calculation as this expression. More... | |
CompiledExpression | createCompiledExpression () const |
Create a CompiledExpression that represents the same calculation as this expression. 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 double | evaluate (const ExpressionTreeNode &node, const std::map< std::string, double > &variables) |
static ExpressionTreeNode | preevaluateVariables (const ExpressionTreeNode &node, const std::map< std::string, double > &variables) |
static ExpressionTreeNode | precalculateConstantSubexpressions (const ExpressionTreeNode &node) |
static ExpressionTreeNode | substituteSimplerExpression (const ExpressionTreeNode &node) |
static ExpressionTreeNode | differentiate (const ExpressionTreeNode &node, const std::string &variable) |
static double | getConstantValue (const ExpressionTreeNode &node) |
static ExpressionTreeNode | renameNodeVariables (const ExpressionTreeNode &node, const std::map< std::string, std::string > &replacements) |
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.
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 |
|
staticprivate |
double PLMD::ParsedExpression::evaluate | ( | ) | const |
Evaluate the expression.
If the expression involves any variables, this method will throw an exception.
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 |
|
staticprivate |
const ExpressionTreeNode & PLMD::ParsedExpression::getRootNode | ( | ) | const |
Get the root node of the expression's abstract syntax tree.
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.14 |