Skip to content

Commit 0630504

Browse files
The tangent substitution, and a linear one, ask the same question (#1802)
* The tangent substitution, and a linear one, ask the same question cot(x)^(3/2) (a + b tan(x))^(3/2) is, in the tangent's u, a sign times a power of a quotient of linears over 1 + u^2, answered when it is asked directly. The tangent substitution asked it one level down, where the split of the quotient's root was out of the reach of the rules scoped to the question asked or one below it, and the integral was declined; with c + d x for x, the renaming of the argument by the substitution search was a level more. Both rename the variable and add no step of their own, and ask the same question now. A linear renaming does so once: one asked inside another spends its level, so two linear arguments renaming each other in turn are bounded by the descent as before. 4.3.2.1's cot^p (a + b tan)^q rows go from 1 of 24 answered to 14 with a 40-second budget, most in under half a second once the quotient of roots is in lowest terms. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * The renaming test asks only rows the integrator answers 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 ecab3f7 commit 0630504

3 files changed

Lines changed: 74 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,22 @@ Rubi's 1.3.2 ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
402402
| `"(k - 2*f*(n - 1)*x^n)/(k^2 + 4*d*f*x^2 + 4*k*f*x^n + 4*f^2*x^(2*n))".ToEntity().Integrate("x")` | `integral(...)` | the same in `x/(x^n + k/(2 f))` |
403403
| `"x^m*(k*(1 + m) + 2*f*(1 + m - n)*x^n)/(k^2 + 4*d*f*x^(2 + 2*m) + 4*k*f*x^n + 4*f^2*x^(2*n))".ToEntity().Integrate("x")` | `integral(...)` | the same in `x^(m + 1)/(x^n + k/(2 f))` |
404404

405+
### The tangent substitution, and a linear one, ask the same question
406+
407+
**Answers where there were none.** `cot(x)^(3/2) (a + b tan(x))^(3/2)` is, in the tangent's `u`, a sign
408+
times a power of a quotient of linears over `1 + u^2`, which is answered when it is asked directly; asked
409+
one level down, where the tangent substitution put it, the split its root's quotient leaves was past the
410+
reach of the rules scoped to the question asked or one below it, and the integral was declined. With
411+
`c + d x` for `x` the renaming of the argument was a level more. Both rename the variable and add no step
412+
of their own, and ask the same question now -- a linear renaming once, so that two arguments renaming
413+
each other in turn spend their levels as before. Rubi's 4.3.2.1
414+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
415+
416+
| Input | Was (2.5.0) | Now |
417+
|---|---|---|
418+
| `"cot(x)^(3/2)*(a + b*tan(x))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | a sign of the tangent times its antiderivative in `sqrt((a + b tan(x))/tan(x))` |
419+
| `"cot(c + d*x)^(5/2)*sqrt(a + b*tan(c + d*x))".ToEntity().Integrate("x")` | `integral(...)`; past half a minute on the unreleased master | the same |
420+
405421
### A half-odd power of a constant over a polynomial of either sign is integrated with its sign
406422

407423
**Answers where there were none.** `sqrt(1/(1 - x^2))`, the arcsine's derivative where it is real,

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10158,7 +10158,12 @@ static bool IsTwice(Entity argument, Entity.Variable x)
1015810158
.Combine(inU / (1 + MathS.Sqr(uSub))).Simplify();
1015910159
if (integrand is Providedf(var withoutCondition, _))
1016010160
integrand = withoutCondition;
10161-
return Integration.ComputeIndefiniteIntegral(integrand, uSub, integrateByParts) is { } result
10161+
// Asked as the same question: the rewrite renames the variable and adds no step of
10162+
// its own, and a rule scoped to the question asked or one below it reads the integrand
10163+
// in u as it reads it asked directly. Asked a level down, the split of
10164+
// `cot(x)^(3/2) (a + b tan(x))^(3/2)` in the root of its quotient was out of every such
10165+
// rule's reach, and the integral was declined where its integrand in u is answered.
10166+
return Integration.ComputeAsTheSameQuestion(integrand, uSub, integrateByParts) is { } result
1016210167
? result.Substitute(uSub, tangent)
1016310168
: null;
1016410169
}
@@ -27999,6 +28004,9 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
2799928004
|| node is Tanf(var argument) && argument == u
2800028005
|| node is Cotanf(var cotangentArgument) && cotangentArgument == u);
2800128006

28007+
/// <summary>Whether a linear renaming is being asked as the same question on this thread.</summary>
28008+
[System.ThreadStatic] private static bool renamingLinearly;
28009+
2800228010
internal static Entity? SolveBySubstitution(Entity expr, Entity.Variable x, bool integrateByParts = true)
2800328011
{
2800428012
// A rational function over written linear factors with symbols in their
@@ -28258,7 +28266,25 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
2825828266

2825928267
if (integrandInU.ContainsNode(x))
2826028268
continue;
28261-
if (Integration.ComputeIndefiniteIntegral(integrandInU, uSub, integrateByParts) is { } resultInU)
28269+
// Under a linear candidate the integrand is the same question with its argument
28270+
// renamed, and is asked as one, at the depth it was asked at: the rules scoped to the
28271+
// question asked or one below it then read `cot(c + d x)^(3/2) (a + b tan(c + d x))^(3/2)`
28272+
// as they read `cot(x)^(3/2) (a + b tan(x))^(3/2)`, where a level spent on the renaming
28273+
// put the split they answer it by out of reach. Once: a renaming asked inside another
28274+
// spends its level, so that two linear arguments renaming each other in turn are
28275+
// bounded by the descent as before.
28276+
var renaming = !renamingLinearly
28277+
&& TreeAnalyzer.TryGetPolyLinear(u, x, out var linearSlope, out var linearOffset) && !linearSlope.ContainsNode(x) && !linearOffset.ContainsNode(x);
28278+
Entity? inU;
28279+
if (renaming)
28280+
{
28281+
renamingLinearly = true;
28282+
try { inU = Integration.ComputeAsTheSameQuestion(integrandInU, uSub, integrateByParts); }
28283+
finally { renamingLinearly = false; }
28284+
}
28285+
else
28286+
inU = Integration.ComputeIndefiniteIntegral(integrandInU, uSub, integrateByParts);
28287+
if (inU is { } resultInU)
2826228288
{
2826328289
// An even root is not negative wherever it is real, so a sign or a modulus
2826428290
// of it that a rule below put in -- the answer for u > 0 extended by parity

‎Sources/Tests/UnitTests/Calculus/TangentSubstitutionIntegralTest.cs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,35 @@ public void ARepeatedQuadraticFromTheSubstitutionIsAnswered()
331331
$"d/dx of the antiderivative is {got} at x = {at}, where the integrand is {want}");
332332
}
333333
}
334+
335+
/// <summary>
336+
/// The tangent substitution, and a linear one, rename the variable and ask the same
337+
/// question, so a rule scoped to the question asked or one below it reads what they make
338+
/// as it would read it asked directly. <c>cot(x)^(3/2) (a + b tan(x))^(3/2)</c> is, in the
339+
/// tangent's <c>u</c>, a sign times a power of a quotient of linears over <c>1 + u^2</c>,
340+
/// answered when that is asked at the top; one level down the split of its quotient in the
341+
/// root declined, and with <c>c + d x</c> for <c>x</c> it was two. Rubi's 4.3.2.1, with
342+
/// <c>c + d x</c> positive under the points, where the tangent is.
343+
/// </summary>
344+
[Theory]
345+
[InlineData("cot(x)^(3/2)*(a + b*tan(x))^(3/2)")]
346+
[InlineData("cot(c + d*x)^(3/2)*(a + b*tan(c + d*x))^(3/2)")]
347+
[InlineData("cot(c + d*x)^(5/2)*sqrt(a + b*tan(c + d*x))")]
348+
[InlineData("cot(c + d*x)^(3/2)/(a + b*tan(c + d*x))^(3/2)")]
349+
public void ASubstitutionThatRenamesAsksTheSameQuestion(string integrand)
350+
{
351+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.1).Substitute("d", 0.9);
352+
var integral = integrand.ToEntity().Integrate("x");
353+
Assert.DoesNotContain("integral(", integral.Stringize());
354+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
355+
var original = Pinned(integrand.ToEntity());
356+
foreach (var at in Points)
357+
{
358+
var got = derivative.Substitute("x", at).EvalNumerical();
359+
var want = original.Substitute("x", at).EvalNumerical();
360+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart) < 1e-9 * Math.Max(1.0, Math.Abs((double)want.RealPart)),
361+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
362+
}
363+
}
334364
}
335365
}

0 commit comments

Comments
 (0)