Skip to content

Commit 755f56f

Browse files
borisdevoslkdvos
authored andcommitted
add unitspace
1 parent 21636f9 commit 755f56f

8 files changed

Lines changed: 33 additions & 33 deletions

File tree

docs/src/lib/spaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ flip
9292
9393
9494
zero(::ElementarySpace)
95-
oneunit
95+
unitspace
9696
supremum
9797
infimum
9898
```

docs/src/man/spaces.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,18 @@ flip(ℂ^4) == ℂ^4
316316
```
317317

318318
We also define the direct sum `V1` and `V2` as `V1 ⊕ V2`, where `` is obtained by typing
319-
`\oplus`+TAB. This is possible only if `isdual(V1) == isdual(V2)`. With a little pun on
320-
Julia Base, `oneunit` applied to an elementary space (in the value or type domain) returns
321-
the one-dimensional space, which is isomorphic to the scalar field of the space itself. Some
322-
examples illustrate this better
319+
`\oplus`+TAB. This is possible only if `isdual(V1) == isdual(V2)`. `unitspace` applied to an elementary space
320+
(in the value or type domain) returns the one-dimensional space, which is isomorphic to the
321+
scalar field of the space itself. Some examples illustrate this better.
323322
```@repl tensorkit
324323
ℝ^5 ⊕ ℝ^3
325324
ℂ^5 ⊕ ℂ^3
326325
ℂ^5 ⊕ (ℂ^3)'
327-
oneunit(ℝ^3)
328-
ℂ^5 ⊕ oneunit(ComplexSpace)
329-
oneunit((ℂ^3)')
330-
(ℂ^5) ⊕ oneunit((ℂ^5))
331-
(ℂ^5)' ⊕ oneunit((ℂ^5)')
326+
unitspace(ℝ^3)
327+
ℂ^5 ⊕ unitspace(ComplexSpace)
328+
unitspace((ℂ^3)')
329+
(ℂ^5) ⊕ unitspace((ℂ^5))
330+
(ℂ^5)' ⊕ unitspace((ℂ^5)')
332331
```
333332

334333
Finally, while spaces have a partial order, there is no unique infimum or supremum of a two

src/spaces/cartesianspace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ hassector(V::CartesianSpace, ::Trivial) = dim(V) != 0
4747
sectors(V::CartesianSpace) = OneOrNoneIterator(dim(V) != 0, Trivial())
4848
sectortype(::Type{CartesianSpace}) = Trivial
4949

50-
Base.oneunit(::Type{CartesianSpace}) = CartesianSpace(1)
50+
unitspace(::Type{CartesianSpace}) = CartesianSpace(1)
5151
Base.zero(::Type{CartesianSpace}) = CartesianSpace(0)
5252

5353
(V₁::CartesianSpace, V₂::CartesianSpace) = CartesianSpace(V₁.d + V₂.d)

src/spaces/complexspace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sectortype(::Type{ComplexSpace}) = Trivial
4848

4949
Base.conj(V::ComplexSpace) = ComplexSpace(dim(V), !isdual(V))
5050

51-
Base.oneunit(::Type{ComplexSpace}) = ComplexSpace(1)
51+
unitspace(::Type{ComplexSpace}) = ComplexSpace(1)
5252
Base.zero(::Type{ComplexSpace}) = ComplexSpace(0)
5353

5454
function (V₁::ComplexSpace, V₂::ComplexSpace)

src/spaces/generalspace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sectortype(::Type{<:GeneralSpace}) = Trivial
3535
field(::Type{GeneralSpace{𝔽}}) where {𝔽} = 𝔽
3636
InnerProductStyle(::Type{<:GeneralSpace}) = NoInnerProduct()
3737

38-
Base.oneunit(::Type{GeneralSpace{𝔽}}) where {𝔽} = GeneralSpace{𝔽}(1, false, false)
38+
unitspace(::Type{GeneralSpace{𝔽}}) where {𝔽} = GeneralSpace{𝔽}(1, false, false)
3939
Base.zero(::Type{GeneralSpace{𝔽}}) where {𝔽} = GeneralSpace{𝔽}(0, false, false)
4040

4141
dual(V::GeneralSpace{𝔽}) where {𝔽} = GeneralSpace{𝔽}(dim(V), !isdual(V), isconj(V))

src/spaces/gradedspace.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ function Base.axes(V::GradedSpace{I}, c::I) where {I <: Sector}
133133
end
134134
return (offset + 1):(offset + dim(c) * dim(V, c))
135135
end
136-
137-
Base.oneunit(S::Type{<:GradedSpace{I}}) where {I <: Sector} = S(one(I) => 1)
138-
Base.zero(S::Type{<:GradedSpace{I}}) where {I <: Sector} = S(one(I) => 0)
136+
#TODO: one -> unit
137+
unitspace(S::Type{<:GradedSpace{I}}) where {I<:Sector} = S(one(I) => 1)
138+
Base.zero(S::Type{<:GradedSpace{I}}) where {I<:Sector} = S(one(I) => 0)
139139

140140
# TODO: the following methods can probably be implemented more efficiently for
141141
# `FiniteGradedSpace`, but we don't expect them to be used often in hot loops, so

src/spaces/productspace.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ end
230230
Return a tensor product of zero spaces of type `S`, i.e. this is the unit object under the
231231
tensor product operation, such that `V ⊗ one(V) == V`.
232232
"""
233+
#TODO: unit(V::S)?
233234
Base.one(V::VectorSpace) = one(typeof(V))
234235
Base.one(::Type{<:ProductSpace{S}}) where {S <: ElementarySpace} = ProductSpace{S, 0}(())
235236
Base.one(::Type{S}) where {S <: ElementarySpace} = ProductSpace{S, 0}(())
@@ -240,8 +241,8 @@ function Base.literal_pow(::typeof(^), V::ElementarySpace, p::Val{N}) where {N}
240241
return ProductSpace{typeof(V), N}(ntuple(n -> V, p))
241242
end
242243

243-
fuse(P::ProductSpace{S, 0}) where {S <: ElementarySpace} = oneunit(S)
244-
fuse(P::ProductSpace{S}) where {S <: ElementarySpace} = fuse(P.spaces...)
244+
fuse(P::ProductSpace{S,0}) where {S<:ElementarySpace} = unitspace(S)
245+
fuse(P::ProductSpace{S}) where {S<:ElementarySpace} = fuse(P.spaces...)
245246

246247
"""
247248
insertleftunit(P::ProductSpace, i::Int=length(P) + 1; conj=false, dual=false)
@@ -252,10 +253,9 @@ More specifically, adds a left monoidal unit or its dual.
252253
253254
See also [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
254255
"""
255-
function insertleftunit(
256-
P::ProductSpace, ::Val{i} = Val(length(P) + 1); conj::Bool = false, dual::Bool = false
257-
) where {i}
258-
u = oneunit(spacetype(P))
256+
function insertleftunit(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
257+
conj::Bool=false, dual::Bool=false) where {i}
258+
u = unitspace(spacetype(P))
259259
if dual
260260
u = TensorKit.dual(u)
261261
end
@@ -274,10 +274,9 @@ More specifically, adds a right monoidal unit or its dual.
274274
275275
See also [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
276276
"""
277-
function insertrightunit(
278-
P::ProductSpace, ::Val{i} = Val(length(P)); conj::Bool = false, dual::Bool = false
279-
) where {i}
280-
u = oneunit(spacetype(P))
277+
function insertrightunit(P::ProductSpace, ::Val{i}=Val(length(P));
278+
conj::Bool=false, dual::Bool=false) where {i}
279+
u = unitspace(spacetype(P))
281280
if dual
282281
u = TensorKit.dual(u)
283282
end
@@ -299,7 +298,7 @@ and [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}
299298
"""
300299
function removeunit(P::ProductSpace, ::Val{i}) where {i}
301300
1 i length(P) || _boundserror(P, i)
302-
isisomorphic(P[i], oneunit(P[i])) || _nontrivialspaceerror(P, i)
301+
isisomorphic(P[i], unitspace(P[i])) || _nontrivialspaceerror(P, i)
303302
return ProductSpace{spacetype(P)}(TupleTools.deleteat(P.spaces, i))
304303
end
305304

@@ -326,8 +325,8 @@ function Base.promote_rule(::Type{S}, ::Type{<:ProductSpace{S}}) where {S <: Ele
326325
end
327326

328327
# ProductSpace to ElementarySpace
329-
Base.convert(::Type{S}, P::ProductSpace{S, 0}) where {S <: ElementarySpace} = oneunit(S)
330-
Base.convert(::Type{S}, P::ProductSpace{S}) where {S <: ElementarySpace} = fuse(P.spaces...)
328+
Base.convert(::Type{S}, P::ProductSpace{S,0}) where {S<:ElementarySpace} = unitspace(S)
329+
Base.convert(::Type{S}, P::ProductSpace{S}) where {S<:ElementarySpace} = fuse(P.spaces...)
331330

332331
# ElementarySpace to ProductSpace
333332
Base.convert(::Type{<:ProductSpace}, V::S) where {S <: ElementarySpace} = (V)

src/spaces/vectorspaces.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Base.adjoint(V::VectorSpace) = dual(V)
8080
"""
8181
isdual(V::ElementarySpace) -> Bool
8282
83-
Return wether an ElementarySpace `V` is normal or rather a dual space. Always returns
83+
Return whether an ElementarySpace `V` is normal or rather a dual space. Always returns
8484
`false` for spaces where `V == dual(V)`.
8585
"""
8686
function isdual end
@@ -120,21 +120,23 @@ Return the sum of all degeneracy dimensions of the vector space `V`.
120120
reduceddim(V::ElementarySpace) = sum(Base.Fix1(dim, V), sectors(V); init = 0)
121121

122122
"""
123-
oneunit(V::S) where {S<:ElementarySpace} -> S
123+
unitspace(V::S) where {S<:ElementarySpace} -> S
124124
125125
Return the corresponding vector space of type `S` that represents the trivial
126126
one-dimensional space, i.e. the space that is isomorphic to the corresponding field. Note
127127
that this is different from `one(V::S)`, which returns the empty product space
128-
`ProductSpace{S,0}(())`.
128+
`ProductSpace{S,0}(())`. `Base.oneunit` falls back to `unitspace`.
129129
"""
130-
Base.oneunit(V::ElementarySpace) = oneunit(typeof(V))
130+
unitspace(V::ElementarySpace) = unitspace(typeof(V))
131+
Base.oneunit(V::ElementarySpace) = unitspace(V)
131132

132133
"""
133134
zero(V::S) where {S<:ElementarySpace} -> S
134135
135136
Return the corresponding vector space of type `S` that represents the zero-dimensional or empty space.
136137
This is, with a slight abuse of notation, the zero element of the direct sum of vector spaces.
137138
"""
139+
#TODO: zerospace?
138140
Base.zero(V::ElementarySpace) = zero(typeof(V))
139141

140142
"""

0 commit comments

Comments
 (0)