Repository navigation
Read exp(x) as a power of e rather than as a product (#730) - #731
Merged
Merged
Conversation
`exp` is the ordinary name for the exponential function everywhere else
-- sympy, Mathematica, MATLAB, numpy -- and the grammar did not have it.
It did not fail. It fell through to implicit multiplication, the rule
that lets `a(b + c)` mean `a * (b + c)`, and came out as the product of
an undeclared variable named `exp` with the argument. Nothing was said
about it, so the misreading propagated into an answer that looked like
one: `exp(x) - 3x = 0` answered `{ 0 }`, which is a root of `exp * x -
3x` and of nothing else. The equation has two real roots, near 0.6191
and 1.5121.
That is the same shape as the arcsinh case -- a name that looks like a
function, is not one, and is quietly absorbed by implicit
multiplication. The difference is that arcsinh is a misnomer and was
right to refuse, whereas exp names something the library already has.
So it maps to `MathS.Pow(MathS.e, arg)` rather than to a new node. A
distinct Expf would have to be taught differentiation, integration and
simplification over again; a power of e already has all of it, which is
why `exp(x) * exp(y)` comes out `e^(x + y)` with nothing further added.
Only the exact name followed by a bracket is taken as the function, as
for every other function in the grammar: `expr(x)`, `expo(x)` and a bare
`exp` are the products they were.
Measured: `exp(x) - 3x = 0` from `{ 0 }` to both real roots. Parser
regenerated with antlr-4.13.1 and the post-processor; regenerating the
unmodified grammar first gave an empty diff, so the only change is the
rule. Full suite 4866 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.
Closes #730.
expis the ordinary name for the exponential function everywhere else — sympy, Mathematica, MATLAB, numpy — and the grammar did not have it.What was wrong
It did not fail. It fell through to implicit multiplication, the rule that lets
a(b + c)meana * (b + c), and came out as the product of an undeclared variable namedexpwith the argument:Nothing was said about it, so the misreading propagated into an answer that looked like one:
0is a root ofexp * x - 3xand of nothing else. The equation has two real roots, near 0.6190612867 and 1.5121345517. A wrong answer to a misread question, rather than a refusal to answer an unsupported one.This is the same shape as the
arcsinhcase fixed earlier. The difference is thatarcsinhis a misnomer and was right to refuse, whereasexpnames something the library already has.The fix
One grammar rule, mapping to
MathS.Pow(MathS.e, arg)rather than to a new node. A distinctExpfwould have to be taught differentiation, integration and simplification over again; a power ofealready has all of it — which is whyexp(x) * exp(y)comes oute ^ (x + y)with nothing further added.Only the exact name followed by a bracket is the function, as for every other function in the grammar:
expr(x),expo(x),aexp(x)and a bareexpare the products they were, and a test pins that.Measured
exp(x)exp * xe ^ xexp(1)evaluatedexp2.71828…exp(x) - 3x = 0{ 0 }d/dx exp(2x)2 * exp2 * e ^ (2 * x)Parser regenerated with the committed
antlr-4.13.1-complete.jarand theAntlrPostProcessorReplacePublicWithInternalstep. Regenerating the unmodified grammar first produced an empty diff, so the toolchain here reproduces the committed files and the only change is the new rule.Full suite 4866 passed / 0 failed, F# 130/130, 117-problem corpus 112/117 with 0 wrong, 0 error, 0 timeout.
🤖 Generated with Claude Code