@@ -4595,6 +4595,76 @@ static bool IsHalfOdd(Entity exponent) => exponent is Number.Rational rational a
45954595 return expr * inTermsOfU.Substitute(u, other.Radicand) / inX;
45964596 }
45974597
4598+ /// <summary>
4599+ /// An odd whole power of <c>tan(y)</c> beside a function of <c>sec(y)</c>, integrated in
4600+ /// <c>u = sec(y)</c>: <c>du = sec(y) tan(y) dy</c> and the even power of the tangent left over
4601+ /// is a power of <c>u^2 - 1</c>, so <c>tan(y)^n</c> with the rest is
4602+ /// <c>(u^2 - 1)^((n - 1)/2)/u du</c> beside it, exactly. The cotangent beside a function of
4603+ /// the cosecant, in <c>u = csc(y)</c>, the same.
4604+ /// </summary>
4605+ /// <remarks>
4606+ /// Rubi's <c>cot(c + d x)/(a + b sec(c + d x))^(3/2)</c> was declined and
4607+ /// <c>cot(c + d x)^3 sqrt(a + b sec(c + d x))</c> ran past thirty seconds, where in the
4608+ /// secant each is a rational function beside the root of a linear.
4609+ /// https://github.com/asc-community/AngouriMath/issues/718
4610+ /// </remarks>
4611+ internal static Entity? SolveAnOddPowerOfTheTangentBesideAFunctionOfTheSecant(Entity expr, Entity.Variable x, bool integrateByParts)
4612+ {
4613+ if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
4614+ return null;
4615+ Entity? argument = null;
4616+ foreach (var node in expr.Nodes)
4617+ {
4618+ if (TrigonometricArgument(node) is not { } thisArgument || !thisArgument.ContainsNode(x))
4619+ continue;
4620+ if (argument is null)
4621+ argument = thisArgument;
4622+ else if (argument != thisArgument)
4623+ return null;
4624+ }
4625+ if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out _)
4626+ || rate.ContainsNode(x) || TreeAnalyzer.IsZero(rate))
4627+ return null;
4628+ if (!expr.Nodes.All(node => !node.ContainsNode(x)
4629+ || node is Variable or Sumf or Minusf or Mulf or Divf or Sinf or Cosf or Secantf or Cosecantf or Tanf or Cotanf
4630+ || node is Powf(_, Number.Rational)))
4631+ return null;
4632+ var t = Variable.CreateUnique(expr, "t_odd_tangent");
4633+ var u = Variable.CreateUnique(expr, "u_secant");
4634+ foreach (var ofTheSecant in new[] { true, false })
4635+ {
4636+ // The tangent and its reciprocal as one base; for the cosecant, the cotangent.
4637+ var inT = expr.Replace(node => node switch
4638+ {
4639+ Tanf(var a) when a == argument => ofTheSecant ? t : 1 / t,
4640+ Cotanf(var a) when a == argument => ofTheSecant ? 1 / t : t,
4641+ _ => node,
4642+ });
4643+ var (rest, exponents) = GatheredOverTheBases(inT, new Entity[] { t });
4644+ var n = exponents[0];
4645+ if (rest.ContainsNode(t) || !n.IsInteger() || n.ToEInteger().IsEven || !n.ToEInteger().CanFitInInt32())
4646+ continue;
4647+ var inU = rest.Replace(node => node switch
4648+ {
4649+ Secantf(var a) when ofTheSecant && a == argument => u,
4650+ Cosf(var a) when ofTheSecant && a == argument => 1 / u,
4651+ Cosecantf(var a) when !ofTheSecant && a == argument => u,
4652+ Sinf(var a) when !ofTheSecant && a == argument => 1 / u,
4653+ _ => node,
4654+ });
4655+ if (inU.ContainsNode(x))
4656+ continue;
4657+ // dy = du/(u t) for the secant, -du/(u t) for the cosecant, and t^(n - 1) = (u^2 - 1)^((n - 1)/2).
4658+ var half = n.Subtract(ERational.One).Divide(ERational.FromInt32(2)).ToEInteger();
4659+ var integrand = (inU * MathS.Pow(MathS.Sqr(u) - 1, Number.Integer.Create(half)) / ((ofTheSecant ? rate : -rate) * u)).InnerSimplified;
4660+ if (Integration.ComputeAsAQuestionOfItsOwn(integrand, u, integrateByParts) is not { } inTermsOfU
4661+ || inTermsOfU.Nodes.Any(node => node == MathS.NaN))
4662+ return null;
4663+ return inTermsOfU.Substitute(u, ofTheSecant ? MathS.Sec(argument) : new Cosecantf(argument));
4664+ }
4665+ return null;
4666+ }
4667+
45984668 /// <summary>
45994669 /// <c>tan(y) tan(2y)</c> written <c>sec(2y) - 1</c>, and the integrand asked again in the
46004670 /// one argument <c>2y</c>.
0 commit comments