Skip to content

Commit 01a944f

Browse files
Powers of asech(a x) and acsch(a x) beside a power of x are integrated, by rounds of parts (#1460)
x^3 asech(a x)^2 was left as written. One step of parts leaves x^2 asech(a x)/sqrt(1/(a x)^2 - 1), and five things stood between that and the next step, each traced and fixed in its place: - The regrouping of parts around the differentiated factor is offered up to two levels below the question asked where everything beside the factor is algebraic with a root in it: the other factor integrates to an algebraic expression or declines at once, and the remainder is algebraic. With a root only, since beside a rational function the rule for a rational function times a logarithm answers, and parts there sent (a + b atanh(c x^2))^2/x^5 into a search that did not return. - SolveByWritingAPowerOfAQuotientApart runs at any depth where every root stands over a monomial with a polynomial above it -- sqrt(1/(a x)^2 - 1) as the derivative of asech writes it -- and answers with sgn(x)^m in front rather than by parity, where the answer in |x| was a remainder no rule read when handed on. The sign goes in front only where every power of |x| taken came from a root that is a factor of the integrand. - SolveByTakingASignOut: the sign of a real-valued factor is constant between its zeros and goes in front of the antiderivative of the rest; after every rule that reads the sign where it stands, so cos(x) sgn(sin(x)) is still |sin(x)|. - A radicand written in two orders is one spelling where it stands in two places that differ in the sign of the power or the side of the bar. - A whole power of a fractional power is normalised to the power it is: ((c^2 x^2 + 1)^(-1/2))^2 handed to Euler's substitution as a radical beside (c^2 x^2 + 1)^(-1) answered the remainder of acsch(c x)^2/x^4 wrongly, and the corpus caught it as its one wrong answer. Rubi's family 7: 210 to 215 of 270, 0 wrong, 0 error, timeouts 26 to 30 (the same rows, over the budget under the load of the new answers); the 1774-problem suite unchanged at 1707, 0 wrong, 0 timeout, wall 85 s. Suite 12552 passed; the kernel gate passed on all 19 gated benchmarks. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 67a89b6 commit 01a944f

4 files changed

Lines changed: 176 additions & 10 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,25 @@ every rule ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
957957
| `"e^(2*asech(a*x))/x^2".Integrate("x")` | left unevaluated | the antiderivative, in `sgn(x)` |
958958
| `"x*(a+b*asech(c*x))/(d+pe*x^2)^2".Integrate("x")` | left unevaluated | the antiderivative |
959959

960+
### Powers of `asech(a x)` and `acsch(a x)` beside a power of `x` are integrated, by rounds of parts
961+
962+
`x^3 asech(a x)^2` was left as written. One step of parts leaves `x^2 asech(a x)/sqrt(1/(a x)^2 - 1)`,
963+
and the step on that -- asked two levels below the question -- is now offered where everything
964+
beside the differentiated factor is algebraic with a root in it; the root over a monomial is
965+
written apart at any depth; a sign of a real-valued factor is constant between its zeros and
966+
goes in front of the antiderivative of the rest; and a root written apart with `|x|` answers
967+
with `sgn(x)` in front rather than in `|x|`, which a further step could not read. A square of
968+
a root is normalised to the power it is, which is what stopped Euler's substitution answering
969+
the remainder of `acsch(c x)^2/x^4` wrongly along the way
970+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
971+
972+
| Input | Was (2.5.0) | Now |
973+
|---|---|---|
974+
| `"x^3*asech(a*x)^2".Integrate("x")` | left unevaluated | the antiderivative, `provided a^2 > 0` |
975+
| `"asech(a*x)^3/x^2".Integrate("x")` | left unevaluated | the antiderivative |
976+
| `"(a+b*acsch(c*x))^2/x^4".Integrate("x")` | left unevaluated | the antiderivative |
977+
| `"x^2/sqrt(1/(a^2*x^2)-1)".Integrate("x")` | left unevaluated | `sgn(x) |a| (2 (1 - a^2 x^2)^(3/2)/3 - 2 sqrt(1 - a^2 x^2))/(2 a^4)` up to the form -- with `sgn(x)` in front, where an answer written in `|x|` used to be given for such shapes |
978+
960979
### `binomial(n, k)` is a function
961980

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

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

Lines changed: 125 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,22 @@ private static (Entity Numerator, Entity Denominator) CancelledWithFunctionsAsIn
408408
// Timofeev's 314 down a path whose answer could not be checked, where the two
409409
// roots apart are split over `(1 - x)(1 + x)` and answered.
410410
string Spelling(Entity radicand) => string.Join(" + ", Sumf.LinearChildren(radicand).Select(term => term.ToString()).OrderBy(term => term, System.StringComparer.Ordinal));
411-
var signsOfSpelling = new Dictionary<string, (bool Negative, bool Positive, Entity First)>();
412-
foreach (var node in numerator.Nodes.Concat(denominator.Nodes))
411+
// Where the radicand stands in two places that differ in the sign of the power as
412+
// written or in the side of the bar -- `q^(-1/2)` above beside `sqrt(q)` below,
413+
// which the joining below reads as one atom, or `sqrt(A)` above beside `sqrt(A)`
414+
// below, which cancel -- and only there.
415+
var placesOfSpelling = new Dictionary<string, (HashSet<(bool Negative, bool Underneath)> Places, Entity First)>();
416+
foreach (var (node, underneath) in numerator.Nodes.Select(n => (n, false)).Concat(denominator.Nodes.Select(n => (n, true))))
413417
if (node is Powf(var radicand, Number.Rational r) && r is not Number.Integer && radicand.ContainsNode(x) && radicand is Sumf or Minusf)
414418
{
415419
var key = Spelling(radicand);
416-
var (negative, positive, first) = signsOfSpelling.TryGetValue(key, out var so) ? so : (false, false, radicand);
417-
signsOfSpelling[key] = (negative || r.ERational.IsNegative, positive || !r.ERational.IsNegative, first);
420+
if (!placesOfSpelling.TryGetValue(key, out var seen))
421+
placesOfSpelling[key] = seen = (new HashSet<(bool, bool)>(), radicand);
422+
seen.Places.Add((r.ERational.IsNegative, underneath));
418423
}
419424
Entity OneSpelling(Entity side) => side.Replace(node =>
420425
node is Powf(var radicand, Number.Rational r) && r is not Number.Integer && radicand.ContainsNode(x) && radicand is Sumf or Minusf
421-
&& signsOfSpelling.TryGetValue(Spelling(radicand), out var seen) && seen.Negative && seen.Positive && seen.First != radicand
426+
&& placesOfSpelling.TryGetValue(Spelling(radicand), out var seen) && seen.Places.Count > 1 && seen.First != radicand
422427
? MathS.Pow(seen.First, r)
423428
: node);
424429
numerator = OneSpelling(numerator);
@@ -1864,7 +1869,16 @@ bool IsAnExponential(Entity factor)
18641869
// although the rule never fires on it at the top at all.
18651870
//
18661871
// The second is in the regrouping: exactly one factor to differentiate, never two.
1867-
if (Integration.AnsweringTheQuestionAsked
1872+
// ...and up to two below the question asked where everything beside the
1873+
// differentiated factor is algebraic in x with a root in it: the second step of
1874+
// parts on `x^3 asech(a x)^2` is `x^2 asech(a x)/sqrt(1/(a x)^2 - 1)`, whose other
1875+
// factor integrates to an algebraic expression or declines at once, and whose
1876+
// remainder is algebraic -- none of the logarithms by the dozen the scope above
1877+
// is there to stop. With a root only: beside a rational function the rule for a
1878+
// rational function times a logarithm is the one that answers, and offering
1879+
// parts there sent `(a + b atanh(c x^2))^2/x^5` into a search that did not return.
1880+
if ((Integration.AnsweringTheQuestionAsked
1881+
|| Integration.AnsweringTheQuestionAskedOrTwoBelow && TryRegroupAroundTheDifferentiatedFactor(expr) is var (_, algebraicOthers) && algebraicOthers is not null && IsAlgebraicIn(algebraicOthers, x) && HasARadicalOf(algebraicOthers, x))
18681882
&& TryRegroupAroundTheDifferentiatedFactor(expr) is var (differentiated, others)
18691883
&& differentiated is not null && others is not null
18701884
&& TrySplit(differentiated, others) is { } byLiate)
@@ -9435,6 +9449,33 @@ node is Powf(var @base, Number.Rational half) && @base == radicand
94359449
return null;
94369450
}
94379451

9452+
/// <summary>
9453+
/// Whether every fractional power of a quotient in <paramref name="x"/> in
9454+
/// <paramref name="expr"/> has a monomial in <paramref name="x"/> below its bar, and
9455+
/// there is at least one: the shape <c>sqrt(1/(c x)^2 - 1)</c> has, and
9456+
/// <c>sqrt((1 + x)/(1 - x))</c> has not.
9457+
/// </summary>
9458+
private static bool EveryRootStandsOverAMonomial(Entity expr, Entity.Variable x)
9459+
{
9460+
var any = false;
9461+
foreach (var node in expr.Nodes)
9462+
{
9463+
if (node is not Powf(var @base, Number.Rational exponent) || exponent is Number.Integer || !@base.ContainsNode(x))
9464+
continue;
9465+
var (above, below) = Functions.SingleQuotient.Of(AsOneQuotient(@base));
9466+
if (below == Number.Integer.One || !below.ContainsNode(x))
9467+
continue;
9468+
// ...and a polynomial above it, so that what comes out is the root of a
9469+
// polynomial: `(1 + ln(u^2)/u^2)^(-3/2)` has a monomial below and is not this,
9470+
// and written apart at every depth it fed Bronstein's `sqrt(x + ln(x))` search.
9471+
if (!TreeAnalyzer.TryGetPolynomial(below, x, out var monomials) || monomials.Count != 1
9472+
|| !TreeAnalyzer.TryGetPolynomial(above, x, out _))
9473+
return false;
9474+
any = true;
9475+
}
9476+
return any;
9477+
}
9478+
94389479
/// <summary>
94399480
/// <paramref name="forPositive"/>, an antiderivative of <paramref name="integrand"/> for
94409481
/// <paramref name="x"/> positive, extended to the other side by parity, which is exact:
@@ -9950,6 +9991,56 @@ node is Powf(Powf(var @base, var inner), var outer)
99509991
return answer?.Substitute(constant, linear - slope * x);
99519992
}
99529993

