Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_error }
 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)
 
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
 
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
 
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. 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 (Ex selector)
 Push a copy of the current state of the expression onto the history stack. More...
 
Ex pop_history ()
 Pop the most recent state of the expression off the history stack; returns the selector that got us there. 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< tree< str_node > > selectors
 Patterns which describe how to get from one history step to the next. More...
 

Member Enumeration Documentation

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_error 

Constructor & Destructor Documentation

cadabra::Ex::Ex ( )
cadabra::Ex::Ex ( tree< str_node >::iterator  it)
cadabra::Ex::Ex ( const str_node x)
cadabra::Ex::Ex ( const Ex other)
cadabra::Ex::Ex ( const std::string &  str)

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

cadabra::Ex::Ex ( int  val)

Member Function Documentation

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.

unsigned int cadabra::Ex::arg_size ( sibling_iterator  sib)
static
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'.

Ex::iterator cadabra::Ex::equation_by_name ( nset_t::iterator  it) const
Ex::iterator cadabra::Ex::equation_by_name ( nset_t::iterator  it,
unsigned int &  tmp 
) const
Ex::iterator cadabra::Ex::equation_by_number ( unsigned int  i) const
Ex::iterator cadabra::Ex::equation_by_number_or_name ( iterator  it,
unsigned int  last_used_equation 
) const
Ex::iterator cadabra::Ex::equation_by_number_or_name ( iterator  it,
unsigned int  last_used_equation,
unsigned int &  real_eqno 
) const
nset_t::iterator cadabra::Ex::equation_label ( iterator  it) const
unsigned int cadabra::Ex::equation_number ( iterator  it) const
std::string cadabra::Ex::equation_number_or_name ( iterator  it,
unsigned int  last_used_equation 
) const
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_rational ( ) const

Test if the expression is a rational number.

FIXME: add tests for integers as well.

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)

unsigned int cadabra::Ex::number_of_equations ( ) const
unsigned int cadabra::Ex::number_of_steps ( iterator  it) const
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.

Ex cadabra::Ex::pop_history ( )

Pop the most recent state of the expression off the history stack; returns the selector that got us there.

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

Output helpers mainly for debugging purposes.

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.

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

Print a representation like Python's 'repr'.

Ex::iterator cadabra::Ex::procedure_by_name ( nset_t::iterator  it) const
void cadabra::Ex::push_history ( Ex  selector)

Push a copy of the current state of the expression onto the history stack.

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
multiplier_t cadabra::Ex::to_rational ( ) const
void cadabra::Ex::update_state ( Ex::result_t  newstate)

Member Data Documentation

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

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

result_t cadabra::Ex::state_
private

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