Skip to content

Commit ca785d3

Browse files
The imaginary part of a value that does not exist has none (#2257)
Im(1/0) was 0, and so was Im(arccos(pi) provided pi < 3), where Re, conj, arg, abs and floor of the same values are NaN. Imf.ImaginaryPart answered any Complex with its imaginary part, and NaN is a Real, whose imaginary part is 0. A NaN argument is now NaN, before that arm. ImaginaryPartOfNaNTest takes Im of three values that do not exist, evaluated, simplified and substituted, and four of them fail on master. Re(1/0) and the imaginary parts of 2 + 3i, 5 and -oo pin what has not changed. Im is new since 2.6.0 (#2145), where im(1/0) was the product im * (1/0), so no answer changes against it. Found by work/domaincheck. Fixes #2253. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 2eec9d4 commit ca785d3

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
941941
[Tests/UnitTests/Convenience/ArcsineOfARealPastOneTest.cs]
942942
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
943943

944+
[Tests/UnitTests/Convenience/ImaginaryPartOfNaNTest.cs]
945+
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
946+
944947
[AngouriMath/Functions/Compilation/RealProducts.cs]
945948
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
946949

‎Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,9 @@ public partial record Imf
826826
// im(prime(x)) has no value at x = -3.
827827
private static Entity? ImaginaryPart(Entity argument, bool isExact) => argument switch
828828
{
829+
// A number that does not exist has no parts. NaN is a Real, whose imaginary part is 0, so
830+
// im(1/0) was 0. https://github.com/asc-community/AngouriMath/issues/2253
831+
Complex { IsNaN: true } => Real.NaN,
829832
Complex number => number.ImaginaryPart,
830833
Conjugatef(var z) => (-new Imf(z)).InnerSimplified(isExact),
831834
Sumf(var left, var right) => (new Imf(left) + new Imf(right)).InnerSimplified(isExact),
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Convenience
13+
{
14+
/// <summary>
15+
/// The imaginary part of a value that does not exist has none, as its real part has none, where it was 0: <c>NaN</c>
16+
/// is a <see cref="Entity.Number.Real"/>, whose imaginary part is 0.
17+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2253">#2253</a>
18+
/// </summary>
19+
[Trait("Area", "Convenience")]
20+
public sealed class ImaginaryPartOfNaNTest
21+
{
22+
[Theory]
23+
[InlineData("Im(1/0)")]
24+
[InlineData("Im(arccos(pi) provided pi < 3)")]
25+
[InlineData("Im(1/0) + 1")]
26+
[InlineData("Re(1/0)")]
27+
public void ItHasNoValue(string expression)
28+
{
29+
Assert.True(expression.ToEntity().Evaled.IsNaN, $"{expression} evaluates to {expression.ToEntity().Evaled}");
30+
Assert.True(expression.ToEntity().Simplify().IsNaN, $"{expression} simplifies to {expression.ToEntity().Simplify()}");
31+
}
32+
33+
[Fact]
34+
public void SubstitutedItHasNoValue()
35+
=> Assert.True("Im(x)".ToEntity().Substitute("x", "1/0".ToEntity()).Evaled.IsNaN);
36+
37+
[Theory]
38+
[InlineData("Im(2 + 3i)", "3")]
39+
[InlineData("Im(5)", "0")]
40+
[InlineData("Im(-oo)", "0")]
41+
public void ANumberHasItsImaginaryPart(string expression, string part)
42+
=> Assert.Equal(part.ToEntity().Evaled, expression.ToEntity().Evaled);
43+
}
44+
}

0 commit comments

Comments
 (0)