Skip to content

Commit 2340e8a

Browse files
A tangent above an imaginary tangent below is written in sines and cosines, and those as exponentials (#1711)
With A + i A tan(z) below the bar written as A e^(i z)/cos(z), a tangent of z above it stayed one, so tan(z) cos(z) was handed on as written, and with z = c + d x the phase was expanded into sin(c) and cos(c) beside d x: tan(c + d x)/(a + i a tan(c + d x)) ran past the budget. The tangent or cotangent above is written in sines and cosines, what the identity puts below cancels against it, and the sines and cosines of z left are written as exponentials, so the whole is a rational function of e^(i z). Only where nothing of x stands beside them but exponentials of linears and polynomials in x: sec(z)^8/(a + i a tan(z))^4 and sqrt(tan(z))/(a + i a tan(z))^(5/2) are read through the tangent as before. 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 599dcb7 commit 2340e8a

3 files changed

Lines changed: 100 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,6 +2388,27 @@ rule answers, where the imaginary unit in the coefficient is read by nothing els
23882388
| `"x/(2+2*i*tan(x))".Integrate("x")` | left unevaluated | the antiderivative |
23892389
| `"(c+d*x)/(a+i*a*tan(pe+f*x))".Integrate("x")` | left unevaluated | the antiderivative |
23902390

2391+
### A tangent above an imaginary tangent below is written in sines and cosines, and those as exponentials
2392+
2393+
**Answers where there were none.** `tan(c + d x)/(a + i a tan(c + d x))` ran past the corpus's budget
2394+
and `1/(a + i a tan(c + d x))` was declined. With `A + i A tan(z)` below the bar written as
2395+
`A e^(i z)/cos(z)`, a tangent of `z` above it stayed one, so `tan(z) cos(z)` was handed on as
2396+
written, and with `z = c + d x` the phase was expanded into `sin(c)` and `cos(c)` beside `d x`. The
2397+
tangent or cotangent above is written in sines and cosines now, what the identity puts below
2398+
cancels against it, and the sines and cosines of `z` that are left are written as the exponentials
2399+
they are, so that the whole is a rational function of `e^(i z)`. Only where nothing of `x` stands
2400+
beside them but exponentials of linears and polynomials in `x`: `sec(z)^8/(a + i a tan(z))^4` and
2401+
`sqrt(tan(z))/(a + i a tan(z))^(5/2)` are read through the tangent as before. Rubi's 4.3.2.1 and
2402+
4.4.2.1 ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
2403+
2404+
| Input | Was (2.5.0) | Now |
2405+
|---|---|---|
2406+
| `"tan(c+d*x)/(a+i*a*tan(c+d*x))".Integrate("x")` | `integral(...)` | `x` and `e^(-2 i (c + d x))`, over `a` |
2407+
| `"1/(a+i*a*tan(c+d*x))".Integrate("x")` | `integral(...)` | the same |
2408+
| `"tan(c+d*x)^3/(a+i*a*tan(c+d*x))^4".Integrate("x")` | `integral(...)` | `x` and powers of `e^(-2 i (c + d x))` |
2409+
| `"cot(c+d*x)/(a+i*a*cot(c+d*x))".Integrate("x")` | `integral(...)` | `x` and `e^(2 i (c + d x))` |
2410+
| `"tan(c+d*x)^2/(a+i*a*tan(c+d*x))".Integrate("x")` | `integral(...)` | a power of `e^(-i (c + d x))` and logarithms of `e^(+/-2 i (c + d x)) + 1` |
2411+
23912412
### A symbolic constant factor no longer stops the rounds of parts
23922413

23932414
`F^(c (a + b x)) sin(d + pe x)^3` was left as written. The exponent's constant part becomes a

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22407,6 +22407,7 @@ static bool IsAWholeNumberOfSteps(ERational difference)
2240722407
var (above, below) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr));
2240822408
if (!below.ContainsNode(x))
2240922409
return null;
22410+
var arguments = new List<Entity>();
2241022411
var rewritten = below.Replace(node =>
2241122412
{
2241222413
if (node is not Sumf and not Minusf || !node.ContainsNode(x))
@@ -22456,12 +22457,53 @@ static bool IsAWholeNumberOfSteps(ERational difference)
2245622457
if (!plus && ratio.Evaled != (-MathS.i).Evaled)
2245722458
return node;
2245822459
var exponential = MathS.Pow(MathS.e, ((plus == isTangent ? MathS.i : -MathS.i) * argument).InnerSimplified);
22460+
arguments.Add(argument);
2245922461
// A + i A tan(z) is A e^(iz)/cos(z); A + i A cot(z) is i A e^(-iz)/sin(z).
2246022462
return isTangent
2246122463
? constant * exponential / MathS.Cos(argument)
2246222464
: (plus ? MathS.i : -MathS.i) * constant * exponential / MathS.Sin(argument);
2246322465
});
22464-
return rewritten == below ? null : Integration.ComputeAsTheSameQuestion((above / rewritten).InnerSimplified, x, integrateByParts);
22466+
if (rewritten == below)
22467+
return null;
22468+
// A tangent or a cotangent of the same argument above the bar in sines and cosines, so that
22469+
// the cosine or sine the identity puts below cancels it: `tan(z)/(A + i A tan(z))` is
22470+
// `sin(z) e^(-i z)/A`, an exponential times a sine, where `tan(z) cos(z) e^(-i z)/A` was
22471+
// a search past the budget with `z = c + d x`.
22472+
var inSinesAndCosines = above.Replace(node => node switch
22473+
{
22474+
Tanf(var inner) when arguments.Contains(inner) => MathS.Sin(inner) / MathS.Cos(inner),
22475+
Cotanf(var inner) when arguments.Contains(inner) => MathS.Cos(inner) / MathS.Sin(inner),
22476+
_ => node,
22477+
});
22478+
var (numerator, denominator) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(inSinesAndCosines / rewritten));
22479+
var (top, bottom) = CancelledWithFunctionsAsIndeterminates(numerator, denominator, x, expr);
22480+
// Only where what is left is made of those sines and cosines, exponentials of linears and
22481+
// polynomials in x: a secant or a root beside them, `sec(z)^8/(A + i A tan(z))^4`, is read
22482+
// through the tangent as written, and rewritten it was a search of minutes.
22483+
bool Plain(Entity node) => node switch
22484+
{
22485+
_ when !node.ContainsNode(x) => true,
22486+
Entity.Variable => true,
22487+
Sinf(var sineOf) => arguments.Contains(sineOf),
22488+
Cosf(var cosineOf) => arguments.Contains(cosineOf),
22489+
Powf(var @base, Number.Integer) => Plain(@base),
22490+
Powf(var @base, var exponent) => @base == MathS.e && TreeAnalyzer.TryGetPolyLinear(exponent, x, out _, out _),
22491+
Mulf or Divf or Sumf or Minusf => node.DirectChildren.All(Plain),
22492+
_ => false,
22493+
};
22494+
if (!Plain(top) || !Plain(bottom))
22495+
return Integration.ComputeAsTheSameQuestion((above / rewritten).InnerSimplified, x, integrateByParts);
22496+
// And what sines and cosines of it are left, as the exponentials they are, so that the whole is
22497+
// a rational function of `e^(i z)`: `tan(z)^2/(A + i A tan(z))` leaves `sin(z)^2/(A cos(z) e^(i z))`.
22498+
var inExponentials = (top / bottom).Replace(node => node switch
22499+
{
22500+
Sinf(var inner) when arguments.Contains(inner)
22501+
=> (MathS.Pow(MathS.e, MathS.i * inner) - MathS.Pow(MathS.e, -MathS.i * inner)) / (2 * MathS.i),
22502+
Cosf(var inner) when arguments.Contains(inner)
22503+
=> (MathS.Pow(MathS.e, MathS.i * inner) + MathS.Pow(MathS.e, -MathS.i * inner)) / 2,
22504+
_ => node,
22505+
});
22506+
return Integration.ComputeAsTheSameQuestion(inExponentials.InnerSimplified, x, integrateByParts);
2246522507
}
2246622508

