Skip to content

Commit f8893b4

Browse files
Rafael-SOWNetclaude
andcommitted
Merge master, with #1518: both breaking-changes entries kept
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
2 parents e8ac320 + a1591e5 commit f8893b4

5 files changed

Lines changed: 261 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,21 @@ where it was `0.1 * x ^ 2 / 2 + C`
16791679
| `limit(sin(c*x)/x, x, 0)` | `NaN` | `c` |
16801680
| `limit((1 - cos(c*x))/x^2, x, 0)` | `NaN` | `c ^ 2 / 2` |
16811681

1682+
### A half-odd power of a logarithm beside a power of `x` is integrated
1683+
1684+
`x sqrt(ln(x))` was left unintegrated. `x^p F^n`, where `F` is `ln x` or `A + B ln(c x^r)` and
1685+
`n` is half an odd number, is now integrated onto the Gaussian's moments under `t = sqrt(F)`.
1686+
A polynomial beside it is summed a power at a time, and the logarithm of a power of a linear is
1687+
the same question under `u = d + e x`
1688+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1689+
1690+
| Input | Was (2.5.0) | Now |
1691+
|---|---|---|
1692+
| `"x*sqrt(ln(x))".Integrate("x")` | `integral(x * sqrt(ln(x)), x)` | the antiderivative, with `erfi` |
1693+
| `"sqrt(ln(a*x^n))".Integrate("x")` | `integral(sqrt(ln(a * x ^ n)), x)` | the antiderivative, with `erfi` |
1694+
| `"x^2/ln(x)^(3/2)".Integrate("x")` | `integral(x ^ 2 / ln(x) ^ (3/2), x)` | the antiderivative, with `erfi` |
1695+
| `"(f + g*x)*(a + b*ln(c*(d + k*x)^n))^(3/2)".Integrate("x")` | `integral((f + g * x) * (a + b * ln(c * (d + k * x) ^ n)) ^ (3/2), x)` | the antiderivative |
1696+
16821697
### The Gaussian with a linear term is integrated beside a power of `x` or a polynomial
16831698

16841699
`x^2 e^(-x^2 + x)` was left unintegrated. `x^m P(x) F^(a x^2 + b x + c)` with `b` not zero is now

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
636636

637637
[Tests/UnitTests/Calculus/DowncastingOffCalculusTest.cs]
638638
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
639+
640+
[Tests/UnitTests/Calculus/HalfOddPowerOfALogarithmTest.cs]
641+
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

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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8536,6 +8536,161 @@ private static Entity SquarefreePartAsWritten(Entity denominator, Entity.Variabl
85368536
return sum.InnerSimplified;
85378537
}
85388538

8539+
/// <summary>
8540+
/// A power of x times a half-odd power of a logarithm, <c>x^p F^n</c> with <c>F</c> =
8541+
/// <c>ln x</c> or <c>A + B ln(c x^r)</c> and <c>2n</c> odd, onto the Gaussian's moments.
8542+
/// With <c>t = sqrt(F)</c> and <c>F' = s/x</c>, <c>dx = 2 x t dt/s</c>, and
8543+
/// <c>x^(p + 1) e^(-(p + 1) F/s)</c> is a constant, so the integral is that constant times
8544+
/// <c>2/s</c> times the integral of <c>t^(2n + 1) e^((p + 1) t^2/s)</c>: an even moment of
8545+
/// the Gaussian, which the table answers. At <c>p = -1</c> it is
8546+
/// <c>F^(n + 1)/(s (n + 1))</c>. Rubi's 3.1.2, <c>(d x)^m (a + b ln(c x^n))^p</c> for a
8547+
/// half-odd <c>p</c>.
8548+
/// https://github.com/asc-community/AngouriMath/issues/1501
8549+
/// </summary>
8550+
/// <remarks>
8551+
/// The constant is written <c>x^(p + 1) e^(-(p + 1) F/s)</c>, as Rubi writes it, rather
8552+
/// than with <c>ln(c x^r)</c> split into <c>ln c + r ln x</c>, which holds only where
8553+
/// <c>c</c> is positive. The logarithm to the right of a whole power of it is
8554+
/// <see cref="SolveAPowerTimesAPowerOfTheLogarithm"/>'s.
8555+
/// </remarks>
8556+
internal static Entity? SolveAPowerTimesAHalfOddPowerOfTheLogarithm(Entity expr, Entity.Variable x)
8557+
{
8558+
Entity? p = null;
8559+
Number.Rational? n = null;
8560+
Entity constant = Number.Integer.One;
8561+
Entity? logarithm = null;
8562+
Dictionary<EInteger, Entity>? polynomial = null;
8563+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
8564+
{
8565+
if (!factor.ContainsNode(x))
8566+
{
8567+
constant = underneath ? constant / factor : constant * factor;
8568+
continue;
8569+
}
8570+
if (factor == x && p is null)
8571+
p = underneath ? Number.Integer.MinusOne : Number.Integer.One;
8572+
else if (factor is Powf(var @base, var exponent) && @base == x && !exponent.ContainsNode(x) && p is null)
8573+
p = underneath ? -exponent : exponent;
8574+
else if (factor is Powf(Mulf(var scale, var scaled), var scaledExponent) && scaled == x && !scale.ContainsNode(x) && !scaledExponent.ContainsNode(x) && p is null)
8575+
{
8576+
p = underneath ? -scaledExponent : scaledExponent;
8577+
var scalePower = MathS.Pow(scale, scaledExponent);
8578+
constant = underneath ? constant / scalePower : constant * scalePower;
8579+
}
8580+
else if (n is null && factor is Powf(var f, Number.Rational half) && half.ERational.Denominator.Equals(EInteger.FromInt32(2)))
8581+
{
8582+
if (f == MathS.Ln(x) || IsAffineInALogarithmOfAPowerOfX(f, x))
8583+
(logarithm, n) = (f, underneath ? Number.Rational.Create(-half.ERational) : half);
8584+
// The logarithm of a power of a linear, Rubi's 3.3: the same question under
8585+
// u = d + e x. Declined, it was integrated by parts against the half-odd
8586+
// power's own antiderivative, which took (f + g x) (a + b ln(c (d + e x)^n))^(3/2)
8587+
// 37 s to give up.
8588+
else if (LinearUnderALogarithm(f, x) is { } linear)
8589+
return ByTheLinearUnderTheLogarithm(expr, x, linear);
8590+
else
8591+
return null;
8592+
}
8593+
// A polynomial beside it, which is how a linear outside the logarithm arrives once
8594+
// the linear inside it has been substituted: summed a power at a time.
8595+
else if (polynomial is null && !underneath && TreeAnalyzer.TryGetPolynomial(factor, x, out var monomials)
8596+
&& monomials.Count > 1 && monomials.Keys.All(power => power.Sign >= 0 && power.CompareTo(EInteger.FromInt32(12)) <= 0))
8597+
polynomial = monomials;
8598+
else
8599+
return null;
8600+
}
8601+
if (logarithm is null || n is null)
8602+
return null;
8603+
p = (p ?? Number.Integer.Zero).InnerSimplified;
8604+
if (p.Evaled is Number.Complex and not Number.Real)
8605+
return null;
8606+
Entity slopeOfF = Number.Integer.One;
8607+
if (logarithm != MathS.Ln(x))
8608+
{
8609+
slopeOfF = Functions.PartialFractions.Bare((logarithm.Differentiate(x) * x).Simplify());
8610+
if (slopeOfF.ContainsNode(x) || slopeOfF.Evaled is Number.Complex { IsZero: true })
8611+
return null;
8612+
}
8613+
if (polynomial is null)
8614+
return HalfOddLogarithmicTerm(p, logarithm, n, slopeOfF, x) is { } single ? (constant * single).InnerSimplified : null;
8615+
Entity sum = Number.Integer.Zero;
8616+
foreach (var monomial in polynomial)
8617+
{
8618+
if (HalfOddLogarithmicTerm((p + Number.Integer.Create(monomial.Key)).InnerSimplified, logarithm, n, slopeOfF, x) is not { } term)
8619+
return null;
8620+
sum += monomial.Value * term;
8621+
}
8622+
return (constant * sum).InnerSimplified;
8623+
}
8624+
8625+
/// <summary>
8626+
/// The linear <c>d + e x</c>, with <c>d</c> not zero, whose powers and constant multiples
8627+
/// make up the argument of the one logarithm in <paramref name="expr"/>, or
8628+
/// <see langword="null"/>.
8629+
/// </summary>
8630+
private static Entity? LinearUnderALogarithm(Entity expr, Entity.Variable x)
8631+
{
8632+
Entity? argument = null;
8633+
foreach (var node in expr.Nodes)
8634+
if (node is Logf(var @base, var antilogarithm) && @base == MathS.e && antilogarithm.ContainsNode(x))
8635+
{
8636+
if (argument is not null && argument != antilogarithm)
8637+
return null;
8638+
argument = antilogarithm;
8639+
}
8640+
if (argument is null)
8641+
return null;
8642+
foreach (var node in argument.Nodes)
8643+
if (node is Sumf or Minusf && TreeAnalyzer.TryGetPolyLinear(node, x, out var slope, out var intercept)
8644+
&& !TreeAnalyzer.IsZero(slope) && !TreeAnalyzer.IsZero(intercept))
8645+
{
8646+
var placeholder = Variable.CreateUnique(argument, "u_lin");
8647+
var inThePlaceholder = argument.Replace(child => child == node ? placeholder : child);
8648+
return !inThePlaceholder.ContainsNode(x) && IsAProductOfPowersOfTheVariable(inThePlaceholder, placeholder) ? node : null;
8649+
}
8650+
return null;
8651+
}
8652+
8653+
/// <summary>
8654+
/// <paramref name="expr"/> under <c>u = d + e x</c>, with <paramref name="linear"/> the
8655+
/// <c>d + e x</c> under its logarithm, answered as a power or a polynomial of <c>u</c>
8656+
/// beside a half-odd power of <c>A + B ln(c u^r)</c> and written back in <c>x</c>.
8657+
/// </summary>
8658+
private static Entity? ByTheLinearUnderTheLogarithm(Entity expr, Entity.Variable x, Entity linear)
8659+
{
8660+
if (!TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out var intercept) || slope is null || intercept is null)
8661+
return null;
8662+
var u = Variable.CreateUnique(expr, "u");
8663+
var inU = (expr.Replace(node => node == linear ? u : node).Substitute(x, (u - intercept) / slope) / slope).InnerSimplified;
8664+
if (inU.ContainsNode(x) || LinearUnderALogarithm(inU, u) is not null)
8665+
return null;
8666+
return SolveAPowerTimesAHalfOddPowerOfTheLogarithm(inU, u)?.Substitute(u, linear).InnerSimplified;
8667+
}
8668+
8669+
/// <summary>
8670+
/// The integral of <c>x^q F^n</c> for a half-odd <c>n</c> and <c>F' = s/x</c>: see
8671+
/// <see cref="SolveAPowerTimesAHalfOddPowerOfTheLogarithm"/>.
8672+
/// </summary>
8673+
private static Entity? HalfOddLogarithmicTerm(Entity q, Entity logarithm, Number.Rational n, Entity slopeOfF, Entity.Variable x)
8674+
{
8675+
var qPlusOne = (q + 1).InnerSimplified;
8676+
if (qPlusOne.Evaled is Number.Complex { IsZero: true })
8677+
return MathS.Pow(logarithm, n + 1) / ((n + 1) * slopeOfF);
8678+
// t^(2n + 1) e^((q + 1) t^2/s) in a variable of its own, for the table's moments.
8679+
var t = Variable.CreateUnique(logarithm, "t");
8680+
var power = (2 * n.ERational + ERational.One).ToEInteger();
8681+
if (!power.CanFitInInt32() || power.Abs().CompareTo(EInteger.FromInt32(32)) > 0)
8682+
return null;
8683+
var gaussian = MathS.Pow(MathS.e, (qPlusOne / slopeOfF).InnerSimplified * MathS.Sqr(t));
8684+
var inT = power.IsZero ? gaussian : MathS.Pow(t, Number.Integer.Create(power)) * gaussian;
8685+
if (IntegralPatterns.TryStandardIntegrals(inT, t) is not { } answerInT)
8686+
return null;
8687+
// x^(q + 1) e^(-(q + 1) ln(x)) is 1 wherever ln(x) is real, so for ln(x) itself it is left out.
8688+
Entity theConstant = logarithm == MathS.Ln(x)
8689+
? Number.Integer.One
8690+
: MathS.Pow(x, qPlusOne) * MathS.Pow(MathS.e, -qPlusOne * logarithm / slopeOfF);
8691+
return 2 / slopeOfF * theConstant * answerInT.Substitute(t, MathS.Sqrt(logarithm));
8692+
}
8693+
85398694
/// <summary>
85408695
/// Whether <paramref name="expr"/> is <c>A + B ln(c x^r)</c> with <c>A</c>, <c>B</c>,
85418696
/// <c>c</c> and <c>r</c> free of <paramref name="x"/> and the logarithm present: one

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
569569
// A power of x times a power of its logarithm, by the closed reduction: exact,
570570
// and by parts n times where the exponent is a symbol was not taken.
571571
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAPowerOfTheLogarithm(expr, x)) is { }) return answer;
572+
// And a half-odd power of it, onto the Gaussian's moments by t = sqrt(F).
573+
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAHalfOddPowerOfTheLogarithm(expr, x)) is { }) return answer;
572574
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
573575
// An exponential of a multiple of a logarithm is a power of the argument, which is
574576
// how every inverse hyperbolic function under an exponential arrives.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 System.Linq;
10+
using AngouriMath.Extensions;
11+
using Xunit;
12+
13+
namespace AngouriMath.Tests.Calculus
14+
{
15+
/// <summary>
16+
/// A power of x times a half-odd power of a logarithm, <c>x^p (A + B ln(c x^r))^n</c>, onto the
17+
/// Gaussian's moments by <c>t = sqrt(F)</c>: Rubi's 3.1.2, <c>(d x)^m (a + b ln(c x^n))^p</c> with
18+
/// <c>p</c> half an odd number, every one of which was left unevaluated.
19+
/// https://github.com/asc-community/AngouriMath/issues/1501
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class HalfOddPowerOfALogarithmTest
23+
{
24+
/// <summary>Past 1, where every logarithm here is real and positive for the pins below.</summary>
25+
private static readonly double[] Points = { 1.3, 1.9, 2.6, 3.4 };
26+
private static readonly (string Name, string Value)[] Pins =
27+
{ ("a", "3/2"), ("b", "2/3"), ("c", "5/4"), ("n", "3"), ("m", "1/2"), ("d", "1/2"), ("k", "2"), ("f", "3/4"), ("g", "2"), ("h", "1/3"), ("p", "2"), ("q", "3/2") };
28+
29+
private static void DifferentiatesBack(string integrand)
30+
{
31+
var integral = integrand.ToEntity().Integrate("x");
32+
Assert.DoesNotContain("integral(", integral.Stringize());
33+
Entity Pinned(Entity e) => Pins.Aggregate(e, (current, pin) => current.Substitute(pin.Name, pin.Value.ToEntity()));
34+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
35+
var original = Pinned(integrand.ToEntity());
36+
foreach (var at in Points)
37+
{
38+
var got = derivative.Substitute("x", at).EvalNumerical();
39+
var want = original.Substitute("x", at).EvalNumerical();
40+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
41+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart));
42+
Assert.True(difference / scale < 1e-9, $"d/dx of {integral} is {got} at x = {at}, where {integrand} is {want}");
43+
}
44+
}
45+
46+
[Theory]
47+
[InlineData("sqrt(ln(x))")]
48+
[InlineData("x*sqrt(ln(x))")]
49+
[InlineData("x^2/sqrt(ln(x))")]
50+
[InlineData("sqrt(ln(x))/x^2")]
51+
[InlineData("x^3*ln(x)^(3/2)")]
52+
[InlineData("1/(x^3*ln(x)^(3/2))")]
53+
[InlineData("x/ln(x)^(5/2)")]
54+
public void OfTheLogarithmItself(string integrand) => DifferentiatesBack(integrand);
55+
56+
[Theory]
57+
[InlineData("sqrt(ln(x^2))")]
58+
[InlineData("sqrt(ln(a*x^n))")]
59+
[InlineData("x^3*sqrt(ln(a*x^n))")]
60+
[InlineData("x^m/sqrt(ln(a*x^n))")]
61+
[InlineData("(a + b*ln(c*x^n))^(1/2)")]
62+
[InlineData("x^3*ln(a*x^n)^(3/2)")]
63+
[InlineData("x^2/ln(a*x^n)^(3/2)")]
64+
[InlineData("x^m/ln(a*x^n)^(5/2)")]
65+
public void OfALogarithmOfAPower(string integrand) => DifferentiatesBack(integrand);
66+
67+
/// <summary>
68+
/// The logarithm of a power of a linear, with a polynomial beside it, under
69+
/// <c>u = d + e x</c>: Rubi's 3.3. Declined, these went by parts against the half-odd
70+
/// power's own antiderivative and took up to 55 s to give up.
71+
/// </summary>
72+
[Theory]
73+
[InlineData("sqrt(ln(2 + 3*x))")]
74+
[InlineData("(f + g*x)*(a + b*ln(c*(d + k*x)^n))^(3/2)")]
75+
[InlineData("(f + g*x)^2*sqrt(a + b*ln(c*(d + k*x)^n))")]
76+
[InlineData("(f + g*x)^3/sqrt(a + b*ln(c*(d + k*x)^n))")]
77+
[InlineData("(f + g*x)/(a + b*ln(c*(d + k*x)^n))^(5/2)")]
78+
[InlineData("(g + h*x)^2/sqrt(a + b*ln(c*(d*(k + f*x)^p)^q))")]
79+
public void OfALogarithmOfAPowerOfALinear(string integrand) => DifferentiatesBack(integrand);
80+
81+
/// <summary>Beside <c>1/x</c> it is elementary, <c>F^(n + 1)/(s (n + 1))</c>.</summary>
82+
[Fact]
83+
public void BesideTheReciprocalItIsAPower()
84+
=> Assert.Equal("2 * sqrt(ln(x)) + C".ToEntity(), "1/(x*sqrt(ln(x)))".ToEntity().Integrate("x"));
85+
}
86+
}

0 commit comments

Comments
 (0)