Cadabra
Computer algebra system for field theory problems
Public Member Functions | Public Attributes | List of all members
ExNode Class Reference

Description

ExNode is a combination of an Ex::iterator and an interface which we can use to manipulate the data pointed to by this iterator.

In this way, we can use

for it in ex: ...

loops and still use 'it' to do things like insertion etc. which requires knowing the Ex::iterator.

Iterators are much safer than in C++, because they carry the tree modification interface themselves, and can thus compute their next value for any destructive operation.

Note that ExNode does not really behave like a Python iterator in the strict sense: it does not return copies of nodes in the tree, but rather objects which know how to modify the tree.

#include <ExNode.hh>

Inheritance diagram for ExNode:
cadabra::IndexClassifier

Public Member Functions

 ExNode (const cadabra::Kernel &, std::shared_ptr< cadabra::Ex >)
 
ExNodeiter ()
 
ExNodenext ()
 
ExNode copy () const
 
std::string __str__ () const
 
std::string _latex_ () const
 
std::string input_form () const
 
std::string get_name () const
 
void set_name (std::string)
 
cadabra::Ex get_ex () const
 Create a copy of the Ex pointed to by this iterator. More...
 
cadabra::str_node::parent_rel_t get_parent_rel () const
 
void set_parent_rel (cadabra::str_node::parent_rel_t)
 
pybind11::object get_multiplier () const
 
void set_multiplier (pybind11::object)
 
void replace (std::shared_ptr< cadabra::Ex > rep)
 Take a child argument out of the node and add as child of current. More...
 
ExNode insert (std::shared_ptr< cadabra::Ex > ins)
 Insert a subtree as previous sibling of the current node. More...
 
ExNode insert_it (ExNode ins)
 
ExNode append_child (std::shared_ptr< cadabra::Ex >)
 Append a subtree as a child. Return an ExNode pointing to the new child. More...
 
ExNode append_child_it (ExNode ins)
 
ExNode add_ex (std::shared_ptr< cadabra::Ex >)
 Add an expression to the given node, adding a sum parent if necessary. More...
 
void erase ()
 Erase the current node, iterator becomes invalid! More...
 
ExNode getitem_string (std::string tag)
 Get a new iterator which always stays below the current one. More...
 
ExNode getitem_iterator (ExNode)
 
void setitem_string (std::string tag, std::shared_ptr< cadabra::Ex > val)
 Set all elements with the indicated tag to the given value. More...
 
void setitem_iterator (ExNode, std::shared_ptr< cadabra::Ex > val)
 
ExNode terms ()
 Get a new iterator which only iterates over all first-level terms. More...
 
ExNode factors ()
 Get a new iterator which only iterates over all first-level factors. More...
 
ExNode own_indices ()
 Get a new iterator which only iterates over all first-level indices (that is, does not iterate over inherited indices; use 'indices' for that). More...
 
ExNode indices ()
 Get a new iterator which only iterates over all indices (whether direct or inherited). More...
 
ExNode free_indices ()
 Get a new iterator which only iterates over all free indices (whether direct or inherited). More...
 
ExNode args ()
 Get a new iterator which only iterates over all first-level arguments (non-indices). More...
 
ExNode children ()
 Get a new iterator which iterates over all first-level children (a sibling iterator, in other words). More...
 
void update (bool first)
 Internal function to update the iterator to the next value. More...
 
- Public Member Functions inherited from cadabra::IndexClassifier
 IndexClassifier (const Kernel &)
 
void fill_index_position_map (Ex::iterator, const index_map_t &, index_position_map_t &) const
 Routines to find and classify all indices in an expression, taking into account sums and products. More...
 
void fill_map (index_map_t &, Ex::sibling_iterator, Ex::sibling_iterator) const
 
void print_classify_indices (std::ostream &, Ex::iterator) const
 
void determine_intersection (index_map_t &one, index_map_t &two, index_map_t &target, bool move_out=false) const
 Determine those indices in 'two' which have a name which is identical to an index name occurring in 'one'. More...
 
