Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ as `a - b = 0`, as a statement's own solve reads it: `"x + 1 = 3".Solve("x")` wa
| `MathS.Equations("x + y = 3", "x - y = 1").Solve("x", "y")` | `null` | `[[2, 1]]` |
| `MathS.Equations("x + y = 3", "x - y = 1").ToString()` | `x + y = 3 = 0` and `x - y = 1 = 0` | `x + y - 3 = 0` and `x - y - 1 = 0` |

### The polygamma functions, and the derivative of the factorial

**Silent: a new reading, and an answer where there was none.**
- **New functions.** `polygamma(n, z)` and `digamma(z)` are the polygamma functions `psi^(n)(z)`, the `(n + 1)`-th derivatives of `ln Gamma(z)`, and the digamma function, which is `polygamma(0, z)`. Neither name was recognised, so each was read as a product with an undeclared variable.
- **Evaluation.** Each is evaluated to the working precision anywhere in the complex plane but at `0, -1, -2, ...`, its poles, where it is `NaN`.
- **Derivatives.** Each order differentiates to the next. The derivative of `x!`, which was left unevaluated, is `x! * digamma(x + 1)` ([#171](https://github.com/asc-community/AngouriMath/issues/171)).

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"digamma(1)".ToEntity()` | `digamma * 1`, the variable `digamma` | `digamma(1)`, which evaluates to `-0.5772156649015328…` |
| `"digamma(x)".ToEntity()` | `digamma * x` | `digamma(x)` |
| `"polygamma(1, 1)".ToEntity()` | an `UnhandledParseException` | `polygamma(1, 1)`, which evaluates to `1.6449340668482264…` |
| `"x!".ToEntity().Differentiate("x")` | `derivative(x!, x)`, unevaluated | `x! * digamma(x + 1)` |
| `"gamma(x)".ToEntity().Differentiate("x")` | `derivative((x - 1)!, x)` | `(x - 1)! * digamma(x - 1 + 1)` |

### Numerical equality is to half the evaluation's digits

**Silent: wrong answers.** `MathS.UnsafeAndInternal.AreEqualNumerically` evaluated both sides at its check points and
Expand Down
6 changes: 6 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,12 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Core/Entity/Continuous/Number/ExponentialIntegrals.cs]
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

[AngouriMath/Core/Entity/Continuous/Number/Polygamma.cs]
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

[AngouriMath/Core/Entity/Continuous/Entity.Continuous.Polygamma.Classes.cs]
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

[AngouriMath/Core/Entity/Continuous/Entity.Continuous.ExponentialIntegrals.Classes.cs]
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

Expand Down
19 changes: 19 additions & 0 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,25 @@ public static Entity VectorLength(Matrix v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Li(Entity a) => new Lif(a);

/// <summary>The polygamma function, <c>psi^(n)(z)</c>, the <c>(n + 1)</c>-th derivative of <c>ln Gamma(z)</c></summary>
/// <param name="order">The order <c>n</c>, a whole number <c>n >= 0</c></param>
/// <param name="argument">The argument, any complex number but <c>0, -1, -2, ...</c>, its poles</param>
/// <returns>The <see cref="Entity.Polygammaf"/> node</returns>
/// <remarks>
/// <c>psi^(0)</c> is the digamma function, <c>Gamma'(z)/Gamma(z)</c>, which is what the derivative of
/// <c>x!</c> is written with: <c>(x!)' = x! psi(x + 1)</c>. Each order is the derivative of the one before.
/// https://github.com/asc-community/AngouriMath/issues/171
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Polygamma(Entity order, Entity argument) => new Polygammaf(order, argument);

/// <summary>The digamma function, <c>psi(z) = Gamma'(z)/Gamma(z)</c>, which is <c>polygamma(0, z)</c></summary>
/// <param name="argument">The argument, any complex number but <c>0, -1, -2, ...</c>, its poles</param>
/// <returns>The <see cref="Entity.Polygammaf"/> node of order <c>0</c></returns>
/// <remarks>https://github.com/asc-community/AngouriMath/issues/171</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Digamma(Entity argument) => new Polygammaf(Integer.Zero, argument);

/// <summary>The sine integral, <c>Si(z) = int_0^z sin(t)/t dt</c></summary>
/// <param name="a">The argument, any complex number</param>
/// <returns>The <see cref="Entity.Sif"/> node</returns>
Expand Down
3 changes: 3 additions & 0 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ atom returns[Entity value]
/* The exponential and logarithmic integrals. https://github.com/asc-community/AngouriMath/issues/1501 */
| 'Ei(' args = function_arguments ')' { Assert("Ei", 1, $args.list.Count); $value = MathS.Ei($args.list[0]); }
| 'li(' args = function_arguments ')' { Assert("li", 1, $args.list.Count); $value = MathS.Li($args.list[0]); }
/* The polygamma functions, and the digamma function, which is the one of order 0. https://github.com/asc-community/AngouriMath/issues/171 */
| 'polygamma(' args = function_arguments ')' { Assert("polygamma", 2, $args.list.Count); $value = MathS.Polygamma($args.list[0], $args.list[1]); }
| 'digamma(' args = function_arguments ')' { Assert("digamma", 1, $args.list.Count); $value = MathS.Digamma($args.list[0]); }
/* The trigonometric and hyperbolic integrals. https://github.com/asc-community/AngouriMath/issues/1501 */
| 'Si(' args = function_arguments ')' { Assert("Si", 1, $args.list.Count); $value = MathS.Si($args.list[0]); }
| 'Ci(' args = function_arguments ')' { Assert("Ci", 1, $args.list.Count); $value = MathS.Ci($args.list[0]); }
Expand Down
6 changes: 5 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

42 changes: 23 additions & 19 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,16 @@ T__179=180
T__180=181
T__181=182
T__182=183
NEWLINE=184
NUMBER=185
SPECIALSET=186
BOOLEAN=187
NAN=188
VARIABLE=189
COMMENT=190
WS=191
T__183=184
T__184=185
NEWLINE=186
NUMBER=187
SPECIALSET=188
BOOLEAN=189
NAN=190
VARIABLE=191
COMMENT=192
WS=193
'!'=1
'^'=2
'-'=3
Expand Down Expand Up @@ -362,14 +364,16 @@ WS=191
'erfi('=171
'Ei('=172
'li('=173
'Si('=174
'Ci('=175
'Shi('=176
'Chi('=177
'trunc('=178
'conjugate('=179
'domain('=180
'piecewise('=181
'apply('=182
'lambda('=183
'NaN'=188
'polygamma('=174
'digamma('=175
'Si('=176
'Ci('=177
'Shi('=178
'Chi('=179
'trunc('=180
'conjugate('=181
'domain('=182
'piecewise('=183
'apply('=184
'lambda('=185
'NaN'=190
Loading
Loading