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 @@ -290,6 +290,21 @@ the expression's own domain as its condition ([#2142](https://github.com/asc-com
| `"(1 - cos(a))/(1 + cos(a))/tan(a/2)^2".Simplify()` | `(1 - cos(a)) / ((cos(a) + 1) * tan(a / 2) ^ 2)` | `1 provided not cos(a) + 1 = 0 and not tan(a / 2) = 0 and not cos(a / 2) = 0` |
| `"(cos(2*x) - 1)^2 + sin(2*x)^2 - 4*sin(x)^2".Simplify()` ([#2133](https://github.com/asc-community/AngouriMath/issues/2133)) | `2 + (-2) * cos(2 * x) + (-4) * sin(x) ^ 2` | `0` |

### The double factorial is the postfix `n!!`

**Not silent: `n!!` is now the double factorial, where it was a parse error.** It is the product of the positive integers
up to `n` with its parity, `0!!` and `(-1)!!` being `1`, and below them `n!! = (n + 2)!!/(n + 2)`. It has no value at a
negative even integer or off the integers, since the extension through the gamma function does not give `0!! = 1`.
`(n!)!` keeps its parentheses, and `n!!!`, the triple factorial, is refused rather than read as `(n!!)!`
([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"7!!".ToEntity().Simplify()` | throws `UnhandledParseException` | `105` |
| `"(-5)!!".ToEntity().Simplify()` | throws `UnhandledParseException` | `1/3` |
| `"n!!".ToEntity()` | throws `UnhandledParseException` | `n!!` |
| `"n!!!".ToEntity()` | throws `UnhandledParseException` | throws `UnrecognizedFunctionParseException` |

### `re` and `im` are the real and the imaginary part

**Not silent: `re(…)` and `im(…)`, and `real(…)` and `imag(…)`, are now the real and the imaginary part, where they were
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[Tests/UnitTests/Convenience/RealAndImaginaryPartTest.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

[Tests/UnitTests/Convenience/DoubleFactorialTest.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

[Tests/UnitTests/Convenience/IversonTest.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
27 changes: 27 additions & 0 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,33 @@ public static Entity VectorLength(Matrix v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Im(Entity z) => new Imf(z);

/// <summary>The double factorial <c>n!!</c>: <c>n (n - 2) (n - 4) ...</c> down to 1 or 2</summary>
/// <param name="n">An integer, other than a negative even one</param>
/// <returns>The <see cref="Entity.DoubleFactorialf"/> node</returns>
/// <remarks>
/// <c>0!!</c> and <c>(-1)!!</c> are <c>1</c>, a negative odd <c>n</c> follows from
/// <c>n!! = (n + 2)!!/(n + 2)</c>, and off the integers it has no value. It is not <c>(n!)!</c>.
/// https://github.com/asc-community/AngouriMath/issues/2182
/// </remarks>
/// <example>
/// <code>
/// using System;
/// using static AngouriMath.MathS;
///
/// Console.WriteLine(DoubleFactorial(7).Simplify());
/// Console.WriteLine(DoubleFactorial(8).Simplify());
/// Console.WriteLine(DoubleFactorial(-5).Simplify());
/// </code>
/// Prints
/// <code>
/// 105
/// 384
/// 1/3
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity DoubleFactorial(Entity n) => new DoubleFactorialf(n);

/// <summary>The aleph number <c>aleph(k)</c>, the size of an infinite set</summary>
/// <param name="index">The index, a whole number from zero</param>
/// <returns>The <see cref="Entity.Alephf"/> node</returns>
Expand Down
9 changes: 7 additions & 2 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ options
// atom is defined later
factorial_expression returns[Entity value]
: p = atom '!' { $value = MathS.Factorial($p.value); }
/* The double factorial, n (n - 2) (n - 4) ..., which is not (n!)!: that keeps its parentheses.
Three marks are the triple factorial in the literature, which the library does not have, so
they are refused rather than read as (n!!)!. https://github.com/asc-community/AngouriMath/issues/2182 */
| p = atom '!!' { $value = MathS.DoubleFactorial($p.value); }
| p = atom '!!!' { throw new UnrecognizedFunctionParseException("n!!! is the triple factorial, which AngouriMath does not have; write (n!!)! for the factorial of a double factorial"); }
| p = atom { $value = $p.value; }
;

Expand Down Expand Up @@ -698,8 +703,8 @@ atom returns[Entity value]
| 'unitstep(' args = function_arguments ')' { $value = NotAFunctionHere("unitstep", "write iverson(x >= 0), which is 1 at 0"); }
| 'isprime(' args = function_arguments ')' { $value = NotAFunctionHere("isprime", "write n in PP"); }
| '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"); }
| 'doublefactorial(' args = function_arguments ')' { $value = NotAFunctionHere("doublefactorial", "the double factorial is to be the postfix n!!, which is not implemented yet"); }
| 'factorial2(' args = function_arguments ')' { $value = NotAFunctionHere("factorial2", "the double factorial is to be the postfix n!!, which is not implemented yet"); }
| 'doublefactorial(' args = function_arguments ')' { $value = NotAFunctionHere("doublefactorial", "the double factorial is the postfix n!!"); }
| 'factorial2(' args = function_arguments ')' { $value = NotAFunctionHere("factorial2", "the double factorial is the postfix n!!"); }
| 'fractionalpart(' args = function_arguments ')' { $value = NotAFunctionHere("fractionalpart", "write x mod 1, which is in [0, 1)"); }
| 'quotient(' args = function_arguments ')' { $value = NotAFunctionHere("quotient", "write floor(a / b)"); }
| 'domain(' args = function_arguments ')'
Expand Down
6 changes: 5 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

Loading
Loading