From ce9a43bee117c2ddfd14f899dd31b98bc3431e23 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 13:31:54 +0000 Subject: [PATCH 1/4] Beside the roots of two linears, a polynomial over a power of a third is integrated by undetermined coefficients Rubi's 1.1.1.6, a polynomial beside sqrt(c + d x) sqrt(e + f x) with symbols in the linears, went through the quotient of the two roots. Its rational function in t is over a power of d - f t^2 that grows with the degree of the polynomial, and (A + B x + C x^2) sqrt(c + d x) sqrt(e + f x) took more than 4 GB; with one more linear below the bar it ran past every budget. Now T/((g + h x)^k S), S the product of the two roots and T a polynomial, is U S plus multiples of two integrals. The polynomial part solves R = U' Q + U Q'/2 + lambda, which is triangular, and each power of the third linear below the bar comes down to the integral of 1/((g + h x) S) by the recurrence its derivative gives. The two integrals left are an artanh and an arctan of sqrt(c + d x)/sqrt(e + f x), each exact wherever sqrt(z)^2 = z, which is everywhere. Each of the nineteen 1.1.1.6 problems tried is answered, in under a second, and differentiates back. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Integration/IndefiniteIntegralSolver.cs | 343 ++++++++++++++++++ .../Integration/Integration.Definition.cs | 5 + .../Calculus/TwoLinearRadicalsIntegralTest.cs | 52 ++- 3 files changed, 395 insertions(+), 5 deletions(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 1a8376c05..e393aee9f 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -7935,6 +7935,349 @@ static Entity WithWholePowersOfTheSecond(List<(EInteger Power, Entity Coefficien return Integration.ComputeAsTheSameQuestion(rewritten.InnerSimplified, x, integrateByParts); } + /// + /// A polynomial over a power of a linear beside the square roots of two others, + /// P(x) (a + b x)^(m/2) (c + d x)^(n/2) / (g + h x)^k with m and n + /// odd and neither below -1, and k >= 0, by undetermined coefficients: + /// algebraic terms times sqrt(a + b x) sqrt(c + d x), and a multiple of each of + /// two integrals that are not algebraic. + /// + /// + /// + /// Write S = sqrt(a + b x) sqrt(c + d x) and Q = (a + b x)(c + d x). Over + /// S the integrand is T(x)/((g + h x)^k S), where + /// T = P (a + b x)^((m + 1)/2) (c + d x)^((n + 1)/2) is a polynomial, and + /// S' = Q'/(2 S) because sqrt(z)^2 = z for every complex z. + /// + /// + /// The polynomial part. In powers of y = g + h x, the terms of T from + /// y^k up leave a polynomial R(x), and + /// int R/S = U S + lambda int 1/S. The derivative of U S is + /// (U' Q + U Q'/2)/S, so R = U' Q + U Q'/2 + lambda, which for U of one + /// degree less than R is triangular. With + /// Q = q0 + q1 x + q2 x^2, the coefficient of x^j on the right is + /// (j + 1) q0 u_(j+1) + (j + 1/2) q1 u_j + j q2 u_(j-1). That is solved for + /// u_(j-1) from the top down, and lambda is what is left at x^0. + /// + /// + /// The terms over powers of y. Write Q = alpha + beta y + gamma y^2. + /// The derivative of S y^(1-j) is + /// h (2 (1 - j) alpha y^(-j) + (3 - 2j) beta y^(1-j) + (4 - 2j) gamma y^(2-j)) / (2 S). + /// So for j >= 2, I_j = int 1/(y^j S) is given by S y^(1-j) and the two + /// integrals before it, and all the way down it is algebraic terms and a multiple of + /// I_1. That needs alpha, the value of Q at the root of y, to be + /// nonzero, so a third linear that shares a root with one under a root is declined. + /// + /// + /// The two integrals left. With t = sqrt(a + b x)/sqrt(c + d x), + /// dx/S = 2 dt/(b - d t^2), so int 1/S is 2 artanh(sqrt(r) t)/(b sqrt(r)) + /// with r = d/b. And dx/(y S) = -2 dt/(p t^2 + q) with p = g d - h c + /// and q = h a - g b, so I_1 is -2 arctan(sqrt(rho) t)/(q sqrt(rho)) + /// with rho = p/q. Each derivative needs only sqrt(z)^2 = z, so each holds for every + /// value of the symbols that the divisions allow. Where r or rho is a number + /// of the other sign, the integral is written as the other function, without an i + /// in it. The slopes are divided by, which is the generic case, as everywhere in the + /// integrator. + /// + /// + /// The substitution answers the same + /// integrands. With symbols in the linears, though, its rational function in t is + /// over a power of b - d t^2 that grows with the degree of P. Rubi's 1.1.1.6 + /// (A + B x + C x^2) sqrt(c + d x) sqrt(e + f x) took more than 4 GB that way, + /// where this is a triangular system. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + /// + internal static Entity? SolveAPolynomialOverAPowerOfALinearBesideTwoRoots(Entity expr, Entity.Variable x) + { + // The two bases, read before anything is built, since this asks every sub-integrand. + Entity? first = null; + Entity? second = null; + foreach (var node in expr.Nodes) + { + if (node is not Powf(var @base, Number.Rational exponent) || exponent is Number.Integer || !@base.ContainsNode(x)) + continue; + if (!exponent.ERational.Denominator.Equals(EInteger.FromInt32(2)) || !exponent.ERational.Numerator.CanFitInInt32()) + return null; + if (first is null) + first = @base; + else if (first != @base) + { + if (second is null) + second = @base; + else if (second != @base) + return null; + } + } + // Two proportional linears are one root with a constant in it, which + // AsOneLinearRadical takes. + if (first is null || second is null + || !TreeAnalyzer.TryGetPolyLinear(first, x, out var b, out var a) + || !TreeAnalyzer.TryGetPolyLinear(second, x, out var d, out var c) + || IsZero(b) || IsZero(d) || IsZero(b * c - a * d)) + return null; + + // As one quotient, with a negative half-power read as the root below the bar it is. + // Each root's power is counted in halves, above the bar and below; anything else of x + // above is the polynomial, and below it may be powers of one more linear. + var (numerator, denominator) = Functions.SingleQuotient.Of(expr.Replace(node => + node is Powf(var @base, Number.Rational power) && power is not Number.Integer && power.ERational.Sign < 0 + ? Number.Integer.One / MathS.Pow(@base, Number.Rational.Create(power.ERational.Negate())) + : node)); + var halves = new Dictionary { [first] = 0, [second] = 0 }; + Entity above = Number.Integer.One; + Entity constantBelow = Number.Integer.One; + Entity? third = null; + var order = 0; + foreach (var (side, sign) in new[] { (numerator, 1), (denominator, -1) }) + foreach (var factor in Mulf.LinearChildren(side)) + { + var (@base, inHalves) = factor switch + { + Powf(var whole, Number.Integer k) when k.EInteger.CanFitInInt32() => (whole, 2 * k.EInteger.ToInt32Unchecked()), + Powf(var radicand, Number.Rational r) when r.ERational.Denominator.Equals(EInteger.FromInt32(2)) + && r.ERational.Numerator.CanFitInInt32() => (radicand, r.ERational.Numerator.ToInt32Unchecked()), + _ => (factor, 2), + }; + if (halves.ContainsKey(@base)) + halves[@base] += sign * inHalves; + else if (!factor.ContainsNode(x)) + { + if (sign > 0) + above = above * factor; + else + constantBelow = constantBelow * factor; + } + else if (sign > 0) + above = above * factor; + else if (inHalves <= 0 || inHalves % 2 != 0 || third is { } && third != @base) + return null; + else + { + third = @base; + order += inHalves / 2; + } + } + // (a + b x)^(m/2) is (a + b x)^((m + 1)/2) over its root. Below -1 there is a pole + // at the root of a linear under a root, which is the substitution's. + if (halves[first] % 2 == 0 || halves[second] % 2 == 0) + return null; + var wholeOfFirst = (halves[first] + 1) / 2; + var wholeOfSecond = (halves[second] + 1) / 2; + if (wholeOfFirst < 0 || wholeOfSecond < 0) + return null; + above = above * Power(first, wholeOfFirst) * Power(second, wholeOfSecond); + if (!TreeAnalyzer.TryGetPolynomial(above, x, out var monomials)) + return null; + var degree = 0; + foreach (var pair in monomials) + { + if (pair.Key.Sign < 0 || pair.Key.CompareTo(EInteger.FromInt32(MaximumDegreeBesideTwoLinearRoots)) > 0 + || pair.Value.ContainsNode(x)) + return null; + degree = System.Math.Max(degree, pair.Key.ToInt32Unchecked()); + } + var t = new Entity[degree + 1]; + for (var j = 0; j <= degree; j++) + t[j] = monomials.TryGetValue(EInteger.FromInt32(j), out var coefficient) ? coefficient : Number.Integer.Zero; + + var q0 = a * c; + var q1 = a * d + b * c; + var q2 = b * d; + var root = MathS.Sqrt(first) / MathS.Sqrt(second); + + // Around the third linear's root, a symbol xi stands for -g/h until the end, so that + // what is computed is polynomial in it: T/(g + h x)^k is T/(h^k (x - xi)^k), and with + // T = sum tau_i (x - xi)^i its terms from (x - xi)^k up are the polynomial R(x), and the + // rest are tau_(k-j)/(x - xi)^j. + Variable? xi = null; + Entity? g = null; + Entity? h = null; + Entity? firstAtThePole = null; + Entity? secondAtThePole = null; + var polynomial = t; + var overThePole = new SortedDictionary(); + Entity ofTheThirdKind = Number.Integer.Zero; + if (third is { }) + { + if (!TreeAnalyzer.TryGetPolyLinear(third, x, out h, out g) || IsZero(h)) + return null; + // h^2 Q at the pole, (h a - g b)(h c - g d): zero where the third linear shares + // a root with one under a root, which is declined. + firstAtThePole = h * a - g * b; + secondAtThePole = h * c - g * d; + if (IsZero(firstAtThePole) || IsZero(secondAtThePole)) + return null; + xi = Variable.CreateUnique(expr, "pole"); + var alpha = Lowest((a + b * xi) * (c + d * xi)); + var beta = Lowest(q1 + 2 * q2 * xi); + var gamma = q2; + var tau = new Entity[degree + 1]; + for (var i = 0; i <= degree; i++) + { + Entity sum = Number.Integer.Zero; + for (var m = i; m <= degree; m++) + if (t[m] != Number.Integer.Zero) + sum = sum + t[m] * Binomial(m, i) * Power(xi, m - i); + tau[i] = Lowest(sum); + } + polynomial = new Entity[System.Math.Max(degree - order + 1, 0)]; + for (var m = 0; m < polynomial.Length; m++) + { + Entity sum = Number.Integer.Zero; + for (var i = order + m; i <= degree; i++) + if (tau[i] != Number.Integer.Zero) + sum = sum + tau[i] * Binomial(i - order, m) * Power(-xi, i - order - m); + polynomial[m] = Lowest(sum); + } + // I_j = int 1/((x - xi)^j S), with Q = alpha + beta (x - xi) + gamma (x - xi)^2. The + // derivative of S (x - xi)^(1-j) is + // (2 (1 - j) alpha (x - xi)^(-j) + (3 - 2j) beta (x - xi)^(1-j) + // + (4 - 2j) gamma (x - xi)^(2-j)) / (2 S), + // so alpha^(j-1) I_j is a polynomial in xi times powers of x - xi, times S, and a + // polynomial in xi times I_1: divided by alpha only once, at the end. + var scaled = new Dictionary[order + 1]; + var ofTheFirst = new Entity[order + 1]; + scaled[0] = new Dictionary(); + ofTheFirst[0] = Number.Integer.Zero; + if (order >= 1) + { + scaled[1] = new Dictionary(); + ofTheFirst[1] = Number.Integer.One; + } + for (var j = 2; j <= order; j++) + { + var these = new Dictionary { [1 - j] = 2 * Power(alpha, j - 2) }; + foreach (var (earlier, times) in new[] { (scaled[j - 1], (3 - 2 * j) * beta), (scaled[j - 2], (4 - 2 * j) * gamma * alpha) }) + foreach (var pair in earlier) + these[pair.Key] = these.TryGetValue(pair.Key, out var so) ? so - times * pair.Value : -times * pair.Value; + scaled[j] = these.ToDictionary(pair => pair.Key, pair => Lowest(pair.Value / (2 * (1 - j)))); + ofTheFirst[j] = Lowest((-(3 - 2 * j) * beta * ofTheFirst[j - 1] - (4 - 2 * j) * gamma * alpha * ofTheFirst[j - 2]) / (2 * (1 - j))); + } + // sum tau_(k-j) I_j over alpha^(k-1). + for (var j = 1; j <= order; j++) + { + if (order - j > degree || tau[order - j] == Number.Integer.Zero) + continue; + var weight = tau[order - j] * Power(alpha, order - j); + foreach (var pair in scaled[j]) + overThePole[pair.Key] = overThePole.TryGetValue(pair.Key, out var so) ? so + weight * pair.Value : weight * pair.Value; + ofTheThirdKind = ofTheThirdKind + weight * ofTheFirst[j]; + } + foreach (var power in overThePole.Keys.ToList()) + overThePole[power] = Lowest(overThePole[power]); + ofTheThirdKind = Lowest(ofTheThirdKind); + } + + // The polynomial part: u_(j-1) from the top down, and lambda at x^0. + var u = new Entity[polynomial.Length + 1]; + for (var j = 0; j < u.Length; j++) + u[j] = Number.Integer.Zero; + Entity lambda = Number.Integer.Zero; + if (polynomial.Length > 0) + { + var n = polynomial.Length - 1; + for (var j = n; j >= 1; j--) + u[j - 1] = Lowest((polynomial[j] - (j + 1) * q0 * u[j + 1] - Number.Rational.Create(2 * j + 1, 2) * q1 * u[j]) / (j * q2)); + lambda = polynomial[0] - q0 * u[1] - q1 * u[0] / 2; + } + + // xi back to -g/h, with the 1/h^k in front. Each side of a coefficient is a + // polynomial in xi, written homogeneous in g and h with the powers of h counted: + // substituted as it stands, each term would bring its own power of h below the bar, + // and over one bar they multiply. + Entity? Back(Entity coefficient, int powerOfH, int belowAtThePole, int belowTheFirst) + { + var (above, below) = Functions.SingleQuotient.Of(Lowest(coefficient)); + if (xi is null) + return Lowest(above / below); + if (Homogeneous(above) is not var (aboveInGAndH, aboveDegree) || Homogeneous(below) is not var (belowInGAndH, belowDegree)) + return null; + var power = powerOfH + belowDegree - aboveDegree - order; + var numerator = Lowest(power > 0 ? aboveInGAndH * Power(h!, power) : aboveInGAndH); + if (numerator == Number.Integer.Zero) + return Number.Integer.Zero; + var denominator = Lowest(power < 0 ? belowInGAndH * Power(h!, -power) : belowInGAndH); + // alpha^(k-1) at the pole is ((h a - g b)(h c - g d))^(k-1)/h^(2 (k - 1)), its powers + // of h counted in powerOfH; the two linears are left as written. + Entity written = denominator * Power(firstAtThePole!, belowTheFirst) * Power(secondAtThePole!, belowAtThePole); + var lowest = Lowest(numerator / written); + return lowest.Complexity <= (numerator / written).Complexity ? lowest : numerator / written; + } + (Entity, int)? Homogeneous(Entity polynomial) + { + if (!TreeAnalyzer.TryGetPolynomial(polynomial, xi!, out var byPower) || byPower.Keys.Any(power => power.Sign < 0 || !power.CanFitInInt32())) + return null; + var top = byPower.Keys.Max()!.ToInt32Unchecked(); + Entity sum = Number.Integer.Zero; + foreach (var pair in byPower) + sum = sum + pair.Value * Power(-g!, pair.Key.ToInt32Unchecked()) * Power(h!, top - pair.Key.ToInt32Unchecked()); + return (Lowest(sum), top); + } + + Entity algebraic = Number.Integer.Zero; + for (var j = u.Length - 1; j >= 0; j--) + if (u[j] != Number.Integer.Zero) + { + if (Back(u[j], 0, 0, 0) is not { } coefficient) + return null; + if (coefficient != Number.Integer.Zero) + algebraic = algebraic + coefficient * Power(x, j); + } + // (x - xi)^p is h^(-p) (g + h x)^p, and 1/alpha^(k-1) brings h^(2 (k - 1)). + foreach (var pair in overThePole) + { + if (Back(pair.Value, -pair.Key + 2 * (order - 1), order - 1, order - 1) is not { } coefficient) + return null; + if (coefficient != Number.Integer.Zero) + algebraic = algebraic + coefficient / Power(third!, -pair.Key); + } + var answer = algebraic * MathS.Sqrt(first) * MathS.Sqrt(second); + if (lambda != Number.Integer.Zero) + { + if (Back(lambda / b, 0, 0, 0) is not { } ofTheLogarithm) + return null; + // int 1/S, with 2 artanh(z) written as the logarithm the library writes it as. + var r = Lowest(d / b); + if (ofTheLogarithm != Number.Integer.Zero) + answer = answer + (r.Evaled is Number.Real { IsNegative: true } + ? 2 * ofTheLogarithm * MathS.Arctan(MathS.Sqrt(-r) * root) / MathS.Sqrt(-r) + : ofTheLogarithm * MathS.Ln((1 + MathS.Sqrt(r) * root) / (1 - MathS.Sqrt(r) * root)) / MathS.Sqrt(r)); + } + if (xi is { } && ofTheThirdKind != Number.Integer.Zero) + { + // int 1/((x - xi) S) is h I_1, and I_1 = -2 arctan(sqrt(rho) t)/((h a - g b) sqrt(rho)) with + // rho = (g d - h c)/(h a - g b). + if (Back(ofTheThirdKind, 2 * (order - 1) + 1, order - 1, order) is not { } coefficient) + return null; + var rho = Lowest(-secondAtThePole! / firstAtThePole!); + if (coefficient != Number.Integer.Zero) + answer = answer + (rho.Evaled is Number.Real { IsNegative: true } + ? -coefficient * MathS.Ln((1 + MathS.Sqrt(-rho) * root) / (1 - MathS.Sqrt(-rho) * root)) / MathS.Sqrt(-rho) + : -2 * coefficient * MathS.Arctan(MathS.Sqrt(rho) * root) / MathS.Sqrt(rho)); + } + return (constantBelow == Number.Integer.One ? answer : answer / constantBelow).InnerSimplified; + + static Entity Lowest(Entity e) => Functions.PartialFractions.InLowestTermsOverTheSymbols(e); + static bool IsZero(Entity e) => e.InnerSimplified is var simplified + && (simplified.Evaled is Number.Complex { IsZero: true } || simplified.Vars.Any() && Lowest(simplified) == Number.Integer.Zero); + // Not e^0, which is 1 only where e is not 0, and says so. + static Entity Power(Entity e, int n) => n switch { 0 => Number.Integer.One, 1 => e, _ => MathS.Pow(e, n) }; + static Entity Binomial(int n, int k) + { + var result = EInteger.One; + for (var i = 1; i <= k; i++) + result = result.Multiply(EInteger.FromInt32(n - k + i)).Divide(EInteger.FromInt32(i)); + return Number.Integer.Create(result); + } + } + + /// + /// The degree of the polynomial + /// solves for: one unknown a degree, and Rubi's 1.1.1.6 reaches eight. + /// + private const int MaximumDegreeBesideTwoLinearRoots = 16; + /// /// Whether is a quotient of two polynomials linear in /// , the one below with a slope. diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 5889a488e..db3ca5074 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -736,6 +736,11 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // `x/sqrt(1 - x^4)`, which the substitution answers, and it is what by parts leaves // from `arcsin(x)/(1 + x^2)^(3/2)`. if ((answer = IndefiniteIntegralSolver.SolveByCombiningRadicals(expr, x, integrateByParts)) is { }) return answer; + // A polynomial beside the roots of two linears with symbols in them, which the + // combining above cannot sign, and over a power of one more linear: + // `(A + B x + C x^2) sqrt(c + d x) sqrt(e + f x)` by undetermined coefficients, + // where the substitution further down took gigabytes. + if ((answer = IndefiniteIntegralSolver.SolveAPolynomialOverAPowerOfALinearBesideTwoRoots(expr, x)) is { }) return answer; // A square root of a polynomial with a repeated factor, the factor taken out of // the root with its sign: `sqrt((x - 3)^2 (x + 1))` is `sgn(x - 3) (x - 3) sqrt(x + 1)`. if ((answer = IndefiniteIntegralSolver.SolveByTakingASquareFactorOutOfARoot(expr, x, integrateByParts)) is { }) return answer; diff --git a/Sources/Tests/UnitTests/Calculus/TwoLinearRadicalsIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/TwoLinearRadicalsIntegralTest.cs index 97625e76b..57e585d44 100644 --- a/Sources/Tests/UnitTests/Calculus/TwoLinearRadicalsIntegralTest.cs +++ b/Sources/Tests/UnitTests/Calculus/TwoLinearRadicalsIntegralTest.cs @@ -6,6 +6,7 @@ // using System; +using System.Linq; using AngouriMath.Extensions; using Xunit; @@ -34,8 +35,10 @@ private static void DifferentiatesBackPinned(string integrand, double[] points, var integral = integrand.ToEntity().Integrate("x"); Assert.DoesNotContain("integral(", integral.Stringize()); - var derivative = integral.Substitute("C", 0).Differentiate("x"); + // The integration constant is C_1 where the integrand has a coefficient named C, + // and zeroing C there would take the coefficient out of the answer. Entity original = integrand.ToEntity(); + var derivative = (original.Vars.Any(v => v.Name == "C") ? integral : integral.Substitute("C", 0)).Differentiate("x"); foreach (var (name, value) in pins) { derivative = derivative.Substitute(name, value); @@ -69,18 +72,57 @@ public void TwoRootsOfTheSameOrder(string integrand) /// /// Two square roots of linears with symbolic coefficients, Hearn's - /// sqrt(a + b x) sqrt(c + d x): the terms are read as written so that the cube - /// of the quadratic the derivative of x(t) carries stays a cube, and the power - /// of a quadratic with a symbolic leading coefficient is made monic before the - /// rational rules see it. + /// sqrt(a + b x) sqrt(c + d x). Beside a polynomial they are answered by + /// undetermined coefficients. With a root below the bar to a higher power, the last + /// row, they go through the quotient of the roots: the terms are read as written so + /// that the power of the quadratic the derivative of x(t) carries stays that + /// power, and the power of a quadratic with a symbolic leading coefficient is made + /// monic before the rational rules see it. /// [Theory] [InlineData("sqrt(a + b*x)*sqrt(c + d*x)")] [InlineData("x/(sqrt(a + b*x)*sqrt(c + d*x))")] [InlineData("1/(sqrt(a + b*x)*sqrt(c + d*x))")] + [InlineData("sqrt(c + d*x)/(a + b*x)^(3/2)")] public void SymbolicCoefficients(string integrand) => DifferentiatesBackPinned(integrand, new[] { 0.3, 0.9, 1.7, 2.6 }, ("a", 1.7), ("b", 2.3), ("c", 0.6), ("d", 1.1)); + /// + /// A polynomial beside the square roots of two linears with symbols in them, Rubi's + /// 1.1.1.6, by undetermined coefficients: U sqrt(L1) sqrt(L2) and a multiple of + /// the integral of 1/(sqrt(L1) sqrt(L2)). Through the quotient of the roots + /// the first five took more than 4 GB each. With the slopes of opposite signs the + /// integral left is an arctangent, and the sixth row has numbers for the slopes, so the + /// arctangent is written as one. + /// + [Theory] + [InlineData("(A + B*x + C*x^2)*sqrt(c + d*x)*sqrt(e + f*x)")] + [InlineData("(a + b*x)^2*(A + B*x + C*x^2)*sqrt(c + d*x)*sqrt(e + f*x)")] + [InlineData("(A + B*x + C*x^2)*sqrt(c + d*x)/sqrt(e + f*x)")] + [InlineData("(e + f*x)^3*(A + B*x + C*x^2)*sqrt(a + b*x)*sqrt(a*c - b*c*x)")] + [InlineData("(c + d*x)^(3/2)*sqrt(e + f*x)")] + [InlineData("x^2*sqrt(a + 2*x)*sqrt(c - 3*x)")] + [InlineData("(a + b*x)*(A + B*x + C*x^2)/(sqrt(c + d*x)*sqrt(e + f*x))")] + [InlineData("x*sqrt(1 + d*x)*sqrt(1 - f*x)")] + public void APolynomialBesideTheRootsOfTwoLinears(string integrand) + => DifferentiatesBackPinned(integrand, new[] { 0.3, 0.9, 1.7, 2.6 }, + ("a", 1.3), ("b", 0.7), ("c", 1.9), ("d", 0.45), ("e", 2.3), ("f", 0.55), ("A", 1.1), ("B", -0.8), ("C", 0.35)); + + /// + /// The same over a power of a third linear, the rest of Rubi's 1.1.1.6: the terms over + /// its powers are reduced to the integral of 1/((g + h x) S), an arctangent of the + /// quotient of the roots, which the substitution answered by a rational function in it + /// past the corpus's budget or not at all. + /// + [Theory] + [InlineData("1/((1 + x)*sqrt(a + b*x)*sqrt(c - d*x))")] + [InlineData("(A + B*x + C*x^2)/((e + f*x)^2*sqrt(a + b*x)*sqrt(a*c - b*c*x))")] + [InlineData("(A + B*x + C*x^2)*sqrt(c + d*x)*sqrt(e + f*x)/(a + b*x)^3")] + [InlineData("(A + B*x + C*x^2)*sqrt(c + d*x)/((a + b*x)^4*sqrt(e + f*x))")] + public void OverAPowerOfAThirdLinear(string integrand) + => DifferentiatesBackPinned(integrand, new[] { 0.3, 0.9, 1.7, 2.6 }, + ("a", 1.3), ("b", 0.7), ("c", 1.9), ("d", 0.45), ("e", 2.3), ("f", 0.55), ("A", 1.1), ("B", -0.8), ("C", 0.35)); + /// Roots of different orders sharing a common one: Timofeev's 315, a sixth root of the quotient. [Fact] public void RootsOfDifferentOrdersInASum() From 0a3725ef349a1b5090eae1b242bb0c4f63914b45 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 13:39:57 +0000 Subject: [PATCH 2/4] The breaking-changes entry for a polynomial beside the roots of two linears Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index a49a687ff..dd3f89d82 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -508,6 +508,23 @@ in both quadratics, the cube's coefficients grow past what the reduction takes, | `"(7 + 13*x)/((5 + x + 2*x^2)^3*sqrt(2 + x + 3*x^2))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative | | `"sqrt(a + a*sec(x))/(c + d*sec(x))^2".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `tan(x/2)` | +### A polynomial beside the square roots of two linears with symbols in them is integrated + +`P(x) sqrt(c + d x) sqrt(e + f x)`, a polynomial beside the roots of two linears with symbols in +them or over their product, was left unevaluated, and so was the same over a power of a third +linear. These are Rubi's 1.1.1.6, `P(x) (a + b x)^m (c + d x)^n (e + f x)^p`. They are now +integrated by undetermined coefficients. The answer is a rational function times the two roots, +a logarithm of their quotient, and an arctangent of the quotient where a third linear is below +the bar. Where the slopes are numbers of opposite signs, the logarithm is written as the +arctangent it is ([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"sqrt(c + d*x)*sqrt(e + f*x)".ToEntity().Integrate("x")` | `integral(...)` | `(x/2 + (d e + c f)/(4 d f)) sqrt(c + d x) sqrt(e + f x)`, and a logarithm in `sqrt(f/d) sqrt(c + d x)/sqrt(e + f x)` | +| `"(A + B*x + C*x^2)*sqrt(c + d*x)*sqrt(e + f*x)".ToEntity().Integrate("x")` | `integral(...)` | a cubic times the two roots, and the same logarithm | +| `"(A + B*x + C*x^2)*sqrt(c + d*x)/((a + b*x)^3*sqrt(e + f*x))".ToEntity().Integrate("x")` | `integral(...)` | the roots over powers of `a + b x`, a logarithm, and an arctangent | +| `"x^2*sqrt(a + 2*x)*sqrt(c - 3*x)".ToEntity().Integrate("x")` | `integral(...)` | a cubic times the two roots, and an arctangent of `sqrt(6)/2 sqrt(a + 2 x)/sqrt(c - 3 x)` | + ### A function comes out of a fractional power of its even power with its sign **Improvement, not silent.** The entry two above made `(sin(x)^2)^(3/2)` the modulus `|sin(x)|^3` From af0dc912e73bd674bf0fc0eca0908712d06f4df2 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 14:02:38 +0000 Subject: [PATCH 3/4] The roots of two linears are taken by undetermined coefficients only with a symbol in them With numbers in both linears the combining of roots and the quotient substitution answer, in their own forms, and the rule is for the symbols that those declined or took gigabytes over: below the top, where the combining does not run, it would otherwise answer what they did, in another form. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Continuous/Integration/IndefiniteIntegralSolver.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index e393aee9f..c801946a9 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -8009,9 +8009,12 @@ static Entity WithWholePowersOfTheSecond(List<(EInteger Power, Entity Coefficien return null; } } - // Two proportional linears are one root with a constant in it, which - // AsOneLinearRadical takes. + // With numbers in both linears the combining of roots and the quotient substitution + // answer, and in their own forms; this is for the symbols, which those declined or + // took gigabytes over. Two proportional linears are one root with a constant in it, + // which AsOneLinearRadical takes. if (first is null || second is null + || !first.Vars.Concat(second.Vars).Any(symbol => symbol != x) || !TreeAnalyzer.TryGetPolyLinear(first, x, out var b, out var a) || !TreeAnalyzer.TryGetPolyLinear(second, x, out var d, out var c) || IsZero(b) || IsZero(d) || IsZero(b * c - a * d)) From c82235e65a58bad9cc1c22ab8e8af6cfd9105b9b Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 21:09:48 +0000 Subject: [PATCH 4/4] Beside two linear roots, each closed form is given where it is real The integral of 1/S is a logarithm for one sign of d/b and an arctangent for the other, and the third kind's is the same in rho. Where the quantity has symbols in it, both are given, each provided where it holds, as 1/(a - x^2) is answered. One form alone is complex, by a constant, on the side where the other is real, and an answer that writes each linear once checks its arms there. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Integration/IndefiniteIntegralSolver.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 0a625edfe..b228374d7 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -8256,9 +8256,9 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer && // int 1/S, with 2 artanh(z) written as the logarithm the library writes it as. var r = Lowest(d / b); if (ofTheLogarithm != Number.Integer.Zero) - answer = answer + (r.Evaled is Number.Real { IsNegative: true } - ? 2 * ofTheLogarithm * MathS.Arctan(MathS.Sqrt(-r) * root) / MathS.Sqrt(-r) - : ofTheLogarithm * MathS.Ln((1 + MathS.Sqrt(r) * root) / (1 - MathS.Sqrt(r) * root)) / MathS.Sqrt(r)); + answer = answer + BySign(r, + ofTheLogarithm * MathS.Ln((1 + MathS.Sqrt(r) * root) / (1 - MathS.Sqrt(r) * root)) / MathS.Sqrt(r), + 2 * ofTheLogarithm * MathS.Arctan(MathS.Sqrt(-r) * root) / MathS.Sqrt(-r)); } if (xi is { } && ofTheThirdKind != Number.Integer.Zero) { @@ -8268,13 +8268,20 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer && return null; var rho = Lowest(-secondAtThePole! / firstAtThePole!); if (coefficient != Number.Integer.Zero) - answer = answer + (rho.Evaled is Number.Real { IsNegative: true } - ? -coefficient * MathS.Ln((1 + MathS.Sqrt(-rho) * root) / (1 - MathS.Sqrt(-rho) * root)) / MathS.Sqrt(-rho) - : -2 * coefficient * MathS.Arctan(MathS.Sqrt(rho) * root) / MathS.Sqrt(rho)); + answer = answer + BySign(rho, + -2 * coefficient * MathS.Arctan(MathS.Sqrt(rho) * root) / MathS.Sqrt(rho), + -coefficient * MathS.Ln((1 + MathS.Sqrt(-rho) * root) / (1 - MathS.Sqrt(-rho) * root)) / MathS.Sqrt(-rho)); } return (constantBelow == Number.Integer.One ? answer : answer / constantBelow).InnerSimplified; static Entity Lowest(Entity e) => Functions.PartialFractions.InLowestTermsOverTheSymbols(e); + // Each closed form is real on one side of the sign of the quantity under its roots, and + // complex by a constant on the other: the form for the sign of a number, and both, each + // where it holds, for a quantity with symbols in it, as `1/(a - x^2)` is answered. + static Entity BySign(Entity quantity, Entity wherePositive, Entity whereNegative) + => !quantity.Vars.Any() && quantity.InnerSimplified is Number.Real number + ? (number.IsNegative ? whereNegative : wherePositive) + : MathS.Piecewise((wherePositive, new Greaterf(quantity, Number.Integer.Zero)), (whereNegative, new Lessf(quantity, Number.Integer.Zero))); static bool IsZero(Entity e) => e.InnerSimplified is var simplified && (simplified.Evaled is Number.Complex { IsZero: true } || simplified.Vars.Any() && Lowest(simplified) == Number.Integer.Zero); // Not e^0, which is 1 only where e is not 0, and says so.