Skip to content

Round the sums in a difference of powers of e, so tanh(10^7) returns - #2570

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
hyperbolic-of-a-large-argument
Nov 26, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
hyperbolic-of-a-large-argument

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2563.

ExpDifference (#2074) evaluates e^u - e^v as e^v (e^(u - v) - 1) for sinh, tanh and coth. It sized the result's residual with two additions taken without a context. Past the exponent range, that added 1 exactly to e^(10^7), an integer of four million digits, and the multiplication after it rounded that back down. The time grew with the argument. PeterO's arithmetic does not check the cancellation token, so work/limitcheck and work/compilesweep both ended their runs on it.

Both additions are now rounded in the working context.

.Evaled of 2.9.0 this branch
tanh(10^6) 1, 408 ms 1, 2 ms
tanh(10^7) 1, 18 s 1, 122 ms
tanh(-10^8) did not return in 60 s -1, 3 ms
coth(-10^7) -1, 14 s -1, 6 ms
sinh(10^7) +oo, 14 s +oo, 9 ms
e^(10^7) - 1, 1 - e^(-10^7) +oo and 1, 5 s each +oo and 1, 5 and 16 ms

Twenty-seven inputs were compared with master to 60 characters: the hung ones, small differences (sinh(10^(-60)), sinh(10^(-20)), e^(1500 + 10^(-60)) - e^1500), and arguments from 999 to 2400, some of them complex. Every value matched except the rows that did not return before.

The new test fails without the fix: the three 10^8 cases do not return within 60 s.

Local checks:

  • the suite: 21,513 passed;
  • the MCP, Terminal, Interactive and F# suites;
  • AOT: 83 passed;
  • all nine harnesses, with canoncheck, confluence and the Modenov corpus matching their baselines;
  • the solver cross-checks and scalecheck: identical to master except timings.

🤖 Generated with Claude Code

…2563)

ExpDifference, which evaluates e^u - e^v as e^v (e^(u - v) - 1) for sinh,
tanh and coth (#2074), sized its residual with two additions taken without a
context. Past the exponent range that added 1 exactly to e^(10^7), an integer
of four million digits, and the multiplication after it rounded that back.
The time grew with the argument: tanh(10^7) took 18 s on 2.9.0, tanh(10^8)
did not return in 60 s, and PeterO's arithmetic does not observe the
cancellation token, so limitcheck and compilesweep both ended on it.

Both additions are now rounded in the working context. Every hung row returns
in milliseconds with the value it had where it returned; small differences
(#2074) and arguments from 999 to 2400 evaluate exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.71%. Comparing base (482e3e5) to head (5f4a391).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2570      +/-   ##
==========================================
- Coverage   86.73%   86.71%   -0.03%     
==========================================
  Files         344      344              
  Lines       74833    74833              
  Branches    21837    21837              
==========================================
- Hits        64905    64889      -16     
- Misses       5361     5376      +15     
- Partials     4567     4568       +1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.21% <100.00%> (-0.03%) ⬇️
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 Δ
...uriMath/Core/Entity/Continuous/Number/Operators.cs 91.44% <100.00%> (ø)

... and 9 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
Rafael-SOWNet merged commit bd55f51 into master Nov 26, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 26, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the hyperbolic-of-a-large-argument branch November 26, 2026 21:35
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.

sinh, tanh and coth of a large argument never return, and ignore cancellation: tanh(10^7)

1 participant