Skip to content

Commit 2af815c

Browse files
Rafael-SOWNetclaude
andcommitted
The names of functions to come are refused by name
An unknown name followed by a bracket is read as a product, so zeta(2) was zeta * 2 and simplified to 2 * zeta, silently. #2182 registers the functions the library is to have, named by what a mathematician calls them, and their long names are now refused until each is implemented, as trunc is: zeta, riemannzeta and hurwitzzeta, lambertw and productlog, mobius and moebiusmu, divisorsigma, primenu, primeomega, primepi, harmonicnumber, catalannumber, multinomial, fallingfactorial and factorialpower, risingfactorial, forwarddifference, laplacian, jacobian and hessian. Names that will not be functions are refused with the spelling to use, as NN is with ZZ+ and ZZ*. heaviside's value at 0 is 0, 1/2 or 1 by source, so it points to iverson(x > 0), iverson(x >= 0) and (1 + sgn(x))/2, and unitstep to iverson(x >= 0). isprime(n) is n in PP, fractionalpart(x) is x mod 1, quotient(a, b) is floor(a / b), the double factorial is to be the postfix n!!, and pochhammer is the rising factorial to some authors and the falling one to others. Each name without a bracket is still a variable, and short names such as beta and norm are still read as products. Part of #2182. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 059513d commit 2af815c

11 files changed

