Imperative Conditions

Overview

While AADC’s functional conditional operations (iIf(), condAssign()) handle most stochastic branching needs, complex analytical code often requires traditional imperative control flow with multiple branches, nested conditions, and early returns. The AADC Imperative Conditions provides macros that enable standard if/else syntax while maintaining correctness for kernel compilation and automatic differentiation.

Key Features:

  • Imperative syntax: Use familiar if/else style with AADC macros
  • Multiple branches: Support for if/else if/else chains
  • Nested conditions: Full support for branching within branches
  • Early returns: Exit functions based on validation or edge cases
  • Backward compatible: Same code compiles in AADC and native modes

Quick Example:

#include <aadc/aadc_ifelse.h>

idouble price_option(idouble spot, idouble strike, idouble barrier) {
    AADC_BRANCHLESS_FUNCTION
    idouble result(0.0);

    AADC_IF(spot > barrier) {
        result = 0.0;  // Knocked out
    } AADC_ELSE_IF(spot > strike) {
        result = spot - strike;  // In the money
    } AADC_ELSE {
        result = 0.0;  // Out of the money
    } AADC_IF_END

    return result;
}

Quick Reference

Component Syntax Purpose
Function setup AADC_BRANCHLESS_FUNCTION Initialize branch tracking (required)
If condition AADC_IF(condition) First branch
Else-if condition AADC_ELSE_IF(condition) Additional branches
Else fallback AADC_ELSE Final branch
Block terminator } AADC_IF_END Close conditional block
Early return AADC_RETURN(value) Exit within AADC_IF block

This is a preview of the Imperative Conditions documentation.

The full documentation includes detailed usage patterns, nested conditions, validation handling, debugging tips, and advanced examples.

Contact us to request a demo version and get access to the complete documentation.