![]() |
Cadabra
Computer algebra system for field theory problems
|
#include <Storage.hh>
Public Types | |
| enum | result_t { l_checkpointed , l_no_action , l_applied , l_applied_no_new_dummies , l_error , l_cached } |
| Keeping track of what algorithms have done to this expression. More... | |
Public Member Functions | |
| Ex () | |
| Ex (cdb_tree::iterator) | |
| Create a new Ex with a copy of the subtree at the given iterator. | |
| Ex (const str_node &) | |
| Create new Ex with single head node being a copy of the given node. | |
| Ex (const Ex &) | |
| Copy constructor: create a full copy of the given other Ex. | |
| Ex (const std::string &) | |
| Copy constructor: create a full copy of the given other Ex. | |
| Ex (int) | |
| Create a single-node Ex representing the given integer. | |
| Ex (double) | |
| Create a single-node Ex representing the given float. | |
| Ex (int, int) | |
| Create a single-node Ex representing the given rational. | |
| Ex & | operator= (Ex) |
| result_t | state () const |
| void | update_state (result_t) |
| void | reset_state () |
| bool | changed_state () |
| A status query method mainly to implement a simple method to apply algorithms until they converge. | |
| bool | is_rational () const |
| Test if the expression is a rational number. | |
| multiplier_t | to_rational () const |
| bool | is_integer () const |
| long | to_integer () const |
| bool | is_string () const |
| bool | equals (const std::string &) const |
| Comparison operators with primitive types. | |
| bool | is_empty () const |
| Test if the expression is empty (no content at all). | |
| std::ostream & | print_entire_tree (std::ostream &str) const |
| Output helpers mainly for debugging purposes. | |
| std::ostream & | print_repr (std::ostream &str, Ex::iterator it) const |
| Print a representation like Python's 'repr'. | |
| iterator | named_parent (iterator it, const std::string &) const |
| Step up until matching node is found (if current node matches, do nothing) | |
| iterator | erase_expression (iterator it) |
| hashval_t | calc_hash (iterator it) const |
| Calculate the hash value for the subtree starting at 'it'. | |
| multiplier_t | arg_to_num (sibling_iterator, unsigned int) const |
| unsigned int | number_of_steps (iterator it) const |
| bool | is_hidden (iterator) const |
| iterator | replace_index (iterator position, const iterator &from, bool keep_parent_rel=false) |
| Replace the index-like object (originally intended to replace indices only, but now used also for e.g. | |
| iterator | move_index (iterator position, const iterator &from) |
| As in replace_index, but moves the index rather than making a copy (so that iterators pointing to the original remain valid). | |
| void | list_wrap_single_element (iterator &) |
| Make sure that the node pointed to is a \comma object, i.e. | |
| void | list_unwrap_single_element (iterator &) |
| iterator | flatten_and_erase (iterator position) |
| Replace the node with the children of the node, useful for e.g. | |
| bool | operator== (const Ex &other) const |
| Compare two Ex objects for exact equality; no dummy equivalence or other things that require property information. | |
| void | push_history (const std::vector< Ex::path_t > &) |
| Push a copy of the current Storstate of the expression onto the history stack. | |
| std::vector< Ex::path_t > | pop_history () |
| Pop the most recent state of the expression off the history stack; returns the set of paths that we are replacing. | |
| int | history_size () const |
| Return the size of the history; 0 means no history, just the current expression. | |
Static Public Member Functions | |
| static std::ostream & | print_python (std::ostream &str, Ex::iterator it) |
| Display expression in Python/Cadabra input form. | |
| static std::ostream & | print_recursive_treeform (std::ostream &str, Ex::iterator it) |
| static std::ostream & | print_recursive_treeform (std::ostream &str, Ex::iterator it, unsigned int &number) |
| static sibling_iterator | arg (iterator, unsigned int) |
| Quick access to arguments or argument lists for A(B)(C,D) type nodes. | |
| static unsigned int | arg_size (sibling_iterator) |
Private Attributes | |
| result_t | state_ |
| std::vector< cdb_tree > | history |
| std::vector< std::vector< Ex::path_t > > | terms |
| Patterns which describe how to get from one history step to the next. | |
Keeping track of what algorithms have done to this expression.
After a reset_state (or at initialisation), the expression sits in the 'checkpointed' state. When an algorithm acts, it can then move to 'no_action' (unchanged), 'applied' (changed) or 'error'. Once it is in 'error', it will stay there until the next 'reset'. FIXME: the following should implement a stack of states, so that it can be used with nested functions.
| Enumerator | |
|---|---|
| l_checkpointed | |
| l_no_action | |
| l_applied | |
| l_applied_no_new_dummies | |
| l_error | |
| l_cached | |
| cadabra::Ex::Ex | ( | ) |
|
explicit |
Create a new Ex with a copy of the subtree at the given iterator.
Create new Ex with single head node being a copy of the given node.
|
explicit |
Copy constructor: create a full copy of the given other Ex.
Initialise with given string as head node (does not parse this string).
Create a single-node Ex representing the given rational.
Quick access to arguments or argument lists for A(B)(C,D) type nodes.
| multiplier_t cadabra::Ex::arg_to_num | ( | sibling_iterator | sib, |
| unsigned int | num | ||
| ) | const |
| hashval_t cadabra::Ex::calc_hash | ( | iterator | it | ) | const |
Calculate the hash value for the subtree starting at 'it'.
| bool cadabra::Ex::changed_state | ( | ) |
A status query method mainly to implement a simple method to apply algorithms until they converge.
Returns true when the expression is in 'checkpointed' or 'applied' state. Will set the state to 'no_action'.
This is used in cadabra::convert_line defined in CdbPython.cc, which essentially defines converge(ex): [block] to mean
ex.reset_state() while ex.changed(): [block]
Comparison operators with primitive types.
| Ex::iterator cadabra::Ex::erase_expression | ( | iterator | it | ) |
| Ex::iterator cadabra::Ex::flatten_and_erase | ( | iterator | position | ) |
Replace the node with the children of the node, useful for e.g.
\prod{A} -> A. This algorithm takes care of the multiplier of the top node, i.e. it does 2\prod{A} -> 2 A. Returns an iterator to the new location of the first child of the original node.
| int cadabra::Ex::history_size | ( | ) | const |
Return the size of the history; 0 means no history, just the current expression.
| bool cadabra::Ex::is_empty | ( | ) | const |
Test if the expression is empty (no content at all).
| bool cadabra::Ex::is_hidden | ( | iterator | it | ) | const |
| bool cadabra::Ex::is_integer | ( | ) | const |
| bool cadabra::Ex::is_rational | ( | ) | const |
Test if the expression is a rational number.
FIXME: add tests for integers as well.
| bool cadabra::Ex::is_string | ( | ) | const |
| void cadabra::Ex::list_unwrap_single_element | ( | iterator & | it | ) |
| void cadabra::Ex::list_wrap_single_element | ( | iterator & | it | ) |
Make sure that the node pointed to is a \comma object, i.e.
wrap the node if not already inside such a \comma. DEPRECATED: in favour of 'do_list' in Functional.hh.
| Ex::iterator cadabra::Ex::move_index | ( | iterator | position, |
| const iterator & | from | ||
| ) |
As in replace_index, but moves the index rather than making a copy (so that iterators pointing to the original remain valid).
| Ex::iterator cadabra::Ex::named_parent | ( | iterator | it, |
| const std::string & | |||
| ) | const |
Step up until matching node is found (if current node matches, do nothing)
Compare two Ex objects for exact equality; no dummy equivalence or other things that require property information.
| std::vector< Ex::path_t > cadabra::Ex::pop_history | ( | ) |
Pop the most recent state of the expression off the history stack; returns the set of paths that we are replacing.
DEPRECATED, only used by take_match/replace_match.
| std::ostream & cadabra::Ex::print_entire_tree | ( | std::ostream & | str | ) | const |
Output helpers mainly for debugging purposes.
|
static |
Display expression in Python/Cadabra input form.
This is fairly straightforward so not handled with a separate DisplayBase derived class.
|
static |
|
static |
| std::ostream & cadabra::Ex::print_repr | ( | std::ostream & | str, |
| Ex::iterator | it | ||
| ) | const |
Print a representation like Python's 'repr'.
Push a copy of the current Storstate of the expression onto the history stack.
Also pushes a set of paths to terms which will be kept in the next history step. DEPRECATED, only used by take_match/replace_match.
| Ex::iterator cadabra::Ex::replace_index | ( | iterator | position, |
| const iterator & | from, | ||
| bool | keep_parent_rel = false |
||
| ) |
Replace the index-like object (originally intended to replace indices only, but now used also for e.g.
normal function arguments, as in
\[ \partial_{z}{ A(z) } \]
with a replacement of z).
Note: this originally kept the bracket and parent_rel, but that is not a good idea, because it prevents us from changing those. If we want to use a _{z} pattern replacing a A(z) index, it is better to make a rule that matches (z) and at the time we find and match _{z}. So this should be handled by the replacement_map logic in Compare.cc.
| void cadabra::Ex::reset_state | ( | ) |
| Ex::result_t cadabra::Ex::state | ( | ) | const |
| long cadabra::Ex::to_integer | ( | ) | const |
| multiplier_t cadabra::Ex::to_rational | ( | ) | const |
| void cadabra::Ex::update_state | ( | Ex::result_t | newstate | ) |
|
private |
|
private |
|
private |
Patterns which describe how to get from one history step to the next.