Skip to content

Read log10 and log2 as logarithms rather than as powers (#733) - #734

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
feat/log10-and-log2
Aug 5, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
feat/log10-and-log2

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Addresses the defect half of #733.

Both names are standard in C, Python, numpy and MATLAB, and the grammar did not have them — while having both functions already, as log(x) and log(2, x). Nothing was missing but the spelling.

What was wrong

What happened instead is worse to read than an ordinary implicit product. log10 lexes as the variable log followed by 10, and x2 means x^2 by design, so the result is a power of an undeclared variable:

log10(100)  =>  log ^ 10 * 100     // the answer is 2
log2(8)     =>  log ^ 2 * 8        // the answer is 3

Silently, in both cases.

The fix

Two grammar rules, mapping to MathS.Log(10, arg) and MathS.Log(2, arg) — so they are the same function as the spelling that already worked, rather than merely each being defined. log10(x) and log(x) parse to one tree, and a test asserts that rather than asserting each value separately.

Only the exact name followed by a bracket is the function, as for every other function in the grammar:

written parses as
log2x log ^ 2 * x implicit power, unchanged
log10 log ^ 10 unchanged
logx(y) logx * y implicit product, unchanged
log3(x) log ^ 3 * x unchanged — only 10 and 2 are named

The one- and two-argument log are untouched: log(100) is 2, log(2, 8) is 3, log(3, 81) is 4.

What is deliberately not here

The rest of the #733 sweep — floor, ceil, round, min, max, gcd, lcm, erf and others that silently become products — names functions the library does not have. Those are feature requests rather than misreadings, and #733 stays open for them.

Measured

before after
log10(100) log ^ 10 * 100 2
log2(8) log ^ 2 * 8 3
log10(1000) log ^ 10 * 1000 3
log2(1024) log ^ 2 * 1024 10

Parser regenerated with the committed antlr-4.13.1-complete.jar and the AntlrPostProcessorReplacePublicWithInternal step; regenerating the unmodified grammar first gives an empty diff, so the only change is the two new rules.

Full suite 4889 passed / 0 failed, F# 130/130, corpus 112/117 with 0 wrong, 0 error, 0 timeout.

🤖 Generated with Claude Code

Both are standard in C, Python, numpy and MATLAB, and the grammar did
not have them -- while having both functions already, as `log(x)` and
`log(2, x)`. Nothing was missing but the spelling.

What happened instead is worse to read than an ordinary implicit
product. `log10` lexes as the variable `log` followed by `10`, and `x2`
means `x^2` by design, so `log10(100)` came out as `log^10 * 100`: a
power of an undeclared variable, silently, where the answer is 2.

Two rules, mapping to `MathS.Log(10, arg)` and `MathS.Log(2, arg)`, so
they are the same function as the spelling that already worked rather
than merely each defined -- `log10(x)` and `log(x)` parse to one tree.

Only the exact name followed by a bracket is the function, as for every
other function in the grammar. Without the bracket `log2x` is still the
implicit power `log^2 * x` and `log10` still `log^10`; `logx(y)` and
`log3(x)` are still the implicit products they were. Tests pin all of
them, and the one- and two-argument `log` are untouched.

This is the defect half of #733. The rest of that sweep -- `floor`,
`ceil`, `round`, `min`, `max`, `gcd`, `lcm` and others that silently
become products -- names functions the library does not have, so those
are feature requests rather than misreadings and are left there.

Measured: `log10(100)` from `log^10 * 100` to 2, `log2(8)` from
`log^2 * 8` to 3, `log10(1000)` 3, `log2(1024)` 10. Parser regenerated
with antlr-4.13.1 and the post-processor. Full suite 4889 passed / 0
failed, F# 130/130, corpus 112/117 with 0 wrong, 0 error, 0 timeout.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Rafael-SOWNet
Rafael-SOWNet merged commit 318ac9f into master Aug 5, 2026
24 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the feat/log10-and-log2 branch August 5, 2026 14:07
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.

1 participant