Skip to content

A logarithm to base 0 has no value - #2258

Open
Rafael-SOWNet wants to merge 2 commits into
masterfrom
a-logarithm-to-base-0-has-no-value
Open

Rafael-SOWNet wants to merge 2 commits into
masterfrom
a-logarithm-to-base-0-has-no-value

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

log(0, x) evaluated to 0 for a positive x, and compiled to (-0, -0). Both took it as ln(x) / ln(0), which is ln(x) / (-oo). But 0 is not a base: no power of it is anything but 0, and Logf's own condition already excluded it. An exact zero base is now NaN in Number.Log, ComplexBranches.Log and the LINQ compiler's double and float Log. A base that is small but not 0 keeps its logarithm, so the check is for an exact zero, not IsZero's tolerance.

2.6.0 master this branch
"log(0, 2)".ToEntity().Evaled 0 0 NaN
"log(0, 1)".ToEntity().Evaled 0 NaN
"log(x, 2)".ToEntity().Compile("x").Call(0) (-0, -0) (-0, 0) (NaN, 0)

Over double, Math.Log already gave NaN except for an antilogarithm of 1, where it gave -0.

The second commit is from BoundCheck in CI. log(b, 1) simplified to 0 provided not b = 1, which is 0 at b = 0. It now provides not b = 0 as well, as log's condition does, and BoundCheck has 0 disagreements again.

LogarithmToBaseZeroTest: seven cases fail on master, and six pass on both (three are logarithms to other bases). Suite 18185 passed. The F# wrapper suite, the Mcp, Terminal and InteractiveWrapper suites and the AOT smoke test pass. Found by work/domaincheck.

Fixes #2255.

🤖 Generated with Claude Code

log(0, 2) evaluated to 0, and log(x, 2) compiled to (-0, -0) at 0.
Both took it as ln(x) / ln(0), which is ln(x) / (-oo). But 0 is not a
base, since no power of it is anything but 0, and Logf's condition
already excluded it: not x = 0 and not x = 1.

Number.Log, ComplexBranches.Log and the LINQ compiler's double and
float Log now answer an exact zero base with NaN. Over double, Math.Log
already gave NaN, except for an antilogarithm of 1, where it gave -0.
A base that is small but not 0 keeps its logarithm, so the test is for
an exact zero, not IsZero's tolerance.

LogarithmToBaseZeroTest takes six logarithms to base 0, evaluated and
simplified, and four compiled by FastExpression, the LINQ compiler over
Complex and over double. Seven fail on master. Three logarithms to other
bases pin what has not changed, 10^(-100) among them.

Found by work/domaincheck.

Fixes #2255.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Oct 30, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.72%. Comparing base (b035ed1) to head (e3ffadc).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2258   +/-   ##
=======================================
  Coverage   86.71%   86.72%           
=======================================
  Files         310      310           
  Lines       67790    67799    +9     
  Branches    19666    19670    +4     
=======================================
+ Hits        58786    58796   +10     
+ Misses       4892     4891    -1     
  Partials     4112     4112           
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.27% <93.33%> (+<0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

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 90.79% <100.00%> (+0.03%) ⬆️
...gouriMath/Functions/Compilation/ComplexBranches.cs 100.00% <100.00%> (ø)
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 87.01% <100.00%> (+0.03%) ⬆️
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 73.97% <50.00%> (ø)

... and 4 files with indirect coverage changes

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

log(b, 1) simplified to 0 provided not b = 1, which is 0 at b = 0.
With log(0, 1) now NaN, BoundCheck found that disagreement, and the
fold now provides not b = 0 as well, as log's condition does.
TheLogarithmOfOneExcludesTheBase0 takes the simplification at 0, 1
and 2. BoundCheck has 0 disagreements again.

Part of #2255.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

A logarithm to base 0 is 0

1 participant