@@ -4818,6 +4818,108 @@ private static bool TryReadAsABinomialIn(Entity expr, Entity.Variable x, out Ent
48184818 return !c.ContainsNode(x) && n >= 1;
48194819 }
48204820
4821+ /// <summary>
4822+ /// A linear over a linear, or a quadratic over a quadratic, beside the reciprocal of the
4823+ /// square root of a cubic binomial <c>a + b x^3</c>, at the coefficients where its
4824+ /// integral is elementary: Rubi's <c>(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))</c>,
4825+ /// <c>(c - 2 d x)/((c + d x) sqrt(c^3 + 4 d^3 x^3))</c>.
4826+ /// </summary>
4827+ /// <remarks>
4828+ /// <para>
4829+ /// The curve <c>y^2 = a + b x^3</c> is elliptic, and the integral of <c>(e + f x)/((c + d x) y)</c>
4830+ /// is elementary only where the coefficients make it so. Rubi's 1.3.3 names those places,
4831+ /// and at each the integral is a constant times <c>int du/(1 + K u^2)</c> at
4832+ /// <c>u = (1 + p x)/y</c>, or <c>(1 + p x)^2/y</c>:
4833+ /// <code>
4834+ /// b c^3 = 4 a d^3, 2 d e + c f = 0: (2 e/d) int 1/(1 + 3 a u^2), u = (1 + 2 d x/c)/y
4835+ /// b c^3 = -8 a d^3, 2 d e + c f = 0: (-2 e/(9 d)) int 1/(1 - (a/9) u^2), u = (1 + f x/e)^2/y
4836+ /// b^2 c^6 - 20 a b c^3 d^3 - 8 a^2 d^6 = 0, 6 a d^4 e = c f (b c^3 - 22 a d^3), k = (d e + 2 c f)/(c f):
4837+ /// ((1 + k) e/d) int 1/(1 + (3 + 2k) a u^2), u = (1 + (1 + k) d x/c)/y
4838+ /// </code>
4839+ /// and over a quadratic, <c>(f + g x + h x^2)/((c + d x + e x^2) y)</c> where
4840+ /// <c>b g^3 = 8 a h^3</c>, <c>g^2 + 2 f h = 0</c> and <c>b d f + b c g = 4 a e h</c>:
4841+ /// <c>-(g/e) int 1/(1 - M u^2)</c>, <c>M = (b d f - 2 a e h)/(2 e h)</c>, at <c>u = (1 + 2 h x/g)/y</c>.
4842+ /// Each condition is decided at sampled values of the symbols, the inner integral is an
4843+ /// arctangent or an inverse hyperbolic tangent by the sign of its constant, and the answer
4844+ /// is differentiated back at sampled points before it is returned.
4845+ /// https://github.com/asc-community/AngouriMath/issues/718
4846+ /// </para>
4847+ /// </remarks>
4848+ internal static Entity? SolveAPseudoEllipticQuotientOverTheRootOfACubicBinomial(Entity expr, Entity.Variable x)
4849+ {
4850+ var (numerator, denominator) = Functions.SingleQuotient.Of(expr);
4851+ Entity? radicand = null;
4852+ Entity below = Number.Integer.One;
4853+ foreach (var factor in Mulf.LinearChildren(denominator))
4854+ if (factor is Powf(var @base, Number.Rational half) && half.ERational.Equals(ERational.Create(1, 2)) && @base.ContainsNode(x))
4855+ {
4856+ if (radicand is not null)
4857+ return null;
4858+ radicand = @base;
4859+ }
4860+ else
4861+ below *= factor;
4862+ if (radicand is null || numerator.Nodes.Any(node => node is Powf(_, Number.Rational r) && r is not Number.Integer && node.ContainsNode(x))
4863+ || !TreeAnalyzer.TryGetPolynomial(radicand, x, out var cubic) || cubic.Count != 2
4864+ || !cubic.TryGetValue(EInteger.Zero, out var a) || !cubic.TryGetValue(EInteger.FromInt32(3), out var b)
4865+ || !TreeAnalyzer.TryGetPolynomial(numerator, x, out var above) || !TreeAnalyzer.TryGetPolynomial(below, x, out var under))
4866+ return null;
4867+ Entity Coefficient(Dictionary<EInteger, Entity> read, int power)
4868+ => read.TryGetValue(EInteger.FromInt32(power), out var value) ? value : Number.Integer.Zero;
4869+ int Degree(Dictionary<EInteger, Entity> read) => read.Count == 0 ? -1 : read.Keys.Max()!.ToInt32Unchecked();
4870+ if (Degree(above) > 2 || Degree(under) is not (1 or 2) || Degree(above) > Degree(under))
4871+ return null;
4872+ // A condition is decided as a value, at pinned symbols where nothing simplifies it
4873+ // to zero -- `6 a d^4 e - c f (b c^3 - 22 a d^3)` at `c = 1 - sqrt(3)` and
4874+ // `d = (b/a)^(1/3)` is one -- since the answer is checked by its derivative anyway.
4875+ static bool Zero(Entity condition) => Functions.PartialFractions.IsZeroAsAValue(condition);
4876+ var y = MathS.Sqrt(radicand);
4877+ var u = Variable.CreateUnique(expr, "u_pseudo");
4878+ // int du/(1 + K u^2), by the sign of K.
4879+ Entity OverOnePlus(Entity k)
4880+ {
4881+ var kLowest = LowestOverTheSymbols(k);
4882+ return BySign(kLowest,
4883+ MathS.Arctan(MathS.Sqrt(kLowest) * u) / MathS.Sqrt(kLowest),
4884+ MathS.Hyperbolic.Artanh(MathS.Sqrt(LowestOverTheSymbols(-kLowest)) * u) / MathS.Sqrt(LowestOverTheSymbols(-kLowest)));
4885+ }
4886+ Entity? answer = null;
4887+ if (Degree(under) == 1)
4888+ {
4889+ var (e, f) = (Coefficient(above, 0), Coefficient(above, 1));
4890+ var (c, d) = (Coefficient(under, 0), Coefficient(under, 1));
4891+ if (Zero(d * e - c * f) || Zero(c))
4892+ return null;
4893+ if (Zero(b * MathS.Pow(c, 3) - 4 * a * MathS.Pow(d, 3)) && Zero(2 * d * e + c * f))
4894+ answer = (2 * e / d * OverOnePlus(3 * a)).Substitute(u, (1 + 2 * d * x / c) / y);
4895+ else if (!Zero(e) && Zero(b * MathS.Pow(c, 3) + 8 * a * MathS.Pow(d, 3)) && Zero(2 * d * e + c * f))
4896+ answer = (-2 * e / (9 * d) * OverOnePlus(-a / 9)).Substitute(u, MathS.Pow(1 + f * x / e, 2) / y);
4897+ else if (!Zero(f)
4898+ && Zero(MathS.Pow(b, 2) * MathS.Pow(c, 6) - 20 * a * b * MathS.Pow(c, 3) * MathS.Pow(d, 3) - 8 * MathS.Pow(a, 2) * MathS.Pow(d, 6))
4899+ && Zero(6 * a * MathS.Pow(d, 4) * e - c * f * (b * MathS.Pow(c, 3) - 22 * a * MathS.Pow(d, 3))))
4900+ {
4901+ var k = LowestOverTheSymbols((d * e + 2 * c * f) / (c * f));
4902+ answer = ((1 + k) * e / d * OverOnePlus((3 + 2 * k) * a)).Substitute(u, (1 + (1 + k) * d * x / c) / y);
4903+ }
4904+ }
4905+ else
4906+ {
4907+ var (f, g, h) = (Coefficient(above, 0), Coefficient(above, 1), Coefficient(above, 2));
4908+ var (c, d, e) = (Coefficient(under, 0), Coefficient(under, 1), Coefficient(under, 2));
4909+ if (!Zero(g) && !Zero(h)
4910+ && Zero(b * MathS.Pow(g, 3) - 8 * a * MathS.Pow(h, 3)) && Zero(MathS.Pow(g, 2) + 2 * f * h)
4911+ && Zero(b * d * f + b * c * g - 4 * a * e * h) && !Zero(b * d * f - 2 * a * e * h))
4912+ answer = (-g / e * OverOnePlus(-(b * d * f - 2 * a * e * h) / (2 * e * h))).Substitute(u, (1 + 2 * h * x / g) / y);
4913+ }
4914+ if (answer is null)
4915+ return null;
4916+ answer = answer.InnerSimplified;
4917+ bool holds;
4918+ using (MathS.Settings.DowncastingEnabled.Set(false))
4919+ holds = Functions.PartialFractions.HoldsAtSampledPoints(answer.Differentiate(x), expr, x);
4920+ return holds ? answer : null;
4921+ }
4922+
48214923 /// <summary>
48224924 /// A root of a quadratic binomial beside another, <c>1/((A + B x^2)^(1/3) (C + D x^2))</c>
48234925 /// with <c>B C + 3 A D = 0</c> or <c>B C - 9 A D = 0</c>, and
0 commit comments