Cadabra
Computer algebra system for field theory problems
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
cadabra::Ex Class Reference

Description

Basic storage class for symbolic mathemematical expressions.

The full meaning of an expression typically requires knowledge about properties of patterns in it, which this class does not contain. All property dependent algorithms acting on Ex objects are in Algorithm.hh.

#include <Storage.hh>

Inheritance diagram for cadabra::Ex:

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 (tree< str_node >::iterator)
 
 Ex (const str_node &)
 
 Ex (const Ex &)
 
 Ex (const std::string &)
 Initialise with given string as head node (does not parse this string). More...
 
 Ex (int)
 
 Ex (float)
 
Exoperator= (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. More...
 
bool is_rational () const
 Test if the expression is a rational number. More...
 
multiplier_t to_rational () const
 
bool is_integer () const
 
long to_integer () const
 
bool is_empty () const
 Test if the expression is empty (no content at all). More...
 
std::ostream & print_entire_tree (std::ostream &str) const
 Output helpers mainly for debugging purposes. More...
 
std::ostream & print_repr (std::ostream &str, Ex::iterator it) const
 Print a representation like Python's 'repr'. More...
 
iterator named_parent (iterator it, const std::string &) const
 Step up until matching node is found (if current node matches, do nothing) More...
 
iterator erase_expression (iterator it)
 
hashval_t calc_hash (iterator it) const
 Calculate the hash value for the subtree starting at 'it'. More...
 
multiplier_t arg_to_num (sibling_iterator, unsigned int) const
 
unsigned int number_of_steps (iterator it) const
 
unsigned int number_of_equations () const
 
unsigned int equation_number (iterator it) const
 
nset_t::iterator equation_label (iterator it) const
 
iterator equation_by_number (unsigned int i) const
 
iterator equation_by_name (nset_t::iterator it) const
 
iterator equation_by_name (nset_t::iterator it, unsigned int &) const
 
iterator equation_by_number_or_name (iterator it, unsigned int last_used_equation) const
 
iterator equation_by_number_or_name (iterator it, unsigned int last_used_equation, unsigned int &) const
 
std::string equation_number_or_name (iterator it, unsigned int last_used_equation) const
 
iterator procedure_by_name (nset_t::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. More...
 
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). More...
 
void list_wrap_single_element (iterator &)
 Make sure that the node pointed to is a \comma object, i.e. More...
 
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. More...
 
bool operator== (const Ex &other) const
 Compare two Ex objects for exact equality; no dummy equivalence or other things that require property information. More...
 
void push_history (const std::vector< Ex::path_t > &)
 Push a copy of the current state of the expression onto the history stack. More...
 
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. More...
 
int history_size () const
 Return the size of the history; 0 means no history, just the current expression. More...
 

Static Public Member Functions

static std::ostream & print_python (std::ostream &str, Ex::iterator it)
 Display expression in Python/Cadabra input form. More...
 
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. More...
 
static unsigned int arg_size (sibling_iterator)
 

Private Attributes

result_t state_
 
std::vector< tree< str_node > > history
 
std::vector< std::vector< Ex::path_t > > terms
 Patterns which describe how to get from one history step to the next. More...
 

Member Enumeration Documentation

◆ result_t

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 

Constructor & Destructor Documentation

◆ Ex() [1/7]

cadabra::Ex::Ex ( )

◆ Ex() [2/7]

cadabra::Ex::Ex ( tree< str_node >::iterator  it)

◆ Ex() [3/7]

cadabra::Ex::Ex ( const str_node x)

◆ Ex() [4/7]

cadabra::Ex::Ex ( const Ex other)

◆ Ex() [5/7]

cadabra::Ex::Ex ( const std::string &  str)

Initialise with given string as head node (does not parse this string).

◆ Ex() [6/7]

cadabra::Ex::Ex ( int  val)

◆ Ex() [7/7]

cadabra::Ex::Ex ( float  val)

Member Function Documentation

◆ arg()

Ex::sibling_iterator cadabra::Ex::arg ( iterator  it,
unsigned int  num 
)
static

Quick access to arguments or argument lists for A(B)(C,D) type nodes.

◆ arg_size()

unsigned int cadabra::Ex::arg_size ( sibling_iterator  sib)
static

◆ arg_to_num()

multiplier_t cadabra::Ex::arg_to_num ( sibling_iterator  sib,
unsigned int  num 
) const

◆ calc_hash()

hashval_t cadabra::Ex::calc_hash ( iterator  it) const

Calculate the hash value for the subtree starting at 'it'.

◆ changed_state()

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]

