import std.math : PI, pow;
import std.stdio : writeln;
auto func = function( double[] xs )
{
if (pow(xs[0],2)+pow(xs[1],2)<= 1.0)
return 1.0;
return 0.0;
};
auto result = integrate( func, [-1.0,-1], [1.0,1.0], 1e-5, 0 );
result.writeln;
assert( result.value <= PI + 3*sqrt(result.error) );
assert( result.value >= PI - 3*sqrt(result.error) );
import std.stdio : writeln;
auto func = function(double[] xs )
{
return xs[0]*xs[1];
};
auto result = integrate( func, [0.0,0], [1.0,1] );
result.writeln;
assert( result.value <= 0.25 + 3*sqrt(result.error) );
assert( result.value >= 0.25 - 3*sqrt(result.error) );
import std.math : PI, cos;
import std.stdio : writeln;
auto func = function(real[] xs )
{
return 1.0/(pow(PI,3)*(1-cos(xs[0])*cos(xs[1])*cos(xs[2])));
};
auto result = integrate( func, [0,0,0], [PI,PI,PI] );
result.writeln;
assert( result.value <= 1.393204 + 3*sqrt(result.error) );
assert( result.value >= 1.393204 - 3*sqrt(result.error) );
The returned error is the expected variance in the result