Skip to content

Commit 4009f74

Browse files
A function of one linear under a power inside a sum is written in that linear (#1702)
* A linear under a power inside a sum is written as the variable x^3/(a + b (c + d x)^3) was declined, and so was (c + d x)^4 over it: in x, the binomial is a polynomial whose roots are those of a + b u^3 moved and scaled, which the partial fractions do not read, and the substitution search reads one function at a time. Written in u = c + d x it is (u - c)^3/(d^4 (a + b u^3)), which the rules for a binomial answer. Rubi's 1.1.3.2, 1.2.3.2 and 1.3.1 write whole sections so. Only where one linear, up to a constant multiple, stands under the powers inside sums, with an offset or a slope other than 1, and x stands nowhere but in sums, products, quotients and powers: written in u, nothing is left in x. First but one, before the polynomial term, which takes the leading coefficient out of a power of the sum and writes what is left in powers of x, where the linear is gone. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * The breaking-changes entry for a function of one linear inside a sum Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 879fb2d commit 4009f74

4 files changed

Lines changed: 155 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,22 @@ one reads a numeric slope, and writes an offset out by the addition formula, whi
475475
| `"csc(1+x)*csc(2+2*x)^2".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `cos(1 + x)` |
476476
| `"sin(a+b*x)^3/sin(2*a+2*b*x)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `tan(a + b x)` |
477477

478+
### A function of one linear under a power inside a sum is written in that linear
479+
480+
`x^3/(a + b (c + d x)^3)` was left unevaluated, and `(c + d x)^4/(a + b (c + d x)^3)` ran for more
481+
than eighty seconds. Written in `x`, the sum is a polynomial whose roots are those of a binomial
482+
moved and scaled, which the partial fractions do not read. Where one linear `c + d x` stands under
483+
the powers inside sums, and `x` elsewhere only in sums, products and powers, the integrand is
484+
written in `u = c + d x` first. Rubi's 1.1.3.2, 1.2.3.2 and 1.3.1 write whole sections so
485+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
486+
487+
| Input | Was (2.5.0) | Now |
488+
|---|---|---|
489+
| `"x^3/(a + b*(c + d*x)^3)".ToEntity().Integrate("x")` | `integral(...)` | powers and logarithms of `c + d x` and of a quadratic in it, and an arctangent |
490+
| `"(c + d*x)^4/(a + b*(c + d*x)^3)".ToEntity().Integrate("x")` | ran for more than eighty seconds | `(c + d x)^2/(2 b)`, and the same logarithms and arctangent |
491+
| `"(c*m + d*m*x)^3/(a + b*(c + d*x)^3)^2".ToEntity().Integrate("x")` | `integral(...)` | `m^3` times a rational function of `c + d x`, the logarithms and the arctangent |
492+
| `"(c + d*x)^4/(a + b*(c + d*x)^2 + k*(c + d*x)^4)^2".ToEntity().Integrate("x")` | `integral(...)` | a rational function of `c + d x` and arctangents |
493+
478494
### A root of an even power is the modulus, and is no longer read as the power
479495

480496
**Wrong answers, silent.** `(u^2)^(3/2)` is `|u|^3`, and two readers took it for `u^3`: the

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9248,6 +9248,70 @@ static bool IsEvenIn(Entity polynomial, Entity.Variable even, Entity.Variable ot
92489248
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
92499249
}
92509250

9251+
/// <summary>
9252+
/// An algebraic integrand in which a linear <c>c + d x</c> stands under a power inside a
9253+
/// sum, written in <c>u = c + d x</c>: <c>x^3/(a + b (c + d x)^3)</c> is
9254+
/// <c>(u - c)^3/(d^4 (a + b u^3))</c>, and <c>(c + d x)^4/(a + b (c + d x)^3)</c> is
9255+
/// <c>u^4/(d (a + b u^3))</c>, which the rules for a binomial answer.
9256+
/// </summary>
9257+
/// <remarks>
9258+
/// In x the sum is a polynomial whose roots are those of <c>a + b u^n</c> moved and
9259+
/// scaled, which the partial fractions do not read, and the substitution search reads
9260+
/// one function at a time: Rubi's 1.1.3.2, 1.2.3.2 and 1.3.1 write whole sections so.
9261+
/// Only where one linear, up to a constant multiple, stands under the powers inside sums,
9262+
/// with an offset or a slope other than 1, and x stands nowhere but in polynomials and
9263+
/// powers of them: written in u, nothing is left in x. At the question asked or one below
9264+
/// it, since it lands on the chain in u.
9265+
/// https://github.com/asc-community/AngouriMath/issues/718
9266+
/// </remarks>
9267+
internal static Entity? SolveByWritingAFunctionOfOneShiftedLinear(Entity expr, Entity.Variable x, bool integrateByParts)
9268+
{
9269+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
9270+
return null;
9271+
// Algebraic in x: sums, products, quotients and powers with exponents free of it.
9272+
foreach (var node in expr.Nodes)
9273+
if (node.ContainsNode(x) && node is not (Variable or Sumf or Minusf or Mulf or Divf)
9274+
&& !(node is Powf(_, var exponent) && !exponent.ContainsNode(x)))
9275+
return null;
9276+
Entity? linear = null;
9277+
Entity? slope = null;
9278+
Entity? offset = null;
9279+
foreach (var node in expr.Nodes)
9280+
{
9281+
if (node is not (Sumf or Minusf))
9282+
continue;
9283+
foreach (var term in Sumf.LinearChildren(node))
9284+
foreach (var factor in Mulf.LinearChildren(term))
9285+
{
9286+
if (factor is not Powf(var @base, _) || !@base.ContainsNode(x)
9287+
|| !TreeAnalyzer.TryGetPolyLinear(@base, x, out var d, out var c)
9288+
|| d.ContainsNode(x) || c.ContainsNode(x) || TreeAnalyzer.IsZero(d))
9289+
continue;
9290+
if (linear is null)
9291+
(linear, slope, offset) = (@base, d, c);
9292+
else if (!VanishesIdentically(slope! * c - d * offset!))
9293+
return null;
9294+
}
9295+
}
9296+
if (linear is null || slope is null || offset is null
9297+
|| VanishesIdentically(offset) && VanishesIdentically(slope - 1))
9298+
return null;
9299+
// x = (u - c)/d, and each base linear in u written as one.
9300+
var u = Variable.CreateUnique(expr, "u_linear");
9301+
var inU = expr.Substitute(x, (u - offset) / slope).InnerSimplified.Replace(node =>
9302+
node is Powf(var @base, var power) && @base.ContainsNode(u)
9303+
&& TreeAnalyzer.TryGetPolyLinear(@base, u, out var d, out var c) && !d.ContainsNode(u) && !c.ContainsNode(u)
9304+
? MathS.Pow(Functions.PartialFractions.InLowestTermsOverTheSymbols(d) * u + Functions.PartialFractions.InLowestTermsOverTheSymbols(c), power)
9305+
: node);
9306+
if (inU.ContainsNode(x))
9307+
return null;
9308+
// dx = du/d.
9309+
if (Integration.ComputeAsAQuestionOfItsOwn((inU / slope).InnerSimplified, u, integrateByParts) is not { } answer)
9310+
return null;
9311+
var back = answer.Substitute(u, linear);
9312+
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
9313+
}
9314+
92519315
/// <summary>
92529316
/// An integrand whose trigonometric functions have <b>different multiples</b> of one
92539317
/// argument — <c>sin(x)/cos(2x)</c>, <c>cos(x)/(sin(x) tan(x/2))</c> — rewritten so that

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
611611
// the question asked only, and the polynomial term below writes `1/u` as `u^(-1)` and
612612
// asks that a level down: `1/(e^atanh(a x) (c - c/(a x))^(3/2))` reached it nowhere.
613613
if ((answer = IndefiniteIntegralSolver.SolveByWritingEachLinearOnce(expr, x, integrateByParts)) is { }) return answer;
614+
// A linear under a power inside a sum, written as the variable: `x^3/(a + b (c + d x)^3)`.
615+
// Before the polynomial term, which takes the leading coefficient out of a power of
616+
// the sum and writes what is left out in powers of x, where the linear is gone; and
617+
// before the substitution search, which reads one function at a time.
618+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAFunctionOfOneShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
614619
if ((answer = IndefiniteIntegralSolver.SolveAsPolynomialTerm(expr, x, integrateByParts)) is { }) return answer;
615620
// A product of powers of the variable with a power of a constant multiple of it
616621
// among them, `(c x)^m x^n`, by the power rule with the written power kept as
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// An algebraic integrand with a linear <c>c + d x</c> under a power inside a sum, written in
16+
/// <c>u = c + d x</c>, as Rubi's 1.1.3.2, 1.2.3.2 and 1.3.1 write whole sections of it.
17+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
18+
/// </summary>
19+
/// <remarks>
20+
/// Checked by differentiating back at points where the integrand is real, never against a
21+
/// printed form.
22+
/// </remarks>
23+
[Trait("Area", "Calculus")]
24+
public sealed class OneShiftedLinearIntegralTest
25+
{
26+
private static void DifferentiatesBack(string integrand, double[] points, params (string, double)[] pins)
27+
{
28+
var integral = integrand.ToEntity().Integrate("x");
29+
Assert.DoesNotContain("integral(", integral.Stringize());
30+
31+
var derivative = integral.Substitute("C", 0).Differentiate("x");
32+
Entity original = integrand.ToEntity();
33+
foreach (var (name, value) in pins)
34+
{
35+
derivative = derivative.Substitute(name, value);
36+
original = original.Substitute(name, value);
37+
}
38+
var compared = 0;
39+
foreach (var at in points)
40+
{
41+
var got = derivative.Substitute("x", at).EvalNumerical();
42+
var want = original.Substitute("x", at).EvalNumerical();
43+
if (got.IsNaN || want.IsNaN)
44+
continue;
45+
compared++;
46+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
47+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
48+
Assert.True(difference / scale < 1e-9,
49+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, "
50+
+ $"where the integrand is {want}");
51+
}
52+
Assert.True(compared >= 3, $"only {compared} points could be compared for {integrand}");
53+
}
54+
55+
/// <summary>
56+
/// A binomial and a trinomial in the linear, with the variable outside it as a power of
57+
/// x, as a power of the linear, or as a multiple of the linear: each declined, or ran past
58+
/// twenty seconds, written in x.
59+
/// </summary>
60+
[Theory]
61+
[InlineData("x^3/(a + b*(c + d*x)^3)")]
62+
[InlineData("(c + d*x)^4/(a + b*(c + d*x)^3)")]
63+
[InlineData("1/((c + d*x)^4*(a + b*(c + d*x)^3))")]
64+
[InlineData("(c*m + d*m*x)^3/(a + b*(c + d*x)^3)^2")]
65+
[InlineData("(c + d*x)^4/(a + b*(c + d*x)^2 + k*(c + d*x)^4)^2")]
66+
public void WrittenInTheLinear(string integrand)
67+
=> DifferentiatesBack(integrand, new[] { 0.3, 0.9, 1.7, 2.6 },
68+
("a", 1.3), ("b", 0.7), ("c", 0.4), ("d", 1.1), ("k", 0.6), ("m", 2.3));
69+
}
70+
}

0 commit comments

Comments
 (0)