Skip to content

Commit 19678c9

Browse files
Rafael-SOWNetclaude
andcommitted
SpecialFunctions moves to Numerics, beside the interval evaluation
The routines are the compilers' today, and the numerical evaluation's fast tier is where they are to be shared next, as asked on #1607: the interval evaluation reads no special function, so an integrator check with erf or Ei in it falls back to the decimal evaluation. Nothing but the namespace and the file's place changes. Part of #1607. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7290956 commit 19678c9

5 files changed

Lines changed: 37 additions & 36 deletions

File tree

‎Sources/.editorconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
342342
[AngouriMath/Core/Entity/Continuous/Number/ErrorFunctions.cs]
343343
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
344344

345-
[AngouriMath/Functions/Compilation/SpecialFunctions.cs]
345+
[AngouriMath/Numerics/SpecialFunctions.cs]
346346
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
347347

348348
[AngouriMath/Core/Entity/Continuous/Entity.Continuous.ErrorFunctions.Classes.cs]

‎Sources/AngouriMath/Functions/Compilation/IntoFE/FastExpression.cs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,31 @@ public System.Numerics.Complex Substitute(params System.Numerics.Complex[] value
231231
// In double precision, as the kernels define them.
232232
// https://github.com/asc-community/AngouriMath/issues/1607
233233
case InstructionType.CALL_ERF:
234-
stack.Push(Core.Compilation.SpecialFunctions.Erf(stack.Pop()));
234+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Erf(stack.Pop()));
235235
break;
236236
case InstructionType.CALL_ERFC:
237-
stack.Push(Core.Compilation.SpecialFunctions.Erfc(stack.Pop()));
237+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Erfc(stack.Pop()));
238238
break;
239239
case InstructionType.CALL_ERFI:
240-
stack.Push(Core.Compilation.SpecialFunctions.Erfi(stack.Pop()));
240+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Erfi(stack.Pop()));
241241
break;
242242
case InstructionType.CALL_EI:
243-
stack.Push(Core.Compilation.SpecialFunctions.Ei(stack.Pop()));
243+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Ei(stack.Pop()));
244244
break;
245245
case InstructionType.CALL_LI:
246-
stack.Push(Core.Compilation.SpecialFunctions.Li(stack.Pop()));
246+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Li(stack.Pop()));
247247
break;
248248
case InstructionType.CALL_SI:
249-
stack.Push(Core.Compilation.SpecialFunctions.Si(stack.Pop()));
249+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Si(stack.Pop()));
250250
break;
251251
case InstructionType.CALL_CI:
252-
stack.Push(Core.Compilation.SpecialFunctions.Ci(stack.Pop()));
252+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Ci(stack.Pop()));
253253
break;
254254
case InstructionType.CALL_SHI:
255-
stack.Push(Core.Compilation.SpecialFunctions.Shi(stack.Pop()));
255+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Shi(stack.Pop()));
256256
break;
257257
case InstructionType.CALL_CHI:
258-
stack.Push(Core.Compilation.SpecialFunctions.Chi(stack.Pop()));
258+
stack.Push(AngouriMath.Numerics.SpecialFunctions.Chi(stack.Pop()));
259259
break;
260260
case InstructionType.CALL_FACTORIAL:
261261
// https://stackoverflow.com/a/15454784/5429648

‎Sources/AngouriMath/Functions/Compilation/IntoLinq/MathAllMethods.cs‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,24 @@ public static System.Numerics.Complex Round(System.Numerics.Complex a)
290290

