@@ -4049,6 +4049,132 @@ private static bool TryReadAsABinomialIn(Entity expr, Entity.Variable x, out Ent
40494049 return !c.ContainsNode(x) && n >= 1;
40504050 }
40514051
4052+ /// <summary>
4053+ /// A root of a quadratic binomial beside another, <c>1/((A + B x^2)^(1/3) (C + D x^2))</c>
4054+ /// with <c>B C + 3 A D = 0</c> or <c>B C - 9 A D = 0</c>, and
4055+ /// <c>1/((A + B x^2)^(1/4) (C + D x^2))</c> with <c>B C - 2 A D = 0</c>: the ratios at which
4056+ /// the integral, elliptic otherwise, is elementary, in closed form.
4057+ /// </summary>
4058+ /// <remarks>
4059+ /// <para>
4060+ /// With <c>y</c> the root, <c>a = A^(1/3)</c>, and <c>q = sqrt(B/A)</c> or <c>sqrt(-B/A)</c> by its sign:
4061+ /// <code>
4062+ /// B C + 3 A D = 0, B/A > 0: -2^(1/3) q/(4 a D) (atan(a q x/(a + 2^(1/3) y)) - atan(q x)/3
4063+ /// - (artanh(sqrt(3) (a - 2^(1/3) y)/(a q x)) + artanh(sqrt(3)/(q x)))/sqrt(3))
4064+ /// B/A < 0: 2^(1/3) q/(4 a D) (artanh(a q x/(a + 2^(1/3) y)) - artanh(q x)/3
4065+ /// + (atan(sqrt(3) (a - 2^(1/3) y)/(a q x)) + atan(sqrt(3)/(q x)))/sqrt(3))
4066+ /// B C - 9 A D = 0, B/A > 0: q/(12 a D) (atan((a - y)^2/(3 a^2 q x)) + atan(q x/3)
4067+ /// - sqrt(3) artanh(sqrt(3) (a - y)/(a q x)))
4068+ /// B/A < 0: q/(12 a D) (artanh((a - y)^2/(3 a^2 q x)) - artanh(q x/3)
4069+ /// - sqrt(3) atan(sqrt(3) (a - y)/(a q x)))
4070+ /// </code>
4071+ /// and for the fourth root, with <c>s = sqrt(A + B x^2)</c> and <c>r = sqrt(|B|)</c>, times
4072+ /// <c>B/D</c>, which takes <c>C + D x^2</c> to <c>2 A + B x^2</c>:
4073+ /// <code>
4074+ /// A > 0, B > 0: -(atan(A^(3/4) (1 + s/sqrt(A))/(x y r)) + artanh(A^(3/4) (1 - s/sqrt(A))/(x y r)))/(2 A^(3/4) r)
4075+ /// A > 0, B < 0: (atan(A^(3/4) (1 - s/sqrt(A))/(x y r)) + artanh(A^(3/4) (1 + s/sqrt(A))/(x y r)))/(2 A^(3/4) r)
4076+ /// A < 0: -(atan(u) + artanh(u))/(2 (-A)^(3/4) sqrt(2) r), u = x r/((-A)^(1/4) y sqrt(2))
4077+ /// </code>
4078+ /// Rubi's, from its 1.1.2.3, written for any constants with the ratio; each was checked by
4079+ /// differentiating it at points in every sign case. The derivative of each uses only that
4080+ /// the roots are roots, so for a sign that is a symbol's both forms are given, each where
4081+ /// it holds.
4082+ /// https://github.com/asc-community/AngouriMath/issues/718
4083+ /// </para>
4084+ /// </remarks>
4085+ internal static Entity? SolveAnEllipticLookingQuotientOfBinomials(Entity expr, Entity.Variable x)
4086+ {
4087+ var (numerator, denominator) = Functions.SingleQuotient.Of(expr);
4088+ if (numerator.ContainsNode(x))
4089+ return null;
4090+ Entity constant = numerator;
4091+ Entity? radicand = null;
4092+ var order = 0;
4093+ Entity? other = null;
4094+ foreach (var factor in Mulf.LinearChildren(denominator))
4095+ {
4096+ if (!factor.ContainsNode(x))
4097+ constant = constant / factor;
4098+ else if (radicand is null && factor is Powf(var @base, Number.Rational power) && power.ERational.Numerator.Equals(EInteger.One)
4099+ && (power.ERational.Denominator.Equals(EInteger.FromInt32(3)) || power.ERational.Denominator.Equals(EInteger.FromInt32(4))))
4100+ {
4101+ radicand = @base;
4102+ order = power.ERational.Denominator.ToInt32Unchecked();
4103+ }
4104+ else if (other is null && factor is not Powf)
4105+ other = factor;
4106+ else
4107+ return null;
4108+ }
4109+ if (radicand is null || other is null || EvenQuadratic(radicand) is not var (a0, b0) || EvenQuadratic(other) is not var (c0, d0))
4110+ return null;
4111+ var (A, B, C, D) = (a0, b0, c0, d0);
4112+ var y = MathS.Pow(radicand, Number.Rational.Create(1, order));
4113+ Entity? answer = null;
4114+ if (order == 3 && VanishesIdentically(B * C + 3 * A * D))
4115+ {
4116+ var a = MathS.Pow(A, Number.Rational.Create(1, 3));
4117+ var cube = MathS.Pow(2, Number.Rational.Create(1, 3));
4118+ var three = MathS.Sqrt(3);
4119+ var quarter = LowestOverTheSymbols(1 / (4 * D));
4120+ Entity Positive(Entity q) => -quarter * cube * q / a * (MathS.Arctan(a * q * x / (a + cube * y)) - MathS.Arctan(q * x) / 3
4121+ - (MathS.Hyperbolic.Artanh(three * (a - cube * y) / (a * q * x)) + MathS.Hyperbolic.Artanh(three / (q * x))) / three);
4122+ Entity Negative(Entity q) => quarter * cube * q / a * (MathS.Hyperbolic.Artanh(a * q * x / (a + cube * y)) - MathS.Hyperbolic.Artanh(q * x) / 3
4123+ + (MathS.Arctan(three * (a - cube * y) / (a * q * x)) + MathS.Arctan(three / (q * x))) / three);
4124+ var ratio = LowestOverTheSymbols(B / A);
4125+ answer = BySign(ratio, Positive(MathS.Sqrt(ratio)), Negative(MathS.Sqrt(LowestOverTheSymbols(-ratio))));
4126+ }
4127+ else if (order == 3 && VanishesIdentically(B * C - 9 * A * D))
4128+ {
4129+ var a = MathS.Pow(A, Number.Rational.Create(1, 3));
4130+ var three = MathS.Sqrt(3);
4131+ var twelfth = LowestOverTheSymbols(1 / (12 * D));
4132+ Entity Positive(Entity q) => twelfth * q / a * (MathS.Arctan(MathS.Pow(a - y, 2) / (3 * MathS.Pow(a, 2) * q * x)) + MathS.Arctan(q * x / 3)
4133+ - three * MathS.Hyperbolic.Artanh(three * (a - y) / (a * q * x)));
4134+ Entity Negative(Entity q) => twelfth * q / a * (MathS.Hyperbolic.Artanh(MathS.Pow(a - y, 2) / (3 * MathS.Pow(a, 2) * q * x)) - MathS.Hyperbolic.Artanh(q * x / 3)
4135+ - three * MathS.Arctan(three * (a - y) / (a * q * x)));
4136+ var ratio = LowestOverTheSymbols(B / A);
4137+ answer = BySign(ratio, Positive(MathS.Sqrt(ratio)), Negative(MathS.Sqrt(LowestOverTheSymbols(-ratio))));
4138+ }
4139+ else if (order == 4 && VanishesIdentically(B * C - 2 * A * D))
4140+ {
4141+ var s = MathS.Sqrt(radicand);
4142+ var threeQuarters = Number.Rational.Create(3, 4);
4143+ Entity BothPositive()
4144+ {
4145+ var r = MathS.Sqrt(B);
4146+ return -(MathS.Arctan(MathS.Pow(A, threeQuarters) * (1 + s / MathS.Sqrt(A)) / (x * y * r))
4147+ + MathS.Hyperbolic.Artanh(MathS.Pow(A, threeQuarters) * (1 - s / MathS.Sqrt(A)) / (x * y * r))) / (2 * MathS.Pow(A, threeQuarters) * r);
4148+ }
4149+ Entity SlopeNegative()
4150+ {
4151+ var r = MathS.Sqrt(-B);
4152+ return (MathS.Arctan(MathS.Pow(A, threeQuarters) * (1 - s / MathS.Sqrt(A)) / (x * y * r))
4153+ + MathS.Hyperbolic.Artanh(MathS.Pow(A, threeQuarters) * (1 + s / MathS.Sqrt(A)) / (x * y * r))) / (2 * MathS.Pow(A, threeQuarters) * r);
4154+ }
4155+ Entity ConstantNegative()
4156+ {
4157+ var r = MathS.Sqrt(B);
4158+ var u = x * r / (MathS.Pow(-A, Number.Rational.Create(1, 4)) * y * MathS.Sqrt(2));
4159+ return -(MathS.Arctan(u) + MathS.Hyperbolic.Artanh(u)) / (2 * MathS.Pow(-A, threeQuarters) * MathS.Sqrt(2) * r);
4160+ }
4161+ var toTheRatio = LowestOverTheSymbols(B / D);
4162+ var form = BySigns(A, B, BothPositive(), SlopeNegative(), ConstantNegative());
4163+ answer = toTheRatio == Number.Integer.One ? form : toTheRatio * form;
4164+ }
4165+ return answer is null ? null : (constant * answer).InnerSimplified;
4166+
4167+ // A + B x^2, both nonzero.
4168+ (Entity, Entity)? EvenQuadratic(Entity polynomial)
4169+ {
4170+ if (!TreeAnalyzer.TryGetPolynomial(polynomial, x, out var terms) || terms.Count != 2
4171+ || !terms.TryGetValue(EInteger.Zero, out var free) || !terms.TryGetValue(EInteger.FromInt32(2), out var square)
4172+ || free.ContainsNode(x) || square.ContainsNode(x) || VanishesIdentically(free) || VanishesIdentically(square))
4173+ return null;
4174+ return (free, square);
4175+ }
4176+ }
4177+
40524178 /// <summary>
40534179 /// A <b>binomial differential</b> <c>x^m (a + b x^n)^(p/q)</c>, in the two of Chebyshev's
40544180 /// three cases that are not a whole power: <c>(m + 1)/n</c> whole, or
0 commit comments