Skip to content

Commit 05855f9

Browse files
a + i a tan beside the tangent's differential is lowered over its conjugate (#1820)
Under u = tan(x), (a + i a u)(a - i a u) = a^2 (1 + u^2), so a power of the sum over 1 + u^2 is one power lower over the conjugate. 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 f8e9734 commit 05855f9

3 files changed

Lines changed: 106 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ the division's; with it on, the rounding is the setting's own and stays
177177
| `"(-60.5)!"` at 30 digits, downcasting off | `5.86118478907722232671451280188E-81` | `2.93059239453861116335725639905E-81` |
178178
| `"abs(75 + 316.22776601683796i)"`, downcasting off | `325` | `325.000000000000026076735749…` |
179179

180+
### `a + i a tan` beside the tangent's differential is lowered over its conjugate
181+
182+
**Answers where there were none.** `sqrt(a + i a tan(x))/(c + d tan(x))^(3/2)` ran past thirty seconds:
183+
under `u = tan(x)` it is `sqrt(a + i a u)/((c + d u)^(3/2) (1 + u^2))`, a search, where
184+
`(a + i a u)(a - i a u)` is `a^2 (1 + u^2)` and the sum's power is lowered by one over its conjugate, a root
185+
of a linear over a linear, which is answered in a second
186+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
187+
188+
| Input | Was (2.5.0) | Now |
189+
|---|---|---|
190+
| `"sqrt(a + i*a*tan(x))/(c + d*tan(x))^(3/2)".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 1,893 characters |
191+
| `"(a + i*a*tan(x))^(3/2)*(c + d*tan(x))^(5/2)".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 670 characters |
192+
| `"sqrt(a + i*a*tan(x))/sqrt(c + d*tan(x))".ToEntity().Integrate("x")` | `integral(...)` | 169 characters |
193+
| `"1/(sqrt(a + i*a*tan(x))*(c + d*tan(x))^(3/2))".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 2,217 characters |
194+
| `"1/((a + i*a*tan(x))^(3/2)*(c + d*tan(x))^(5/2))".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 3,333 characters |
195+
180196
### One linear twice is not two linear powers
181197

