Skip to content

Commit 916f7c2

Browse files
Rafael-SOWNetclaude
andcommitted
The tangent substitution's integrand with symbols in it is not simplified either
Under u = tan(x) the integrand was simplified as under the half angle, and with symbols in it at the same cost: (c + d tan(x))^3 (A + B tan(x) + C tan(x)^2)/(a + b tan(x))^3 took 21 s, almost all of it in the simplifier, and takes 3 without. Both substitutions share one helper now. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent eaf9d91 commit 916f7c2

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,21 +630,24 @@ poles of `tan(x/2)`, as every half-angle answer.
630630
| `"1/(a+b*cos(x)+c*cos(x)^2)".Integrate("x")` | unevaluated | the cosine form |
631631
| `"csc(x)^2/(a-a*sin(x)^2)".Integrate("x")` | unevaluated | `-cot(x)/a` and two terms rational in `tan(x/2)` |
632632

633-
### A rational function of the sine and cosine with symbols in it is no longer simplified under the half angle
633+
### A rational function of the sine and cosine, or of the tangent, with symbols in it is no longer simplified under its substitution
634634

635635
**Answers where there were none.** Under `t = tan(x/2)` the integrand was simplified before it was
636636
integrated, and with symbols in it the simplifier's search grew past any budget:
637637
`sec(x)^2/(a + b cos(x))^3` spent 43 s in it and `sec(x)^2/(a + b cos(x))^4` more than two minutes,
638638
where integrating what it returned takes a tenth of a second. With a symbol in it the integrand is
639639
now put over one bar with its whole powers of products written as products of powers, and not
640-
simplified further; one without a symbol is simplified as before
640+
simplified further; one without a symbol is simplified as before. The same under `u = tan(x)`, where
641+
`(c + d tan(x))^3 (A + B tan(x) + C tan(x)^2)/(a + b tan(x))^3` spent most of its time the same way
641642
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
642643

643644
| Input | Was (2.5.0) | Now |
644645
|---|---|---|
645646
| `"sec(x)^2/(a + b*cos(x))^3".ToEntity().Integrate("x")` | `integral(...)` | a piecewise antiderivative in `tan(x/2)` |
646647
| `"sec(x)^2/(a + b*cos(x))^4".ToEntity().Integrate("x")` | `integral(...)` | the same |
647648
| `"sec(c + d*x)^2/(a + b*cos(c + d*x))^4".ToEntity().Integrate("x")` | `integral(...)` | the same in `tan((c + d x)/2)` |
649+
| `"(c + d*tan(x))^3*(A + B*tan(x) + C*tan(x)^2)/(a + b*tan(x))^3".ToEntity().Integrate("x")` | no answer within a minute and a half | an antiderivative in `tan(x)`, in 3 s |
650+
| `"(a + b*tan(x))*(A + B*tan(x) + C*tan(x)^2)/(c + d*tan(x))^2".ToEntity().Integrate("x")` | no answer within a minute and a half | an antiderivative in `tan(x)`, in 1 s |
648651

