2 #include <ginac/ginac.h>
3 // Yes, we are using CUBA (should be installed on the system!)
10 * Demonstrates the use of compile_ex with the CUBA library.
12 * The user can enter an expression on the command line. This expression is
13 * compiled via compile_ex and integrated over the region 0 <= x,y <= 1 with
14 * the help of the CUBA library (http://www.feynarts.de/cuba).
20 // Let the user enter a expression
21 symbol x("x"), y("y");
23 cout << "Enter an expression containing 'x' and/or 'y': ";
25 // Expression now in expr
28 cout << "start integration of " << expr << " ..." << endl;
30 // Some definitions for VEGAS
41 // Some variables for VEGAS
42 int comp, nregions, neval, fail;
43 double integral[NCOMP], error[NCOMP], prob[NCOMP];
45 // Our function pointer that points to the compiled ex
48 // Optionally, compile with custom compiler flags:
49 // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
50 compile_ex(lst{expr}, lst{x,y}, fp);
53 // By invocation of compile() the expression in expr is converted into the
54 // appropriate function pointer
55 Vegas(NDIM, NCOMP, fp,
56 EPSREL, EPSABS, VERBOSE, MINEVAL, MAXEVAL, NSTART, NINCREASE,
57 &neval, &fail, integral, error, prob);
60 cout << "result: " << integral[0] << endl;