Skip to content

Commit 7d70c32

Browse files
authored
Automatic quality testing using Aqua (#4)
* Add Aqua in testing * Add analytical second derivative * version bump to v0.3.1
1 parent 0776652 commit 7d70c32

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

Project.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name = "LegendrePolynomials"
22
uuid = "3db4a2ba-fc88-11e8-3e01-49c72059a882"
3-
version = "0.3"
3+
version = "0.3.1"
44

55
[deps]
66
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
77

88
[compat]
9+
Aqua = "0.5"
10+
HyperDualNumbers = "4"
911
OffsetArrays = "0.11, 1"
1012
julia = "1"
1113

1214
[extras]
15+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1316
HyperDualNumbers = "50ceba7f-c3ee-5a84-a6e8-3ad40456ec97"
1417
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1518

1619
[targets]
17-
test = ["HyperDualNumbers", "Test"]
20+
test = ["Aqua", "HyperDualNumbers", "Test"]

docs/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
34
HyperDualNumbers = "50ceba7f-c3ee-5a84-a6e8-3ad40456ec97"
45
LegendrePolynomials = "3db4a2ba-fc88-11e8-3e01-49c72059a882"
56

67
[compat]
78
Documenter = "0.26"
8-
HyperDualNumbers = "4"
9+
DualNumbers = "0.6"
10+
HyperDualNumbers = "4"

docs/src/derivatives.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,50 @@ Pl_dPl_d2Pl (generic function with 1 method)
8585
julia> Pl_dPl_d2Pl(0.5, lmax = 3)
8686
([1.0, 0.5, -0.125, -0.4375], [0.0, 1.0, 1.5, 0.375], [0.0, 0.0, 3.0, 7.5])
8787
```
88+
89+
# Analytical approach for higher derivatives
90+
91+
Legendre polynomials satisfy the differential equation
92+
93+
```math
94+
\frac{d}{dx}\left[(1-x^2)\frac{d P_n}{dx} \right] + n(n+1) P_n(x) = 0
95+
```
96+
97+
We may rearrange the terms to obtain
98+
99+
```math
100+
\frac{d^2 P_n}{dx^2} = \frac{1}{(1-x^2)}\left( 2x \frac{d P_n(x)}{dx} - n(n+1)P_n{x} \right)
101+
```
102+
103+
We may therefore compute the second derivative from the function and its first derivative. Higher derivatives may further be computed in terms of the lower ones.
104+
105+
We demonstrate the second-derivative computation using the package [`DualNumbers.jl`](https://github.com/JuliaDiff/DualNumbers.jl) v0.5:
106+
107+
```jldoctest dual
108+
julia> using DualNumbers
109+
110+
julia> x = 0.5;
111+
112+
julia> xd = Dual(x, one(x));
113+
114+
julia> d2Pl(x, P, dP, n) = (2x * dP - n*(n+1) * P)/(1 - x^2);
115+
116+
julia> function d2Pl(x, n)
117+
xd = Dual(x, one(x))
118+
y = Pl(xd, n)
119+
P, dP = realpart(y), dualpart(y)
120+
d2Pl(x, P, dP, n)
121+
end;
122+
123+
julia> d2Pl(x, 20)
124+
32.838787646905985
125+
```
126+
127+
We may check that this matches the result obtained using `HyperDualNumbers`:
128+
129+
```jldoctest hyperdual
130+
julia> ε₁ε₂part(Pl(xh, 20))
131+
32.838787646905985
132+
```
133+
134+
Unfortunately at this point, higher derivatives need to be evaluated analytically and expresed in terms of lower derivatives.

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Compute [Legendre polynomials](https://en.wikipedia.org/wiki/Legendre_polynomial
1313
P_\ell(x) = \left((2\ell-1) x P_{\ell-1}(x) - (\ell-1)P_{\ell - 2}(x)\right)/\ell
1414
```
1515

16-
Currently this package evaluates the standard polynomials that satisfy ``P_\ell(1) = 1``. These are normalized as
16+
Currently this package evaluates the standard polynomials that satisfy ``P_\ell(1) = 1`` and ``P_0(x) = 1``. These are normalized as
1717

1818
```math
19-
\int P_m(x) P_n(x) dx = \frac{2}{2n+1} \delta_{mn}.
19+
\int_{-1}^1 P_m(x) P_n(x) dx = \frac{2}{2n+1} \delta_{mn}.
2020
```
2121

2222
There are two main functions:

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ using Test
22
using LegendrePolynomials
33
using OffsetArrays
44
using HyperDualNumbers
5+
using Aqua
6+
7+
@testset "Project quality assurance" begin
8+
Aqua.test_all(LegendrePolynomials)
9+
end
510

611
import LegendrePolynomials: LegendrePolynomialIterator
712

0 commit comments

Comments
 (0)