Skip to content

Commit cb8e133

Browse files
A rational function with symbols in it beside a root of a linear is split into partial fractions first (#1741)
1/(x (1 + x^2) sqrt(a + b x)) was declined while each of its partial fractions beside the root was answered: under v = sqrt(a + b x) it is a rational function over a sextic with symbols in it, which nothing factors. With two or more factors below the bar, the rational function is split over them as written -- the whole part of the power among them, so each term stands over a root -- and integrated term by term. Rubi's 4.3.2.1, cot(x)/sqrt(a + b tan(x)), under the tangent. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 61bd8e7 commit cb8e133

4 files changed

Lines changed: 166 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ the division's; with it on, the rounding is the setting's own and stays
146146
| `"(-60.5)!"` at 30 digits, downcasting off | `5.86118478907722232671451280188E-81` | `2.93059239453861116335725639905E-81` |
147147
| `"abs(75 + 316.22776601683796i)"`, downcasting off | `325` | `325.000000000000026076735749…` |
148148

149+
### A rational function with symbols in it beside a root of a linear is split into partial fractions first
150+
151+
**Answers where there were none.** `1/(x (1 + x^2) sqrt(a + b x))` was declined, while
152+
`1/(x sqrt(a + b x))` and `x/((1 + x^2) sqrt(a + b x))`, its two partial fractions beside the root,
153+
were each answered: under `v = sqrt(a + b x)` it is a rational function over a sextic with symbols in
154+
it, which nothing factors. A rational function with symbols in it and two or more factors below the bar,
155+
beside a power that is not whole of a linear, is now split over its factors as written -- the whole part
156+
of the power among them, so that each term stands over a root -- and integrated term by term. It is what
157+
the tangent substitution makes of Rubi's 4.3.2.1, `cot(x)/sqrt(a + b tan(x))`
158+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
159+
160+
| Input | Was (2.5.0) | Now |
161+
|---|---|---|
162+
| `"1/(x*(1 + x^2)*sqrt(a + b*x))".ToEntity().Integrate("x")` | `integral(...)` | a piecewise of arctangents and a logarithm in `sqrt(a + b x)` |
163+
| `"cot(x)/sqrt(a + b*tan(x))".ToEntity().Integrate("x")` | `integral(...)` | the same in `tan(x)` |
164+
| `"cot(x)^2/(a + b*tan(x))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | the same, beside a power of `a + b tan(x)` |
165+
149166
### A quotient of polynomials is split into coprime blocks before a root is peeled off
150167

151168
`SolveByPartialFractions` tried `TrySplitOffRationalRoot` before `TrySplitIntoCoprimeParts`. Both

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19281,6 +19281,98 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons
1928119281
return Integration.ComputeIndefiniteIntegral(written, x, integrateByParts);
1928219282
}
1928319283

19284+
/// <summary>
19285+
/// A rational function with symbols in it beside a power that is not whole of a linear,
19286+
/// <c>R(x) (a + b x)^q</c>, with two or more factors below the bar: split into partial
19287+
/// fractions over the factors as written, each term beside the power is the question
19288+
/// the rules for one factor answer. <c>1/(x (1 + x^2) sqrt(a + b x))</c> is
19289+
/// <c>1/(x sqrt(a + b x)) - x/((1 + x^2) sqrt(a + b x))</c>, and was declined: under
19290+
/// <c>v = sqrt(a + b x)</c> it is a rational function over a sextic with symbols in it,
19291+
/// which nothing factors, where each term above is answered at once. It is what the
19292+
/// tangent substitution makes of Rubi's 4.3.2.1, <c>cot(x)/sqrt(a + b tan(x))</c>.
19293+
/// https://github.com/asc-community/AngouriMath/issues/718
19294+
/// </summary>
19295+
/// <remarks>
19296+
/// Late, so that whatever answers the integrand whole answers first, and only with a symbol
19297+
/// in it: with numbers the substitution's rational function is split over the rationals.
19298+
/// </remarks>
19299+
internal static Entity? SolveARationalFunctionBesideARootOfALinearSplitFirst(Entity expr, Entity.Variable x, bool integrateByParts)
19300+
{
19301+
if (!expr.Vars.Any(symbol => symbol != x))
19302+
return null;
19303+
Entity? radicand = null;
19304+
var exponent = ERational.Zero;
19305+
Entity constant = Number.Integer.One;
19306+
Entity above = Number.Integer.One;
19307+
Entity below = Number.Integer.One;
19308+
var belowFactors = 0;
19309+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
19310+
{
19311+
if (!factor.ContainsNode(x))
19312+
{
19313+
constant = underneath ? constant / factor : constant * factor;
19314+
continue;
19315+
}
19316+
if (factor is Powf(var linear, Number.Rational power) && power is not Number.Integer
19317+
&& TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out _) && !TreeAnalyzer.IsZero(slope))
19318+
{
19319+
if (radicand is not null)
19320+
return null;
19321+
(radicand, exponent) = (linear, underneath ? power.ERational.Negate() : power.ERational);
19322+
continue;
19323+
}
19324+
// A polynomial, or a whole power of one.
19325+
var (@base, whole) = factor is Powf(var raised, Number.Integer n) && n.EInteger.CanFitInInt32() ? (raised, n.EInteger.ToInt32Checked()) : (factor, 1);
19326+
if (!TreeAnalyzer.TryGetPolynomial(@base, x, out var read) || read.Keys.Any(degree => degree.Sign < 0) || read.Values.Any(coefficient => coefficient.ContainsNode(x)))
19327+
return null;
19328+
var written = System.Math.Abs(whole) == 1 ? @base : MathS.Pow(@base, System.Math.Abs(whole));
19329+
if (underneath == whole > 0)
19330+
{
19331+
below = below == Number.Integer.One ? written : below * written;
19332+
belowFactors++;
19333+
}
19334+
else
19335+
above = above == Number.Integer.One ? written : above * written;
19336+
}
19337+
if (radicand is null)
19338+
return null;
19339+
// The whole part of the power goes into the rational function, and what is left of it
19340+
// is a root below the bar, `L^q = L^k / L^(k - q)` with `k` the least whole number past
19341+
// `q`: `1/(x (1 + x^2) (a + b x)^(3/2))` is split with `a + b x` among the factors and
19342+
// every term over `sqrt(a + b x)`, the shape the rules for one factor read.
19343+
var (top, bottom) = (exponent.Numerator, exponent.Denominator);
19344+
var wholePart = top.Sign > 0 ? top.Add(bottom).Subtract(EInteger.One).Divide(bottom) : top.Divide(bottom);
19345+
if (wholePart.Sign > 0)
19346+
above = above == Number.Integer.One ? MathS.Pow(radicand, Number.Integer.Create(wholePart)) : above * MathS.Pow(radicand, Number.Integer.Create(wholePart));
19347+
else if (wholePart.Sign < 0)
19348+
{
19349+
var negated = wholePart.Negate();
19350+
var power = negated.Equals(EInteger.One) ? radicand : MathS.Pow(radicand, Number.Integer.Create(negated));
19351+
below = below == Number.Integer.One ? power : below * power;
19352+
belowFactors++;
19353+
}
19354+
var root = MathS.Pow(radicand, Number.Rational.Create(ERational.FromEInteger(wholePart).Subtract(exponent)));
19355+
if (belowFactors < 2
19356+
|| !Functions.PartialFractions.TrySplitOverWrittenFactors(above, below, x, out var decomposition))
19357+
return null;
19358+
// The split comes over the denominator's constant, which goes in front.
19359+
if (decomposition is Divf(var split, var over) && !over.ContainsNode(x))
19360+
(decomposition, constant) = (split, constant / over);
19361+
var terms = Sumf.LinearChildren(decomposition).Where(term => !TreeAnalyzer.IsZero(term)).ToList();
19362+
if (terms.Count < 2)
19363+
return null;
19364+
Entity sum = Number.Integer.Zero;
19365+
foreach (var term in terms)
19366+
{
19367+
var question = term / root;
19368+
if (Integration.ComputeIndefiniteIntegral(question, x, integrateByParts) is not { } integral
19369+
|| integral.Nodes.Any(node => node is Integralf))
19370+
return null;
19371+
sum += integral;
19372+
}
19373+
return constant * sum;
19374+
}
19375+
1928419376
/// <summary>
1928519377
/// A rational function over one block quadratic in a power of x, <c>a + b x^n + c x^(2n)</c>
1928619378
/// with a symbol in it, split at the block's roots in <c>u = x^n</c>: the single block

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
11101110
// One block quadratic in a power of x, split at its roots, which are complex where its
11111111
// discriminant is negative: as late, so that a rule answering the block whole goes first.
11121112
if ((answer = IndefiniteIntegralSolver.SolveByOneBlockInAPowerOfXAtItsRoots(expr, x, integrateByParts)) is { }) return answer;
1113+
// A rational function with symbols in it beside a root of a linear, split into partial
1114+
// fractions first, each term the question of one factor beside the root.
1115+
if ((answer = IndefiniteIntegralSolver.SolveARationalFunctionBesideARootOfALinearSplitFirst(expr, x, integrateByParts)) is { }) return answer;
11131116
// The sign of a real-valued factor is constant between its zeros, and goes in
11141117
// front of the antiderivative of the rest. After every rule that reads the sign
11151118
// where it stands: `cos(x) sgn(sin(x))` is `|sin(x)|` by the substitution, and
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// A rational function with symbols in it beside a root of a linear, split into partial
16+
/// fractions first: <c>1/(x (1 + x^2) sqrt(a + b x))</c> is
17+
/// <c>1/(x sqrt(a + b x)) - x/((1 + x^2) sqrt(a + b x))</c>, each answered alone, and was
18+
/// declined; so was what the tangent substitution makes of Rubi's 4.3.2.1,
19+
/// <c>cot(x)/sqrt(a + b tan(x))</c>.
20+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class SplitBesideARootIntegralTest
24+
{
25+
[Theory]
26+
[InlineData("1/(x*(1 + x^2)*sqrt(a + b*x))")]
27+
[InlineData("1/(x*(1 + x^2)*(a + b*x)^(3/2))")]
28+
[InlineData("1/((x + c)*(x + d)*sqrt(a + b*x))")]
29+
[InlineData("cot(x)/sqrt(a + b*tan(x))")]
30+
[InlineData("cot(x)^2/(a + b*tan(x))^(3/2)")]
31+
public void TermByTerm(string integrand)
32+
{
33+
var integral = integrand.ToEntity().Integrate("x");
34+
Assert.DoesNotContain("integral(", integral.Stringize());
35+
Assert.DoesNotContain("NaN", integral.Stringize());
36+
Entity Pinned(Entity e) => e.Substitute("a", 2.3).Substitute("b", 0.7).Substitute("c", 1.3).Substitute("d", 0.6);
37+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
38+
var original = Pinned(integrand.ToEntity());
39+
var compared = 0;
40+
foreach (var at in new[] { -1.7, -0.9, 0.3, 0.8, 1.6, 2.9 })
41+
{
42+
var want = original.Substitute("x", at).EvalNumerical();
43+
if (want.IsNaN || Math.Abs((double)want.ImaginaryPart) > 1e-12)
44+
continue;
45+
compared++;
46+
var got = derivative.Substitute("x", at).EvalNumerical();
47+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
48+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)),
49+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
50+
}
51+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)