Skip to main content

Module nested_dual

Module nested_dual 

Source
Expand description

Nested second-order forward-AD dual for FD-free high-order cross-checks (#932).

Dual2<S> is a single-direction second-order jet (value, first and second derivative in ONE direction) over a scalar field S. Because the field is generic, it composes with itself: Dual2<Dual2<f64>> carries every mixed partial ∂^i_a ∂^j_b for i, j ∈ {0, 1, 2}, i.e. the full 2 + 2 = 4th-order bidirectional derivative in two INDEPENDENT directions a, b.

Why this exists: the flexible survival marginal-slope Jet4 tower (the moving-boundary implicit-intercept path, gam#932) is the last derivative surface whose fourth-order channel is verified only by a finite-difference stencil — the hand reference is provably incomplete there, and a 4th-order FD probes a 6th derivative, so the truncation floor sits far above machine precision (the same pathology as gam#979). A nested dual evaluates the SAME single-source program by a DIFFERENT composition ordering (two nested second-order sweeps instead of one fourth-order sweep), so its ∂²_a ∂²_b channel is a truncation-free, hand-oracle-free cross-check of the Jet4 bidirectional block.

The construction is standard forward-over-forward automatic differentiation; its correctness is pinned channel-for-channel against the engine crate::jet_tower::Tower4 on smooth programs (see the module tests).

Structs§

Dual2
A single-direction second-order jet over the field S: value v, first derivative g, second derivative h, all with respect to ONE seeded direction. Nest it (Dual2<Dual2<f64>>) for a second, independent direction.

Traits§

JetField
Minimal scalar field a Dual2 can be built over. Implemented by f64 (the base case) and by Dual2 itself (the nesting case). Every operation mirrors the crate::jet_tower::Tower4 / crate::jet_scalar::JetScalar Faà di Bruno convention exactly, so a program written against JetField evaluates identically on the engine tower and on a nested dual.
JetFieldConst
A JetField that is Copy and can be built from a real constant with every derivative channel zero. The nested-dual oracle (Dual2 over a Copy leaf) needs a dimensionless constructor; the runtime-p Vec-backed flex jets deliberately do NOT satisfy this (their constant needs a primary count), so it lives on this subtrait rather than the shared algebra base.

Type Aliases§

Dual22
A Dual2<Dual2<f64>> seeded with independent directions a (outer) and b (inner): value x, unit first derivative along both requested directions. p0 should be seeded (a=1, b=0) and p1 (a=0, b=1) for a two-primary program (mirrors Tower4::variable(x, 0) / Tower4::variable(x, 1)).