182198
**Answers that had no value.** `(a c + b c x)^(-3 - 2 p) (f + g x) (a^2 + 2 a b x + b^2 x^2)^p` was answered

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10360,8 +10360,14 @@ static bool IsTwice(Entity argument, Entity.Variable x)
1036010360
// none: `1/(u^2*(1 + u^2))` is integrated and `(1/u)^2/(1 + u^2)`, which is the same
1036110361
// expression, is not. The half-angle and exponential substitutions comb their
1036210362
// integrands for the same reason.
10363-
var integrand = Functions.SingleQuotient
10364-
.Combine(inU / (1 + MathS.Sqr(uSub))).Simplify();
10363+
// A power of A + i A u beside the differential: (A + i A u)(A - i A u) is A^2 (1 + u^2),
10364+
// so 1/(1 + u^2) is A^2/((A + i A u)(A - i A u)) and the sum's power is lowered by one,
10365+
// a root of a linear over a linear. `sqrt(a + i a tan(x))/(c + d tan(x))^(3/2)` was a
10366+
// search past thirty seconds as a quotient by 1 + u^2, and in the sum's conjugate it is
10367+
// answered in a second.
10368+
var integrand = ByTheSumsConjugate(inU, uSub) is { } overTheConjugate
10369+
? overTheConjugate
10370+
: Functions.SingleQuotient.Combine(inU / (1 + MathS.Sqr(uSub))).Simplify();
1036510371
if (integrand is Providedf(var withoutCondition, _))
1036610372
integrand = withoutCondition;
1036710373
// Asked as the same question: the rewrite renames the variable and adds no step of
@@ -10373,6 +10379,34 @@ static bool IsTwice(Entity argument, Entity.Variable x)
1037310379
? result.Substitute(uSub, tangent)
1037410380
: null;
1037510381
}
10382+
10383+
/// <summary>
10384+
/// <c>inU/(1 + u^2)</c> written with the conjugate of a factor <c>A +- i A u</c> of
10385+
/// <paramref name="inU"/>: <c>inU/(A +- i A u) A^2/(A -+ i A u)</c>. Null where no factor is
10386+
/// such a sum.
10387+
/// </summary>
10388+
private static Entity? ByTheSumsConjugate(Entity inU, Entity.Variable u)
10389+
{
10390+
// A reciprocal of a product read as the quotient it is: a constant taken out of the
10391+
// sum's root leaves `(sqrt(1 + i u) (c + d u)^(3/2))^(-1)`, whose factors are below the bar.
10392+
if (inU is Powf(var reciprocal, Number.Integer { EInteger: var minusOne }) && minusOne.Equals(EInteger.FromInt32(-1)))
10393+
inU = 1 / reciprocal;
10394+
foreach (var (factor, _) in FactorsOfTheIntegrand(inU))
10395+
{
10396+
// A root of the sum, not a whole power: a polynomial in it beside the cosine is the
10397+
// rules' for the sine and the cosine, which answer `cos(x)^6 (a + i a tan(x))` sooner.
10398+
if (factor is not Powf(var sum, Number.Rational { ERational.Denominator: var denominator }) || denominator.Equals(EInteger.One))
10399+
continue;
10400+
if (sum is not Sumf and not Minusf || !TreeAnalyzer.TryGetPolyLinear(sum, u, out var slope, out var intercept)
10401+
|| TreeAnalyzer.IsZero(intercept) || TreeAnalyzer.IsZero(slope))
10402+
continue;
10403+
if (!TreeAnalyzer.IsZero((slope - MathS.i * intercept).Simplify()) && !TreeAnalyzer.IsZero((slope + MathS.i * intercept).Simplify()))
10404+
continue;
10405+
var conjugate = intercept - slope * u;
10406+
return (inU / sum * MathS.Sqr(intercept) / conjugate).InnerSimplified;
10407+
}
10408+
return null;
10409+
}
1037610410
/// <summary>
1037710411
/// <c>(prod f_i^(k_i))^(p/q)</c>, <c>q</c> odd, as <c>prod f_i^(k_i p/q)</c> where every
1037810412
/// <c>f_i</c> is a trigonometric function of <paramref name="x"/> itself or free of it,
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 power of <c>a + i a tan(x)</c> beside a root of <c>c + d tan(x)</c>. Under <c>u = tan(x)</c>,
16+
/// <c>dx = du/(1 + u^2)</c> and <c>(a + i a u)(a - i a u) = a^2 (1 + u^2)</c>, so the sum's power is
17+
/// lowered by one over its conjugate: a root of a linear over a linear. Rubi's 4.3.2.1. The
18+
/// integrands are complex for a real <c>x</c> and are compared as complex numbers.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ImaginaryTangentSumBesideARootOfALinearInTheTangentIntegralTest
23+
{
24+
[Theory]
25+
[InlineData("sqrt(a + i*a*tan(x))/(c + d*tan(x))^(3/2)")]
26+
[InlineData("(a + i*a*tan(x))^(3/2)*(c + d*tan(x))^(5/2)")]
27+
[InlineData("sqrt(a + i*a*tan(x))/sqrt(c + d*tan(x))")]
28+
[InlineData("1/(sqrt(a + i*a*tan(x))*(c + d*tan(x))^(3/2))")]
29+
[InlineData("1/((a + i*a*tan(x))^(3/2)*(c + d*tan(x))^(5/2))")]
30+
public void OverTheSumsConjugate(string integrand)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
var text = integral.Stringize();
34+
Assert.DoesNotContain("integral(", text);
35+
Assert.True(text.Length < 5000, $"{text.Length} characters of answer for {integrand}");
36+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 0.7).Substitute("d", 1.1);
37+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
38+
var original = Pinned(integrand.ToEntity());
39+
var compared = 0;
40+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
41+
{
42+
var want = original.Substitute("x", at).EvalNumerical();
43+
var got = derivative.Substitute("x", at).EvalNumerical();
44+
if (want.IsNaN)
45+
continue;
46+
compared++;
47+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
48+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
49+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
50+
}
51+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)