2246722509
/// <summary>

‎Sources/Tests/UnitTests/Calculus/PolynomialExponentialTrigTest.cs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,42 @@ public void TheResonanceIsSeenSymbolically(string integrand, string? symbol)
263263
[InlineData("(1 + 2*x)/(3 + 3*i*tan(1/2 + x))^2")]
264264
public void AnImaginaryTangentBelowTheBarIsAnExponential(string integrand) => DifferentiatesBack(integrand);
265265

266+
/// <summary>
267+
/// A tangent of the same argument above the bar is written in sines and cosines, so that the
268+
/// cosine the identity puts below cancels it, and what sines and cosines of it are left as
269+
/// exponentials: <c>tan(z)/(A + i A tan(z))</c> is <c>sin(z) e^(-i z)/A</c>, and
270+
/// <c>tan(z) cos(z) e^(-i z)/A</c> was a search past the budget with <c>z = c + d x</c>.
271+
/// The symbols pinned only after integrating.
272+
/// </summary>
273+
[Theory]
274+
[InlineData("tan(c + d*x)/(a + i*a*tan(c + d*x))")]
275+
[InlineData("tan(c + d*x)^2/(a + i*a*tan(c + d*x))")]
276+
[InlineData("tan(c + d*x)^3/(a + i*a*tan(c + d*x))^4")]
277+
[InlineData("cot(c + d*x)/(a + i*a*cot(c + d*x))")]
278+
[InlineData("1/(a + i*a*tan(c + d*x))")]
279+
public void AnImaginaryTangentOfALinearWithATangentAboveTheBar(string integrand)
280+
{
281+
var integral = integrand.ToEntity().Integrate("x");
282+
Assert.DoesNotContain("integral(", integral.Stringize());
283+
Assert.DoesNotContain("NaN", integral.Stringize());
284+
Entity Pin(Entity e) => e.Substitute("a", 0.9).Substitute("c", 0.3).Substitute("d", 1.1);
285+
var derivative = Pin(integral.Substitute("C", 0)).Differentiate("x");
286+
var original = Pin(integrand.ToEntity());
287+
var compared = 0;
288+
foreach (var at in Points)
289+
{
290+
var got = derivative.Substitute("x", at).EvalNumerical();
291+
var want = original.Substitute("x", at).EvalNumerical();
292+
if (got.IsNaN || want.IsNaN)
293+
continue;
294+
compared++;
295+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
296+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
297+
Assert.True(difference / scale < 1e-9, $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
298+
}
299+
Assert.True(compared >= 4, $"only {compared} points could be compared for {integrand}");
300+
}
301+
266302
/// <summary>
267303
/// And its sibling, <c>A cos(y) + i A sin(y)</c>, which is <c>A e^(i y)</c>: a sum of a
268304
/// cosine and a sine with no real rotation, since <c>A^2 + (i A)^2</c> is zero, and beside

0 commit comments

Comments
 (0)