Skip to content

Commit 9444691

Browse files
Refuse the arc- spellings of the inverse hyperbolic functions (#687)
arcsinh(x) parsed as arcsinh * x -- a product of an undeclared variable and x -- and said nothing about it. The same for arccosh, arctanh, arccotanh, arcsech and arccosech. Rewritten from taking those spellings as synonyms to refusing them, following Happypig375 on the pull request: the inverse hyperbolic functions are area functions, not arc functions, so arcsinh is not another name for arsinh, it is not a name for anything. Each is now an UnrecognizedFunctionParseException that says so and names the spellings that do work: there is no function arcsinh: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic sine is arsinh, asinh or arsh Nothing else changes. The twenty-one spellings the grammar already accepted still parse, arcsin and its five relatives are correct and untouched, and a name that merely begins the same way -- arcs(x), arcsinhh(x) -- is still the product it was. Done by changing AngouriMath.g and regenerating with the repository's own antlr-4.13.1-complete.jar and post-processor, as Docs/Contributing/ImproveParser.md sets out. Four spellings that already parsed but were untested are added to TestHyperbolic while passing. 4036 tests, 127 F#.
1 parent 4756cf9 commit 9444691

10 files changed

Lines changed: 945 additions & 693 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,28 +324,34 @@ atom returns[Entity value]
324324
| 'asinh(' args = function_arguments ')' { Assert("arcsin", 1, $args.list.Count); $value = MathS.Hyperbolic.Arsinh($args.list[0]); }
325325
| 'arsinh(' args = function_arguments ')' { Assert("arcsin", 1, $args.list.Count); $value = MathS.Hyperbolic.Arsinh($args.list[0]); }
326326
| 'arsh(' args = function_arguments ')' { Assert("arcsin", 1, $args.list.Count); $value = MathS.Hyperbolic.Arsinh($args.list[0]); }
327+
| 'arcsinh(' args = function_arguments ')' { throw new UnrecognizedFunctionParseException("there is no function arcsinh: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic sine is arsinh, asinh or arsh"); }
327328

328329
| 'acosh(' args = function_arguments ')' { Assert("arccos", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosh($args.list[0]); }
329330
| 'arcosh(' args = function_arguments ')' { Assert("arccos", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosh($args.list[0]); }
330331
| 'arch(' args = function_arguments ')' { Assert("arccos", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosh($args.list[0]); }
332+
| 'arccosh(' args = function_arguments ')' { throw new UnrecognizedFunctionParseException("there is no function arccosh: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic cosine is arcosh, acosh or arch"); }
331333

332334
| 'atanh(' args = function_arguments ')' { Assert("arctan", 1, $args.list.Count); $value = MathS.Hyperbolic.Artanh($args.list[0]); }
333335
| 'artanh(' args = function_arguments ')' { Assert("arctan", 1, $args.list.Count); $value = MathS.Hyperbolic.Artanh($args.list[0]); }
334336
| 'arth(' args = function_arguments ')' { Assert("arctan", 1, $args.list.Count); $value = MathS.Hyperbolic.Artanh($args.list[0]); }
337+
| 'arctanh(' args = function_arguments ')' { throw new UnrecognizedFunctionParseException("there is no function arctanh: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic tangent is artanh, atanh or arth"); }
335338

336339
| 'acoth(' args = function_arguments ')' { Assert("arccotan", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcotanh($args.list[0]); }
337340
| 'arcoth(' args = function_arguments ')' { Assert("arccotan", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcotanh($args.list[0]); }
338341
| 'acotanh(' args = function_arguments ')' { Assert("arccotan", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcotanh($args.list[0]); }
339342
| 'arcotanh(' args = function_arguments ')' { Assert("arccotan", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcotanh($args.list[0]); }
340343
| 'arcth(' args = function_arguments ')' { Assert("arccotan", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcotanh($args.list[0]); }
344+
| 'arccotanh(' args = function_arguments ')' { throw new UnrecognizedFunctionParseException("there is no function arccotanh: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic cotangent is arcotanh, acotanh, arcoth, acoth or arcth"); }
341345

342346
| 'asech(' args = function_arguments ')' { Assert("arcsec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arsech($args.list[0]); }
343347
| 'arsech(' args = function_arguments ')' { Assert("arcsec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arsech($args.list[0]); }
344348
| 'arsch(' args = function_arguments ')' { Assert("arcsec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arsech($args.list[0]); }
349+
| 'arcsech(' args = function_arguments ')' { throw new UnrecognizedFunctionParseException("there is no function arcsech: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic secant is arsech, asech or arsch"); }
345350

346351
| 'acosech(' args = function_arguments ')' { Assert("arccosec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosech($args.list[0]); }
347352
| 'arcosech(' args = function_arguments ')' { Assert("arccosec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosech($args.list[0]); }
348353
| 'arcsch(' args = function_arguments ')' { Assert("arccosec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosech($args.list[0]); }
354+
| 'arccosech(' args = function_arguments ')' { throw new UnrecognizedFunctionParseException("there is no function arccosech: the inverse hyperbolic functions are area functions, not arc functions, so the inverse hyperbolic cosecant is arcosech, acosech, arcsch or acsch"); }
349355
| 'acsch(' args = function_arguments ')' { Assert("arccosec", 1, $args.list.Count); $value = MathS.Hyperbolic.Arcosech($args.list[0]); }
350356
/* End */
351357

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

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

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

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,19 @@ T__117=118
119119
T__118=119
120120
T__119=120
121121
T__120=121
122-
NEWLINE=122
123-
NUMBER=123
124-
SPECIALSET=124
125-
BOOLEAN=125
126-
VARIABLE=126
127-
COMMENT=127
128-
WS=128
122+
T__121=122
123+
T__122=123
124+
T__123=124
125+
T__124=125
126+
T__125=126
127+
T__126=127
128+
NEWLINE=128
129+
NUMBER=129
130+
SPECIALSET=130
131+
BOOLEAN=131
132+
VARIABLE=132
133+
COMMENT=133
134+
WS=134
129135
'!'=1
130136
'^'=2
131137
'-'=3
@@ -214,36 +220,42 @@ WS=128
214220
'asinh('=86
215221
'arsinh('=87
216222
'arsh('=88
217-
'acosh('=89
218-
'arcosh('=90
219-
'arch('=91
220-
'atanh('=92
221-
'artanh('=93
222-
'arth('=94
223-
'acoth('=95
224-
'arcoth('=96
225-
'acotanh('=97
226-
'arcotanh('=98
227-
'arcth('=99
228-
'asech('=100
229-
'arsech('=101
230-
'arsch('=102
231-
'acosech('=103
232-
'arcosech('=104
233-
'arcsch('=105
234-
'acsch('=106
235-
'gamma('=107
236-
'derivative('=108
237-
'integral('=109
238-
'limit('=110
239-
'limitleft('=111
240-
'limitright('=112
241-
'signum('=113
242-
'sgn('=114
243-
'sign('=115
244-
'abs('=116
245-
'phi('=117
246-
'domain('=118
247-
'piecewise('=119
248-
'apply('=120
249-
'lambda('=121
223+
'arcsinh('=89
224+
'acosh('=90
225+
'arcosh('=91
226+
'arch('=92
227+
'arccosh('=93
228+
'atanh('=94
229+
'artanh('=95
230+
'arth('=96
231+
'arctanh('=97
232+
'acoth('=98
233+
'arcoth('=99
234+
'acotanh('=100
235+
'arcotanh('=101
236+
'arcth('=102
237+
'arccotanh('=103
238+
'asech('=104
239+
'arsech('=105
240+
'arsch('=106
241+
'arcsech('=107
242+
'acosech('=108
243+
'arcosech('=109
244+
'arcsch('=110
245+
'arccosech('=111
246+
'acsch('=112
247+
'gamma('=113
248+
'derivative('=114
249+
'integral('=115
250+
'limit('=116
251+
'limitleft('=117
252+
'limitright('=118
253+
'signum('=119
254+
'sgn('=120
255+
'sign('=121
256+
'abs('=122
257+
'phi('=123
258+
'domain('=124
259+
'piecewise('=125
260+
'apply('=126
261+
'lambda('=127

0 commit comments

Comments
 (0)