Skip to content

Commit a8a2b7e

Browse files
A root the substitution search would write through i is kept, and the cube is answered too (#1552)
* A substitution that brings in the imaginary unit is passed over Under a candidate `u`, the substitution search simplifies the rewritten integrand one level, and that writes `sqrt(-u)` as `i sqrt(u)`: the other root wherever u is negative. `sqrt(a + b sech(x)) tanh(x)^5` meets it with `u = tanh(x)^2 - 1`, negative everywhere, and was answered through `i`, off at every real point, and then declined by the tangent substitution's check. A candidate whose integrand holds the imaginary unit where the integrand did not is now passed over, and the search goes on to one under which the root stays real. The cube, `sqrt(a + b sech(x)) tanh(x)^3`, is still declined, as on master, and is left for a follow-up. Measured against master 40b7e58, together with the other two fixes opened beside it: a sample of families 1 to 7 (912 problems) 764 solved on both, row for row, and family 0 1750/1814 on both, 0 wrong. Part of #1370. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * A candidate's integrand keeps its root where simplifying would write it through i The cube, `sqrt(a + b sech(x)) tanh(x)^3`, was still declined. Under `u = tanh(x)^2 - 1` the one-level simplification of its integrand in u went one step further than the fifth power's, from `sqrt(-u)` to `i sqrt(u)`, so the candidate was passed over, where the fifth power's kept `sqrt(-u)` and was answered through it. Each one-level simplification of a candidate's integrand now keeps the integrand as written where the simplified one would hold the imaginary unit and neither the written one nor the integrand in x does. Both powers are answered and differentiate back. Closes #1370. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 882c1eb commit a8a2b7e

3 files changed

Lines changed: 57 additions & 16 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,21 @@ is `sqrt(b + a u^2)/|u|`, and `|u|^k` for the bare square is `sgn(u) u^k` at eve
12681268
| `"coth(x)/(a+b*coth(x)^2)^(3/2)".Integrate("x")` | left unevaluated | the antiderivative |
12691269
| `"(a+b*coth(x)^2)^(3/2)*tanh(x)^2".Integrate("x")` | left unevaluated | the antiderivative |
12701270

1271+
### A substitution that would write a root of a negated quantity through `i` keeps the root
1272+
1273+
`sqrt(a + b sech(x)) tanh(x)^5` ran past two minutes. Under `u = tanh(x)` a substitution the
1274+
search tried wrote `sqrt(1 - u^2)`, simplified one level, as `i sqrt(u^2 - 1)`: that is the other
1275+
root wherever `u^2 < 1`, which is everywhere `tanh` goes, and the answer's derivative was off at
1276+
every real point. The search now keeps a candidate's integrand as written where simplifying it
1277+
would bring in the imaginary unit, and passes over a candidate whose integrand holds it all the
1278+
same. With the root as it was, the cube is answered too
1279+
([#1370](https://github.com/asc-community/AngouriMath/issues/1370)).
1280+
1281+
| Input | Was (2.5.0) | Now |
1282+
|---|---|---|
1283+
| `"sqrt(a+b*sech(x))*tanh(x)^5".Integrate("x")` | ran past two minutes | the antiderivative, in `sqrt(a + b sqrt(1 - tanh(x)^2))`, written in exponentials |
1284+
| `"sqrt(a+b*sech(x))*tanh(x)^3".Integrate("x")` | ran past five minutes | the antiderivative, the same way |
1285+
12711286
### A rational function of the hyperbolic functions odd in the sine or the cosine is integrated by the other
12721287

12731288
`sinh(x)^3/(a + b cosh(x)^2)` was a search past the budget: under `u = e^x` it is a rational

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18278,6 +18278,28 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1827818278
_ => null
1827918279
};
1828018280

18281+
/// <summary>Whether a number with an imaginary part is written in <paramref name="expr"/>.</summary>
18282+
private static bool HoldsTheImaginaryUnit(Entity expr)
18283+
=> expr.Nodes.Any(node => node is Number.Complex number && !number.ImaginaryPart.EDecimal.IsZero);
18284+
18285+
/// <summary>
18286+
/// A candidate's integrand in its variable simplified one level, or as it is written where
18287+
/// that would bring in the imaginary unit which neither it nor <paramref name="integrand"/>
18288+
/// holds. The one level writes <c>sqrt(-u)</c> as <c>i sqrt(u)</c>, the other root wherever
18289+
/// <c>u</c> is negative, and a candidate is negative on the whole line as often as not:
18290+
/// <c>tanh(x)^2 - 1</c> is, and <c>sqrt(a + b sech(x)) tanh(x)^3</c> under it was
18291+
/// <c>sqrt(a + i b sqrt(u))</c>, where the root written as it was is answered by the
18292+
/// search in <c>u</c>. https://github.com/asc-community/AngouriMath/issues/1370
18293+
/// </summary>
18294+
private static Entity SimplifiedWithoutTheImaginaryUnit(Entity written, Entity integrand)
18295+
{
18296+
var simplified = written.Simplify(1);
18297+
if (simplified is Providedf(var inner, _)) simplified = inner; // TODO: singularities ignored but not handled properly
18298+
return HoldsTheImaginaryUnit(simplified) && !HoldsTheImaginaryUnit(written) && !HoldsTheImaginaryUnit(integrand)
18299+
? written
18300+
: simplified;
18301+
}
18302+
1828118303
/// <summary>
1828218304
/// Attempts to solve an integral using u-substitution.
1828318305
/// Looks for patterns where f(g(x)) * g'(x) can be integrated as F(g(x)).
@@ -18394,8 +18416,7 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1839418416
var complemented = WithTheComplementInEvenPowers(firstPass[u], u, uSub);
1839518417
if (complemented == firstPass[u])
1839618418
continue; // nothing the first pass did not see
18397-
integrandInU = complemented.Simplify(1);
18398-
if (integrandInU is Providedf(var innerComplemented, _)) integrandInU = innerComplemented;
18419+
integrandInU = SimplifiedWithoutTheImaginaryUnit(complemented, expr);
1839918420
}
1840018421
else
1840118422
{
@@ -18434,8 +18455,7 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1843418455
&& expr.Complexity <= (expr.Vars.Any(v => v != x) ? LargestSymbolicIntegrandCollected : LargestIntegrandOfferedSums)
1843518456
? WithThePowersOfXCollected(Functions.SingleQuotient.Combine(expr / duDx), x)
1843618457
: source / duDx;
18437-
integrandInU = InTermsOf(quotient, u, uSub, x).Simplify(1);
18438-
if (integrandInU is Providedf(var innerExpr, _)) integrandInU = innerExpr; // TODO: singularities ignored but not handled properly
18458+
integrandInU = SimplifiedWithoutTheImaginaryUnit(InTermsOf(quotient, u, uSub, x), expr);
1843918459
// A factor written on both sides of the bar cancelled, where x survived:
1844018460
// the one-level simplification leaves `u/((a w + b)^2 p u)` as it is, and
1844118461
// the candidate was refused for the u it did not cancel.
@@ -18445,8 +18465,7 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1844518465
var cancelled = CancelCommonFactors(top, bottom);
1844618466
if (cancelled != integrandInU && !cancelled.ContainsNode(x))
1844718467
{
18448-
integrandInU = cancelled.Simplify(1);
18449-
if (integrandInU is Providedf(var innerCancelled, _)) integrandInU = innerCancelled;
18468+
integrandInU = SimplifiedWithoutTheImaginaryUnit(cancelled, expr);
1845018469
}
1845118470
}
1845218471
// A polynomial in x left over under a candidate that is itself a polynomial
@@ -18467,8 +18486,7 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1846718486
var inTheCandidate = WithPolynomialsInTheCandidate(aboveTheBar, u, uSub, x) / WithPolynomialsInTheCandidate(belowTheBar, u, uSub, x);
1846818487
if (inTheCandidate.ContainsNode(x) == false || inTheCandidate != aboveTheBar / belowTheBar)
1846918488
{
18470-
integrandInU = inTheCandidate.Simplify(1);
18471-
if (integrandInU is Providedf(var innerInTheCandidate, _)) integrandInU = innerInTheCandidate;
18489+
integrandInU = SimplifiedWithoutTheImaginaryUnit(inTheCandidate, expr);
1847218490
}
1847318491
}
1847418492
if (u is Sinf or Cosf && integrandInU.ContainsNode(x))
@@ -18487,6 +18505,13 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1848718505
// NaN * (sin(x)^2 + cos(x)^2).
1848818506
if (integrandInU.Nodes.Any(node => node == MathS.NaN))
1848918507
continue;
18508+
// And a candidate whose integrand holds the imaginary unit where the integrand did
18509+
// not is not taken, whichever step wrote it: `i sqrt(u)` for `sqrt(-u)` is the other
18510+
// root wherever u is negative -- as `tanh(x)^2 - 1` is everywhere, which is how
18511+
// `sqrt(a + b sech(x)) tanh(x)^5` was answered through `i` and was off at every
18512+
// real point. https://github.com/asc-community/AngouriMath/issues/1370
18513+
if (HoldsTheImaginaryUnit(integrandInU) && !HoldsTheImaginaryUnit(expr))
18514+
continue;
1849018515

