|
3 | 3 |
|
4 | 4 | #include <SeQuant/core/complex.hpp> |
5 | 5 | #include <SeQuant/core/expressions/expr.hpp> |
6 | | -#include <SeQuant/core/expressions/expr_ptr.hpp> |
7 | | -#include <SeQuant/core/io/latex/latex.hpp> |
8 | 6 | #include <SeQuant/core/rational.hpp> |
9 | 7 | #include <SeQuant/core/utility/macros.hpp> |
10 | 8 |
|
|
14 | 12 |
|
15 | 13 | namespace sequant { |
16 | 14 |
|
| 15 | +class ExprPtr; |
| 16 | + |
17 | 17 | // implementation details of Constant; prefer sequant::detail over an unnamed |
18 | 18 | // namespace in a header (see CppCoreGuidelines SF.21) |
19 | 19 | namespace detail { |
@@ -67,68 +67,37 @@ class Constant : public Expr { |
67 | 67 | throw Exception("Constant::value<T>: cannot convert value to type T"); |
68 | 68 | } |
69 | 69 |
|
70 | | - std::wstring to_latex() const override { |
71 | | - return L"{" + io::latex::to_string(value()) + L"}"; |
72 | | - } |
| 70 | + std::wstring to_latex() const override; |
73 | 71 |
|
74 | | - type_id_type type_id() const override { return get_type_id<Constant>(); } |
| 72 | + type_id_type type_id() const override; |
75 | 73 |
|
76 | | - bool is_scalar() const override { return true; } |
| 74 | + bool is_scalar() const override; |
77 | 75 |
|
78 | | - ExprPtr clone() const override { return ex<Constant>(this->value()); } |
| 76 | + ExprPtr clone() const override; |
79 | 77 |
|
80 | 78 | /// @brief adjoint of a Constant is its complex conjugate |
81 | 79 | virtual void adjoint() override; |
82 | 80 |
|
83 | | - virtual Expr &operator*=(const Expr &that) override { |
84 | | - if (that.is<Constant>()) { |
85 | | - value_ *= that.as<Constant>().value(); |
86 | | - } else { |
87 | | - throw Exception("Constant::operator*=(that): not valid for that"); |
88 | | - } |
89 | | - return *this; |
90 | | - } |
| 81 | + Constant &operator*=(const Expr &that); |
91 | 82 |
|
92 | | - virtual Expr &operator+=(const Expr &that) override { |
93 | | - if (that.is<Constant>()) { |
94 | | - value_ += that.as<Constant>().value(); |
95 | | - } else { |
96 | | - throw Exception("Constant::operator+=(that): not valid for that"); |
97 | | - } |
98 | | - return *this; |
99 | | - } |
| 83 | + Constant &operator+=(const Expr &that); |
100 | 84 |
|
101 | | - virtual Expr &operator-=(const Expr &that) override { |
102 | | - if (that.is<Constant>()) { |
103 | | - value_ -= that.as<Constant>().value(); |
104 | | - } else { |
105 | | - throw Exception("Constant::operator-=(that): not valid for that"); |
106 | | - } |
107 | | - return *this; |
108 | | - } |
| 85 | + Constant &operator-=(const Expr &that); |
109 | 86 |
|
110 | 87 | /// @param[in] v a scalar |
111 | 88 | /// @return true if this is zero |
112 | | - static bool is_zero(scalar_type v) { return v.is_zero(); } |
| 89 | + static bool is_zero(scalar_type v); |
113 | 90 |
|
114 | 91 | /// @return `Constant::is_zero(this->value())` |
115 | | - bool is_zero() const final { return is_zero(this->value()); } |
| 92 | + bool is_zero() const final; |
116 | 93 |
|
117 | 94 | private: |
118 | 95 | scalar_type value_; |
119 | 96 |
|
120 | | - hash_type memoizing_hash() const override { |
121 | | - if (!hash_value_) { |
122 | | - hash_value_ = hash::value(value_); |
123 | | - } else { |
124 | | - SEQUANT_ASSERT(*hash_value_ == hash::value(value_)); |
125 | | - } |
126 | | - return *hash_value_; |
127 | | - } |
| 97 | + hash_type memoizing_hash() const override; |
| 98 | + |
| 99 | + bool static_equal(const Expr &that) const override; |
128 | 100 |
|
129 | | - bool static_equal(const Expr &that) const override { |
130 | | - return value() == static_cast<const Constant &>(that).value(); |
131 | | - } |
132 | 101 | }; // class Constant |
133 | 102 |
|
134 | 103 | } // namespace sequant |
|
0 commit comments