Skip to content

Commit 06070d2

Browse files
A rational function of the tangent of a linear argument with symbols in it is not simplified under the linear substitution (#1731)
* A linear substitution's quotient is not simplified The substitution search reaches tan(g + h x) through u = g + h x and simplified the quotient of the integrand by du/dx in u before asking for its integral. Under a linear candidate that quotient is the integrand with its argument renamed, over a constant, and holds nothing to simplify; with the nine symbols of Rubi's 4.3.4.2 in it the simplification took 28 of 32 s. It is handed on as it is: (a + b tan(g + h x))(A + B tan(g + h x) + K tan(g + h x)^2)/(c + d tan(g + h x))^2 is answered in 4.5 s where master took 38, and the cube over a cube in 18 s where master ran past a minute and a half. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * Only a function of the tangent alone is handed on unsimplified under a linear substitution Measured one build at a time, seven integrands master answers ran out of time on the branch: beside a sine, a secant, a logarithm or the imaginary unit, the simplified form is what the rules after the substitution read, and cot(c + d x)^8/(a + a sin(c + d x)) went from one second to seventy without it. The quotient is handed on unsimplified only where every function of u in it is its tangent or cotangent and it holds no imaginary unit, which is 4.3.4.2's shape; the seven are back at master's times and 4.3.4.2's answers keep theirs. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * The linear substitution's entry gives the time master measures today Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 752974b commit 06070d2

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,21 @@ those now. Each answer holds on both sides of zero, an odd root of a negative be
843843
| `"x^4*(a + b*x^3)^(1/3)/(c + d*x^3)".ToEntity().Integrate("x")` | `integral(...)` | the same, beside a rational function of it |
844844
| `"x/((1 + x^3)^(2/3)*(2 + x^3))".ToEntity().Integrate("x")` | `integral(...)` | the same with numbers |
845845

846+
### A rational function of the tangent of a linear argument with symbols in it is not simplified under the linear substitution
847+
848+
**Answers where there were none.** The substitution search reaches `tan(g + h x)` through `u = g + h x`,
849+
and simplified the quotient of the integrand by `h` in `u` before asking for its integral: with the
850+
nine symbols of Rubi's 4.3.4.2 in it that took about half a minute, for an expression that is the
851+
integrand with its argument renamed and holds nothing to simplify. Under a linear candidate, where
852+
the integrand in `u` is a function of the tangent alone and holds no imaginary unit, the quotient
853+
is handed on as it is
854+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
855+
856+
| Input | Was (2.5.0) | Now |
857+
|---|---|---|
858+
| `"(a + b*tan(g + h*x))*(A + B*tan(g + h*x) + K*tan(g + h*x)^2)/(c + d*tan(g + h*x))^2".ToEntity().Integrate("x")` | `integral(...)` after 33 s | the antiderivative, in 4.5 s |
859+
| `"(c + d*tan(g + h*x))^3*(A + B*tan(g + h*x) + K*tan(g + h*x)^2)/(a + b*tan(g + h*x))^3".ToEntity().Integrate("x")` | no answer within a minute and a half | the antiderivative, in 18 s |
860+
846861
### A rational function of `x^n` beside a power of a symbolic binomial is integrated without a search
847862

848863
**Answers where there were none.** A rational function of `x^n` beside `(c + d x^n)^(k - 1/n)` is a

‎Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23726,6 +23726,17 @@ private static bool HoldsAnEvenRootBesides(Entity expr, Entity radicand, Entity.
2372623726
return false;
2372723727
}
2372823728

23729+
/// <summary>
23730+
/// Whether every function of <paramref name="u"/> in <paramref name="expr"/> is its tangent
23731+
/// or its cotangent: sums, products, quotients and powers of those, and of anything free of
23732+
/// <paramref name="u"/>.
23733+
/// </summary>
23734+
private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
23735+
=> expr.Nodes.All(node => node is Sumf or Minusf or Mulf or Divf or Powf or Number or Variable
23736+
|| !node.ContainsNode(u)
23737+
|| node is Tanf(var argument) && argument == u
23738+
|| node is Cotanf(var cotangentArgument) && cotangentArgument == u);
23739+
2372923740
internal static Entity? SolveBySubstitution(Entity expr, Entity.Variable x, bool integrateByParts = true)
2373023741
{
2373123742
// A rational function over written linear factors with symbols in their
@@ -23877,7 +23888,20 @@ private static bool HoldsAnEvenRootBesides(Entity expr, Entity radicand, Entity.
2387723888
&& expr.Complexity <= (expr.Vars.Any(v => v != x) ? LargestSymbolicIntegrandCollected : LargestIntegrandOfferedSums)
2387823889
? WithThePowersOfXCollected(Functions.SingleQuotient.Combine(expr / duDx), x)
2387923890
: source / duDx;
23880-
integrandInU = SimplifiedWithoutTheImaginaryUnit(InTermsOf(quotient, u, uSub, x), expr);
23891+
// Under a linear candidate the quotient is the integrand with its argument
23892+
// renamed, over a constant, and where it is a function of the tangent alone
23893+
// there is nothing in it for the simplifier to find:
23894+
// `(a + b tan(e + f x))(A + B tan(e + f x) + C tan(e + f x)^2)/(c + d tan(e + f x))^2`
23895+
// under `u = e + f x` spent 28 of its 32 s being simplified, nine symbols and
23896+
// nothing to cancel. Only there: beside a sine, a secant, a logarithm or the
23897+
// imaginary unit the simplified form is what the rules after this read, and
23898+
// `cot(c + d x)^8/(a + a sin(c + d x))` went from one second to seventy without it.
23899+
var inTermsOfU = InTermsOf(quotient, u, uSub, x);
23900+
integrandInU = !inTermsOfU.ContainsNode(x)
23901+
&& TreeAnalyzer.TryGetPolyLinear(u, x, out var slope, out var offset) && !slope.ContainsNode(x) && !offset.ContainsNode(x)
23902+
&& IsAFunctionOfTheTangentAlone(inTermsOfU, uSub) && !HoldsTheImaginaryUnit(inTermsOfU)
23903+
? Functions.PartialFractions.Bare(inTermsOfU.InnerSimplified)
23904+
: SimplifiedWithoutTheImaginaryUnit(inTermsOfU, expr);
2388123905
// A factor written on both sides of the bar cancelled, where x survived:
2388223906
// the one-level simplification leaves `u/((a w + b)^2 p u)` as it is, and
2388323907
// the candidate was refused for the u it did not cancel.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// A rational function of the tangent of a linear argument with symbols for its
16+
/// coefficients, Rubi's 4.3.3.1 and 4.3.4.2. The substitution search reaches the tangent
17+
/// through <c>u = g + h x</c>, and under a linear candidate the quotient by its derivative is
18+
/// the integrand with its argument renamed over a constant: there is nothing in it to
19+
/// simplify, and simplifying it with nine symbols in it was most of the time each of these
20+
/// took.
21+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
22+
/// </summary>
23+
/// <remarks>
24+
/// Checked by differentiating back with the symbols pinned after the integral is taken, at
25+
/// points where the tangent and every factor below the bar stay away from their poles and
26+
/// zeros.
27+
/// </remarks>
28+
[Trait("Area", "Calculus")]
29+
public sealed class LinearArgumentSubstitutionTest
30+
{
31+
private static readonly double[] Points = { 0.2, 0.5, 0.8 };
32+
33+
[Theory]
34+
[InlineData("(a + b*tan(g + h*x))*(A + B*tan(g + h*x) + K*tan(g + h*x)^2)/(c + d*tan(g + h*x))^2")]
35+
[InlineData("(a + b*tan(g + h*x))*(A + B*tan(g + h*x))/(c + d*tan(g + h*x))^2")]
36+
[InlineData("(A + B*tan(g + h*x) + K*tan(g + h*x)^2)/((a + b*tan(g + h*x))*(c + d*tan(g + h*x)))")]
37+
public void ARationalFunctionOfTheTangentOfALinear(string integrand)
38+
{
39+
var integral = integrand.ToEntity().Integrate("x");
40+
Assert.DoesNotContain("integral(", integral.Stringize());
41+
Entity Pin(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 2.1).Substitute("d", 0.9)
42+
.Substitute("g", 0.3).Substitute("h", 1.1).Substitute("A", 0.5).Substitute("B", 1.7).Substitute("K", 0.4);
43+
var derivative = Pin(integral.Substitute("C", 0)).Differentiate("x");
44+
var original = Pin(integrand.ToEntity());
45+
foreach (var point in Points)
46+
{
47+
var expected = original.Substitute("x", point).EvalNumerical().RealPart.EDecimal.ToDouble();
48+
var actual = derivative.Substitute("x", point).EvalNumerical().RealPart.EDecimal.ToDouble();
49+
Assert.True(Math.Abs(expected - actual) < 1e-8 * Math.Max(1, Math.Abs(expected)),
50+
$"d/dx of the antiderivative of {integrand} is {actual} at x = {point}, where the integrand is {expected}");
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)