Repository navigation
Expand file tree
/
Copy pathExponentialOfALogarithmIntegralTest.cs
More file actions
94 lines (87 loc) · 4.67 KB
/
Copy pathExponentialOfALogarithmIntegralTest.cs
File metadata and controls
94 lines (87 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//
using System;
using AngouriMath.Extensions;
using Xunit;
namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// <c>e^(k ln(q))</c> is <c>q^k</c>, the definition of the principal power, and that is the
/// spelling the parser gives every inverse hyperbolic function: <c>acoth(a x)</c> is
/// <c>1/2 ln((a x + 1)/(a x - 1))</c>. So <c>e^acoth(a x) x^3</c> arrives as an exponential
/// of a logarithm, which no exponential rule reads, and is <c>x^3 sqrt((a x + 1)/(a x - 1))</c>,
/// which the radical substitution answers. Rubi's 7.4.2, exponentials of the inverse
/// hyperbolic cotangent, where every row was declined.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ExponentialOfALogarithmIntegralTest
{
/// <summary>Beyond <c>a x = 1</c> for <c>a = 2</c>, where <c>acoth(2x)</c> is real.</summary>
private static readonly double[] Points = { 0.6, 0.8, 1.1, 1.5, 2.2 };
private static void DifferentiatesBack(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
Assert.DoesNotContain("integral(", integral.Stringize());
var derivative = integral.Substitute("C", 0).Differentiate("x");
var original = integrand.ToEntity();
var compared = 0;
foreach (var at in Points)
{
var got = derivative.Substitute("x", at).EvalNumerical();
var want = original.Substitute("x", at).EvalNumerical();
if (got.IsNaN || want.IsNaN)
continue;
compared++;
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart));
Assert.True(difference / scale < 1e-9,
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
Assert.True(compared >= 4, $"only {compared} of {Points.Length} points were comparable for {integrand}");
}
[Theory]
[InlineData("e^(2*acoth(2*x))*(3 - 4*3*x^2)^2")]
[InlineData("e^acoth(2*x)/(3 - 3/(2*x))")]
[InlineData("e^(1/3*acoth(x))*x^2")]
[InlineData("(3 - 3/(4*x^2))^3/e^(2*acoth(2*x))")]
public void AnExponentialOfAnInverseHyperbolicCotangent(string integrand) => DifferentiatesBack(integrand);
/// <summary>
/// The quotient of linears under the root leaves <c>(a (1 - u^2))^5</c> below the bar in
/// <c>u</c>, which the rational reader does not read as <c>a^5 (1 - u^2)^5</c> until it
/// is written so: <c>x^3 sqrt((a x + 1)/(a x - 1))</c> took nine seconds through the
/// split terms and takes half of one as a single quotient; <c>e^acoth(a x) x^3</c>
/// eighteen seconds and a tenth. Pinned as solved, not as timed -- a wall clock in a
/// test measures the runner.
/// </summary>
[Theory]
[InlineData("x^3*sqrt((2*x+1)/(2*x-1))")]
[InlineData("e^acoth(2*x)*x^3")]
[InlineData("1/(e^(3*acoth(2*x))*x^4)")]
[InlineData("e^acoth(2*x)*sqrt(3-3/(2*x))/x^4")]
public void APowerOfAProductBelowTheBarIsReadDistributed(string integrand) => DifferentiatesBack(integrand);
/// <summary>The fold is the identity it is: <c>e^(k ln q)</c> with any multiplier, nested or not.</summary>
[Theory]
[InlineData("e^(3*ln(x + 1))")]
[InlineData("e^(ln(x^2 + 1)/2) * x")]
[InlineData("e^(2*(1/2*ln(x + 2)))")]
public void AnExponentialOfAMultipleOfALogarithm(string integrand) => DifferentiatesBack(integrand);
/// <summary>
/// The exponent read structurally, since <c>e^(u + v)</c> is <c>e^u e^v</c> and
/// <c>e^(k u)</c> is <c>(e^u)^k</c>: a hyperbolic function of a logarithm is written
/// with <c>e^(a + b ln(q))</c> above the bar and <c>e^(-(a + b ln(q)))</c> below it,
/// and both are powers of <c>q</c> times a constant. Rubi's 6.5.3 and 6.6.3.
/// </summary>
[Theory]
[InlineData("sinh(2 + 3*ln(x))")]
[InlineData("cosh(1 + ln(x^2 + 1))")]
[InlineData("sech(3 + 2*ln(2/x^(1/2)))^3")]
[InlineData("e^(1 + ln(x + 2)/2)")]
[InlineData("tanh(ln(x))")]
public void AHyperbolicFunctionOfALogarithm(string integrand) => DifferentiatesBack(integrand);
}
}