Skip to content

Commit 50b5246

Browse files
committed
Add setdiff for ElementarySpace
1 parent 40d12d8 commit 50b5246

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/spaces/cartesianspace.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ flip(V::CartesianSpace) = V
5656
infimum(V₁::CartesianSpace, V₂::CartesianSpace) = CartesianSpace(min(V₁.d, V₂.d))
5757
supremum(V₁::CartesianSpace, V₂::CartesianSpace) = CartesianSpace(max(V₁.d, V₂.d))
5858

59+
function Base.setdiff(V::CartesianSpace, W::CartesianSpace)
60+
V W || throw(ArgumentError("$(W) is not a subspace of $(V)"))
61+
return CartesianSpace(dim(V) - dim(W))
62+
end
63+
5964
Base.show(io::IO, V::CartesianSpace) = print(io, "ℝ^$(V.d)")

src/spaces/complexspace.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ function supremum(V₁::ComplexSpace, V₂::ComplexSpace)
6969
throw(SpaceMismatch("Supremum of space and dual space does not exist"))
7070
end
7171

72+
function Base.setdiff(V::ComplexSpace, W::ComplexSpace)
73+
(V W && isdual(V) == isdual(W)) ||
74+
throw(ArgumentError("$(W) is not a subspace of $(V)"))
75+
return ComplexSpace(dim(V) - dim(W), isdual(V))
76+
end
77+
7278
Base.show(io::IO, V::ComplexSpace) = print(io, isdual(V) ? "(ℂ^$(V.d))'" : "ℂ^$(V.d)")

src/spaces/gradedspace.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ function supremum(V₁::GradedSpace{I}, V₂::GradedSpace{I}) where {I<:Sector}
187187
end
188188
end
189189

190+
function Base.setdiff(V::GradedSpace{I}, W::GradedSpace{I}) where {I<:Sector}
191+
V W && isdual(V) == isdual(W) ||
192+
throw(SpaceMismatch("$(W) is not a subspace of $(V)"))
193+
return typeof(V)(c => dim(V, c) - dim(W, c) for c in sectors(V))
194+
end
195+
190196
function Base.show(io::IO, V::GradedSpace{I}) where {I<:Sector}
191197
print(io, type_repr(typeof(V)), "(")
192198
seperator = ""

src/spaces/vectorspaces.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,11 @@ have the same value.
395395
function supremum(V₁::S, V₂::S, V₃::S...) where {S<:ElementarySpace}
396396
return supremum(supremum(V₁, V₂), V₃...)
397397
end
398+
399+
"""
400+
setdiff(V::ElementarySpace, W::ElementarySpace)
401+
402+
Return the set difference of two elementary spaces, i.e. an instance `X::ElementarySpace`
403+
such that `V = W ⊕ X`.
404+
"""
405+
Base.setdiff(V₁::S, V₂::S) where {S<:ElementarySpace}

0 commit comments

Comments
 (0)