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

#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 (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.
 
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.
 
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_treehistory
 
std::vector< std::vector< Ex::path_t > > terms
 Patterns which describe how to get from one history step to the next.
 

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/8]

cadabra::Ex::Ex ( )

◆ Ex() [2/8]

cadabra::Ex::Ex ( cdb_tree::iterator  it)
explicit

Create a new Ex with a copy of the subtree at the given iterator.

◆ Ex() [3/8]

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

Create new Ex with single head node being a copy of the given node.

◆ Ex() [4/8]

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

Copy constructor: create a full copy of the given other Ex.

◆ Ex() [5/8]

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

Copy constructor: create a full copy of the given other Ex.

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

◆ Ex() [6/8]

cadabra::Ex::Ex ( int  val)
explicit

Create a single-node Ex representing the given integer.

◆ Ex() [7/8]

cadabra::Ex::Ex ( double  val)
explicit

Create a single-node Ex representing the given float.

◆ Ex() [8/8]

cadabra::Ex::Ex ( int  numer,
int  denom 
)
explicit

Create a single-node Ex representing the given rational.

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]

◆ equals()

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

Comparison operators with primitive types.

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

◆ is_string()

bool cadabra::Ex::is_string ( ) const

◆ 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_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'.

◆ push_history()

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

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.

◆ 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<cdb_tree> 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: