Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
symmetry.hpp
Go to the documentation of this file.
1
9#pragma once
10
12
13#include <span>
14#include <stdexcept>
15#include <string>
16#include <string_view>
17
18namespace uni20
19{
20
24class Symmetry {
25 public:
27 Symmetry() = default;
28
31 explicit Symmetry(std::string_view spec) : impl_(detail::SymmetryImpl::parse(spec)) {}
32
35 explicit Symmetry(detail::SymmetryImpl const* impl) : impl_(impl) {}
36
40 static auto parse(std::string_view spec) -> Symmetry { return Symmetry{detail::SymmetryImpl::parse(spec)}; }
41
44 auto valid() const -> bool { return impl_ != nullptr; }
45
48 auto factor_count() const -> std::size_t
49 {
50 this->ensure_valid();
51 return impl_->factor_count();
52 }
53
56 auto factors() const -> std::span<detail::SymmetryFactorSpec const>
57 {
58 this->ensure_valid();
59 return impl_->factors();
60 }
61
64 auto to_string() const -> std::string
65 {
66 this->ensure_valid();
67 return impl_->to_string();
68 }
69
72 auto impl() const -> detail::SymmetryImpl const*
73 {
74 this->ensure_valid();
75 return impl_;
76 }
77
81 auto operator==(Symmetry const& other) const -> bool = default;
82
83 private:
85 void ensure_valid() const
86 {
87 if (!this->valid())
88 {
89 throw std::logic_error("Symmetry handle is not initialized");
90 }
91 }
92
93 detail::SymmetryImpl const* impl_ = nullptr;
94};
95
99inline auto to_string(Symmetry const& symmetry) -> std::string { return symmetry.to_string(); }
100
101} // namespace uni20
Public handle to a canonicalized direct-product symmetry specification.
Definition symmetry.hpp:24
Symmetry(detail::SymmetryImpl const *impl)
Construct from a canonical implementation pointer.
Definition symmetry.hpp:35
static auto parse(std::string_view spec) -> Symmetry
Parse a string specification such as "N:U(1),Sz:U(1)".
Definition symmetry.hpp:40
auto operator==(Symmetry const &other) const -> bool=default
Compare two symmetry handles for canonical identity.
auto factors() const -> std::span< detail::SymmetryFactorSpec const >
Return the named factor list.
Definition symmetry.hpp:56
auto to_string() const -> std::string
Return the canonical string spelling of this symmetry.
Definition symmetry.hpp:64
auto valid() const -> bool
Return whether this handle refers to a valid symmetry.
Definition symmetry.hpp:44
auto impl() const -> detail::SymmetryImpl const *
Return the internal canonical symmetry implementation pointer.
Definition symmetry.hpp:72
auto factor_count() const -> std::size_t
Return the number of direct-product factors.
Definition symmetry.hpp:48
Symmetry()=default
Construct an invalid symmetry handle.
Symmetry(std::string_view spec)
Construct a symmetry from its string specification.
Definition symmetry.hpp:31
Definition qnum.hpp:403
Definition async/async.hpp:26
auto to_string(basic_half_int< T > value) -> std::string
Format a half-integer as an integer or decimal .5.
Definition half_int.hpp:477
std::size_t span
Definition presentation.cpp:2017
Defines the internal canonicalized representation of direct-product symmetries.