diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs
index 34cf23b18..384a49f5f 100644
--- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs
@@ -7955,6 +7955,20 @@ private static Entity SquarefreePartAsWritten(Entity denominator, Entity.Variabl
/// logarithm of in it, the expression linear in that logarithm,
/// and the logarithm's argument a constant times a power of .
///
+ ///
+ /// Whether is built from and constants by
+ /// products, quotients and powers with exponents free of , however
+ /// nested: c (d x^m)^n, and not x + 1 or e^x.
+ ///
+ private static bool IsAProductOfPowersOfTheVariable(Entity expr, Entity.Variable x)
+ => !expr.ContainsNode(x) || expr == x || expr switch
+ {
+ Mulf(var left, var right) => IsAProductOfPowersOfTheVariable(left, x) && IsAProductOfPowersOfTheVariable(right, x),
+ Divf(var left, var right) => IsAProductOfPowersOfTheVariable(left, x) && IsAProductOfPowersOfTheVariable(right, x),
+ Powf(var @base, var exponent) => !exponent.ContainsNode(x) && IsAProductOfPowersOfTheVariable(@base, x),
+ _ => false,
+ };
+
private static bool IsAffineInALogarithmOfAPowerOfX(Entity expr, Entity.Variable x)
{
Entity? logarithm = null;
@@ -7967,6 +7981,14 @@ private static bool IsAffineInALogarithmOfAPowerOfX(Entity expr, Entity.Variable
}
if (logarithm is not Logf(_, var antilogarithm))
return false;
+ // The argument c x^r, read before it is differentiated: products, quotients and
+ // powers of x and of constants, however nested -- `c (d x^m)^n` -- and nothing
+ // else of x. Simplifying the logarithmic derivative of any argument was what took
+ // `atanh(tanh(a + b x))^4` -- a fourth power of a logarithm of a quotient of
+ // exponentials, a 300 ms answer before -- past three minutes on the way to
+ // declining.
+ if (!IsAProductOfPowersOfTheVariable(antilogarithm, x))
+ return false;
// The argument c x^r: its logarithmic derivative is r/x.
var rate = Functions.PartialFractions.Bare((antilogarithm.Differentiate(x) * x / antilogarithm).Simplify());
if (rate.ContainsNode(x) || rate.Nodes.Any(node => node == MathS.NaN))
@@ -9894,6 +9916,13 @@ bool TryReadLinear(Entity linear, out Entity slope, out Entity offset)
(slope, offset) = (readSlope, readOffset);
return !TreeAnalyzer.IsZero(slope);
}
+ // Only a rational spelling is read by its derivative: a leaf with a function
+ // of x in it is not a linear however it simplifies, and simplifying it costs.
+ if (!IsARationalFunction(linear, x))
+ {
+ (slope, offset) = (Number.Integer.Zero, Number.Integer.Zero);
+ return false;
+ }
slope = Functions.PartialFractions.Bare(linear.Differentiate(x).Simplify());
offset = Functions.PartialFractions.Bare((linear - slope * x).Simplify());
return !slope.ContainsNode(x) && !offset.ContainsNode(x) && !TreeAnalyzer.IsZero(slope)
diff --git a/Sources/Tests/UnitTests/Calculus/LogarithmOfARationalFunctionByPartsTest.cs b/Sources/Tests/UnitTests/Calculus/LogarithmOfARationalFunctionByPartsTest.cs
index 7d4af054c..b616c187b 100644
--- a/Sources/Tests/UnitTests/Calculus/LogarithmOfARationalFunctionByPartsTest.cs
+++ b/Sources/Tests/UnitTests/Calculus/LogarithmOfARationalFunctionByPartsTest.cs
@@ -119,5 +119,23 @@ private static void DifferentiatesBack(string integrand)
[InlineData("(a + b*ln(c*(d*x^m)^n))^4")]
[InlineData("(a + b*ln(c*(d*(f + g*x)^m)^n))^4")]
public void APowerTimesAPowerOfAnAffineLogarithm(string integrand) => DifferentiatesBack(integrand);
+
+ ///
+ /// A power of a logarithm whose argument is not c x^r is read as not one before
+ /// its logarithmic derivative is simplified: atanh(tanh(a + b x))^4 is a fourth
+ /// power of a logarithm of a quotient of exponentials, answered in 300 ms, and the
+ /// simplification of that derivative on the way to declining took it past three
+ /// minutes. Bounded by , which is far past the
+ /// answer and far short of that.
+ ///
+ [Theory]
+ [InlineData("atanh(tanh(a + b*x))^4")]
+ [InlineData("acoth(coth(a + b*x))")]
+ public void AnAffineLogarithmIsReadBeforeItsDerivativeIsSimplified(string integrand)
+ {
+ var watch = System.Diagnostics.Stopwatch.StartNew();
+ DifferentiatesBack(integrand);
+ Assert.True(watch.Elapsed < IntegrationDecline.Guard, $"took {watch.Elapsed}");
+ }
}
}