diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md
index fad9d71b9..01e44bd32 100644
--- a/BREAKING-CHANGES.md
+++ b/BREAKING-CHANGES.md
@@ -757,6 +757,36 @@ and it was `+oo`. It is `NaN`, as `(-x)^x` at 0 is. Measured on master `34d48113
| `x^(1/2 + x) / x` at 0 | `NaN` | unevaluated |
| `x^(x - 1)` at 0 from the right; `x^x`, `x^(x - 1) * x` at 0 from the left | `+oo`; `1`, `1` | unchanged |
+### A limit with a real and an imaginary infinity in it takes the one that grows faster
+
+**Silent: a wrong `+oo` or `-oo` becomes `+ooi`, `-ooi` or an unevaluated limit, and `+oo + +ooi` an answer or an
+unevaluated limit.** A limit whose real and imaginary parts both grow without bound was answered with the real part's
+infinity whichever grew faster, or left as `+oo + +ooi`. The rates are now compared, by the limit of the quotient of
+the two terms, of the same quotient with `arcsin(u)`, `arccos(u)` of an unbounded `u` read as `ln(u)`, whose modulus
+grows at the same rate, or of the quotient of their logarithms: where one dominates the limit is that one's infinity,
+and where they grow at the same rate the direction is off the axes, where the library writes no infinity, and the
+limit is left unevaluated, as it is for `x^(x - 1/3)` at 0 from the left. `+oo + +ooi` is not taken for a direction:
+it is also the value of `(1 + 2i) * +oo`. A product of two infinities on the axes points in the product of their
+directions, where `(pi/2 - +ooi) * +oo` was `+oo - +ooi`. A quotient whose numerator grows without a direction on the
+axes is still read as oo/oo by l'Hopital's rule, so `(3 + 4i) x / abs((3 + 4i) x)` at `+oo` stays `3/5 + 4/5 i`.
+Directions checked against mpmath at `x` up to `1e40`. Measured on master `409d68805` and on this branch
+([#2707](https://github.com/asc-community/AngouriMath/issues/2707)).
+
+| `.Limit(x, +oo)` | Was (`409d68805`) | Now |
+|---|---|---|
+| `i * x + ln(x)`, `i * x - ln(x)` | `+oo`, `-oo` | `+ooi` |
+| `2 * ln(x) + sqrt(-x)` | `+oo + +ooi` | `+ooi` |
+| `(i * ln(x) + 1) * x` | `+oo` | `+ooi` |
+| `arcsin(x) * ln(x)`, `arcsin(x) - ln(ln(x))` | `+oo`, `-oo` | `-ooi` |
+| `exp(x) + sqrt(-x)` | `+oo + +ooi` | `+oo` |
+| `i * x + x`, `(1 + i) * x`, `arcsin(x) + ln(x)`, `sqrt(arcsin(x) * x)` | `+oo` | unevaluated |
+| `sqrt(x) + sqrt(-x)`, `(-x)^(1/4)` | `+oo + +ooi` | unevaluated |
+| `arcsin(exp(x)) + sqrt(x)`, `arcsin(exp(x)) + ln(ln(x))`, `ln(1 - x) + arcsin(exp(x))` | `+oo` | `-ooi` |
+| `sqrt(x) - arcsin(exp(x))`, `arccos(exp(x)) + ln(x)` | `+oo` | `+ooi` |
+| `arcsin(x) + arcosh(-exp(x))`, `arcsin(x) - arcosh(-exp(x))` | `+oo - +ooi`, `-oo - +ooi` | `+oo`, `-oo` |
+| `arcsin(exp(x)) + x`, `2 * ln(x) + arccos(x)`, `arccos(x) + (-x)^(1/4)` | `+oo`, `+oo`, `+oo + +ooi` | unevaluated |
+| `x^2 + arcsin(exp(x))`, `arcsin(exp(x)) - x^2` | `+oo`, `-oo` | unchanged |
+
### A limit on a side that is not real is the infinity its direction settles in
**Not silent: an unevaluated limit becomes a directed infinity, and a wrong `+oo` becomes an unevaluated limit.** Where
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs
index ed08bf760..3b53f0a0f 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs
@@ -40,6 +40,8 @@ partial record Sumf
var (augendLimit, addendLimit) = (Augend.ComputeLimitDivideEtImpera(x, dist, side), Addend.ComputeLimitDivideEtImpera(x, dist, side));
if (AnInfinityBesideAConstant(augendLimit, addendLimit, x) is { } infinite)
return infinite;
+ if (AnInfinityOnEachAxis(Augend, augendLimit, Addend, addendLimit, subtracting: false, x, dist, side) is (true, var byRates))
+ return byRates;
var (augend, addend) =
(augendLimit, addendLimit) switch
{
@@ -62,6 +64,8 @@ partial record Minusf
var (minuendLimit, subtrahendLimit) = (Minuend.ComputeLimitDivideEtImpera(x, dist, side), Subtrahend.ComputeLimitDivideEtImpera(x, dist, side));
if (AnInfinityBesideAConstant(minuendLimit, subtrahendLimit is Real { IsFinite: false, IsNaN: false } infinity ? (-infinity).Evaled : subtrahendLimit, x) is { } infinite)
return infinite;
+ if (AnInfinityOnEachAxis(Minuend, minuendLimit, Subtrahend, subtrahendLimit, subtracting: true, x, dist, side) is (true, var byRates))
+ return byRates;
var (minuend, subtrahend) =
(minuendLimit, subtrahendLimit) switch
{
@@ -97,6 +101,179 @@ static bool IsAConstant(Entity? e, Variable x)
return null;
}
+ ///
+ /// The direction of an infinite limit that settles on one of the axes, as (real, imaginary) with one of them
+ /// 1 or -1 and the other 0: an infinite real part beside a finite imaginary one, as +oo + 3i, or the
+ /// other way round, as arcsin(x) at +oo, pi/2 - +ooi. for anything else,
+ /// including both parts infinite, which is no direction.
+ /// https://github.com/asc-community/AngouriMath/issues/2707
+ ///
+ private static (int Real, int Imaginary)? AxisOfAnInfinity(Entity? limit)
+ {
+ if (limit is null || limit.Nodes.Any(static node => node is Limitf)
+ || limit.Evaled is not Complex { IsNaN: false } value
+ || value.RealPart.IsNaN || value.ImaginaryPart.IsNaN)
+ return null;
+ return (value.RealPart.IsFinite, value.ImaginaryPart.IsFinite) switch
+ {
+ (false, true) => (value.RealPart.IsNegative ? -1 : 1, 0),
+ (true, false) => (0, value.ImaginaryPart.IsNegative ? -1 : 1),
+ _ => null
+ };
+ }
+
+ private static Entity TheInfinityAlong((int Real, int Imaginary) axis)
+ => axis switch
+ {
+ (> 0, _) => Real.PositiveInfinity,
+ (< 0, _) => Real.NegativeInfinity,
+ (_, > 0) => Complex.Create(Integer.Zero, Real.PositiveInfinity),
+ _ => Complex.Create(Integer.Zero, Real.NegativeInfinity)
+ };
+
+ [System.ThreadStatic] private static int ratesBeingCompared;
+
+ ///
+ /// How many limits the quotient of two terms may take to compare their rates. A quotient the machinery settles
+ /// is settled within it: across the 394 sums of the sweep behind
+ /// https://github.com/asc-community/AngouriMath/issues/2707, none settled without it and declined with it,
+ /// while unbudgeted the quotient of arccos(1/x) and sqrt(-1/x) at 0 from the left took 4 s and more each way
+ /// up, for a sum that was answered in 40 ms.
+ ///
+ private const int LimitsToCompareRates = 20;
+
+ ///
+ /// The limit of a sum or a difference of a term tending to a real infinity and one tending to an imaginary one,
+ /// or (false, null) where the terms are not of that shape.
+ ///
+ ///
+ /// Which term dominates is a comparison of rates, and it is made by the limit of their quotient: where it is 0,
+ /// the sum tends to the first term's infinity; where it is infinite, to the second's; where it is finite and not
+ /// 0, the quotient is imaginary, the sum's direction is off the axes, and the library writes no infinity there,
+ /// so the limit is declined, as for anything the quotient's limit does not settle. The arithmetic of the two
+ /// infinities makes none of this comparison: +oo + +ooi was read as +oo, which answered
+ /// i x + ln(x) at +oo with +oo where it is +ooi, and i x + x, whose direction is
+ /// (1 + i) / sqrt(2), with +oo too; or it was left as the answer, as for e^x + sqrt(-x), which is
+ /// +oo. https://github.com/asc-community/AngouriMath/issues/2707
+ ///
+ private static (bool Asked, Entity? Limit) AnInfinityOnEachAxis(Entity first, Entity? firstLimit, Entity second, Entity? secondLimit,
+ bool subtracting, Variable x, Entity dist, ApproachFrom side)
+ {
+ if (AxisOfAnInfinity(firstLimit) is not { } firstAxis || AxisOfAnInfinity(secondLimit) is not { } secondAxis
+ || (firstAxis.Real == 0) == (secondAxis.Real == 0))
+ return (false, null);
+ if (subtracting)
+ secondAxis = (-secondAxis.Real, -secondAxis.Imaginary);
+ // The quotient's limit asks for the terms' limits again, which are remembered; a comparison nested in it
+ // past this depth is declined rather than followed.
+ if (ratesBeingCompared >= 2)
+ return (true, null);
+ ratesBeingCompared++;
+ try
+ {
+ // Asked both ways up, since the machinery can settle one quotient and not its reciprocal:
+ // (-x)^(1/4) / ln(x) at +oo is left unevaluated, and ln(x) / (-x)^(1/4) is 0.
+ var order = OrderOfTheQuotient(second / first, x, dist, side) ?? -OrderOfTheQuotient(first / second, x, dist, side)
+ ?? (OfTheSameModulus(first, x, dist, side) is var firstModulus && OfTheSameModulus(second, x, dist, side) is var secondModulus
+ && (firstModulus is not null || secondModulus is not null)
+ ? OrderOfTheQuotient((secondModulus ?? second) / (firstModulus ?? first), x, dist, side)
+ ?? -OrderOfTheQuotient((firstModulus ?? first) / (secondModulus ?? second), x, dist, side)
+ : null)
+ ?? OrderOfTheLogarithms(MathS.Ln(second) / MathS.Ln(first), x, dist, side)
+ ?? -OrderOfTheLogarithms(MathS.Ln(first) / MathS.Ln(second), x, dist, side);
+ return (true, order switch
+ {
+ < 0 => TheInfinityAlong(firstAxis),
+ > 0 => TheInfinityAlong(secondAxis),
+ _ => null
+ });
+ }
+ finally { ratesBeingCompared--; }
+
+ // -1 where the quotient tends to 0, 1 where it tends to an infinity, 0 where to a finite number other than
+ // 0, and null where its limit is not settled.
+ static int? OrderOfTheQuotient(Entity quotient, Variable x, Entity dist, ApproachFrom side)
+ {
+ if (WithinABudget(LimitsToCompareRates, () => ComputeLimit(quotient, x, dist, side)) is not { } ratio || ratio.Nodes.Any(static node => node is Limitf)
+ || ratio.Evaled is not Complex { IsNaN: false } value || value.RealPart.IsNaN || value.ImaginaryPart.IsNaN)
+ return null;
+ if (!value.RealPart.IsFinite || !value.ImaginaryPart.IsFinite)
+ return 1;
+ return value.IsZero ? -1 : 0;
+ }
+
+ // The term with each inverse trigonometric factor of an argument growing without bound replaced by the
+ // logarithm of the argument, or null where it has no such factor. arcsin(u) and arccos(u) have a real part in
+ // [-pi/2, pi] and an imaginary part of modulus ln(2|u|) + o(1) as |u| grows, in any direction, and |ln(u)| is
+ // ln|u| + o(1); arcsec(v) and arccsc(v) are those of 1/v. Only factors are replaced, through products,
+ // quotients and real constant powers, so the modulus of the term changes by a factor tending to 1, and a
+ // quotient of two terms tends to 0 or to an infinity exactly when the quotient of what replaces them does.
+ // arcsin(e^x) / x^2 at +oo is left unevaluated either way up, and x / x^2 is 0.
+ static Entity? OfTheSameModulus(Entity term, Variable x, Entity dist, ApproachFrom side)
+ {
+ switch (term)
+ {
+ case Mulf(var multiplier, var multiplicand):
+ {
+ var (a, b) = (OfTheSameModulus(multiplier, x, dist, side), OfTheSameModulus(multiplicand, x, dist, side));
+ return a is null && b is null ? null : (a ?? multiplier) * (b ?? multiplicand);
+ }
+ case Divf(var dividend, var divisor):
+ {
+ var (a, b) = (OfTheSameModulus(dividend, x, dist, side), OfTheSameModulus(divisor, x, dist, side));
+ return a is null && b is null ? null : (a ?? dividend) / (b ?? divisor);
+ }
+ case Powf(var @base, var exponent) when !exponent.ContainsNode(x) && exponent.Evaled is Real:
+ return OfTheSameModulus(@base, x, dist, side) is { } baseModulus ? MathS.Pow(baseModulus, exponent) : null;
+ case Arcsinf(var argument): return OfAnUnboundedArgument(argument);
+ case Arccosf(var argument): return OfAnUnboundedArgument(argument);
+ case Arcsecantf(var argument): return OfAnUnboundedArgument(1 / argument);
+ case Arccosecantf(var argument): return OfAnUnboundedArgument(1 / argument);
+ default: return null;
+ }
+
+ Entity? OfAnUnboundedArgument(Entity argument)
+ => argument.ContainsNode(x)
+ && WithinABudget(LimitsToCompareRates, () => ComputeLimit(argument, x, dist, side)) is { } limit
+ && !limit.Nodes.Any(static node => node is Limitf)
+ && limit.Evaled is Complex { IsNaN: false } value && !value.RealPart.IsNaN && !value.ImaginaryPart.IsNaN
+ && (!value.RealPart.IsFinite || !value.ImaginaryPart.IsFinite)
+ ? MathS.Ln(argument)
+ : null;
+ }
+
+ // Where neither quotient settles, the quotient of the logarithms may: both terms grow in modulus and their
+ // arguments stay within (-pi, pi], so ln(b) / ln(a) has the limit of ln|b| / ln|a|, and a limit c other than
+ // 1 makes |b| / |a| = |a|^(c - 1 + o(1)), which tends to 0 below 1 and to +oo above it. arcsin(x) / x^x at
+ // +oo is left unevaluated either way up, and ln(arcsin(x)) / ln(x^x) is 0.
+ static int? OrderOfTheLogarithms(Entity quotient, Variable x, Entity dist, ApproachFrom side)
+ {
+ if (WithinABudget(LimitsToCompareRates, () => ComputeLimit(quotient, x, dist, side)) is not { } ratio || ratio.Nodes.Any(static node => node is Limitf)
+ || ratio.Evaled is not Complex { IsNaN: false } value || value.RealPart.IsNaN || !value.ImaginaryPart.IsZero)
+ return null;
+ if (!value.RealPart.IsFinite)
+ return value.RealPart.IsNegative ? null : 1;
+ return value.RealPart.Evaled is Real real && (real - 1).Evaled is Real { IsZero: false } offOne
+ ? offOne.IsNegative ? -1 : 1
+ : null;
+ }
+ }
+
+ ///
+ /// The limit of a product of two factors tending to infinities on the axes, not both real, or (false, null)
+ /// otherwise. Its direction is the product of theirs, and the arithmetic of the two does not give it:
+ /// arcsin(x) ln(x) at +oo is (pi/2 - +ooi) * +oo, which evaluates to +oo - +ooi, the
+ /// finite real part of the first multiplied out to an infinity, and it was answered +oo where it is
+ /// -ooi. https://github.com/asc-community/AngouriMath/issues/2707
+ ///
+ private static (bool Asked, Entity? Limit) AProductOfInfinitiesOnTheAxes(Entity? firstLimit, Entity? secondLimit)
+ {
+ if (AxisOfAnInfinity(firstLimit) is not { } a || AxisOfAnInfinity(secondLimit) is not { } b
+ || a.Imaginary == 0 && b.Imaginary == 0)
+ return (false, null);
+ return (true, TheInfinityAlong((a.Real * b.Real - a.Imaginary * b.Imaginary, a.Real * b.Imaginary + a.Imaginary * b.Real)));
+ }
+
///
/// The limit of a sum or a difference with each term whose limit is finite replaced by that limit, the
/// terms that are not left together as one sum, or where no term has a finite
@@ -154,6 +331,8 @@ partial record Mulf
return byMultiplier;
if (AnInfinityTimesASign(Multiplicand, Multiplier, multiplierLimit, dividing: false, x, dist, side) is { } byMultiplicand)
return byMultiplicand;
+ if (AProductOfInfinitiesOnTheAxes(multiplierLimit, multiplicandLimit) is (true, var byDirections))
+ return byDirections;
// 0 * oo from one side, with a quotient for one factor, is asked as that quotient
// with the other factor in its dividend, its whole limit once. Read as a product,
// nothing settles the form, and the rewriting solvers took x * (ln(x) / ln(2 + x)) at
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs
index 771579792..88db9e831 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Solvers.cs
@@ -85,8 +85,13 @@ internal static class LimitSolvers
// lim x->+oo (x!)^(1/x) came back 1 where it is +oo.
// https://github.com/asc-community/AngouriMath/issues/754
if (LimitFunctional.HoldsAnIndeterminatePowerForm(res)) return null;
+ // An infinite real part beside a finite imaginary one is that real infinity: the imaginary part stays
+ // bounded while the modulus grows. Beside an infinite imaginary part it says nothing, since which of
+ // the two dominates is a comparison of rates the arithmetic did not make: i x + ln(x) is +oo + +ooi
+ // here, and it was answered +oo where it is +ooi.
+ // https://github.com/asc-community/AngouriMath/issues/2707
if (!limit.RealPart.IsFinite)
- return limit.RealPart; // TODO: sometimes we get { oo + value * i } so we assume it is just infinity
+ return limit.ImaginaryPart.IsFinite ? limit.RealPart : null;
if (limit == Integer.Zero) return limit;
return res;
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
index adebd6b1c..caaec9a7e 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
@@ -721,7 +721,7 @@ internal static Entity CancelledDifference(Entity limit, Variable x)
var enclosingApproach = EnterApproach(x, dest);
var (outerComparing, outerRoot, outerCompared) = (comparingSides, descentRoot, comparedRoot);
(comparingSides, descentRoot, comparedRoot) = (false, null, null);
- try { return ComputeLimitWithinApproach(expr, x, dest, side, acceptNaN); }
+ try { return ComputeLimitWithinApproach(expr, x, dest, side, acceptNaN) is { } found && !HasNoDirection(found) ? found : null; }
finally
{
(comparingSides, descentRoot, comparedRoot) = (outerComparing, outerRoot, outerCompared);
@@ -848,7 +848,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
Entity? oneSided;
try { oneSided = expr.ComputeLimitDivideEtImpera(x, dest, side); }
finally { descentRoot = null; }
- if (oneSided is { } found && (acceptNaN || found.Evaled != MathS.NaN))
+ if (oneSided is { } found && (acceptNaN || found.Evaled != MathS.NaN) && !HasNoDirection(found))
return oneSided;
// The same rule the two-sided path falls through to, asked with the side it was
// given. l'Hopital's rule is stated one-sidedly to begin with -- the two-sided
@@ -894,7 +894,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
Entity? atInfinity;
try { atInfinity = expr.ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Left); }
finally { descentRoot = null; }
- if (atInfinity is { } found && found.Evaled != MathS.NaN)
+ if (atInfinity is { } found && found.Evaled != MathS.NaN && !HasNoDirection(found))
return found;
// l'Hopital's rule was only ever reached for a finite destination, so the
// textbook oo/oo cases at infinity -- ln(x) / x, x / e^x, ln(x) / sqrt(x) --
@@ -1019,6 +1019,17 @@ bool AnInfinityAgreedOffTheRealLine(Entity agreed)
}
}
+ ///
+ /// Whether evaluates to a number whose real and imaginary parts are both infinite, which
+ /// is no answer: it says the modulus grows and not in which direction, since which part dominates is a
+ /// comparison of rates the arithmetic of the two infinities does not make. Left as the answer, e^x + sqrt(-x)
+ /// at +oo was +oo + +ooi, where it is +oo.
+ /// https://github.com/asc-community/AngouriMath/issues/2707
+ ///
+ internal static bool HasNoDirection(Entity limit)
+ => limit.Evaled is Complex { RealPart: { IsFinite: false } real, ImaginaryPart: { IsFinite: false } imaginary }
+ && !real.IsNaN && !imaginary.IsNaN;
+
internal static Entity? ComputeLimitImpl(Entity expr, Variable x, Entity dist, ApproachFrom side) => dist switch
{
_ when !expr.ContainsNode(x) => expr,
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
index 1b10ceae0..febeb6d45 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs
@@ -850,6 +850,17 @@ private static bool DivergesDecidedly(Entity expr)
private static bool HoldsAnUndecidedLimit(Entity expr)
=> expr.Nodes.Any(node => node is Limitf);
+ ///
+ /// Whether , whose limit is undecided, still grows without bound
+ /// in modulus, as a term tending to infinity off the axes does: (3 + 4i) x at +oo has no infinity the
+ /// library writes, and is still the numerator of an oo/oo form in (3 + 4i) x / abs((3 + 4i) x), whose limit is
+ /// 3/5 + 4/5 i. Asked only beside a part that diverges decidedly.
+ /// https://github.com/asc-community/AngouriMath/issues/2707
+ ///
+ private static bool GrowsWithoutADirectionOnTheAxes(Entity part, Entity limit, Variable x, Entity dest, ApproachFrom side)
+ => HoldsAnUndecidedLimit(limit)
+ && DivergesDecidedly(EvalAssumingContinuous(MathS.Abs(part).Limit(x, dest, side)));
+
///
/// Whether what the machinery handed back is an indeterminate form rather than a value:
/// 0 / abs(0), (+oo * 0)^2 -- a shape assembled out of the parts' limits
@@ -2262,7 +2273,9 @@ bool VanishesIdentically(Entity polynomial)
&& QuotientOfDeterminateLimits(numExact, numLimit, denExact, denLimit) is { } determinate)
return determinate;
if (numLimit == 0 && denLimit == 0 ||
- DivergesDecidedly(numLimit) && DivergesDecidedly(denLimit))
+ DivergesDecidedly(numLimit) && DivergesDecidedly(denLimit)
+ || DivergesDecidedly(denLimit) && GrowsWithoutADirectionOnTheAxes(num, numLimit, x, dest, side)
+ || DivergesDecidedly(numLimit) && GrowsWithoutADirectionOnTheAxes(den, denLimit, x, dest, side))
if (num is not Number && den is not Number)
if (num.ContainsNode(x) && den.ContainsNode(x)
&& !HasAStepThatJumpsNear(expr, x, dest, side))
diff --git a/Sources/Tests/UnitTests/Calculus/RealAndImaginaryInfinitiesComparedTest.cs b/Sources/Tests/UnitTests/Calculus/RealAndImaginaryInfinitiesComparedTest.cs
new file mode 100644
index 000000000..def540515
--- /dev/null
+++ b/Sources/Tests/UnitTests/Calculus/RealAndImaginaryInfinitiesComparedTest.cs
@@ -0,0 +1,82 @@
+//
+// 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 Xunit;
+using static AngouriMath.Entity.Number;
+
+namespace AngouriMath.Tests.Calculus
+{
+ ///
+ /// A limit whose real and imaginary parts both grow without bound tends to the infinity of the part that grows
+ /// faster, and has no direction on either axis where they grow at the same rate. i x + ln(x) at x = 1e20 is
+ /// 46.1 + 1e20 i, and its limit is +ooi, not the real part's +oo. Values by mpmath.
+ /// https://github.com/asc-community/AngouriMath/issues/2707
+ ///
+ [Trait("Area", "Calculus")]
+ public sealed class RealAndImaginaryInfinitiesComparedTest
+ {
+ private static readonly Complex PositiveImaginaryInfinity = Complex.Create(Integer.Zero, Real.PositiveInfinity);
+ private static readonly Complex NegativeImaginaryInfinity = Complex.Create(Integer.Zero, Real.NegativeInfinity);
+
+ // arcsin(x) ln(x) at 1e20 is 72.3 - 2152.7i, arcsin(x) - ln(ln(x)) is -2.26 - 46.7i: arg/pi tends to -1/2.
+ [Theory]
+ [InlineData("i * x + ln(x)", true)]
+ [InlineData("i * x - ln(x)", true)]
+ [InlineData("2 * ln(x) + sqrt(-x)", true)]
+ [InlineData("(i * ln(x) + 1) * x", true)]
+ [InlineData("arcsin(x) * ln(x)", false)]
+ [InlineData("arcsin(x) - ln(ln(x))", false)]
+ [InlineData("arcsin(exp(x)) + sqrt(x)", false)]
+ [InlineData("sqrt(x) - arcsin(exp(x))", true)]
+ [InlineData("arcsin(exp(x)) + ln(ln(x))", false)]
+ [InlineData("arccos(exp(x)) + ln(x)", true)]
+ [InlineData("ln(1 - x) + arcsin(exp(x))", false)]
+ public void Issue2707_TheImaginaryPartGrowsFaster(string input, bool positive)
+ => Assert.Equal(positive ? PositiveImaginaryInfinity : NegativeImaginaryInfinity,
+ MathS.FromString(input).Limit("x", Real.PositiveInfinity));
+
+ // e^x + sqrt(-x) at 100 is 2.7E+43 + 10i, and was left as +oo + +ooi. arcsin(x) / x^x is not settled either
+ // way up, and the quotient of the logarithms is: ln(arcsin(x)) / ln(x^x) tends to 0. Nor is arcsin(e^x) / x^2,
+ // and |arcsin(e^x)| is x + ln(2) + o(1), so it is read as ln(e^x): arcsin(e^x) - x^2 at 10 is -98.43 - 10.69i.
+ [Theory]
+ [InlineData("exp(x) + sqrt(-x)", "+oo")]
+ [InlineData("x - i * ln(x)", "+oo")]
+ [InlineData("sqrt(-x) - x", "-oo")]
+ [InlineData("arcsin(x) + x^x", "+oo")]
+ [InlineData("arcsin(x) - x^x", "-oo")]
+ [InlineData("arcsin(exp(x)) - x^2", "-oo")]
+ [InlineData("arcsin(exp(x)) + x^2", "+oo")]
+ [InlineData("x^2 - arcsin(exp(x))", "+oo")]
+ [InlineData("arcsin(x) + arcosh(-exp(x))", "+oo")]
+ [InlineData("arcsin(x) - arcosh(-exp(x))", "-oo")]
+ public void Issue2707_TheRealPartGrowsFaster(string input, string expected)
+ => Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", Real.PositiveInfinity));
+
+ // The direction settles off the axes, at pi/4 for i x + x and at -pi/4 for arcsin(x) + ln(x) and for
+ // sqrt(arcsin(x) x): -0.247 pi at 1e40. No infinity the library writes points along it.
+ [Theory]
+ [InlineData("i * x + x")]
+ [InlineData("(1 + i) * x")]
+ [InlineData("arcsin(x) + ln(x)")]
+ [InlineData("arcsin(exp(x)) + x")]
+ [InlineData("2 * ln(x) + arccos(x)")]
+ [InlineData("sqrt(arcsin(x) * x)")]
+ public void Issue2707_IsLeftUnevaluatedOffTheAxes(string input)
+ => Assert.IsType(MathS.FromString(input).Limit("x", Real.PositiveInfinity));
+
+ // A real infinity beside a bounded imaginary part, and an imaginary one beside a bounded real part, are as
+ // they were.
+ [Theory]
+ [InlineData("x + i", "+oo")]
+ [InlineData("i * x + 1", "1 + +oo * i")]
+ [InlineData("arcosh(-x)", "+oo")]
+ [InlineData("i * x * ln(x)", "+oo * i")]
+ public void Issue2707_IsAsItWas(string input, string expected)
+ => Assert.Equal(MathS.FromString(expected).Evaled, MathS.FromString(input).Limit("x", Real.PositiveInfinity).Evaled);
+ }
+}