20 #ifndef _libint2_src_bin_libint_algebra_h_ 21 #define _libint2_src_bin_libint_algebra_h_ 23 #include <smart_ptr.h> 25 #include <exception.h> 26 #include <global_macros.h> 28 #include <class_registry.h> 34 typedef enum {Plus, Minus, Times, Divide} OperatorType;
36 static const char OperatorSymbol[][2] = {
"+",
"-",
"*",
"/" };
53 typedef algebra::OperatorTypes::OperatorType OperatorType;
56 const SafePtr<T>& left,
57 const SafePtr<T>& right) :
59 label_(algebra::OperatorSymbol[OT_])
66 const SafePtr<T>& left,
67 const SafePtr<T>& right) :
69 left_(left), right_(right), label_(A->label_)
72 if (num_exit_arcs() != 2)
73 cout <<
"AlgebraicOperator<DGVertex> copy constructor: number of children != 2" << endl;
76 typedef DGVertex::ArcSetType::const_iterator aciter;
77 aciter a = this->first_exit_arc();
78 auto left_arg = (*a)->dest(); ++a;
79 auto right_arg = (*a)->dest();
81 if (left_ != left_arg && left_ != right_arg)
82 cout <<
"AlgebraicOperator<DGVertex> copy constructor: invalid left operand given" << endl;
83 if (right_ != left_arg && right_ != right_arg)
84 cout <<
"AlgebraicOperator<DGVertex> copy constructor: invalid right operand given" << endl;
90 OperatorType
type()
const {
return OT_; }
92 const SafePtr<T>&
left()
const {
return left_; }
94 const SafePtr<T>&
right()
const {
return right_; }
97 void add_exit_arc(
const SafePtr<DGArc>& a);
99 unsigned int size()
const {
return 1; }
101 bool equiv(
const SafePtr<DGVertex>& a)
const 103 if (typeid_ == a->typeid_) {
104 #if ALGEBRAICOPERATOR_USE_KEY_TO_COMPARE 105 #if USE_INT_KEY_TO_COMPARE 106 if (key() == a->key())
107 return *
this == static_pointer_cast<AlgebraicOperator,DGVertex>(a);
111 return description() == a->description();
123 #if ALGEBRAICOPERATOR_USE_SAFEPTR 125 if (left_->equiv(a->left()) && left_ != a->left_) {
126 cout <<
"Left arguments are equivalent but pointers differ!" << endl;
127 cout << left_->description() << endl;
128 cout << a->left_->description() << endl;
131 if (right_->equiv(a->right()) && right_ != a->right_) {
132 cout <<
"Left arguments are equivalent but pointers differ!" << endl;
133 cout << right_->description() << endl;
134 cout << a->right_->description() << endl;
138 #if ALGEBRAICOPERATOR_USE_SAFEPTR 139 if (left_ == a->left_ && right_ == a->right_)
141 if (left_->equiv(a->left()) && right_->equiv(a->right()))
157 const std::string&
id()
const 165 os <<
"( ( " << left_->description() <<
" ) " 166 << algebra::OperatorSymbol[OT_] <<
" ( " 167 << right_->description() <<
" ) )";
168 const std::string descr = os.str();
175 throw CannotAddArc(
"AlgebraicOperator::del_exit_arcs() -- cannot safely use del_exit_arcs on operator vertices.");
179 typename DGVertex::KeyReturnType
key()
const {
return 0; }
181 void print(std::ostream& os)
const {
184 std::string prefix(
"AlgebraicOperator::print: ");
185 os << prefix <<
"this = " <<
this << endl;
186 os << prefix <<
"left_ = " << left_ << endl;
187 os << prefix <<
"right_ = " << right_ << endl;
196 bool this_precomputed()
const 221 template <
class C,
class T>
224 typedef std::pair<C,T> term_t;
225 typedef std::vector<term_t> data_t;
235 size_t size()
const {
return data_.size(); }
236 const term_t& operator[](
unsigned int i)
const {
return data_[i]; }
244 template <
class L,
class R>
246 Wedge(
const L& l,
const R& r) : left(l), right(r) {}
250 template <
class L,
class R>
Wedge<L,R> make_wedge(
const L& l,
const R& r) {
return Wedge<L,R>(l,r); }
253 template <
class C,
class Tl,
class Tr>
255 wedge(
const std::pair<C,Tl>& L,
256 const std::pair<C,Tr>& R) {
257 return make_pair(L.first*R.first,
263 template <
class C,
class Tl,
class Tr>
268 data_t* result =
new data_t;
269 const size_t nL = L.size();
270 const size_t nR = R.size();
271 for(
unsigned int l=0; l<nL; ++l)
272 for(
unsigned int r=0; r<nR; ++r) {
273 result->push_back(algebra::wedge(L[l],R[r]));
278 template <
class C,
class Tl,
class Tr>
280 operator^(
const Tl& L,
283 data_t* result =
new data_t;
284 const size_t nR = R.size();
285 for(
unsigned int r=0; r<nR; ++r) {
286 result->push_back(L ^ R[r]);
const SafePtr< T > & left() const
Returns the left argument.
Definition: algebra.h:92
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
Wedge is a typeholder for the result of a wedge product.
Definition: algebra.h:245
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:42
const std::string & id() const
Implements DGVertex::id()
Definition: algebra.h:157
const SafePtr< T > & right() const
Returns the right argument.
Definition: algebra.h:94
std::string description() const
Implements DGVertex::description()
Definition: algebra.h:162
void del_exit_arcs()
Overloads DGVertex::del_exit_arcs()
Definition: algebra.h:173
virtual void print(std::ostream &os) const
print(os) prints vertex info to os
Definition: dgvertex.cc:455
represents linear combination of objects of type T with coefficients of type C
Definition: algebra.h:222
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition: algebra.h:47
bool operator==(const SafePtr< AlgebraicOperator > &a) const
laboriously compare 2 operators element by element
Definition: algebra.h:122
const std::string & label() const
Implements DGVertex::label()
Definition: algebra.h:152
Objects of this type provide limited information about the class at runtime.
Definition: class_registry.h:43
Definition: exception.h:39
unsigned int size() const
Implements DGVertex::size()
Definition: algebra.h:99
bool equiv(const SafePtr< DGVertex > &a) const
Implements DGVertex::equiv()
Definition: algebra.h:101
AlgebraicOperator(const SafePtr< AlgebraicOperator > &A, const SafePtr< T > &left, const SafePtr< T > &right)
Clone A but replace operands with left and right.
Definition: algebra.h:65
OperatorType type() const
Returns the OperatorType.
Definition: algebra.h:90
void print(std::ostream &os) const
print(os) prints vertex info to os
Definition: algebra.h:181
DGVertex::KeyReturnType key() const
Implements Hashable::key()
Definition: algebra.h:179