Repository navigation
spec(tla): exact-arithmetic AVERAGE model; replay checks pool value - #1692
Merged
Merged
Conversation
…s pool VALUE AVERAGECorrect.tla computed the average cost with integer division (\div), which made the pool value model-inexact — the behavior replay could only check the units abstraction. The model now tracks the pool value as an exact rational valueNum/valueDen (GCD-normalized, opCount-bounded), with reduction as value' = value * (t - u) / t. Exactness admits an invariant the integer model could not state: ZeroUnitsZeroValue — full liquidation empties the pool EXACTLY. TLC checks all six invariants over 1,354 states. - Corpus regenerated: 3,584 behaviors (was 1,500) covering the exact model's full transition graph. - The replay now asserts pool-value conformance: impl value (28-digit Decimal) vs the model's exact num/den, within a 1e-12 tolerance — ~17 orders above accumulated Decimal rounding and ~7 below the smallest genuine conformance discrepancy at these bounds. Units stay exact. - Generator derive updated for the rational state (add-cost recovered exactly from the numerator delta; denominator invariance asserted). All 3,584 behaviors conform — the #1444 AVERAGE-pool fix is now value- verified exhaustively up to the model bound, not just units-verified. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR upgrades the AVERAGECorrect TLA+ spec from integer-division modeling to an exact rational (valueNum/valueDen) model so pool-value conformance can be replay-checked (in addition to unit totals), and updates the behavior generation + Rust replay harness accordingly.
Changes:
- Reworks
spec/tla/AVERAGECorrect.tlato track pool value as a normalized rational and adds invariants enabled by exact arithmetic (e.g.,ZeroUnitsZeroValue). - Updates the TLC config (
AVERAGECorrect.cfg) and documentation (RUST_MAPPING.md) to reflect the new invariants and expanded replay corpus. - Updates the behavior corpus derivation (
scripts/tla-behaviors.py) and the Rust replay test to assert value conformance against the model’s rational state.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/tla/RUST_MAPPING.md | Updates the spec coverage table to reflect exact-rational AVERAGE modeling and the larger replay corpus. |
| spec/tla/AVERAGECorrect.tla | Switches AVERAGE pool value tracking to exact rational arithmetic and adds/updates invariants. |
| spec/tla/AVERAGECorrect.cfg | Adds MaxOperations and updates the invariant set to match the new model. |
| scripts/tla-behaviors.py | Adjusts AVERAGE behavior derivation/state schema to emit valueNum/valueDen for replay. |
| crates/rustledger-core/tests/tla_behavior_replay.rs | Extends AVERAGE replay to validate pool value vs model rational (with tolerance). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-07-02)
What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Last item from the FV improvement menu:
AVERAGECorrect.tla's integer\divmade the pool value model-inexact, so the 1,500-behavior replay could only check units. Now:Exact rational model
Pool value =
valueNum / valueDen(GCD-normalized,opCount-bounded); reduction is exactlyvalue·(t−u)/t. Exactness admits a new invariant the integer model could not state:ZeroUnitsZeroValue— full liquidation empties the pool exactly. TLC: 1,354 states, all six invariants hold.Value-checked replay
Corpus regenerated: 3,584 behaviors (was 1,500). The replay now asserts pool-value conformance — implementation (28-digit
Decimal) vs the model's exactnum/den, within a1e-12tolerance (~17 orders above accumulated Decimal rounding, ~7 below the smallest genuine discrepancy at these bounds). Units remain exact. All 3,584 behaviors conform — the #1444 AVERAGE-pool fix is now value-verified exhaustively up to the model bound.Machinery
Generator derive updated for rational state (add-cost recovered exactly from the numerator delta, denominator invariance asserted); lockstep guard covers the new corpus automatically; this PR triggers the TLA workflow, so model-check + corpus lockstep + trace validation all run on it.
Verified: TLC clean · 7/7 replay suites · generator self-test · clippy
-D warnings+ fmt clean.🤖 Generated with Claude Code