649652
### A linear over a quadratic beside the root of another quadratic is integrated
650653

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8429,7 +8429,7 @@ static bool IsTwice(Entity argument, Entity.Variable x)
84298429
break;
84308430
withOne = apart;
84318431
}
8432-
var signed = Functions.SingleQuotient.Combine(withOne / secantSquared.Substitute(tangent, uSub)).Simplify();
8432+
var signed = SimplifiedWhereNoSymbolIs(Functions.SingleQuotient.Combine(withOne / secantSquared.Substitute(tangent, uSub)), uSub);
84338433
if (signed is Providedf(var bareSigned, _))
84348434
signed = bareSigned;
84358435
if (signed.ContainsNode(x) || signed.Nodes.Any(node => node == MathS.NaN))
@@ -8448,8 +8448,10 @@ static bool IsTwice(Entity argument, Entity.Variable x)
84488448
// none: `1/(u^2*(1 + u^2))` is integrated and `(1/u)^2/(1 + u^2)`, which is the same
84498449
// expression, is not. The half-angle and exponential substitutions comb their
84508450
// integrands for the same reason.
8451-
var integrand = Functions.SingleQuotient
8452-
.Combine(inU / (1 + MathS.Sqr(uSub))).Simplify();
8451+
// Not simplified with a symbol in it, as under the half angle: `(c + d tan(x))^3
8452+
// (A + B tan(x) + C tan(x)^2)/(a + b tan(x))^3` took 21 s, most of them simplifying, and
8453+
// takes 3 without.
8454+
var integrand = SimplifiedWhereNoSymbolIs(Functions.SingleQuotient.Combine(inU / (1 + MathS.Sqr(uSub))), uSub);
84538455
if (integrand is Providedf(var withoutCondition, _))
84548456
integrand = withoutCondition;
84558457
return Integration.ComputeIndefiniteIntegral(integrand, uSub, integrateByParts) is { } result
@@ -22851,16 +22853,7 @@ static bool IsOneOfTheFour(Entity node, Entity argument)
2285122853
// `tan(x)^6/(a + b sec(x))` was declined that way. And a base of a lower degree than it
2285222854
// is written in is written as its polynomial: `a (1 + t^2) + a (1 - t^2)` is `2 a`, and
2285322855
// read as a quadratic its leading coefficient is zero as a value only.
22854-
var combined = Functions.SingleQuotient.Combine(inT * 2 / (rate * (1 + tSquared)));
22855-
Entity integrand;
22856-
if (combined.Vars.Any(symbol => symbol != t))
22857-
{
22858-
var (combinedAbove, combinedBelow) = Functions.SingleQuotient.Of(combined.InnerSimplified);
22859-
integrand = (WithDegenerateBasesLowered(WithWholePowersDistributed(combinedAbove), t)
22860-
/ WithDegenerateBasesLowered(WithWholePowersDistributed(combinedBelow), t)).InnerSimplified;
22861-
}
22862-
else
22863-
integrand = combined.Simplify();
22856+
var integrand = SimplifiedWhereNoSymbolIs(Functions.SingleQuotient.Combine(inT * 2 / (rate * (1 + tSquared))), t);
2286422857

2286522858
// Collapsing the nesting attaches a condition saying the denominator it cleared is
2286622859
// non-zero, and that denominator is 1 + t^2 -- so 1/(1 + cos(x)) comes out as
@@ -22918,6 +22911,22 @@ static bool NoRemainder(Entity rest)
2291822911
: null;
2291922912
}
2292022913

22914+
/// <summary>
22915+
/// A rational function of <paramref name="t"/> a trigonometric substitution made, put over
22916+
/// one bar, simplified where it holds no symbol but <paramref name="t"/>; where it holds one,
22917+
/// with its whole powers of products distributed and its bases of a lower degree than they
22918+
/// are written in lowered, and not simplified, since the simplifier's search grows with the
22919+
/// symbols past any budget where the integral of what it returns is a fraction of a second.
22920+
/// </summary>
22921+
private static Entity SimplifiedWhereNoSymbolIs(Entity combined, Entity.Variable t)
22922+
{
22923+
if (!combined.Vars.Any(symbol => symbol != t))
22924+
return combined.Simplify();
22925+
var (above, below) = Functions.SingleQuotient.Of(combined.InnerSimplified);
22926+
return (WithDegenerateBasesLowered(WithWholePowersDistributed(above), t)
22927+
/ WithDegenerateBasesLowered(WithWholePowersDistributed(below), t)).InnerSimplified;
22928+
}
22929+
2292122930
/// <summary>
2292222931
/// <paramref name="product"/> with each whole power of a product written as the product
2292322932
/// of the powers, the rest as written: <c>((1 + t^2)(1 - t^2))^6</c> is

0 commit comments

Comments
 (0)