]> www.ginac.de Git - ginac.git/blob - doc/examples/compile2.cpp
Don't force every algebraic class to implement archiving/unarchiving.
[ginac.git] / doc / examples / compile2.cpp
1 #include <iostream>
2 using namespace std;
3 #include <ginac/ginac.h>
4 using namespace GiNaC;
5 // Yes, we are using CUBA (should be installed on the system!)
6 #include <cuba.h>
7
8 /*
9  * Demonstrates the use of compile_ex with the CUBA library.
10  *
11  * The user can enter an expression on the command line. This expression is
12  * compiled via compile_ex and integrated over the region 0 <= x,y <= 1 with
13  * the help of the CUBA library (http://www.feynarts.de/cuba).
14  *
15  */
16
17 int main()
18 {
19         // Let the user enter a expression
20         symbol x("x"), y("y");
21         string s;
22         cout << "Enter an expression containing 'x' and/or 'y': ";
23         cin >> s;
24         // Expression now in expr
25         ex expr(s, lst(x,y));
26  
27         cout << "start integration of " << expr << " ..." << endl;
28
29         // Some definitions for VEGAS 
30         #define NDIM 2
31         #define NCOMP 1
32         #define EPSREL 1e-3
33         #define EPSABS 1e-12
34         #define VERBOSE 0
35         #define MINEVAL 0
36         #define MAXEVAL 50000
37         #define NSTART 1000
38         #define NINCREASE 500
39
40         // Some variables for VEGAS
41         int comp, nregions, neval, fail;
42         double integral[NCOMP], error[NCOMP], prob[NCOMP];
43
44         // Our function pointer that points to the compiled ex
45         FUNCP_CUBA fp;
46         compile_ex(lst(expr), lst(x,y), fp);
47
48         // Starting VEGAS
49         // By invocation of compile() the expression in expr is converted into the
50         // appropriate function pointer
51         Vegas(NDIM, NCOMP, fp,
52               EPSREL, EPSABS, VERBOSE, MINEVAL, MAXEVAL, NSTART, NINCREASE,
53               &neval, &fail, integral, error, prob);
54
55         // Show the result
56         cout << "result: " << integral[0] << endl;
57
58         return 0;
59 }