Skip to content

Commit fa542e0

Browse files
Two linear factors whose product is a multiple of the radicand arsinh holds are written as that radicand (#1488)
`(a + b arsinh(c x)) sqrt(d + i c d x) sqrt(f - i c f x)` ran out of time. The two linear factors multiply to `d f (1 + c^2 x^2)`, a constant multiple of the radicand `arsinh(c x) = ln(c x + sqrt(c^2 x^2 + 1))` holds -- the case #1487 answers, spelled as two factors. Rubi's 7.1.4 writes seventy-two of its 663 rows this way. `L1^p L2^q` with `p - q` whole is now `L1^(p - q) L1^q L2^q`, and `L1^q L2^q` is `lambda^q M^q` for a whole `q` and `K^k M^(k/2)` for `q = k/2`, with `K = sqrt(L1) sqrt(L2)/sqrt(M)` carried as a symbol and written in front of the answer: constant wherever it is defined, as #1487's is. Tried only where no single base is a multiple of the radicand, on the factors of both sides of the bar, with a nested power read through and a factor below the bar read with its exponent negated. Rubi's 7.1.4 and 7.1.5, all 376 problems that count: 308 to 345, no row lost, 56 timeouts to 27. Family 7 235 to 237 of 270; the 7.2 files, families 1, 4, 5 and 6 and the 1774-problem suite unchanged, row for row. The answers are complex-valued along the whole line and are exact at five points each compared as complex numbers, with a negative `d` among the pins. Part of #718. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent d7c0be5 commit fa542e0

3 files changed

Lines changed: 129 additions & 4 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,21 @@ is real on `(-1/2, 1/2)`, where `arcosh(2x)` is `i arccos(2x)`.
14101410

14111411
Rubi's 7.2.4 and 7.2.5, all 277 problems that count: 127 to 255, no row lost, 121 timeouts to 18.
14121412

1413+
### Two linear factors whose product is a multiple of the radicand `arsinh` holds are written as that radicand
1414+
1415+
`(a + b arsinh(c x)) sqrt(d + i c d x) sqrt(f - i c f x)` ran out of time. The two linear factors
1416+
multiply to `d f (1 + c^2 x^2)`, a constant multiple of the radicand `arsinh(c x) =
1417+
ln(c x + sqrt(c^2 x^2 + 1))` holds -- the entry above's case, spelled as two factors. `L1^p L2^q`
1418+
with `p - q` whole is now `L1^(p - q) L1^q L2^q`, and `L1^q L2^q` is `K^k M^(k/2)` for `q = k/2`,
1419+
with `K = sqrt(L1) sqrt(L2)/sqrt(M)` in front of the answer, constant wherever it is defined.
1420+
1421+
| Input | Was (2.5.0) | Now |
1422+
|---|---|---|
1423+
| `"(a+b*asinh(c*x))*sqrt(d+i*c*d*x)*sqrt(f-i*c*f*x)".Integrate("x")` | left unevaluated | in `arsinh(c x)` and `1 + c^2 x^2`, with `K` in front |
1424+
| `"(d+i*c*d*x)^(5/2)*(a+b*asinh(c*x))*sqrt(f-i*c*f*x)".Integrate("x")` | left unevaluated | the same, with `(d + i c d x)^2` beside it |
1425+
1426+
Rubi's 7.1.4 and 7.1.5, all 376 problems that count: 308 to 345, no row lost, 56 timeouts to 27.
1427+
14131428
### `binomial(n, k)` is a function
14141429

14151430
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

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

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15018,21 +15018,95 @@ static bool Through(Entity node, Entity.Variable x)
1501815018
}
1501915019
return node;
1502015020
});
15021+
if (written is not null && reference is not null)
15022+
root = MathS.Sqrt(written) / MathS.Sqrt(reference);
15023+
// And the radicand written as two linear factors, when no single base was its multiple.
15024+
if (rewritten == expr && TryWriteAPairOfLinearsOverARadicand(expr, x, references, multiple, out var paired, out var pairRoot))
15025+
(rewritten, root) = (paired, pairRoot);
1502115026
if (rewritten == expr)
1502215027
return null;
1502315028
var simplified = rewritten.InnerSimplified;
1502415029
if (simplified == expr || simplified == expr.InnerSimplified)
1502515030
return null;
1502615031
if (Integration.ComputeAsTheSameQuestion(simplified, x, integrateByParts) is not { } answer)
1502715032
return null;
15028-
if (written is not null && reference is not null)
15029-
{
15030-
root = MathS.Sqrt(written) / MathS.Sqrt(reference);
15033+
if (root is not null)
1503115034
answer = answer.Substitute(multiple, root);
15032-
}
1503315035
return answer.ContainsNode(multiple) ? null : answer;
1503415036
}
1503515037

