Skip to content

Commit ba8eb99

Browse files
A radical function of whole powers of x written through its logarithm says where its answer holds (#1729)
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 02d12a5 commit ba8eb99

3 files changed

Lines changed: 108 additions & 10 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,22 @@ zero-discriminant arm, which gives the right answer.
553553
Each of these was checked by differentiating it back with the parameters pinned and comparing at
554554
four points. Nothing that already had an antiderivative changes.
555555

556+
### A radical function of whole powers of `x` written through its logarithm says where its answer holds
557+
558+
**Answers where there were none, each with the condition it holds under.** `1/csch(2 ln(x))^(1/2)`
559+
is `sqrt(sinh(2 ln(x)))`, which is `sqrt((x^2 - x^(-2))/2)` and real on both sides of zero; 2.5.0
560+
declined it. On the unreleased master it was integrated under `t = ln(x)`, where the rules take
561+
`e^t` to be positive, and the answer was right for a positive `x` and wrong for every negative one.
562+
Such an answer is given `provided x > 0` now, and `provided c x^n > 0` for a logarithm of `c x^n`
563+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
564+
565+
| Input | Was (2.5.0) | Now |
566+
|---|---|---|
567+
| `"1/csch(2*ln(x))^(1/2)".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative, `provided x > 0` |
568+
| `"csch(2*ln(x))^(-3/2)".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative, `provided x > 0` |
569+
| `"1/csch(2*ln(c*x))^(1/2)".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative, `provided c x > 0` |
570+
| `"1/sech(2*ln(x))^(1/2)".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative, `provided x > 0` |
571+
556572
### `e^(k acoth(a x))` beside a power of `c - a c x` is integrated
557573

558574
**Improvement, not silent.** `e^(3 acoth(a x))/(c - a c x)^3` and `e^(2 acoth(a x)) sqrt(c - a c x)/x`

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

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8076,8 +8076,14 @@ private static bool IsTheSameQuadratic(Entity candidate, Entity wanted, Entity.V
80768076
/// <para>
80778077
/// <b>Where the answer holds.</b> <c>u = ln(x)</c> is a bijection from the positive reals
80788078
/// to the whole line, so the answer is an antiderivative for <c>x &gt; 0</c> — which is
8079-
/// where an integrand built from <c>ln(x)</c> is real in the first place. Nothing is
8080-
/// assumed that the integrand did not already assume.
8079+
/// where an integrand built from <c>ln(x)</c> is real, with one kind of exception. A
8080+
/// radical function of whole powers of <c>x = e^u</c>, <c>sqrt(sinh(2 ln(x)))</c> or
8081+
/// <c>1/csch(2 ln(x))^(1/2)</c>, is real for a negative <c>x</c> too, where <c>ln(x)</c>
8082+
/// is <c>ln(-x) + i pi</c>; and the rules that integrate it in <c>u</c> take <c>e^u</c> to
8083+
/// be positive, which it is for every real <c>u</c>. That answer is given
8084+
/// <c>provided x &gt; 0</c>. Written in powers of <c>x</c>, which
8085+
/// <see cref="SolveByFoldingAnExponentialOfALogarithm"/> does before this, the same
8086+
/// integrand is answered on both sides of zero where the rules read it.
80818087
/// </para>
80828088
/// https://github.com/asc-community/AngouriMath/issues/718
80838089
/// </remarks>
@@ -8103,19 +8109,46 @@ node is Logf(var @base, var argument) && !@base.ContainsNode(x) && @base != Math
81038109
if (integrand is Providedf(var inner, _))
81048110
integrand = inner;
81058111

8106-
return Integration.ComputeIndefiniteIntegral(integrand, u, integrateByParts) is { } result
8107-
? result.Substitute(u, MathS.Ln(x))
8108-
: null;
8112+
if (Integration.ComputeIndefiniteIntegral(integrand, u, integrateByParts) is not { } result)
8113+
return null;
8114+
var back = result.Substitute(u, MathS.Ln(x));
8115+
return IsARadicalFunctionOfWholePowersOfTheExponential(inU, u) ? back.Provided(x > Number.Integer.Zero) : back;
8116+
}
8117+
8118+
/// <summary>
8119+
/// Whether <paramref name="expr"/> holds <paramref name="t"/> only in exponentials
8120+
/// <c>e^(k t + a)</c> with a whole <c>k</c>, some of them under a power that is not
8121+
/// whole: a radical function of whole powers of <c>e^t</c>. At <c>t = s + i pi</c>,
8122+
/// where a substitution <c>t = ln(c x^n)</c> lands for a negative <c>c x^n</c>, it is the
8123+
/// same function of <c>-e^s</c>, real again wherever its radicands are positive; and an
8124+
/// integral of it in <c>t</c> is found for a real <c>t</c>, under which <c>e^t</c> is
8125+
/// positive and gives up its powers from under a root.
8126+
/// </summary>
8127+
private static bool IsARadicalFunctionOfWholePowersOfTheExponential(Entity expr, Entity.Variable t)
8128+
{
8129+
var exponential = Variable.CreateUnique(expr, "w_exp");
8130+
var inExponentials = expr.Replace(node =>
8131+
node is Powf(var @base, var exponent) && @base == MathS.e && exponent.ContainsNode(t)
8132+
&& TreeAnalyzer.TryGetPolyLinear(exponent, t, out var slope, out var offset)
8133+
&& slope.Evaled is Number.Integer && !offset.ContainsNode(t)
8134+
? exponential
8135+
: node);
8136+
return !inExponentials.ContainsNode(t)
8137+
&& inExponentials.Nodes.Any(node => node is Powf(var @base, var power) && @base.ContainsNode(exponential) && power.Evaled is not Number.Integer);
81098138
}
81108139

81118140
/// <summary>
81128141
/// A power of <c>x</c> times a function of one logarithm of a monomial, <c>x^m G(ln(c x^n))</c>,
81138142
/// under <c>t = ln(c x^n)</c>: <c>dx = x dt/n</c>, and <c>x^(m + 1)</c> is
81148143
/// <c>K e^((m + 1) t/n)</c> with <c>K = x^(m + 1) (c x^n)^(-(m + 1)/n)</c>, whose derivative
81158144
/// is 0 wherever it is defined. So the answer is <c>K/n</c> times the integral of
8116-
/// <c>e^((m + 1) t/n) G(t)</c> at <c>t = ln(c x^n)</c>, an antiderivative on the whole of
8117-
/// the real line where the integrand is real -- for an even <c>n</c> that includes negative
8118-
/// <c>x</c>, where <c>ln(c x^n)</c> is not <c>ln(c) + n ln(x)</c>. A power of a monomial,
8145+
/// <c>e^((m + 1) t/n) G(t)</c> at <c>t = ln(c x^n)</c>, an antiderivative wherever
8146+
/// <c>c x^n</c> is positive -- for an even <c>n</c> and a positive <c>c</c> the whole line,
8147+
/// negative <c>x</c> included, where <c>ln(c x^n)</c> is not <c>ln(c) + n ln(x)</c>. Where
8148+
/// <c>c x^n</c> is negative, <c>t</c> is <c>ln(-c x^n) + i pi</c>, and a function of whole
8149+
/// powers of <c>e^t</c>, <c>sqrt(sinh(2 t))</c> say, is real there as well; a radical one
8150+
/// has its integral in <c>t</c> found for a real <c>t</c>, under which <c>e^t</c> is
8151+
/// positive, so that answer is given <c>provided c x^n &gt; 0</c>. A power of a monomial,
81198152
/// <c>(e x)^p</c>, is <c>x^p</c> times a factor of the same kind. What by parts leaves of
81208153
/// <c>(e x)^m Si(d (a + b ln(c x^n)))</c> is this, with <c>G(t)</c> a sine over a linear in
81218154
/// <c>t</c>. Rubi's answers to 8.3 to 8.5 are written in exactly this <c>K</c>.
@@ -8172,7 +8205,14 @@ node is Logf(var @base, var argument) && !@base.ContainsNode(x) && @base != Math
81728205
var k = logarithms[0].Antilogarithm == x ? Number.Integer.One
81738206
: MathS.Pow(x, mPlusOne) * MathS.Pow(logarithms[0].Antilogarithm, (-mPlusOne / n).InnerSimplified);
81748207
var back = constant * locallyConstant * k / n * inTIntegral.Substitute(t, logarithms[0]);
8175-
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
8208+
if (back.Nodes.Any(node => node == MathS.NaN))
8209+
return null;
8210+
// Positive for every x other than 0 when n is even and c a positive number, and
8211+
// nothing to say then.
8212+
var positiveEverywhere = n.Evaled is Number.Integer whole && whole.EInteger.IsEven && c.Evaled is Number.Real { IsPositive: true };
8213+
return !positiveEverywhere && IsARadicalFunctionOfWholePowersOfTheExponential(inT, t)
8214+
? back.Provided(logarithms[0].Antilogarithm > Number.Integer.Zero)
8215+
: back;
81768216
}
81778217

