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

Description

Class to display expressions in a format that Mathematica can parse. Will throw an exception if a Cadabra Ex object cannot be understood by Mathematica. Can also convert expressions back to Cadabra notation.

#include <DisplayMMA.hh>

Inheritance diagram for cadabra::DisplayMMA:
cadabra::DisplayBase

Public Member Functions

 DisplayMMA (const Kernel &, const Ex &, bool use_unicode)
 
void import (Ex &)
 Rewrite the output of mathematica back into a notation used by Cadabra. More...
 
std::string preparse_import (const std::string &)
 
- Public Member Functions inherited from cadabra::DisplayBase
 DisplayBase (const Kernel &, const Ex &)
 
void output (std::ostream &)
 
void output (std::ostream &, Ex::iterator)
 

Protected Member Functions

virtual bool needs_brackets (Ex::iterator it) override
 Determine if a node needs extra brackets around it. More...
 

Protected Attributes

bool use_unicode
 
- Protected Attributes inherited from cadabra::DisplayBase
const Extree
 
const Kernelkernel
 

Private Member Functions

void print_multiplier (std::ostream &, Ex::iterator)
 Output the expression to a mathematica-readable form. More...
 
void print_opening_bracket (std::ostream &, str_node::bracket_t)
 
void print_closing_bracket (std::ostream &, str_node::bracket_t)
 
void print_parent_rel (std::ostream &, str_node::parent_rel_t, bool first)
 
void print_children (std::ostream &, Ex::iterator, int skip=0)
 
virtual void dispatch (std::ostream &, Ex::iterator) override
 For every object encountered, dispatch will figure out the most appropriate way to convert it into a LaTeX expression. More...
 
void print_productlike (std::ostream &, Ex::iterator, const std::string &inbetween)
 Printing members for various standard constructions, e.g. More...
 
void print_sumlike (std::ostream &, Ex::iterator)
 
void print_fraclike (std::ostream &, Ex::iterator)
 
void print_commalike (std::ostream &, Ex::iterator)
 
void print_arrowlike (std::ostream &, Ex::iterator)
 
void print_powlike (std::ostream &, Ex::iterator)
 
void print_intlike (std::ostream &, Ex::iterator)
 
void print_equalitylike (std::ostream &, Ex::iterator)
 
void print_components (std::ostream &, Ex::iterator)
 
void print_partial (std::ostream &str, Ex::iterator it)
 
void print_matrix (std::ostream &str, Ex::iterator it)
 
void print_other (std::ostream &str, Ex::iterator it)
 
bool children_have_brackets (Ex::iterator ch) const
 

Private Attributes

std::map< std::string, std::string > symmap
 Map from Cadabra symbols to Mathematica symbols. More...
 
std::multimap< std::string, std::string > regex_map
 
std::map< nset_t::iterator, Ex, nset_it_lessdepsyms
 Map from symbols which have had dependencies added to an expression containing these dependencies. More...
 

Constructor & Destructor Documentation

◆ DisplayMMA()

DisplayMMA::DisplayMMA ( const Kernel kernel,
const Ex e,
bool  use_unicode 
)

Member Function Documentation

◆ children_have_brackets()

bool DisplayMMA::children_have_brackets ( Ex::iterator  ch) const
private

◆ dispatch()

void DisplayMMA::dispatch ( std::ostream &  str,
Ex::iterator  it 
)
overrideprivatevirtual

For every object encountered, dispatch will figure out the most appropriate way to convert it into a LaTeX expression.

This may be done by simply looking at the object's name (e.g. \prod will print as a product) but may also involve looking up properties and deciding on the best course of action based on the attached properties.

Implements cadabra::DisplayBase.

◆ import()

void DisplayMMA::import ( Ex ex)

Rewrite the output of mathematica back into a notation used by Cadabra.

This in particular involves converting 'Sin' and friends to \sin and so on, as well as converting all the greek symbols. Currently only acts node-by-node, does not do anything complicated with trees.

◆ needs_brackets()

bool DisplayMMA::needs_brackets ( Ex::iterator  it)
overrideprotectedvirtual

Determine if a node needs extra brackets around it.

Uses context from the parent node if necessary. Has to be implemented in a derived class, because the answer depends on the printing method (e.g. (a+b)/c needs brackets when printed like this, but does not need brackets when printed as \frac{a+b}{c}).

Implements cadabra::DisplayBase.

◆ preparse_import()

std::string DisplayMMA::preparse_import ( const std::string &  in)

◆ print_arrowlike()

void DisplayMMA::print_arrowlike ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_children()

void DisplayMMA::print_children ( std::ostream &  str,
Ex::iterator  it,
int  skip = 0 
)
private

◆ print_closing_bracket()

void DisplayMMA::print_closing_bracket ( std::ostream &  str,
str_node::bracket_t  br 
)
private

◆ print_commalike()

void DisplayMMA::print_commalike ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_components()

void DisplayMMA::print_components ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_equalitylike()

void DisplayMMA::print_equalitylike ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_fraclike()

void DisplayMMA::print_fraclike ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_intlike()

void DisplayMMA::print_intlike ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_matrix()

void DisplayMMA::print_matrix ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_multiplier()

void DisplayMMA::print_multiplier ( std::ostream &  str,
Ex::iterator  it 
)
private

Output the expression to a mathematica-readable form.

For symbols which cannot be parsed by mathematica, this can convert to an alternative, Such rewrites can then be undone by the 'import' member above.

◆ print_opening_bracket()

void DisplayMMA::print_opening_bracket ( std::ostream &  str,
str_node::bracket_t  br 
)
private

◆ print_other()

void DisplayMMA::print_other ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_parent_rel()

void DisplayMMA::print_parent_rel ( std::ostream &  str,
str_node::parent_rel_t  pr,
bool  first 
)
private

◆ print_partial()

void DisplayMMA::print_partial ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_powlike()

void DisplayMMA::print_powlike ( std::ostream &  str,
Ex::iterator  it 
)
private

◆ print_productlike()

void DisplayMMA::print_productlike ( std::ostream &  str,
Ex::iterator  it,
const std::string &  inbetween 
)
private

Printing members for various standard constructions, e.g.

print as a list, or as a decorated symbol with super/subscripts etc. The names reflect the structure of the output, not necessarily the meaning or name of the object that is being printed.

◆ print_sumlike()

void DisplayMMA::print_sumlike ( std::ostream &  str,
Ex::iterator  it 
)
private

Member Data Documentation

◆ depsyms

std::map<nset_t::iterator, Ex, nset_it_less> cadabra::DisplayMMA::depsyms
private

Map from symbols which have had dependencies added to an expression containing these dependencies.

◆ regex_map

std::multimap<std::string, std::string> cadabra::DisplayMMA::regex_map
private

◆ symmap

std::map<std::string, std::string> cadabra::DisplayMMA::symmap
private

Map from Cadabra symbols to Mathematica symbols.

This is a bit tricky because MathLink does not pass \[Alpha] and friends transparently. So we feed it UTF8 α and so on, but then we get \[Alpha] back, and that needs to be regex-replaced before we feed it to our parser as ours does not swallow that kind of bracketing.

◆ use_unicode

bool cadabra::DisplayMMA::use_unicode
protected

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