15038+
/// <summary>
15039+
/// Two linear factors whose product is a constant multiple of a radicand a logarithm holds,
15040+
/// written as that radicand: `d + i c d x` and `f - i c f x` beside `arsinh(c x)`, whose
15041+
/// product is `d f (1 + c^2 x^2)`. `L1^p L2^q` is `L1^(p - q) L1^q L2^q` where `p - q` is
15042+
/// whole, and `L1^q L2^q` is `lambda^q M^q` for a whole `q` and `K^k M^(k/2)` for
15043+
/// `q = k/2`, with `K = sqrt(L1) sqrt(L2)/sqrt(M)` constant wherever it is defined -- the
15044+
/// same factor the single base is written with. Rubi's 7.1.4 states seventy-two of its
15045+
/// rows this way; `(d + i c d x)^(5/2) sqrt(f - i c f x) (a + b arsinh(c x))` ran past
15046+
/// seventy seconds where the same thing over `1 + c^2 x^2` takes two thirds of one.
15047+
/// </summary>
15048+
private static bool TryWriteAPairOfLinearsOverARadicand(Entity expr, Entity.Variable x, List<Entity> references,
15049+
Entity.Variable multiple, out Entity rewritten, out Entity? root)
15050+
{
15051+
rewritten = expr;
15052+
root = null;
15053+
// The factors on both sides of the bar, as powers: a nested power read through, and a
15054+
// factor below the bar with its exponent negated.
15055+
var (above, below) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr));
15056+
var factors = new List<(Entity Base, Entity Exponent)>();
15057+
foreach (var factor in Mulf.LinearChildren(above))
15058+
factors.Add(AsAPower(factor));
15059+
foreach (var factor in Mulf.LinearChildren(below))
15060+
{
15061+
var (@base, exponent) = AsAPower(factor);
15062+
factors.Add((@base, (-exponent).InnerSimplified));
15063+
}
15064+
for (var i = 0; i < factors.Count; i++)
15065+
for (var j = 0; j < factors.Count; j++)
15066+
{
15067+
if (i == j)
15068+
continue;
15069+
var (first, p) = factors[i];
15070+
var (second, q) = factors[j];
15071+
if (!first.ContainsNode(x) || !second.ContainsNode(x)
15072+
|| !TreeAnalyzer.TryGetPolyLinear(first, x, out _, out _) || !TreeAnalyzer.TryGetPolyLinear(second, x, out _, out _)
15073+
|| (p - q).Evaled is not Number.Integer || q.Evaled is not Number.Rational half)
15074+
continue;
15075+
var twice = (2 * half).Evaled;
15076+
if (half is not Number.Integer && twice is not Number.Integer)
15077+
continue;
15078+
var product = (first * second).Expand();
15079+
foreach (var candidate in references)
15080+
{
15081+
if (TryReadAsAConstantMultiple(product, candidate, x) is not { } lambda)
15082+
continue;
15083+
Entity together;
15084+
if (half is Number.Integer)
15085+
together = MathS.Pow(lambda, half) * MathS.Pow(candidate, half);
15086+
else
15087+
{
15088+
together = MathS.Pow(multiple, twice) * MathS.Pow(candidate, half);
15089+
root = MathS.Sqrt(first) * MathS.Sqrt(second) / MathS.Sqrt(candidate);
15090+
}
15091+
Entity result = MathS.Pow(first, (p - q).InnerSimplified) * together;
15092+
for (var k = 0; k < factors.Count; k++)
15093+
if (k != i && k != j)
15094+
result = result * MathS.Pow(factors[k].Base, factors[k].Exponent);
15095+
rewritten = result;
15096+
return true;
15097+
}
15098+
}
15099+
return false;
15100+
15101+
static (Entity Base, Entity Exponent) AsAPower(Entity factor)
15102+
=> factor switch
15103+
{
15104+
Powf(Powf(var inner, var innerExponent), var outerExponent) => (inner, (innerExponent * outerExponent).InnerSimplified),
15105+
Powf(var @base, var exponent) => (@base, exponent),
15106+
_ => (factor, Number.Integer.One),
15107+
};
15108+
}
15109+
1503615110
/// <summary>
1503715111
/// Whether <paramref name="expr"/>/<paramref name="reference"/> takes the same value at two
1503815112
/// points, every other symbol pinned to a fixed value -- a necessary condition for a

