Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,27 @@ rule answers, where the imaginary unit in the coefficient is read by nothing els
| `"x/(2+2*i*tan(x))".Integrate("x")` | left unevaluated | the antiderivative |
| `"(c+d*x)/(a+i*a*tan(pe+f*x))".Integrate("x")` | left unevaluated | the antiderivative |

### A tangent above an imaginary tangent below is written in sines and cosines, and those as exponentials

**Answers where there were none.** `tan(c + d x)/(a + i a tan(c + d x))` ran past the corpus's budget
and `1/(a + i a tan(c + d x))` was declined. 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`. The
tangent or cotangent above is written in sines and cosines now, what the identity puts below
cancels against it, and the sines and cosines of `z` that are left are written as the exponentials
they are, so that 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. Rubi's 4.3.2.1 and
4.4.2.1 ([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"tan(c+d*x)/(a+i*a*tan(c+d*x))".Integrate("x")` | `integral(...)` | `x` and `e^(-2 i (c + d x))`, over `a` |
| `"1/(a+i*a*tan(c+d*x))".Integrate("x")` | `integral(...)` | the same |
| `"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))` |
| `"cot(c+d*x)/(a+i*a*cot(c+d*x))".Integrate("x")` | `integral(...)` | `x` and `e^(2 i (c + d x))` |
| `"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` |

### A symbolic constant factor no longer stops the rounds of parts

`F^(c (a + b x)) sin(d + pe x)^3` was left as written. The exponent's constant part becomes a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22407,6 +22407,7 @@ static bool IsAWholeNumberOfSteps(ERational difference)
var (above, below) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr));
if (!below.ContainsNode(x))
return null;
var arguments = new List<Entity>();
var rewritten = below.Replace(node =>
{
if (node is not Sumf and not Minusf || !node.ContainsNode(x))
Expand Down Expand Up @@ -22456,12 +22457,53 @@ static bool IsAWholeNumberOfSteps(ERational difference)
if (!plus && ratio.Evaled != (-MathS.i).Evaled)
return node;
var exponential = MathS.Pow(MathS.e, ((plus == isTangent ? MathS.i : -MathS.i) * argument).InnerSimplified);
arguments.Add(argument);
// A + i A tan(z) is A e^(iz)/cos(z); A + i A cot(z) is i A e^(-iz)/sin(z).
return isTangent
? constant * exponential / MathS.Cos(argument)
: (plus ? MathS.i : -MathS.i) * constant * exponential / MathS.Sin(argument);
});
return rewritten == below ? null : Integration.ComputeAsTheSameQuestion((above / rewritten).InnerSimplified, x, integrateByParts);
if (rewritten == below)
return null;
// A tangent or a cotangent of the same argument above the bar in sines and cosines, so that
// the cosine or sine the identity puts below cancels it: `tan(z)/(A + i A tan(z))` is
// `sin(z) e^(-i z)/A`, an exponential times a sine, where `tan(z) cos(z) e^(-i z)/A` was
// a search past the budget with `z = c + d x`.
var inSinesAndCosines = above.Replace(node => node switch
{
Tanf(var inner) when arguments.Contains(inner) => MathS.Sin(inner) / MathS.Cos(inner),
Cotanf(var inner) when arguments.Contains(inner) => MathS.Cos(inner) / MathS.Sin(inner),
_ => node,
});
var (numerator, denominator) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(inSinesAndCosines / rewritten));
var (top, bottom) = CancelledWithFunctionsAsIndeterminates(numerator, denominator, x, expr);
// Only where what is left is made of those sines and cosines, exponentials of linears and
// polynomials in x: a secant or a root beside them, `sec(z)^8/(A + i A tan(z))^4`, is read
// through the tangent as written, and rewritten it was a search of minutes.
bool Plain(Entity node) => node switch
{
_ when !node.ContainsNode(x) => true,
Entity.Variable => true,
Sinf(var sineOf) => arguments.Contains(sineOf),
Cosf(var cosineOf) => arguments.Contains(cosineOf),
Powf(var @base, Number.Integer) => Plain(@base),
Powf(var @base, var exponent) => @base == MathS.e && TreeAnalyzer.TryGetPolyLinear(exponent, x, out _, out _),
Mulf or Divf or Sumf or Minusf => node.DirectChildren.All(Plain),
_ => false,
};
if (!Plain(top) || !Plain(bottom))
return Integration.ComputeAsTheSameQuestion((above / rewritten).InnerSimplified, x, integrateByParts);
// And what sines and cosines of it are left, as the exponentials they are, so that the whole is
// 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))`.
var inExponentials = (top / bottom).Replace(node => node switch
{
Sinf(var inner) when arguments.Contains(inner)
=> (MathS.Pow(MathS.e, MathS.i * inner) - MathS.Pow(MathS.e, -MathS.i * inner)) / (2 * MathS.i),
Cosf(var inner) when arguments.Contains(inner)
=> (MathS.Pow(MathS.e, MathS.i * inner) + MathS.Pow(MathS.e, -MathS.i * inner)) / 2,
_ => node,
});
return Integration.ComputeAsTheSameQuestion(inExponentials.InnerSimplified, x, integrateByParts);
}

/// <summary>
Expand Down
36 changes: 36 additions & 0 deletions Sources/Tests/UnitTests/Calculus/PolynomialExponentialTrigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,42 @@ public void TheResonanceIsSeenSymbolically(string integrand, string? symbol)
[InlineData("(1 + 2*x)/(3 + 3*i*tan(1/2 + x))^2")]
public void AnImaginaryTangentBelowTheBarIsAnExponential(string integrand) => DifferentiatesBack(integrand);

/// <summary>
/// A tangent of the same argument above the bar is written in sines and cosines, so that the
/// cosine the identity puts below cancels it, and what sines and cosines of it are left as
/// exponentials: <c>tan(z)/(A + i A tan(z))</c> is <c>sin(z) e^(-i z)/A</c>, and
/// <c>tan(z) cos(z) e^(-i z)/A</c> was a search past the budget with <c>z = c + d x</c>.
/// The symbols pinned only after integrating.
/// </summary>
[Theory]
[InlineData("tan(c + d*x)/(a + i*a*tan(c + d*x))")]
[InlineData("tan(c + d*x)^2/(a + i*a*tan(c + d*x))")]
[InlineData("tan(c + d*x)^3/(a + i*a*tan(c + d*x))^4")]
[InlineData("cot(c + d*x)/(a + i*a*cot(c + d*x))")]
[InlineData("1/(a + i*a*tan(c + d*x))")]
public void AnImaginaryTangentOfALinearWithATangentAboveTheBar(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
Assert.DoesNotContain("integral(", integral.Stringize());
Assert.DoesNotContain("NaN", integral.Stringize());
Entity Pin(Entity e) => e.Substitute("a", 0.9).Substitute("c", 0.3).Substitute("d", 1.1);
var derivative = Pin(integral.Substitute("C", 0)).Differentiate("x");
var original = Pin(integrand.ToEntity());
var compared = 0;
foreach (var at in Points)
{
var got = derivative.Substitute("x", at).EvalNumerical();
var want = original.Substitute("x", at).EvalNumerical();
if (got.IsNaN || want.IsNaN)
continue;
compared++;
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
Assert.True(difference / scale < 1e-9, $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
Assert.True(compared >= 4, $"only {compared} points could be compared for {integrand}");
}

/// <summary>
/// And its sibling, <c>A cos(y) + i A sin(y)</c>, which is <c>A e^(i y)</c>: a sum of a
/// cosine and a sine with no real rotation, since <c>A^2 + (i A)^2</c> is zero, and beside
Expand Down
Loading