Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PythonCdb.hh
Go to the documentation of this file.
1 /*
2 
3  Cadabra: a field-theory motivated computer algebra system.
4  Copyright (C) 2001-2014 Kasper Peeters <kasper.peeters@phi-sci.com>
5 
6  This program is free software: you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation, either version 3 of the
9  License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #pragma once
22 
23 #include <boost/python.hpp>
24 #include <stdexcept>
25 #include "Storage.hh"
26 #include "Kernel.hh"
27 #include "Algorithm.hh"
28 
34 
35 bool __eq__Ex_Ex(const cadabra::Ex&, const cadabra::Ex&);
36 
40 
41 bool __eq__Ex_int(const cadabra::Ex&, int);
42 
44 
45 std::shared_ptr<cadabra::Ex> fetch_from_python(const std::string& nm);
46 
50 
51 std::string Ex_str_(const cadabra::Ex&);
52 std::string Ex_repr_(const cadabra::Ex&);
53 
65 
66 std::string Ex_latex_(const cadabra::Ex&);
67 
77 
78 boost::python::object Ex_to_Sympy(const cadabra::Ex&);
79 
82 
83 std::string Ex_to_Sympy_string(const cadabra::Ex&);
84 
85 
89 
90 cadabra::Ex operator+(const cadabra::Ex& ex1, const cadabra::Ex& ex2);
91 
95 
96 cadabra::Ex operator-(const cadabra::Ex& ex1, const cadabra::Ex& ex2);
97 
102 
104 };
105 
131 
132 template<class T>
133 class Property : public BaseProperty {
134  public:
135  Property(std::shared_ptr<cadabra::Ex> obj, std::shared_ptr<cadabra::Ex> params=0);
136 
138  std::string str_() const;
139 
141  std::string latex_() const;
142 
144  std::string repr_() const;
145 
146 
147  private:
148  // We keep a pointer to the C++ property, so it is possible to
149  // query properties using the Python interface. However, this C++
150  // object is owned by the C++ kernel and does not get destroyed
151  // when the Python object goes out of scope.
152 
153  // When the Python object survives the local scope, results are
154  // undefined.
155  T *prop;
156 
157  // We also keep a shared pointer to the expression for which we
158  // have defined this property, so that we can print sensible
159  // information.
160  std::shared_ptr<cadabra::Ex> for_obj;
161 };
162 
163 
225 
229 
237 
239 
244 
248 
cadabra::Kernel * create_scope_from_global()
Definition: PythonCdb.cc:822
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:130
std::string Ex_to_Sympy_string(const cadabra::Ex &)
Similar to Ex_to_Sympy, but only producing a string which can be parsed by Sympy, instead of a full-f...
Definition: PythonCdb.cc:343
cadabra::Ex operator+(const cadabra::Ex &ex1, const cadabra::Ex &ex2)
Add two expressions, adding a top-level node if required.
Definition: PythonCdb.cc:536
bool __eq__Ex_Ex(const cadabra::Ex &, const cadabra::Ex &)
Comparison operator for Ex objects in Python.
Definition: PythonCdb.cc:433
T * prop
Definition: PythonCdb.hh:155
cadabra::Kernel * create_empty_scope()
Definition: PythonCdb.cc:829
cadabra::Kernel * create_scope()
Setup of kernels in current scope, callable from Python.
Definition: PythonCdb.cc:815
cadabra::Ex operator-(const cadabra::Ex &ex1, const cadabra::Ex &ex2)
Subtract two expressions, adding a top-level node if required.
Definition: PythonCdb.cc:572
std::string Ex_latex_(const cadabra::Ex &)
The Python 'print' function always calls the 'str' member on objects to be printed.
Definition: PythonCdb.cc:327
std::string Ex_str_(const cadabra::Ex &)
Generate the Python str() and repr() representation of the Ex object.
Definition: PythonCdb.cc:299
cadabra::Kernel * get_kernel_from_scope()
Get a pointer to the currently visible kernel.
Definition: PythonCdb.cc:766
std::string str_() const
Human-readable form in text, i.e. no special formatting.
Definition: PythonCdb.cc:915
void call_post_process(cadabra::Kernel &, cadabra::Ex &ex)
Run the post-process Python function (if defined) on the given expression.
Definition: PythonCdb.cc:1007
std::shared_ptr< cadabra::Ex > fetch_from_python(const std::string &nm)
Fetch an Ex object from the Python side using its Python identifier.
Definition: PythonCdb.cc:390
boost::python::object Ex_to_Sympy(const cadabra::Ex &)
Outputs a Cadabra 'Ex' as a Sympy expression.
Definition: PythonCdb.cc:359
Helper class to ensure that all Python property objects derive from the same base class...
Definition: PythonCdb.hh:103
Property(std::shared_ptr< cadabra::Ex > obj, std::shared_ptr< cadabra::Ex > params=0)
Definition: PythonCdb.cc:905
std::string repr_() const
Python-parseable form. FIXME: not correct right now.
Definition: PythonCdb.cc:952
Property is a templated wrapper around a C++ property object.
Definition: PythonCdb.hh:133
std::shared_ptr< cadabra::Ex > for_obj
Definition: PythonCdb.hh:160
std::string latex_() const
Human-readable form using LaTeX markup.
Definition: PythonCdb.cc:925
Definition: Kernel.hh:15
void inject_defaults(cadabra::Kernel *)
Inject properties directly into the Kernel, even if the kernel is not yet on the Python stack (needed...
Definition: PythonCdb.cc:835
std::string Ex_repr_(const cadabra::Ex &)
Definition: PythonCdb.cc:335
bool __eq__Ex_int(const cadabra::Ex &, int)
Comparison operator for Ex objects in Python.
Definition: PythonCdb.cc:438