From 3508537489c0b1fee4707447b3ccac5ee188682b Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Sep 2026 17:47:02 +0000 Subject: [PATCH 1/2] compass(ir): the grouped price reuses a body price, it does not multiply it GroupingEvidence documented the free-grouping condition as "pricing the body once and multiplying". Multiplying re-associates the sum, so it is not the arithmetic the grouped form performs: the grouped price is the same prices, in the same order, added the same way, over a body price obtained once and reused. The three stacks measured against their recorded prices reproduce under reuse and under multiplication in none: eight identical layers (3.2e-05 s multiplied against 3.200000000000001e-05 s recorded), a four-block pattern repeated twenty times (0.00036 against 0.0003600000000000009), and six instances of 0.1 s (0.6000000000000001 against 0.6). Docstring only; no behaviour, no subclass and no test changes. Co-Authored-By: Claude Opus 5 (1M context) --- atom/compass/ir/nodes.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/atom/compass/ir/nodes.py b/atom/compass/ir/nodes.py index bdf677df25..e7345e6046 100644 --- a/atom/compass/ir/nodes.py +++ b/atom/compass/ir/nodes.py @@ -479,8 +479,16 @@ class GroupingEvidence(abc.ABC): """What was compared before a repeat was allowed to replace a sequence. Collapsing *n* instances into one body is only free if pricing the body once - and multiplying gives what pricing the instances separately would give. The - two subclasses are the two things that can be compared: the instances' + and *reusing* that price for every instance gives what pricing the instances + separately would give -- the same prices, in the same order, added the same + way. Multiplying is a different sum, because it re-associates. Reuse + reproduces the recorded price exactly in all three shapes measured and + multiplying in none of them: eight identical layers, 3.2e-05 s multiplied + against 3.200000000000001e-05 s recorded; a four-block pattern repeated + twenty times, 0.00036 against 0.0003600000000000009; six instances of 0.1 s, + 0.6000000000000001 against 0.6. + + The two subclasses are the two things that can be compared: the instances' structure, and their price. A repeat takes one of them, mandatorily. Abstract, and not merely a base class, because an instance of this by itself From ef38f5c31cd0fde498dae2dd497be9b2ed21c588 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Sep 2026 18:23:36 +0000 Subject: [PATCH 2/2] compass(ir): say the reuse is of the body's prices, plural Round 1 on #83 found the correction itself one granularity short. "pricing the body once and reusing that price" is singular: read literally it means one number per body, folded count times. Measured against prove_grouping on compass/ir-4-grouping-rule at 3549d2c49, that reading reproduces neither of the two multi-operator shapes this docstring cites, and in both it lands on exactly the number the docstring attributes to multiplying -- fold([4e-06] * 8) and 8 * 4e-06 are both 3.2e-05 against 3.200000000000001e-05 recorded, and both are 0.00036 against 0.0003600000000000009. It does reproduce the six-instance shape, 0.6, because a single-operator body has no internal order and reusing its price list and reusing its total are the same computation there. That shape cannot separate the two readings; the other two can, and they refuse it. What is reused is the body's sequence of per-operator prices, re-emitted in order once per instance. The docstring now says that, in the same terms the grouping rule states it in: prices obtained once and reused, plural. Docstring only. No behaviour, no test, no public name changes. Co-Authored-By: Claude Opus 5 (1M context) --- atom/compass/ir/nodes.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/atom/compass/ir/nodes.py b/atom/compass/ir/nodes.py index e7345e6046..a83eba39ff 100644 --- a/atom/compass/ir/nodes.py +++ b/atom/compass/ir/nodes.py @@ -478,10 +478,12 @@ def value_at(self, position: int) -> int: class GroupingEvidence(abc.ABC): """What was compared before a repeat was allowed to replace a sequence. - Collapsing *n* instances into one body is only free if pricing the body once - and *reusing* that price for every instance gives what pricing the instances - separately would give -- the same prices, in the same order, added the same - way. Multiplying is a different sum, because it re-associates. Reuse + Collapsing *n* instances into one body is only free if pricing the body's + operators once and *reusing* those prices for every instance gives what + pricing the instances separately would give -- the same prices, in the same + order, added the same way. What is reused is the body's sequence of + per-operator prices, re-emitted in order once per instance, and not a body + total. Multiplying is a different sum, because it re-associates. Reuse reproduces the recorded price exactly in all three shapes measured and multiplying in none of them: eight identical layers, 3.2e-05 s multiplied against 3.200000000000001e-05 s recorded; a four-block pattern repeated