Skip to content

Commit d8dff2a

Browse files
a + i a tan of a shifted linear below the bar is integrated in the linear (#1822)
Where every trigonometric function is of one linear other than x, the rule that writes a + i a tan(z) as an exponential integrates in u = g + f x first. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ea2cb5e commit d8dff2a

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ after it
208208
|---|---|---|
209209
| `"(a*c + b*c*x)^(-3-2*p)*(f + g*x)*(a^2 + 2*a*b*x + b^2*x^2)^p".ToEntity().Integrate("x")` | `integral(...)`; an answer with no value on the unreleased master | the antiderivative |
210210

211+
### `a + i a tan` of a shifted linear below the bar is integrated in the linear
212+
213+
**Answers where there were none.** `sqrt(a + i a tan(g + f x)) (A + B tan(g + f x))/sqrt(c - i c tan(g + f x))`
214+
ran past thirty seconds, where with `x` for the argument it is answered in one: the rule that writes
215+
`a + i a tan(z)` as an exponential expanded the exponential of `i (g + f x)` and its phase into a search.
216+
Where every trigonometric function in the integrand is of one linear other than `x`, it integrates in
217+
`u = g + f x` first ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
218+
219+
| Input | Was (2.5.0) | Now |
220+
|---|---|---|
221+
| `"sqrt(a + i*a*tan(g + f*x))*(A + B*tan(g + f*x))/sqrt(c - i*c*tan(g + f*x))".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 448 characters |
222+
| `"(A + B*tan(g + f*x))/(sqrt(a + i*a*tan(g + f*x))*(c - i*c*tan(g + f*x))^(3/2))".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 597 characters |
223+
211224
### A value substituted under a binder is not captured by the name it binds
212225

213226
**Wrong answers fixed.** An integral, a sum, a product, a derivative, a limit, a set builder and the

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26805,6 +26805,49 @@ 2 when NotWhole(sums[0].Base) != NotWhole(sums[1].Base) => NotWhole(sums[0].Base
2680526805
/// handed on is the integrand in another spelling.
2680626806
/// https://github.com/asc-community/AngouriMath/issues/718
2680726807
/// </remarks>
26808+
/// <summary>
26809+
/// <paramref name="expr"/> integrated in <c>u = g + f x</c> where x stands only in trigonometric
26810+
/// functions of that one linear, other than x itself, and a root of something in x stands: <c>dx = du/f</c>. Null
26811+
/// otherwise.
26812+
/// </summary>
26813+
private static Entity? InItsOneShiftedLinear(Entity expr, Entity.Variable x, bool integrateByParts)
26814+
{
26815+
// Beside a root only: whole powers, `(a + i a tan(z))^3 (A + B tan(z))/(c - i c tan(z))^3`, the
26816+
// exponential's spelling answers sooner of the linear than of x.
26817+
if (!expr.Nodes.Any(node => node is Powf(var @base, Number.Rational power) && power is not Number.Integer && @base.ContainsNode(x)))
26818+
return null;
26819+
Entity? linear = null;
26820+
foreach (var node in expr.Nodes)
26821+
{
26822+
if (node is not (Tanf or Cotanf or Sinf or Cosf or Secantf or Cosecantf) || !node.ContainsNode(x))
26823+
continue;
26824+
var argument = node.DirectChildren.First();
26825+
if (linear is null)
26826+
linear = argument;
26827+
else if (linear != argument)
26828+
return null;
26829+
}
26830+
if (linear is null || !TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out var offset)
26831+
|| slope.ContainsNode(x) || offset.ContainsNode(x) || TreeAnalyzer.IsZero(slope) || linear == x)
26832+
return null;
26833+
var u = Variable.CreateUnique(expr, "u_shifted");
26834+
var inU = expr.Replace(node => node switch
26835+
{
26836+
Tanf(var a) when a == linear => MathS.Tan(u),
26837+
Cotanf(var a) when a == linear => MathS.Cotan(u),
26838+
Sinf(var a) when a == linear => MathS.Sin(u),
26839+
Cosf(var a) when a == linear => MathS.Cos(u),
26840+
Secantf(var a) when a == linear => MathS.Sec(u),
26841+
Cosecantf(var a) when a == linear => new Cosecantf(u),
26842+
_ => node,
26843+
});
26844+
if (inU.ContainsNode(x)
26845+
|| Integration.ComputeAsAQuestionOfItsOwn((inU / slope).InnerSimplified, u, integrateByParts) is not { } answer
26846+
|| answer.Nodes.Any(node => node == MathS.NaN))
26847+
return null;
26848+
return answer.Substitute(u, linear);
26849+
}
26850+
2680826851
internal static Entity? SolveByWritingAnImaginaryTangentAsAnExponential(Entity expr, Entity.Variable x, bool integrateByParts)
2680926852
{
2681026853
// Below the bar only: `(A + i A tan(z))^3` above it is a polynomial in the tangent,
@@ -26872,6 +26915,12 @@ Entity AsAnExponential(Entity node)
2687226915
var rewritten = below.Replace(AsAnExponential);
2687326916
if (rewritten == below)
2687426917
return null;
26918+
// One linear other than x for every argument, `g + f x`, is integrated in it: the rewriting
26919+
// below expands an exponential of `i (g + f x)` and its phase into a search that ran past
26920+
// thirty seconds for `sqrt(a + i a tan(g + f x)) (A + B tan(g + f x))/sqrt(c - i c tan(g + f x))`,
26921+
// which in `u = g + f x` is answered in a second.
26922+
if (InItsOneShiftedLinear(expr, x, integrateByParts) is { } inTheLinear)
26923+
return inTheLinear;
2687526924
// A root of the tangent or the cotangent of that argument, or of a constant times one, is
2687626925
// read as written by the substitution `t = tan(z)`, where it is a root of `t`, and by
2687726926
// nothing in the exponential's spelling: `sqrt(tan(c + d x))/(a + i a tan(c + d x))`
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
/// <c>a + i a tan(g + f x)</c> below the bar, beside other functions of the same shifted linear,
16+
/// integrated in <c>u = g + f x</c>. Rubi's 4.3.3.1. The integrands are complex for a real <c>x</c>
17+
/// and are compared as complex numbers.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class AnImaginaryTangentSumOfAShiftedLinearIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("sqrt(a + i*a*tan(g + f*x))*(A + B*tan(g + f*x))/sqrt(c - i*c*tan(g + f*x))")]
25+
[InlineData("(A + B*tan(g + f*x))/(sqrt(a + i*a*tan(g + f*x))*(c - i*c*tan(g + f*x))^(3/2))")]
26+
public void InTheLinear(string integrand)
27+
{
28+
var integral = integrand.ToEntity().Integrate("x");
29+
var text = integral.Stringize();
30+
Assert.DoesNotContain("integral(", text);
31+
Assert.True(text.Length < 5000, $"{text.Length} characters of answer for {integrand}");
32+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 0.7).Substitute("g", 0.4).Substitute("f", 1.1).Substitute("A", 0.9).Substitute("B", 1.7);
33+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
34+
var original = Pinned(integrand.ToEntity());
35+
var compared = 0;
36+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
37+
{
38+
var want = original.Substitute("x", at).EvalNumerical();
39+
var got = derivative.Substitute("x", at).EvalNumerical();
40+
if (want.IsNaN)
41+
continue;
42+
compared++;
43+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
44+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
45+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
46+
}
47+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)