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
13 changes: 13 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ filed.
| `"floor(log(x - 1, x))".ToEntity().Limit("x", 1, ApproachFrom.Right)` | `limitright(floor(log(x - 1, x)), x, 1)` | `-1` |
| `"floor(x / log(x, x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `limitleft(floor(x / log(x, x)), x, 0)` | `-1` |

### A power of a power of a positive base is one power in a limit

**Silent: in a limit, `(g^a)^b` with `a` and `b` real constants, `b` not an integer, is read as `g^(a b)` where `g` is
positive near the point on each side approached.** The two are equal for a positive `g` and not for a negative one --
`sqrt(x^3)` is `i |x|^(3/2)` for `x < 0`, where `x^(3/2)` is `-i |x|^(3/2)` -- so a limit from the left, or from both
sides, of such a root is read as before. Read as written, `sqrt(x^3) / x` at 0 from the right was 0 only after 4
seconds, and `floor(sqrt(x^3))` after 6; each now takes under 0.2 s. One limit 2.6.0 left unevaluated is answered.
Found by limitcheck; no issue was filed.

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"sinh(arctan(x))^sqrt(x * x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(((e ^ arctan(x) - e ^ (-arctan(x))) / 2) ^ sqrt(x * x), x, 0)` | `1` |

### A real power in a limit is read by its order

**Silent: in a limit, a factor `g^a` with `a` a constant that is not an integer, and `g` tending to 0 or to +oo, is read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,26 @@ private static Entity LogarithmOfAPower(Entity node, Variable x, Entity dest, Ap
};
}

/// <summary>
/// A power of a power to constant real exponents, (g^a)^b, as g^(a b) where g is positive near the point on each
/// side approached.
/// </summary>
/// <remarks>
/// For g positive and a, b real, g^a is positive and (g^a)^b is g^(a b). Where g is negative it is not:
/// sqrt(x^3) is i |x|^(3/2) for x &lt; 0, and x^(3/2) is -i |x|^(3/2). Read as written, sqrt(x^3) / x at 0 from the
/// right was 0 only after four seconds of l'Hopital's rule, each step another root over a power, where x^(3/2) / x
/// is sqrt(x) at once; floor(sqrt(x^3)) and sgn(sqrt(x^3)) asked it for the sign of sqrt(x^3). An integer outer
/// exponent is left to the normalisation, which takes (g^a)^n apart whatever the sign of g. Found by limitcheck;
/// no issue was filed.
/// </remarks>
private static Entity PowerOfAPower(Entity node, Variable x, Entity dest, ApproachFrom side)
=> node is Powf(Powf(var @base, var inner), var outer)
&& @base.ContainsNode(x) && !inner.ContainsNode(x) && !outer.ContainsNode(x)
&& inner.Evaled is Real { IsFinite: true } && outer.Evaled is Real { IsFinite: true } and not Integer
&& SignOnEachSide(@base, x, dest, side) is 1
? MathS.Pow(@base, (inner * outer).InnerSimplified)
: node;

/// <summary>
/// A logarithm to a base other than e as a quotient of natural logarithms.
/// </summary>
Expand Down Expand Up @@ -492,6 +512,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat

expr = expr.Replace(ExpandLogarithm);
expr = expr.Replace(node => LogarithmOfAPower(node, x, dest, side));
expr = expr.Replace(node => PowerOfAPower(node, x, dest, side));

// In front of both paths, not only the two-sided one. Each of these is guarded on
// a two-sided limit, and a two-sided limit that exists is also the limit from
Expand Down
43 changes: 43 additions & 0 deletions Sources/Tests/UnitTests/Calculus/APowerOfAPowerIsOnePowerTest.cs
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 AngouriMath.Core;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// In a limit, (g^a)^b with a and b real constants is g^(a b) where g is positive near the point. Read as written,
/// sqrt(x^3) / x at 0 from the right was 0 only after four seconds of l'Hopital's rule, and floor(sqrt(x^3)) took six,
/// asking it for the sign of sqrt(x^3). Where g is negative the two differ, so from the left and from both sides
/// nothing changes. Found by limitcheck; no issue was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class APowerOfAPowerIsOnePowerTest
{
[Theory]
[InlineData("sqrt(x^3) / x", "0")]
[InlineData("floor(sqrt(x^3))", "0")]
[InlineData("sgn(sqrt(x^3))", "1")]
[InlineData("sgn(sqrt(x^5))", "1")]
[InlineData("sqrt(x^3) / x^(3/2)", "1")]
public void AtZeroFromTheRight(string input, string expected)
=> Assert.Equal(expected.ToEntity(), input.ToEntity().Limit("x", 0, ApproachFrom.Right));

[Fact]
public void BothSidesOfAQuotientAgree()
=> Assert.Equal("0".ToEntity(), "sqrt(x^3) / x".ToEntity().Limit("x", 0, ApproachFrom.BothSides));

// Left of 0, x^3 is negative and sqrt(x^3) is imaginary: floor of it has no limit to give.
[Theory]
[InlineData(ApproachFrom.Left)]
[InlineData(ApproachFrom.BothSides)]
public void ANegativeBaseIsLeftAlone(ApproachFrom side)
=> Assert.IsType<Entity.Limitf>("floor(sqrt(x^3))".ToEntity().Limit("x", 0, side));
}
}
Loading