Skip to content

Commit e2cf38a

Browse files
Integrate a power of x beside a power of a logarithm of a binomial in that binomial (#2093)
x^k beside a power that is not whole of a logarithm of one binomial a + b x^q is written in t = a + b x^q where N = (k + 1)/q is a whole number above 0. Then x^k dx is (t - a)^(N - 1) dt/(q b^N) on every branch, since x^(k + 1) = (x^q)^N and x^(k + 1 - q) = (x^q)^(N - 1) are whole powers of x^q, and the integrand in t is a polynomial beside the logarithm's power, which the rules answer: (a + b ln(c (d + e/sqrt(x))))^p/x^2 is -2/e^2 times the integral of (t - d) (a + b ln(c t))^p. An exponential of a binomial is left to the exponential rules, which write it in its own base. 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 92227d9 commit e2cf38a

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18199,6 +18199,121 @@ bool Read(Entity node, bool insideASum)
1819918199
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
1820018200
}
1820118201

18202+
/// <summary>
18203+
/// A power <c>x^k</c> beside a power of a logarithm of one binomial <c>a + b x^q</c>, written in
18204+
/// <c>t = a + b x^q</c>, where <c>N = (k + 1)/q</c> is a whole number above 0. Then <c>x^k dx</c> is
18205+
/// <c>(t - a)^(N - 1) dt/(q b^N)</c> on every branch, since <c>x^(k + 1) = (x^q)^N</c> and
18206+
/// <c>x^(k + 1 - q) = (x^q)^(N - 1)</c> are whole powers of <c>x^q</c>, and what is left is a polynomial in t beside
18207+
/// the function of t: <c>(a + b ln(c (d + e/sqrt(x))))^p/x^2</c> is <c>-2/e^2</c> times the integral of
18208+
/// <c>(t - d) (a + b ln(c t))^p</c>. A linear <c>a + b x</c> is the rule above's. Rubi's 3.4.
18209+
/// https://github.com/asc-community/AngouriMath/issues/2075
18210+
/// </summary>
18211+
internal static Entity? SolveAPowerOfXBesideATranscendentalPowerOfABinomial(Entity expr, Entity.Variable x, bool integrateByParts)
18212+
{
18213+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow || expr is not (Mulf or Divf))
18214+
return null;
18215+
var (numerator, denominator) = expr is Divf(var above, var below) ? (above, below) : (expr, (Entity)Number.Integer.One);
18216+
Entity? transcendental = null;
18217+
// A power that is not whole of something holding a logarithm: an exponential of a binomial is the exponential
18218+
// rules', which write it in its own base, f^(a + b/x).
18219+
foreach (var factor in Mulf.LinearChildren(numerator))
18220+
if (factor is Powf(var @base, var exponent) && !exponent.ContainsNode(x) && exponent is not Number.Integer
18221+
&& @base.Nodes.Any(node => node is Logf(_, var antilogarithm) && antilogarithm.ContainsNode(x)))
18222+
{
18223+
if (transcendental is not null)
18224+
return null;
18225+
transcendental = factor;
18226+
}
18227+
if (transcendental is null || TheOneBinomialIn(transcendental, x) is not var (binomial, offset, scale, q)
18228+
|| q == Number.Integer.One || VanishesIdentically(offset))
18229+
return null;
18230+
// Beside it, constants and powers of x, whose exponents sum to k.
18231+
Entity constant = Number.Integer.One;
18232+
Entity k = Number.Integer.Zero;
18233+
for (var side = 0; side < 2; side++)
18234+
foreach (var factor in Mulf.LinearChildren(side == 0 ? numerator : denominator))
18235+
{
18236+
if (ReferenceEquals(factor, transcendental))
18237+
continue;
18238+
if (!factor.ContainsNode(x))
18239+
constant = side == 0 ? constant * factor : constant / factor;
18240+
else if (ThePowerOfXItIs(factor, x) is { } power)
18241+
k = side == 0 ? k + power : k - power;
18242+
else
18243+
return null;
18244+
}
18245+
if (((k + 1) / q).InnerSimplified is not Number.Integer { EInteger: var whole } || whole.Sign <= 0 || whole.CompareTo(EInteger.FromInt32(30)) > 0)
18246+
return null;
18247+
var t = Variable.CreateUnique(expr, "t_binomial");
18248+
var inT = transcendental.Replace(node => node == binomial ? t : node);
18249+
if (inT.ContainsNode(x))
18250+
return null;
18251+
var integrand = constant * MathS.Pow(t - offset, Number.Integer.Create(whole.Subtract(EInteger.One))) * inT / (q * MathS.Pow(scale, Number.Integer.Create(whole)));
18252+
if (Integration.ComputeAsAQuestionOfItsOwn(integrand.InnerSimplified, t, integrateByParts) is not { } answer)
18253+
return null;
18254+
var back = answer.Substitute(t, binomial);
18255+
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
18256+
}
18257+
18258+
/// <summary>The exponent of <paramref name="factor"/> as a power of <paramref name="x"/>, free of it, or <see langword="null"/>.</summary>
18259+
private static Entity? ThePowerOfXItIs(Entity factor, Entity.Variable x) => factor switch
18260+
{
18261+
_ when factor == x => Number.Integer.One,
18262+
Powf(var @base, var exponent) when @base == x && !exponent.ContainsNode(x) => exponent,
18263+
_ => null
18264+
};
18265+
18266+
/// <summary>
18267+
/// The one binomial <c>a + b x^q</c> that every <paramref name="x"/> in <paramref name="expr"/> stands in, with
18268+
/// <c>a</c>, <c>b</c> and <c>q</c> free of x and <c>q</c> a number, read as a sum of terms free of x and one term
18269+
/// <c>b x^q</c>, or <see langword="null"/>.
18270+
/// </summary>
18271+
private static (Entity Binomial, Entity Offset, Entity Scale, Entity Exponent)? TheOneBinomialIn(Entity expr, Entity.Variable x)
18272+
{
18273+
(Entity Binomial, Entity Offset, Entity Scale, Entity Exponent)? found = null;
18274+
bool Read(Entity node)
18275+
{
18276+
if (!node.ContainsNode(x))
18277+
return true;
18278+
if (node is Sumf or Minusf && ABinomial(node, x) is { } read)
18279+
{
18280+
found ??= read;
18281+
return node == found.Value.Binomial;
18282+
}
18283+
if (node == x)
18284+
return false;
18285+
return node.DirectChildren.All(Read);
18286+
}
18287+
return Read(expr) ? found : null;
18288+
}
18289+
18290+
private static (Entity Binomial, Entity Offset, Entity Scale, Entity Exponent)? ABinomial(Entity sum, Entity.Variable x)
18291+
{
18292+
Entity offset = Number.Integer.Zero;
18293+
Entity? term = null;
18294+
foreach (var summand in Sumf.LinearChildren(sum is Minusf(var left, var right) ? left + -right : sum))
18295+
if (!summand.ContainsNode(x))
18296+
offset += summand;
18297+
else if (term is null)
18298+
term = summand;
18299+
else
18300+
return null;
18301+
if (term is null)
18302+
return null;
18303+
var (above, below) = term is Divf(var n, var d) ? (n, d) : (term, (Entity)Number.Integer.One);
18304+
Entity scale = Number.Integer.One;
18305+
Entity? exponent = null;
18306+
for (var side = 0; side < 2; side++)
18307+
foreach (var factor in Mulf.LinearChildren(side == 0 ? above : below))
18308+
if (!factor.ContainsNode(x))
18309+
scale = side == 0 ? scale * factor : scale / factor;
18310+
else if (exponent is null && ThePowerOfXItIs(factor, x) is Number.Rational power && !power.IsZero)
18311+
exponent = side == 0 ? power : -power;
18312+
else
18313+
return null;
18314+
return exponent is null ? null : (sum, offset, scale, exponent.InnerSimplified);
18315+
}
18316+
1820218317
/// <summary>
1820318318
/// Whether <paramref name="factor"/> is a power that is not whole of something holding a logarithm of something in
1820418319
/// <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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ internal static bool ASumOverRootsWouldAnswer
937937
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideErrorFunctionsOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
938938
// And beside a symbolic power of a logarithm of one, or an exponential of a power of one, the same way.
939939
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideATranscendentalPowerOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
940+
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfXBesideATranscendentalPowerOfABinomial(expr, x, integrateByParts)) is { }) return answer;
940941
// A half-odd power of a ± a sin(y) beside powers of other linears in the sine, by the half
941942
// angle, before the polynomial term: beneath it the substitution search ran out of time.
942943
if ((answer = IndefiniteIntegralSolver.SolveAHalfOddPowerOfOnePlusMinusASineBesidePowersOfLinearsInIt(expr, x, integrateByParts)) is { }) return answer;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ public void APositiveRateIsTakenOutOfThePower()
147147
[InlineData("x*(d + f*acosh(f*x))^n/(sqrt(f*x - 1)*sqrt(f*x + 1))")]
148148
public void ASymbolicPowerOfAnInverseHyperbolicFunction(string integrand) => DifferentiatesBack(integrand);
149149

150+
/// <summary>
151+
/// A power <c>x^k</c> beside a power of a logarithm of one binomial <c>d + f x^q</c>, where <c>(k + 1)/q</c> is a whole
152+
/// number, written in <c>t = d + f x^q</c>: a polynomial in t beside the logarithm's power. Rubi's 3.4.
153+
/// </summary>
154+
[Theory]
155+
[InlineData("(a - b*ln(c*(d + f/sqrt(x))))^n/x^2")]
156+
[InlineData("x^3*(a - b*ln(c*(d + f*x^(2/3))))^n")]
157+
[InlineData("(a - b*ln(c*(d + f/x^(1/3))^2))^n/x^2")]
158+
public void APowerOfXBesideAFunctionOfABinomial(string integrand) => DifferentiatesBack(integrand);
159+
150160
/// <summary>
151161
/// Not where the integral is elementary, an exponential integral or an error function: those keep the form
152162
/// they had.

0 commit comments

Comments
 (0)