Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
98bb938
Move ExprPtr related things to expr_ptr.cpp
Krzmbrzl Aug 12, 2026
788c8ba
Also separate impl of Constant to dedicated file
Krzmbrzl Aug 12, 2026
516504d
Remove in-place arithmetic operators from Expr interface
Krzmbrzl Aug 12, 2026
7c0211d
Make certain Expr API functions pure virtual
Krzmbrzl Aug 12, 2026
0f7724a
Fix error message assembly
Krzmbrzl Aug 12, 2026
926eca9
Clean up Variable impl
Krzmbrzl Aug 12, 2026
5279d12
Clean up Power impl
Krzmbrzl Aug 12, 2026
8e476fc
Add declaration of specialization of NormalOperator::labels()
Krzmbrzl Aug 12, 2026
873e0f1
Remove outdated comments
Krzmbrzl Aug 17, 2026
0bb04be
Make Product::operator* non-virtual
Krzmbrzl Aug 17, 2026
06c0b93
Reset memoized hash after modification
Krzmbrzl Aug 17, 2026
e37010c
Remove declaration of non-existent function
Krzmbrzl Aug 17, 2026
6ac7b1a
Separate Product impl
Krzmbrzl Aug 17, 2026
0fb64e5
Cleanly separate public and private interface
Krzmbrzl Aug 17, 2026
6e6b625
Cleanly separate (N)CProduct impl
Krzmbrzl Aug 17, 2026
6120935
Move some headers to impl file
Krzmbrzl Aug 17, 2026
94b967e
Remove redundant swap function
Krzmbrzl Aug 17, 2026
1dd0734
Add missing header
Krzmbrzl Aug 17, 2026
2d90288
Separate Sum impl
Krzmbrzl Aug 17, 2026
8f2f145
Remove redundant headers
Krzmbrzl Aug 17, 2026
92c8eeb
Add back missing header
Krzmbrzl Aug 17, 2026
1ad9644
Do not slice CProduct/NCProduct in clone()
evaleev Aug 22, 2026
53e3585
Keep NCProduct::adjoint() on range-v3 views
evaleev Aug 22, 2026
da3050f
Replace range/v3/all.hpp with targeted includes in product.cpp
evaleev Aug 22, 2026
25ada93
Clean up leftovers from the expression impl split
evaleev Aug 22, 2026
b2a5204
Include hash.hpp where hash:: is used
evaleev Aug 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,28 @@ set(SeQuant_symb_src
SeQuant/core/context.hpp
SeQuant/core/expressions/abstract_tensor.cpp
SeQuant/core/expressions/abstract_tensor.hpp
SeQuant/core/expressions/constant.cpp
SeQuant/core/expressions/constant.hpp
SeQuant/core/expressions/expr.cpp
SeQuant/core/expressions/expr.hpp
SeQuant/core/expressions/expr_algorithms.cpp
SeQuant/core/expressions/expr_algorithms.hpp
SeQuant/core/expressions/expr_operators.hpp
SeQuant/core/expressions/expr_ptr.cpp
SeQuant/core/expressions/expr_ptr.hpp
SeQuant/core/expressions/expr_range.hpp
SeQuant/core/expressions/power.cpp
SeQuant/core/expressions/power.hpp
SeQuant/core/expressions/product.cpp
SeQuant/core/expressions/product.hpp
SeQuant/core/expressions/result_expr.cpp
SeQuant/core/expressions/result_expr.hpp
SeQuant/core/expressions/sum.cpp
SeQuant/core/expressions/sum.hpp
SeQuant/core/expressions/tensor.cpp
SeQuant/core/expressions/tensor.hpp
SeQuant/core/expressions/variable.cpp
SeQuant/core/expressions/variable.hpp
SeQuant/core/hash.cpp
SeQuant/core/hash.hpp
SeQuant/core/hugenholtz.hpp
Expand Down
78 changes: 78 additions & 0 deletions SeQuant/core/expressions/constant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <SeQuant/core/expressions/constant.hpp>
#include <SeQuant/core/expressions/expr_ptr.hpp>
#include <SeQuant/core/hash.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/utility/exception.hpp>
#include <SeQuant/core/utility/macros.hpp>

namespace sequant {

std::wstring Constant::to_latex() const {
return L"{" + io::latex::to_string(value()) + L"}";
}

Expr::type_id_type Constant::type_id() const { return get_type_id<Constant>(); }

bool Constant::is_scalar() const { return true; }

ExprPtr Constant::clone() const { return ex<Constant>(this->value()); }

void Constant::adjoint() {
value_ = conj(value_);
reset_hash_value();
}

Constant &Constant::operator*=(const Expr &that) {
if (that.is<Constant>()) {
value_ *= that.as<Constant>().value();
} else {
throw Exception("Constant::operator*=(that): not valid for that");
}

reset_hash_value();

return *this;
}

Constant &Constant::operator+=(const Expr &that) {
if (that.is<Constant>()) {
value_ += that.as<Constant>().value();
} else {
throw Exception("Constant::operator+=(that): not valid for that");
}

reset_hash_value();

return *this;
}

Constant &Constant::operator-=(const Expr &that) {
if (that.is<Constant>()) {
value_ -= that.as<Constant>().value();
} else {
throw Exception("Constant::operator-=(that): not valid for that");
}

reset_hash_value();

return *this;
}

bool Constant::is_zero(scalar_type v) { return v.is_zero(); }

bool Constant::is_zero() const { return is_zero(this->value()); }

Expr::hash_type Constant::memoizing_hash() const {
if (!hash_value_) {
hash_value_ = hash::value(value_);
} else {
SEQUANT_ASSERT(*hash_value_ == hash::value(value_));
}
return *hash_value_;
}

bool Constant::static_equal(const Expr &that) const {
return value() == static_cast<const Constant &>(that).value();
}

} // namespace sequant
59 changes: 14 additions & 45 deletions SeQuant/core/expressions/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include <SeQuant/core/complex.hpp>
#include <SeQuant/core/expressions/expr.hpp>
#include <SeQuant/core/expressions/expr_ptr.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/rational.hpp>
#include <SeQuant/core/utility/macros.hpp>

Expand All @@ -14,6 +12,8 @@

namespace sequant {

class ExprPtr;

// implementation details of Constant; prefer sequant::detail over an unnamed
// namespace in a header (see CppCoreGuidelines SF.21)
namespace detail {
Expand Down Expand Up @@ -67,68 +67,37 @@ class Constant : public Expr {
throw Exception("Constant::value<T>: cannot convert value to type T");
}

std::wstring to_latex() const override {
return L"{" + io::latex::to_string(value()) + L"}";
}
std::wstring to_latex() const override;

type_id_type type_id() const override { return get_type_id<Constant>(); }
type_id_type type_id() const override;

bool is_scalar() const override { return true; }
bool is_scalar() const override;

ExprPtr clone() const override { return ex<Constant>(this->value()); }
ExprPtr clone() const override;

/// @brief adjoint of a Constant is its complex conjugate
virtual void adjoint() override;

virtual Expr &operator*=(const Expr &that) override {
if (that.is<Constant>()) {
value_ *= that.as<Constant>().value();
} else {
throw Exception("Constant::operator*=(that): not valid for that");
}
return *this;
}
Constant &operator*=(const Expr &that);

virtual Expr &operator+=(const Expr &that) override {
if (that.is<Constant>()) {
value_ += that.as<Constant>().value();
} else {
throw Exception("Constant::operator+=(that): not valid for that");
}
return *this;
}
Constant &operator+=(const Expr &that);

virtual Expr &operator-=(const Expr &that) override {
if (that.is<Constant>()) {
value_ -= that.as<Constant>().value();
} else {
throw Exception("Constant::operator-=(that): not valid for that");
}
return *this;
}
Constant &operator-=(const Expr &that);

/// @param[in] v a scalar
/// @return true if this is zero
static bool is_zero(scalar_type v) { return v.is_zero(); }
static bool is_zero(scalar_type v);

/// @return `Constant::is_zero(this->value())`
bool is_zero() const final { return is_zero(this->value()); }
bool is_zero() const final;

private:
scalar_type value_;

hash_type memoizing_hash() const override {
if (!hash_value_) {
hash_value_ = hash::value(value_);
} else {
SEQUANT_ASSERT(*hash_value_ == hash::value(value_));
}
return *hash_value_;
}
hash_type memoizing_hash() const override;

bool static_equal(const Expr &that) const override;

bool static_equal(const Expr &that) const override {
return value() == static_cast<const Constant &>(that).value();
}
}; // class Constant

} // namespace sequant
Expand Down
Loading
Loading