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 @@ -1753,6 +1753,20 @@ where it was `0.1 * x ^ 2 / 2 + C`
| `limit(sin(c*x)/x, x, 0)` | `NaN` | `c` |
| `limit((1 - cos(c*x))/x^2, x, 0)` | `NaN` | `c ^ 2 / 2` |

### With the downcasting off, a comparison of real values is decided

With `DowncastingEnabled` off, `cos(3)` evaluates to a complex number whose imaginary part is zero,
and a comparison of one was `NaN`: inequalities were decided only between numbers of the real
type. A number with no imaginary part is now compared as the real it is, so `cos(3) >= 0` is
`false` under either setting, and a condition an answer states on a sign, `provided cos(x) >= 0`,
can be evaluated at a point. A comparison with a value off the real line is still `NaN`.

| Evaluated, with the downcasting off | Was (2.5.0) | Now |
|---|---|---|
| `cos(3) >= 0` | `NaN` | `false` |
| `sin(4) < 0` | `NaN` | `true` |
| `cos(1) > cos(3)` | `NaN` | `true` |

### A half-odd power of a logarithm beside a power of `x` is integrated

`x sqrt(ln(x))` was left unintegrated. `x^p F^n`, where `F` is `ln x` or `A + B ln(c x^r)` and
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed

[Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.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/DowncastingOffComparisonTest.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
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ protected override Entity InnerSimplify(bool isExact)
propagateSet: !(Left.InnerSimplified(isExact) is Set && Right.InnerSimplified(isExact) is Set));
}

/// <summary>
/// <paramref name="number"/> as the real it is, or <see langword="null"/> where it has an
/// imaginary part. With downcasting off a value such as <c>cos(3)</c> evaluates to a
/// <see cref="Number.Complex"/> whose imaginary part is zero, and comparing it is as defined
/// as comparing the real it equals: <c>cos(3) &gt;= 0</c> is false, not <c>NaN</c>.
/// </summary>
private static Number.Real? AsAReal(Number number) => number switch
{
Number.Real real => real,
Number.Complex complex when complex.ImaginaryPart.EDecimal.IsZero => complex.RealPart,
_ => null,
};

partial record Greaterf
{
// Inequality comparisons are only defined for real numbers.
Expand All @@ -292,7 +305,7 @@ protected override Entity InnerSimplify(bool isExact)
=> ExpandOnTwoArguments(Left, Right,
(a, b) => (a, b) switch
{
(Real reLeft, Real reRight) => reLeft > reRight,
(Number numLeft, Number numRight) when AsAReal(numLeft) is { } reLeft && AsAReal(numRight) is { } reRight => reLeft > reRight,
(Number numLeft, Number numRight) => MathS.NaN,
_ => null
},
Expand All @@ -311,7 +324,7 @@ protected override Entity InnerSimplify(bool isExact)
=> ExpandOnTwoArguments(Left, Right,
(a, b) => (a, b) switch
{
(Real reLeft, Real reRight) => reLeft >= reRight,
(Number numLeft, Number numRight) when AsAReal(numLeft) is { } reLeft && AsAReal(numRight) is { } reRight => reLeft >= reRight,
(Number numLeft, Number numRight) => MathS.NaN,
_ => null
},
Expand All @@ -330,7 +343,7 @@ protected override Entity InnerSimplify(bool isExact)
=> ExpandOnTwoArguments(Left, Right,
(a, b) => (a, b) switch
{
(Real reLeft, Real reRight) => reLeft < reRight,
(Number numLeft, Number numRight) when AsAReal(numLeft) is { } reLeft && AsAReal(numRight) is { } reRight => reLeft < reRight,
(Number numLeft, Number numRight) => MathS.NaN,
_ => null
},
Expand All @@ -348,7 +361,7 @@ protected override Entity InnerSimplify(bool isExact)
=> ExpandOnTwoArguments(Left, Right,
(a, b) => (a, b) switch
{
(Real reLeft, Real reRight) => reLeft <= reRight,
(Number numLeft, Number numRight) when AsAReal(numLeft) is { } reLeft && AsAReal(numRight) is { } reRight => reLeft <= reRight,
(Number numLeft, Number numRight) => MathS.NaN,
_ => null
},
Expand Down
53 changes: 53 additions & 0 deletions Sources/Tests/UnitTests/Core/DowncastingOffComparisonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using AngouriMath;
using Xunit;
using static AngouriMath.Entity;

namespace AngouriMath.Tests.Core
{
/// <summary>
/// A comparison of two numbers with no imaginary part is decided whatever the downcasting
/// setting. With it off, <c>cos(3)</c> evaluates to a complex number whose imaginary part is
/// zero, and a comparison of it was <c>NaN</c>, which also made every condition an answer
/// stated on a sign undecidable.
/// </summary>
[Trait("Area", "Core")]
public sealed class DowncastingOffComparisonTest
{
[Theory]
[InlineData("cos(3) >= 0", false)]
[InlineData("cos(1) >= 0", true)]
[InlineData("cos(1) > cos(3)", true)]
[InlineData("sin(4) < 0", true)]
[InlineData("sin(4) <= -1", false)]
[InlineData("cos(3) < 1 and cos(1) > 0", true)]
public void AComparisonOfRealValuesIsDecided(string comparison, bool expected)
{
foreach (var downcasting in new[] { true, false })
{
using var _ = MathS.Settings.DowncastingEnabled.Set(downcasting);
Assert.Equal(expected ? Boolean.True : Boolean.False, MathS.FromString(comparison, useCache: false).Evaled);
}
}

/// <summary>A comparison with a value off the real line is still not decided.</summary>
[Theory]
[InlineData("i >= 0")]
[InlineData("(1 + i) > 1")]
[InlineData("sqrt(-2) >= 0")]
public void AComparisonOffTheRealLineIsNaN(string comparison)
{
foreach (var downcasting in new[] { true, false })
{
using var _ = MathS.Settings.DowncastingEnabled.Set(downcasting);
Assert.Equal(MathS.NaN, MathS.FromString(comparison, useCache: false).Evaled);
}
}
}
}
Loading