Skip to content

Commit 136e36b

Browse files
Rafael-SOWNetclaude
andcommitted
Merge master, with #1522: 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 70f17fc + 0775ca1 commit 136e36b

5 files changed

Lines changed: 260 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,21 @@ quadratic alone, or beside a polynomial only, is left to the rules that answered
17451745
| `"x^2*sinh(a + b*x + c*x^2)^2".Integrate("x")` | `integral(x ^ 2 * ((e ^ (a + b * x + c * x ^ 2) - e ^ (-(a + b * x + c * x ^ 2))) / 2) ^ 2, x)` | the antiderivative |
17461746
| `"2^(x^2)*3^(x + 1)".Integrate("x")` | `integral(2 ^ x ^ 2 * 3 ^ (x + 1), x)` | the antiderivative, with `erfi` |
17471747

1748+
### An exponential of a quadratic in a logarithm beside a power of `x` is integrated
1749+
1750+
`e^(ln(x)^2)` was left unintegrated. `x^p G^(Q(L))`, where `L` is `ln(c x^r)` and `Q` a quadratic
1751+
with a square term, is now integrated under `t = L`, where it is the Gaussian with a linear term. A
1752+
polynomial beside it is summed a power at a time, and the logarithm of a power of a linear is the
1753+
same question under `u = d + e x`
1754+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1755+
1756+
| Input | Was (2.5.0) | Now |
1757+
|---|---|---|
1758+
| `"e^(ln(x)^2)".Integrate("x")` | `integral(e ^ ln(x) ^ 2, x)` | the antiderivative, with `erfi` |
1759+
| `"x^2*F^(f*(a + b*ln(c*x^n))^2)".Integrate("x")` | `integral(x ^ 2 * F ^ (f * (a + b * ln(c * x ^ n)) ^ 2), x)` | the antiderivative |
1760+
| `"(d*g + k*g*x)^m*F^(f*(a + b*ln(c*(d + k*x)^n))^2)".Integrate("x")` | `integral((d * g + k * g * x) ^ m * F ^ (f * (a + b * ln(c * (d + k * x) ^ n)) ^ 2), x)` | the antiderivative |
1761+
| `"(g + h*x)^3*F^(f*(a + b*ln(c*(d + k*x)^n)^2))".Integrate("x")` | `integral((g + h * x) ^ 3 * F ^ (f * (a + b * ln(c * (d + k * x) ^ n) ^ 2)), x)` | the antiderivative |
1762+
17481763
### A power of `x` one less than a half-odd multiple of the power inside is integrated
17491764

17501765
`f^(a + b x^n) x^(-1 + 5n/2)` was left unintegrated. `x^(k n - 1) g(x^n)`, with a symbolic `n`, was

‎Sources/.editorconfig‎

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

643643
[Tests/UnitTests/Calculus/ExponentialsOfQuadraticsTest.cs]
644644
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
645+
646+
[Tests/UnitTests/Calculus/ExponentialOfAQuadraticInALogarithmTest.cs]
647+
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: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9059,6 +9059,166 @@ private static Entity SquarefreePartAsWritten(Entity denominator, Entity.Variabl
90599059
return 2 / slopeOfF * theConstant * answerInT.Substitute(t, MathS.Sqrt(logarithm));
90609060
}
90619061

