diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index 72be07dd3..8002c9a16 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1298,13 +1298,16 @@ private static ApproachFrom[] Sides(Entity dest, ApproachFrom side) // e^(-1/x) vanishing at 0, so nothing had a sign for it. u is a proper part, and the side u arrives from is the // sign of u - L, which is skipped where it is this very expression: ln(1 + e^x) at -oo asks it of (1 + e^x) - 1, // whose own u - L is (1 + e^x) - 1 again, and that recursion overflowed the stack. Its next part, e^x, answers. + // t is real, so u has to be real on the side approached: ln(x) on the left of 0 is ln|x| + i pi, and e^ln(x), + // which is x and negative there, was read as e^t at -oo, positive, so floor(e^ln(x)) at 0 from the left was 0. private static int? SignThroughAChangeOfVariable(Entity expr, Variable x, Entity dest, ApproachFrom side) { var t = Variable.CreateTemp(expr.Vars); foreach (var part in expr.Nodes) { if (ReferenceEquals(part, expr) || part == x || !part.ContainsNode(x) - || expr.Substitute(part, t) is not { } outer || outer.ContainsNode(x)) + || expr.Substitute(part, t) is not { } outer || outer.ContainsNode(x) + || !IsRealOnEachSide(part, x, dest, side)) continue; if (EvalAssumingContinuous(part.Limit(x, dest, side)) is not Real { IsNaN: false } limit) return null; diff --git a/Sources/Tests/UnitTests/Calculus/AComplexPartIsNotARealVariableTest.cs b/Sources/Tests/UnitTests/Calculus/AComplexPartIsNotARealVariableTest.cs new file mode 100644 index 000000000..33966d73c --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AComplexPartIsNotARealVariableTest.cs @@ -0,0 +1,35 @@ +// +// 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.Core; +using AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A sign read through a change of variable puts a real t for a part u, so u has to be real on the side approached. + /// ln(x) on the left of 0 is ln|x| + i pi, and e^ln(x), which is x and negative there, was read as e^t at -oo, which is + /// positive: floor(e^ln(x)) at 0 from the left was 0 and sgn(e^ln(x)) was 1, where both are -1. They are declined now, + /// as they were in 2.6.0. Found by limitcheck; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class AComplexPartIsNotARealVariableTest + { + [Theory] + [InlineData("floor(exp(ln(x)))", ApproachFrom.Left)] + [InlineData("floor(exp(ln(x)))", ApproachFrom.BothSides)] + [InlineData("sgn(exp(ln(x)))", ApproachFrom.Left)] + [InlineData("floor(exp(ln(x)) + 1)", ApproachFrom.Left)] + public void ThePositiveReadingIsNotGiven(string input, ApproachFrom side) + => Assert.IsType(input.ToEntity().Limit("x", 0, side)); + + [Fact] + public void TheRightSideIsStillAnswered() + => Assert.Equal(MathS.FromString("0"), "floor(exp(ln(x)))".ToEntity().Limit("x", 0, ApproachFrom.Right).Evaled); + } +}