@@ -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
0 commit comments