5 #include <ginac/ginac.h>
7 // Yes, we are using CUBA (should be installed on the system!)
11 using namespace GiNaC;
14 * Demonstrates the use of compile_ex with the CUBA library.
16 * The user can enter an expression on the command line. This expression is
17 * compiled via compile_ex and integrated over the region 0 <= x,y <= 1 with
18 * the help of the CUBA library (http://www.feynarts.de/cuba).
24 // Let the user enter a expression
25 symbol x("x"), y("y");
27 cout << "Enter an expression containing 'x' and/or 'y': ";
29 // Expression now in expr
32 cout << "start integration of " << expr << " ..." << endl;
34 // Some definitions for VEGAS
45 // Some variables for VEGAS
46 int comp, nregions, neval, fail;
47 double integral[NCOMP], error[NCOMP], prob[NCOMP];
49 // Our function pointer that points to the compiled ex
52 // Optionally, compile with custom compiler flags:
53 // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
54 compile_ex(lst{expr}, lst{x,y}, fp);
57 // By invocation of compile() the expression in expr is converted into the
58 // appropriate function pointer
59 Vegas(NDIM, NCOMP, fp,
60 EPSREL, EPSABS, VERBOSE, MINEVAL, MAXEVAL, NSTART, NINCREASE,
61 &neval, &fail, integral, error, prob);
64 cout << "result: " << integral[0] << endl;