Skip to content

Commit 85d6601

Browse files
Two tangents of arguments a constant apart are written apart (#1767)
tan(a + b x) tan(c + b x) was declined, with the secants, cotangents and cosecants the same way and the products whose arguments add to a constant, the eight of Rubi's 4.7.7. The addition formulas, read for the product: for a constant d = A - B, tan(A) tan(B) = cot(d) (tan(A) - tan(B)) - 1, cot(A) cot(B) = cot(d) (cot(B) - cot(A)) - 1, sec(A) sec(B) = csc(d) (tan(A) - tan(B)) and csc(A) csc(B) = csc(d) (cot(B) - cot(A)); for a constant A + B the same with the signs of the sums. 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 9d8662d commit 85d6601

4 files changed

Lines changed: 138 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,19 @@ read them as nonzero. They are now decided over one bar, expanded, and at pinned
826826
| `"e^(3*acoth(a*x))/(c-a*c*x)^3".Integrate("x")`, and over `(c - a c x)^4` | left unevaluated | an antiderivative in `sqrt((a x + 1)/(a x - 1))` |
827827
| `"e^(2*acoth(a*x))*sqrt(c-a*c*x)/x".Integrate("x")`, and over `x^2` | left unevaluated | an antiderivative in `sqrt(c - a c x)`, by cases on the sign of `c` |
828828

829+
### Two tangents of arguments a constant apart are written apart
830+
831+
**Answers where there were none.** `tan(a + b x) tan(c + b x)` was declined, with the secants,
832+
cotangents and cosecants the same way and the products whose arguments add to a constant, Rubi's
833+
4.7.7. By the addition formulas each such product is the functions of the two arguments apart:
834+
`tan(A) tan(B) = cot(A - B) (tan(A) - tan(B)) - 1` and its kin, for `A - B` or `A + B` a constant
835+
that is not a multiple of `pi` ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
836+
837+
| Input | Was (2.5.0) | Now |
838+
|---|---|---|
839+
| `"tan(a + b*x)*tan(c + b*x)".ToEntity().Integrate("x")` | `integral(...)` | `cot(a - c) (ln(cos(c + b x)) - ln(cos(a + b x)))/b - x` |
840+
| `"sec(c - b*x)*sec(a + b*x)".ToEntity().Integrate("x")` | `integral(...)` | `csc(a + c) (ln(cos(c - b x)) - ln(cos(a + b x)))/b` |
841+
829842
### A trigonometric function of an imaginary multiple of a logarithm is integrated in exponentials
830843

831844
**Answers where there were none.** `tan(a + i ln(x))` and `sin(a + ln(c x^2) sqrt(-1/4))` were

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8821,6 +8821,76 @@ private static (Entity Coefficient, Entity Degree)? TheMonomial(Entity expr, Ent
88218821
return null;
88228822
}
88238823

8824+
/// <summary>
8825+
/// A product of two tangents, cotangents, secants or cosecants of linear arguments whose
8826+
/// difference or sum is a constant, written as the functions of each apart: with
8827+
/// <c>d = A - B</c>, <c>tan(A) tan(B) = cot(d) (tan(A) - tan(B)) - 1</c>.
8828+
/// </summary>
8829+
/// <remarks>
8830+
/// <para>
8831+
/// The addition formulas, read for the product: for a constant <c>d = A - B</c>,
8832+
/// <c>tan(A) tan(B) = cot(d) (tan(A) - tan(B)) - 1</c>,
8833+
/// <c>cot(A) cot(B) = cot(d) (cot(B) - cot(A)) - 1</c>,
8834+
/// <c>sec(A) sec(B) = csc(d) (tan(A) - tan(B))</c> and
8835+
/// <c>csc(A) csc(B) = csc(d) (cot(B) - cot(A))</c>; for a constant <c>s = A + B</c>,
8836+
/// <c>tan(A) tan(B) = 1 - cot(s) (tan(A) + tan(B))</c>,
8837+
/// <c>cot(A) cot(B) = 1 + cot(s) (cot(A) + cot(B))</c>,
8838+
/// <c>sec(A) sec(B) = csc(s) (tan(A) + tan(B))</c> and
8839+
/// <c>csc(A) csc(B) = csc(s) (cot(A) + cot(B))</c>. Each holds wherever both sides are
8840+
/// defined, for <c>d</c> or <c>s</c> not a multiple of <c>pi</c>, which a symbolic one is
8841+
/// taken not to be, as everywhere in this integrator. Rubi's 4.7.7 has
8842+
/// <c>tan(a + b x) tan(c + b x)</c> and the rest, and nothing read two arguments.
8843+
/// </para>
8844+
/// <para>
8845+
/// The same question in another spelling, so asked as it. A constant times the product
8846+
/// only, and the two functions of one kind.
8847+
/// https://github.com/asc-community/AngouriMath/issues/718
8848+
/// </para>
8849+
/// </remarks>
8850+
internal static Entity? SolveByWritingTwoFunctionsOfShiftedArgumentsApart(Entity expr, Entity.Variable x, bool integrateByParts)
8851+
{
8852+
Entity constant = Number.Integer.One;
8853+
Entity? first = null, second = null;
8854+
foreach (var factor in Mulf.LinearChildren(expr))
8855+
{
8856+
if (!factor.ContainsNode(x))
8857+
constant = constant == Number.Integer.One ? factor : constant * factor;
8858+
else if (first is null)
8859+
first = factor;
8860+
else if (second is null)
8861+
second = factor;
8862+
else
8863+
return null;
8864+
}
8865+
if (first is null || second is null || first.GetType() != second.GetType()
8866+
|| first is not (Tanf or Cotanf or Secantf or Cosecantf))
8867+
return null;
8868+
var a = first.DirectChildren.First();
8869+
var b = second.DirectChildren.First();
8870+
if (a == b || !TreeAnalyzer.TryGetPolyLinear(a, x, out var slopeOfA, out _) || slopeOfA.ContainsNode(x)
8871+
|| !TreeAnalyzer.TryGetPolyLinear(b, x, out var slopeOfB, out _) || slopeOfB.ContainsNode(x))
8872+
return null;
8873+
static bool IsZero(Entity value) => value.Expand().InnerSimplified.Evaled is Number.Complex { IsZero: true };
8874+
var sameSlope = IsZero(slopeOfA - slopeOfB);
8875+
if (!sameSlope && !IsZero(slopeOfA + slopeOfB))
8876+
return null;
8877+
var shift = (sameSlope ? a - b : a + b).Expand().InnerSimplified;
8878+
if (shift.ContainsNode(x) || shift.Evaled is Number.Complex { IsZero: true })
8879+
return null;
8880+
Entity apart = first switch
8881+
{
8882+
Tanf => sameSlope
8883+
? MathS.Cotan(shift) * (MathS.Tan(a) - MathS.Tan(b)) - 1
8884+
: 1 - MathS.Cotan(shift) * (MathS.Tan(a) + MathS.Tan(b)),
8885+
Cotanf => sameSlope
8886+
? MathS.Cotan(shift) * (MathS.Cotan(b) - MathS.Cotan(a)) - 1
8887+
: 1 + MathS.Cotan(shift) * (MathS.Cotan(a) + MathS.Cotan(b)),
8888+
Secantf => MathS.Cosec(shift) * (sameSlope ? MathS.Tan(a) - MathS.Tan(b) : MathS.Tan(a) + MathS.Tan(b)),
8889+
_ => MathS.Cosec(shift) * (sameSlope ? MathS.Cotan(b) - MathS.Cotan(a) : MathS.Cotan(a) + MathS.Cotan(b)),
8890+
};
8891+
return Integration.ComputeAsTheSameQuestion(constant == Number.Integer.One ? apart : constant * apart, x, integrateByParts);
8892+
}
8893+
88248894
/// <summary>
88258895
/// A quotient of two <b>homogeneous</b> polynomials in <c>sin(u)</c> and <c>cos(u)</c>,
88268896
/// integrated by <c>t = tan(u)</c> — which turns it into a rational function of <c>t</c>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
884884
// search, which reads the quotient term by term.
885885
if ((answer = IndefiniteIntegralSolver.SolveACosineAndASineOverAPowerOfAnother(expr, x, integrateByParts)) is { }) return answer;
886886
if ((answer = IndefiniteIntegralSolver.SolveByWritingMultiplesOfOneLinearArgument(expr, x, integrateByParts)) is { }) return answer;
887+
// Two tangents, cotangents, secants or cosecants of arguments a constant apart, written
888+
// as functions of each alone by the addition formulas.
889+
if ((answer = IndefiniteIntegralSolver.SolveByWritingTwoFunctionsOfShiftedArgumentsApart(expr, x, integrateByParts)) is { }) return answer;
887890
// A constant out of a fractional power of a trigonometric factor: `sqrt(b sec(x))` is
888891
// `sqrt(b) sqrt(sec(x))` for a positive `b`, which meets the other powers of the
889892
// secant beside it. After the rules that answer the same shapes for any real
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
/// Two tangents, cotangents, secants or cosecants of arguments whose difference or sum is a
16+
/// constant, written as the functions of each apart by the addition formulas. Rubi's 4.7.7.
17+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
18+
/// </summary>
19+
/// <remarks>
20+
/// Checked by differentiating back with <c>a = 0.3</c>, <c>b = 0.9</c>, <c>c = 1.1</c>, on
21+
/// both sides of zero and away from the poles of every function of the three arguments.
22+
/// </remarks>
23+
[Trait("Area", "Calculus")]
24+
public sealed class TwoFunctionsOfShiftedArgumentsIntegralTest
25+
{
26+
[Theory]
27+
[InlineData("tan(a + b*x)*tan(c + b*x)")]
28+
[InlineData("tan(c - b*x)*tan(a + b*x)")]
29+
[InlineData("cot(a + b*x)*cot(c + b*x)")]
30+
[InlineData("cot(c - b*x)*cot(a + b*x)")]
31+
[InlineData("sec(a + b*x)*sec(c + b*x)")]
32+
[InlineData("sec(c - b*x)*sec(a + b*x)")]
33+
[InlineData("csc(a + b*x)*csc(c + b*x)")]
34+
[InlineData("csc(c - b*x)*csc(a + b*x)")]
35+
public void IsWrittenApartByTheAdditionFormulas(string integrand)
36+
{
37+
var integral = integrand.ToEntity().Integrate("x");
38+
Assert.DoesNotContain("integral(", integral.Stringize());
39+
Entity Pinned(Entity e) => e.Substitute("a", 0.3).Substitute("b", 0.9).Substitute("c", 1.1);
40+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
41+
var original = Pinned(integrand.ToEntity());
42+
foreach (var at in new[] { -1.0, -0.8, 0.1, 0.2, 0.9, 1.0 })
43+
{
44+
var want = original.Substitute("x", at).EvalNumerical();
45+
var got = derivative.Substitute("x", at).EvalNumerical();
46+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
47+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
48+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)