9062+
/// <summary>
9063+
/// A power of x times an exponential of a quadratic in a logarithm, <c>x^p G^(Q(L))</c> with
9064+
/// <c>L</c> = <c>ln(c x^r)</c> and <c>Q</c> a quadratic with a square term, onto the
9065+
/// Gaussian. With <c>t = L</c> and <c>L' = s/x</c>, <c>dx = x dt/s</c>, and
9066+
/// <c>x^(p + 1) e^(-(p + 1) L/s)</c> is a constant, so the integral is that constant over
9067+
/// <c>s</c> times the integral of <c>e^(Q(t) ln G + (p + 1) t/s)</c>: the Gaussian with a
9068+
/// linear term, which the table answers. A polynomial beside it is summed a power at a time,
9069+
/// and the logarithm of a power of a linear is the same question under <c>u = d + e x</c>.
9070+
/// Rubi's 2.3, <c>F^(f (a + b ln(c (d + e x)^n))^2) (g + h x)^m</c> and
9071+
/// <c>F^(f (a + b ln(c (d + e x)^n)^2)) (g + h x)^m</c>.
9072+
/// https://github.com/asc-community/AngouriMath/issues/1501
9073+
/// </summary>
9074+
/// <remarks>
9075+
/// The constant is written <c>x^(p + 1) e^(-(p + 1) L/s)</c>, as
9076+
/// <see cref="SolveAPowerTimesAHalfOddPowerOfTheLogarithm"/> writes it and as Rubi does,
9077+
/// rather than with <c>ln(c x^r)</c> split into <c>ln c + r ln x</c>, which holds only
9078+
/// where <c>c</c> is positive. A quadratic without its square term is a power of
9079+
/// <c>c x^r</c>, which the rules for powers answer.
9080+
/// </remarks>
9081+
internal static Entity? SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm(Entity expr, Entity.Variable x)
9082+
{
9083+
// The exponential and its logarithm first, which allocates nothing where there is
9084+
// none; and the logarithm of a linear before any factor is read, since beside it a
9085+
// constant multiple of that linear, (d g + e g x)^m, is a factor only in u.
9086+
if (expr is not (Mulf or Divf or Powf) || AnExponentialOfALogarithm(expr, x) is not { } theExponential)
9087+
return null;
9088+
if (TheLogarithmOfAPowerOfX(theExponential.Exponent, x) is not { } logarithm)
9089+
return LinearUnderALogarithm(theExponential.Exponent, x) is { } linear ? UnderTheLinearUnderTheLogarithm(expr, x, linear) : null;
9090+
Entity? p = null;
9091+
Entity constant = Number.Integer.One;
9092+
Entity? @base = null, exponent = null;
9093+
Dictionary<EInteger, Entity>? polynomial = null;
9094+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
9095+
{
9096+
if (!factor.ContainsNode(x))
9097+
{
9098+
constant = underneath ? constant / factor : constant * factor;
9099+
continue;
9100+
}
9101+
if (factor == x && p is null)
9102+
p = underneath ? Number.Integer.MinusOne : Number.Integer.One;
9103+
else if (factor is Powf(var b, var e) && b == x && !e.ContainsNode(x) && p is null)
9104+
p = underneath ? -e : e;
9105+
else if (factor is Powf(Mulf(var left, var right), var scaledExponent) && (left == x) != (right == x)
9106+
&& !(left == x ? right : left).ContainsNode(x) && !scaledExponent.ContainsNode(x) && p is null)
9107+
{
9108+
p = underneath ? -scaledExponent : scaledExponent;
9109+
var scalePower = MathS.Pow(left == x ? right : left, scaledExponent);
9110+
constant = underneath ? constant / scalePower : constant * scalePower;
9111+
}
9112+
else if (exponent is null && factor is Powf(var g, var power) && !g.ContainsNode(x) && power.ContainsNode(x))
9113+
(@base, exponent) = (g, underneath ? -power : power);
9114+
else if (polynomial is null && !underneath && TreeAnalyzer.TryGetPolynomial(factor, x, out var monomials)
9115+
&& monomials.Count > 1 && monomials.Keys.All(degree => degree.Sign >= 0 && degree.CompareTo(EInteger.FromInt32(12)) <= 0))
9116+
polynomial = monomials;
9117+
else
9118+
return null;
9119+
}
9120+
if (@base is null || exponent is null || !exponent.ContainsNode(logarithm))
9121+
return null;
9122+
var t = Variable.CreateUnique(expr, "t");
9123+
var inT = exponent.Replace(node => node == logarithm ? t : node);
9124+
if (inT.ContainsNode(x) || !TreeAnalyzer.TryGetPolyQuadratic(inT, t, out var square, out _, out _) || TreeAnalyzer.IsZero(square))
9125+
return null;
9126+
var rate = Functions.PartialFractions.Bare((logarithm.Differentiate(x) * x).Simplify());
9127+
if (rate.ContainsNode(x) || rate.Evaled is Number.Complex { IsZero: true } || rate.Nodes.Any(node => node == MathS.NaN))
9128+
return null;
9129+
var exponentInT = @base == MathS.e ? inT : inT * MathS.Ln(@base);
9130+
p = (p ?? Number.Integer.Zero).InnerSimplified;
9131+
if (polynomial is null)
9132+
return ExponentialOfAQuadraticInALogarithmTerm(p, exponentInT, t, logarithm, rate, x) is { } single ? (constant * single).InnerSimplified : null;
9133+
Entity sum = Number.Integer.Zero;
9134+
foreach (var monomial in polynomial)
9135+
{
9136+
if (ExponentialOfAQuadraticInALogarithmTerm((p + Number.Integer.Create(monomial.Key)).InnerSimplified, exponentInT, t, logarithm, rate, x) is not { } term)
9137+
return null;
9138+
sum += monomial.Value * term;
9139+
}
9140+
return (constant * sum).InnerSimplified;
9141+
}
9142+
9143+
/// <summary>
9144+
/// The integral of <c>x^q e^(E(L))</c>, where <paramref name="exponentInT"/> is <c>E</c> in
9145+
/// <paramref name="t"/> standing for <paramref name="logarithm"/> and <c>L' = s/x</c>: see
9146+
/// <see cref="SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm"/>.
9147+
/// </summary>
9148+
private static Entity? ExponentialOfAQuadraticInALogarithmTerm(Entity q, Entity exponentInT, Entity.Variable t, Entity logarithm, Entity rate, Entity.Variable x)
9149+
{
9150+
var qPlusOne = (q + 1).InnerSimplified;
9151+
var atMinusOne = qPlusOne.Evaled is Number.Complex { IsZero: true };
9152+
var inT = MathS.Pow(MathS.e, atMinusOne ? exponentInT : exponentInT + qPlusOne / rate * t);
9153+
if (IntegralPatterns.TryStandardIntegrals(inT, t) is not { } answerInT)
9154+
return null;
9155+
// x^(q + 1) e^(-(q + 1) ln(x)) is 1 wherever ln(x) is real, so for ln(x) itself it is left out.
9156+
Entity theConstant = atMinusOne || logarithm == MathS.Ln(x)
9157+
? Number.Integer.One
9158+
: MathS.Pow(x, qPlusOne) * MathS.Pow(MathS.e, -qPlusOne * logarithm / rate);
9159+
return theConstant / rate * answerInT.Substitute(t, logarithm);
9160+
}
9161+
9162+
/// <summary>
9163+
/// A factor of <paramref name="expr"/> that is an exponential of <paramref name="x"/> with a
9164+
/// logarithm in its exponent, read through products and quotients, or <see langword="null"/>.
9165+
/// </summary>
9166+
private static Powf? AnExponentialOfALogarithm(Entity expr, Entity.Variable x) => expr switch
9167+
{
9168+
Mulf(var left, var right) => AnExponentialOfALogarithm(left, x) ?? AnExponentialOfALogarithm(right, x),
9169+
Divf(var numerator, var denominator) => AnExponentialOfALogarithm(numerator, x) ?? AnExponentialOfALogarithm(denominator, x),
9170+
Powf(var @base, var exponent) power when !@base.ContainsNode(x) && exponent.ContainsNode(x)
9171+
&& exponent.Nodes.Any(node => node is Logf) => power,
9172+
_ => null
9173+
};
9174+
9175+
/// <summary>
9176+
/// The one natural logarithm of <paramref name="x"/> in <paramref name="expr"/>, where its
9177+
/// argument is a constant times a power of <paramref name="x"/>, or <see langword="null"/>.
9178+
/// </summary>
9179+
private static Entity? TheLogarithmOfAPowerOfX(Entity expr, Entity.Variable x)
9180+
{
9181+
Entity? logarithm = null;
9182+
foreach (var node in expr.Nodes)
9183+
if (node is Logf(var @base, var argument) && @base == MathS.e && argument.ContainsNode(x))
9184+
{
9185+
if (logarithm is not null && logarithm != node)
9186+
return null;
9187+
logarithm = node;
9188+
}
9189+
return logarithm is Logf(_, var antilogarithm) && IsAProductOfPowersOfTheVariable(antilogarithm, x) ? logarithm : null;
9190+
}
9191+
9192+
/// <summary>
9193+
/// <paramref name="expr"/> under <c>u = d + e x</c>, with <paramref name="linear"/> the
9194+
/// <c>d + e x</c> under the logarithm, answered by
9195+
/// <see cref="SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm"/> in <c>u</c> and
9196+
/// written back in <c>x</c>. A constant multiple of the linear, as <c>(d g + e g x)^m</c>
9197+
/// writes one, is read as <c>g u</c>, where substituting for <c>x</c> would leave a sum
9198+
/// that is a multiple of <c>u</c> only once simplified.
9199+
/// </summary>
9200+
private static Entity? UnderTheLinearUnderTheLogarithm(Entity expr, Entity.Variable x, Entity linear)
9201+
{
9202+
if (!TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out var intercept) || slope is null || intercept is null)
9203+
return null;
9204+
var u = Variable.CreateUnique(expr, "u");
9205+
var inU = (expr.Replace(node =>
9206+
{
9207+
if (node == linear)
9208+
return u;
9209+
if (node is not (Sumf or Minusf) || !TreeAnalyzer.TryGetPolyLinear(node, x, out var nodeSlope, out var nodeIntercept)
9210+
|| TreeAnalyzer.IsZero(nodeSlope) || TreeAnalyzer.IsZero(nodeIntercept))
9211+
return node;
9212+
// Bare: simplified, k g/k is g provided k is not 0, which k is, the linear being one.
9213+
return Functions.PartialFractions.Bare((nodeIntercept * slope - nodeSlope * intercept).Simplify()).Evaled is Number.Complex { IsZero: true }
9214+
? Functions.PartialFractions.Bare((nodeSlope / slope).Simplify()) * u
9215+
: node;
9216+
}).Substitute(x, (u - intercept) / slope) / slope).InnerSimplified;
9217+
if (inU.ContainsNode(x) || LinearUnderALogarithm(inU, u) is not null)
9218+
return null;
9219+
return SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm(inU, u)?.Substitute(u, linear).InnerSimplified;
9220+
}
9221+
90629222
/// <summary>
90639223
/// Whether <paramref name="expr"/> is <c>A + B ln(c x^r)</c> with <c>A</c>, <c>B</c>,
90649224
/// <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
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAPowerOfTheLogarithm(expr, x)) is { }) return answer;
570570
// And a half-odd power of it, onto the Gaussian's moments by t = sqrt(F).
571571
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAHalfOddPowerOfTheLogarithm(expr, x)) is { }) return answer;
572+
// And an exponential of a quadratic in it, onto the Gaussian by t = ln(c x^r).
573+
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm(expr, x)) is { }) return answer;
572574
// A power of an exponential with a positive base is the exponential of the product,
573575
// exactly, and only that spelling is one the exponential rules read.
574576
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 an exponential of a quadratic in a logarithm, <c>x^p G^(Q(ln(c x^r)))</c>,
17+
/// onto the Gaussian by <c>t = ln(c x^r)</c>: Rubi's 2.3,
18+
/// <c>F^(f (a + b ln(c (d + e x)^n))^2) (g + h x)^m</c>, 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 ExponentialOfAQuadraticInALogarithmTest
23+
{
24+
/// <summary>Past 1, where every logarithm here is real 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+
{ ("F", "2"), ("a", "1/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") };
28+
29+
private static Entity 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+
return integral;
45+
}
46+
47+
[Theory]
48+
[InlineData("e^(ln(x)^2)")]
49+
[InlineData("x*e^(ln(x)^2)")]
50+
[InlineData("e^(-ln(x)^2)/x^2")]
51+
[InlineData("2^(ln(x)^2 + ln(x))")]
52+
[InlineData("x^m*e^(ln(x)^2)")]
53+
public void OfTheLogarithmItself(string integrand) => DifferentiatesBack(integrand);
54+
55+
[Theory]
56+
[InlineData("F^(f*(a + b*ln(c*x^n))^2)")]
57+
[InlineData("x^2*F^(f*(a + b*ln(c*x^n))^2)")]
58+
[InlineData("F^(-f*(a + b*ln(c*x^n)^2))/x^3")]
59+
[InlineData("x^m*F^(f*(a + b*ln(c*x^n))^2)")]
60+
[InlineData("(1 + x)^2*F^(f*(a + b*ln(c*x^n))^2)")]
61+
public void OfALogarithmOfAPower(string integrand) => DifferentiatesBack(integrand);
62+
63+
/// <summary>
64+
/// The logarithm of a power of a linear, under <c>u = d + e x</c>, with a constant multiple
65+
/// of the linear or a polynomial beside it, as Rubi's 2.3 writes them.
66+
/// </summary>
67+
[Theory]
68+
[InlineData("F^(f*(a + b*ln(c*(d + k*x)^n))^2)")]
69+
[InlineData("(d*g + k*g*x)^m*F^(f*(a + b*ln(c*(d + k*x)^n))^2)")]
70+
[InlineData("F^(f*(a + b*ln(c*(d + k*x)^n)^2))/(d*g + k*g*x)^2")]
71+
[InlineData("(g + h*x)^3*F^(f*(a + b*ln(c*(d + k*x)^n))^2)")]
72+
[InlineData("e^(ln((d + k*x)^n)^2)*(d + k*x)^m")]
73+
public void OfALogarithmOfAPowerOfALinear(string integrand) => DifferentiatesBack(integrand);
74+
75+
/// <summary>Beside <c>1/x</c> it is the Gaussian in <c>ln(x)</c> alone.</summary>
76+
[Fact]
77+
public void BesideTheReciprocalItIsTheGaussianOfTheLogarithm()
78+
=> Assert.Contains(DifferentiatesBack("e^(ln(x)^2)/x").Nodes, node => node is Entity.Erfif);
79+
}
80+
}

0 commit comments

Comments
 (0)