From b84f8f0793e738d1970c78dccc36badf2ebf63bf Mon Sep 17 00:00:00 2001 From: lkdvos Date: Fri, 29 Sep 2023 17:44:21 +0200 Subject: [PATCH] Refactor deligne field test in a function --- src/spaces/deligne.jl | 33 ++++++++++++++++++--------------- src/spaces/productspace.jl | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/spaces/deligne.jl b/src/spaces/deligne.jl index 52c76892..48a0029f 100644 --- a/src/spaces/deligne.jl +++ b/src/spaces/deligne.jl @@ -12,11 +12,15 @@ The Deligne tensor product also works in the type domain and for sectors and ten group representations, we have `Rep[G₁] ⊠ Rep[G₂] == Rep[G₁ × G₂]`, i.e. these are the natural representation spaces of the direct product of two groups. """ -⊠(V₁::VectorSpace, V₂::VectorSpace) = (V₁ ⊠ one(V₂)) ⊗ (one(V₁) ⊠ V₂) +function ⊠(V₁::VectorSpace, V₂::VectorSpace) + check_fields_deligne(V₁, V₂) + return (V₁ ⊠ one(V₂)) ⊗ (one(V₁) ⊠ V₂) +end -# define deligne products with empty tensor product: just add a trivial sector of the type of the empty space to each of the sectors in the non-empty space +# define deligne products with empty tensor product: just add a trivial sector of the type +# of the empty space to each of the sectors in the non-empty space function ⊠(V::GradedSpace, P₀::ProductSpace{<:ElementarySpace,0}) - field(V) == field(P₀) || throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(V, P₀) I₁ = sectortype(V) I₂ = sectortype(P₀) return Vect[I₁ ⊠ I₂](ifelse(isdual(V), dual(c), c) ⊠ one(I₂) => dim(V, c) @@ -24,8 +28,7 @@ function ⊠(V::GradedSpace, P₀::ProductSpace{<:ElementarySpace,0}) end function ⊠(P₀::ProductSpace{<:ElementarySpace,0}, V::GradedSpace) - field(V) == field(P₀) || - throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(V, P₀) I₁ = sectortype(P₀) I₂ = sectortype(V) return Vect[I₁ ⊠ I₂](one(I₁) ⊠ ifelse(isdual(V), dual(c), c) => dim(V, c) @@ -33,31 +36,27 @@ function ⊠(P₀::ProductSpace{<:ElementarySpace,0}, V::GradedSpace) end function ⊠(V::ComplexSpace, P₀::ProductSpace{<:ElementarySpace,0}) - field(V) == field(P₀) || - throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(V, P₀) I₂ = sectortype(P₀) return Vect[I₂](one(I₂) => dim(V); dual=isdual(V)) end function ⊠(P₀::ProductSpace{<:ElementarySpace,0}, V::ComplexSpace) - field(V) == field(P₀) || - throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(V, P₀) I₁ = sectortype(P₀) return Vect[I₁](one(I₁) => dim(V); dual=isdual(V)) end function ⊠(P::ProductSpace{<:ElementarySpace,0}, P₀::ProductSpace{<:ElementarySpace,0}) - field(P) == field(P₀) || - throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(P, P₀) I₁ = sectortype(P) I₂ = sectortype(P₀) return one(Vect[I₁ ⊠ I₂]) end function ⊠(P::ProductSpace{<:ElementarySpace}, P₀::ProductSpace{<:ElementarySpace,0}) - field(P) == field(P₀) || - throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(P, P₀) I₁ = sectortype(P) I₂ = sectortype(P₀) S = Vect[I₁ ⊠ I₂] @@ -66,11 +65,15 @@ function ⊠(P::ProductSpace{<:ElementarySpace}, P₀::ProductSpace{<:Elementary end function ⊠(P₀::ProductSpace{<:ElementarySpace,0}, P::ProductSpace{<:ElementarySpace}) - field(P) == field(P₀) || - throw(ArgumentError("Deligne products require spaces over the same field")) + check_fields_deligne(P, P₀) I₁ = sectortype(P₀) I₂ = sectortype(P) S = Vect[I₁ ⊠ I₂] N = length(P) return ProductSpace{S,N}(map(V -> P₀ ⊠ V, tuple(P...))) end + +@noinline function check_fields_deligne(P₁, P₂) + return field(P₁) == field(P₂) || + throw(ArgumentError("Deligne products require spaces over the same field")) +end diff --git a/src/spaces/productspace.jl b/src/spaces/productspace.jl index 368df0d5..d32df0ac 100644 --- a/src/spaces/productspace.jl +++ b/src/spaces/productspace.jl @@ -257,4 +257,4 @@ Base.convert(::Type{S}, P::ProductSpace{S,0}) where {S<:ElementarySpace} = oneun Base.convert(::Type{S}, P::ProductSpace{S}) where {S<:ElementarySpace} = fuse(P.spaces...) # ElementarySpace to ProductSpace -Base.convert(::Type{<:ProductSpace}, V::S) where {S<:ElementarySpace} = ⊗(V) \ No newline at end of file +Base.convert(::Type{<:ProductSpace}, V::S) where {S<:ElementarySpace} = ⊗(V)