Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
PLMD::lepton::ParsedExpression Class Reference

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 ExpressionTreeNodegetRootNode () 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ParsedExpression() [1/2]

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.

◆ ParsedExpression() [2/2]

PLMD::ParsedExpression::ParsedExpression ( const ExpressionTreeNode rootNode)

Create a ParsedExpression.

Normally you will not call this directly. Instead, use the Parser class to parse expression.

Member Function Documentation

◆ createCompiledExpression()

CompiledExpression PLMD::ParsedExpression::createCompiledExpression ( ) const

Create a CompiledExpression that represents the same calculation as this expression.

◆ createProgram()

ExpressionProgram PLMD::ParsedExpression::createProgram ( ) const

Create an ExpressionProgram that represents the same calculation as this expression.

◆ differentiate() [1/2]

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.

Parameters
variablethe variable with respect to which the derivate should be taken

◆ differentiate() [2/2]

ExpressionTreeNode PLMD::ParsedExpression::differentiate ( const ExpressionTreeNode node,
const std::string &  variable 
)
staticprivate

◆ evaluate() [1/3]

double PLMD::ParsedExpression::evaluate ( ) const

Evaluate the expression.

If the expression involves any variables, this method will throw an exception.

◆ evaluate() [2/3]

double PLMD::ParsedExpression::evaluate ( const std::map< std::string, double > &  variables) const

Evaluate the expression.

Parameters
variablesa 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.

◆ evaluate() [3/3]

double PLMD::ParsedExpression::evaluate ( const ExpressionTreeNode node,
const std::map< std::string, double > &  variables 
)
staticprivate

◆ getConstantValue()

double PLMD::ParsedExpression::getConstantValue ( const ExpressionTreeNode node)
staticprivate

◆ getRootNode()

const ExpressionTreeNode & PLMD::ParsedExpression::getRootNode ( ) const

Get the root node of the expression's abstract syntax tree.

◆ optimize() [1/2]

ParsedExpression PLMD::ParsedExpression::optimize ( ) const

Create a new ParsedExpression which produces the same result as this one, but is faster to evaluate.

◆ optimize() [2/2]

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.

Parameters
variablesa 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.

◆ precalculateConstantSubexpressions()

ExpressionTreeNode PLMD::ParsedExpression::precalculateConstantSubexpressions ( const ExpressionTreeNode node)
staticprivate

◆ preevaluateVariables()

ExpressionTreeNode PLMD::ParsedExpression::preevaluateVariables ( const ExpressionTreeNode node,
const std::map< std::string, double > &  variables 
)
staticprivate

◆ renameNodeVariables()

ExpressionTreeNode PLMD::ParsedExpression::renameNodeVariables ( const ExpressionTreeNode node,
const std::map< std::string, std::string > &  replacements 
)
staticprivate

◆ renameVariables()

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.

Parameters
replacementsa map whose keys are the names of variables, and whose values are the new names to replace them with

◆ substituteSimplerExpression()

ExpressionTreeNode PLMD::ParsedExpression::substituteSimplerExpression ( const ExpressionTreeNode node)
staticprivate

Member Data Documentation

◆ rootNode

ExpressionTreeNode PLMD::lepton::ParsedExpression::rootNode
private

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