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
Original file line number Diff line number Diff line change
Expand Up @@ -5142,6 +5142,26 @@ static bool IsTwice(Entity argument, Entity.Variable x)
return reduced.Denominator.Equals(EInteger.One) && reduced.Numerator.IsEven ? rebuilt : null;
}

/// <summary>
/// Every whole power of a product written as the product of the powers, <c>(a P)^5</c>
/// as <c>a^5 P^5</c>, which is exact for a whole power and is the spelling the rational
/// reader needs: <c>(4u^2 + 12u^4 + 12u^6 + 4u^8)/(a (1 - u^2))^5</c> was declined after
/// five seconds and is answered in 27 ms as <c>.../(a^4 (1 - u^2)^5)</c>. Four rounds,
/// since a distributed factor may itself be such a power.
/// </summary>
private static Entity WithWholePowersOfProductsDistributed(Entity integrand)
{
for (var round = 0; round < 4; round++)
{
var distributed = integrand.Replace(node =>
node is Powf(Mulf(var l, var r), Number.Integer power) ? MathS.Pow(l, power) * MathS.Pow(r, power) : node);
if (distributed == integrand)
break;
integrand = distributed;
}
return integrand;
}

/// <summary>
/// An integrand holding a fractional power of something <b>linear</b> in the variable,
/// turned into a rational function by <c>u^q = a*x + b</c>.
Expand Down Expand Up @@ -5308,6 +5328,15 @@ node is Powf(var radical, Number.Rational e) && e is not Number.Integer
var integrand = Functions.SingleQuotient.Combine((rewritten * dx).Simplify());
if (integrand is Providedf(var inner, _))
integrand = inner;
// The quotient of linears leaves `(a (1 - u^2))^5` below the bar, which the rational
// reader does not read and whose distributed spelling it answers at once: Rubi's
// `x^3 sqrt((a x + 1)/(a x - 1))` took nine seconds through the split terms, and
// takes half of one as a single quotient over `a^5 (1 - u^2)^5`. Only where the
// integrand in u is rational: with a root of u still in it -- a second base, as in
// Timofeev's 314 -- the distributed spelling sent the radical rules down a path
// that answered with a sign function, where the undistributed one is answered exactly.
if (!integrand.Nodes.Any(node => node is Powf(var radicand, Number.Rational fractional) && fractional is not Number.Integer && radicand.ContainsNode(u)))
integrand = WithWholePowersOfProductsDistributed(integrand);
// For an even q the principal root is not negative wherever it is real, and a root
// holding a power of u gives that power up: `1/sqrt(t + t^(3/2))` under `u = sqrt(t)`
// is `2u/sqrt(u^2 + u^3)`, a root of a cubic, and is `2/sqrt(1 + u)`. Where the
Expand Down Expand Up @@ -9890,14 +9919,7 @@ node is Powf(Powf(var @base, var inner), var outer)
// simplifier writes `4a^2 u^2` as `(a u)^2 4`, and no rational reader sees the `u^2`
// inside -- Timofeev's `1/(a^2 + b^2 cosh(x)^2)` was declined in that spelling and
// is answered in the other.
for (var round = 0; round < 4; round++)
{
var distributed = integrand.Replace(node =>
node is Powf(Mulf(var l, var r), Number.Integer power) ? MathS.Pow(l, power) * MathS.Pow(r, power) : node);
if (distributed == integrand)
break;
integrand = distributed;
}
integrand = WithWholePowersOfProductsDistributed(integrand);
// u is an exponential, so it is positive, and a root holding a power of it gives
// that power up: `sqrt(1 + tanh(4x))` is a root of `2u/(1 + u)` here and nothing
// rationalises that; as `sqrt(2) sqrt(u)/sqrt(1 + u)` it is one substitution more.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ private static void DifferentiatesBack(string integrand)
[InlineData("(3 - 3/(4*x^2))^3/e^(2*acoth(2*x))")]
public void AnExponentialOfAnInverseHyperbolicCotangent(string integrand) => DifferentiatesBack(integrand);

/// <summary>
/// The quotient of linears under the root leaves <c>(a (1 - u^2))^5</c> below the bar in
/// <c>u</c>, which the rational reader does not read as <c>a^5 (1 - u^2)^5</c> until it
/// is written so: <c>x^3 sqrt((a x + 1)/(a x - 1))</c> took nine seconds through the
/// split terms and takes half of one as a single quotient; <c>e^acoth(a x) x^3</c>
/// eighteen seconds and a tenth. Pinned as solved, not as timed -- a wall clock in a
/// test measures the runner.
/// </summary>
[Theory]
[InlineData("x^3*sqrt((2*x+1)/(2*x-1))")]
[InlineData("e^acoth(2*x)*x^3")]
[InlineData("1/(e^(3*acoth(2*x))*x^4)")]
[InlineData("e^acoth(2*x)*sqrt(3-3/(2*x))/x^4")]
public void APowerOfAProductBelowTheBarIsReadDistributed(string integrand) => DifferentiatesBack(integrand);

/// <summary>The fold is the identity it is: <c>e^(k ln q)</c> with any multiplier, nested or not.</summary>
[Theory]
[InlineData("e^(3*ln(x + 1))")]
Expand Down
Loading