Skip to content

Commit 836ca93

Browse files
A power of the variable below the bar beside a root of a quadratic (#1476)
`1/(x^2 sqrt(4 + 3x + 2x^2))` was left as written while `1/(x sqrt(...))` came out: the single factor was read and the repeated one was not, and the repeated one is what a round of parts against `arccos(a + b x)/x^4` leaves. Under `x = 1/t` the integrand is `-sgn(t) t^(n - 1)/sqrt(q0 t^2 + q1 t + q2)`, a polynomial over the root of the quadratic read the other way round, which the rules for those answer. The radicand is assembled rather than substituted into -- `Q(1/t)` is `R(t)/t^2`, and writing the quotient inside the root leaves a nesting nothing downstream reduces -- and the modulus that leaves is a `sgn(t)` in front, which at `t = 1/x` is `sgn(x)`. The reciprocal's own `t != 0` is stripped before the integrand is handed on: it says what the integrand already says, and a condition is not an integrand to the rules below, which declined it. `SolveByReciprocalSubstitution` is this substitution for a different shape, a palindromic quartic under the root, and reads nothing here. Family 5 of the Rubi suite: 211 -> 212 of 257, family 1 155 -> 156 of 228, 0 wrong; the 1774-problem suite 1707 unchanged. Suite 12662 passed; allocation gate passed on all 19 gated benchmarks. Six forms differentiate back at five points, with and without symbols among the coefficients. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f46d55f commit 836ca93

4 files changed

Lines changed: 158 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,26 @@ keeps its decline ([#718](https://github.com/asc-community/AngouriMath/issues/71
12121212
| `"tan(x)/sqrt(2+tan(x)+tan(x)^2)".Integrate("x")` | left unevaluated | the antiderivative |
12131213
| `"tan(x)^2/(2+tan(x)+tan(x)^2)^(3/2)".Integrate("x")` | left unevaluated | the antiderivative |
12141214

1215+
### A power of the variable below the bar beside a root of a quadratic
1216+
1217+
`1/(x^2 sqrt(4 + 3x + 2x^2))` was left as written, while `1/(x sqrt(...))` came out: the single
1218+
factor was read and the repeated one was not. Under `x = 1/t` the integrand is
1219+
`-sgn(t) t^(n - 1)/sqrt(q0 t^2 + q1 t + q2)` -- a polynomial over the root of the quadratic read
1220+
the other way round, which the rules for those answer. That is what one round of parts against
1221+
`arccos(a + b x)/x^4` leaves, so the inverse trigonometric rows over a power of `x` come with it.
1222+
1223+
The radicand is assembled rather than substituted into, as `Q(1/t)` is `R(t)/t^2` and writing the
1224+
quotient inside the root leaves a nesting nothing reduces; the modulus that leaves is a `sgn(t)`
1225+
in front, which at `t = 1/x` is `sgn(x)`. `SolveByReciprocalSubstitution` is the same substitution
1226+
for a different shape -- a palindromic quartic, where the reciprocal maps the quartic to itself --
1227+
and reads nothing here ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
1228+
1229+
| Input | Was (2.5.0) | Now |
1230+
|---|---|---|
1231+
| `"1/(x^3*sqrt(4+3*x+2*x^2))".Integrate("x")` | left unevaluated | the antiderivative |
1232+
| `"1/(x^2*sqrt(1-(a+b*x)^2))".Integrate("x")` | left unevaluated | the antiderivative |
1233+
| `"acos(a+b*x)/x^4".Integrate("x")` | left unevaluated | the antiderivative |
1234+
12151235
### `binomial(n, k)` is a function
12161236

12171237
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

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

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14431,6 +14431,112 @@ private static (Entity Factor, Entity Inside)? TryTakeACommonLinearFactorOfASum(
1443114431
return shifted.Nodes.Any(node => node == MathS.NaN) ? null : shifted;
1443214432
}
1443314433

14434+
/// <summary>
14435+
/// A power of the variable below the bar beside a root of a quadratic, by
14436+
/// <c>x = 1/t</c>: <c>1/(x^n sqrt(q0 + q1 x + q2 x^2))</c> is
14437+
/// <c>-sgn(t) t^(n - 1)/sqrt(q0 t^2 + q1 t + q2)</c>, a polynomial over the root of the
14438+
/// quadratic with its coefficients reversed, which the rules for those answer.
14439+
/// </summary>
14440+
/// <remarks>
14441+
/// <para>
14442+
/// <c>1/(x sqrt(1 - (a + b x)^2))</c> was answered and <c>1/(x^2 sqrt(...))</c> was not:
14443+
/// the repeated factor is what nothing reads, and it is what a round of parts against
14444+
/// <c>acos(a + b x)/x^4</c> leaves. <see cref="SolveByReciprocalSubstitution"/> is the
14445+
/// same substitution for a different shape -- a palindromic quartic under the root, where
14446+
/// the reciprocal maps the quartic to itself -- and reads nothing here.
14447+
/// </para>
14448+
/// <para>
14449+
/// The radicand is assembled rather than substituted into: <c>Q(1/t)</c> is
14450+
/// <c>R(t)/t^2</c> with <c>R</c> the reversed quadratic, so the root is
14451+
/// <c>R^(p/2) |t|^(-p)</c>, and writing the quotient inside the root instead leaves a
14452+
/// nesting nothing downstream reduces. The modulus is a <c>sgn(t)</c> in front for an odd
14453+
/// <c>p</c>, constant between its zeros; with <c>t = 1/x</c> it is <c>sgn(x)</c>, which is
14454+
/// what the answers of this family carry anyway.
14455+
/// https://github.com/asc-community/AngouriMath/issues/718
14456+
/// </para>
14457+
/// </remarks>
14458+
internal static Entity? SolveByTheReciprocalBesideARootOfAQuadratic(Entity expr, Entity.Variable x, bool integrateByParts)
14459+
{
14460+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
14461+
return null;
14462+
var (numerator, denominator) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr));
14463+
// A power of x, two or more, below the bar; one root of a quadratic; polynomials else.
14464+
var powerOfX = 0;
14465+
Entity? radicand = null;
14466+
Number.Rational? rootPower = null;
14467+
Entity rest = Number.Integer.One;
14468+
foreach (var (side, isBelow) in new[] { (numerator, false), (denominator, true) })
14469+
foreach (var factor in Mulf.LinearChildren(side))
14470+
{
14471+
if (!factor.ContainsNode(x))
14472+
{
14473+
rest = isBelow ? rest / factor : rest * factor;
14474+
continue;
14475+
}
14476+
switch (factor)
14477+
{
14478+
case Variable bare when bare == x && isBelow:
14479+
powerOfX += 1;
14480+
continue;
14481+
case Powf(Variable bare, Number.Integer whole) when bare == x && isBelow && whole.EInteger.Sign > 0 && whole.EInteger.CanFitInInt32():
14482+
powerOfX += whole.EInteger.ToInt32Unchecked();
14483+
continue;
14484+
case Powf(var inner, Number.Rational power) when power is not Number.Integer && radicand is null:
14485+
if (!power.ERational.Denominator.Equals(EInteger.FromInt32(2)))
14486+
return null;
14487+
radicand = inner;
14488+
rootPower = isBelow ? Number.Rational.Create(power.ERational.Negate()) : power;
14489+
continue;
14490+
default:
14491+
if (!TreeAnalyzer.TryGetPolynomial(factor, x, out _))
14492+
return null;
14493+
rest = isBelow ? rest / factor : rest * factor;
14494+
continue;
14495+
}
14496+
}
14497+
if (powerOfX < 2 || radicand is null || rootPower is null)
14498+
return null;
14499+
if (!TreeAnalyzer.TryGetPolynomial(radicand, x, out var monomials) || monomials.Count == 0
14500+
|| monomials.Keys.Any(k => k.Sign < 0 || k.CompareTo(EInteger.FromInt32(2)) > 0)
14501+
|| !monomials.ContainsKey(EInteger.FromInt32(2)))
14502+
return null;
14503+
if (!TreeAnalyzer.TryGetPolynomial(rest, x, out var restMonomials) || restMonomials.Keys.Any(k => k.Sign < 0))
14504+
return null;
14505+
14506+
var t = Variable.CreateUnique(expr, "u_recip");
14507+
// Q(1/t) is R(t)/t^2 with R the quadratic read the other way round.
14508+
var q0 = monomials.TryGetValue(EInteger.Zero, out var m0) ? m0 : Number.Integer.Zero;
14509+
var q1 = monomials.TryGetValue(EInteger.One, out var m1) ? m1 : Number.Integer.Zero;
14510+
var q2 = monomials[EInteger.FromInt32(2)];
14511+
var reversed = (q0 * MathS.Sqr(t) + q1 * t + q2).InnerSimplified;
14512+
if (q0.Evaled is Number.Complex { IsZero: true })
14513+
return null; // the reversed quadratic is linear, which is the substitution's own shape
14514+
// The rest at 1/t, term by term, so that no quotient is left nested.
14515+
Entity restInT = Number.Integer.Zero;
14516+
foreach (var pair in restMonomials)
14517+
{
14518+
if (!pair.Key.CanFitInInt32())
14519+
return null;
14520+
var degree = pair.Key.ToInt32Unchecked();
14521+
restInT += degree == 0 ? pair.Value : pair.Value / MathS.Pow(t, Number.Integer.Create(degree));
14522+
}
14523+
// dx = -dt/t^2, x^(-n) = t^n, and the root is R^(p/2) |t|^(-p).
14524+
var numeratorPower = Number.Integer.Create(rootPower.ERational.Numerator);
14525+
Entity integrand = -restInT * MathS.Pow(t, Number.Integer.Create(powerOfX - 2))
14526+
* MathS.Pow(reversed, rootPower) * MathS.Pow(t, (-numeratorPower).InnerSimplified);
14527+
Entity signs = numeratorPower.EInteger.IsEven ? Number.Integer.One : MathS.Signum(t);
14528+
// Bare: the reciprocal's own `t != 0` rides along as a condition -- it is `1/x`, so
14529+
// it says what the integrand already says -- and a condition is not an integrand to
14530+
// the rules below, which decline it.
14531+
integrand = Functions.PartialFractions.Bare(integrand.InnerSimplified);
14532+
if (integrand.ContainsNode(x) || integrand.Nodes.Any(node => node == MathS.NaN))
14533+
return null;
14534+
if (Integration.ComputeAsAQuestionOfItsOwn(integrand, t, integrateByParts) is not { } answer)
14535+
return null;
14536+
var back = (signs == Number.Integer.One ? answer : signs * answer).Substitute(t, (Number.Integer.One / x).InnerSimplified);
14537+
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
14538+
}
14539+
1443414540
/// <summary>
1443514541
/// A pair of hyperbolic powers two apart whose coefficients kill the reduction's
1443614542
/// residual: <c>cosh(y)^p - (p - 1)/p cosh(y)^(p - 2)</c> is

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,10 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
799799
// And a root of a palindromic quartic, which is a root of a quadratic in x -+ 1/x:
800800
// Charlwood's `(1 + x^2)/((1 - x^2) sqrt(1 + x^4))` is `-du/(u sqrt(u^2 + 2))`.
801801
if ((answer = IndefiniteIntegralSolver.SolveByReciprocalSubstitution(expr, x)) is { }) return answer;
802+
// And a power of the variable below the bar beside a root of a quadratic, by the
803+
// same reciprocal: `1/(x^2 sqrt(Q))` is a polynomial over the root of the reversed
804+
// quadratic, which the rules for those answer.
805+
if ((answer = IndefiniteIntegralSolver.SolveByTheReciprocalBesideARootOfAQuadratic(expr, x, integrateByParts)) is { }) return answer;
802806
// A rational function of x and one cube root of a polynomial: no substitution
803807
// rationalises it, and the elementary ones are logarithms of `L - y` for linear L
804808
// whose cube agrees with the polynomial at the poles, found by an ansatz.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,33 @@ public void WhatIsNotAFunctionOfTheReciprocalVariable(string integrand)
142142
return; // unanswered is a legitimate verdict; a wrong answer is not
143143
DifferentiatesBack(integrand);
144144
}
145+
146+
/// <summary>
147+
/// A power of the variable below the bar beside a root of a quadratic, by the same
148+
/// reciprocal: <c>1/(x^n sqrt(q0 + q1 x + q2 x^2))</c> is
149+
/// <c>-sgn(t) t^(n - 1)/sqrt(q0 t^2 + q1 t + q2)</c>, a polynomial over the root of the
150+
/// quadratic read the other way round. <c>1/(x sqrt(1 - (a + b x)^2))</c> was answered
151+
/// and the repeated factor was not, which is what a round of parts against
152+
/// <c>acos(a + b x)/x^4</c> leaves.
153+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
154+
/// </summary>
155+
[Theory]
156+
[InlineData("1/(x^2*sqrt(1 + x^2))")]
157+
[InlineData("1/(x^3*sqrt(4 + 3*x + 2*x^2))")]
158+
[InlineData("1/(x^2*sqrt(1 + x + x^2))")]
159+
[InlineData("1/(x^4*sqrt(2 - x + x^2))")]
160+
public void APowerOfTheVariableBesideARootOfAQuadratic(string integrand) => DifferentiatesBack(integrand);
161+
162+
/// <summary>
163+
/// And with symbols among the coefficients, which is the shape Rubi's 5.2 rows leave:
164+
/// <c>acos(a + b x)/x^4</c> by parts is <c>1/(x^3 sqrt(1 - (a + b x)^2))</c> up to the
165+
/// constants.
166+
/// </summary>
167+
[Theory]
168+
[InlineData("1/(x^2*sqrt(1 - (a + b*x)^2))")]
169+
[InlineData("1/(x^3*sqrt(1 - (a + b*x)^2))")]
170+
[InlineData("acos(a + b*x)/x^4")]
171+
public void TheSameWithSymbolicCoefficients(string integrand)
172+
=> DifferentiatesBack(integrand, ("a", 0.3), ("b", 0.4));
145173
}
146174
}

0 commit comments

Comments
 (0)