Skip to content

Commit feb0e25

Browse files
A sine of a double argument beside the argument is written as a product (#1826)
sin(2A) = 2 sin(A) cos(A) is one product whatever its power, so it is written so beside functions of A for any slope, where the rule for multiples of one argument reads a numeric slope and bounds the degree. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent b8b252b commit feb0e25

4 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ after it
208208
|---|---|---|
209209
| `"(a*c + b*c*x)^(-3-2*p)*(f + g*x)*(a^2 + 2*a*b*x + b^2*x^2)^p".ToEntity().Integrate("x")` | `integral(...)`; an answer with no value on the unreleased master | the antiderivative |
210210

211+
### A sine of a double argument beside the argument is written as a product
212+
213+
**Answers where there were none.** `csc(a + b x)^3 sin(2a + 2b x)^7` was declined: the rule that writes multiples
214+
of one argument in it reads a numeric slope and bounds the degree it writes. A sine of the double is one product,
215+
`sin(2A) = 2 sin(A) cos(A)`, whatever its power, and is written so beside functions of `A` for any slope
216+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
217+
218+
| Input | Was (2.5.0) | Now |
219+
|---|---|---|
220+
| `"csc(a + b*x)^3*sin(2*a + 2*b*x)^7".ToEntity().Integrate("x")` | `integral(...)` | 127 characters |
221+
| `"csc(a + b*x)*sin(2*a + 2*b*x)^8".ToEntity().Integrate("x")` | `integral(...)` | 134 characters |
222+
211223
### A sine or a cosine of a shifted argument is written in the other
212224

213225
**Answers where there were none.** `sin(a + b x) sec(c + b x)^3` was declined, with the rest of Rubi's 4.7.1

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12197,6 +12197,40 @@ node is Powf(var @base, var power) && @base.ContainsNode(u)
1219712197
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
1219812198
}
1219912199

12200+
/// <summary>
12201+
/// A sine of twice an argument beside functions of the argument, written as the product it is:
12202+
/// <c>sin(2A) = 2 sin(A) cos(A)</c>, so that every trigonometric function is of <c>A</c>.
12203+
/// <c>csc(a + b x)^3 sin(2a + 2b x)^7</c> is <c>2^7 sin(a + b x)^4 cos(a + b x)^7</c>.
12204+
/// </summary>
12205+
/// <remarks>
12206+
/// The rule that writes multiples of one argument in it reads a numeric slope, and bounds the
12207+
/// degree it writes; a sine of the double is one product whatever its power, so it is written
12208+
/// here for any slope. Rubi's 4.7.1.
12209+
/// https://github.com/asc-community/AngouriMath/issues/718
12210+
/// </remarks>
12211+
internal static Entity? SolveByWritingASineOfADoubleArgumentAsAProduct(Entity expr, Entity.Variable x, bool integrateByParts)
12212+
{
12213+
var arguments = new List<Entity>();
12214+
foreach (var node in expr.Nodes)
12215+
if (node is Sinf or Cosf or Tanf or Cotanf or Secantf or Cosecantf && node.ContainsNode(x)
12216+
&& node.DirectChildren.First() is var argument && !arguments.Contains(argument))
12217+
arguments.Add(argument);
12218+
if (arguments.Count != 2)
12219+
return null;
12220+
foreach (var (single, twice) in new[] { (arguments[0], arguments[1]), (arguments[1], arguments[0]) })
12221+
{
12222+
if (!TreeAnalyzer.TryGetPolyLinear(single, x, out var slope, out _) || slope.ContainsNode(x)
12223+
|| (twice - 2 * single).Expand().InnerSimplified.Evaled is not Number.Complex { IsZero: true })
12224+
continue;
12225+
// Only sines of the double, so that each is one product.
12226+
if (expr.Nodes.Any(node => node is Cosf or Tanf or Cotanf or Secantf or Cosecantf && node.DirectChildren.First() == twice))
12227+
return null;
12228+
var rewritten = expr.Replace(node => node is Sinf(var a) && a == twice ? 2 * MathS.Sin(single) * MathS.Cos(single) : node);
12229+
return Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts);
12230+
}
12231+
return null;
12232+
}
12233+
1220012234
/// <summary>
1220112235
/// An integrand whose trigonometric functions have <b>different multiples</b> of one
1220212236
/// 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
11961196
// And the other way round: not a product of two arguments but anything else built
11971197
// from different multiples of one -- `sin(x)/cos(2x)`, `cos(x)/(sin(x) tan(x/2))` --
11981198
// rewritten to the one argument every trigonometric rule above reads.
1199+
// A sine of the double argument beside the argument: one product, for any slope.
1200+
if ((answer = IndefiniteIntegralSolver.SolveByWritingASineOfADoubleArgumentAsAProduct(expr, x, integrateByParts)) is { }) return answer;
11991201
if ((answer = IndefiniteIntegralSolver.SolveByUnifyingTrigonometricArguments(expr, x, integrateByParts)) is { }) return answer;
12001202
// The exponential substitution beside the other rewrites. It is also what integrates
12011203
// the hyperbolic functions, which are not nodes here but quotients of exponentials.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 of twice an argument beside functions of the argument, written as the product
16+
/// <c>sin(2A) = 2 sin(A) cos(A)</c>, for a symbolic slope too. Rubi's 4.7.1.
17+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
18+
/// </summary>
19+
[Trait("Area", "Calculus")]
20+
public sealed class ASineOfADoubleArgumentIntegralTest
21+
{
22+
[Theory]
23+
[InlineData("csc(a + b*x)^3*sin(2*a + 2*b*x)^7")]
24+
[InlineData("csc(a + b*x)*sin(2*a + 2*b*x)^8")]
25+
public void AsAProduct(string integrand)
26+
{
27+
var integral = integrand.ToEntity().Integrate("x");
28+
var text = integral.Stringize();
29+
Assert.DoesNotContain("integral(", text);
30+
Assert.True(text.Length < 5000, $"{text.Length} characters of answer for {integrand}");
31+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7);
32+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
33+
var original = Pinned(integrand.ToEntity());
34+
var compared = 0;
35+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
36+
{
37+
var want = original.Substitute("x", at).EvalNumerical();
38+
var got = derivative.Substitute("x", at).EvalNumerical();
39+
if (want.IsNaN)
40+
continue;
41+
compared++;
42+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
43+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
44+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
45+
}
46+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)