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
14 changes: 14 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ 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` |

### `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
read as products, and they print as `Re(…)` and `Im(…)`, as Mathematica, Maple and ISO 80000-2 write them.** `re(z)` was the variable `re` times `z`. They were left as products while the library had neither
function, since two letters is short enough to be somebody's variable; the name without a bracket is still a variable.
Both are real, `im(3 + 4i)` being `4`, real-linear, and turned by the conjugate as they should be
([#2145](https://github.com/asc-community/AngouriMath/issues/2145)).

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"re(z)".ToEntity()` | `re * z` | `Re(z)` |
| `"im(3 + 4i)".ToEntity().Simplify()` | `(3 + 4i) * im` | `4` |
| `"re * x".ToEntity()` | `re * x` | `re * x` |

### `conjugate`, `conj` and `arg` are functions

**Not silent: these names followed by a bracket are now the complex conjugate and the principal argument, where they
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[Tests/UnitTests/Algebra/SolveTest/FractionalPowerRangeTest.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/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/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
42 changes: 42 additions & 0 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,48 @@ public static Entity VectorLength(Matrix v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Arg(Entity z) => new Argf(z);

/// <summary>The real part <c>re(z)</c>: <c>a</c> for <c>z = a + b i</c></summary>
/// <param name="z">The argument, any complex number</param>
/// <returns>The <see cref="Entity.Ref"/> node</returns>
/// <remarks>https://github.com/asc-community/AngouriMath/issues/2145</remarks>
/// <example>
/// <code>
/// using System;
/// using static AngouriMath.MathS;
///
/// Console.WriteLine(Re("3 + 4i").Simplify());
/// Console.WriteLine(Re("a + conj(b)").Simplify());
/// </code>
/// Prints
/// <code>
/// 3
/// Re(a) + Re(b)
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Re(Entity z) => new Ref(z);

/// <summary>The imaginary part <c>im(z)</c>: the real number <c>b</c> for <c>z = a + b i</c></summary>
/// <param name="z">The argument, any complex number</param>
/// <returns>The <see cref="Entity.Imf"/> node</returns>
/// <remarks>https://github.com/asc-community/AngouriMath/issues/2145</remarks>
/// <example>
/// <code>
/// using System;
/// using static AngouriMath.MathS;
///
/// Console.WriteLine(Im("3 + 4i").Simplify());
/// Console.WriteLine(Im("conj(z)").Simplify());
/// </code>
/// Prints
/// <code>
/// 4
/// -Im(z)
/// </code>
/// </example>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Entity Im(Entity z) => new Imf(z);

/// <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
10 changes: 10 additions & 0 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,16 @@ atom returns[Entity value]
| 'conj(' args = function_arguments ')' { Assert("conj", 1, $args.list.Count); $value = MathS.Conjugate($args.list[0]); }
/* The principal argument, in (-pi, pi]. https://github.com/asc-community/AngouriMath/issues/2145 */
| 'arg(' args = function_arguments ')' { Assert("arg", 1, $args.list.Count); $value = MathS.Arg($args.list[0]); }
/* The real and the imaginary part, written Re and Im as Mathematica, Maple and ISO 80000-2
write them, and accepted as SymPy's re and im and as MATLAB's real and imag. re and im were
read as products, re(z) being re * z, while there was nothing for them to mean.
https://github.com/asc-community/AngouriMath/issues/2145 */
| 'Re(' args = function_arguments ')' { Assert("Re", 1, $args.list.Count); $value = MathS.Re($args.list[0]); }
| 'Im(' args = function_arguments ')' { Assert("Im", 1, $args.list.Count); $value = MathS.Im($args.list[0]); }
| 're(' args = function_arguments ')' { Assert("re", 1, $args.list.Count); $value = MathS.Re($args.list[0]); }
| 'real(' args = function_arguments ')' { Assert("real", 1, $args.list.Count); $value = MathS.Re($args.list[0]); }
| 'im(' args = function_arguments ')' { Assert("im", 1, $args.list.Count); $value = MathS.Im($args.list[0]); }
| 'imag(' args = function_arguments ')' { Assert("imag", 1, $args.list.Count); $value = MathS.Im($args.list[0]); }

/* Names the library does not have. Each is a function every other CAS spells this way, so
a caller reaches for it, and without these rules each is silently read as a product --
Expand Down
14 changes: 13 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

40 changes: 26 additions & 14 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,20 @@ T__188=189
T__189=190
T__190=191
T__191=192
NEWLINE=193
NUMBER=194
SPECIALSET=195
BOOLEAN=196
NAN=197
VARIABLE=198
COMMENT=199
WS=200
T__192=193
T__193=194
T__194=195
T__195=196
T__196=197
T__197=198
NEWLINE=199
NUMBER=200
SPECIALSET=201
BOOLEAN=202
NAN=203
VARIABLE=204
COMMENT=205
WS=206
'!'=1
'^'=2
'-'=3
Expand Down Expand Up @@ -385,9 +391,15 @@ WS=200
'conjugate('=185
'conj('=186
'arg('=187
'trunc('=188
'domain('=189
'piecewise('=190
'apply('=191
'lambda('=192
'NaN'=197
'Re('=188
'Im('=189
're('=190
'real('=191
'im('=192
'imag('=193
'trunc('=194
'domain('=195
'piecewise('=196
'apply('=197
'lambda('=198
'NaN'=203
Loading
Loading