Repository navigation
Expand file tree
/
Copy pathAPolynomialBesideErrorFunctionsOfAShiftedLinearIntegralTest.cs
More file actions
54 lines (52 loc) · 2.52 KB
/
Copy pathAPolynomialBesideErrorFunctionsOfAShiftedLinearIntegralTest.cs
File metadata and controls
54 lines (52 loc) · 2.52 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
//
// 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>
/// A polynomial times powers of error functions of one shifted linear, written in
/// <c>u = a + b x</c>. In x, by parts leaves a Gaussian of <c>a + b x</c> beside a polynomial,
/// which nothing read, and <c>(c + d x)^2 erf(a + b x)^2</c> ran past twenty seconds. Rubi's 8.1.
/// <a href="https://github.com/asc-community/AngouriMath/issues/1945">#1945</a>
/// </summary>
[Trait("Area", "Calculus")]
public sealed class APolynomialBesideErrorFunctionsOfAShiftedLinearIntegralTest
{
[Theory]
[InlineData("x*erf(a + b*x)^2")]
[InlineData("x^2*erf(a + b*x)^2")]
[InlineData("(c + d*x)^2*erf(a + b*x)^2")]
[InlineData("(c + d*x)^2*erfc(a + b*x)^2")]
[InlineData("(c + d*x)^2*erfi(a + b*x)^2")]
[InlineData("(c + d*x)*erf(a + b*x)")]
public void WrittenInTheShiftedLinear(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
var text = integral.Stringize();
Assert.DoesNotContain("integral(", text);
Assert.True(text.Length < 5000, $"{text.Length} characters of answer for {integrand}");
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.4).Substitute("d", 0.3);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
var compared = 0;
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
{
var want = original.Substitute("x", at).EvalNumerical();
var got = derivative.Substitute("x", at).EvalNumerical();
if (want.IsNaN)
continue;
compared++;
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
}
}
}