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 
11 	/// \ingroup pythoncore
12 	///
13 	/// Comparison operator for Ex objects in Python. Since comparison operators
14 	/// need a Properties object, we cannot have such operator== things in C++,
15 	/// but we can in Python since we can get the kernel in the current scope.
16 	bool Ex_compare(Ex_ptr, Ex_ptr);
17 	bool Ex_compare(Ex_ptr, int);
18 
19 	/// \ingroup pythoncore
20 	///
21 	/// Add two expressions, adding a top-level \sum node if required.
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 
27 	/// \ingroup pythoncore
28 	///
29 	/// Multiply two expressions, adding a top-level \prod node if required.
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 
33 	/// \ingroup pythoncore
34 	///
35 	/// Subtract two expressions, adding a top-level \sum node if required.
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 
40 	/// \ingroup pythoncore
41 	///
42 	/// Fetch an Ex object from the Python side using its Python identifier.
43 	Ex_ptr fetch_from_python(const std::string& nm);
44 	Ex_ptr fetch_from_python(const std::string& nm, pybind11::object scope);
45 
46 	/// \ingroup pythoncore
47 	///
48 	/// Generate the Python str() and repr() representation of the Ex object.
49 	std::string Ex_as_str(Ex_ptr);
50 	std::string Ex_as_repr(Ex_ptr);
51 
52 	/// \ingroup pythoncore
53 	///
54 	/// The Python 'print' function always calls the 'str' member on
55 	/// objects to be printed. This one is required to produce output
56 	/// which looks readable but is also still valid input. In order to
57 	/// produce proper LaTeX output, this is therefore not the right
58 	/// function to use, because Cadabra only reads a restricted subset
59 	/// of LaTeX (for instance, we output spacing commands like '\,' but
60 	/// do not accept it on input).
61 	/// So we have a separate _latex_() member on each object, which
62 	///internally uses DisplayTeX to do the actual printing.
63 	std::string Ex_as_latex(Ex_ptr);
64 
65 	/// \ingroup scalar
66 	///
67 	/// Outputs a Cadabra 'Ex' as a Sympy expression. This first converts the
68 	/// Cadabra expression to a string, and then reads that back in by calling
69 	/// sympy.parsing.sympy_parser.parse_expr. Is mapped to a '_sympy_()'
70 	/// function on each Ex object.
71 	/// When you feed an Ex object to a Sympy function, the Ex gets converted
72 	/// to a Sympy object in 'sympy.sympify' because the latter attempts to
73 	/// call __sympy__ on every object that you feed it.
74 	pybind11::object Ex_as_sympy(Ex_ptr);
75 
76 	/// Similar to Ex_to_Sympy, but only producing a string which can be parsed
77 	/// by Sympy, instead of a full-fledged Sympy expression.
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 
86 	cadabra::Ex lhs(Ex_ptr ex);
87 	cadabra::Ex rhs(Ex_ptr ex);
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 	}