Skip to content

Commit 6821140

Browse files
Integrate a polynomial beside a function of a shifted linear in that linear (#2087)
A polynomial beside a function of one shifted linear a + b x that parts cannot reach -- a power that is not whole of something holding a logarithm of it, or an exponential of a function of it that is not linear -- is written in u = a + b x, as the rule for error functions of a shifted linear writes its integrand. The polynomial is one in u there, and each of its terms beside the function is a gamma function: x (a + b ln(c (d + e x)))^p becomes u (a + b ln(c u))^p and the offset's own term, and x^2 f^(c (a + b x)^3) becomes powers of u beside f^(c u^3). In u the offset is zero, and the rule declines there. The function is found by its shape before any factor is read as a polynomial, which expands it: asked of every product the algebraic files are, the reading the other way round was five per cent of the corpus's time. Rubi's suite on the harness that reads GAMMA, against master 3dbae24: 48,875 -> 48,907 of 49,052, 0 wrong, no solved row lost, no row to a timeout, no answer's allocation grown; time per stream 0.97 to 1.01 of master's. The gains are 18 in 3.4, 9 in 2.3 and 5 in 3.3. Three definite integrals agree with quadrature to 25 digits. 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 3dbae24 commit 6821140

4 files changed

Lines changed: 108 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ as `a - b = 0`, as a statement's own solve reads it: `"x + 1 = 3".Solve("x")` wa
150150
`x^31 e^(-x)` is, whose sum of 32 terms is `-gamma(32, x)` now. A definite integral of such an answer that is
151151
undefined at a bound is left as written. And beside a power of a sine and a cosine, which Euler's formula writes as
152152
those exponentials, the gamma functions of an imaginary argument, and beside a hyperbolic function of a power of
153-
`x`, as `x sinh(c + d x^3)`.
153+
`x`, as `x sinh(c + d x^3)`. A polynomial beside a symbolic power of a logarithm of one shifted linear, or an
154+
exponential of a power of one, is written in that linear, where each term is one of these:
155+
`x (a + b ln(c (d + e x)))^p` and `x^2 f^(c (a + b x)^3)`.
154156
([#2075](https://github.com/asc-community/AngouriMath/issues/2075))
155157

156158
| Input | Was (2.6.0) | Now |

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18148,6 +18148,96 @@ bool Read(Entity node, bool insideASum)
1814818148
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
1814918149
}
1815018150

18151+
/// <summary>
18152+
/// A polynomial beside a function of one shifted linear <c>a + b x</c> that parts cannot reach, written in
18153+
/// <c>u = a + b x</c>: a power that is not whole of something holding a logarithm of it, <c>x (a + b ln(c (d + e x)))^p</c>,
18154+
/// or an exponential of a function of it that is not linear, <c>x^2 f^(c (a + b x)^3)</c>. In u the polynomial is one
18155+
/// in u, and each of its terms beside the function is answered in the gamma function: <c>u (a + b ln(c u))^p</c> and
18156+
/// <c>u^2 f^(c u^3)</c>. Only where the offset is not zero, since in u it is, and this declines there. Rubi's 3.3, 3.4
18157+
/// and 2.3. https://github.com/asc-community/AngouriMath/issues/2075
18158+
/// </summary>
18159+
internal static Entity? SolveAPolynomialBesideATranscendentalPowerOfAShiftedLinear(Entity expr, Entity.Variable x, bool integrateByParts)
18160+
{
18161+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow || expr is not (Mulf or Divf))
18162+
return null;
18163+
// The function first, by its shape, before any factor is read as a polynomial: that expands it, and asked of
18164+
// every product an algebraic integrand is, it was five per cent of the corpus's time.
18165+
Entity? transcendental = null;
18166+
foreach (var factor in Mulf.LinearChildren(expr))
18167+
if (factor.ContainsNode(x) && IsATranscendentalPowerOfSomethingInX(factor, x))
18168+
{
18169+
if (transcendental is not null)
18170+
return null;
18171+
transcendental = factor;
18172+
}
18173+
if (transcendental is null)
18174+
return null;
18175+
Entity? polynomial = null;
18176+
foreach (var factor in Mulf.LinearChildren(expr))
18177+
{
18178+
if (!factor.ContainsNode(x) || ReferenceEquals(factor, transcendental))
18179+
continue;
18180+
if (ThePolynomialIn(factor, x) is not null)
18181+
polynomial = polynomial is null ? factor : polynomial * factor;
18182+
else
18183+
return null;
18184+
}
18185+
if (transcendental is null || polynomial is null
18186+
|| TheOneLinearIn(transcendental, x) is not { } linear
18187+
|| !TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out var offset)
18188+
|| slope.ContainsNode(x) || offset.ContainsNode(x) || TreeAnalyzer.IsZero(slope) || VanishesIdentically(offset))
18189+
return null;
18190+
// x = (u - a)/b, so that the function is of u, and dx = du/b: the whole integrand, its constants with it.
18191+
var u = Variable.CreateUnique(expr, "u_linear");
18192+
if (transcendental.Replace(node => node == linear ? u : node).ContainsNode(x))
18193+
return null;
18194+
var inU = expr.Replace(node => node == linear ? u : node).Substitute(x, (u - offset) / slope);
18195+
if (inU.ContainsNode(x)
18196+
|| Integration.ComputeAsAQuestionOfItsOwn((inU / slope).InnerSimplified, u, integrateByParts) is not { } answer)
18197+
return null;
18198+
var back = answer.Substitute(u, linear);
18199+
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
18200+
}
18201+
18202+
/// <summary>
18203+
/// Whether <paramref name="factor"/> is a power that is not whole of something holding a logarithm of something in
18204+
/// <paramref name="x"/>, or an exponential of something in <paramref name="x"/> that is not linear in it.
18205+
/// </summary>
18206+
private static bool IsATranscendentalPowerOfSomethingInX(Entity factor, Entity.Variable x) => factor switch
18207+
{
18208+
// An exponential whose exponent holds a sum in x, c (a + b x)^3 or c/(a + b x), read as not linear only then.
18209+
Powf(var @base, var exponent) when !@base.ContainsNode(x) && exponent.ContainsNode(x)
18210+
=> exponent.Nodes.Any(node => node is Sumf or Minusf && node.ContainsNode(x))
18211+
&& !TreeAnalyzer.TryGetPolyLinear(exponent, x, out _, out _),
18212+
Powf(var @base, var exponent) when !exponent.ContainsNode(x) && exponent is not Number.Integer
18213+
=> @base.Nodes.Any(node => node is Logf(_, var antilogarithm) && antilogarithm.ContainsNode(x)),
18214+
_ => false
18215+
};
18216+
18217+
/// <summary>
18218+
/// The one sum linear in <paramref name="x"/> that every <paramref name="x"/> in <paramref name="expr"/> stands in,
18219+
/// outermost, or <see langword="null"/>.
18220+
/// </summary>
18221+
private static Entity? TheOneLinearIn(Entity expr, Entity.Variable x)
18222+
{
18223+
Entity? found = null;
18224+
bool Read(Entity node)
18225+
{
18226+
if (!node.ContainsNode(x))
18227+
return true;
18228+
if (node is Sumf or Minusf && TreeAnalyzer.TryGetPolyLinear(node, x, out var slope, out _) && !slope.ContainsNode(x))
18229+
{
18230+
if (found is null)
18231+
found = node;
18232+
return node == found;
18233+
}
18234+
if (node == x)
18235+
return false;
18236+
return node.DirectChildren.All(Read);
18237+
}
18238+
return Read(expr) ? found : null;
18239+
}
18240+
1815118241
/// <summary>
1815218242
/// A sine or a cosecant of twice an argument beside functions of the argument, written as the
1815318243
/// product it is: <c>sin(2A) = 2 sin(A) cos(A)</c>, so that every trigonometric function is of

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ internal static bool ASumOverRootsWouldAnswer
935935
// A polynomial beside error functions of one shifted linear, written in it: by parts in
936936
// x leaves a Gaussian of the shifted linear beside a polynomial, which nothing reads.
937937
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideErrorFunctionsOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
938+
// And beside a symbolic power of a logarithm of one, or an exponential of a power of one, the same way.
939+
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideATranscendentalPowerOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
938940
// A half-odd power of a ± a sin(y) beside powers of other linears in the sine, by the half
939941
// angle, before the polynomial term: beneath it the substitution search ran out of time.
940942
if ((answer = IndefiniteIntegralSolver.SolveAHalfOddPowerOfOnePlusMinusASineBesidePowersOfLinearsInIt(expr, x, integrateByParts)) is { }) return answer;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void AHighWholePowerIsOneGammaFunction()
8686
[InlineData("integral(e^(-x^3), x, 0, 1)", 0.807511182139671)]
8787
// 3^(-2/3) on both half-lines, which is not a number but one constant.
8888
[InlineData("integral(x^(1/3)*e^(-(1 + 3*x^2)), x, 0, 1)", 0.1169389395696306439)]
89+
[InlineData("integral(x*(1/3 + 2*ln(3/2*(1 + 2*x)))^(5/2), x, 1, 2)", 47.01873105138465896167)]
8990
public void ADefiniteIntegralFromZero(string integral, double value)
9091
{
9192
var result = integral.ToEntity().Simplify().EvalNumerical();
@@ -123,6 +124,18 @@ public void APositiveRateIsTakenOutOfThePower()
123124
[InlineData("x^m*e^(-(a + b*x^2))")]
124125
public void AHyperbolicFunctionOfAPowerOfX(string integrand) => DifferentiatesBack(integrand);
125126

127+
/// <summary>
128+
/// A polynomial beside a symbolic power of a logarithm of one shifted linear, or an exponential of a power of one,
129+
/// written in <c>u = a + b x</c>, where each term is a gamma function. The constant in front comes along. Rubi's 3.3,
130+
/// 3.4 and 2.3.
131+
/// </summary>
132+
[Theory]
133+
[InlineData("2*x*(a + b*ln(c*(d + f*x)))^n")]
134+
[InlineData("x*(a + b*ln(c*(d + f*sqrt(x))))^n")]
135+
[InlineData("x^2*f^(c*(a + b*x)^3)")]
136+
[InlineData("(a + b*x)^2*e^(-c*(d + f*x)^3)")]
137+
public void APolynomialBesideAFunctionOfAShiftedLinear(string integrand) => DifferentiatesBack(integrand);
138+
126139
/// <summary>
127140
/// Not where the integral is elementary, an exponential integral or an error function: those keep the form
128141
/// they had.

0 commit comments

Comments
 (0)