Skip to content

Reducer

opulse.trace.reducer

Step-by-step reduction of an expression by unfolding operator definitions.

Strategy: applicative order, leftmost-innermost. At each step the reducer picks the leftmost operator application whose arguments are all numbers (the focus) and rewrites it:

  • eval - a primitive operator (no definition), or an operator the caller chose not to unfold, is replaced by its computed value;
  • expand - a defined operator is replaced by the body of the branch whose condition holds, with the parameters substituted by the argument values;
  • undefined - a branch condition compared NaN, or no branch matched: the focus becomes NaN (docs/reference/semantics.md section 4, rules 2-3).

Recursive operators simply expand again on the next steps, so the trace shows the recursion unfolding. The final number always equals the value the compiled function returns (tests check this).

Reducer

Unfolds definitions of operators in registry using runtime for primitives.

Granularity (how detailed a solution is):

  • expand decides which defined operators are unfolded; the others are known and computed in one step. The default unfolds every operator that has a definition; pass e.g. lambda op: op.recursive_layer >= 2 to treat layers 0 and 1 as known.
  • max_depth limits how deep unfolding goes: an application produced by max_depth unfoldings is computed in one step. max_depth=1 unfolds only the operators written in the expression itself.

A one-step computation of a defined operator is an eval step like a base operation; its value is checked like any other step (opulse.verify.verify_trace).