Skip to content

A constant is worth the current precision's digits, and a cached evaluation is recomputed when the precision context has changed - #1368

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
precision-epoch
Sep 16, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
precision-epoch

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #1367: pi and e were worth the digits of whichever precision context was set when Variable.ConstantList was built, and an entity's cached Evaled survived a change of MathS.Settings.DecimalPrecisionContext. So pi at 300 digits after an evaluation at 100 came back with 100, e^x at 300 came back correct to 100 (its base no longer equalled the cache's e, so Pow fell from "the exponential of the power" to a logarithm of the 100-digit base and an exponential), and a held expression evaluated at 100 digits and again at 500 answered from the first.

Two changes:

  • ConstantList maps a name to Func<Complex> — () => MathS.DecimalConst.pi — so Constant.Value is the current context's digits every time. The registry's shape (a name is a constant exactly when it is a key) is unchanged.
  • An evaluation epoch (Convenience.EvaluationEpoch, a static counter): the precision setting advances it on every Set and on every scope's Dispose (a Setting<T> opts in with AdvancesEvaluationEpoch, and only DecimalPrecisionContext does). Entity.Evaled records the epoch it was computed at beside its lazy slot and resets the slot when it has moved. The counter is one for every thread — settings are AsyncLocal, so a change on another flow costs a recomputation there, never a stale value.

Cost: one int per entity and one volatile read per Evaled. The gate's allocation rows move by +0.1% to +1.0% (8 bytes × the entities a row builds), all inside its band, so the baseline stands; time flat. The performance log has the entry (the 2075th).

Tests: ConstantsAndCachedEvaluationsFollowThePrecision (pi and a held sin 1 + pi at 100 → 300 → 100 digits, the 300-digit pi pinned against mpmath) and EToAPowerAtAHigherPrecisionAfterALowerOne (300 digits of e^0.37000000000001234 pinned against mpmath); both fail on master.

Four suites green (11,349 / 134 / 18 / 41).

Part of #1338.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

…uation is recomputed when the precision context has changed

pi and e were worth the digits of whichever precision context was set
when Variable.ConstantList was built, and an entity's cached Evaled
survived a change of MathS.Settings.DecimalPrecisionContext: pi at
three hundred digits after an evaluation at a hundred came back with a
hundred, and e^x at three hundred came back correct to a hundred,
since its base no longer equalled the cache's e and the power fell to
a logarithm of the hundred-digit base and an exponential. A held
expression evaluated at a hundred digits and again at five hundred
answered from the first. The constant's value is looked up at the
moment of evaluation now, and the precision setting advances an
evaluation epoch on every Set and on every scope's end, which an
entity records beside its Evaled and compares on each read, so a
cached evaluation under another precision is recomputed. One int per
entity and one static read per evaluation; the gate's allocation rows
move by 0.1 to 1.0 per cent, inside its band, and the baseline stands.
The performance log has the entry.

Four suites green (11,349 / 134 / 18 / 41).

Closes #1367. Part of #1338.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet
Rafael-SOWNet merged commit 01fa27b into master Sep 16, 2026
31 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the precision-epoch branch September 16, 2026 01:33
Rafael-SOWNet added a commit that referenced this pull request Oct 9, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Rafael-SOWNet added a commit that referenced this pull request Oct 9, 2026
* Breaking-changes entries for #1828 to #1832 and #1374

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

* And for #1368, #1611 and #1517, each measured on 2.5.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

* And for #1289, #1312, #1315, #1377, #1380 and #1371, each measured on 2.5.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pi, e and a cached Evaled keep the digits of the first precision context they were evaluated under

1 participant