Expand description
The single shared Faà di Bruno / Leibniz combinatorial kernel (#1151).
Two jet representations live in this crate and historically each carried its own hand-written copy of the same calculus:
crate::jet_tower::Tower4— full dense derivative tensors (v,g,h,t3,t4) inKprimary variables, with the Leibniz product and Faà di Bruno composition written out term-by-term per derivative order.crate::jet_partitions::MultiDirJet— bitmask-coefficient jet over distinct seeded directions, with the same two rules written as general submask / set-partition loops.
The data layouts are legitimately different (a complete small-K tower
vs. a handful of directions of a large-K expression) and stay separate.
What is identical is the combinatorics: for a group of differentiation
slots, the Leibniz rule sums over subsets of those slots and the Faà di
Bruno rule sums over their set-partitions. This module owns that
combinatorics once, as a layout-agnostic [JetAlgebra] trait plus walkers
parameterised by closures that read each representation’s own derivative
for a slot-group. Both
Tower4 and MultiDirJet route their mul / compose_unary through
these walkers, so a fix to the rule is a fix to both — and a bit-exact
equivalence test (see tests) proves the two layouts agree.
A “slot-group” is a list of positions 0..m (the differentiation
arguments of one output coefficient). Each representation maps a group to
a derivative:
- For a tensor index tuple
(i, j, k, l), the positions0..mcarry axis labels[i, j, k, l]; a sub-group of positions selects the corresponding lower-order tensor entry (e.g. positions{0, 2}→h[i][k]). - For a bitmask coefficient
mask, the set bits are the slots; a sub-group of bits is itself a sub-mask read straight out ofcoeffs.
Functions§
- faa_
di_ bruno - Walk the multivariate Faà di Bruno rule for an output of
mslots.