Skip to content

Keep an exact number past the working digits exact (#2615) - #2620

Merged
Rafael-SOWNet merged 4 commits into
masterfrom
exact-past-precision-2615
Nov 28, 2026
Merged

Rafael-SOWNet merged 4 commits into
masterfrom
exact-past-precision-2615

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

A number that evaluation had rounded was taken as an exact value in three places. This PR fixes all three, plus one test that had depended on the first.

  1. Real.Create read a rounded decimal as an integer. At 100 digits, a product past about 10^50 comes out with its last digits rounded to 0. Simplify then used that integer in place of the exact expression.
    • Fix: a value is downcast only where the working digits reach the downcasting tolerance below its point, that is, its magnitude is under tolerance × 10^precision.
    • Machine numbers are exempt, because all their digits are exact.
  2. The guards against a zero or an infinity made only by rounding (CannotBeZero, IsFiniteRoundedOntoAnInfinity) asked IsFinite. That reads a rational through the decimals, so 2^4000 and 2^3400 counted as not finite. As a result, 2^4000 * sqrt(2) simplified to +oo and sqrt(2) / 2^3400 to 0.
    • Fix: a rational now counts as finite however large.
    • An operand written exactly whose value is a decimal, such as sqrt(2), also counts as finite.
  3. A power with an exact base and a huge decimal exponent is now left written. This matches a whole exponent of that size. 46655^(e^(e^6)) had reached that arm only because e^403 was taken for an integer, and AnExactPowerTooLargeToBuildTest pins it.
simplified master / 2.10.0 this branch
2^340 * sqrt(2) 3167477390…7832751217000 2239744742…607115776 * sqrt(2)
sqrt(2)^800 / 2^400 1231312693…/1231312693…, not 1 1
10^200 * pi / 10^199 7853981633…/2500000000… 10 * pi
e^700 1014232054… followed by about 200 zeros e ^ 700
2^4000 * sqrt(2) +oo 1318204093… * sqrt(2)
2^(-20000) * sqrt(2) 0 sqrt(2) / 3980276840…
integral(exp(x), x, 0, 300) 1942426395…41999…9 e ^ 300 - 1
integral(exp(-x^2) * 10^100, x, -oo, +oo) 1772453850… 10^100 * sqrt(pi)

Blast radius. I diffed 79 answers with large constants (eval, simplify, solve, integrals, limits, sums, comparisons) against master.

  • Every change is one of the rows above, or eval now printing a Real decimal (for example 9.99…E+149) where it used to print a rounded integer.
  • Nothing that was right on master changed.
  • Exact large-integer arithmetic is unchanged: sqrt(2)^400 = 2^200, 2^4000 * 3 - 2^4000 * 2 = 2^4000.

Tests

  • The new test fails 8 of 11 cases on master.
  • The first full-suite run found AMachineNumberIsMadeAsBeforeTest (4 failures, fixed by the machine-number exemption) and AnExactPowerTooLargeToBuildTest (fixed by item 3).
  • The second full run: 21692 passed, and 1 failure, DocCommentPlacementTest. That came from a summary I had inserted inside another member's doc comment. I moved it and reran that test and the power test (43 passed). I did not rerun the full suite after that comment-only fix.
  • The library builds with 0 errors for every target framework.
  • The harnesses run in the queued chain.

The BREAKING-CHANGES.md entry is included.

Closes #2615.

🤖 Generated with Claude Code

At a hundred digits, a product past about 10^50 evaluated to a decimal
whose last digits were rounded to 0. Real.Create read that decimal as an
integer, and since an Integer is exact, InnerSimplified and Simplify put it
in place of the exact expression: 2^340 sqrt(2) became a 103-digit
integer, and sqrt(2)^800 / 2^400 a fraction that is not 1. A value is now
downcast only where the working digits reach the downcasting tolerance
below its point, that is, below the tolerance times ten to the precision. A machine number is
exempt: all of its digits are exact.

Past the decimals' exponent range, a rational reads as not finite through
IsFinite. The guards that keep an infinity or a zero made only by rounding
from being taken as an exact value asked IsFinite of their operands, so
2^4000 sqrt(2) simplified to +oo and 2^(-20000) sqrt(2) to 0. They now
count a rational as finite however large, and an operand written exactly
whose value is a decimal, such as sqrt(2), as finite too.

An exact base to a decimal exponent past the size a power is built to is
left written, as it is for a whole exponent that large. 46655^(e^(e^6))
had reached that arm only because e^403 was taken for an integer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.72%. Comparing base (a3b3d25) to head (972c463).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ty/Continuous/Entity.Continuous.Real.Definition.cs 88.88% 1 Missing and 1 partial ⚠️
...uriMath/Functions/Evaluation/Evaluation.Classes.cs 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2620      +/-   ##
==========================================
+ Coverage   86.70%   86.72%   +0.02%     
==========================================
  Files         345      345              
  Lines       75428    75559     +131     
  Branches    22034    22083      +49     
==========================================
+ Hits        65397    65530     +133     
+ Misses       5418     5410       -8     
- Partials     4613     4619       +6     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.22% <91.17%> (+0.02%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 89.16% <100.00%> (+0.21%) ⬆️
...uriMath/Functions/Evaluation/Evaluation.Classes.cs 85.64% <85.71%> (+0.60%) ⬆️
...ty/Continuous/Entity.Continuous.Real.Definition.cs 89.24% <88.88%> (-0.23%) ⬇️

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Rafael-SOWNet and others added 2 commits November 28, 2026 13:26
Every number the parser reads is downcast, and the check built ten to
the precision and a product for each: CI's allocation gate measured
ParseEasy 7.1% and ParseHard 3.6% above the baseline. A magnitude a
digit or more either side of the bound is now decided in doubles, which
allocate nothing; only one near it is compared exactly. Measured over
2000 parses: 19656 -> 18456 B/op and 61608 -> 60100 B/op, against 18360
and 59478 on master 00813f6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Rafael-SOWNet

Copy link
Copy Markdown
Member Author

Blocked before merge. Merged with master, this branch fails Issue2446_EveryRowOfASystemWithACancellingCoefficientIsASolution(n: 70) locally and on CI (ubuntu). The system y^2 - 2 = 0, x^2 + (P - Q y) x - 3 = 0 with the 70th Pell numbers comes back with 3 rows, where it must have 4 or decline. The missing row is the small root at y = -sqrt(2), x ≈ 4.8e-27. The branch alone passes, and so does the branch merged with #2608 or #2616. Merged with #2612's c31e25e it fails. Keeping P + Q sqrt(2) exact opens a path in the system solver that loses the root. The fix goes in the solver, as its own PR, and this one waits for it.

Also fixed on the branch: CI's allocation gate failed on ParseEasy (+7.1%) and ParseHard (+3.6%), because the working-digits check built 10^precision for every number parsed. It now decides in doubles first. Over 2000 parses that is 18,456 and 60,100 B/op, against 18,360 and 59,478 on master.

Rafael-SOWNet added a commit that referenced this pull request Nov 28, 2026
y^2 - 2 = 0, x^2 + (P - Q y) x - c = 0, with (1 + sqrt(2))^n = P + Q sqrt(2),
has four solutions. Since #2612 the eliminator also solves for y from the
second equation, through ((x^2 + P x - c)/(Q x))^2 = 2, a quartic in x
with coefficients near Q^2. At n = 90 the small root of that quartic,
exact, evaluated to a residual of -0.042 against terms of 3 at a hundred
digits, and no interval enclosure of it could be worked out. It was
dropped as spurious, and the system was answered with three rows. Master
answers three rows of four at n = 80, 90, 100 and 120 for several c.
2.10.0 declined all of them. Merged with #2620, which keeps P + Q sqrt(2)
exact, the same happens at n = 70 in the system's own row check: the row's
residual evaluates to -7.2e-21, while its enclosure leaves zero out by
only about 6e-53.

StatementSolver.Weigh now reads such a residual as rounding having
reached the root, and whether it is one cannot be told. That is so where
an enclosure leaves zero out but is within what IsEvidenceAgainst lets
rounding leave, and where no enclosure can be worked out and twice the
digits evaluate the residual to something else. A one-variable solve
then declines the equation, as ShownNotARoot already did, and a system
declines in RowsThatHold. A residual that more digits leave where it was
is still evidence, so an extraneous root is still dropped. Every case
measured is now four rows or a decline, on master and on master merged
with #2620.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Rafael-SOWNet
Rafael-SOWNet merged commit e095094 into master Nov 28, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 28, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the exact-past-precision-2615 branch November 28, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

An exact integer times an irrational past 10^100 simplifies to a rounded integer, and past 10^1000 to +oo

1 participant