void classify_add_index (Ex::iterator it, index_map_t &ind_free, index_map_t &ind_dummy) const
 
void classify_indices_up (Ex::iterator, index_map_t &ind_free, index_map_t &ind_dummy) const
 Classify indices bottom-up, that is, given a node, it goes up the tree to find. More...
 
void classify_indices (Ex::iterator, index_map_t &ind_free, index_map_t &ind_dummy) const
 Classify indices top-down, that is, finds the free indices and all dummy index pairs used in the full subtree below a given node. More...
 
int max_numbered_name_one (const std::string &nm, const index_map_t *one) const
 
int max_numbered_name (const std::string &, const index_map_t *m1, const index_map_t *m2=0, const index_map_t *m3=0, const index_map_t *m4=0, const index_map_t *m5=0) const
 
Ex get_dummy (const list_property *, const index_map_t *m1, const index_map_t *m2=0, const index_map_t *m3=0, const index_map_t *m4=0, const index_map_t *m5=0) const
 
Ex get_dummy (const list_property *, Ex::iterator) const
 
Ex get_dummy (const list_property *, Ex::iterator, Ex::iterator) const
 
bool index_in_set (Ex, const index_map_t *) const
 
void dumpmap (std::ostream &, const index_map_t &) const
 
index_map_t::iterator find_modulo_parent_rel (Ex::iterator it, index_map_t &imap) const
 Find an index in the set, not taking into account index position. More...
 

Public Attributes

std::shared_ptr< cadabra::Exex
 
cadabra::Ex::iterator it
 
std::string tag
 
bool indices_only
 
bool args_only
 
bool terms_only
 
bool factors_only
 
cadabra::Ex::iterator nxtit
 
cadabra::Ex::sibling_iterator sibnxtit
 
cadabra::index_iterator indnxtit
 
bool use_sibling_iterator
 
bool use_index_iterator
 
cadabra::Ex::iterator topit
 
cadabra::Ex::iterator stopit
 
index_map_t ind_free
 
index_map_t ind_dummy
 
index_position_map_t ind_pos_dummy
 

Additional Inherited Members

- Public Types inherited from cadabra::IndexClassifier
typedef std::multimap< Ex, Ex::iterator, tree_exact_less_for_indexmap_objindex_map_t
 A map from a pattern to the position where it occurs in the tree. More...
 
typedef std::map< Ex::iterator, int, Ex::iterator_base_less > index_position_map_t
 A map from the position of each index to the sequential index. More...
 
- Protected Attributes inherited from cadabra::IndexClassifier
const Kernelkernel
 

Constructor & Destructor Documentation

◆ ExNode()

ExNode::ExNode ( const cadabra::Kernel k,
std::shared_ptr< cadabra::Ex ex_ 
)

Member Function Documentation

◆ __str__()

std::string ExNode::__str__ ( ) const

◆ _latex_()

std::string ExNode::_latex_ ( ) const

◆ add_ex()

ExNode ExNode::add_ex ( std::shared_ptr< cadabra::Ex )

Add an expression to the given node, adding a sum parent if necessary.

◆ append_child()

ExNode ExNode::append_child ( std::shared_ptr< cadabra::Ex rep)

Append a subtree as a child. Return an ExNode pointing to the new child.

◆ append_child_it()

ExNode ExNode::append_child_it ( ExNode  ins)

◆ args()

ExNode ExNode::args ( )

Get a new iterator which only iterates over all first-level arguments (non-indices).

◆ children()

ExNode ExNode::children ( )

Get a new iterator which iterates over all first-level children (a sibling iterator, in other words).

◆ copy()

ExNode ExNode::copy ( ) const

◆ erase()

void ExNode::erase ( )

Erase the current node, iterator becomes invalid!

◆ factors()

ExNode ExNode::factors ( )

Get a new iterator which only iterates over all first-level factors.

If the first-level is not a product, the iterator will only return the single node and then end.