‎Sources/Tests/UnitTests/Calculus/InverseHyperbolicSubstitutionTest.cs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,42 @@ private static void DifferentiatesBack(string integrand, double[] points)
9797
public void AConstantMultipleOfTheRadicandIsWrittenOverIt(string integrand, double[] points)
9898
=> DifferentiatesBack(integrand, points);
9999

100+
/// <summary>
101+
/// The radicand written as two linear factors: <c>(5 + 10 i x)(7 - 14 i x)</c> is
102+
/// <c>35 (1 + 4 x^2)</c>, the radicand of <c>arsinh(2x)</c>, so <c>L1^p L2^q</c> is
103+
/// <c>L1^(p - q) K^k (1 + 4 x^2)^(k/2)</c> with <c>K = sqrt(L1) sqrt(L2)/sqrt(1 + 4 x^2)</c>
104+
/// in front, constant wherever it is defined. Rubi's 7.1.4 and 7.1.5, 39 rows; the
105+
/// integrands are complex everywhere, and compared so.
106+
/// </summary>
107+
[Theory]
108+
[InlineData("(3 + 2*arsinh(2*x))*sqrt(5 + 10*i*x)*sqrt(7 - 14*i*x)", new[] { -0.4, 0.1, 0.3, 0.7, 1.2 })]
109+
[InlineData("(5 + 10*i*x)^(5/2)*(3 + 2*arsinh(2*x))*sqrt(7 - 14*i*x)", new[] { -0.4, 0.1, 0.3, 0.7, 1.2 })]
110+
[InlineData("(5 + 10*i*x)^(3/2)*(7 - 14*i*x)^(3/2)*(3 + 2*arsinh(2*x))", new[] { -0.4, 0.1, 0.3, 0.7, 1.2 })]
111+
[InlineData("x*(3 + 2*arsinh(2*x))*sqrt(5 + 10*i*x)*sqrt(7 - 14*i*x)", new[] { -0.4, 0.1, 0.3, 0.7, 1.2 })]
112+
public void ARadicandWrittenAsTwoLinearFactorsIsWrittenAsOne(string integrand, double[] points)
113+
=> DifferentiatesBack(integrand, points);
114+
115+
/// <summary>The same with every coefficient a symbol, pinned only after integrating.</summary>
116+
[Theory]
117+
[InlineData("(a+b*asinh(c*x))*sqrt(d+i*c*d*x)*sqrt(f-i*c*f*x)")]
118+
[InlineData("(d+i*c*d*x)^(5/2)*(a+b*asinh(c*x))*sqrt(f-i*c*f*x)")]
119+
public void TwoLinearFactorsWithSymbolicCoefficients(string integrand)
120+
{
121+
var integral = integrand.ToEntity().Integrate("x");
122+
Assert.DoesNotContain("integral(", integral.Stringize());
123+
Entity Pin(Entity e) => e.Substitute("a", 0.9).Substitute("b", 1.7).Substitute("c", 0.6).Substitute("d", -1.3).Substitute("f", 0.8);
124+
var derivative = Pin(integral.Substitute("C", 0)).Differentiate("x");
125+
var original = Pin(integrand.ToEntity());
126+
foreach (var at in new[] { -0.4, 0.1, 0.3, 0.7, 1.2 })
127+
{
128+
var got = derivative.Substitute("x", at).EvalNumerical();
129+
var want = original.Substitute("x", at).EvalNumerical();
130+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
131+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
132+
Assert.True(difference / scale < 1e-9, $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
133+
}
134+
}
135+
100136
/// <summary>
101137
/// A root of a *negative* multiple of the quadratic is not the multiple's root times
102138
/// the quadratic's: <c>arcosh(a x)^2/sqrt(1 - a^2 x^2)</c> came back with <c>i a</c>

0 commit comments

Comments
 (0)