9994+
/// <summary>
9995+
/// The sign of a real-valued function of <paramref name="x"/> among the factors of the
9996+
/// integrand is constant on every interval between its zeros, and goes in front of the
9997+
/// antiderivative of the rest: <c>sgn(x) f(x)</c> is <c>sgn(x) F(x)</c> on each half-line,
9998+
/// which is the generic case every rule answers in. The extension by parity writes the
9999+
/// antiderivative of <c>x^2/sqrt(1/(a x)^2 - 1)</c> with a <c>sgn(x)</c> in front, and a
10000+
/// step of parts against it -- <c>x^2 asech(a x)/sqrt(1/(a x)^2 - 1)</c>, the second step
10001+
/// on <c>x^3 asech(a x)^2</c> -- leaves that sign beside the remainder, where no rule
10002+
/// read past it. Only a sign whose argument is shown real: for a complex <c>g</c>,
10003+
/// <c>sgn(g)</c> is <c>g/|g|</c> and is not constant anywhere. Asked as the same question.
10004+
/// https://github.com/asc-community/AngouriMath/issues/718
10005+
/// </summary>
10006+
internal static Entity? SolveByTakingASignOut(Entity expr, Entity.Variable x, bool integrateByParts)
10007+
{
10008+
if (!TryReadAsQuotient(expr, out var numerator, out var denominator) && expr is Mulf)
10009+
(numerator, denominator) = (expr, Number.Integer.One);
10010+
else if (numerator is null)
10011+
return null;
10012+
var signs = new Dictionary<Entity, int>();
10013+
Entity Without(Entity side)
10014+
{
10015+
Entity? rest = null;
10016+
foreach (var factor in Mulf.LinearChildren(side))
10017+
{
10018+
var (@base, times) = factor is Powf(var inner, Number.Integer whole) ? (inner, whole.EInteger) : (factor, EInteger.One);
10019+
if (@base is Signumf(var signed) && signed.ContainsNode(x) && TreeAnalyzer.IsRealValued(signed, x) && times.CanFitInInt32())
10020+
{
10021+
signs[signed] = (signs.TryGetValue(signed, out var seen) ? seen : 0) + times.ToInt32Unchecked();
10022+
continue;
10023+
}
10024+
rest = rest is null ? factor : rest * factor;
10025+
}
10026+
return rest ?? Number.Integer.One;
10027+
}
10028+
var above = Without(numerator);
10029+
var below = Without(denominator);
10030+
if (signs.Count == 0)
10031+
return null;
10032+
var rest = below == Number.Integer.One ? above : above / below;
10033+
if (!rest.ContainsNode(x))
10034+
return null;
10035+
var answer = Integration.ComputeAsTheSameQuestion(rest, x, integrateByParts);
10036+
if (answer is null)
10037+
return null;
10038+
foreach (var pair in signs)
10039+
if (pair.Value % 2 != 0)
10040+
answer = MathS.Signum(pair.Key) * answer;
10041+
return answer;
10042+
}
10043+
995310044
/// <summary>
995410045
/// A whole power of a product in which the variable stands beside a constant, written
995510046
/// as the product of the powers: <c>(c x)^2</c> is <c>c^2 x^2</c>, exact for a whole
@@ -13073,7 +13164,12 @@ private static bool OnEveryRealInterval(List<Entity> bases, Entity.Variable x, S
1307313164
// and no deeper: unscoped, it fed the search on `arcsin(sqrt(1 + x) - sqrt(x))`,
1307413165
// thirty levels of the same root written apart and combined again, five seconds
1307513166
// where declining takes one.
13076-
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
13167+
// ...except where every root written apart stands over a monomial in x, which is
13168+
// the derivative of asech(c x) and acsch(c x) as they are written -- `1/(c x)^2 - 1`
13169+
// over `c^2 x^2` -- and is a rewriting that lands on the root of a quadratic beside
13170+
// `|c| |x|` and nothing else: the second step of parts on `x^3 asech(a x)^2` asks
13171+
// for `x^2/sqrt(1/(a x)^2 - 1)` three levels down, and declined it there.
13172+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow && !EveryRootStandsOverAMonomial(expr, x))
1307713173
return null;
1307813174
var tookAPowerOfX = false;
1307913175
// Whether every power of x taken is a whole one, and whether their sum is odd:
@@ -13083,6 +13179,10 @@ private static bool OnEveryRealInterval(List<Entity> bases, Entity.Variable x, S
1308313179
// and was declined for that after its antiderivative had been found.
1308413180
var wholePowersOfX = true;
1308513181
var oddPowersOfX = false;
13182+
// ...and only where every such power came from a root that is a factor of the
13183+
// integrand: a sign can go in front of the answer for `|x|` that multiplied the
13184+
// integrand, and not for one inside a sum or a logarithm's argument.
13185+
var everyPowerOfXFromAFactor = true;
1308613186
// A parameter's even power taken for positive -- `c^2 x^2` below the bar, which is
1308713187
// how `acsch(c x)` and `asech(c x)` arrive, is positive for a real `c` -- and the
1308813188
// answer says so: `provided c^2 > 0`, which holds exactly for a real non-zero `c`.
@@ -13095,7 +13195,7 @@ private static bool OnEveryRealInterval(List<Entity> bases, Entity.Variable x, S
1309513195
// front of the answer only from a power that is one of them, and not from one
1309613196
// inside a logarithm or a sum, where it is not a factor of anything.
1309713197
var factors = new HashSet<Entity>(
13098-
expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(Mulf.LinearChildren(divisor))
13198+
TryReadAsQuotient(expr, out var dividend, out var divisor) ? Mulf.LinearChildren(dividend).Concat(Mulf.LinearChildren(divisor))
1309913199
: expr is Mulf ? Mulf.LinearChildren(expr)
1310013200
: new[] { expr });
1310113201
// A root inside the argument of a logarithm is left as it is: the logarithm is an
@@ -13112,7 +13212,11 @@ expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(M
1311213212
var (above, below) = Functions.SingleQuotient.Of(AsOneQuotient(@base));
1311313213
if (below != Number.Integer.One && below.ContainsNode(x) && OfModestDegree(above)
1311413214
&& (IsPositiveForReal(below, x) || IsPositiveForARealParameter(below, x, out assumed, assumed)))
13215+
{
13216+
if (!factors.Contains(node))
13217+
everyPowerOfXFromAFactor = false;
1311513218
return MathS.Pow(above, exponent) * PowerOfAPositive(below, -exponent);
13219+
}
1311613220
// An even power of a polynomial below the bar is positive wherever the
1311713221
// polynomial is real and not zero, which the answer states: `(A/P^2)^(1/2)` is
1311813222
// `sqrt(A) |P|^(-1)`, and `|P|` is `sgn(P) P`, the sign taken out in front.
@@ -13196,6 +13300,8 @@ expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(M
1319613300
&& (g == x || power is Number.Integer { EInteger.IsEven: true } || IsPositiveForReal(g, x)))
1319713301
{
1319813302
var evenPower = MathS.Pow(g, Number.Integer.Create(even));
13303+
if (g == x && !factors.Contains(node))
13304+
everyPowerOfXFromAFactor = false;
1319913305
taken = taken * (g == x ? PowerOfAPositive(evenPower, underneath ? -exponent : exponent)
1320013306
: power is Number.Integer ? MathS.Pow(g, power) : MathS.Pow(evenPower, underneath ? -exponent : exponent));
1320113307
if (!n.EInteger.IsEven)
@@ -13225,6 +13331,8 @@ expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(M
1322513331
Entity term = degree == 0 ? pair.Value : degree == 1 ? pair.Value * x : pair.Value * MathS.Pow(x, degree);
1322613332
rest = rest == Number.Integer.Zero ? term : rest + term;
1322713333
}
13334+
if (!factors.Contains(node))
13335+
everyPowerOfXFromAFactor = false;
1322813336
return PowerOfAPositive(MathS.Pow(x, 2 * k), exponent) * MathS.Pow(rest.InnerSimplified, exponent);
1322913337
}
1323013338
return node;
@@ -13239,8 +13347,16 @@ expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(M
1323913347
var forPositive = Integration.ComputeIndefiniteIntegral(Functions.PartialFractions.Bare(written), x, integrateByParts: true);
1324013348
if (forPositive is null || forPositive.Nodes.Any(node => node == MathS.NaN))
1324113349
return null;
13350+
// With the sign in front where every power of |x| taken is whole -- |x|^m is
13351+
// sgn(x)^m x^m -- and by parity otherwise. The extension by parity writes the
13352+
// answer in |x|, and an answer in |x| handed on by a step of parts -- the second
13353+
// step on `asech(a x)^2/x^2` -- is a remainder in |x| and `(1 - (|x| a)^2)` that no
13354+
// rule reads, where the same answer with `sgn(x)` in front is the answer in x
13355+
// beside a factor the sign-out route takes.
1324213356
var extended = tookAPowerOfX
13243-
? ExtendedByParity(expr, forPositive, x) ?? (wholePowersOfX ? (oddPowersOfX ? MathS.Signum(x) * Functions.PartialFractions.Bare(forPositive) : Functions.PartialFractions.Bare(forPositive)) : null)
13357+
? (wholePowersOfX && everyPowerOfXFromAFactor
13358+
? (oddPowersOfX ? MathS.Signum(x) * Functions.PartialFractions.Bare(forPositive) : Functions.PartialFractions.Bare(forPositive))
13359+
: ExtendedByParity(expr, forPositive, x))
1324413360
: forPositive;
1324513361
foreach (var pair in signs)
1324613362
if (pair.Value % 2 == 1 && extended is { })

0 commit comments

Comments
 (0)