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