◆ equation_by_name() [1/2]

Ex::iterator cadabra::Ex::equation_by_name ( nset_t::iterator  it) const

◆ equation_by_name() [2/2]

Ex::iterator cadabra::Ex::equation_by_name ( nset_t::iterator  it,
unsigned int &  tmp 
) const

◆ equation_by_number()

Ex::iterator cadabra::Ex::equation_by_number ( unsigned int  i) const

◆ equation_by_number_or_name() [1/2]

Ex::iterator cadabra::Ex::equation_by_number_or_name ( iterator  it,
unsigned int  last_used_equation 
) const

◆ equation_by_number_or_name() [2/2]

Ex::iterator cadabra::Ex::equation_by_number_or_name ( iterator  it,
unsigned int  last_used_equation,
unsigned int &  real_eqno 
) const

◆ equation_label()

nset_t::iterator cadabra::Ex::equation_label ( iterator  it) const

◆ equation_number()

unsigned int cadabra::Ex::equation_number ( iterator  it) const

◆ equation_number_or_name()

std::string cadabra::Ex::equation_number_or_name ( iterator  it,
unsigned int  last_used_equation 
) const

◆ erase_expression()

Ex::iterator cadabra::Ex::erase_expression ( iterator  it)

◆ flatten_and_erase()

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.

◆ history_size()

int cadabra::Ex::history_size ( ) const

Return the size of the history; 0 means no history, just the current expression.

◆ is_empty()

bool cadabra::Ex::is_empty ( ) const

Test if the expression is empty (no content at all).

◆ is_hidden()

bool cadabra::Ex::is_hidden ( iterator  it) const

◆ is_integer()

bool cadabra::Ex::is_integer ( ) const

◆ is_rational()

bool cadabra::Ex::is_rational ( ) const

Test if the expression is a rational number.

FIXME: add tests for integers as well.

◆ list_unwrap_single_element()

void cadabra::Ex::list_unwrap_single_element ( iterator &  it)

◆ list_wrap_single_element()

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.

◆ move_index()

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).

◆ named_parent()

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)

◆ number_of_equations()

unsigned int cadabra::Ex::number_of_equations ( ) const

◆ number_of_steps()

unsigned int cadabra::Ex::number_of_steps ( iterator  it) const

◆ operator=()

Ex & cadabra::Ex::operator= ( Ex  other)

◆ operator==()

bool cadabra::Ex::operator== ( const Ex other) const

Compare two Ex objects for exact equality; no dummy equivalence or other things that require property information.

◆ pop_history()

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.

◆ print_entire_tree()

std::ostream & cadabra::Ex::print_entire_tree ( std::ostream &  str) const

Output helpers mainly for debugging purposes.

◆ print_python()

std::ostream & cadabra::Ex::print_python ( std::ostream &  str,
Ex::iterator  it 
)
static

Display expression in Python/Cadabra input form.

This is fairly straightforward so not handled with a separate DisplayBase derived class.

◆ print_recursive_treeform() [1/2]

std::ostream & cadabra::Ex::print_recursive_treeform ( std::ostream &  str,
Ex::iterator  it 
)
static

◆ print_recursive_treeform() [2/2]

std::ostream & cadabra::Ex::print_recursive_treeform ( std::ostream &  str,
Ex::iterator  it,
unsigned int &  number 
)
static

◆ print_repr()

std::ostream & cadabra::Ex::print_repr ( std::ostream &  str,
Ex::iterator  it 
) const

Print a representation like Python's 'repr'.

◆ procedure_by_name()

Ex::iterator cadabra::Ex::procedure_by_name ( nset_t::iterator  it) const

◆ push_history()

void cadabra::Ex::push_history ( const std::vector< Ex::path_t > &  paths)

Push a copy of the current state 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.

◆ replace_index()

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.

◆ reset_state()

void cadabra::Ex::reset_state ( )

◆ state()

Ex::result_t cadabra::Ex::state ( ) const

◆ to_integer()

long cadabra::Ex::to_integer ( ) const

◆ to_rational()

multiplier_t cadabra::Ex::to_rational ( ) const

◆ update_state()

void cadabra::Ex::update_state ( Ex::result_t  newstate)

Member Data Documentation

◆ history

std::vector<tree<str_node> > cadabra::Ex::history
private

◆ state_

result_t cadabra::Ex::state_
private

◆ terms

std::vector<std::vector<Ex::path_t> > cadabra::Ex::terms
private

Patterns which describe how to get from one history step to the next.


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