Skip to content

Commit b82ab99

Browse files
A function of a quotient of two linears is integrated over the quotient's denominator (#1771)
sin((a + b x)/(c + d x)) was declined, with the rest of Rubi's 4.7.7, 6.1.5 and 6.2.5 sines, cosines, hyperbolic sines and cosines and their powers of a quotient of two linears. (a + b x)/(c + d x) is b/d + (a d - b c)/(d (c + d x)); written so, sin(p + k/(c + d x)) is answered in the sine and cosine integrals and e^(p + k/(c + d x)) in the exponential integral. The constant and the multiple are named while the question is asked, and a constant in front of the quotient stays in front, so that e^Q and e^(-Q) keep one argument between them. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 85d6601 commit b82ab99

4 files changed

Lines changed: 169 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,23 @@ polynomial exponent in `u` now, and the question asked in `u`. Rubi's 2.3
390390
| `"F^(a + b/(c + d*x))/(c + d*x)".ToEntity().Integrate("x")` | `integral(...)` | an exponential integral |
391391
| `"F^(a + b/(c + d*x)^3)*(c + d*x)^2".ToEntity().Integrate("x")` | `integral(...)` | an exponential integral of the cube, and the exponential |
392392

393+
### A function of a quotient of two linears is integrated over the quotient's denominator
394+
395+
**Answers where there were none.** `sin((a + b x)/(c + d x))` and its powers were declined, and so
396+
were the cosine's, the hyperbolic sine's and cosine's and the exponential of the same quotient,
397+
where `sin(p + k/(c + d x))` is answered in the sine and cosine integrals and `e^(p + k/(c + d x))`
398+
in the exponential integral. The quotient is one of those: `b/d + (a d - b c)/(d (c + d x))`, by
399+
polynomial division, for `d` and `a d - b c` not zero. Each such argument is written so and the
400+
question asked again. Rubi's 4.7.7, 6.1.5 and 6.2.5
401+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
402+
403+
| Input | Was (2.5.0) | Now |
404+
|---|---|---|
405+
| `"sin((a + b*x)/(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | in the sine and cosine integrals of `(a d - b c)/(d (c + d x))` |
406+
| `"cos((a + b*x)/(c + d*x))^2".ToEntity().Integrate("x")` | `integral(...)` | in the sine and cosine integrals of twice that |
407+
| `"sinh((a + b*x)/(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | in the exponential integrals of `±(a d - b c)/(d (c + d x))` |
408+
| `"e^((a + b*x)/(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | in the exponential integral of `(a d - b c)/(d (c + d x))` |
409+
393410
### A polynomial over a power of a binomial past the cube is integrated
394411

395412
**Answers where there were none.** `P(x)/(a + b x^n)^k` with symbols in the binomial, `n >= 3`, was

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11418,6 +11418,97 @@ static bool IsEvenIn(Entity polynomial, Entity.Variable even, Entity.Variable ot
1141811418
return !inPlaceholder.ContainsNode(x) && TreeAnalyzer.TryGetPolynomial(inPlaceholder, placeholder, out _);
1141911419
}
1142011420

11421+
/// <summary>
11422+
/// A function whose argument is a quotient of two linears, <c>(a + b x)/(c + d x)</c>, with
11423+
/// that argument written over the denominator: <c>b/d + (a d - b c)/(d (c + d x))</c>, a
11424+
/// constant plus a multiple of the reciprocal of a linear.
11425+
/// </summary>
11426+
/// <remarks>
11427+
/// <para>
11428+
/// Rubi's <c>sin((a + b x)/(c + d x))</c> and its powers were declined, and the hyperbolic
11429+
/// sine and cosine of the same, written in exponentials, likewise, where
11430+
/// <c>sin(a + k/(c + d x))</c> is answered in sines and cosine integrals and
11431+
/// <c>e^(a + k/(c + d x))</c> in exponential integrals: those rules read a reciprocal of a
11432+
/// linear, and a quotient of two linears is one plus a constant. Exact: polynomial division,
11433+
/// for <c>d</c> and <c>a d - b c</c> not zero, as everywhere in the integrator.
11434+
/// </para>
11435+
/// <para>
11436+
/// The arguments of the sine, cosine, tangent, cotangent, secant and cosecant and the
11437+
/// exponents of the exponential, each written so; the same question in another spelling.
11438+
/// https://github.com/asc-community/AngouriMath/issues/718
11439+
/// </para>
11440+
/// </remarks>
11441+
internal static Entity? SolveByWritingAQuotientOfLinearsOverItsDenominator(Entity expr, Entity.Variable x, bool integrateByParts)
11442+
{
11443+
var names = new Dictionary<Variable, Entity>();
11444+
Entity? Divided(Entity argument)
11445+
{
11446+
// Written as a quotient, or a constant times one: the sum this writes is neither,
11447+
// so the same question asked again does not divide it a second time.
11448+
Entity factor = Number.Integer.One;
11449+
var quotient = argument;
11450+
// The product's two children as written: read through, `-(a + b x)/(c + d x)` as a
11451+
// constant times a quotient is a quotient taken apart into its factors.
11452+
if (argument is Mulf(var left, var right))
11453+
(factor, quotient) = left.ContainsNode(x) ? (right, left) : (left, right);
11454+
if (factor.ContainsNode(x))
11455+
return null;
11456+
if (quotient is not Divf(var above, var below))
11457+
return null;
11458+
if (!below.ContainsNode(x) || !above.ContainsNode(x)
11459+
|| !TreeAnalyzer.TryGetPolyLinear(above, x, out var b, out var a) || b.ContainsNode(x) || a.ContainsNode(x)
11460+
|| !TreeAnalyzer.TryGetPolyLinear(below, x, out var d, out var c) || d.ContainsNode(x) || c.ContainsNode(x))
11461+
return null;
11462+
var remainder = (a * d - b * c).InnerSimplified;
11463+
if (remainder.Evaled is Number.Complex { IsZero: true } || d.Evaled is Number.Complex { IsZero: true })
11464+
return null;
11465+
// The constant and the multiple named, each a symbol of its own while the question
11466+
// is asked: `sin(b/d + ((a d - b c)/d)/(c + d x))` was declined where
11467+
// `sin(p + k/(c + d x))` is answered, the rules reading a symbol where they meet a
11468+
// quotient of symbols.
11469+
Entity Named(Entity value)
11470+
{
11471+
value = value.InnerSimplified;
11472+
if (value is Variable || value is Number)
11473+
return value;
11474+
foreach (var pair in names)
11475+
if (pair.Value == value)
11476+
return pair.Key;
11477+
var name = Variable.CreateUnique(expr + names.Keys.Aggregate((Entity)Number.Integer.Zero, (sum, v) => sum + v), "k_quotient");
11478+
names[name] = value;
11479+
return name;
11480+
}
11481+
// A constant in front stays in front, so that `e^Q` and `e^(-Q)` keep one argument
11482+
// and their product is 1.
11483+
var divided = Named(b / d) + Named(remainder / d) / below;
11484+
return factor == Number.Integer.One ? divided : factor * divided;
11485+
}
11486+
var changed = false;
11487+
var rewritten = expr.Replace(node =>
11488+
{
11489+
Entity? divided;
11490+
switch (node)
11491+
{
11492+
case Sinf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Sin(divided);
11493+
case Cosf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Cos(divided);
11494+
case Tanf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Tan(divided);
11495+
case Cotanf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Cotan(divided);
11496+
case Secantf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Sec(divided);
11497+
case Cosecantf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Cosec(divided);
11498+
case Powf(var @base, var exponent) when @base == MathS.e && (divided = Divided(exponent)) is not null:
11499+
changed = true;
11500+
return MathS.Pow(MathS.e, divided);
11501+
default:
11502+
return node;
11503+
}
11504+
});
11505+
if (!changed || Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts) is not { } answer)
11506+
return null;
11507+
foreach (var pair in names)
11508+
answer = answer.Substitute(pair.Key, pair.Value);
11509+
return answer;
11510+
}
11511+
1142111512
/// <summary>
1142211513
/// Trigonometric functions of several arguments that are whole or rational multiples of one
1142311514
/// linear, <c>p + q x</c>, written in <c>u = p + q x</c>: <c>csc(a + b x) csc(2a + 2b x)^2</c>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,16 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
876876
if ((answer = IndefiniteIntegralSolver.SolveByTheHalfAngleWhereOnePlusAHyperbolicCosineIsASquare(expr, x, integrateByParts)) is { }) return answer;
877877
// The hyperbolic sine's, off the real line: 1 + i sinh(y) is (cosh(y/2) + i sinh(y/2))^2.
878878
if ((answer = IndefiniteIntegralSolver.SolveAHalfOddPowerOfOnePlusAnImaginaryHyperbolicSine(expr, x, integrateByParts)) is { }) return answer;
879-
// Several trigonometric arguments that are multiples of one linear with an offset or a
880-
// symbolic slope, written in that linear: before the substitution search, which reads
881-
// each function on its own.
879+
// A quotient of linears as a function's argument, written over its denominator: a
880+
// constant plus a multiple of the reciprocal of a linear, which the rules read.
881+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAQuotientOfLinearsOverItsDenominator(expr, x, integrateByParts)) is { }) return answer;
882882
// A cosine and a sine over a power of another such sum, through the denominator, its
883883
// derivative and a constant, down to the reciprocal of the base: before the substitution
884884
// search, which reads the quotient term by term.
885885
if ((answer = IndefiniteIntegralSolver.SolveACosineAndASineOverAPowerOfAnother(expr, x, integrateByParts)) is { }) return answer;
886+
// Several trigonometric arguments that are multiples of one linear with an offset or a
887+
// symbolic slope, written in that linear: before the substitution search, which reads
888+
// each function on its own.
886889
if ((answer = IndefiniteIntegralSolver.SolveByWritingMultiplesOfOneLinearArgument(expr, x, integrateByParts)) is { }) return answer;
887890
// Two tangents, cotangents, secants or cosecants of arguments a constant apart, written
888891
// as functions of each alone by the addition formulas.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
/// A sine, cosine or exponential of a quotient of two linears, <c>(a + b x)/(c + d x)</c>,
16+
/// written as the constant <c>b/d</c> plus <c>(a d - b c)/d</c> over <c>c + d x</c>, and
17+
/// answered in the sine, cosine and exponential integrals. Rubi's 4.7.7, 6.1.5 and 6.2.5.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
/// <remarks>
21+
/// Checked by differentiating back with <c>a = 0.3</c>, <c>b = 0.9</c>, <c>c = 1.1</c>,
22+
/// <c>d = 0.7</c>, on both sides of the pole at <c>c + d x = 0</c>.
23+
/// </remarks>
24+
[Trait("Area", "Calculus")]
25+
public sealed class QuotientOfLinearsAsAnArgumentIntegralTest
26+
{
27+
[Theory]
28+
[InlineData("sin((a + b*x)/(c + d*x))")]
29+
[InlineData("sin((a + b*x)/(c + d*x))^2")]
30+
[InlineData("sin((a + b*x)/(c + d*x))^3")]
31+
[InlineData("cos((a + b*x)/(c + d*x))")]
32+
[InlineData("cos((a + b*x)/(c + d*x))^2")]
33+
[InlineData("sinh((a + b*x)/(c + d*x))")]
34+
[InlineData("sinh((a + b*x)/(c + d*x))^3")]
35+
[InlineData("cosh((a + b*x)/(c + d*x))^2")]
36+
[InlineData("e^((a + b*x)/(c + d*x))")]
37+
[InlineData("sin(2*(a + b*x)/(c + d*x))")]
38+
public void IsWrittenOverTheDenominator(string integrand)
39+
{
40+
var integral = integrand.ToEntity().Integrate("x");
41+
Assert.DoesNotContain("integral(", integral.Stringize());
42+
Entity Pinned(Entity e) => e.Substitute("a", 0.3).Substitute("b", 0.9).Substitute("c", 1.1).Substitute("d", 0.7);
43+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
44+
var original = Pinned(integrand.ToEntity());
45+
foreach (var at in new[] { -2.5, -2.0, 0.3, 0.8, 1.4 })
46+
{
47+
var want = original.Substitute("x", at).EvalNumerical();
48+
var got = derivative.Substitute("x", at).EvalNumerical();
49+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
50+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
51+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)