|
| 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 System.Threading; |
| 10 | +using System.Threading.Tasks; |
| 11 | +using AngouriMath.Extensions; |
| 12 | +using Xunit; |
| 13 | + |
| 14 | +namespace AngouriMath.Tests.Calculus |
| 15 | +{ |
| 16 | + /// <summary> |
| 17 | + /// A rational function of a hyperbolic sine or cosine over a symbolic quadratic in it, asked under |
| 18 | + /// Osborn's rule as one of a sine over a quadratic before the tangent of the half argument: under that |
| 19 | + /// tangent Rubi's 6.7.1 <c>sinh(x)^2/(a + b sinh(x) + c sinh(x)^2)</c> is a quartic with symbols in it, |
| 20 | + /// and its partial fractions ran past the budget. |
| 21 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/233">#233</a> |
| 22 | + /// </summary> |
| 23 | + [Trait("Area", "Calculus")] |
| 24 | + public sealed class AHyperbolicQuotientOverAQuadraticInItAsTheSinesIntegralTest |
| 25 | + { |
| 26 | + [Theory] |
| 27 | + [InlineData("sinh(x)^2/(a + b*sinh(x) + c*sinh(x)^2)")] |
| 28 | + [InlineData("sinh(x)^3/(a + b*sinh(x) + c*sinh(x)^2)")] |
| 29 | + [InlineData("cosh(x)^2/(a + b*cosh(x) + c*cosh(x)^2)")] |
| 30 | + public void IsAnswered(string integrand) |
| 31 | + { |
| 32 | + Entity? answer = null; |
| 33 | + // A thread of its own, so that the guard is not spent waiting behind other tests' work. |
| 34 | + var task = Task.Factory.StartNew(() => answer = integrand.ToEntity().Integrate("x"), |
| 35 | + CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); |
| 36 | + Assert.True(task.Wait(LimitTermination.Guard), $"{integrand} did not finish within {LimitTermination.Guard}"); |
| 37 | + var integral = answer!; |
| 38 | + Assert.DoesNotContain("integral(", integral.Stringize()); |
| 39 | + Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.4); |
| 40 | + var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x"); |
| 41 | + var original = Pinned(integrand.ToEntity()); |
| 42 | + foreach (var at in new[] { -1.7, -0.6, 0.4, 1.3, 2.2 }) |
| 43 | + { |
| 44 | + var want = original.Substitute("x", at).EvalNumerical(); |
| 45 | + var got = derivative.Substitute("x", at).EvalNumerical(); |
| 46 | + Assert.False(got.IsNaN, $"d/dx of the antiderivative of {integrand} has no value at x = {at}, where the integrand is {want}"); |
| 47 | + Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart) |
| 48 | + < 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)), |
| 49 | + $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments