-
Notifications
You must be signed in to change notification settings - Fork 0
/
determinant.cc
57 lines (49 loc) · 1.08 KB
/
determinant.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "determinant.h"
determinant::determinant(int nso) : occupation_(nso) {}
bool determinant::operator<(const determinant &other) const {
return occupation_ < other.occupation_;
}
std::string
determinant::str() const { // const here means I am not changing the object
std::string s;
s += '|';
for (auto &n : occupation_) {
if (n == 0) {
s += '0';
}
if (n == 1) {
s += '1';
}
}
// Matrix sum;
// vector<Matrix> vm;
// for (Matrix mat : vm) { // bad, I am copying the matrix
// for (Matrix &mat : vm) { // ok, I am just getting a reference to the
// matrix
// sum += mat;
// }
s += '>';
return s;
}
double determinant::cre(int p) {
if (occupation_[p] == 1) {
return 0.0;
}
occupation_[p] = 1;
return slater_sign(p);
}
double determinant::ann(int p) {
if (occupation_[p] == 0) {
return 0.0;
}
occupation_[p] = 0;
return slater_sign(p);
}
double determinant::slater_sign(int p) const {
double sign = 1.0;
for (int n = 0; n < p; n++) {
if (occupation_[n] == 1)
sign *= -1.0;
}
return sign;
}