Skip to content

Commit bcb831d

Browse files
Take the arm off the real line for a quadratic with an even root of a symbol among its coefficients (#1987)
1/(b (c + d x)^2 + sqrt(-a)) was answered by arms on the sign of its discriminant 4 sqrt(-a) b d^2, which is imaginary for every a > 0 and has no sign there, so the answer had a value for no positive a. The arm off the real line that a quadratic with i among its coefficients takes, the arctangent, uses nothing about its root but sqrt(q)^2 = q; it is taken where an even root of a symbol is among the coefficients too. An odd root is real in this library, and a root seen only squared leaves the discriminant real, so neither takes it. Rubi's 1.3.1:131 is answered for either sign of a, and is the one row of a 2,944-row pocket whose verdict moves; 164 of 166 corpus rows with a root of a symbol in a coefficient answer as before, character for character. Part of #233. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 20c464f commit bcb831d

3 files changed

Lines changed: 100 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,21 @@ whatever `a` is ([#718](https://github.com/asc-community/AngouriMath/issues/718)
27602760
| `"sqrt(a + i*a*sinh(g + f*x))/x".ToEntity().Integrate("x")` | `integral(...)` | `Shi` and `Chi` of half of `f x` |
27612761
| `"1/sqrt(a + i*a*sinh(g + f*x))".ToEntity().Integrate("x")` | `integral(...)` | arctangents and logarithms of `e^((g + f x)/2)` |
27622762

2763+
### A quadratic with an even root of a symbol among its coefficients is integrated where the root is imaginary
2764+
2765+
**Answers where there were none.** `1/(b (c + d x)^2 + sqrt(-a))` was answered by arms on the sign
2766+
of its discriminant `4 sqrt(-a) b d^2`, which is imaginary for every `a > 0` and has no sign there,
2767+
so the answer had a value for no positive `a`. The arm off the real line that a quadratic with `i`
2768+
among its coefficients takes, the arctangent, which uses nothing about its root but
2769+
`sqrt(q)^2 = q`, is taken where an even root of a symbol is among them too. An odd root is real
2770+
here and a root seen only squared leaves the discriminant real, so neither takes it. Rubi's 1.3.1
2771+
([#233](https://github.com/asc-community/AngouriMath/issues/233)).
2772+
2773+
| Input | Was (2.5.0) | Now |
2774+
|---|---|---|
2775+
| `"1/(b*(c + d*x)^2 + sqrt(-a))".ToEntity().Integrate("x")` | 920 characters, with no value at a real `x` for `a = 1.07` or `a = -1.3`; 570, with none for `a > 0`, on the unreleased master | 608 characters, the arctangent `provided not D in RR or D > 0` |
2776+
| `"1/(x^2 + sqrt(a))".ToEntity().Integrate("x")` | 297 characters, with no value at a real `x` for `a = 1.07` or `a = -1.3`; 261, with none for `a < 0`, on the unreleased master | 286 characters |
2777+
27632778
### The arm for a quadratic off the real line excludes the arms on the sign of its discriminant
27642779

27652780
**Shorter answers.** An antiderivative over a quadratic with `i` among its coefficients has an arm

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ private static Entity IntegrateOverRootOfQuadratic(
819819
/// <summary>
820820
/// The arm that a piecewise on a sign owes a quadratic off the real line, answered by
821821
/// <paramref name="form"/> wherever one of <paramref name="coefficients"/> is not real;
822-
/// <see langword="null"/> where none of them holds the imaginary unit, and the sign arms
823-
/// are left to decide.
822+
/// <see langword="null"/> where none of them holds the imaginary unit or an even root of a
823+
/// symbol, and the sign arms are left to decide.
824824
/// </summary>
825825
/// <remarks>
826826
/// The sign arms choose between forms by which is real where the integrand is, and off
@@ -834,18 +834,43 @@ private static Entity IntegrateOverRootOfQuadratic(
834834
/// came back as minus its integrand below -2. The arctangent and the logarithm use nothing about their root but
835835
/// <c>sqrt(q)^2 = q</c>, and are antiderivatives off the real line as well.
836836
/// https://github.com/asc-community/AngouriMath/issues/1598
837+
/// <para>
838+
/// An even root of a symbol leaves the real line as the imaginary unit does, on half of the
839+
/// symbol's values: <c>1/(b (c + d x)^2 + sqrt(-a))</c> has the discriminant
840+
/// <c>4 sqrt(-a) b d^2</c>, imaginary for every <c>a &gt; 0</c>, and was answered with
841+
/// nothing there, an antiderivative of a function with one. Rubi's 1.3.1. An odd root is
842+
/// real here, <c>(-8)^(1/3) = -2</c>, and is left to the sign arms, and so is a root seen
843+
/// only squared: the discriminant of <c>a b - b^2 x^2 - x sqrt(b^2 - 4 a b^3)</c> holds
844+
/// <c>sqrt(b^2 - 4 a b^3)^2</c>, and is real.
845+
/// https://github.com/asc-community/AngouriMath/issues/233
846+
/// </para>
837847
/// </remarks>
838848
private static Entity.Providedf? ArmOffTheRealLine(Entity form, params Entity[] coefficients)
839849
{
840850
Entity? offTheRealLine = null;
841851
foreach (var coefficient in coefficients)
842-
if (coefficient.InnerSimplified.Nodes.Any(node => node is Entity.Number.Complex number && !number.ImaginaryPart.EDecimal.IsZero))
852+
{
853+
var simplified = coefficient.InnerSimplified;
854+
if (simplified.Nodes.Any(node => node is Entity.Number.Complex number && !number.ImaginaryPart.EDecimal.IsZero)
855+
|| AnEvenRootOfASymbolNotSquared(simplified))
843856
offTheRealLine = offTheRealLine is null
844857
? !coefficient.In(AngouriMath.Core.Domain.Real)
845858
: offTheRealLine | !coefficient.In(AngouriMath.Core.Domain.Real);
859+
}
846860
return offTheRealLine is null ? null : new Entity.Providedf(form, offTheRealLine);
847861
}
848862

863+
// An even root of something with a symbol in it, anywhere but as the base of an even power.
864+
private static bool AnEvenRootOfASymbolNotSquared(Entity expr) => expr switch
865+
{
866+
Entity.Powf(var root, Entity.Number.Integer { EInteger.IsEven: true }) when IsAnEvenRootOfASymbol(root) => false,
867+
_ when IsAnEvenRootOfASymbol(expr) => true,
868+
_ => expr.DirectChildren.Any(AnEvenRootOfASymbolNotSquared),
869+
};
870+
871+
private static bool IsAnEvenRootOfASymbol(Entity expr)
872+
=> expr is Entity.Powf(var radicand, Entity.Number.Rational { ERational.Denominator.IsEven: true }) && radicand.Vars.Any();
873+
849874
/// <summary>
850875
/// ∫ (px + q)/(ax^2 + bx + c) dx, by writing the numerator as a multiple of the
851876
/// denominator's derivative plus a constant:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 quadratic with an even root of a symbol among its coefficients is off the real line on
16+
/// half of that symbol's values, as one with <c>i</c> in it is, and takes the arm there:
17+
/// <c>1/(b (c + d x)^2 + sqrt(-a))</c> has the discriminant <c>4 sqrt(-a) b d^2</c>, which has no
18+
/// sign for <c>a &gt; 0</c>, and the answer had no value for any positive <c>a</c>. Rubi's 1.3.1.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/233">#233</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class AnEvenRootOfASymbolInAQuadraticIntegralTest
23+
{
24+
[Theory]
25+
[InlineData("1/(b*(c + d*x)^2 + sqrt(-a))", "1.3")]
26+
[InlineData("1/(b*(c + d*x)^2 + sqrt(-a))", "-1.3")]
27+
[InlineData("1/(x^2 + sqrt(a))", "1.3")]
28+
[InlineData("1/(x^2 + sqrt(a))", "-1.3")]
29+
[InlineData("x/(x^2 + x + sqrt(a))", "-1.3")]
30+
public void DifferentiatesBackOnEitherSideOfTheRoot(string integrand, string a)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
Assert.DoesNotContain("integral(", integral.Stringize());
34+
Entity Pinned(Entity e) => e.Substitute("a", a.ToEntity()).Substitute("b", 0.7).Substitute("c", 0.4).Substitute("d", 0.3);
35+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
36+
var original = Pinned(integrand.ToEntity());
37+
var compared = 0;
38+
foreach (var at in new[] { -1.7, -0.6, 0.3, 0.8, 1.3, 2.9 })
39+
{
40+
var want = original.Substitute("x", at).EvalNumerical();
41+
if (want.IsNaN)
42+
continue;
43+
var got = derivative.Substitute("x", at).EvalNumerical();
44+
compared++;
45+
var size = Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
46+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart) < 1e-9 * size,
47+
$"d/dx of the antiderivative of {integrand} at a = {a} is {got} at x = {at}, where the integrand is {want}");
48+
}
49+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand} at a = {a}");
50+
}
51+
52+
// An odd root is real here, (-8)^(1/3) = -2, and leaves the arms on the sign as they were.
53+
[Fact]
54+
public void AnOddRootTakesNoArmOffTheRealLine()
55+
=> Assert.DoesNotContain("in RR", "1/(x^2 + a^(1/3))".ToEntity().Integrate("x").Stringize());
56+
}
57+
}

0 commit comments

Comments
 (0)