|
| 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