Cadabra
Computer algebra system for field theory problems
|
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>
Public Member Functions | |
ExNode (const cadabra::Kernel &, std::shared_ptr< cadabra::Ex >) | |
ExNode & | iter () |
ExNode & | next () |
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. | |
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. | |
ExNode | insert (std::shared_ptr< cadabra::Ex > ins) |
Insert a subtree as previous sibling of the current node. | |
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. | |
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. | |
void | erase () |
Erase the current node, iterator becomes invalid! | |
ExNode | getitem_string (std::string tag) |
Get a new iterator which always stays below the current one. | |
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. | |
void | setitem_iterator (ExNode, std::shared_ptr< cadabra::Ex > val) |
ExNode | terms () |
Get a new iterator which only iterates over all first-level terms. | |
ExNode | factors () |
Get a new iterator which only iterates over all first-level factors. | |
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). | |
ExNode | indices () |
Get a new iterator which only iterates over all indices (whether direct or inherited). | |
ExNode | free_indices () |
Get a new iterator which only iterates over all free indices (whether direct or inherited). | |
ExNode | args () |
Get a new iterator which only iterates over all first-level arguments (non-indices). | |
ExNode | children () |
Get a new iterator which iterates over all first-level children (a sibling iterator, in other words). | |
void | update (bool first) |
Internal function to update the iterator to the next value. | |
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. | |
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'. | |
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. | |
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. | |
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. | |
Public Attributes | |
std::shared_ptr< cadabra::Ex > | ex |
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_obj > | index_map_t |
A map from a pattern to the position where it occurs in the tree. | |
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. | |
Protected Attributes inherited from cadabra::IndexClassifier | |
const Kernel & | kernel |
ExNode::ExNode | ( | const cadabra::Kernel & | k, |
std::shared_ptr< cadabra::Ex > | ex_ | ||
) |
std::string ExNode::__str__ | ( | ) | const |
std::string ExNode::_latex_ | ( | ) | const |
ExNode ExNode::add_ex | ( | std::shared_ptr< cadabra::Ex > | ) |
Add an expression to the given node, adding a sum parent if necessary.
ExNode ExNode::append_child | ( | std::shared_ptr< cadabra::Ex > | rep | ) |
Append a subtree as a child. Return an ExNode pointing to the new child.
ExNode ExNode::args | ( | ) |
Get a new iterator which only iterates over all first-level arguments (non-indices).
ExNode ExNode::children | ( | ) |
Get a new iterator which iterates over all first-level children (a sibling iterator, in other words).
ExNode ExNode::copy | ( | ) | const |
void ExNode::erase | ( | ) |
Erase the current node, iterator becomes invalid!
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.
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).
cadabra::Ex ExNode::get_ex | ( | ) | const |
Create a copy of the Ex pointed to by this iterator.
pybind11::object ExNode::get_multiplier | ( | ) | const |
std::string ExNode::get_name | ( | ) | const |
str_node::parent_rel_t ExNode::get_parent_rel | ( | ) | const |
ExNode ExNode::getitem_string | ( | std::string | tag | ) |
Get a new iterator which always stays below the current one.
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).
std::string ExNode::input_form | ( | ) | const |
ExNode ExNode::insert | ( | std::shared_ptr< cadabra::Ex > | ins | ) |
Insert a subtree as previous sibling of the current node.
ExNode & ExNode::iter | ( | ) |
ExNode & ExNode::next | ( | ) |
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).
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.
void ExNode::set_multiplier | ( | pybind11::object | mult | ) |
void ExNode::set_name | ( | std::string | nm | ) |
void ExNode::set_parent_rel | ( | cadabra::str_node::parent_rel_t | pr | ) |
void ExNode::setitem_iterator | ( | ExNode | en, |
std::shared_ptr< cadabra::Ex > | val | ||
) |
void ExNode::setitem_string | ( | std::string | tag, |
std::shared_ptr< cadabra::Ex > | val | ||
) |
Set all elements with the indicated tag to the given value.
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.
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;
bool ExNode::args_only |
std::shared_ptr<cadabra::Ex> ExNode::ex |
bool ExNode::factors_only |
index_map_t ExNode::ind_dummy |
index_map_t ExNode::ind_free |
index_position_map_t ExNode::ind_pos_dummy |
bool ExNode::indices_only |
cadabra::index_iterator ExNode::indnxtit |
cadabra::Ex::iterator ExNode::it |
cadabra::Ex::iterator ExNode::nxtit |
cadabra::Ex::sibling_iterator ExNode::sibnxtit |
cadabra::Ex::iterator ExNode::stopit |
std::string ExNode::tag |
bool ExNode::terms_only |
cadabra::Ex::iterator ExNode::topit |
bool ExNode::use_index_iterator |
bool ExNode::use_sibling_iterator |