Repository navigation
Read log10 and log2 as logarithms rather than as powers (#733) - #734
Merged
Merged
Conversation
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>
This was referenced Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)andlog(2, x). Nothing was missing but the spelling.What was wrong
What happened instead is worse to read than an ordinary implicit product.
log10lexes as the variablelogfollowed by10, andx2meansx^2by design, so the result is a power of an undeclared variable:Silently, in both cases.
The fix
Two grammar rules, mapping to
MathS.Log(10, arg)andMathS.Log(2, arg)— so they are the same function as the spelling that already worked, rather than merely each being defined.log10(x)andlog(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:
log2xlog ^ 2 * xlog10log ^ 10logx(y)logx * ylog3(x)log ^ 3 * xThe one- and two-argument
logare 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,erfand 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
log10(100)log ^ 10 * 1002log2(8)log ^ 2 * 83log10(1000)log ^ 10 * 10003log2(1024)log ^ 2 * 102410Parser regenerated with the committed
antlr-4.13.1-complete.jarand theAntlrPostProcessorReplacePublicWithInternalstep; 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