Skip to content

Commit 8d2a356

Browse files
committed
add unitspace
1 parent 6b4eb48 commit 8d2a356

File tree

8 files changed

+26
-24
lines changed

8 files changed

+26
-24
lines changed

docs/src/lib/spaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ conj
9191
flip
9292
9393
zero(::ElementarySpace)
94-
oneunit
94+
unitspace
9595
supremum
9696
infimum
9797
```

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
(V₁::CartesianSpace, V₂::CartesianSpace) = CartesianSpace(V₁.d + V₂.d)
5353
fuse(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
function (V₁::ComplexSpace, V₂::ComplexSpace)
5454
return isdual(V₁) == isdual(V₂) ?

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ function Base.axes(V::GradedSpace{I}, c::I) where {I<:Sector}
130130
end
131131
return (offset + 1):(offset + dim(c) * dim(V, c))
132132
end
133-
134-
Base.oneunit(S::Type{<:GradedSpace{I}}) where {I<:Sector} = S(one(I) => 1)
133+
#TODO: one -> unit
134+
unitspace(S::Type{<:GradedSpace{I}}) where {I<:Sector} = S(one(I) => 1)
135135
Base.zero(S::Type{<:GradedSpace{I}}) where {I<:Sector} = S(one(I) => 0)
136136

137137
# TODO: the following methods can probably be implemented more efficiently for

src/spaces/productspace.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ end
232232
Return a tensor product of zero spaces of type `S`, i.e. this is the unit object under the
233233
tensor product operation, such that `V ⊗ one(V) == V`.
234234
"""
235+
#TODO: unit(V::S)?
235236
Base.one(V::VectorSpace) = one(typeof(V))
236237
Base.one(::Type{<:ProductSpace{S}}) where {S<:ElementarySpace} = ProductSpace{S,0}(())
237238
Base.one(::Type{S}) where {S<:ElementarySpace} = ProductSpace{S,0}(())
@@ -242,7 +243,7 @@ function Base.literal_pow(::typeof(^), V::ElementarySpace, p::Val{N}) where {N}
242243
return ProductSpace{typeof(V),N}(ntuple(n -> V, p))
243244
end
244245

245-
fuse(P::ProductSpace{S,0}) where {S<:ElementarySpace} = oneunit(S)
246+
fuse(P::ProductSpace{S,0}) where {S<:ElementarySpace} = unitspace(S)
246247
fuse(P::ProductSpace{S}) where {S<:ElementarySpace} = fuse(P.spaces...)
247248

248249
"""
@@ -256,7 +257,7 @@ See also [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) wher
256257
"""
257258
function insertleftunit(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
258259
conj::Bool=false, dual::Bool=false) where {i}
259-
u = oneunit(spacetype(P))
260+
u = unitspace(spacetype(P))
260261
if dual
261262
u = TensorKit.dual(u)
262263
end
@@ -277,7 +278,7 @@ See also [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where
277278
"""
278279
function insertrightunit(P::ProductSpace, ::Val{i}=Val(length(P));
279280
conj::Bool=false, dual::Bool=false) where {i}
280-
u = oneunit(spacetype(P))
281+
u = unitspace(spacetype(P))
281282
if dual
282283
u = TensorKit.dual(u)
283284
end
@@ -299,7 +300,7 @@ and [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}
299300
"""
300301
function removeunit(P::ProductSpace, ::Val{i}) where {i}
301302
1 i length(P) || _boundserror(P, i)
302-
isisomorphic(P[i], oneunit(P[i])) || _nontrivialspaceerror(P, i)
303+
isisomorphic(P[i], unitspace(P[i])) || _nontrivialspaceerror(P, i)
303304
return ProductSpace{spacetype(P)}(TupleTools.deleteat(P.spaces, i))
304305
end
305306

@@ -326,7 +327,7 @@ function Base.promote_rule(::Type{S}, ::Type{<:ProductSpace{S}}) where {S<:Eleme
326327
end
327328

328329
# 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,0}) where {S<:ElementarySpace} = unitspace(S)
330331
Base.convert(::Type{S}, P::ProductSpace{S}) where {S<:ElementarySpace} = fuse(P.spaces...)
331332

332333
# ElementarySpace to ProductSpace

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)