Skip to content

Commit 9e9b60b

Browse files
erf, erfc and erfi are functions (#1506)
The error function, its complement and the imaginary error function are nodes, the first of #1501's special functions: parsed, printed in text, LaTeX and SymPy, differentiated from their definitions, exact at 0 and +-oo, monotone over a real interval, and evaluated to the working precision anywhere in the complex plane -- by a series of positive terms on the real line, carrying the digits it cancels off it, by the asymptotic series of erfc past |z|^2 = P ln 10, and on the imaginary axis through erfi as a real function, so that erf(i y) has no real part. An equation in one of them is left unsolved, since none of their inverses is a node here. erf was refused by name; erfc and erfi were not, and each was read as a product with an undeclared variable: erfc(1) simplified to the variable erfc. Part of #1501. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c9f688b commit 9e9b60b

30 files changed

Lines changed: 1836 additions & 898 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,25 @@ has no zeros, so `x! = 0` is still `{ }`, and so is `arcsin(x) = 5`.
15781578
| `"phi(x) = 4".Solve("x")` | `{ }` | `{ x : phi(x) = 4 }` |
15791579
| `"binomial(x, 2) = 3".Solve("x")` | `UnhandledParseException` | `{ x : binomial(x, 2) = 3 }` |
15801580

1581+
### `erf`, `erfc` and `erfi` are functions
1582+
1583+
**Addition, and two silent misreadings fixed.** The error function `erf(z) = 2/sqrt(pi) int_0^z
1584+
e^(-t^2) dt`, its complement `erfc(z) = 1 - erf(z)` and the imaginary error function
1585+
`erfi(z) = -i erf(i z)` are nodes (`MathS.Erf`, `MathS.Erfc`, `MathS.Erfi`), the first of #1501's
1586+
special functions. Each is differentiated, printed in LaTeX as `\operatorname{erf}` and so on, and
1587+
evaluated to the working precision anywhere in the complex plane (`Entity.Number.Erf`, `Erfc`,
1588+
`Erfi`). An equation in one of them is left unsolved rather than answered with no roots. `erf`
1589+
was refused by name, but `erfc` and `erfi` were not, so each was read as a product with an
1590+
undeclared variable.
1591+
1592+
| Input | Was (2.5.0) | Now |
1593+
|---|---|---|
1594+
| `"erf(x)"` | `UnrecognizedFunctionParseException` | `erf(x)` |
1595+
| `"erfc(x)"` | `erfc * x` | `erfc(x)` |
1596+
| `"erfi(x)"` | `erfi * x` | `erfi(x)` |
1597+
| `"erfc(1)".Simplify()` | `erfc` | `erfc(1)`, and `0.157299207050285…` evaluated |
1598+
| `"erf(x)".Differentiate("x")` | `UnrecognizedFunctionParseException` | `2 / sqrt(pi) * e ^ (-x ^ 2)` |
1599+
15811600
### `binomial(n, k)` is a function
15821601

15831602
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

‎Sources/.editorconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,18 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
324324
[AngouriMath/Functions/Boolean/QuantifierFacts.cs]
325325
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
326326

327+
[AngouriMath/Core/Entity/Continuous/Number/ErrorFunctions.cs]
328+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
329+
330+
[AngouriMath/Core/Entity/Continuous/Entity.Continuous.ErrorFunctions.Classes.cs]
331+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
332+
327333
[Tests/UnitTests/Core/ProofRecordingTest.cs]
328334
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
329335

336+
[Tests/UnitTests/Convenience/ErrorFunctionTest.cs]
337+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
338+
330339
[Tests/UnitTests/Core/Sets/PrimeSetTest.cs]
331340
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
332341

‎Sources/AngouriMath/Convenience/MathS.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,31 @@ public static Entity VectorLength(Matrix v)
13671367
[MethodImpl(MethodImplOptions.AggressiveInlining)]
13681368
public static Entity Binomial(Entity n, Entity k) => new Binomialf(n, k);
13691369

1370+
/// <summary>The error function, <c>erf(z) = 2/sqrt(pi) int_0^z e^(-t^2) dt</c></summary>
1371+
/// <param name="a">The argument, any complex number</param>
1372+
/// <returns>The <see cref="Entity.Erff"/> node</returns>
1373+
/// <remarks>https://github.com/asc-community/AngouriMath/issues/1501</remarks>
1374+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1375+
public static Entity Erf(Entity a) => new Erff(a);
1376+
1377+
/// <summary>The complementary error function, <c>erfc(z) = 1 - erf(z)</c></summary>
1378+
/// <param name="a">The argument, any complex number</param>
1379+
/// <returns>The <see cref="Entity.Erfcf"/> node</returns>
1380+
/// <remarks>https://github.com/asc-community/AngouriMath/issues/1501</remarks>
1381+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1382+
public static Entity Erfc(Entity a) => new Erfcf(a);
1383+
1384+
/// <summary>The imaginary error function, <c>erfi(z) = -i erf(i z)</c></summary>
1385+
/// <param name="a">The argument, any complex number</param>
1386+
/// <returns>The <see cref="Entity.Erfif"/> node</returns>
1387+
/// <remarks>
1388+
/// On the real line <c>erfi(x) = 2/sqrt(pi) int_0^x e^(t^2) dt</c>, so it is what
1389+
/// <c>int e^(x^2) dx</c> is in closed form.
1390+
/// https://github.com/asc-community/AngouriMath/issues/1501
1391+
/// </remarks>
1392+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1393+
public static Entity Erfi(Entity a) => new Erfif(a);
1394+
13701395
/// <summary>Boolean negation
13711396
/// <a href="https://en.wikipedia.org/wiki/Negation">Wikipedia</a></summary>
13721397
/// <param name="a">Argument node of which Negation function will be taken</param>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,17 @@ atom returns[Entity value]
596596
| 'gcd(' args = function_arguments ')' { AssertAtLeast("gcd", 1, $args.list.Count); $value = $args.list.Aggregate((a, b) => MathS.Gcd(a, b)); }
597597
| 'lcm(' args = function_arguments ')' { AssertAtLeast("lcm", 1, $args.list.Count); $value = $args.list.Aggregate((a, b) => MathS.Lcm(a, b)); }
598598
| 'binomial(' args = function_arguments ')' { Assert("binomial", 2, $args.list.Count); $value = MathS.Binomial($args.list[0], $args.list[1]); }
599+
/* The error functions. https://github.com/asc-community/AngouriMath/issues/1501 */
600+
| 'erf(' args = function_arguments ')' { Assert("erf", 1, $args.list.Count); $value = MathS.Erf($args.list[0]); }
601+
| 'erfc(' args = function_arguments ')' { Assert("erfc", 1, $args.list.Count); $value = MathS.Erfc($args.list[0]); }
602+
| 'erfi(' args = function_arguments ')' { Assert("erfi", 1, $args.list.Count); $value = MathS.Erfi($args.list[0]); }
599603
600604
/* Names the library does not have. Each is a function every other CAS spells this way, so
601605
a caller reaches for it, and without these rules each is silently read as a product --
602606
see NotImplementedFunction above. Refusing is not the feature; it is the difference
603607
between a missing function and a wrong answer. */
604608
605609
| 'trunc(' args = function_arguments ')' { $value = NotImplementedFunction("trunc", "rounding functions"); }
606-
| 'erf(' args = function_arguments ')' { $value = NotImplementedFunction("erf", "error function"); }
607610
| 'conjugate(' args = function_arguments ')' { $value = NotImplementedFunction("conjugate", "complex conjugate as a symbolic function"); }
608611
| 'domain(' args = function_arguments ')'
609612
{

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

Lines changed: 6 additions & 2 deletions
Large diffs are not rendered by default.

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,16 @@ T__169=170
171171
T__170=171
172172
T__171=172
173173
T__172=173
174-
NEWLINE=174
175-
NUMBER=175
176-
SPECIALSET=176
177-
BOOLEAN=177
178-
NAN=178
179-
VARIABLE=179
180-
COMMENT=180
181-
WS=181
174+
T__173=174
175+
T__174=175
176+
NEWLINE=176
177+
NUMBER=177
178+
SPECIALSET=178
179+
BOOLEAN=179
180+
NAN=180
181+
VARIABLE=181
182+
COMMENT=182
183+
WS=183
182184
'!'=1
183185
'^'=2
184186
'-'=3
@@ -345,11 +347,13 @@ WS=181
345347
'gcd('=164
346348
'lcm('=165
347349
'binomial('=166
348-
'trunc('=167
349-
'erf('=168
350-
'conjugate('=169
351-
'domain('=170
352-
'piecewise('=171
353-
'apply('=172
354-
'lambda('=173
355-
'NaN'=178
350+
'erf('=167
351+
'erfc('=168
352+
'erfi('=169
353+
'trunc('=170
354+
'conjugate('=171
355+
'domain('=172
356+
'piecewise('=173
357+
'apply('=174
358+
'lambda('=175
359+
'NaN'=180

0 commit comments

Comments
 (0)