◆ free_indices()

ExNode ExNode::free_indices ( )

Get a new iterator which only iterates over all free indices (whether direct or inherited).

Uses an index_iterator internally (see its documentation for details on behaviour).

◆ get_ex()

cadabra::Ex ExNode::get_ex ( ) const

Create a copy of the Ex pointed to by this iterator.

◆ get_multiplier()

pybind11::object ExNode::get_multiplier ( ) const

◆ get_name()

std::string ExNode::get_name ( ) const

◆ get_parent_rel()

str_node::parent_rel_t ExNode::get_parent_rel ( ) const

◆ getitem_iterator()

ExNode ExNode::getitem_iterator ( ExNode  it)

◆ getitem_string()

ExNode ExNode::getitem_string ( std::string  tag)

Get a new iterator which always stays below the current one.

◆ indices()

ExNode ExNode::indices ( )

Get a new iterator which only iterates over all indices (whether direct or inherited).

Uses an index_iterator internally (see its documentation for details on behaviour).

◆ input_form()

std::string ExNode::input_form ( ) const

◆ insert()

ExNode ExNode::insert ( std::shared_ptr< cadabra::Ex ins)

Insert a subtree as previous sibling of the current node.

◆ insert_it()

ExNode ExNode::insert_it ( ExNode  ins)

◆ iter()

ExNode & ExNode::iter ( )

◆ next()

ExNode & ExNode::next ( )

◆ own_indices()

ExNode ExNode::own_indices ( )

Get a new iterator which only iterates over all first-level indices (that is, does not iterate over inherited indices; use 'indices' for that).

◆ replace()

void ExNode::replace ( std::shared_ptr< cadabra::Ex rep)

Take a child argument out of the node and add as child of current.

Replace the subtree at the current node with the given expression. Updates the iterator so that it points to the replacement subtree.

◆ set_multiplier()

void ExNode::set_multiplier ( pybind11::object  mult)

◆ set_name()

void ExNode::set_name ( std::string  nm)

◆ set_parent_rel()

void ExNode::set_parent_rel ( cadabra::str_node::parent_rel_t  pr)

◆ setitem_iterator()

void ExNode::setitem_iterator ( ExNode  en,
std::shared_ptr< cadabra::Ex val 
)

◆ setitem_string()

void ExNode::setitem_string ( std::string  tag,
std::shared_ptr< cadabra::Ex val 
)

Set all elements with the indicated tag to the given value.

◆ terms()

ExNode ExNode::terms ( )

Get a new iterator which only iterates over all first-level terms.

If the first-level is not a sum, the iterator will only return the single node and then end.

◆ update()

void ExNode::update ( bool  first)

Internal function to update the iterator to the next value.

Switches behaviour depending on use_sibling_iterator, use_index_iterator, indices_only, args_only, terms_only, factors_only;

Member Data Documentation

◆ args_only

bool ExNode::args_only

◆ ex

std::shared_ptr<cadabra::Ex> ExNode::ex

◆ factors_only

bool ExNode::factors_only

◆ ind_dummy

index_map_t ExNode::ind_dummy

◆ ind_free

index_map_t ExNode::ind_free

◆ ind_pos_dummy

index_position_map_t ExNode::ind_pos_dummy

◆ indices_only

bool ExNode::indices_only

◆ indnxtit

cadabra::index_iterator ExNode::indnxtit

◆ it

cadabra::Ex::iterator ExNode::it

◆ nxtit

cadabra::Ex::iterator ExNode::nxtit

◆ sibnxtit

cadabra::Ex::sibling_iterator ExNode::sibnxtit

◆ stopit

cadabra::Ex::iterator ExNode::stopit

◆ tag

std::string ExNode::tag

◆ terms_only

bool ExNode::terms_only

◆ topit

cadabra::Ex::iterator ExNode::topit

◆ use_index_iterator

bool ExNode::use_index_iterator

◆ use_sibling_iterator

bool ExNode::use_sibling_iterator

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