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 @@ -834,6 +834,21 @@ carried a condition the piecewise read as no value, so the sum was `0` at `n = 0
| `"sum(binomial(n, k), k, 0, n)".ToEntity().Evaled` | `UnhandledParseException` | `piecewise((2 ^ n) provided (n >= 0), 0 provided True)` |
| `"sum(n! / (k! (n - k)!) (-1)^k, k, 0, n)".ToEntity().Evaled` | `piecewise(0 provided True)` — wrong at `n = 0` | `piecewise(1 provided (n = 0), 0 provided True)` |

### `iverson(P)` is the Iverson bracket, and was a product

`iverson(P)` is `1` where the statement `P` holds and `0` where it does not, and is kept as written
where `P` is not decided, so a count is a sum of brackets: `sum(iverson(k divides 12), k, 1, 12)` is
`6`. A number is not a statement and is left as written; a statement with no truth value, such as
`i > 0`, gives `NaN`. It prints as `[\![P]\!]` in LaTeX and as a `Piecewise` for SymPy
([#1478](https://github.com/asc-community/AngouriMath/issues/1478)). In 2.5.0 the name was read as a
variable multiplying its argument, and a product with a truth value is `NaN`.

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"iverson(2 > 1)".ToEntity().Simplify()` | `NaN` — `iverson * (2 > 1)` | `1` |
| `"iverson(x > 0)".ToEntity().Simplify()` | `iverson * (x > 0)` | `iverson(x > 0)` |
| `"sum(sum(sum(iverson(r + b + g = 4), g, 0, 3), b, 0, 3), r, 0, 3)".ToEntity().Simplify()` | `NaN` | `12` |

### A statement about a sum up to `n` is decided by induction

`forall n in ZZ+ : sum(f, k, a, n) = g` is proved from the least member of the set: the statement
Expand Down
6 changes: 6 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[Tests/UnitTests/Convenience/BinomialTest.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

[Tests/UnitTests/Common/ExponentialOfALogarithmTest.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 Expand Up @@ -330,6 +333,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Core/Entity/Continuous/Entity.Continuous.ErrorFunctions.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.Iverson.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

[Tests/UnitTests/Core/ProofRecordingTest.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 @@ -1367,6 +1367,33 @@ public static Entity VectorLength(Matrix v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Binomial(Entity n, Entity k) => new Binomialf(n, k);

/// <summary>The Iverson bracket <c>iverson(P)</c>: <c>1</c> where the statement holds, <c>0</c> where it does not</summary>
/// <param name="statement">The statement</param>
/// <returns>The <see cref="Entity.Iversonf"/> node</returns>
/// <remarks>
/// A statement that is not decided is kept as the node. A count is a sum of these:
/// <c>sum(iverson(k divides 12), k, 1, 12)</c> is the number of divisors of <c>12</c>.
/// https://github.com/asc-community/AngouriMath/issues/1478
/// </remarks>
/// <example>
/// <code>
/// using System;
/// using static AngouriMath.MathS;
///
/// Console.WriteLine(Iverson("3 divides 12").Simplify());
/// Console.WriteLine(Iverson("2 > 3").Simplify());
/// Console.WriteLine(Iverson("x > 0").Simplify());
/// </code>
/// Prints
/// <code>
/// 1
/// 0
/// iverson(x > 0)
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Iverson(Entity statement) => new Iversonf(statement);

/// <summary>The error function, <c>erf(z) = 2/sqrt(pi) int_0^z e^(-t^2) dt</c></summary>
/// <param name="a">The argument, any complex number</param>
/// <returns>The <see cref="Entity.Erff"/> 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 @@ -596,6 +596,9 @@ atom returns[Entity value]
| 'gcd(' args = function_arguments ')' { AssertAtLeast("gcd", 1, $args.list.Count); $value = $args.list.Aggregate((a, b) => MathS.Gcd(a, b)); }
| 'lcm(' args = function_arguments ')' { AssertAtLeast("lcm", 1, $args.list.Count); $value = $args.list.Aggregate((a, b) => MathS.Lcm(a, b)); }
| 'binomial(' args = function_arguments ')' { Assert("binomial", 2, $args.list.Count); $value = MathS.Binomial($args.list[0], $args.list[1]); }
/* The Iverson bracket, 1 where a statement holds and 0 where it does not: a count written as
a sum. https://github.com/asc-community/AngouriMath/issues/1478 */
| 'iverson(' args = function_arguments ')' { Assert("iverson", 1, $args.list.Count); $value = MathS.Iverson($args.list[0]); }
/* The error functions. https://github.com/asc-community/AngouriMath/issues/1501 */
| 'erf(' args = function_arguments ')' { Assert("erf", 1, $args.list.Count); $value = MathS.Erf($args.list[0]); }
| 'erfc(' args = function_arguments ')' { Assert("erfc", 1, $args.list.Count); $value = MathS.Erfc($args.list[0]); }
Expand Down
4 changes: 3 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,15 @@ T__177=178
T__178=179
T__179=180
T__180=181
NEWLINE=182
NUMBER=183
SPECIALSET=184
BOOLEAN=185
NAN=186
VARIABLE=187
COMMENT=188
WS=189
T__181=182
NEWLINE=183
NUMBER=184
SPECIALSET=185
BOOLEAN=186
NAN=187
VARIABLE=188
COMMENT=189
WS=190
'!'=1
'^'=2
'-'=3
Expand Down Expand Up @@ -353,19 +354,20 @@ WS=189
'gcd('=164
'lcm('=165
'binomial('=166
'erf('=167
'erfc('=168
'erfi('=169
'Ei('=170
'li('=171
'Si('=172
'Ci('=173
'Shi('=174
'Chi('=175
'trunc('=176
'conjugate('=177
'domain('=178
'piecewise('=179
'apply('=180
'lambda('=181
'NaN'=186
'iverson('=167
'erf('=168
'erfc('=169
'erfi('=170
'Ei('=171
'li('=172
'Si('=173
'Ci('=174
'Shi('=175
'Chi('=176
'trunc('=177
'conjugate('=178
'domain('=179
'piecewise('=180
'apply('=181
'lambda('=182
'NaN'=187
Loading
Loading