@@ -4185,6 +4185,14 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
41854185 /// The identity holds wherever the root is real, which is where the answer is
41864186 /// asked; <c>u</c> goes back in as <c>x (c + d x^n)^(-1/n)</c>.
41874187 /// </para>
4188+ /// <para>
4189+ /// And beside a power of <c>x</c> that is not one of <c>x^n</c>: <c>x^j</c> times a
4190+ /// rational function of <c>x^n</c> times <c>(c + d x^n)^(k - (j + 1)/n)</c> is
4191+ /// <c>u^j</c> times the same in <c>u</c>, since <c>x^j (c + d x^n)^(-j/n)</c> is
4192+ /// <c>u^j</c>. Rubi's 1.1.3.4: <c>x/((a + b x^3)^(2/3) (c + d x^3))</c> is
4193+ /// <c>u/(c - (b c - a d) u^3)</c>, and <c>x^4 (a + b x^3)^(1/3)/(c + d x^3)</c> is the
4194+ /// same with <c>x^3</c> beside it; each was declined.
4195+ /// </para>
41884196 /// https://github.com/asc-community/AngouriMath/issues/718
41894197 /// </remarks>
41904198 internal static Entity? SolveByDividingByTheRoot(Entity expr, Entity.Variable x)
@@ -4195,6 +4203,8 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
41954203 Entity? c = null, d = null;
41964204 var n = 0;
41974205 var k = EInteger.Zero;
4206+ // The power of x beside it, below n: the exponent is `k - (j + 1)/n`.
4207+ var j = 0;
41984208 Entity rest = Number.Integer.One;
41994209 var (above, below) = Functions.SingleQuotient.Of(expr);
42004210 foreach (var (side, isBelow) in new[] { (above, false), (below, true) })
@@ -4206,15 +4216,18 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
42064216 if (radicand is not null || !TryReadAsABinomialIn(@base, x, out var readC, out var readD, out var readN)
42074217 || readN < 2 || !signed.Denominator.Equals(EInteger.FromInt32(readN)))
42084218 return null;
4209- // The numerator of the exponent is k n - 1.
4210- var shifted = signed.Numerator.Add(EInteger.One);
4211- if (!shifted.Remainder(EInteger.FromInt32(readN)).IsZero)
4212- return null;
4219+ // The numerator of the exponent is k n - j - 1, for j from 0 to n - 1.
4220+ var nAsEInteger = EInteger.FromInt32(readN);
4221+ var residue = signed.Numerator.Add(EInteger.One).Remainder(nAsEInteger);
4222+ if (residue.Sign < 0)
4223+ residue = residue.Add(nAsEInteger);
4224+ var readJ = residue.IsZero ? 0 : readN - residue.ToInt32Checked();
42134225 radicand = @base;
42144226 c = readC;
42154227 d = readD;
42164228 n = readN;
4217- k = shifted.Divide(EInteger.FromInt32(readN));
4229+ j = readJ;
4230+ k = signed.Numerator.Add(EInteger.FromInt32(readJ + 1)).Divide(nAsEInteger);
42184231 continue;
42194232 }
42204233 if (factor.ContainsNode(x) && !IsRationalIn(factor, x))
@@ -4223,8 +4236,25 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
42234236 }
42244237 if (radicand is null || c is null || d is null || TreeAnalyzer.IsZero(c) || TreeAnalyzer.IsZero(d))
42254238 return null;
4226- // The rest as a rational function of x^n: written in a stand-in for x^n where every
4227- // power of x is a multiple of n, and declined otherwise.
4239+ // The rest as a rational function of x^n, x^j taken out of it first: written in a
4240+ // stand-in for x^n where every power of x is a multiple of n, and declined otherwise.
4241+ if (j != 0)
4242+ {
4243+ // Out of the polynomial above the bar, each of whose powers is then a multiple of n.
4244+ var (restAbove, restBelow) = Functions.SingleQuotient.Of(rest);
4245+ if (!TreeAnalyzer.TryGetPolynomial(restAbove, x, out var aboveTerms) || aboveTerms.Count == 0)
4246+ return null;
4247+ Entity lowered = Number.Integer.Zero;
4248+ foreach (var term in aboveTerms)
4249+ {
4250+ var power = term.Key.Subtract(EInteger.FromInt32(j));
4251+ if (power.Sign < 0 || term.Value.ContainsNode(x))
4252+ return null;
4253+ var monomial = power.IsZero ? term.Value : term.Value * MathS.Pow(x, Number.Integer.Create(power));
4254+ lowered = lowered == Number.Integer.Zero ? monomial : lowered + monomial;
4255+ }
4256+ rest = restBelow == Number.Integer.One ? lowered : lowered / restBelow;
4257+ }
42284258 var xToTheN = Variable.CreateUnique(expr, "x_n");
42294259 var inXToTheN = rest.Replace(node =>
42304260 node is Powf(var xAgain, Number.Integer power) && xAgain == x && power.EInteger.Remainder(EInteger.FromInt32(n)).IsZero
@@ -4243,8 +4273,11 @@ node is Powf(var xAgain, Number.Integer power) && xAgain == x && power.EInteger.
42434273 // base is its polynomial in u first, which collects what the substitution writes twice --
42444274 // `1 - (-u^2) - u^2` is 1 under a secant's half angle -- and the factors stay as they are
42454275 // written, which the rules after this read better than their product expanded.
4276+ var restInU = inXToTheN.Substitute(xToTheN, c * uToTheN / oneMinusDUToTheN);
4277+ if (j != 0)
4278+ restInU = MathS.Pow(u, j) * restInU;
42464279 var integrand = WithTheFactorsWrittenOnBothSidesCancelled(u, Functions.SingleQuotient.Combine(
4247- inXToTheN.Substitute(xToTheN, c * uToTheN / oneMinusDUToTheN)
4280+ restInU
42484281 * (k.IsZero ? Number.Integer.One : MathS.Pow(binomialInU, Number.Integer.Create(k)))
42494282 / oneMinusDUToTheN).InnerSimplified);
42504283 if (integrand is Providedf(var inner, _))
0 commit comments