|
| 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.Core; |
| 9 | +using AngouriMath.Extensions; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace AngouriMath.Tests.Calculus |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// f floor(g), f ceil(g) and f round(g), where f tends to 0 and g is real, have the limit of f g: the step is within 1 |
| 16 | + /// of its argument, so the two products differ by f times something bounded. x floor(2/x) at 0 was left unevaluated, |
| 17 | + /// each side stopping at 0 * floor(+-oo), where it is 2. Each value here was checked at x = +-7/3 * 10^-k for k from 4 |
| 18 | + /// to 8. No issue was filed. |
| 19 | + /// </summary> |
| 20 | + [Trait("Area", "Calculus")] |
| 21 | + public sealed class AStepOfAnUnboundedArgumentTimesAVanishingFactorTest |
| 22 | + { |
| 23 | + [Theory] |
| 24 | + [InlineData("x * floor(2/x)", "0", "2")] |
| 25 | + [InlineData("floor(1/x) * sin(x)", "0", "1")] |
| 26 | + [InlineData("x^2 * floor(1/x^2)", "0", "1")] |
| 27 | + [InlineData("x * ceil(1/x)", "0", "1")] |
| 28 | + [InlineData("x * round(1/x)", "0", "1")] |
| 29 | + [InlineData("x * ceil(-2/x)", "0", "-2")] |
| 30 | + [InlineData("-3 * x * floor(1/x)", "0", "-3")] |
| 31 | + [InlineData("x^2 * floor(1/x)", "0", "0")] |
| 32 | + [InlineData("(x - 1) * floor(1/(x - 1))", "1", "1")] |
| 33 | + [InlineData("x * floor(2/x) + 3", "0", "5")] |
| 34 | + [InlineData("floor(x) / x", "+oo", "1")] |
| 35 | + public void FromEachSideAndBoth(string input, string destination, string expected) |
| 36 | + { |
| 37 | + var expr = input.ToEntity(); |
| 38 | + Assert.Equal(expected.ToEntity(), expr.Limit("x", destination, ApproachFrom.Left).InnerSimplified); |
| 39 | + Assert.Equal(expected.ToEntity(), expr.Limit("x", destination, ApproachFrom.Right).InnerSimplified); |
| 40 | + Assert.Equal(expected.ToEntity(), expr.Limit("x", destination).InnerSimplified); |
| 41 | + } |
| 42 | + |
| 43 | + // Where f g has no limit, neither has f floor(g): the sides diverge in different directions, so there is none. |
| 44 | + [Theory] |
| 45 | + [InlineData("x * floor(1/x^2)")] |
| 46 | + [InlineData("sqrt(abs(x)) * floor(1/x)")] |
| 47 | + public void SidesThatDivergeApart(string input) |
| 48 | + { |
| 49 | + var expr = input.ToEntity(); |
| 50 | + Assert.Equal(Entity.Number.Real.NegativeInfinity, expr.Limit("x", 0, ApproachFrom.Left)); |
| 51 | + Assert.Equal(Entity.Number.Real.PositiveInfinity, expr.Limit("x", 0, ApproachFrom.Right)); |
| 52 | + Assert.Equal(MathS.NaN, expr.Limit("x", 0)); |
| 53 | + } |
| 54 | + |
| 55 | + // x floor(sin(1/x)/x) is sin(1/x) up to a term that vanishes, and has no limit. The rule takes only a value from |
| 56 | + // the limit of f g, so it leaves this unevaluated rather than claiming anything. |
| 57 | + [Fact] |
| 58 | + public void AnOscillatingProductIsNotAnswered() |
| 59 | + => Assert.IsType<Entity.Limitf>("x * floor(sin(1/x)/x)".ToEntity().Limit("x", 0)); |
| 60 | + } |
| 61 | +} |
0 commit comments