limes 3.1.0
Composable Calculus Expressions for C++20
Loading...
Searching...
No Matches
limes::expr::BoxIntegral< E, Dims > Struct Template Reference

N-dimensional integral over a rectangular box. More...

#include <box_integral.hpp>

Public Types

using value_type = typename E::value_type
 
using integrand_type = E
 
using bounds_type = std::array< std::pair< value_type, value_type >, Dims >
 

Public Member Functions

constexpr BoxIntegral (E e, bounds_type b) noexcept
 
algorithms::integration_result< value_typeeval (methods::monte_carlo< value_type > const &method) const
 Evaluate using Monte Carlo integration.
 
algorithms::integration_result< value_typeeval () const
 Evaluate with default Monte Carlo (10000 samples)
 
algorithms::integration_result< value_typeeval (std::size_t samples) const
 Evaluate with sample count.
 
algorithms::integration_result< value_typeevaluate () const
 
std::string to_string () const
 String representation.
 
template<typename Constraint >
constexpr auto where (Constraint c) const
 Add a constraint to the box integral (for rejection sampling)
 

Public Attributes

integrand
 
bounds_type bounds
 

Static Public Attributes

static constexpr std::size_t dims_v = Dims
 
static constexpr std::size_t arity_v = (E::arity_v > Dims) ? (E::arity_v - Dims) : 0
 

Detailed Description

template<typename E, std::size_t Dims>
struct limes::expr::BoxIntegral< E, Dims >

N-dimensional integral over a rectangular box.

Represents:

\[
  \int_{a_0}^{b_0} \cdots \int_{a_{n-1}}^{b_{n-1}} f(x_0, \ldots, x_{n-1}) \, dx_0 \cdots dx_{n-1}
\]

Box integrals are evaluated using Monte Carlo integration, which scales well to high dimensions (error decreases as O(1/√n) regardless of dimension).

Template Parameters
EIntegrand expression type
DimsNumber of dimensions
Example
auto x = arg<0>;
auto y = arg<1>;
auto z = arg<2>;
// Volume of unit cube (should be 1.0)
auto I = integral(1.0).over_box({{0,1}, {0,1}, {0,1}});
// Triple integral
auto J = integral(x*y*z).over_box({{0,1}, {0,1}, {0,1}});
auto result = J.eval(monte_carlo_method(1000000)); // ≈ 0.125
constexpr auto integral(E expr)
Create an IntegralBuilder for fluent integral construction.
Definition integral.hpp:505
constexpr Var< 2, T > z
Definition var.hpp:52
constexpr Var< 1, T > y
Definition var.hpp:49
constexpr Var< 0, T > x
Definition var.hpp:46
constexpr auto monte_carlo_method(std::size_t n)
Factory for Monte Carlo integration.
Definition methods.hpp:162
See also
integral().over_box() Builder method
ConstrainedBoxIntegral For irregular regions

Definition at line 132 of file box_integral.hpp.

Member Typedef Documentation

◆ bounds_type

template<typename E , std::size_t Dims>
using limes::expr::BoxIntegral< E, Dims >::bounds_type = std::array<std::pair<value_type, value_type>, Dims>

Definition at line 135 of file box_integral.hpp.

◆ integrand_type

template<typename E , std::size_t Dims>
using limes::expr::BoxIntegral< E, Dims >::integrand_type = E

Definition at line 134 of file box_integral.hpp.

◆ value_type

template<typename E , std::size_t Dims>
using limes::expr::BoxIntegral< E, Dims >::value_type = typename E::value_type

Definition at line 133 of file box_integral.hpp.

Constructor & Destructor Documentation

◆ BoxIntegral()

template<typename E , std::size_t Dims>
constexpr limes::expr::BoxIntegral< E, Dims >::BoxIntegral ( e,
bounds_type  b 
)
inlineconstexprnoexcept

Definition at line 143 of file box_integral.hpp.

Member Function Documentation

◆ eval() [1/3]

template<typename E , std::size_t Dims>
algorithms::integration_result< value_type > limes::expr::BoxIntegral< E, Dims >::eval ( ) const
inline

◆ eval() [2/3]

◆ eval() [3/3]

template<typename E , std::size_t Dims>
algorithms::integration_result< value_type > limes::expr::BoxIntegral< E, Dims >::eval ( std::size_t  samples) const
inline

Evaluate with sample count.

Definition at line 185 of file box_integral.hpp.

References limes::expr::BoxIntegral< E, Dims >::eval().

◆ evaluate()

template<typename E , std::size_t Dims>
algorithms::integration_result< value_type > limes::expr::BoxIntegral< E, Dims >::evaluate ( ) const
inline

Definition at line 191 of file box_integral.hpp.

References limes::expr::BoxIntegral< E, Dims >::eval().

◆ to_string()

template<typename E , std::size_t Dims>
std::string limes::expr::BoxIntegral< E, Dims >::to_string ( ) const
inline

String representation.

Definition at line 196 of file box_integral.hpp.

References limes::expr::BoxIntegral< E, Dims >::bounds, and limes::expr::BoxIntegral< E, Dims >::integrand.

◆ where()

template<typename E , std::size_t Dims>
template<typename Constraint >
constexpr auto limes::expr::BoxIntegral< E, Dims >::where ( Constraint  c) const
inlineconstexpr

Add a constraint to the box integral (for rejection sampling)

Definition at line 209 of file box_integral.hpp.

References limes::expr::BoxIntegral< E, Dims >::bounds, and limes::expr::BoxIntegral< E, Dims >::integrand.

Member Data Documentation

◆ arity_v

template<typename E , std::size_t Dims>
constexpr std::size_t limes::expr::BoxIntegral< E, Dims >::arity_v = (E::arity_v > Dims) ? (E::arity_v - Dims) : 0
staticconstexpr

Definition at line 138 of file box_integral.hpp.

◆ bounds

◆ dims_v

template<typename E , std::size_t Dims>
constexpr std::size_t limes::expr::BoxIntegral< E, Dims >::dims_v = Dims
staticconstexpr

Definition at line 137 of file box_integral.hpp.

◆ integrand

template<typename E , std::size_t Dims>
E limes::expr::BoxIntegral< E, Dims >::integrand

The documentation for this struct was generated from the following file: