Compound (Fused) Operations

Compound operations perform multiple arithmetic steps in a single call for performance. Use these instead of chaining separate operations.

Formula reference:

MethodFormulaInstead of
AddAndMul(X, Y, Z)self = (X + Y) * ZAdd(X,Y) then Mul(Z)
SubAndMul(X, Y, Z)self = (X - Y) * ZSub(X,Y) then Mul(Z)
MulAndAdd(X, Y, Z)self = X * Y + ZMul(X,Y) then Add(Z)
MulAndSub(X, Y, Z)self = X * Y - ZMul(X,Y) then Sub(Z)
DivAndAdd(X, Y, Z)self = X / Y + ZDiv(X,Y) then Add(Z)
DivAndSub(X, Y, Z)self = X / Y - ZDiv(X,Y) then Sub(Z)
AddScaled(Y, yScale)self = self + Y * yScaleMul then Add
SubScaled(Y, yScale)self = self - Y * yScaleMul then Sub
SqrAddScaled(X, Y, yScale)self = sqr(X) + sqr(Y) * yScaleSqr twice, Mul, Add

Scale variants: Most compound methods have scale factor overloads:

  • AddAndMul(X, Y, Z, zScale) → self = (X + Y) Z zScale
  • MulAndAdd(X, Y, Z, zScale) → self = X Y + Z zScale

Performance: Compound operations are 2-3x faster than separate calls because:

  1. Single pass through memory (cache-friendly)
  2. No temporary arrays allocated
  3. Vectorized (SIMD) implementation

When to use: Whenever your formula matches one of the patterns above. The AI should recognize expressions like (A + B) * C and suggest AddAndMul.