Skip to content

Commit 287c69a

Browse files
A quadratic sharing a root off the real line with a linear beside it is written over that root (#1750)
1/((a + i a tan(x)) (c + d tan(x))) is under the tangent substitution a rational function over (1 + i u)(c + d u)(1 + u^2), and 1 + u^2 is (1 + i u)(1 - i u): the written factors share a linear, while the splits read written factors as coprime and the divisors that take shared factors apart are taken over the rationals. With a symbol in the denominator, a quadratic that has a root off the real line in common with a linear beside it is written as its leading coefficient times the linears of its two roots, and the shared linear taken as one power. 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 874c5e7 commit 287c69a

3 files changed

Lines changed: 147 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,23 @@ left as it was, since the sum is real on both sides of 0 and `x^(j p)` is not. R
888888
| `"1/(x*sqrt(b*x^(2/3) + a*x))".ToEntity().Integrate("x")` | `integral(...)` | `K` times an antiderivative in `sqrt(b + a x^(1/3))` |
889889
| `"x/sqrt(1 + 1/(c*x)^2)".ToEntity().Integrate("x")` | `integral(...)` | `sgn(x) (x sqrt(x^2 + 1/c^2)/2 - ln(2 x + 2 sqrt(x^2 + 1/c^2))/(2 c^2))`, for any `c` but 0 |
890890

891+
### A quadratic sharing a root off the real line with a linear beside it is written over that root
892+
893+
**Answers where there were none.** `1/((a + i a tan(x)) (c + d tan(x)))`, Rubi's 4.3.2.1, is under the
894+
tangent substitution a rational function over `(1 + i u)(c + d u)(1 + u^2)`, and `1 + u^2` is
895+
`(1 + i u)(1 - i u)`: the written factors share a linear. The splits read written factors as coprime,
896+
and the divisors that take shared factors apart are taken over the rationals, which the imaginary unit
897+
is not; it was declined, and with a square of `c + d tan(x)` it ran past a minute. With a symbol in the
898+
denominator, a quadratic that has a root off the real line in common with a linear beside it is now
899+
written as its leading coefficient times the linears of its two roots, and the shared linear taken as
900+
one power ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
901+
902+
| Input | Was (2.5.0) | Now |
903+
|---|---|---|
904+
| `"1/((a + i*a*tan(x))*(c + d*tan(x)))".ToEntity().Integrate("x")` | `integral(...)` | a quotient by `tan(x) - i` and logarithms |
905+
| `"1/((a + i*a*tan(x))^2*(c + d*tan(x)))".ToEntity().Integrate("x")` | `integral(...)` | the same |
906+
| `"1/((a + i*a*tan(x))*(c + d*tan(x))^2)".ToEntity().Integrate("x")` | `integral(...)` | the same |
907+
891908
### A rational function of a sine over a symbolic quadratic in it is integrated over the two roots
892909

893910
**Improvement, not silent.** `sin(x)/(a + b sin(x) + c sin(x)^2)` and everything rational in

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,17 @@ is var (multiple, leftover)
701701
?? Integration.ComputeIndefiniteIntegral(above / below, x, integrateByParts)) is { } overWhatTheyShare)
702702
return overWhatTheyShare;
703703

704+
// And a linear with a root off the real line that a quadratic beside it shares, which
705+
// the divisors over the rationals above cannot see: `1 + i u` beside `1 + u^2`, which is
706+
// `(1 + i u)(1 - i u)`, what the tangent substitution makes of Rubi's 4.3.2.1
707+
// `1/((a + i a tan(x)) (c + d tan(x)))`. The quadratic is written over the linears of
708+
// its roots and the shared one taken as one power, coprime and squarefree for the
709+
// splits below.
710+
if (OverAComplexRootSharedWithAQuadratic(denominator, x) is { } overTheSharedRoot
711+
&& (SolveByPartialFractions(numerator / overTheSharedRoot, x, integrateByParts)
712+
?? Integration.ComputeIndefiniteIntegral(numerator / overTheSharedRoot, x, integrateByParts)) is { } overTheComplexRoot)
713+
return overTheComplexRoot;
714+
704715
// Written linear factors with symbols in their coefficients, two or more, one of
705716
// them to a power: decomposed over the written factors, the coefficients read
706717
// off derivatives at the roots and each a line. First, before the respellings
@@ -12909,6 +12920,72 @@ private static bool IsASumOfMonomials(Entity expr, Entity.Variable x)
1290912920
return changed ? product : null;
1291012921
}
1291112922

