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: 10 additions & 5 deletions Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,12 @@ private static ApproachFrom[] Sides(Entity dest, ApproachFrom side)
/// </summary>
internal static int? SignNear(Entity expr, Variable x, Entity dest, ApproachFrom side)
{
// A difference with 0 is read as what it subtracts 0 from. A step function at a jump of 0 and a comparison
// with 0 both ask about g - 0, which is not simplified on the way, and every reading below carried the 0
// along: floor(sinh(2)^log(2, x)) at 0 from the right asked for the slope (g - 0) / (x - 0), which
// l'Hopital's rule took seven seconds to decline, where g / x is declined in under half a second.
while (expr is Minusf(var minuend, Integer { IsZero: true }))
expr = minuend;
if (EvalAssumingContinuous(expr.Limit(x, dest, side)) is not Real { IsNaN: false } limit)
return null;
// A non-zero limit, infinities included, fixes the sign on its own: the expression
Expand Down Expand Up @@ -1268,13 +1274,10 @@ private static ApproachFrom[] Sides(Entity dest, ApproachFrom side)
// A product or a quotient has the product of its parts' signs: sqrt(x) * x at 0 from the
// right has the slope sqrt(x), which tends to 0, and so had no sign. A positive base to a
// real power is positive: sqrt(1/x) at +oo has no slope to read, and e^x at -oo none either.
// A difference with 0 is read as what it subtracts 0 from: a step function at a jump of 0 and a
// comparison with 0 both ask about g - 0, and floor(x^(3/2)) at 0 from the right was declined
// for want of the sign x^(3/2) has as a power.
// floor(x^(3/2)) at 0 from the right was declined for want of the sign x^(3/2) has as a power.
private static int? SignOfTheFactors(Entity expr, Variable x, Entity dest, ApproachFrom side)
=> expr switch
{
Minusf(var minuend, Integer { IsZero: true }) => SignNear(minuend, x, dest, side),
Mulf(var left, var right) => SignOfTheProduct(left, right, x, dest, side),
Divf(var left, var right) => SignOfTheProduct(left, right, x, dest, side),
Powf(var @base, var exponent) when IsRealNear(exponent, x, dest, side)
Expand Down Expand Up @@ -1316,7 +1319,9 @@ private static ApproachFrom[] Sides(Entity dest, ApproachFrom side)
if (!Functions.TreeAnalyzer.IsRealValued(expr, x)
&& !(Functions.TreeAnalyzer.WhereRealValued(expr, x) is { } whereReal && HoldsNear(whereReal, x, dest, side) is true))
return null;
if (EvalAssumingContinuous((expr / (x - dest)).Limit(x, dest, side)) is not Real { IsNaN: false, IsZero: false } slope)
// Over x itself at 0, for the reason SignNear reads g - 0 as g.
var offset = dest is Integer { IsZero: true } ? (Entity)x : x - dest;
if (EvalAssumingContinuous((expr / offset).Limit(x, dest, side)) is not Real { IsNaN: false, IsZero: false } slope)
return null;
return slope.IsNegative == (side is ApproachFrom.Left) ? 1 : -1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// 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 System;
using System.Threading.Tasks;
using AngouriMath.Core;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A step function at a jump of 0, and a comparison with 0, ask for the sign of g - 0, and every reading of that sign
/// carried the 0 along: floor(sinh(2)^log(2, x)) at 0 from the right asked for the limit of (g - 0) / (x - 0), which
/// l'Hopital's rule took seven seconds to decline, where g / x is declined at once. Found by limitcheck; no issue was
/// filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ASignIsReadWithoutAZeroOffsetTest
{
// A minute: the answer is the same either way, and only a return to seven seconds a run, or worse, is caught.
[Fact]
public void AFloorAtAJumpOfZero()
{
var task = Task.Run(() => "floor(sinh(2)^log(2, x))".ToEntity().Limit("x", 0, ApproachFrom.Right));
Assert.True(task.Wait(TimeSpan.FromMinutes(1)));
Assert.Equal("0".ToEntity(), task.Result);
}

[Theory]
[InlineData("floor(x^(3/2))", ApproachFrom.Right, "0")]
[InlineData("floor(sin(x))", ApproachFrom.Left, "-1")]
[InlineData("floor(sin(x))", ApproachFrom.Right, "0")]
[InlineData("floor(-x^2)", ApproachFrom.BothSides, "-1")]
[InlineData("ceil(x^2)", ApproachFrom.BothSides, "1")]
public void AStepAtZeroIsReadAsBefore(string input, ApproachFrom side, string expected)
=> Assert.Equal(expected.ToEntity(), input.ToEntity().Limit("x", 0, side));
}
}
Loading