81788218
/// <summary>

‎Sources/Tests/UnitTests/Calculus/LogarithmSubstitutionTest.cs‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
using System;
9+
using System.Linq;
910
using AngouriMath.Extensions;
1011
using Xunit;
1112

@@ -30,7 +31,9 @@ namespace AngouriMath.Tests.Calculus
3031
/// <para>
3132
/// The sample points are positive, which is where an integrand built from <c>ln(x)</c> is
3233
/// real: <c>u = ln(x)</c> is a bijection from the positive reals onto the whole line, so the
33-
/// answer holds wherever the integrand does and nothing further is assumed.
34+
/// answer holds wherever the integrand does and nothing further is assumed. A radical
35+
/// function of whole powers of <c>x</c> is real on both sides of zero, and is compared on
36+
/// both.
3437
/// </para>
3538
/// </remarks>
3639
[Trait("Area", "Calculus")]
@@ -115,6 +118,45 @@ public void ATrigonometricFunctionOfTheLogarithm(string integrand)
115118
[InlineData("ln(x) + x")]
116119
public void TheNeighboursAreUntouched(string integrand) => DifferentiatesBack(integrand);
117120

121+
/// <summary>
122+
/// A radical function of whole powers of <c>x</c> written through its logarithm, which is
123+
/// real on both sides of zero: <c>sinh(2 ln(x))</c> is <c>(x^2 - x^(-2))/2</c> for a
124+
/// negative <c>x</c> as well. Each answer is compared at three negative points and three
125+
/// positive ones, wherever it does not say it holds only elsewhere. Integrated under
126+
/// <c>t = ln(x)</c>, the first four say they hold where the logarithm's argument is
127+
/// positive; the last two are answered in powers of <c>x</c> and hold on both sides.
128+
/// Rubi's 6.5.3, 226, and 6.6.3, 188.
129+
/// </summary>
130+
[Theory]
131+
[InlineData("1/csch(2*ln(x))^(1/2)", false)]
132+
[InlineData("csch(2*ln(x))^(-3/2)", false)]
133+
[InlineData("1/csch(2*ln(13/10*x))^(1/2)", false)]
134+
[InlineData("1/sech(2*ln(x))^(1/2)", false)]
135+
[InlineData("sqrt(sinh(2*ln(x)))", true)]
136+
[InlineData("sqrt(cosh(2*ln(13/10*x)))", true)]
137+
public void ARadicalFunctionOfAWholePowerOfX(string integrand, bool onBothSides)
138+
{
139+
var integral = integrand.ToEntity().Integrate("x");
140+
Assert.DoesNotContain("integral(", integral.Stringize());
141+
var derivative = integral.Substitute("C", 0).Differentiate("x");
142+
var original = integrand.ToEntity();
143+
var conditions = integral.Nodes.OfType<Entity.Providedf>().Select(provided => provided.Predicate).ToList();
144+
foreach (var at in new[] { -2.7, -1.9, -1.3, 1.3, 1.9, 2.7 })
145+
{
146+
if (conditions.Any(condition => condition.Substitute("x", at).Evaled == Entity.Boolean.False))
147+
{
148+
Assert.False(onBothSides, $"the antiderivative of {integrand} says it does not hold at x = {at}");
149+
Assert.True(at < 0, $"the antiderivative of {integrand} says it does not hold at x = {at}");
150+
continue;
151+
}
152+
var got = derivative.Substitute("x", at).EvalNumerical();
153+
var want = original.Substitute("x", at).EvalNumerical();
154+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
155+
Assert.True(difference / Math.Max(1.0, Math.Abs((double)want.RealPart)) < 1e-9,
156+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
157+
}
158+
}
159+
118160
/// <summary>
119161
/// What the read must refuse: an <c>x</c> that survives the rewrite, so the integrand is
120162
/// not a function of the logarithm alone. <c>ln(x)*sin(x)</c> is the plain case, and

0 commit comments

Comments
 (0)