|
| 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 constant over a linear with a symbolic slope beside the root of a quadratic with no |
| 16 | + /// linear term: the quadratic's value at the pole came back with the slope's condition on it, |
| 17 | + /// and the table read no quadratic through it. Rubi's 1.2.1.4 |
| 18 | + /// <c>sqrt(a + c x^2)/(x (d + e x))</c>, written here with <c>k</c> for <c>e</c>, which is |
| 19 | + /// Euler's number. |
| 20 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a> |
| 21 | + /// </summary> |
| 22 | + [Trait("Area", "Calculus")] |
| 23 | + public sealed class APoleWithASymbolicSlopeBesideARootIntegralTest |
| 24 | + { |
| 25 | + private static void DifferentiatesBack(string integrand, params (string, double)[] pins) |
| 26 | + { |
| 27 | + var integral = integrand.ToEntity().Integrate("x"); |
| 28 | + Assert.DoesNotContain("integral(", integral.Stringize()); |
| 29 | + |
| 30 | + // Pinned before it is differentiated: the answer carries `sgn(x + d/k)`, whose |
| 31 | + // derivative is read where its argument is a number. |
| 32 | + var pinned = integral.Substitute("C", 0); |
| 33 | + Entity original = integrand.ToEntity(); |
| 34 | + foreach (var (name, value) in pins) |
| 35 | + { |
| 36 | + pinned = pinned.Substitute(name, value); |
| 37 | + original = original.Substitute(name, value); |
| 38 | + } |
| 39 | + var derivative = pinned.Differentiate("x"); |
| 40 | + foreach (var at in new[] { -2.3, -0.7, 0.4, 1.9 }) |
| 41 | + { |
| 42 | + var got = derivative.Substitute("x", at).EvalNumerical(); |
| 43 | + var want = original.Substitute("x", at).EvalNumerical(); |
| 44 | + var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart); |
| 45 | + var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)); |
| 46 | + Assert.True(difference / scale < 1e-8, |
| 47 | + $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + [Theory] |
| 52 | + [InlineData("1/((d+k*x)*sqrt(2+3*x^2))")] |
| 53 | + [InlineData("sqrt(a+c*x^2)/(x*(d+k*x))")] |
| 54 | + [InlineData("1/(x^2*(d+k*x)*sqrt(a+c*x^2))")] |
| 55 | + [InlineData("1/(x*(d+k*x)^2*sqrt(a+c*x^2))")] |
| 56 | + public void IsAnsweredAndDifferentiatesBack(string integrand) |
| 57 | + { |
| 58 | + DifferentiatesBack(integrand, ("a", 2), ("c", 1.5), ("d", 1.25), ("k", 2)); |
| 59 | + DifferentiatesBack(integrand, ("a", -1), ("c", 2), ("d", -0.5), ("k", 1.5)); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments