Skip to content

Commit 8a940c9

Browse files
A half-odd power of a constant over a polynomial of either sign is integrated with its sign (#1757)
sqrt(1/(1 - x^2)), the arcsine's derivative where it is real, was declined, with every half-odd power of a constant over a polynomial whose sign changes. For a real Q other than zero, (A/Q)^r is (A/Q)^r Q^r times Q^(-r), and the first factor's derivative is zero wherever it has one; for a positive number A and r half an odd number it is A^r sgn(Q). A half-odd power of a constant over a polynomial of degree four at most, not positive everywhere, among the factors of the integrand, is written so, the rest asked as the same question and the factor put in front of the answer. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent ce4d1a1 commit 8a940c9

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ Rubi's `x^m (a + b x^n)^p` and `(a + b x^n)^p (c + d x^n)^q`
264264
| `"1/(2+3/x^2)^3".Integrate("x")`, `1/(a + b/x^3)` | left unevaluated | an antiderivative |
265265
| `"(a+b*x^n)*(c+d*x^n)^3".Integrate("x")` | left unevaluated | written out, eight powers of `x` integrated: `a c^3 x + ... + b d^3 x^(4 n + 1)/(4 n + 1)` |
266266

267+
### A half-odd power of a constant over a polynomial of either sign is integrated with its sign
268+
269+
**Answers where there were none.** `sqrt(1/(1 - x^2))`, the arcsine's derivative where it is real,
270+
was declined, with every half-odd power of a constant over a polynomial whose sign changes: the
271+
reading that writes a power of a quotient apart does so only where the denominator is positive. For
272+
a real `Q` other than zero, `(A/Q)^r` is `(A/Q)^r Q^r` times `Q^(-r)`, the first factor's derivative
273+
being zero wherever it has one, and for a positive number `A` that factor is `A^r sgn(Q)`. The power
274+
is written so, after the substitutions, and the factor goes in front of the answer
275+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
276+
277+
| Input | Was (2.5.0) | Now |
278+
|---|---|---|
279+
| `"sqrt(1/(1 - x^2))".ToEntity().Integrate("x")` | `integral(...)` | `sgn(1 - x^2) arcsin(x)` |
280+
| `"(1/(1 - x^2))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `sgn(1 - x^2) x/sqrt(1 - x^2)` |
281+
| `"(c/(a + b*x^2))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `(c/(a + b x^2))^(3/2) (a + b x^2)^(3/2) x/(a sqrt(a + b x^2))` |
282+
267283
### A whole power of a quotient with a symbol in it is integrated as the quotient of the powers
268284

269285
**Answers where there were none, and a slowdown since 2.5.0 undone.** `(c/(a + c x^2))^2` was

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17034,6 +17034,44 @@ Entity Without(Entity side)
1703417034
return answer;
1703517035
}
1703617036

17037+
/// <summary>
17038+
/// A half-odd power of a constant over a polynomial whose sign changes, among the factors
17039+
/// of the integrand, written apart with the factor that keeps it right on both sides of the
17040+
/// polynomial's zeros: for a real <c>Q</c> other than zero, <c>(A/Q)^r</c> is
17041+
/// <c>K Q^(-r)</c> with <c>K = (A/Q)^r Q^r</c>, whose derivative is zero wherever it has one,
17042+
/// and for a positive number <c>A</c> that is <c>A^r</c> times the sign of <c>Q</c>, the
17043+
/// root of a negative being <c>i</c> times the root of its modulus on both sides of the bar.
17044+
/// </summary>
17045+
/// <remarks>
17046+
/// <c>sqrt(1/(1 - x^2))</c> is <c>sgn(1 - x^2)/sqrt(1 - x^2)</c>, the arcsine's derivative
17047+
/// where it is real, and was declined, with every such power over a polynomial that is not
17048+
/// positive: the reading that writes a power of a quotient apart does so only where it is.
17049+
/// Late in the chain, after the substitutions, which answer some of these without the
17050+
/// factor -- <c>x sqrt(1/(4 - x^2))</c> is <c>-(1/(4 - x^2))^(-1/2)</c> -- and asked as the
17051+
/// same question, as the sign taken out above is.
17052+
/// https://github.com/asc-community/AngouriMath/issues/718
17053+
/// </remarks>
17054+
internal static Entity? SolveByWritingAHalfOddPowerOfAReciprocalWithItsSign(Entity expr, Entity.Variable x, bool integrateByParts)
17055+
{
17056+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
17057+
{
17058+
if (underneath || factor is not Powf(var @base, Number.Rational exponent)
17059+
|| !exponent.ERational.Denominator.Equals(EInteger.FromInt32(2)) || !@base.ContainsNode(x))
17060+
continue;
17061+
var (above, below) = Functions.SingleQuotient.Of(@base);
17062+
if (below == Number.Integer.One || above.ContainsNode(x) || !below.ContainsNode(x)
17063+
|| !TreeAnalyzer.TryGetPolynomial(below, x, out var read) || read.Count == 0
17064+
|| read.Keys.Max()!.CompareTo(EInteger.FromInt32(4)) > 0 || IsPositiveForReal(below, x))
17065+
continue;
17066+
var positive = above.Evaled is Number.Real { IsPositive: true };
17067+
var inFront = positive ? MathS.Signum(below) : factor * MathS.Pow(below, exponent);
17068+
var replacement = positive ? MathS.Pow(above, exponent) * MathS.Pow(below, -exponent) : MathS.Pow(below, -exponent);
17069+
var written = expr.Replace(node => node == factor ? replacement : node);
17070+
return Integration.ComputeAsTheSameQuestion(written, x, integrateByParts) is { } answer ? inFront * answer : null;
17071+
}
17072+
return null;
17073+
}
17074+
1703717075
/// <summary>
1703817076
/// <c>x^(n - 1) g(x^n)</c> with a symbolic <c>n</c>, which is <c>g(u)/n</c> under
1703917077
/// <c>u = x^n</c>: the power in front is the derivative of the power inside up to the

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
11601160
// A rational function with symbols in it beside a root of a linear, split into partial
11611161
// fractions first, each term the question of one factor beside the root.
11621162
if ((answer = IndefiniteIntegralSolver.SolveARationalFunctionBesideARootOfALinearSplitFirst(expr, x, integrateByParts)) is { }) return answer;
1163+
// A half-odd power of a constant over a polynomial of either sign, written apart with
1164+
// its sign in front. After the substitutions, which answer some of these without it.
1165+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAHalfOddPowerOfAReciprocalWithItsSign(expr, x, integrateByParts)) is { }) return answer;
11631166
// The sign of a real-valued factor is constant between its zeros, and goes in
11641167
// front of the antiderivative of the rest. After every rule that reads the sign
11651168
// where it stands: `cos(x) sgn(sin(x))` is `|sin(x)|` by the substitution, and
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// A half-odd power of a constant over a polynomial whose sign changes, written apart with the
16+
/// factor that keeps it right on both sides of the polynomial's zeros: <c>(A/Q)^r</c> is
17+
/// <c>(A/Q)^r Q^r</c> times <c>Q^(-r)</c>, and for a positive number <c>A</c> that factor is
18+
/// <c>A^r sgn(Q)</c>. <c>sqrt(1/(1 - x^2))</c>, the arcsine's derivative where it is real, was
19+
/// declined.
20+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
21+
/// </summary>
22+
/// <remarks>
23+
/// Checked by differentiating back with <c>a = 2.3</c>, <c>b = -0.7</c>, <c>c = 1.3</c>, so that
24+
/// <c>a + b x^2</c> changes sign as well, at points on both sides of every denominator's zeros;
25+
/// where the denominator is negative the integrand is imaginary, and the two are compared as
26+
/// complex numbers.
27+
/// </remarks>
28+
[Trait("Area", "Calculus")]
29+
public sealed class HalfOddPowerOfAReciprocalIntegralTest
30+
{
31+
[Theory]
32+
[InlineData("sqrt(1/(1 - x^2))")]
33+
[InlineData("sqrt(1/(x^2 - 1))")]
34+
[InlineData("(1 - x^2)*sqrt(1/(2 - x^2))")]
35+
[InlineData("(1/(1 - x^2))^(3/2)")]
36+
[InlineData("(c/(a + b*x^2))^(3/2)")]
37+
[InlineData("x^2*(c/(a + b*x^2))^(3/2)")]
38+
public void IsWrittenApartWithItsSign(string integrand)
39+
{
40+
var integral = integrand.ToEntity().Integrate("x");
41+
Assert.DoesNotContain("integral(", integral.Stringize());
42+
Entity Pinned(Entity e) => e.Substitute("a", 2.3).Substitute("b", -0.7).Substitute("c", 1.3);
43+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
44+
var original = Pinned(integrand.ToEntity());
45+
foreach (var at in new[] { -2.4, -1.6, -0.6, 0.6, 1.6, 2.4 })
46+
{
47+
var want = original.Substitute("x", at).EvalNumerical();
48+
var got = derivative.Substitute("x", at).EvalNumerical();
49+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
50+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
51+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)