Branches

Most conditional logic in analytical code works normally with AADC. Only a specific subset - branches that depend on kernel inputs - require special handling to maintain correctness for both Kernel compilation and automatic differentiation.

Overview

Key Concepts:

  • Static branches: Conditions that don’t depend on kernel inputs - use standard if/else
  • Stochastic branches: Conditions that depend on kernel inputs - use iIf() or Imperative Conditions
  • Diff-only branches: Conditions on markAsDiff() variables - either approach works

Quick Example:

idouble spot(100.0), strike(95.0);
spot.markAsInput();

// Stochastic branch - use iIf()
idouble payoff = iIf(spot > strike, spot - strike, 0.0);

Two Approaches for Stochastic Branches:

Approach Best For
iIf() Simple ternary logic, inline calculations
Imperative Conditions Complex multi-branch logic, nested conditions, early returns

This is a preview of the Branches documentation.

The full documentation includes detailed branch classification, code examples, performance patterns, and advanced patterns for numerical methods.

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