Skip to content

Commit 23f272f

Browse files
An answer that read the sign of an even root says where the root is real (#1532)
The substitution search writes a sign or a modulus of u = t^(1/q), for an even q, as the root itself, which is so only where the root is real. Beyond the radicand's zero u is imaginary, and the integrand can still be real there, a product of two imaginary factors: (1 + sec(x))^(5/2) sqrt(cos(x)) under t = cos(x) and u = sqrt(t) had its power of a quotient taken apart as (1 + u^2)^(5/2)/|u|^5, and its answer was wrong wherever the cosine is negative. An answer that had a sign or a modulus of u now carries provided t >= 0, as the factoring below it already does. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5983248 commit 23f272f

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,22 @@ was ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
575575
| `"x * sqrt(c - a*c*x) / e^(3 * atanh(a*x))".Integrate("x")` | `integral(…)` — left unevaluated, with `e` evaluated to a hundred digits inside it | an antiderivative in `sqrt(c - a c x)`, `provided c - a * c * x >= 0` |
576576
| `"1/sqrt(x + x^(3/2))".Integrate("x")` | `integral(1 / sqrt(x + x ^ (3/2)), x)` — left unevaluated | `2 * sqrt(1 + sqrt(x)) / (1/2) + C provided x >= 0` |
577577

578+
### An answer that read the sign of an even root says where the root is real
579+
580+
The general substitution for an even root, `u = t^(1/q)`, writes a sign or a modulus of `u` that a
581+
rule below it put in as the root itself, `sgn(u) = 1` and `|u| = u`, which is so only where the
582+
root is real. Beyond the radicand's zero `u` is imaginary, and the integrand can still be real
583+
there, a product of two imaginary factors: `(1 + sec(x))^(5/2) sqrt(cos(x))` under `t = cos(x)` and
584+
`u = sqrt(t)` has its power of a quotient taken apart as `(1 + u^2)^(5/2)/|u|^5`, and its answer
585+
was not the integrand's antiderivative wherever the cosine is negative. An answer that had a sign
586+
or a modulus of `u` now carries `provided t >= 0`, as the entry above conditions the factoring.
587+
Rubi's 4.5.3.1:640 was wrong on that region
588+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
589+
590+
| Input | Was (2.5.0) | Now |
591+
|---|---|---|
592+
| `"(1+sec(x))^(5/2)*sqrt(cos(x))".Integrate("x")` | `integral((1 + sec(x)) ^ (5/2) * sqrt(cos(x)), x)` — left unevaluated | an antiderivative with `sgn(sin(x))` in it, `provided cos(x) >= 0` |
593+
578594
### A zero imaginary part is on the real axis, whatever its sign
579595

580596
**Silent, with the downcasting off.** A decimal's negative zero — `0E-100 * -0.43` is `-0E-102`

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18160,13 +18160,25 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1816018160
// -- is the root itself: `sqrt(x)/sqrt(x + x^2)` under `u = sqrt(x)` is
1816118161
// `2u^2/sqrt(u^2 + u^4)`, answered as `2 sgn(u) sqrt(1 + |u|^2)`, and
1816218162
// `sgn(sqrt(x))` is a sign nothing differentiates.
18163-
if (u is Powf(_, Number.Rational evenRoot) && evenRoot.ERational.Denominator.IsEven)
18164-
resultInU = resultInU.Replace(node => node switch
18163+
if (u is Powf(var rootOf, Number.Rational evenRoot) && evenRoot.ERational.Denominator.IsEven)
18164+
{
18165+
var asTheRoot = resultInU.Replace(node => node switch
1816518166
{
1816618167
Signumf(var argument) when argument == uSub => Number.Integer.One,
1816718168
Absf(var argument) when argument == uSub => uSub,
1816818169
_ => node,
1816918170
});
18171+
// Only where the root is real, though: the answer below read the sign of
18172+
// a real u, and where the radicand is negative u is imaginary while the
18173+
// integrand can still be real, a product of two imaginary factors.
18174+
// `(1 + sec(x))^(5/2) sqrt(cos(x))` under `t = cos(x)` and `u = sqrt(t)` is
18175+
// `-2 u^2 (1 + 1/u^2)^(5/2)/sqrt(1 - u^4)`, whose power of a quotient was
18176+
// taken apart as `(1 + u^2)^(5/2)/|u|^5`, and was answered wrongly
18177+
// wherever the cosine is negative. So the answer is conditioned on the
18178+
// radicand, as the factoring below conditions its own.
18179+
if (asTheRoot != resultInU)
18180+
return Functions.PartialFractions.Bare(asTheRoot).Substitute(uSub, u).Provided(rootOf >= Number.Integer.Zero);
18181+
}
1817018182
// Substitute back: replace u with g(x)
1817118183
return resultInU.Substitute(uSub, u);
1817218184
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,37 @@ public void TheEvenRootStepSaysWhereItHolds()
117117
Assert.True(derivative.Substitute("x", 0.59).Evaled.IsNaN, "the answer claims a derivative outside its condition");
118118
}
119119

120+
/// <summary>
121+
/// The substitution search's even root reads the sign of a real <c>u</c> as well, and
122+
/// says where it does: <c>(1 + sec(x))^(5/2) sqrt(cos(x))</c> under <c>t = cos(x)</c> and
123+
/// <c>u = sqrt(t)</c> is <c>-2 u^2 (1 + 1/u^2)^(5/2)/sqrt(1 - u^4)</c>, whose power of a
124+
/// quotient is taken apart as <c>(1 + u^2)^(5/2)/|u|^5</c>. Where the cosine is negative the
125+
/// integrand is still real, a product of two imaginary factors, and the answer built for a
126+
/// real <c>u</c> was not its antiderivative there. Rubi's 4.5.3.1.
127+
/// </summary>
128+
[Fact]
129+
public void TheSearchsEvenRootSaysWhereItHolds()
130+
{
131+
var integrand = "(1 + sec(x))^(5/2)*sqrt(cos(x))".ToEntity();
132+
var integral = integrand.Integrate("x");
133+
Assert.DoesNotContain("integral(", integral.Stringize());
134+
Assert.Contains("provided cos(x) >= 0", integral.Stringize());
135+
var derivative = integral.Substitute("C", 0).Differentiate("x");
136+
// Inside the condition the derivative is the integrand.
137+
foreach (var at in new[] { 0.3, 0.9, -0.7, 5.9 })
138+
{
139+
var got = derivative.Substitute("x", at).EvalNumerical();
140+
var want = integrand.Substitute("x", at).EvalNumerical();
141+
Assert.False(got.IsNaN, $"no answer at x = {at}, inside the condition");
142+
Assert.True(Math.Abs((double)(got - want).RealPart) < 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)),
143+
$"d/dx of the antiderivative is {got} at x = {at}, where the integrand is {want}");
144+
}
145+
// Beyond it the integrand is real and the answer claims nothing.
146+
var outside = integrand.Substitute("x", 2.8).EvalNumerical();
147+
Assert.True(Math.Abs((double)outside.ImaginaryPart) < 1e-12, $"the integrand at x = 2.8 is {outside}, not real");
148+
Assert.True(derivative.Substitute("x", 2.8).Evaled.IsNaN, "the answer claims a derivative outside its condition");
149+
}
150+
120151
/// <summary>
121152
/// A polynomial over a square root of something linear. None of these had an
122153
/// antiderivative, and each is a first-year exercise.

0 commit comments

Comments
 (0)