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

Fluent builder for computing symbolic derivatives. More...

#include <derivative_builder.hpp>

Public Types

using value_type = typename E::value_type
 
using expr_type = E
 

Public Member Functions

constexpr DerivativeBuilder (E e) noexcept
 
template<std::size_t Dim>
constexpr auto wrt () const
 Compute ∂/∂x_Dim and return a new builder for chaining.
 
template<std::size_t D1, std::size_t D2>
constexpr auto wrt () const
 Compute ∂²/∂x_D1 ∂x_D2 (convenience for second-order mixed partials)
 
template<std::size_t D1, std::size_t D2, std::size_t D3>
constexpr auto wrt () const
 Compute ∂³/∂x_D1 ∂x_D2 ∂x_D3 (convenience for third-order mixed partials)
 
constexpr auto gradient () const
 Returns tuple<∂f/∂x₀, ∂f/∂x₁, ..., ∂f/∂x_{n-1}>
 
constexpr E get () const noexcept
 Allow implicit conversion to the underlying derivative expression.
 
constexpr value_type eval (std::span< value_type const > args) const
 Evaluate the derivative expression.
 
constexpr value_type evaluate (std::span< value_type const > args) const
 Deprecated: use eval() instead.
 
std::string to_string () const
 String representation.
 
template<std::size_t Dim>
constexpr auto derivative () const
 Further differentiation through the member function.
 

Public Attributes

expr
 

Static Public Attributes

static constexpr std::size_t arity_v = E::arity_v
 Arity of the derivative expression.
 

Detailed Description

template<typename E>
struct limes::expr::DerivativeBuilder< E >

Fluent builder for computing symbolic derivatives.

DerivativeBuilder wraps an expression and provides chainable methods for computing partial derivatives. Derivatives are computed symbolically at compile time using the chain rule.

Template Parameters
EThe expression type being differentiated
Fluent API
derivative(f).wrt<0>() // ∂f/∂x₀
derivative(f).wrt<0>().wrt<1>() // ∂²f/∂x₀∂x₁
derivative(f).wrt<0, 0>() // ∂²f/∂x₀² (convenience)
derivative(f).gradient() // all partials as tuple
constexpr auto derivative() const
Further differentiation through the member function.
Evaluation
The result of differentiation is itself an expression that can be evaluated:
auto df = derivative(sin(x*x)).wrt<0>();
double result = df.eval({2.0}); // Evaluate at x=2
constexpr auto sin(E e)
constexpr Var< 0, T > x
Definition var.hpp:46
See also
derivative() Entry point function

Definition at line 79 of file derivative_builder.hpp.

Member Typedef Documentation

◆ expr_type

template<typename E >
using limes::expr::DerivativeBuilder< E >::expr_type = E

Definition at line 81 of file derivative_builder.hpp.

◆ value_type

template<typename E >
using limes::expr::DerivativeBuilder< E >::value_type = typename E::value_type

Definition at line 80 of file derivative_builder.hpp.

Constructor & Destructor Documentation

◆ DerivativeBuilder()

template<typename E >
constexpr limes::expr::DerivativeBuilder< E >::DerivativeBuilder ( e)
inlineconstexprnoexcept

Definition at line 85 of file derivative_builder.hpp.

Member Function Documentation

◆ derivative()

template<typename E >
template<std::size_t Dim>
constexpr auto limes::expr::DerivativeBuilder< E >::derivative ( ) const
inlineconstexpr

Further differentiation through the member function.

Definition at line 147 of file derivative_builder.hpp.

References limes::expr::DerivativeBuilder< E >::expr.

◆ eval()

template<typename E >
constexpr value_type limes::expr::DerivativeBuilder< E >::eval ( std::span< value_type const >  args) const
inlineconstexpr

Evaluate the derivative expression.

Definition at line 127 of file derivative_builder.hpp.

References limes::expr::DerivativeBuilder< E >::expr.

Referenced by limes::expr::DerivativeBuilder< E >::evaluate().

◆ evaluate()

template<typename E >
constexpr value_type limes::expr::DerivativeBuilder< E >::evaluate ( std::span< value_type const >  args) const
inlineconstexpr

Deprecated: use eval() instead.

Definition at line 133 of file derivative_builder.hpp.

References limes::expr::DerivativeBuilder< E >::eval().

◆ get()

template<typename E >
constexpr E limes::expr::DerivativeBuilder< E >::get ( ) const
inlineconstexprnoexcept

Allow implicit conversion to the underlying derivative expression.

Definition at line 124 of file derivative_builder.hpp.

References limes::expr::DerivativeBuilder< E >::expr.

◆ gradient()

template<typename E >
constexpr auto limes::expr::DerivativeBuilder< E >::gradient ( ) const
inlineconstexpr

Returns tuple<∂f/∂x₀, ∂f/∂x₁, ..., ∂f/∂x_{n-1}>

Definition at line 115 of file derivative_builder.hpp.

◆ to_string()

template<typename E >
std::string limes::expr::DerivativeBuilder< E >::to_string ( ) const
inline

String representation.

Definition at line 138 of file derivative_builder.hpp.

References limes::expr::DerivativeBuilder< E >::expr.

◆ wrt() [1/3]

template<typename E >
template<std::size_t Dim>
constexpr auto limes::expr::DerivativeBuilder< E >::wrt ( ) const
inlineconstexpr

Compute ∂/∂x_Dim and return a new builder for chaining.

Definition at line 93 of file derivative_builder.hpp.

References limes::expr::DerivativeBuilder< E >::expr.

◆ wrt() [2/3]

template<typename E >
template<std::size_t D1, std::size_t D2>
constexpr auto limes::expr::DerivativeBuilder< E >::wrt ( ) const
inlineconstexpr

Compute ∂²/∂x_D1 ∂x_D2 (convenience for second-order mixed partials)

Definition at line 100 of file derivative_builder.hpp.

◆ wrt() [3/3]

template<typename E >
template<std::size_t D1, std::size_t D2, std::size_t D3>
constexpr auto limes::expr::DerivativeBuilder< E >::wrt ( ) const
inlineconstexpr

Compute ∂³/∂x_D1 ∂x_D2 ∂x_D3 (convenience for third-order mixed partials)

Definition at line 106 of file derivative_builder.hpp.

Member Data Documentation

◆ arity_v

template<typename E >
constexpr std::size_t limes::expr::DerivativeBuilder< E >::arity_v = E::arity_v
staticconstexpr

Arity of the derivative expression.

Definition at line 143 of file derivative_builder.hpp.

◆ expr


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