Skip to content

ltm: cyclic_orderings' (m-1)!/2 mirror-skip rationale is incorrect; cross-agg loop count is arbitrary #676

Closed

Description

@bpowers

Summary

cyclic_orderings (src/simlin-engine/src/db/ltm/loops.rs, ~line 1118; also referenced by MAX_CROSS_AGG_LOOPS doc at ~line 1041 and the call site in recover_cross_agg_loops at ~line 1351) emits (m-1)!/2 directed cycles per disjoint m-petal subset, with a doc comment justifying the /2 by claiming mirror reversals are skipped because "a directed cycle and its reverse share a score." A 2026-06-02 design review found that rationale is mathematically incorrect, and that the loop count is internally inconsistent against either of its two plausible goals.

This is a follow-up critique of the resolution of the now-closed #515 (LTM arrays hardening Phase 5; epic #488 line 58 records the cyclic_orderings(m) -- (m-1)!/2 for m>=3, mirror reversals skipped" design). #515 itself was about the MAX_AGG_PETALS cap and per-subset (vs per-ordering) under-enumeration; this issue is specifically about the new cyclic_orderings enumeration that landed to fix it.

The bug in the rationale

The involution actually applied in cyclic_orderings is petal-SEQUENCE reversal with each petal still traversed FORWARD: [0, p1, .., p_{n-1}] -> [0, p_{n-1}, .., p1] (the comment at ~line 1128 even says this). That is NOT the edge-reverse of the kept ordering:

  • The genuine edge-reverse of a directed cycle traverses each petal backward, and those reverse edges are not even present in the element graph.
  • So the skipped orderings are distinct directed circuits, not the reverses of the kept ones. The stated justification ("a directed cycle and its reverse share a score") does not apply to the orderings actually being dropped.

Deeper: every cyclic ordering of a fixed petal subset shares one score

For a fixed petal subset, every cyclic ordering produces the same edge multiset: each petal contributes the same agg->head / internal / tail->agg edges regardless of its position in the concatenation. The loop score is a commutative product over that edge multiset, so all orderings share a single loop_score. Therefore the count is inconsistent with both intents:

  • For loop identity (distinct directed elementary circuits): the truth is (m-1)!. The current (m-1)!/2 under-counts by half for m>=3.
  • For distinct loop scores: the truth is 1. The current (m-1)!/2 over-counts -- it mints (m-1)!/2 redundant loop IDs with byte-identical dominance profiles.

The test cross_agg_loop_recovery_four_petals_enumerates_cyclic_orderings (src/simlin-engine/src/db/ltm_unified_tests.rs, ~line 2975) confirms it currently produces 3 distinct four-petal loops that all share one score.

Why it matters

  • Severity: minor. Dominance analysis is unaffected -- the variants carry identical scores, so rankings/post-sim normalization are correct.
  • The comment is actively misleading about why /2 is applied (it cites edge-reversal symmetry that does not hold).
  • The redundant loop IDs waste the MAX_CROSS_AGG_LOOPS = 256 budget: each disjoint subset consumes (m-1)!/2 budget slots for loops that are indistinguishable for dominance, so the budget is exhausted faster and genuinely-distinct petal subsets can be truncated earlier than necessary.

Component(s) affected

  • src/simlin-engine/src/db/ltm/loops.rs -- cyclic_orderings (~1118), its doc comment, MAX_CROSS_AGG_LOOPS doc (~1041), the call site in recover_cross_agg_loops (~1351).
  • src/simlin-engine/src/db/ltm_unified_tests.rs -- cross_agg_loop_recovery_four_petals_enumerates_cyclic_orderings (~2975) would change with the chosen fix.

Possible approaches

Decide the intent and make the count consistent with it, fixing the comment either way:

  1. Recommended: emit one representative per disjoint petal subset. Identical scores make the orderings indistinguishable for dominance, so a single loop per subset is sufficient and it frees MAX_CROSS_AGG_LOOPS budget for genuinely-distinct subsets. Replace cyclic_orderings(m) with "one canonical ordering."
  2. Or, if full directed-circuit identity is wanted, emit (m-1)! (all rotation classes, no mirror quotient) and correct the comment to drop the false edge-reversal justification.

Either way, rewrite the doc comment so it no longer claims the skipped orderings are edge-reverses sharing a score.

Discovery context

Identified during a 2026-06-02 design review of the #515 resolution (LTM arrays hardening Phase 5). Algebraic verification of the involution and the per-subset single-score property was done by hand and cross-checked against cross_agg_loop_recovery_four_petals_enumerates_cyclic_orderings.

Related: #515 (closed; the resolution this critiques), epic #488.

Activity

  1. added
    ltm
    on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions