Skip to content

Commit e780ce9

Browse files
A power of a logarithm is read as one of c x^r before its derivative is simplified (#1407)
atanh(tanh(a + b x))^4 was answered in 300 ms and, since #1379, ran past three minutes: the reader for a power of A + B ln(c x^r) simplified the logarithmic derivative of any single logarithm's argument to see whether it was r/x, and the argument here is a quotient of exponentials whose derivative the simplifier turns over for minutes on the way to no. The argument is read first -- products, quotients and powers of x and of constants, however nested, c (d x^m)^n -- and anything else is not this shape without a derivative being taken. The reader of a linear in the quotient-of-linears rule gets the same guard: a leaf with a function of x in it is not a linear however it simplifies. Family 7's atanh(tanh) and acoth(coth) rows are answers again, in 300 ms and 41 ms; the 1774-problem suite is unchanged at 1706 with 0 wrong. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7b7f28e commit e780ce9

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8125,6 +8125,20 @@ private static Entity SquarefreePartAsWritten(Entity denominator, Entity.Variabl
81258125
/// logarithm of <paramref name="x"/> in it, the expression linear in that logarithm,
81268126
/// and the logarithm's argument a constant times a power of <paramref name="x"/>.
81278127
/// </summary>
8128+
/// <summary>
8129+
/// Whether <paramref name="expr"/> is built from <paramref name="x"/> and constants by
8130+
/// products, quotients and powers with exponents free of <paramref name="x"/>, however
8131+
/// nested: <c>c (d x^m)^n</c>, and not <c>x + 1</c> or <c>e^x</c>.
8132+
/// </summary>
8133+
private static bool IsAProductOfPowersOfTheVariable(Entity expr, Entity.Variable x)
8134+
=> !expr.ContainsNode(x) || expr == x || expr switch
8135+
{
8136+
Mulf(var left, var right) => IsAProductOfPowersOfTheVariable(left, x) && IsAProductOfPowersOfTheVariable(right, x),
8137+
Divf(var left, var right) => IsAProductOfPowersOfTheVariable(left, x) && IsAProductOfPowersOfTheVariable(right, x),
8138+
Powf(var @base, var exponent) => !exponent.ContainsNode(x) && IsAProductOfPowersOfTheVariable(@base, x),
8139+
_ => false,
8140+
};
8141+
81288142
private static bool IsAffineInALogarithmOfAPowerOfX(Entity expr, Entity.Variable x)
81298143
{
81308144
Entity? logarithm = null;
@@ -8137,6 +8151,14 @@ private static bool IsAffineInALogarithmOfAPowerOfX(Entity expr, Entity.Variable
81378151
}
81388152
if (logarithm is not Logf(_, var antilogarithm))
81398153
return false;
8154+
// The argument c x^r, read before it is differentiated: products, quotients and
8155+
// powers of x and of constants, however nested -- `c (d x^m)^n` -- and nothing
8156+
// else of x. Simplifying the logarithmic derivative of any argument was what took
8157+
// `atanh(tanh(a + b x))^4` -- a fourth power of a logarithm of a quotient of
8158+
// exponentials, a 300 ms answer before -- past three minutes on the way to
8159+
// declining.
8160+
if (!IsAProductOfPowersOfTheVariable(antilogarithm, x))
8161+
return false;
81408162
// The argument c x^r: its logarithmic derivative is r/x.
81418163
var rate = Functions.PartialFractions.Bare((antilogarithm.Differentiate(x) * x / antilogarithm).Simplify());
81428164
if (rate.ContainsNode(x) || rate.Nodes.Any(node => node == MathS.NaN))
@@ -10064,6 +10086,13 @@ bool TryReadLinear(Entity linear, out Entity slope, out Entity offset)
1006410086
(slope, offset) = (readSlope, readOffset);
1006510087
return !TreeAnalyzer.IsZero(slope);
1006610088
}
10089+
// Only a rational spelling is read by its derivative: a leaf with a function
10090+
// of x in it is not a linear however it simplifies, and simplifying it costs.
10091+
if (!IsARationalFunction(linear, x))
10092+
{
10093+
(slope, offset) = (Number.Integer.Zero, Number.Integer.Zero);
10094+
return false;
10095+
}
1006710096
slope = Functions.PartialFractions.Bare(linear.Differentiate(x).Simplify());
1006810097
offset = Functions.PartialFractions.Bare((linear - slope * x).Simplify());
1006910098
return !slope.ContainsNode(x) && !offset.ContainsNode(x) && !TreeAnalyzer.IsZero(slope)

‎Sources/Tests/UnitTests/Calculus/LogarithmOfARationalFunctionByPartsTest.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,23 @@ private static void DifferentiatesBack(string integrand)
119119
[InlineData("(a + b*ln(c*(d*x^m)^n))^4")]
120120
[InlineData("(a + b*ln(c*(d*(f + g*x)^m)^n))^4")]
121121
public void APowerTimesAPowerOfAnAffineLogarithm(string integrand) => DifferentiatesBack(integrand);
122+
123+
/// <summary>
124+
/// A power of a logarithm whose argument is not <c>c x^r</c> is read as not one before
125+
/// its logarithmic derivative is simplified: <c>atanh(tanh(a + b x))^4</c> is a fourth
126+
/// power of a logarithm of a quotient of exponentials, answered in 300 ms, and the
127+
/// simplification of that derivative on the way to declining took it past three
128+
/// minutes. Bounded by <see cref="IntegrationDecline.Guard"/>, which is far past the
129+
/// answer and far short of that.
130+
/// </summary>
131+
[Theory]
132+
[InlineData("atanh(tanh(a + b*x))^4")]
133+
[InlineData("acoth(coth(a + b*x))")]
134+
public void AnAffineLogarithmIsReadBeforeItsDerivativeIsSimplified(string integrand)
135+
{
136+
var watch = System.Diagnostics.Stopwatch.StartNew();
137+
DifferentiatesBack(integrand);
138+
Assert.True(watch.Elapsed < IntegrationDecline.Guard, $"took {watch.Elapsed}");
139+
}
122140
}
123141
}

0 commit comments

Comments
 (0)