1849118516
if (integrandInU.ContainsNode(x))
1849218517
continue;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,19 +521,20 @@ public void ACubedSymbolicQuadraticBesideARealQuadraticIsNotAnsweredWrongly(stri
521521

522522
/// <summary>
523523
/// A root of <c>a + b sech(x)</c> beside an odd power of the tangent was integrated
524-
/// through <c>i</c>: the substitution took a root of a negative radicand on the way
525-
/// and the answer's derivative was off at every real point. Declined or right now,
526-
/// as the tangent substitution checks its answer at sampled points where a symbol is
527-
/// involved. https://github.com/asc-community/AngouriMath/issues/1370
524+
/// through <c>i</c>: under <c>u = tanh(x)^2 - 1</c> the one-level simplification wrote
525+
/// <c>sqrt(-u)</c> as <c>i sqrt(u)</c>, the other root for the negative u there, and the
526+
/// answer's derivative was off at every real point. The search keeps a candidate's
527+
/// integrand as written where simplifying it would bring in <c>i</c>, and with the root
528+
/// as it was both are answered: the cube had been declined, since its simplification
529+
/// went one step further than the fifth power's.
530+
/// https://github.com/asc-community/AngouriMath/issues/1370
528531
/// </summary>
529532
[Theory]
530533
[InlineData("sqrt(a + b*sech(x))*tanh(x)^5")]
531534
[InlineData("sqrt(a + b*sech(x))*tanh(x)^3")]
532-
public void ARootOfTheSecantBesideAnOddTangentIsNotAnsweredWrongly(string integrand)
535+
public void ARootOfTheSecantBesideAnOddPowerOfTheTangentIsAnswered(string integrand)
533536
{
534-
var integral = integrand.ToEntity().Integrate("x");
535-
if (integral.Stringize().Contains("integral("))
536-
return;
537+
Assert.DoesNotContain("integral(", integrand.ToEntity().Integrate("x").Stringize());
537538
DifferentiatesBackWithParametersPinned(integrand, new[] { -0.7, 0.23, 0.61, 1.05, 1.7 });
538539
}
539540

0 commit comments

Comments
 (0)