291291
// The special functions, in double precision as the kernels define them.
292292
// https://github.com/asc-community/AngouriMath/issues/1607
293-
public static System.Numerics.Complex Erf(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Erf(a);
294-
public static double Erf(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Erf(a);
295-
public static System.Numerics.Complex Erfc(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Erfc(a);
296-
public static double Erfc(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Erfc(a);
297-
public static System.Numerics.Complex Erfi(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Erfi(a);
298-
public static double Erfi(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Erfi(a);
299-
public static System.Numerics.Complex Ei(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Ei(a);
300-
public static double Ei(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Ei(a);
301-
public static System.Numerics.Complex Li(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Li(a);
302-
public static double Li(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Li(a);
303-
public static System.Numerics.Complex Si(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Si(a);
304-
public static double Si(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Si(a);
305-
public static System.Numerics.Complex Ci(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Ci(a);
306-
public static double Ci(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Ci(a);
307-
public static System.Numerics.Complex Shi(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Shi(a);
308-
public static double Shi(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Shi(a);
309-
public static System.Numerics.Complex Chi(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.Chi(a);
310-
public static double Chi(double a) => AngouriMath.Core.Compilation.SpecialFunctions.Chi(a);
293+
public static System.Numerics.Complex Erf(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Erf(a);
294+
public static double Erf(double a) => AngouriMath.Numerics.SpecialFunctions.Erf(a);
295+
public static System.Numerics.Complex Erfc(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Erfc(a);
296+
public static double Erfc(double a) => AngouriMath.Numerics.SpecialFunctions.Erfc(a);
297+
public static System.Numerics.Complex Erfi(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Erfi(a);
298+
public static double Erfi(double a) => AngouriMath.Numerics.SpecialFunctions.Erfi(a);
299+
public static System.Numerics.Complex Ei(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Ei(a);
300+
public static double Ei(double a) => AngouriMath.Numerics.SpecialFunctions.Ei(a);
301+
public static System.Numerics.Complex Li(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Li(a);
302+
public static double Li(double a) => AngouriMath.Numerics.SpecialFunctions.Li(a);
303+
public static System.Numerics.Complex Si(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Si(a);
304+
public static double Si(double a) => AngouriMath.Numerics.SpecialFunctions.Si(a);
305+
public static System.Numerics.Complex Ci(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Ci(a);
306+
public static double Ci(double a) => AngouriMath.Numerics.SpecialFunctions.Ci(a);
307+
public static System.Numerics.Complex Shi(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Shi(a);
308+
public static double Shi(double a) => AngouriMath.Numerics.SpecialFunctions.Shi(a);
309+
public static System.Numerics.Complex Chi(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.Chi(a);
310+
public static double Chi(double a) => AngouriMath.Numerics.SpecialFunctions.Chi(a);
311311

312312
/// <summary>
313313
/// True where <c>System.Numerics.Complex.IsNaN</c> is, spelled out because that overload is

‎Sources/AngouriMath/Functions/Compilation/IntoLinq/MathAllMethods.tt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ namespace AngouriMath.Core.Compilation.IntoLinq
194194
// The special functions, in double precision as the kernels define them.
195195
// https://github.com/asc-community/AngouriMath/issues/1607
196196
<# foreach (var name in special) { #>
197-
public static System.Numerics.Complex <#= name #>(System.Numerics.Complex a) => AngouriMath.Core.Compilation.SpecialFunctions.<#= name #>(a);
198-
public static double <#= name #>(double a) => AngouriMath.Core.Compilation.SpecialFunctions.<#= name #>(a);
197+
public static System.Numerics.Complex <#= name #>(System.Numerics.Complex a) => AngouriMath.Numerics.SpecialFunctions.<#= name #>(a);
198+
public static double <#= name #>(double a) => AngouriMath.Numerics.SpecialFunctions.<#= name #>(a);
199199
<# } #>
200200

201201
/// <summary>

Sources/AngouriMath/Functions/Compilation/SpecialFunctions.cs renamed to Sources/AngouriMath/Numerics/SpecialFunctions.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
using System;
99
using NumericsComplex = System.Numerics.Complex;
1010

11-
namespace AngouriMath.Core.Compilation
11+
namespace AngouriMath.Numerics
1212
{
1313
/// <summary>
14-
/// The special functions in double precision, for both compilers: <c>erf</c>, <c>erfc</c>,
15-
/// <c>erfi</c>, <c>Ei</c>, <c>li</c>, <c>Si</c>, <c>Ci</c>, <c>Shi</c> and <c>Chi</c>.
14+
/// The special functions in double precision: <c>erf</c>, <c>erfc</c>, <c>erfi</c>, <c>Ei</c>,
15+
/// <c>li</c>, <c>Si</c>, <c>Ci</c>, <c>Shi</c> and <c>Chi</c>. Both compilers call them, and they
16+
/// sit beside the numerical evaluation so that its fast tier can take them up too.
1617
/// The interpreter's kernels, <see cref="Entity.Number.Erf(Entity.Number.Complex)"/> and the
1718
/// others, work in arbitrary precision. At 20 digits they take 0.7 to 5.5 ms a call. Newton's
1819
/// method makes thousands of calls. These take a microsecond or two.
@@ -54,7 +55,7 @@ internal static class SpecialFunctions
5455

5556
private static bool IsNaN(NumericsComplex z) => double.IsNaN(z.Real) || double.IsNaN(z.Imaginary);
5657
private static bool IsInfinite(NumericsComplex z) => double.IsInfinity(z.Real) || double.IsInfinity(z.Imaginary);
57-
[ConstantField] private static readonly NumericsComplex NaN = new(double.NaN, double.NaN);
58+
[AngouriMath.Core.ConstantField] private static readonly NumericsComplex NaN = new(double.NaN, double.NaN);
5859

5960
public static NumericsComplex Erf(NumericsComplex z)
6061
{
@@ -140,15 +141,15 @@ private static NumericsComplex Faddeeva(NumericsComplex z)
140141
}
141142

142143
private const int WeidemanTerms = 40;
143-
[ConstantField] private static readonly double WeidemanL = Math.Sqrt(WeidemanTerms / Math.Sqrt(2));
144+
[AngouriMath.Core.ConstantField] private static readonly double WeidemanL = Math.Sqrt(WeidemanTerms / Math.Sqrt(2));
144145

145146
/// <summary>
146147
/// The polynomial's coefficients, <c>a_n = 1/(4N) sum_k f(t_k) cos(pi n k/(2N))</c> over
147148
/// <c>|k| &lt; 2N</c>, with <c>t_k = L tan(pi k/(4N))</c> and <c>f(t) = e^(-t^2) (L^2 + t^2)</c>:
148149
/// the discrete Fourier transform Weideman takes, written out, since <c>f</c> is even.
149150
/// Index 0 is unused.
150151
/// </summary>
151-
[ConstantField] private static readonly double[] weideman = WeidemanCoefficients();
152+
[AngouriMath.Core.ConstantField] private static readonly double[] weideman = WeidemanCoefficients();
152153

153154
private static double[] WeidemanCoefficients()
154155
{

0 commit comments

Comments
 (0)