12923+
/// <summary>
12924+
/// <paramref name="denominator"/> with every quadratic factor that has a root off the real line
12925+
/// in common with a linear factor beside it written as its leading coefficient times the
12926+
/// linears of its two roots, each linear with such a root written as its slope times
12927+
/// <c>x - r</c>, and the powers of one linear gathered into one; <see langword="null"/>
12928+
/// where no quadratic shares such a root. <c>(1 + i x)(1 + x^2)</c> is
12929+
/// <c>i (x - i)^2 (x + i)</c>.
12930+
/// </summary>
12931+
private static Entity? OverAComplexRootSharedWithAQuadratic(Entity denominator, Entity.Variable x)
12932+
{
12933+
// With numbers only, the split over the rationals and the imaginary unit answers it as
12934+
// it is written.
12935+
if (!denominator.Vars.Any(symbol => symbol != x))
12936+
return null;
12937+
var written = new List<(Entity Base, EInteger Power)>();
12938+
Entity constant = Number.Integer.One;
12939+
foreach (var factor in Mulf.LinearChildren(denominator))
12940+
{
12941+
if (!factor.ContainsNode(x))
12942+
{
12943+
constant = constant * factor;
12944+
continue;
12945+
}
12946+
written.Add(factor is Powf(var @base, Number.Integer n) && n.EInteger.Sign > 0 ? (@base, n.EInteger) : (factor, EInteger.One));
12947+
}
12948+
// The roots of the linears that are not real, each with the linear's slope.
12949+
var roots = new Dictionary<Entity, (Number.Complex Root, Entity Slope)>();
12950+
foreach (var (@base, _) in written)
12951+
if (TreeAnalyzer.TryGetPolyLinear(@base, x, out var slope, out var offset) && !TreeAnalyzer.IsZero(slope)
12952+
&& Functions.PartialFractions.Bare((-offset / slope).Simplify()).Evaled is Number.Complex root && root is not Number.Real)
12953+
roots[@base] = (root, slope);
12954+
if (roots.Count == 0)
12955+
return null;
12956+
var gathered = new Dictionary<Entity, EInteger>();
12957+
void Add(Entity @base, EInteger power) => gathered[@base] = gathered.TryGetValue(@base, out var before) ? before.Add(power) : power;
12958+
var shared = false;
12959+
foreach (var (@base, power) in written)
12960+
{
12961+
if (roots.TryGetValue(@base, out var linear))
12962+
{
12963+
constant = constant * MathS.Pow(linear.Slope, Number.Integer.Create(power));
12964+
Add((x - linear.Root).InnerSimplified, power);
12965+
continue;
12966+
}
12967+
if (TreeAnalyzer.TryGetPolyQuadratic(@base, x, out var a, out var b, out var c) && !TreeAnalyzer.IsZero(a)
12968+
&& a.Evaled is Number.Complex && b.Evaled is Number.Complex && c.Evaled is Number.Complex
12969+
&& roots.Values.FirstOrDefault(candidate => (a * candidate.Root * candidate.Root + b * candidate.Root + c).Evaled is Number.Complex { IsZero: true }) is var (root, _)
12970+
&& root is not null)
12971+
{
12972+
shared = true;
12973+
var other = (-b / a - root).Evaled;
12974+
constant = constant * MathS.Pow(a, Number.Integer.Create(power));
12975+
Add((x - root).InnerSimplified, power);
12976+
Add((x - other).InnerSimplified, power);
12977+
continue;
12978+
}
12979+
Add(@base, power);
12980+
}
12981+
if (!shared)
12982+
return null;
12983+
Entity product = constant;
12984+
foreach (var pair in gathered)
12985+
product = product * (pair.Value.Equals(EInteger.One) ? pair.Key : MathS.Pow(pair.Key, Number.Integer.Create(pair.Value)));
12986+
return product;
12987+
}
12988+
1291212989
/// <summary>
1291312990
/// <paramref name="numerator"/> over <paramref name="denominator"/>, the denominator's
1291412991
/// written factors taken apart over their greatest common divisors -- with one another,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 linear with a root off the real line that a quadratic beside it shares, with symbols in
16+
/// the rest: <c>1/((1 + i u)(c + d u)(1 + u^2))</c>, where <c>1 + u^2</c> is
17+
/// <c>(1 + i u)(1 - i u)</c>, the tangent substitution's form of Rubi's 4.3.2.1
18+
/// <c>1/((a + i a tan(x)) (c + d tan(x)))</c>, declined or past a minute. The integrands are
19+
/// complex for a real <c>x</c>, and compared as complex numbers.
20+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class ComplexRootSharedWithAQuadraticIntegralTest
24+
{
25+
[Theory]
26+
[InlineData("1/((1 + i*x)*(c + d*x)*(1 + x^2))")]
27+
[InlineData("1/((a + i*a*tan(x))*(c + d*tan(x)))")]
28+
[InlineData("1/((a + i*a*tan(x))^2*(c + d*tan(x)))")]
29+
[InlineData("1/((a + i*a*tan(x))*(c + d*tan(x))^2)")]
30+
public void OverTheSharedRoot(string integrand)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
Assert.DoesNotContain("integral(", integral.Stringize());
34+
Assert.DoesNotContain("NaN", integral.Stringize());
35+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 1.1).Substitute("d", 0.6);
36+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
37+
var original = Pinned(integrand.ToEntity());
38+
var compared = 0;
39+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
40+
{
41+
var want = original.Substitute("x", at).EvalNumerical();
42+
if (want.IsNaN)
43+
continue;
44+
compared++;
45+
var got = derivative.Substitute("x", at).EvalNumerical();
46+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
47+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
48+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
49+
}
50+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)