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
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,21 @@ but `sqrt(q)^2 = q` ([#1598](https://github.com/asc-community/AngouriMath/issues
| `"1/sqrt(-x^2 + i)".Integrate("x")` | `-arcsin(-2x/sqrt(4i)) + C` | `ln(-2x + 2i sqrt(-x^2 + i))/i + C`, an antiderivative as before, in the logarithm |
| `"1/(sqrt(x)*sqrt(1 + i*x))".Integrate("x")`, and Rubi 4.3.2.1's `sqrt(tan(c + d x))/(a + i a tan(c + d x))^(5/2)` | `integral(...)` | the antiderivative |

### A power of a constant times a whole power of a polynomial is integrated as that power

**Answers where there were none.** `(c S^k)^p`, a constant times a whole power past the first of a
polynomial in `x` under a power that is not whole, was declined where it was not a function of a
linear: `x^2 (c (a + b x^2)^2)^(3/2)` is a polynomial times a factor that is constant wherever
`a + b x^2` is not zero. It is integrated as `K S^(k p)` now, with `K = c^q (c S^k)^r/S^(k r)` for the
whole part `q` and the rest `r` of `p`, where the substitution search, asked first, declines it. Rubi's
1.3.2
([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"x^2*(c*(a + b*x^2)^2)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x^2)^2)^(1/2)/(a + b x^2)` times `a^3 x^3/3 + 3 a^2 b x^5/5 + 3 a b^2 x^7/7 + b^3 x^9/9` |
| `"(c*(a + b*x^2)^3)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x^2)^3)^(1/2)/(a + b x^2)^(3/2)` times an antiderivative of `(a + b x^2)^(9/2)` |

### A quotient by the square of a base is integrated by parts against the base's reciprocal

**Answers where there were none.** `x^2/(a x cos(a x) - sin(a x))^2` was declined, with the rest of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25177,6 +25177,94 @@ private static bool HasTheSameRatioAtTwoPoints(Entity expr, Entity reference, En
return lambda;
}

/// <summary>
/// A power that is not whole of a constant times a whole power of something of x,
/// <c>(c S^k)^p</c> for a whole <c>k</c> past 1, as <c>K S^(k p)</c>, with
/// <c>K = c^q (c S^k)^r/S^(k r)</c> for the whole part <c>q</c> of <c>p</c> and the rest
/// <c>r</c>: Rubi's 1.3.2 <c>x^m (c (a + b x^2)^2)^(3/2)</c> is <c>K x^m (a + b x^2)^3</c>,
/// a polynomial, and was declined.
/// </summary>
/// <remarks>
/// <c>K</c> is constant on every interval where <c>S</c> is not zero: its logarithmic
/// derivative is <c>r (k S'/S - k S'/S)</c>. So it goes in front of the integral, and over it
/// for a factor below the bar, as the factor of
/// <see cref="SolveByTakingAPowerOfXOutOfAFractionalPower"/> does. A whole power of the
/// constant times the power distributes exactly, which is why only the rest of <c>p</c> is
/// in <c>K</c>. Only factors of the integrand, where <c>K</c> is a factor of the whole; only
/// something of x by arithmetic, since a power of a function is the rules' for that function,
/// which write its sign; and at the top only, where the answer is the caller's.
/// https://github.com/asc-community/AngouriMath/issues/718
/// </remarks>
internal static Entity? SolveByTakingAWholePowerOutOfAPowerOfAProduct(Entity expr, Entity.Variable x, bool integrateByParts)
{
if (!Integration.AnsweringTheQuestionAsked)
return null;
var (above, below) = Functions.SingleQuotient.Of(expr);
Entity constant = Number.Integer.One;
var changed = false;
var top = Rewritten(above, Number.Integer.One);
var bottom = Rewritten(below, Number.Integer.MinusOne);
if (!changed)
return null;
var question = (bottom == Number.Integer.One ? top : top / bottom).InnerSimplified;
if (Integration.ComputeIndefiniteIntegral(question, x, integrateByParts) is not { } integral)
return null;
var answer = constant * integral;
return answer.Nodes.Any(node => node == MathS.NaN) ? null : answer;

Entity Rewritten(Entity side, Number.Integer sign)
{
Entity product = Number.Integer.One;
foreach (var factor in Mulf.LinearChildren(side))
{
var written = factor;
if (factor is Powf(var @base, var power) && power is not Number.Integer && !power.ContainsNode(x)
&& @base is Mulf or Divf && ConstantTimesAWholePower(@base, x) is var (c, inner, k))
{
written = MathS.Pow(inner, (k * power).InnerSimplified);
var signed = (sign * power).InnerSimplified;
Entity whole = Number.Integer.Zero;
var fraction = signed;
if (signed is Number.Rational rational)
{
whole = Number.Integer.Create(rational.ERational.Numerator.Divide(rational.ERational.Denominator));
fraction = (signed - whole).InnerSimplified;
}
var turned = MathS.Pow(@base, fraction) / MathS.Pow(inner, (k * fraction).InnerSimplified);
var turn = whole == Number.Integer.Zero || c == Number.Integer.One ? turned : MathS.Pow(c, whole) * turned;
constant = constant == Number.Integer.One ? turn : constant * turn;
changed = true;
}
product = product == Number.Integer.One ? written : product * written;
}
return product;
}

// A product of constants and one whole power past 1 of something of x: the constant,
// the something and the power.
static (Entity Constant, Entity Inner, Number.Integer Power)? ConstantTimesAWholePower(Entity @base, Entity.Variable x)
{
Entity c = Number.Integer.One;
(Entity Inner, Number.Integer Power)? found = null;
foreach (var part in Mulf.LinearChildren(@base))
{
if (!part.ContainsNode(x))
{
c = c == Number.Integer.One ? part : c * part;
continue;
}
if (found is not null || part is not Powf(var inner, Number.Integer { EInteger: var k } whole) || k.CompareTo(2) < 0)
return null;
// Of x by arithmetic alone: a power of a function of x is the rules' for that
// function, which write its sign.
if (inner.Nodes.Any(node => node.ContainsNode(x) && node is not (Sumf or Minusf or Mulf or Divf or Powf or Variable)))
return null;
found = (inner, whole);
}
return found is var (i, w) ? (c, i, w) : null;
}
}

/// <summary>
/// A fractional or symbolic power of a monomial, distributed: <c>(c x^n)^b</c> is
/// <c>c^b x^(n b)</c> for a positive <c>c</c> and a <c>n</c> that is not whole.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,12 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
// substitution search, which reads each root on its own.
if ((answer = IndefiniteIntegralSolver.SolveBySubstitutingTheSumOfTwoRootsOfLinears(expr, x, integrateByParts)) is { }) return answer;
if ((answer = IndefiniteIntegralSolver.SolveBySubstitution(expr, x, integrateByParts)) is { }) return answer;
// A constant times a whole power of something of x under a power that is not whole, the
// whole power taken out with the factor constant where it is not zero:
// `x^2 (c (a + b x^2)^2)^(3/2)` is that factor times a polynomial. After the substitution
// search, which answers a power of a linear and an odd power of x beside a function of
// x^2 more shortly: `1/(c (a + b x)^2)^(5/2)` in 64 characters, where this writes 98.
if ((answer = IndefiniteIntegralSolver.SolveByTakingAWholePowerOutOfAPowerOfAProduct(expr, x, integrateByParts)) is { }) return answer;
// A logarithmic derivative the substitution above could not read for a symbol in
// an exponent: `(x^(n-1) - 1)/(x^n - n x)`.
if ((answer = IndefiniteIntegralSolver.SolveALogarithmicDerivativeWithASymbolicExponent(expr, x)) is { }) return answer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using System;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A power that is not whole of a constant times a whole power of something of x,
/// <c>(c S^k)^p</c>, as <c>K S^(k p)</c> with <c>K</c> constant where <c>S</c> is not zero.
/// Rubi's 1.3.2:338-352, which the substitution search, asked first, declines.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
/// <remarks>
/// Checked by differentiating back with <c>a = -1.3</c>, <c>b = 0.7</c> and <c>c = 0.4</c>, on
/// both sides of 0 and of the roots of <c>a + b x^2</c>, where <c>K</c> changes sign, wherever
/// the integrand is real.
/// </remarks>
[Trait("Area", "Calculus")]
public sealed class WholePowerOutOfAPowerOfAProductIntegralTest
{
private static readonly double[] Points = { -2.3, -1.9, -0.8, -0.3, 0.4, 0.9, 1.9, 2.3 };

[Theory]
[InlineData("x^2*(c*(a + b*x^2)^2)^(3/2)")]
[InlineData("x^4*(c*(a + b*x^2)^2)^(3/2)")]
[InlineData("(c*(a + b*x^2)^2)^(3/2)")]
[InlineData("(c*(a + b*x^2)^2)^(3/2)/x^2")]
[InlineData("(c*(a + b*x^2)^3)^(3/2)")]
[InlineData("(c*(a + b*x^2)^3)^(3/2)/x^2")]
public void IsIntegrated(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
Assert.DoesNotContain("integral(", integral.Stringize());
Entity Pinned(Entity e) => e.Substitute("a", -1.3).Substitute("b", 0.7).Substitute("c", 0.4);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
var compared = 0;
foreach (var at in Points)
{
var want = original.Substitute("x", at).EvalNumerical();
if (want.IsNaN || Math.Abs((double)want.ImaginaryPart) > 1e-12 * Math.Max(1, Math.Abs((double)want.RealPart)))
continue;
var got = derivative.Substitute("x", at).EvalNumerical();
compared++;
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)),
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
Assert.True(compared >= 4, $"only {compared} points were real for {integrand}");
}
}
}
Loading