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
7 changes: 7 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,20 @@ in Rubi's 1.1.3.4 come out shorter as well, and those that took two seconds take
of Rubi's 4.1.4.1, 4.2.4.1 and 4.5.4.1. `f^m (alpha + beta f^2)` for `f` a sine, cosine, secant or cosecant of a linear
is the derivative of `cos sin^(m + 1)`, `sin cos^(m + 1)`, `tan sec^m` or `cot csc^m` where its bracket is a multiple of
that derivative's, and is now integrated so ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
The power is read as a factor of the integrand, so one under the bar is `f^(-m)`: `(m + (1 - m) sec^2)/sec^m` is
the derivative of `tan sec^(-m)`. And `m` may be a number that is not whole, as in Rubi's 4.5.4.1
`(3 + 3 sec(c + d x)^2)/sqrt(sec(c + d x))`.

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"sec(c+d*x)^m*(-q*m/(1+m)+q*sec(c+d*x)^2)".ToEntity().Integrate("x")` | `integral(...)` | 75 characters |
| `"sec(c+d*x)^m*(A-A*(1+m)*sec(c+d*x)^2/m)".ToEntity().Integrate("x")` | `integral(...)` | 54 characters |
| `"sec(k+f*x)^m*(m-(1+m)*sec(k+f*x)^2)".ToEntity().Integrate("x")` | `integral(...)` | 54 characters |
| `"sin(k+f*x)^m*(1+m-(2+m)*sin(k+f*x)^2)".ToEntity().Integrate("x")` | `integral(...)` | 71 characters |
| `"(m+(1-m)*sec(c+d*x)^2)/sec(c+d*x)^m".ToEntity().Integrate("x")` | `integral(...)` | 56 characters |
| `"(-(1-m)+(2-m)*cos(x)^2)/cos(x)^m".ToEntity().Integrate("x")` | `integral(...)` | 55 characters |
| `"(3+3*sec(c+d*x)^2)/sec(c+d*x)^(1/2)".ToEntity().Integrate("x")` | `integral(...)` | 60 characters |
| `"sqrt(sin(x))*(3/2-5/2*sin(x)^2)".ToEntity().Integrate("x")` | `integral(...)` | 27 characters |

### A power of a sine or hyperbolic sine over a binomial in a power of it is split over the binomial's roots

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31310,8 +31310,8 @@ Piecewise piecewise when piecewise.Cases.Any() => piecewise.Cases.First().Expres
}

/// <summary>
/// <c>f^m (alpha + beta f^2)</c> for a symbolic <c>m</c> and <c>f</c> a sine, cosine, secant or
/// cosecant of a linear <c>u</c>, where it is the derivative of a product: with <c>u' = 1</c>,
/// <c>f^m (alpha + beta f^2)</c> for a symbolic <c>m</c>, or a number that is not whole, and <c>f</c> a
/// sine, cosine, secant or cosecant of a linear <c>u</c>, where it is the derivative of a product: with <c>u' = 1</c>,
/// <c>(cos sin^(m + 1))' = sin^m ((m + 1) - (m + 2) sin^2)</c>,
/// <c>(sin cos^(m + 1))' = cos^m ((m + 2) cos^2 - (m + 1))</c>,
/// <c>(tan sec^m)' = sec^m ((m + 1) sec^2 - m)</c> and <c>(cot csc^m)' = -csc^m ((m + 1) csc^2 - m)</c>.
Expand All @@ -31321,23 +31321,39 @@ Piecewise piecewise when piecewise.Cases.Any() => piecewise.Cases.First().Expres
/// square terms, <c>alpha + beta f^2</c>, which matches <c>p0 + p2 f^2</c> above where
/// <c>beta p0 = alpha p2</c>; the answer is <c>(alpha/p0) G/u'</c>. Rubi's 4.1.4.1, 4.2.4.1 and 4.5.4.1
/// <c>sec(c + d x)^m (m - (1 + m) sec(c + d x)^2)</c> and the like were declined.
/// The power is one of the integrand's factors, and one under the bar is <c>f^(-m)</c>: only then is the
/// integrand <c>f^m</c> times the rest, and a power in one term of a sum, as in
/// <c>-m sec^m + (1 + m) sec^2</c>, is not a factor of it.
/// https://github.com/asc-community/AngouriMath/issues/718
/// </remarks>
internal static Entity? SolveASymbolicPowerOfATrigonometricFunctionAsTheDerivativeOfAProduct(Entity expr, Entity.Variable x)
{
if (!Integration.AnsweringTheQuestionAsked)
return null;
// The power with a symbol in its exponent, of a sine, cosine, secant or cosecant of a linear.
var power = expr.Nodes.OfType<Powf>().FirstOrDefault(node => node.Exponent.Vars.Any() && !node.Exponent.ContainsNode(x)
&& node.Base is Sinf or Cosf or Secantf or Cosecantf);
if (power is not Powf(var function, var m))
return null;
// The power with a symbol in its exponent, of a sine, cosine, secant or cosecant of a linear,
// as a factor of the integrand.
var factors = FactorsOfTheIntegrand(expr);
var at = factors.FindIndex(pair => pair.Factor is Powf(Sinf or Cosf or Secantf or Cosecantf, var exponent)
&& (exponent.Vars.Any() && !exponent.ContainsNode(x)
// Or a number that is not whole: the derivatives hold for any m on the principal branch,
// and a whole one is left to the rules for whole powers.
|| exponent is Number.Rational and not Number.Integer));
if (at < 0 || factors[at].Factor is not Powf(var function, var written))
return null;
var m = factors[at].Underneath ? (-written).InnerSimplified : written;
var argument = function switch { Sinf(var y) => y, Cosf(var y) => y, Secantf(var y) => y, Cosecantf(var y) => y, _ => null };
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var slope, out _) || Functions.PartialFractions.IsZeroAsAValue(slope))
return null;
var s = Variable.CreateUnique(expr, "s_trig");
// The power taken off by writing 1 for it: `s^m (...)/s^m` is not cancelled by the simplification.
var inS = expr.Substitute(power, Number.Integer.One).Substitute(function, s).InnerSimplified;
// The rest of the factors, without the power: `s^m (...)/s^m` is not cancelled by the simplification.
Entity above = Number.Integer.One, below = Number.Integer.One;
for (var i = 0; i < factors.Count; i++)
if (i != at)
{
if (factors[i].Underneath) below *= factors[i].Factor;
else above *= factors[i].Factor;
}
var inS = (above / below).Substitute(function, s).InnerSimplified;
if (inS.ContainsNode(x) || !TreeAnalyzer.TryGetPolynomial(inS.Expand(), s, out var read)
|| read.Keys.Any(key => !key.IsZero && !key.Equals(EInteger.FromInt32(2))))
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ private static void DifferentiatesBack(string integrand, params (string, double)
{
var integral = integrand.ToEntity().Integrate("x");
Assert.DoesNotContain("integral(", integral.Stringize());
DifferentiatesBack(integrand, integral, pins);
}

private static void DifferentiatesBack(string integrand, Entity integral, params (string, double)[] pins)
{
var pinned = integral.Substitute("C", 0);
Entity original = integrand.ToEntity();
foreach (var (name, value) in pins)
Expand Down Expand Up @@ -52,12 +56,46 @@ private static void DifferentiatesBack(string integrand, params (string, double)
[InlineData("sin(c+d*x)^m*(1+m-(2+m)*sin(c+d*x)^2)")]
[InlineData("cos(x)^m*(-(1+m)+(2+m)*cos(x)^2)")]
[InlineData("csc(x)^m*(m-(1+m)*csc(x)^2)")]
// Under the bar the power is f^(-m): (tan sec^(-m))' and (sin cos^(1 - m))'.
[InlineData("(m+(1-m)*sec(c+d*x)^2)/sec(c+d*x)^m")]
[InlineData("(-(1-m)+(2-m)*cos(x)^2)/cos(x)^m")]
public void IsAnsweredAndDifferentiatesBack(string integrand)
{
DifferentiatesBack(integrand, ("A", 0.6), ("q", 1.25), ("c", 0.3), ("d", 0.75), ("m", 2.5));
DifferentiatesBack(integrand, ("A", -0.75), ("q", 0.4), ("c", -1), ("d", -0.5), ("m", 1.0 / 3));
}

// A power that is not whole: Rubi's 4.5.4.1 (3 + 3 sec(c + d x)^2)/sqrt(sec(c + d x)), and the
// same derivatives at m = 1/2, 1/3 and 3/2.
[Theory]
[InlineData("(3+3*sec(c+d*x)^2)/sec(c+d*x)^(1/2)")]
[InlineData("sqrt(sin(x))*(3/2-5/2*sin(x)^2)")]
[InlineData("sin(c+d*x)^(1/3)*(4/3-7/3*sin(c+d*x)^2)")]
[InlineData("cos(x)^(3/2)*(-5/2+7/2*cos(x)^2)")]
[InlineData("csc(x)^(1/2)*(1/2-3/2*csc(x)^2)")]
public void IsAnsweredForAPowerThatIsNotWhole(string integrand)
{
DifferentiatesBack(integrand, ("c", 0.3), ("d", 0.75));
DifferentiatesBack(integrand, ("c", -1), ("d", -0.5));
}

// The power is not a factor of the whole integrand, or is one under the bar, where the bracket is
// not the derivative's: none of these is the derivative of a single product.
[Theory]
[InlineData("(-m+(1+m)*sec(x)^2)/sec(x)^m")]
[InlineData("-m*sec(x)^m+(1+m)*sec(x)^2")]
[InlineData("sin(x)^m*(1+m)-(2+m)*sin(x)^2")]
[InlineData("(1+m-(2+m)*sin(x)^2)/sin(x)^m")]
[InlineData("(-m+(1+m)*csc(x)^2)/csc(x)^m")]
public void IsNotAnsweredWronglyWhereThePowerIsNotThatFactor(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
if (integral.Stringize().Contains("integral("))
return;
DifferentiatesBack(integrand, integral, ("m", 2.5));
DifferentiatesBack(integrand, integral, ("m", 1.0 / 3));
}

[Fact]
public void IsNotClaimedWhereTheBracketIsNotTheDerivative()
{
Expand Down
Loading