From 0e056691cb7ac99c394f1f8ce240fb28ecc2bea7 Mon Sep 17 00:00:00 2001 From: "Thomas (Tom) C. Gorordo" Date: Thu, 15 Aug 2024 09:34:47 -0700 Subject: [PATCH] remove added Combinatorics dep by hardcoding 9j arg permutations --- Project.toml | 1 - src/WignerSymbols.jl | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 02e6f6f..dedcec9 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,6 @@ authors = ["Jutho Haegeman"] version = "2.1.0" [deps] -Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721" LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637" Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae" diff --git a/src/WignerSymbols.jl b/src/WignerSymbols.jl index 449e8fc..bec5de8 100644 --- a/src/WignerSymbols.jl +++ b/src/WignerSymbols.jl @@ -6,7 +6,6 @@ using RationalRoots using LRUCache const RRBig = RationalRoot{BigInt} import RationalRoots: _convert -using Combinatorics: permutations include("growinglist.jl") include("bigint.jl") # additional GMP BigInt functionality not wrapped in Base.GMP.MPZ @@ -270,8 +269,19 @@ function wigner9j(T::Type{<:Real}, j₁, j₂, j₃, j₄, j₅, j₆, j₇, j return _wigner9j(T, HalfInteger.((j₁, j₂, j₃, j₄, j₅, j₆, j₇, j₈, j₉))...) end -const _perms9j = [(i, j) for i in permutations([1, 2, 3]), - j in permutations([1, 2, 3])] +const _perms9j = [([1, 2, 3], [1, 2, 3]) ([1, 2, 3], [1, 3, 2]) ([1, 2, 3], [2, 1, 3]) ([1, 2, 3], [2, 3, 1]) ([1, 2, 3], [3, 1, 2]) ([1, 2, 3], [3, 2, 1]); + ([1, 3, 2], [1, 2, 3]) ([1, 3, 2], [1, 3, 2]) ([1, 3, 2], [2, 1, 3]) ([1, 3, 2], [2, 3, 1]) ([1, 3, 2], [3, 1, 2]) ([1, 3, 2], [3, 2, 1]); + ([2, 1, 3], [1, 2, 3]) ([2, 1, 3], [1, 3, 2]) ([2, 1, 3], [2, 1, 3]) ([2, 1, 3], [2, 3, 1]) ([2, 1, 3], [3, 1, 2]) ([2, 1, 3], [3, 2, 1]); + ([2, 3, 1], [1, 2, 3]) ([2, 3, 1], [1, 3, 2]) ([2, 3, 1], [2, 1, 3]) ([2, 3, 1], [2, 3, 1]) ([2, 3, 1], [3, 1, 2]) ([2, 3, 1], [3, 2, 1]); + ([3, 1, 2], [1, 2, 3]) ([3, 1, 2], [1, 3, 2]) ([3, 1, 2], [2, 1, 3]) ([3, 1, 2], [2, 3, 1]) ([3, 1, 2], [3, 1, 2]) ([3, 1, 2], [3, 2, 1]); + ([3, 2, 1], [1, 2, 3]) ([3, 2, 1], [1, 3, 2]) ([3, 2, 1], [2, 1, 3]) ([3, 2, 1], [2, 3, 1]) ([3, 2, 1], [3, 1, 2]) ([3, 2, 1], [3, 2, 1])] + +const _signs9j = [1 -1 -1 1 1 -1; + -1 1 1 -1 -1 1; + -1 1 1 -1 -1 1; + 1 -1 -1 1 1 -1; + 1 -1 -1 1 1 -1; + -1 1 1 -1 -1 1] function _wigner9j(T::Type{<:Real}, j₁::HalfInteger, j₂::HalfInteger, j₃::HalfInteger, j₄::HalfInteger, j₅::HalfInteger, j₆::HalfInteger, @@ -284,15 +294,15 @@ function _wigner9j(T::Type{<:Real}, j₁::HalfInteger, j₂::HalfInteger, j₃:: # dictionary lookup, check all 72 permutations k = [j₁ j₂ j₃; j₄ j₅ j₆; j₇ j₈ j₉] - for p in _perms9j + for (p, m) in zip(_perms9j, _signs9j) kk = Tuple(reshape(k[p...], 9)) kkT = Tuple(reshape(transpose(k[p...]), 9)) if haskey(Wigner9j, kk) r, s = Wigner9j[kk] - return _convert(T, s) * convert(T, signedroot(r)) + return m * _convert(T, s) * convert(T, signedroot(r)) elseif haskey(Wigner9j, kkT) r, s = Wigner9j[kkT] - return _convert(T, s) * convert(T, signedroot(r)) + return m * _convert(T, s) * convert(T, signedroot(r)) end end