21#ifndef _libint2_src_bin_libint_algebra_h_
22#define _libint2_src_bin_libint_algebra_h_
24#include <class_registry.h>
27#include <global_macros.h>
35 typedef enum { Plus, Minus, Times, Divide } OperatorType;
37static const char OperatorSymbol[][2] = {
"+",
"-",
"*",
"/"};
50 typedef algebra::OperatorTypes::OperatorType OperatorType;
53 const std::shared_ptr<T>&
right)
58 label_(algebra::OperatorSymbol[OT_]) {}
63 const std::shared_ptr<T>&
left,
64 const std::shared_ptr<T>&
right)
72 std::cout <<
"AlgebraicOperator<DGVertex> copy constructor: number of "
76 typedef DGVertex::ArcSetType::const_iterator aciter;
78 auto left_arg = (*a)->dest();
80 auto right_arg = (*a)->dest();
82 if (left_ != left_arg && left_ != right_arg)
83 std::cout <<
"AlgebraicOperator<DGVertex> copy constructor: invalid "
86 if (right_ != left_arg && right_ != right_arg)
87 std::cout <<
"AlgebraicOperator<DGVertex> copy constructor: invalid "
95 OperatorType
type()
const {
return OT_; }
97 const std::shared_ptr<T>&
left()
const {
return left_; }
99 const std::shared_ptr<T>&
right()
const {
return right_; }
105 unsigned int size()
const override {
return 1; }
107 bool equiv(
const std::shared_ptr<DGVertex>& a)
const override {
109#if ALGEBRAICOPERATOR_USE_KEY_TO_COMPARE
110#if USE_INT_KEY_TO_COMPARE
111 if (
key() == a->key())
113 std::static_pointer_cast<AlgebraicOperator, DGVertex>(a);
120 return *
this == std::static_pointer_cast<AlgebraicOperator, DGVertex>(a);
127 bool operator==(
const std::shared_ptr<AlgebraicOperator>& a)
const {
128#if ALGEBRAICOPERATOR_USE_SHAREDPTR
131 if (left_->equiv(a->left()) && left_ != a->left_) {
132 std::cout <<
"Left arguments are equivalent but pointers differ!"
134 std::cout << left_->description() << std::endl;
135 std::cout << a->left_->description() << std::endl;
139 if (right_->equiv(a->right()) && right_ != a->right_) {
140 std::cout <<
"Left arguments are equivalent but pointers differ!"
142 std::cout << right_->description() << std::endl;
143 std::cout << a->right_->description() << std::endl;
147#if ALGEBRAICOPERATOR_USE_SHAREDPTR
148 if (left_ == a->left_ && right_ == a->right_)
150 if (left_->equiv(a->left()) && right_->equiv(a->right()))
160 const std::string&
label()
const override {
return label_; }
162 const std::string&
id()
const override {
return label(); }
165 std::ostringstream os;
166 os <<
"( ( " << left_->description() <<
" ) "
167 << algebra::OperatorSymbol[OT_] <<
" ( " << right_->description()
169 const std::string descr = os.str();
176 "AlgebraicOperator::del_exit_arcs() -- cannot safely use del_exit_arcs "
177 "on operator vertices.");
181 typename DGVertex::KeyReturnType
key()
const override {
return 0; }
183 void print(std::ostream& os)
const override {
185 std::string prefix(
"AlgebraicOperator::print: ");
186 os << prefix <<
"this = " <<
this << std::endl;
187 os << prefix <<
"left_ = " << left_ << std::endl;
188 os << prefix <<
"right_ = " << right_ << std::endl;
193 std::shared_ptr<T> left_;
194 std::shared_ptr<T> right_;
197 bool this_precomputed()
const override {
return false; }
221template <
class C,
class T>
224 typedef std::pair<C, T> term_t;
225 typedef std::vector<term_t> data_t;
238 size_t size()
const {
return data_.size(); }
239 const term_t& operator[](
unsigned int i)
const {
return data_[i]; }
247template <
class L,
class R>
249 Wedge(
const L& l,
const R& r) : left(l), right(r) {}
253template <
class L,
class R>
259template <
class C,
class Tl,
class Tr>
261 const std::pair<C, Tl>& L,
const std::pair<C, Tr>& R) {
262 return make_pair(L.first * R.first, L.second ^ R.second);
266template <
class C,
class Tl,
class Tr>
267typename LinearCombination<C, algebra::Wedge<Tl, Tr> >::data_t* operator^(
268 const LinearCombination<C, Tl>& L,
const LinearCombination<C, Tr>& R) {
269 typedef typename LinearCombination<C, algebra::Wedge<Tl, Tr> >::data_t data_t;
270 data_t* result =
new data_t;
271 const size_t nL = L.size();
272 const size_t nR = R.size();
273 for (
unsigned int l = 0; l < nL; ++l)
274 for (
unsigned int r = 0; r < nR; ++r) {
275 result->push_back(algebra::wedge(L[l], R[r]));
280template <
class C,
class Tl,
class Tr>
281typename LinearCombination<C, algebra::Wedge<Tl, Tr> >::data_t* operator^(
282 const Tl& L,
const LinearCombination<C, Tr>& R) {
283 typedef typename LinearCombination<C, algebra::Wedge<Tl, Tr> >::data_t data_t;
284 data_t* result =
new data_t;
285 const size_t nR = R.size();
286 for (
unsigned int r = 0; r < nR; ++r) {
287 result->push_back(L ^ R[r]);
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition algebra.h:47
const std::string & id() const override
Implements DGVertex::id()
Definition algebra.h:162
bool equiv(const std::shared_ptr< DGVertex > &a) const override
Implements DGVertex::equiv()
Definition algebra.h:107
const std::string & label() const override
Implements DGVertex::label()
Definition algebra.h:160
void del_exit_arcs() override
Overloads DGVertex::del_exit_arcs()
Definition algebra.h:174
bool operator==(const std::shared_ptr< AlgebraicOperator > &a) const
laboriously compare 2 operators element by element
Definition algebra.h:127
const std::shared_ptr< T > & right() const
Returns the right argument.
Definition algebra.h:99
std::string description() const override
Implements DGVertex::description()
Definition algebra.h:164
unsigned int size() const override
Implements DGVertex::size()
Definition algebra.h:105
void add_exit_arc(const std::shared_ptr< DGArc > &a) override
Overloads DGVertex::add_exit_arc().
const std::shared_ptr< T > & left() const
Returns the left argument.
Definition algebra.h:97
OperatorType type() const
Returns the OperatorType.
Definition algebra.h:95
void print(std::ostream &os) const override
print(os) prints vertex info to os
Definition algebra.h:183
DGVertex::KeyReturnType key() const override
Implements Hashable::key()
Definition algebra.h:181
AlgebraicOperator(const std::shared_ptr< AlgebraicOperator > &A, const std::shared_ptr< T > &left, const std::shared_ptr< T > &right)
Clone A but replace operands with left and right.
Definition algebra.h:62
Definition exception.h:37
Objects of this type provide limited information about the class at runtime.
Definition class_registry.h:46
This is a vertex of a Directed Graph (DG)
Definition dgvertex.h:44
ClassID typeid_
typeid stores the ClassID of the concrete type.
Definition dgvertex.h:71
unsigned int num_exit_arcs() const
returns the number of children
Definition dgvertex.cc:254
DGVertex(ClassID tid)
Sets typeid to tid.
Definition dgvertex.cc:32
ArcSetType::const_iterator first_exit_arc() const
returns children::begin()
Definition dgvertex.h:124
virtual void print(std::ostream &os) const
print(os) prints vertex info to os
Definition dgvertex.cc:433
represents linear combination of objects of type T with coefficients of type C
Definition algebra.h:222
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
Wedge is a typeholder for the result of a wedge product.
Definition algebra.h:248