]> www.ginac.de Git - ginac.git/blob - ginac/excompiler.h
Fixed a bug in is_polynomial() that caused expressions like
[ginac.git] / ginac / excompiler.h
1 /** @file excompiler.h
2  *
3  *  Functions to facilitate the conversion of a ex to a function pointer suited for
4  *  fast numerical integration. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #ifndef GINAC_EXCOMPILER_H
25 #define GINAC_EXCOMPILER_H
26
27 #include "lst.h"
28
29 #include <string>
30
31 namespace GiNaC {
32
33 class ex;
34 class symbol;
35
36 /**
37  * Function pointer with one function parameter.
38  */
39 typedef double (*FUNCP_1P) (double);
40
41 /**
42  * Function pointer with two function parameters.
43  */
44 typedef double (*FUNCP_2P) (double, double);
45
46 /**
47  * Function pointer for use with the CUBA library (http://www.feynarts.de/cuba).
48  */
49 typedef void (*FUNCP_CUBA) (const int*, const double[], const int*, double[]);
50
51 /**
52  * Takes an expression and produces a function pointer to the compiled and linked
53  * C code equivalent in double precision. The function pointer has type FUNCP_1P.
54  *
55  * @param expr Expression to be compiled
56  * @param sym Symbol from the expression to become the function parameter
57  * @param fp Returned function pointer
58  * @param filename Name of the intermediate source code and so-file. If
59  * supplied, these intermediate files will not be deleted
60  */
61 void compile_ex(const ex& expr, const symbol& sym, FUNCP_1P& fp, const std::string filename = "");
62
63 /**
64  * Takes an expression and produces a function pointer to the compiled and linked
65  * C code equivalent in double precision. The function pointer has type FUNCP_2P.
66  *
67  * @param expr Expression to be compiled
68  * @param sym Symbol from the expression to become the function parameter
69  * @param fp Returned function pointer
70  * @param filename Name of the intermediate source code and so-file. If
71  * supplied, these intermediate files will not be deleted
72  */
73 void compile_ex(const ex& expr, const symbol& sym1, const symbol& sym2, FUNCP_2P& fp, const std::string filename = "");
74
75 /**
76  * Takes an expression and produces a function pointer to the compiled and linked
77  * C code equivalent in double precision. The function pointer has type FUNCP_CUBA.
78  *
79  * @param expr Expression to be compiled
80  * @param sym Symbol from the expression to become the function parameter
81  * @param fp Returned function pointer
82  * @param filename Name of the intermediate source code and so-file. If
83  * supplied, these intermediate files will not be deleted
84  */
85 void compile_ex(const lst& exprs, const lst& syms, FUNCP_CUBA& fp, const std::string filename = "");
86
87 /** 
88  * Opens an existing so-file and returns a function pointer of type FUNCP_1P to
89  * the contained function. The so-file has to be generated by compile_ex in
90  * advance.
91  *
92  * @param filename Name of the so-file to open and link
93  * @param fp Returned function pointer
94  */
95 void link_ex(const std::string filename, FUNCP_1P& fp);
96
97 /** 
98  * Opens an existing so-file and returns a function pointer of type FUNCP_2P to
99  * the contained function. The so-file has to be generated by compile_ex in
100  * advance.
101  *
102  * @param filename Name of the so-file to open and link
103  * @param fp Returned function pointer
104  */
105 void link_ex(const std::string filename, FUNCP_2P& fp);
106
107 /** 
108  * Opens an existing so-file and returns a function pointer of type FUNCP_CUBA to
109  * the contained function. The so-file has to be generated by compile_ex in
110  * advance.
111  *
112  * @param filename Name of the so-file to open and link
113  * @param fp Returned function pointer
114  */
115 void link_ex(const std::string filename, FUNCP_CUBA& fp);
116
117 /**
118  * Closes all linked .so files that have the supplied filename.
119  *
120  * @param filename Name of the so-file to close
121  */
122 void unlink_ex(const std::string filename);
123
124 } // namespace GiNaC
125
126 #endif // ndef GINAC_EXCOMPILER_H