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
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ it was ([#2611](https://github.com/asc-community/AngouriMath/issues/2611)).
| `integral(1/x, x, -2, -1)` | `ln(-1) - ln(-2)` | `-ln(2)` |
| `integral(1/(x^2-1), x, -1/2, 1/2)` | `(ln(-1/3) - ln(-3)) / 2` | `ln(1/3)` |

### ln(x) over a rational function symmetric under x -> a^2/x is integrated over [0, +oo)

**An answer where there was none.** `ln(x)/(1 + x^2)` has no elementary antiderivative, and its integral over
`[0, +oo)` was left unevaluated. It is 0, because `x -> 1/x` maps it onto its own negative. In general, for rational `R`
with `R(a^2/x) a^2/x^2 = R(x)`, the integral of `ln(x) R(x)` is `ln(a)` times the integral of `R`. The rule applies
only where the integral converges: `R` finite at 0, no pole on the half-line, and the denominator of degree at least two
above the numerator. `ln(x)/x` has the symmetry and diverges, and it is not 0
([#2638](https://github.com/asc-community/AngouriMath/issues/2638)).

| simplified | Was (2.10.0) | Now |
|---|---|---|
| `integral(ln(x)/(1+x^2), x, 0, +oo)` | unevaluated | `0` |
| `integral(ln(x)/(x^2+x+1), x, 0, +oo)` | unevaluated | `0` |
| `integral(ln(x)/(4+x^2), x, 0, +oo)` | unevaluated | `pi * ln(4) / 8` |

### Logarithms whose multiples are not rational multiples of each other cancel at infinity

**An answer where there was none.** The antiderivative of `1/(x^5 + 1)` has three logarithms with the multiples
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Functions/Continuous/Integration/RothsteinTrager.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[AngouriMath/Functions/Continuous/Integration/InversionSymmetry.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[AngouriMath/Functions/Continuous/Integration/CubeRootLogarithmAnsatz.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public Entity Integrate(Variable x, Entity from, Entity to) =>
// Where there is no antiderivative to take it through, an integrand holding abs(u) is split where u
// changes sign. https://github.com/asc-community/AngouriMath/issues/2605
?? Functions.Algebra.BreakpointIntegration.AcrossTheSignsOfAbs(this, x, from, to)
// ln(x) R(x) over [0, +oo) with R(1/x)/x^2 = R(x) is its own negative under x -> 1/x, and so 0, where it
// converges. https://github.com/asc-community/AngouriMath/issues/2638
?? Functions.Algebra.InversionSymmetry.OverTheHalfLine(this, x, from, to)
?? new Integralf(this, x, (from, to));

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// 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.Collections.Generic;
using System.Linq;
using static AngouriMath.Entity;
using static AngouriMath.Entity.Number;

namespace AngouriMath.Functions.Algebra
{
/// <summary>
/// A definite integral over <c>[0, +oo)</c> of <c>ln(x) R(x)</c>, <c>R</c> rational with <c>R(a^2/x) a^2 / x^2 = R(x)</c>
/// for some <c>a &gt; 0</c>. With <c>a = 1</c> it is 0: the substitution <c>x -> 1/x</c> maps the range onto itself
/// and the integrand <c>ln(x) R(x) dx</c> onto <c>-ln(x) R(x) dx</c>, so the integral is its own negative. Otherwise
/// it is <c>ln(a)</c> times the integral of <c>R</c>.
/// </summary>
/// <remarks>
/// The integrand of <c>ln(x)/(1 + x^2)</c> has no elementary antiderivative, and the integral was left unevaluated.
/// The symmetry says nothing of an integral that diverges, and <c>ln(x)/x</c> has it, so the integral must also be
/// shown to converge: at 0, where <c>ln(x)</c> is integrable, <c>R</c> must be finite; at <c>+oo</c> it must fall
/// like <c>x^-2</c> at least, the denominator's degree above the numerator's by two; and in between the denominator
/// must have no zero. https://github.com/asc-community/AngouriMath/issues/2638
/// </remarks>
internal static class InversionSymmetry
{
internal static Entity? OverTheHalfLine(Entity expr, Variable x, Entity from, Entity to)
{
if (from.Evaled is not Integer { IsZero: true } || to.Evaled is not Real { EDecimal: var upper } || !upper.IsPositiveInfinity())
return null;
var logarithm = MathS.Ln(x);
if (!expr.ContainsNode(logarithm))
return null;
// expr as ln(x) R(x), with no other ln(x) in it.
var standIn = Variable.CreateUnique(expr, "u");
var linear = expr.Substitute(logarithm, standIn);
var rational = linear.Differentiate(standIn).Simplify();
rational = Bare(rational);
if (rational.ContainsNode(standIn) || rational.Vars.Any(variable => variable != x)
|| rational.Nodes.Any(node => node is Logf or Powf(_, not Integer))
|| Bare((linear - rational * standIn).Simplify()) != Integer.Zero)
return null;
if (rational is not Divf(var numerator, var denominator)
|| Degree(numerator, x) is not { } numeratorDegree || Degree(denominator, x) is not { } denominatorDegree
|| denominatorDegree < numeratorDegree + 2)
return null;
if (denominator.Substitute(x, 0).Evaled is not Complex { IsZero: false } atZero)
return null;
var zeros = new List<(Entity At, Real Value)>();
if (!AntiderivativeBreaks.ZerosOf(denominator, x, Integer.Zero, Real.PositiveInfinity, zeros) || zeros.Count > 0)
return null;
// The scale a^2 that x -> a^2/x would have to keep: the product of the denominator's roots in modulus is
// |D(0) / lead(D)|, and a symmetric denominator has it a^(2 deg D). With a = 1 the integral is 0; otherwise
// x = a t turns it into ln(a) times the integral of R, plus the integral of ln(t) R(a t) a dt, which is 0:
// ln(x)/(4 + x^2) over [0, +oo) is ln(2) pi/4.
if (LeadingCoefficient(denominator, x, denominatorDegree) is not { } leading)
return null;
var squareOfTheScale = MathS.Pow(MathS.Abs(atZero / leading), Rational.Create(2, denominatorDegree)).InnerSimplified;
if (Bare((rational.Substitute(x, squareOfTheScale / x) * squareOfTheScale / MathS.Pow(x, 2) - rational).Simplify()) != Integer.Zero)
return null;
if (squareOfTheScale == Integer.One)
return Integer.Zero;
var ofTheRationalFunction = rational.Integrate(x, Integer.Zero, Real.PositiveInfinity).Simplify();
if (ofTheRationalFunction.Nodes.Any(node => node is Integralf) || ofTheRationalFunction.Evaled is not Real { IsFinite: true })
return null;
return (MathS.Ln(squareOfTheScale) / 2 * ofTheRationalFunction).Simplify();
}

private static Entity? LeadingCoefficient(Entity polynomial, Variable x, int degree)
=> LimitSolvers.ParseAsPolynomial(polynomial, x) is { } monomials
&& monomials.FirstOrDefault(monomial => monomial.Key.CompareTo(PeterO.Numbers.EDecimal.FromInt32(degree)) == 0) is { Value: { } coefficient }
? coefficient
: null;

private static Entity Bare(Entity expr)
{
while (expr is Providedf(var inner, _))
expr = inner;
return expr;
}

private static int? Degree(Entity polynomial, Variable x)
{
if (!polynomial.ContainsNode(x))
return polynomial.Evaled is Complex ? 0 : null;
if (LimitSolvers.ParseAsPolynomial(polynomial, x) is not { Count: > 0 } monomials
|| monomials.Values.Any(coefficient => coefficient.ContainsNode(x)))
return null;
var highest = monomials.Keys.Max()!;
return highest.IsInteger() && highest.Sign >= 0 && highest.CompareTo(PeterO.Numbers.EDecimal.FromInt32(1000)) < 0
? highest.ToInt32Checked() : null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// 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.Linq;
using AngouriMath.Extensions;
using Xunit;
using static AngouriMath.Entity;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// <c>ln(x)/(1 + x^2)</c> has no elementary antiderivative, and its integral over <c>[0, +oo)</c> was left unevaluated.
/// It is 0: <c>x -> 1/x</c> maps it onto its own negative. Likewise <c>ln(x) R(x)</c> for any rational <c>R</c> with
/// <c>R(a^2/x) a^2/x^2 = R(x)</c> is <c>ln(a)</c> times the integral of <c>R</c>, where the integral converges.
/// https://github.com/asc-community/AngouriMath/issues/2638
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ALogarithmOverASymmetricRationalFunctionTest
{
/// <summary>Values from mpmath's quadrature at 30 digits.</summary>
[Theory]
[InlineData("ln(x)/(1 + x^2)", "0")]
[InlineData("ln(x)/(x^2 + x + 1)", "0")]
[InlineData("x ln(x)/(1 + x^2)^2", "0")]
[InlineData("ln(x) (1 + x^2)/(1 + x^4)", "0")]
[InlineData("ln(x)/(4 + x^2)", "0.544396522575900532625172224559")]
[InlineData("ln(x)/(9 + x^2)", "0.575232049203867110238970097303")]
[InlineData("ln(x)/(x^2 + 2x + 4)", "0.419076638473456469623951562782")]
[InlineData("ln(x)/(x^2 + 3)", "0.498165567681529093555754443278")]
public void TheIntegralOverTheHalfLineIsItsValue(string integrand, string expected)
{
var integral = integrand.ToEntity().Integrate("x", 0, "+oo".ToEntity()).Simplify();
Assert.DoesNotContain(integral.Nodes, node => node is Integralf);
Assert.True((integral - expected.ToEntity()).EvalNumerical().Abs() < 1e-12,
$"{integrand} over [0, +oo) was {integral}, not {expected}");
}

/// <summary>
/// The symmetry without convergence says nothing: <c>ln(x)/x</c> has it and diverges, and with a pole on the
/// half-line, or a denominator not of degree two more, no value is given by it.
/// </summary>
[Theory]
[InlineData("ln(x)/x")]
[InlineData("ln(x)/(x^2 - 3x + 1)")]
[InlineData("ln(x) x/(x^2 + 1)")]
public void ADivergentIntegralIsNotZero(string integrand)
{
var integral = integrand.ToEntity().Integrate("x", 0, "+oo".ToEntity()).Simplify();
Assert.False(integral.Evaled is Number.Complex { IsFinite: true }, $"{integrand} over [0, +oo) was {integral}");
}
}
}
Loading