Lines changed: 2116 additions & 999 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,26 @@ the right shape, written out or once its operations are carried out, throws `Inv
420420
| `"dot([1, 2], [3, 4])".ToEntity()` | throws `UnhandledParseException` | `1 * 3 + 2 * 4` |
421421
| `"resultant(x^2 - 1, x - a, x)".ToEntity()` | throws `UnhandledParseException` | `a ^ 2 - 1` |
422422

423+
### The names of functions to come are refused by name
424+
425+
**Not silent: these names followed by a bracket now throw `UnrecognizedFunctionParseException` where they were read as
426+
products.** An unknown name followed by a bracket is a product, so `zeta(2)` was `zeta * 2` and simplified to
427+
`2 * zeta`. The long names of the functions the library is to have are refused until each is implemented, as `trunc`
428+
is: `zeta`, `riemannzeta`, `hurwitzzeta`, `lambertw`, `productlog`, `mobius`, `moebiusmu`, `divisorsigma`, `primenu`,
429+
`primeomega`, `primepi`, `harmonicnumber`, `catalannumber`, `multinomial`, `fallingfactorial`, `factorialpower`,
430+
`risingfactorial`, `forwarddifference`, `laplacian`, `jacobian` and `hessian`. Names that will not be functions,
431+
because what they mean differs between sources or is already written exactly, are refused with the spelling to use:
432+
`heaviside`, `unitstep`, `isprime`, `pochhammer`, `doublefactorial`, `factorial2`, `fractionalpart` and `quotient`.
433+
Each name without a bracket is still a variable, and short names such as `beta` and `norm` are still read as products
434+
([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
435+
436+
| Input | Was (2.6.0) | Now |
437+
|---|---|---|
438+
| `"zeta(s)".ToEntity()` | `zeta * s` | throws `UnrecognizedFunctionParseException` |
439+
| `"zeta(2)".ToEntity().Simplify()` | `2 * zeta` | throws `UnrecognizedFunctionParseException` |
440+
| `"isprime(7)".ToEntity()` | `isprime * 7` | throws `UnrecognizedFunctionParseException`: write `n in PP` |
441+
| `"heaviside(x)".ToEntity()` | `heaviside * x` | throws `UnrecognizedFunctionParseException`: write `iverson(x > 0)`, `iverson(x >= 0)` or `(1 + sgn(x))/2` |
442+
| `"divisorsigma(k, n)".ToEntity()` | throws `UnhandledParseException` | throws `UnrecognizedFunctionParseException` |
423443
### A subscript may have a subscript
424444

425445
**Not silent: what was a parse error is a name.** A name took at most one `_`, so `x_1_2` and `X_a_beta` were lexer

‎Sources/AngouriMath/Core/Antlr/AngouriMath.g‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ options
5656
$"there is no function {name}: AngouriMath has no {what}. It is refused by name " +
5757
$"rather than read as the product of a variable named {name} with its argument, " +
5858
$"which is what an unknown name followed by a bracket would otherwise mean");
59+
60+
// A name that will not be a function, because what it means is ambiguous or is already
61+
// written exactly another way, refused with the spelling to use, as NN is refused with ZZ+
62+
// and ZZ*. https://github.com/asc-community/AngouriMath/issues/2182
63+
static Entity NotAFunctionHere(string name, string instead)
64+
=> throw new UnrecognizedFunctionParseException(
65+
$"{name} is not a function in AngouriMath: {instead}. It is refused by name rather " +
66+
$"than read as the product of a variable named {name} with its argument");
5967
}
6068

6169
@namespace { Antlr }
@@ -658,6 +666,42 @@ atom returns[Entity value]
658666
between a missing function and a wrong answer. */
659667

660668
| 'trunc(' args = function_arguments ')' { $value = NotImplementedFunction("trunc", "rounding functions"); }
669+
/* Names of functions to come, reserved so that each is refused rather than read as a
670+
product until it is implemented: zeta(s) was zeta * s. Only names no one writes as a
671+
variable before a bracket; beta, norm, grad, div, curl and the other short ones are left
672+
as products until each lands. The names and their conventions are in
673+
https://github.com/asc-community/AngouriMath/issues/2182 */
674+
| 'zeta(' args = function_arguments ')' { $value = NotImplementedFunction("zeta", "Riemann or Hurwitz zeta function yet"); }
675+
| 'riemannzeta(' args = function_arguments ')' { $value = NotImplementedFunction("riemannzeta", "Riemann zeta function yet"); }
676+
| 'hurwitzzeta(' args = function_arguments ')' { $value = NotImplementedFunction("hurwitzzeta", "Hurwitz zeta function yet"); }
677+
| 'lambertw(' args = function_arguments ')' { $value = NotImplementedFunction("lambertw", "Lambert W function yet"); }
678+
| 'productlog(' args = function_arguments ')' { $value = NotImplementedFunction("productlog", "Lambert W function yet"); }
679+
| 'mobius(' args = function_arguments ')' { $value = NotImplementedFunction("mobius", "Mobius function yet"); }
680+
| 'moebiusmu(' args = function_arguments ')' { $value = NotImplementedFunction("moebiusmu", "Mobius function yet"); }
681+
| 'divisorsigma(' args = function_arguments ')' { $value = NotImplementedFunction("divisorsigma", "divisor function yet"); }
682+
| 'primenu(' args = function_arguments ')' { $value = NotImplementedFunction("primenu", "count of distinct prime factors yet"); }
683+
| 'primeomega(' args = function_arguments ')' { $value = NotImplementedFunction("primeomega", "count of prime factors with multiplicity yet"); }
684+
| 'primepi(' args = function_arguments ')' { $value = NotImplementedFunction("primepi", "prime-counting function yet"); }
685+
| 'harmonicnumber(' args = function_arguments ')' { $value = NotImplementedFunction("harmonicnumber", "harmonic numbers yet"); }
686+
| 'catalannumber(' args = function_arguments ')' { $value = NotImplementedFunction("catalannumber", "Catalan numbers yet"); }
687+
| 'multinomial(' args = function_arguments ')' { $value = NotImplementedFunction("multinomial", "multinomial coefficients yet"); }
688+
| 'fallingfactorial(' args = function_arguments ')' { $value = NotImplementedFunction("fallingfactorial", "falling factorial yet"); }
689+
| 'factorialpower(' args = function_arguments ')' { $value = NotImplementedFunction("factorialpower", "falling factorial yet"); }
690+
| 'risingfactorial(' args = function_arguments ')' { $value = NotImplementedFunction("risingfactorial", "rising factorial yet"); }
691+
| 'forwarddifference(' args = function_arguments ')' { $value = NotImplementedFunction("forwarddifference", "forward difference yet"); }
692+
| 'laplacian(' args = function_arguments ')' { $value = NotImplementedFunction("laplacian", "Laplacian yet"); }
693+
| 'jacobian(' args = function_arguments ')' { $value = NotImplementedFunction("jacobian", "Jacobian yet"); }
694+
| 'hessian(' args = function_arguments ')' { $value = NotImplementedFunction("hessian", "Hessian yet"); }
695+
/* Names that will not be functions, refused with the spelling to use: what they mean is
696+
ambiguous between sources, or is already written exactly another way. */
697+
| 'heaviside(' args = function_arguments ')' { $value = NotAFunctionHere("heaviside", "its value at 0 is 0, 1/2 or 1 by source; write iverson(x > 0), iverson(x >= 0) or (1 + sgn(x))/2"); }
698+
| 'unitstep(' args = function_arguments ')' { $value = NotAFunctionHere("unitstep", "write iverson(x >= 0), which is 1 at 0"); }
699+
| 'isprime(' args = function_arguments ')' { $value = NotAFunctionHere("isprime", "write n in PP"); }
700+
| 'pochhammer(' args = function_arguments ')' { $value = NotAFunctionHere("pochhammer", "(x)_n is the rising factorial to some and the falling one to others; write risingfactorial or fallingfactorial"); }
701+
| 'doublefactorial(' args = function_arguments ')' { $value = NotAFunctionHere("doublefactorial", "the double factorial is to be the postfix n!!, which is not implemented yet"); }
702+
| 'factorial2(' args = function_arguments ')' { $value = NotAFunctionHere("factorial2", "the double factorial is to be the postfix n!!, which is not implemented yet"); }
703+
| 'fractionalpart(' args = function_arguments ')' { $value = NotAFunctionHere("fractionalpart", "write x mod 1, which is in [0, 1)"); }
704+
| 'quotient(' args = function_arguments ')' { $value = NotAFunctionHere("quotient", "write floor(a / b)"); }
661705
| 'domain(' args = function_arguments ')'
662706
{
663707
Assert("domain", 2, $args.list.Count);

‎Sources/AngouriMath/Core/Antlr/AngouriMath.interp‎

Lines changed: 59 additions & 1 deletion
Large diffs are not rendered by default.

‎Sources/AngouriMath/Core/Antlr/AngouriMath.tokens‎

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,43 @@ T__194=195
196196
T__195=196
197197
T__196=197
198198
T__197=198
199-
NEWLINE=199
200-
NUMBER=200
201-
SPECIALSET=201
202-
BOOLEAN=202
203-
NAN=203
204-
VARIABLE=204
205-
COMMENT=205
206-
WS=206
199+
T__198=199
200+
T__199=200
201+
T__200=201
202+
T__201=202
203+
T__202=203
204+
T__203=204
205+
T__204=205
206+
T__205=206
207+
T__206=207
208+
T__207=208
209+
T__208=209
210+
T__209=210
211+
T__210=211
212+
T__211=212
213+
T__212=213
214+
T__213=214
215+
T__214=215
216+
T__215=216
217+
T__216=217
218+
T__217=218
219+
T__218=219
220+
T__219=220
221+
T__220=221
222+
T__221=222
223+
T__222=223
224+
T__223=224
225+
T__224=225
226+
T__225=226
227+
T__226=227
228+
NEWLINE=228
229+
NUMBER=229
230+
SPECIALSET=230
231+
BOOLEAN=231
232+
NAN=232
233+
VARIABLE=233
234+
COMMENT=234
235+
WS=235
207236
'!'=1
208237
'^'=2
209238
'-'=3
@@ -398,8 +427,37 @@ WS=206
398427
'im('=192
399428
'imag('=193
400429
'trunc('=194
401-
'domain('=195
402-
'piecewise('=196
403-
'apply('=197
404-
'lambda('=198
405-
'NaN'=203
430+
'zeta('=195
431+
'riemannzeta('=196
432+
'hurwitzzeta('=197
433+
'lambertw('=198
434+
'productlog('=199
435+
'mobius('=200
436+
'moebiusmu('=201
437+
'divisorsigma('=202
438+
'primenu('=203
439+
'primeomega('=204
440+
'primepi('=205
441+
'harmonicnumber('=206
442+
'catalannumber('=207
443+
'multinomial('=208
444+
'fallingfactorial('=209
445+
'factorialpower('=210
446+
'risingfactorial('=211
447+
'forwarddifference('=212
448+
'laplacian('=213
449+
'jacobian('=214
450+
'hessian('=215
451+
'heaviside('=216
452+
'unitstep('=217
453+
'isprime('=218
454+
'pochhammer('=219
455+
'doublefactorial('=220
456+
'factorial2('=221
457+
'fractionalpart('=222
458+
'quotient('=223
459+
'domain('=224
460+
'piecewise('=225
461+
'apply('=226
462+
'lambda('=227
463+
'NaN'=232

0 commit comments

Comments
 (0)