Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,23 @@ and in no release -- and is `sgn(u) u/(u^2 - 1)`
| `"1/sqrt(1+csch(x)^2)".Integrate("x")` | left unevaluated | `-sgn(tanh(x)) ln(tanh(x)^2 - 1)/2`, in exponentials |
| `"x^4/sech(2*ln(c*x))^(1/2)".Integrate("x")` | left unevaluated | `sgn(x) (1 + c^4 x^4)^(3/2)/(6 sqrt(2) c^5)` up to the form, `provided c^4 > 0` |

### A root of a rational function of `coth(x)` is integrated by the hyperbolic half-angle

`coth(x)^3/sqrt(a + b coth(x)^2)` was a search past the budget. The rational-in-`tanh` route
declined the half-angle -- `u = tanh(x)` for an integrand written in `e^(2x)` -- whenever a
root was in the integrand, because for `sqrt(sinh(x))` the half makes a root of `2u/(1 - u^2)`
where `u = e^x` answers with a root of a polynomial. With a root it now takes the half where
every radicand comes out over a power of `u`: `a + b coth(x)^2` is `(b + a u^2)/u^2`, whose root
is `sqrt(b + a u^2)/|u|`, and `|u|^k` for the bare square is `sgn(u) u^k` at every depth. Rubi's
6.4.7, nine rows ([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"coth(x)^3/sqrt(a+b*coth(x)^2)".Integrate("x")` | left unevaluated | the antiderivative, in `sgn(tanh(x))` and `sqrt(b + a tanh(x)^2)`, by cases on `a + b` |
| `"coth(x)*(a+b*coth(x)^2)^(3/2)".Integrate("x")` | left unevaluated | the antiderivative |
| `"coth(x)/(a+b*coth(x)^2)^(3/2)".Integrate("x")` | left unevaluated | the antiderivative |
| `"(a+b*coth(x)^2)^(3/2)*tanh(x)^2".Integrate("x")` | left unevaluated | the antiderivative |

### `binomial(n, k)` is a function

**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10145,14 +10145,19 @@ Entity Without(Entity side)
/// written for it is a factor the rest of the search has to carry:
/// <c>tanh(x)/(a + b tanh(x)^2)^(5/2)</c> under <c>u = e^(2x)</c> holds
/// <c>(1 + 2u + u^2)^(5/2)</c>, and with that rewritten the search ran past its budget
/// where it had answered in twenty seconds.
/// where it had answered in twenty seconds. The one half-odd power taken beyond the
/// square root is of the bare square, <c>(x^2)^(3/2)</c>, which is <c>sgn(x) x^3</c>:
/// it is what a root of <c>(b + a u^2)/u^2</c> -- <c>a + b coth(x)^2</c> under
/// <c>u = tanh(x)</c> -- leaves once the quotient is written apart, and nothing else
/// reads it.
/// </remarks>
internal static Entity? SolveByTakingARootOfAPerfectSquare(Entity expr, Entity.Variable x, bool integrateByParts)
{
// Asked of every integrand at every depth, so the radicand is read as a polynomial
// only where it is small enough to be a written square: x^2, or a x^2 + b x + c.
static bool MayBeARootOfASquare(Entity node, Entity.Variable x)
=> node is Powf(var radicand, Number.Rational r) && r.ERational.Equals(ERational.Create(1, 2))
=> node is Powf(var radicand, Number.Rational r) && r.ERational.Denominator.Equals(EInteger.FromInt32(2))
&& (r.ERational.Equals(ERational.Create(1, 2)) || radicand is Powf(var @base, var degree) && @base == x && degree == Number.Integer.Create(2))
&& radicand.ContainsNode(x) && radicand.Complexity <= 12
&& radicand.Nodes.Count(inner => inner == x) <= 2;
if (!expr.Nodes.Any(node => MayBeARootOfASquare(node, x)))
Expand Down Expand Up @@ -11447,11 +11452,14 @@ private static bool IsTheZeroPolynomial(Entity expr)
// for the lower degrees and the answer in the argument as written. The half only
// where every exponent is written with an even factor in front -- `coth(c + d x)`
// is written with `e^(2 (c + d x))`, and `tanh(c + d x)` is its argument's
// tangent, not the half-angle of `2(c + d x)` -- and not with a root in the
// integrand, which the half turns into a root of a quotient: `sinh(x)` writes
// `e^x`, and its `u = tanh(x/2)` answers were what `u = e^x` answered in less,
// Timofeev's `e^x/sqrt(e^(2x) + a^2)` among them, a root of a polynomial there.
var halfIsTheArgument = !HasARadicalOf(expr, x) && exponentials.Keys.All(node => node is Powf(_, var exponent) && WrittenWithAnEvenFactor(exponent));
// tangent, not the half-angle of `2(c + d x)` -- and with a root in the
// integrand only where the half leaves every radicand over a power of u
// (checked once the integrand is in u, below): `sinh(x)` writes `e^x`, the half
// makes a root of `2u/(1 - u^2)` of `sqrt(sinh(x))`, and its `u = tanh(x/2)`
// answers were what `u = e^x` answered in less, Timofeev's
// `e^x/sqrt(e^(2x) + a^2)` among them, a root of a polynomial there.
var hasARadical = HasARadicalOf(expr, x);
var halfIsTheArgument = exponentials.Keys.All(node => node is Powf(_, var exponent) && WrittenWithAnEvenFactor(exponent));
foreach (var halved in new[] { false, true })
{
if (halved && !halfIsTheArgument)
Expand All @@ -11464,11 +11472,19 @@ private static bool IsTheZeroPolynomial(Entity expr)
return null;
if (InTanh(inV) is not var (inT, parity) || parity != 0)
continue;
// With a root, the half only where every radicand comes out over a power
// of t -- `a + b coth(x)^2` is `(b + a t^2)/t^2`, Rubi's cotangent and
// cosecant families -- and not over `1 - t^2`, which is where the half
// makes a root of a quotient out of `sinh(x)`, and `u = e^x` answers in less.
if (halved && hasARadical && !inT.Nodes.All(node => node is not Powf(var radicand, Number.Rational root) || root is Number.Integer || !radicand.ContainsNode(t)
|| Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(radicand)).Item2 is var below
&& Mulf.LinearChildren(below).All(factor => !factor.ContainsNode(t) || factor == t || factor is Powf(var b, Number.Integer) && b == t)))
continue;
var rationalInT = WithThePowersOfOnePlusMinusTCollected(inT / (1 - MathS.Sqr(t)));
if (rationalInT.ContainsNode(square) || rationalInT.ContainsNode(vt) || rationalInT.Nodes.Any(node => node == MathS.NaN)
|| Integration.ComputeAsAQuestionOfItsOwn(rationalInT, t, integrateByParts) is not { } evenResult)
return null;
var evenAnswer = evenResult.Substitute(t, MathS.Hyperbolic.Tanh(halved ? (y / 2).InnerSimplified : y));
var evenAnswer = evenResult.Substitute(t, MathS.Hyperbolic.Tanh(halved ? Functions.PartialFractions.Bare((y / 2).Simplify()) : y));
if (evenAnswer.Nodes.Any(node => node == MathS.NaN))
return null;
// dx is dy/d, and twice that in the half of y.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,22 @@ public void ANegativePowerOfTheQuadraticIsWrittenBelowTheBar(string integrand)
public void ARationalFunctionOfTheHyperbolicTangent(string integrand)
=> DifferentiatesBackWithParametersPinned(integrand, new[] { -0.5, 0.23, 0.61, 1.05, 1.7 });

/// <summary>
/// And with a root: <c>coth(x)^3/sqrt(a + b coth(x)^2)</c> is <c>u = tanh(x)</c>'s
/// half-angle of <c>e^(2x)</c>, and every radicand comes out over a power of <c>u</c>
/// -- <c>a + b coth(x)^2</c> is <c>(b + a u^2)/u^2</c> -- which is the shape the half
/// is admitted with a root for; the roots of <c>1 - u^2</c> that the half makes of
/// <c>sinh(x)</c> stay with <c>u = e^x</c>. Rubi's 6.4.7, each a search past the budget
/// before. https://github.com/asc-community/AngouriMath/issues/718
/// </summary>
[Theory]
[InlineData("coth(x)^3/sqrt(a + b*coth(x)^2)")]
[InlineData("coth(x)*(a + b*coth(x)^2)^(3/2)")]
[InlineData("coth(x)/(a + b*coth(x)^2)^(3/2)")]
[InlineData("coth(2*x + 1)^3/sqrt(a + b*coth(2*x + 1)^2)")]
public void ARootOfARationalFunctionOfTheHyperbolicCotangent(string integrand)
=> DifferentiatesBackWithParametersPinned(integrand, new[] { -0.5, 0.23, 0.61, 1.05, 1.7 });

/// <summary>
/// A cubed symbolic quadratic beside a quadratic with real roots was integrated to a
/// wrong answer -- the Hermite ansatz's logarithmic part, with coefficients that are
Expand Down
Loading