Skip to content

Commit

Permalink
Switch to using HalfIntegers (#6)
Browse files Browse the repository at this point in the history
* swich to using HalfIntegers, add project.toml, bump version, update CI

* add Random and add seed to avoid unlikely test failure
  • Loading branch information
Jutho committed Jul 8, 2019
1 parent 6ddbd34 commit a5ee2d5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 417 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ os:
- linux
- osx
julia:
- 0.7
- 1.0
- 1.1
- 1.2
- nightly
notifications:
email: false
Expand Down
19 changes: 19 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "WignerSymbols"
uuid = "9f57e263-0b3d-5e2e-b1be-24f2bb48858b"
authors = ["Jutho Haegeman"]
version = "1.0.0"

[deps]
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"

[compat]
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[targets]
test = ["Test", "LinearAlgebra", "Random"]
2 changes: 0 additions & 2 deletions REQUIRE

This file was deleted.

3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1
- julia_version: 1.1
- julia_version: 1.2
- julia_version: nightly

platform:
Expand Down
31 changes: 14 additions & 17 deletions src/WignerSymbols.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module WignerSymbols
export δ, Δ, clebschgordan, wigner3j, wigner6j, racahV, racahW, HalfInteger

using Base.GMP.MPZ
using HalfIntegers

include("halfinteger.jl")
include("primefactorization.jl")

const Wigner3j = Dict{Tuple{UInt,UInt,UInt,Int,Int},Tuple{Rational{BigInt},Rational{BigInt}}}()
Expand All @@ -29,13 +29,7 @@ end
Checks the triangle conditions `j₃ <= j₁ + j₂`, `j₁ <= j₂ + j₃` and `j₂ <= j₃ + j₁`.
"""
function δ(j₁, j₂, j₃)
j₃ <= j₁ + j₂ || return false
j₁ <= j₂ + j₃ || return false
j₂ <= j₃ + j₁ || return false
isinteger(j₁+j₂+j₃) || return false
return true
end
δ(j₁, j₂, j₃) = (j₃ <= j₁ + j₂) && (j₁ <= j₂ + j₃) && (j₂ <= j₃ + j₁) && isinteger(j₁+j₂+j₃)

# triangle coefficient
"""
Expand All @@ -51,7 +45,7 @@ throws a `DomainError` if the `jᵢ`s are not (half)integer
Δ(j₁, j₂, j₃) = Δ(Float64, j₁, j₂, j₃)
function Δ(T::Type{<:AbstractFloat}, j₁, j₂, j₃)
for jᵢ in (j₁, j₂, j₃)
(ishalfinteger(jᵢ) && jᵢ >= 0) || throw(DomainError("invalid jᵢ", jᵢ))
(ishalfinteger(jᵢ) && jᵢ >= zero(jᵢ)) || throw(DomainError("invalid jᵢ", jᵢ))
end
if !δ(j₁, j₂, j₃)
return zero(T)
Expand Down Expand Up @@ -109,7 +103,8 @@ function wigner3j(T::Type{<:AbstractFloat}, j₁, j₂, j₃, m₁, m₂, m₃ =
Wigner3j[(β₁, β₂, β₃, α₁, α₂)] = (r,s)
end

return sgn*sqrt(convert(T, r.num)/convert(T, r.den))*(convert(T, s.num)/convert(T, s.den))
sn, sd, rn, rd = convert.(T, (s.num, s.den, r.num, r.den))
return sgn*(sn/sd)*sqrt(rn/rd)
end

"""
Expand All @@ -121,7 +116,8 @@ as a type `T` floating point number. By default, `T = Float64` and `m₃ = m₁+
Returns `zero(T)` if the triangle condition `δ(j₁, j₂, j₃)` is not satisfied, but
throws a `DomainError` if the `jᵢ`s and `mᵢ`s are not (half)integer or `abs(mᵢ) > jᵢ`.
"""
clebschgordan(j₁, m₁, j₂, m₂, j₃, m₃ = m₁+m₂) = clebschgordan(Float64, j₁, m₁, j₂, m₂, j₃, m₃)
clebschgordan(j₁, m₁, j₂, m₂, j₃, m₃ = m₁+m₂) =
clebschgordan(Float64, j₁, m₁, j₂, m₂, j₃, m₃)
function clebschgordan(T::Type{<:AbstractFloat}, j₁, m₁, j₂, m₂, j₃, m₃ = m₁+m₂)
s = wigner3j(T, j₁, j₂, j₃, m₁, m₂, -m₃)
iszero(s) && return s
Expand Down Expand Up @@ -162,13 +158,13 @@ wigner6j(j₁, j₂, j₃, j₄, j₅, j₆) = wigner6j(Float64, j₁, j₂, j
function wigner6j(T::Type{<:AbstractFloat}, j₁, j₂, j₃, j₄, j₅, j₆)
# check validity of `jᵢ`s
for jᵢ in (j₁, j₂, j₃, j₄, j₅, j₆)
(ishalfinteger(jᵢ) && jᵢ >= 0) || throw(DomainError("invalid jᵢ", jᵢ))
(ishalfinteger(jᵢ) && jᵢ >= zero(jᵢ)) || throw(DomainError("invalid jᵢ", jᵢ))
end

α̂₁ = map(converthalfinteger, (j₁, j₂, j₃))
α̂₂ = map(converthalfinteger, (j₁, j₆, j₅))
α̂₃ = map(converthalfinteger, (j₂, j₄, j₆))
α̂₄ = map(converthalfinteger, (j₃, j₄, j₅))
α̂₁ = (j₁, j₂, j₃)
α̂₂ = (j₁, j₆, j₅)
α̂₃ = (j₂, j₄, j₆)
α̂₄ = (j₃, j₄, j₅)

# check triangle conditions
if !(δ(α̂₁...) && δ(α̂₂...) && δ(α̂₃...) && δ(α̂₄...))
Expand Down Expand Up @@ -206,7 +202,8 @@ function wigner6j(T::Type{<:AbstractFloat}, j₁, j₂, j₃, j₄, j₅, j₆)
Wigner6j[(β₁, β₂, β₃, α₁, α₂, α₃)] = (r, s)
end

return sqrt(convert(T, r.num)/convert(T, r.den))*(convert(T, s.num)/convert(T, s.den))
sn, sd, rn, rd = convert.(T, (s.num, s.den, r.num, r.den))
return (sn/sd)*sqrt(rn/rd)
end

"""
Expand Down
190 changes: 0 additions & 190 deletions src/halfinteger.jl

This file was deleted.

Loading

2 comments on commit a5ee2d5

@Jutho
Copy link
Owner Author

@Jutho Jutho commented on a5ee2d5 Jul 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/1896

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" a5ee2d5fc65311e2d74bd49c0a03174692910bf7
git push origin v1.0.0

Please sign in to comment.