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
17 changes: 17 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,23 @@ read them as nonzero. They are now decided over one bar, expanded, and at pinned
| `"e^(3*acoth(a*x))/(c-a*c*x)^3".Integrate("x")`, and over `(c - a c x)^4` | left unevaluated | an antiderivative in `sqrt((a x + 1)/(a x - 1))` |
| `"e^(2*acoth(a*x))*sqrt(c-a*c*x)/x".Integrate("x")`, and over `x^2` | left unevaluated | an antiderivative in `sqrt(c - a c x)`, by cases on the sign of `c` |

### A trigonometric function of an imaginary multiple of a logarithm is integrated in exponentials

**Answers where there were none.** `tan(a + i ln(x))` and `sin(a + ln(c x^2) sqrt(-1/4))` were
declined: the closed form for a power of the variable times a sine or cosine of a logarithm divides
by `(m + 1)^2 + B^2`, which an imaginary `B` can make zero, and Rubi's 4.7.5 is built on exactly
that. `e^(i (a + b ln(u)))` is `e^(i a)` times a real power of `u` when `b` is imaginary, so each
such function is a sum or quotient of powers of `u`, and is written so now when `b` is an imaginary
number; the zero is a power `1/x`, whose integral is a logarithm. A symbolic `b`,
`sqrt(-1/n^2)`, is left alone, since whether the zero is there turns on the sign of `n`
([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"tan(a + i*ln(x))".ToEntity().Integrate("x")` | `integral(...)` | a rational function of `x` and `e^(i a)`, with a logarithm |
| `"sin(a + ln(c*x^2)*sqrt(-1/4))".ToEntity().Integrate("x")` | `integral(...)` | powers of `x` and `c x^2` and a logarithm, through `e^(i a)` |
| `"1/cos(a - 2*i*ln(c*x))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | an arctangent and a logarithm of a root, through `e^(i a)` |

### `e^(n i arctan(a x))` to a power that is not whole is integrated

**Answers where there were none.** `e^(n i arctan(L))` is written algebraically, as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21977,6 +21977,95 @@ private static (Entity Factor, Entity Inside)? TryTakeACommonLinearFactorOfASum(
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
}

/// <summary>
/// A trigonometric function of <c>a + b ln(u)</c> with an imaginary <c>b</c>, written in
/// exponentials: <c>e^(i (a + b ln(u)))</c> is <c>e^(i a)</c> times the real power
/// <c>u^(i b)</c>, so the sine, cosine and the rest are sums and quotients of powers of
/// <c>u</c>, which the rules for those answer.
/// </summary>
/// <remarks>
/// <c>sin(a + ln(c x^2) sqrt(-1/4))</c> and <c>tan(a + i ln(x))</c> were declined: the closed
/// form for a power of the variable times a sine or cosine of a logarithm divides by
/// <c>(m + 1)^2 + B^2</c>, which an imaginary <c>B</c> makes zero, and Rubi's 4.7.5 has 62
/// problems built on exactly that, with <c>b = sqrt(-(m + 1)^2/n^2)</c>. In exponentials the
/// zero is a power of <c>x</c> that is <c>1/x</c>, and its integral a logarithm. Only for a
/// number: a real <c>b</c> is the closed form's, after which this is asked, and a symbolic
/// one, <c>sqrt(-1/n^2)</c>, makes the zero one that only a sign of <c>n</c> decides.
/// https://github.com/asc-community/AngouriMath/issues/718
/// </remarks>
internal static Entity? SolveByWritingATrigonometricFunctionOfAnImaginaryLogarithmInExponentials(Entity expr, Entity.Variable x, bool integrateByParts)
{
if (!expr.Nodes.Any(node => node is Logf && node.ContainsNode(x)))
return null;
var any = false;
var rewritten = expr.Replace(node =>
{
var (argument, kind) = node switch
{
Sinf(var of) => (of, 0),
Cosf(var of) => (of, 1),
Tanf(var of) => (of, 2),
Cotanf(var of) => (of, 3),
Secantf(var of) => (of, 4),
Cosecantf(var of) => (of, 5),
_ => ((Entity?)null, -1)
};
if (argument is null || !IsLinearInALogarithmWithAnImaginaryCoefficient(argument, x))
return node;
any = true;
var plus = MathS.Pow(MathS.e, MathS.i * argument);
var minus = MathS.Pow(MathS.e, -MathS.i * argument);
return kind switch
{
0 => (plus - minus) / (2 * MathS.i),
1 => (plus + minus) / 2,
2 => (plus - minus) / (MathS.i * (plus + minus)),
3 => MathS.i * (plus + minus) / (plus - minus),
4 => 2 / (plus + minus),
_ => 2 * MathS.i / (plus - minus),
};
});
if (!any)
return null;
// Beside its own derivative the logarithm is a substitution's: `tan(a + i ln(x))/x` is
// `tan(a + i u)` in `u = ln(x)`, which the integrator answers in a closed form, where the
// exponentials would answer it as a piecewise in `e^(i a)`.
if (expr.Nodes.FirstOrDefault(node => node is Logf(var @base, var of) && @base == MathS.e && of.ContainsNode(x)) is { } logarithm)
{
Entity beside = Number.Integer.One;
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
if (!factor.ContainsNode(logarithm))
beside = underneath ? beside / factor : beside * factor;
if (beside.ContainsNode(x) && AreProportionalAtSampledPoints(beside, logarithm.Differentiate(x), x))
return null;
}
return Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts);
}

/// <summary>
/// Whether <paramref name="argument"/> is <c>a + b ln(u)</c>, with <c>u</c> the only place the
/// variable is and <c>b</c> an imaginary number.
/// </summary>
private static bool IsLinearInALogarithmWithAnImaginaryCoefficient(Entity argument, Entity.Variable x)
{
var logarithms = argument.Nodes
.Where(node => node is Logf(var @base, var of) && @base == MathS.e && of.ContainsNode(x))
.Distinct().ToList();
if (logarithms.Count != 1)
return false;
var placeholder = Variable.CreateUnique(argument, "l_log");
var inPlaceholder = argument.Replace(node => node == logarithms[0] ? placeholder : node);
if (inPlaceholder.ContainsNode(x)
|| !TreeAnalyzer.TryGetPolyLinear(inPlaceholder, placeholder, out var coefficient, out _)
|| TreeAnalyzer.IsZero(coefficient))
return false;
// A number, and not a symbol's: with `b = sqrt(-1/n^2)` the power of the variable this
// leaves is `1/x` for every positive n, which nothing reading `n` symbolically can know,
// and the general power's formula comes back with a zero below its bar.
return coefficient.Vars.Count() == 0 && coefficient.Evaled is Number.Complex number && number is not Number.Real
&& System.Math.Abs((double)number.RealPart) < 1e-12 * System.Math.Abs((double)number.ImaginaryPart);
}

/// <summary>
/// A power of the variable times a sine or cosine of a logarithm, in closed form:
/// <c>int x^m sin(L) dx</c> is <c>x^(m + 1)((m + 1) sin(L) - B cos(L))/((m + 1)^2 + B^2)</c>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
// A power of the variable times a sine or cosine of a logarithm, where two rounds of
// parts close on the integrand: `int x^m sin(a + b ln(c x^n))` in closed form.
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesATrigonometricOfALogarithm(expr, x, integrateByParts)) is { }) return answer;
// The same with an imaginary coefficient on the logarithm, where the closed form divides
// by zero: in exponentials, powers of the variable.
if ((answer = IndefiniteIntegralSolver.SolveByWritingATrigonometricFunctionOfAnImaginaryLogarithmInExponentials(expr, x, integrateByParts)) is { }) return answer;
// A logarithm of a quotient that cancels with the functions in it as
// indeterminates, which is how an inverse hyperbolic function of a hyperbolic
// one arrives: atanh(tanh(u)) is 1/2 ln(e^(2u)) once its quotient is cancelled.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using System;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A trigonometric function of <c>a + b ln(u)</c> with an imaginary number for <c>b</c>, in
/// exponentials: <c>e^(i (a + b ln(u)))</c> is <c>e^(i a)</c> times a real power of
/// <c>u</c>. The closed form for a power of the variable times a sine or cosine of a logarithm
/// divides by zero on exactly these, Rubi's 4.7.5. The integrands are complex, and compared as
/// complex numbers.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
[Trait("Area", "Calculus")]
public sealed class TrigonometricOfAnImaginaryLogarithmIntegralTest
{
[Theory]
[InlineData("sin(a + ln(c*x^2)*sqrt(-1/4))")]
[InlineData("tan(a + i*ln(x))")]
[InlineData("cot(a + i*ln(x))/x^2")]
[InlineData("1/cos(a - 2*i*ln(c*x))^(3/2)")]
[InlineData("x^2*cos(a + i*ln(x))^2")]
public void InExponentials(string integrand) => DifferentiatesBack(integrand, integrand.ToEntity().Integrate("x"));

/// <summary>
/// Beside its own derivative the logarithm is left to the substitution:
/// <c>tan(a + i ln(x))/x</c> is <c>tan(a + i u)</c> in <c>u = ln(x)</c>, answered in a
/// closed form, where the exponentials would answer it as a piecewise in <c>e^(i a)</c>.
/// </summary>
[Theory]
[InlineData("tan(a + i*ln(x))/x")]
[InlineData("cot(a + i*ln(x))/x")]
public void BesideItsOwnDerivativeByTheSubstitution(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
Assert.DoesNotContain("piecewise", integral.Stringize());
DifferentiatesBack(integrand, integral);
}

private static void DifferentiatesBack(string integrand, Entity integral)
{
Assert.DoesNotContain("integral(", integral.Stringize());
Entity Pinned(Entity e) => e.Substitute("a", 0.4).Substitute("c", 1.3);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
foreach (var at in new[] { 0.3, 0.8, 1.5, 2.4 })
{
var want = original.Substitute("x", at).EvalNumerical();
var got = derivative.Substitute("x", at).EvalNumerical();
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
}
}
}
Loading