Cadabra
Computer algebra system for field theory problems
py_ex.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include "../Storage.hh"
6 #include "../ExNode.hh"
7 
8 namespace cadabra {
9  using Ex_ptr = std::shared_ptr<Ex>;
10 
16  bool Ex_compare(Ex_ptr, Ex_ptr);
17  bool Ex_compare(Ex_ptr, int);
18 
22 
23  Ex_ptr Ex_add(const Ex_ptr ex1, const ExNode ex2);
24  Ex_ptr Ex_add(const Ex_ptr ex1, const Ex_ptr ex2);
25  Ex_ptr Ex_add(const Ex_ptr ex1, const Ex_ptr ex2, Ex::iterator top2);
26 
30  Ex_ptr Ex_mul(const Ex_ptr ex1, const Ex_ptr ex2);
31  Ex_ptr Ex_mul(const Ex_ptr ex1, const Ex_ptr ex2, Ex::iterator top2);
32 
36  Ex_ptr Ex_sub(const Ex_ptr ex1, const ExNode ex2);
37  Ex_ptr Ex_sub(const Ex_ptr ex1, const Ex_ptr ex2);
38  Ex_ptr Ex_sub(const Ex_ptr ex1, const Ex_ptr ex2, Ex::iterator top2);
39 
43  Ex_ptr fetch_from_python(const std::string& nm);
44  Ex_ptr fetch_from_python(const std::string& nm, pybind11::object scope);
45 
49  std::string Ex_as_str(Ex_ptr);
50  std::string Ex_as_repr(Ex_ptr);
51 
63  std::string Ex_as_latex(Ex_ptr);
64 
74  pybind11::object Ex_as_sympy(Ex_ptr);
75 
78  std::string Ex_as_sympy_string(Ex_ptr);
79 
80  std::string Ex_as_input(Ex_ptr ex);
81 
82  std::string Ex_as_MMA(Ex_ptr ex, bool use_unicode);
83 
84  std::string Ex_as_tree(Ex *ex);
85 
88 
89  Ex Ex_getslice(Ex_ptr ex, pybind11::slice slice);
90  Ex Ex_getitem(Ex &ex, int index);
91  void Ex_setitem(Ex_ptr ex, int index, Ex val);
92  void Ex_setitem_iterator(Ex_ptr ex, ExNode en, Ex_ptr val);
93  size_t Ex_len(Ex_ptr ex);
94  std::string Ex_head(Ex_ptr ex);
95  pybind11::object Ex_get_mult(Ex_ptr ex);
96 
97  // Split a 'sum' expression into its individual terms.
98  // FIXME: now deprecated because we have operator[]?
99  pybind11::list terms(Ex_ptr ex);
100 
101  Ex_ptr Ex_from_string(const std::string& in, bool make_ref = true, Kernel * kernel = nullptr);
102  Ex_ptr Ex_from_int(int num, bool make_ref = true);
103 
104  Ex_ptr map_sympy_wrapper(Ex_ptr ex, std::string head, pybind11::args args);
105 #ifdef MATHEMATICA_FOUND
106  Ex_ptr map_mma_wrapper(Ex_ptr ex, std::string head);
107 #endif
108 
109  void call_post_process(Kernel& kernel, Ex_ptr ex);
110 
111  void init_ex(pybind11::module& m);
112  }
ExNode is a combination of an Ex::iterator and an interface which we can use to manipulate the data p...
Definition: ExNode.hh:29
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:142
Definition: Kernel.hh:15
Ex_ptr Ex_add(const Ex_ptr ex1, const ExNode ex2)
Add two expressions, adding a top-level \sum node if required.
Definition: py_ex.cc:49
std::string Ex_as_str(Ex_ptr ex)
Generate the Python str() and repr() representation of the Ex object.
Definition: py_ex.cc:247
Ex_ptr Ex_mul(const Ex_ptr ex1, const Ex_ptr ex2)
Multiply two expressions, adding a top-level \prod node if required.
Definition: py_ex.cc:155
Ex_ptr Ex_sub(const Ex_ptr ex1, const ExNode ex2)
Subtract two expressions, adding a top-level \sum node if required.
Definition: py_ex.cc:176
Ex_ptr fetch_from_python(const std::string &nm)
Fetch an Ex object from the Python side using its Python identifier.
Definition: py_ex.cc:212
bool Ex_compare(Ex_ptr one, Ex_ptr other)
Comparison operator for Ex objects in Python.
Definition: py_ex.cc:38
std::string Ex_as_latex(Ex_ptr ex)
The Python 'print' function always calls the 'str' member on objects to be printed.
Definition: py_ex.cc:272
pybind11::object Ex_as_sympy(Ex_ptr ex)
Outputs a Cadabra 'Ex' as a Sympy expression.
Definition: py_ex.cc:282
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
Ex_ptr map_sympy_wrapper(Ex_ptr ex, std::string head, pybind11::args args)
Definition: py_ex.cc:604
void Ex_setitem(Ex_ptr ex, int index, Ex val)
Definition: py_ex.cc:429
void Ex_setitem_iterator(Ex_ptr ex, ExNode en, Ex_ptr val)
Definition: py_ex.cc:440
size_t Ex_len(Ex_ptr ex)
Definition: py_ex.cc:466
Ex Ex_getitem(Ex &ex, int index)
Definition: py_ex.cc:412
std::string Ex_head(Ex_ptr ex)
Definition: py_ex.cc:478
std::string Ex_as_sympy_string(Ex_ptr ex)
Similar to Ex_to_Sympy, but only producing a string which can be parsed by Sympy, instead of a full-f...
Definition: py_ex.cc:297
void init_ex(py::module &m)
Definition: py_ex.cc:612
std::string Ex_as_MMA(Ex_ptr ex, bool use_unicode)
Definition: py_ex.cc:328
std::string Ex_as_tree(Ex *ex)
Ex_ptr Ex_from_int(int num, bool)
Definition: py_ex.cc:561
void call_post_process(Kernel &kernel, Ex_ptr ex)
Definition: py_ex.cc:567
std::string Ex_as_repr(Ex_ptr ex)
Definition: py_ex.cc:261
std::shared_ptr< Ex > Ex_ptr
Definition: py_ex.hh:9
pybind11::list terms(Ex_ptr ex)
Definition: py_ex.cc:497
Ex rhs(Ex_ptr ex)
Definition: py_ex.cc:375
pybind11::object Ex_get_mult(Ex_ptr ex)
Definition: py_ex.cc:485
Ex lhs(Ex_ptr ex)
Definition: py_ex.cc:363
Ex_ptr Ex_from_string(const std::string &ex_, bool, Kernel *kernel)
Definition: py_ex.cc:521
std::string Ex_as_input(Ex_ptr ex)
Definition: py_ex.cc:314
Ex Ex_getslice(Ex_ptr ex, pybind11::slice slice)
Definition: py_ex.cc:389