Skip to content

Commit b04f46c

Browse files
Integrate a power of a logarithm beside a linear in another as two powers of the first (#2094)
(a + b L)^p (d + e M), with L = ln(c x^n) and M = ln(f x^r), was declined, and so was it with M = L. M is (r/n) L + delta, where delta = M - (r/n) L is constant between the cuts: its derivative is r/x - (r/n)(n/x) = 0. So d + e M is alpha (a + b L) + beta with alpha = e r/(n b), and the integrand is alpha (a + b L)^(p + 1) + beta (a + b L)^p beside what else is there, each answered by the rules for a power of one logarithm. delta is written back in the answer. Asked after the product of powers read as a derivative, which writes p x^m ln(x)^n ((m + 1) ln(x) + n + 1) as p x^(m + 1) ln(x)^(n + 1), where this would write a sum of gamma functions. Part of #2075. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent e2cf38a commit b04f46c

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18314,6 +18314,75 @@ private static (Entity Binomial, Entity Offset, Entity Scale, Entity Exponent)?
1831418314
return exponent is null ? null : (sum, offset, scale, exponent.InnerSimplified);
1831518315
}
1831618316

18317+
/// <summary>
18318+
/// A power that is not whole of a linear in one logarithm <c>L = ln(c x^n)</c>, beside a linear in it or in another
18319+
/// logarithm of a power of x, <c>(a + b L)^p (d + e M)</c> with <c>M = ln(f x^r)</c>. M is <c>(r/n) L + delta</c>,
18320+
/// where <c>delta = M - (r/n) L</c> is constant between the cuts, its derivative being <c>r/x - (r/n)(n/x) = 0</c>.
18321+
/// So <c>d + e M</c> is <c>alpha (a + b L) + beta</c>, with <c>alpha = e r/(n b)</c> and
18322+
/// <c>beta = d + e delta - alpha a</c>, and the integrand is <c>alpha (a + b L)^(p + 1) + beta (a + b L)^p</c> beside
18323+
/// what else is there: powers of the one logarithm, which the rules for those answer. delta is written back in the
18324+
/// answer. Rubi's 3.1.5. https://github.com/asc-community/AngouriMath/issues/2075
18325+
/// </summary>
18326+
internal static Entity? SolveAPowerOfALogarithmBesideALinearInALogarithm(Entity expr, Entity.Variable x, bool integrateByParts)
18327+
{
18328+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow || expr is not (Mulf or Divf))
18329+
return null;
18330+
var (numerator, denominator) = expr is Divf(var above, var below) ? (above, below) : (expr, (Entity)Number.Integer.One);
18331+
Powf? power = null;
18332+
Entity? linear = null;
18333+
Entity beside = Number.Integer.One;
18334+
foreach (var factor in Mulf.LinearChildren(numerator))
18335+
{
18336+
if (power is null && factor is Powf(var @base, var exponent) candidate && exponent is not Number.Integer
18337+
&& !exponent.ContainsNode(x) && TheLinearInOneLogarithm(@base, x) is not null)
18338+
power = candidate;
18339+
else if (linear is null && factor.ContainsNode(x) && factor is Logf or Sumf or Minusf && TheLinearInOneLogarithm(factor, x) is not null)
18340+
linear = factor;
18341+
else
18342+
beside *= factor;
18343+
}
18344+
if (power is null || linear is null
18345+
|| TheLinearInOneLogarithm(power.Base, x) is not var (logarithm, degree, a, b)
18346+
|| TheLinearInOneLogarithm(linear, x) is not var (other, otherDegree, d, e))
18347+
return null;
18348+
var ratio = (otherDegree / degree).InnerSimplified;
18349+
Entity delta = other == logarithm ? Number.Integer.Zero : Variable.CreateUnique(expr, "delta_log");
18350+
var alpha = e * ratio / b;
18351+
var beta = d + e * delta - alpha * a;
18352+
beside /= denominator;
18353+
if (Integration.ComputeAsAQuestionOfItsOwn((beside * MathS.Pow(power.Base, power.Exponent + 1)).InnerSimplified, x, integrateByParts) is not { } raised
18354+
|| Integration.ComputeAsAQuestionOfItsOwn((beside * power).InnerSimplified, x, integrateByParts) is not { } asWritten)
18355+
return null;
18356+
var answer = alpha * raised + beta * asWritten;
18357+
if (delta is Variable constant)
18358+
answer = answer.Substitute(constant, other - ratio * logarithm);
18359+
return answer.Nodes.Any(node => node == MathS.NaN) ? null : answer;
18360+
}
18361+
18362+
/// <summary>
18363+
/// <paramref name="expr"/> as <c>a + b L</c>, linear in one logarithm <c>L = ln(c x^n)</c> and free of x otherwise,
18364+
/// with the logarithm, <c>n</c>, <c>a</c> and <c>b</c>; or <see langword="null"/>.
18365+
/// </summary>
18366+
private static (Entity Logarithm, Entity Degree, Entity Offset, Entity Slope)? TheLinearInOneLogarithm(Entity expr, Entity.Variable x)
18367+
{
18368+
Entity? logarithm = null;
18369+
foreach (var node in expr.Nodes)
18370+
if (node is Logf(var @base, var antilogarithm) && @base == MathS.e && antilogarithm.ContainsNode(x))
18371+
{
18372+
if (logarithm is not null && node != logarithm)
18373+
return null;
18374+
logarithm = node;
18375+
}
18376+
if (logarithm is not Logf(_, var argument) || TheMonomial(argument, x) is not var (_, degree) || TreeAnalyzer.IsZero(degree))
18377+
return null;
18378+
var l = Variable.CreateUnique(expr, "l_log");
18379+
var inL = expr.Replace(node => node == logarithm ? l : node);
18380+
if (inL.ContainsNode(x) || !TreeAnalyzer.TryGetPolyLinear(inL, l, out var slope, out var offset)
18381+
|| slope.ContainsNode(l) || offset.ContainsNode(l) || TreeAnalyzer.IsZero(slope))
18382+
return null;
18383+
return (logarithm, degree, offset, slope);
18384+
}
18385+
1831718386
/// <summary>
1831818387
/// Whether <paramref name="factor"/> is a power that is not whole of something holding a logarithm of something in
1831918388
/// <paramref name="x"/>, or an exponential of something in <paramref name="x"/> that is not linear in it.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,10 @@ internal static bool ASumOverRootsWouldAnswer
18381838
// And a product of powers that is the derivative of one with symbolic exponents, its
18391839
// constant read at a point where the quotient of the brackets does not simplify free of x.
18401840
if ((answer = IndefiniteIntegralSolver.SolveAsTheDerivativeOfAProductOfPowersReadAtAPoint(expr, x, integrateByParts)) is { }) return answer;
1841+
// A power of a logarithm beside a linear in another as two powers of the first, after the product of powers read
1842+
// as a derivative: p x^m ln(x)^n ((m + 1) ln(x) + n + 1) is p x^(m + 1) ln(x)^(n + 1) there, and a sum of gamma
1843+
// functions here. https://github.com/asc-community/AngouriMath/issues/2075
1844+
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfALogarithmBesideALinearInALogarithm(expr, x, integrateByParts)) is { }) return answer;
18411845
// An arcoth of a linear as its artanh plus a constant, last of all, so that every arcoth
18421846
// answered as written keeps that answer: `acoth(x)^2/(1 - x^2)^2` is
18431847
// `(atanh(x) + K)^2/(1 - x^2)^2` with `K = acoth(x) - atanh(x)`, constant where it is

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ public void APositiveRateIsTakenOutOfThePower()
157157
[InlineData("(a - b*ln(c*(d + f/x^(1/3))^2))^n/x^2")]
158158
public void APowerOfXBesideAFunctionOfABinomial(string integrand) => DifferentiatesBack(integrand);
159159

160+
/// <summary>
161+
/// A power of a linear in one logarithm of a power of x beside a linear in it or in another, which is the first
162+
/// times a ratio of degrees plus a constant between the cuts: two powers of the one logarithm. Rubi's 3.1.5.
163+
/// </summary>
164+
[Theory]
165+
[InlineData("(f - b*ln(c*x^2))^n*(d + a*ln(f*x^3))")]
166+
[InlineData("x^2*(f - b*ln(c*x))^n*(d + a*ln(f*x^3))")]
167+
[InlineData("(f - b*ln(c*x))^n*(d + a*ln(c*x))/x^2")]
168+
[InlineData("(d*x)^m*(f - b*ln(c*x^2))^n*ln(a*x)")]
169+
public void APowerOfALogarithmBesideALinearInALogarithm(string integrand) => DifferentiatesBack(integrand);
170+
160171
/// <summary>
161172
/// Not where the integral is elementary, an exponential integral or an error function: those keep the form
162173
/// they had.

0 commit comments

Comments
 (0)