Skip to content

Commit ea2cb5e

Browse files
e^(i arctan(L)) beside a function of x is written as two powers of linears (#1821)
For a real L, e^(+-i arctan(L)) is (1 + i L)^(+-1/2) (1 - i L)^(-+1/2): powers of two linears, where (1 + i L)/sqrt(1 + L^2) is a root of a quadratic. 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 05855f9 commit ea2cb5e

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ integrals with `0` ([#1769](https://github.com/asc-community/AngouriMath/issues/
240240
| `"e^(-160)".ToEntity().InnerSimplified` | `0` | `e ^ (-160)` |
241241
| `"x^n*((1 - d^2)/x - x)^3*(1 + x^2 - d*x)/(x - d)/pi^2".ToEntity().Simplify()` | `0 provided not x - d = 0 and ...` | `x ^ n * ((1 - d ^ 2) / x - x) ^ 3 * (1 - d * x + x ^ 2) / (pi ^ 2 * (x - d))` |
242242

243+
### `e^(i arctan(L))` beside a function of `x` is written as two powers of linears
244+
245+
**Answers where there were none, and shorter ones.** `1/(e^(i arctan(a + b x)) x^2)` ran past thirty
246+
seconds: `e^(i arctan(L))` was written `(1 + i L)/sqrt(1 + L^2)`, a root of a quadratic beside the pole.
247+
It is `(1 + i L)^(1/2) (1 - i L)^(-1/2)` as well, for a real `L` -- the two principal powers' arguments are
248+
`arctan(L)/2` each and their moduli cancel -- powers of two linears, and beside a function of `x` it is
249+
written so. Of Rubi's 5.3.6, four integrals are answered that were not, and the 28 answers that change are
250+
a ninth of the length together ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
251+
252+
| Input | Was (2.5.0) | Now |
253+
|---|---|---|
254+
| `"1/(e^(i*atan(a + b*x))*x^2)".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 340 characters |
255+
| `"x^3/e^(i*atan(a + b*x))".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 373 characters |
256+
| `"x^3/e^(i*atan(a*x))".ToEntity().Integrate("x")` | `integral(...)`; 25,944 characters on the unreleased master | 218 characters |
257+
243258
### The floor and the ceiling of a rational are exact whatever its size
244259

245260
**Wrong answers fixed.** The floor and the ceiling of an exact rational went through a decimal at the

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8549,6 +8549,11 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer &&
85498549
internal static Entity? SolveByWritingAnExponentialOfAnInverseAlgebraically(Entity expr, Entity.Variable x, bool integrateByParts)
85508550
{
85518551
var rewrote = false;
8552+
// A power of a quadratic in x outside the exponentials, which `(1 + L^2)^(-n/2)` meets.
8553+
var quadraticElsewhere = expr.Nodes.Any(node => node is Powf(var q, _) && q.ContainsNode(x) && !q.Nodes.Any(inner => inner is Arctanf or Arcsinf or Arccosf)
8554+
&& TreeAnalyzer.TryGetPolyQuadratic(q, x, out var leading, out _, out _) && !TreeAnalyzer.IsZero(leading));
8555+
// The variable outside the exponentials.
8556+
var xElsewhere = expr.Replace(node => node is Powf(var e, var power) && e == MathS.e && power.ContainsNode(x) ? Number.Integer.One : node).ContainsNode(x);
85528557
var rewritten = expr.Replace(node =>
85538558
{
85548559
if (node is not Powf(var @base, var exponent) || @base != MathS.e || !exponent.ContainsNode(x))
@@ -8583,6 +8588,20 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer &&
85838588
// of different orders that nothing reads.
85848589
if (inverse is Arctanf)
85858590
{
8591+
// `(1 + i L)^(n/2) (1 - i L)^(-n/2)`: the two principal powers' arguments are
8592+
// `(n/2) arctan(L)` each and their moduli cancel, for a real L, so it is
8593+
// `e^(n i arctan(L))` exactly, powers of two linears, which the rules for a
8594+
// product of linear powers read. For n = 1 or -1 beside a function of x and no
8595+
// power of a quadratic in x for the other form to meet: `e^(i arctan(a + b x))/x^2`
8596+
// was `(1 + i L)/sqrt(1 + L^2)` over `x^2`, a root of a quadratic beside a pole, and
8597+
// ran past thirty seconds, and `x^3 e^(-i arctan(a x))` came out in 26 thousand
8598+
// characters where so it is 218. Alone the exponential is answered shorter as the
8599+
// root, and for a power not whole the quotient's power is.
8600+
if ((n == Number.Integer.One || n == Number.Integer.MinusOne) && !quadraticElsewhere && xElsewhere)
8601+
{
8602+
var half = Number.Rational.Create(n.ERational.Divide(2));
8603+
return MathS.Pow(1 + MathS.i * argument, half) * MathS.Pow(1 - MathS.i * argument, Number.Rational.Create(half.ERational.Negate()));
8604+
}
85868605
var halfPower = Number.Rational.Create(n.ERational.Negate().Divide(2));
85878606
if (n is not Number.Integer)
85888607
return MathS.Pow((1 + MathS.i * argument) / (1 - MathS.i * argument), Number.Rational.Create(n.ERational.Divide(2)));
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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>e^(+-i arctan(L))</c> beside a function of <c>x</c>, written as <c>(1 + i L)^(+-1/2) (1 - i L)^(-+1/2)</c>:
16+
/// the two principal powers' arguments are <c>arctan(L)/2</c> each and their moduli cancel, for a real
17+
/// <c>L</c>. Rubi's 5.3.6. The integrands are complex for a real <c>x</c> 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 AnExponentialOfAnArctangentBesideAPowerIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("1/(e^(i*atan(a + b*x))*x^2)")]
25+
[InlineData("x^3/e^(i*atan(a + b*x))")]
26+
[InlineData("x^3/e^(i*atan(a*x))")]
27+
[InlineData("e^(i*atan(a*x))*x^2")]
28+
public void AsTwoPowersOfLinears(string integrand)
29+
{
30+
var integral = integrand.ToEntity().Integrate("x");
31+
var text = integral.Stringize();
32+
Assert.DoesNotContain("integral(", text);
33+
Assert.True(text.Length < 5000, $"{text.Length} characters of answer for {integrand}");
34+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7);
35+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
36+
var original = Pinned(integrand.ToEntity());
37+
var compared = 0;
38+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
39+
{
40+
var want = original.Substitute("x", at).EvalNumerical();
41+
var got = derivative.Substitute("x", at).EvalNumerical();
42+
if (want.IsNaN)
43+
continue;
44+
compared++;
45+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
46+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
47+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
48+
}
49+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)