3 #include <ginac/ginac.h>
5 // Yes, we are using CUBA (should be installed on the system!)
9 * Demonstrates the use of compile_ex with the CUBA library.
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).
19 // Let the user enter a expression
20 symbol x("x"), y("y");
22 cout << "Enter an expression containing 'x' and/or 'y': ";
24 // Expression now in expr
27 cout << "start integration of " << expr << " ..." << endl;
29 // Some definitions for VEGAS
40 // Some variables for VEGAS
41 int comp, nregions, neval, fail;
42 double integral[NCOMP], error[NCOMP], prob[NCOMP];
44 // Our function pointer that points to the compiled ex
47 // Optionally, compile with custom compiler flags:
48 // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
49 compile_ex(lst{expr}, lst{x,y}, fp);
52 // By invocation of compile() the expression in expr is converted into the
53 // appropriate function pointer
54 Vegas(NDIM, NCOMP, fp,
55 EPSREL, EPSABS, VERBOSE, MINEVAL, MAXEVAL, NSTART, NINCREASE,
56 &neval, &fail, integral, error, prob);
59 cout << "result: " << integral[0] << endl;