Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
cadabra::NEvaluator Class Reference

Description

Functionality to numerically evaluate a scalar expression, give the values of its building blocks.

The input is a map which relates subtrees in the expression to numerical values. The evaluate function will then do a post-order iteration over the tree, collecting and combining the values thus obtained.

Currently needs the leaf nodes to have an entry in the subtree_values map; may be extended later to cover values of non-elementary subtrees.

If there are 'n' variables, then at any stage the tree will be an n-tensor, with the dimension of each index set by the length of the value array for the corresponding variable.

#include <NEvaluator.hh>

Classes

class  VariableValues
 The expression will get evaluated for a range of values for each unknown sub-expression (variable). More...
 

Public Types

typedef std::function< std::complex< double >(const Ex &)> lookup_function_t
 Set an external function which will be used by evaluate to lookup values of objects as a last resort, if they do not resolve using the variable_values list above.
 

Public Member Functions

 NEvaluator ()
 
 NEvaluator (Ex::iterator)
 
void set_function (Ex::iterator)
 Set function to evaluate. Can also be passed in the constructor.
 
void set_variable (const Ex &, const NTensor &val)
 Set the range of values which we want to insert into the indicated variable.
 
void set_lookup_function (lookup_function_t)
 
NTensor evaluate ()
 Evaluate the expression, using the variable values set in set_variable.
 
void find_variable_locations ()
 PRIVATE:
 

Public Attributes

std::map< Ex::iterator, NTensor, Ex::iterator_base_less > subtree_values
 If we know the value of a subtree explicitly as a number, it is stored in this map.
 
std::map< Ex::iterator, Ex::iterator, Ex::iterator_base_less > subtree_equalities
 If we know the value of a subtree is equal to another subtree (either in the same expression or another one), it is stored in the map below.
 
std::vector< VariableValuesvariable_values
 
std::map< Ex, size_t, tree_exact_less_no_wildcards_objvariable_values_locs
 

Private Attributes

Ex ex
 
lookup_function_t lookup_function
 
std::vector< size_tfullshape
 

Member Typedef Documentation

◆ lookup_function_t

Set an external function which will be used by evaluate to lookup values of objects as a last resort, if they do not resolve using the variable_values list above.

Constructor & Destructor Documentation

◆ NEvaluator() [1/2]

NEvaluator::NEvaluator ( )

◆ NEvaluator() [2/2]

NEvaluator::NEvaluator ( Ex::iterator  ex_it)

Member Function Documentation

◆ evaluate()

NTensor NEvaluator::evaluate ( )

Evaluate the expression, using the variable values set in set_variable.

This will only work if the expression evaluates to a complex double.

◆ find_variable_locations()

void NEvaluator::find_variable_locations ( )

PRIVATE:

◆ set_function()

void NEvaluator::set_function ( Ex::iterator  ex_it)

Set function to evaluate. Can also be passed in the constructor.

◆ set_lookup_function()

void NEvaluator::set_lookup_function ( lookup_function_t  f)

◆ set_variable()

void NEvaluator::set_variable ( const Ex var,
const NTensor val 
)

Set the range of values which we want to insert into the indicated variable.

Fills the map above.

Member Data Documentation

◆ ex

Ex cadabra::NEvaluator::ex
private

◆ fullshape

std::vector<size_t> cadabra::NEvaluator::fullshape
private

◆ lookup_function

lookup_function_t cadabra::NEvaluator::lookup_function
private

◆ subtree_equalities

std::map<Ex::iterator, Ex::iterator, Ex::iterator_base_less> cadabra::NEvaluator::subtree_equalities

If we know the value of a subtree is equal to another subtree (either in the same expression or another one), it is stored in the map below.

This then still needs a lookup in the subtree_values map. FIXME: not used right now. The idea was that if we find two subtrees which are equal symbolically, we only have to evaluate one, and can then read off the value of the other one by referring to the first.

◆ subtree_values

std::map<Ex::iterator, NTensor, Ex::iterator_base_less> cadabra::NEvaluator::subtree_values

If we know the value of a subtree explicitly as a number, it is stored in this map.

These are computed nodes. Note that keys are compared as pointers, so two identical expressions at two different locations in the tree will have two entries in this map.

◆ variable_values

std::vector<VariableValues> cadabra::NEvaluator::variable_values

◆ variable_values_locs

std::map<Ex, size_t, tree_exact_less_no_wildcards_obj> cadabra::NEvaluator::variable_values_locs

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