Skip to content

Commit

Permalink
Replace std::endl with '\n'
Browse files Browse the repository at this point in the history
  • Loading branch information
krivenko committed May 13, 2024
1 parent 6e264cc commit 1e305dd
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 78 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ int main() {
}

// Total number of terms (monomials) in 'H'.
std::cout << "Total number of terms in H: " << H.size() << std::endl;
std::cout << "Total number of terms in H: " << H.size() << '\n';
// Is H Hermitian?
std::cout << "H^\\dagger - H = " << (conj(H) - H) << std::endl;
std::cout << "H^\\dagger - H = " << (conj(H) - H) << '\n';

// Does H commute with N and S_z?
decltype(H) N, S_z;
Expand All @@ -206,8 +206,8 @@ int main() {
S_z += 0.5 * (n(ix, iy, "up") - n(ix, iy, "down"));
}
}
std::cout << "[H, N] = " << (H * N - N * H) << std::endl;
std::cout << "[H, S_z] = " << (H * S_z - S_z * H) << std::endl;
std::cout << "[H, N] = " << (H * N - N * H) << '\n';
std::cout << "[H, S_z] = " << (H * S_z - S_z * H) << '\n';

// Iterate over all terms in 'H' and print those of degree 3.
//
Expand All @@ -216,7 +216,7 @@ int main() {
for(auto const& term: H) {
if(term.monomial.size() == 3) {
// term.coeff is coefficient in front of the monomial
std::cout << term.monomial << " => " << term.coeff << std::endl;
std::cout << term.monomial << " => " << term.coeff << '\n';
}
}

Expand Down Expand Up @@ -258,12 +258,12 @@ int main() {
auto H = 0.5 * (S_p(1) * S_m(2) + S_m(1) * S_p(2)) + S_z(1) * S_z(2);

// Print 'H'
std::cout << "H = " << H << std::endl;
std::cout << "H = " << H << '\n';

// Automatically analyze structure of 'H' and construct a 4-dimensional
// Hilbert space (direct product of two spin-1/2 spaces).
auto hs = make_hilbert_space(H);
std::cout << "dim(hs) = " << hs.dim() << std::endl;
std::cout << "dim(hs) = " << hs.dim() << '\n';

// Construct a 'loperator' object that represents action of expression 'H' on
// state vectors in the Hilbert space 'hs'.
Expand Down Expand Up @@ -291,7 +291,7 @@ int main() {
for(int j = 0; j < 4; ++j) {
std::cout << "+(" << phi[j] << ")|" << j << ">";
}
std::cout << std::endl;
std::cout << '\n';
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions doc/expression/expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ This allows for writing complex expression analysis algorithms.
}
}
std::cout << std::endl;
std::cout << '\n';
}
.. note:: Only the constant iterators are implemented by :type:`expression` and
Expand Down Expand Up @@ -531,7 +531,7 @@ taken to be different on odd and even chain links.
H += v * (c_dag(a) * c(a + 1) + c_dag(a + 1) * c(a));
}
std::cout << "H = " << H << std::endl;
std::cout << "H = " << H << '\n';
// Construct the Su-Schrieffer-Heeger (SSH) model by changing hopping
// constants on all even links of the chain.
Expand All @@ -557,7 +557,7 @@ taken to be different on odd and even chain links.
auto H_SSH = transform(H, update_hopping_element);
std::cout << "H_SSH = " << H_SSH << std::endl;
std::cout << "H_SSH = " << H_SSH << '\n';
.. _hc:

Expand Down
14 changes: 7 additions & 7 deletions doc/expression/generator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ In other words,
// or annihilation operator.
if(is_fermion(g)) {
auto const& f = dynamic_cast<generator_fermion<int, std::string> const&>(g);
std::cout << (f.dagger() ? "creation" : "annihilation") << std::endl;
std::cout << (f.dagger() ? "creation" : "annihilation") << '\n';
}
.. _generator_boson:
Expand Down Expand Up @@ -416,7 +416,7 @@ In other words,
// annihilation operator.
if(is_boson(g)) {
auto const& b = dynamic_cast<generator_boson<int> const&>(g);
std::cout << (b.dagger() ? "creation" : "annihilation") << std::endl;
std::cout << (b.dagger() ? "creation" : "annihilation") << '\n';
}
.. _generator_spin:
Expand Down Expand Up @@ -573,17 +573,17 @@ In other words,
if(is_spin(g)) {
auto const& s = dynamic_cast<generator_spin<int> const&>(g);
std::cout << "J = " << s.spin() << std::endl;
std::cout << "2J+1 = " << s.multiplicity() << std::endl;
std::cout << "J = " << s.spin() << '\n';
std::cout << "2J+1 = " << s.multiplicity() << '\n';
switch(s.component()) {
case libcommute::plus:
std::cout << "+" << std::endl;
std::cout << "+\n";
break;
case libcommute::minus:
std::cout << "-" << std::endl;
std::cout << "-\n";
break;
case libcommute::z:
std::cout << "z" << std::endl;
std::cout << "z\n";
break;
}
}
6 changes: 3 additions & 3 deletions examples/exchange_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ int main() {
auto H = 0.5 * (S_p(1) * S_m(2) + S_m(1) * S_p(2)) + S_z(1) * S_z(2);

// Print 'H'
std::cout << "H = " << H << std::endl;
std::cout << "H = " << H << '\n';

// Automatically analyze structure of 'H' and construct a 4-dimensional
// Hilbert space (direct product of two spin-1/2 spaces).
auto hs = make_hilbert_space(H);
std::cout << "dim(hs) = " << hs.dim() << std::endl;
std::cout << "dim(hs) = " << hs.dim() << '\n';

// Construct a 'loperator' object that represents action of expression 'H' on
// state vectors in the Hilbert space 'hs'.
Expand Down Expand Up @@ -75,7 +75,7 @@ int main() {
for(int j = 0; j < 4; ++j) {
std::cout << "+(" << phi[j] << ")|" << j << ">";
}
std::cout << std::endl;
std::cout << '\n';
}

return 0;
Expand Down
7 changes: 3 additions & 4 deletions examples/gamma.expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main() {
std::cout << "{" << gamma_mu << ", " << gamma_nu << "}"
<< " - 2\\eta(" << mu << ", " << nu << "} = "
<< (gamma_mu * gamma_nu + gamma_nu * gamma_mu - 2 * eta(mu, nu))
<< std::endl;
<< '\n';
}
}

Expand All @@ -50,13 +50,12 @@ int main() {
I * make_gamma(0) * make_gamma(1) * make_gamma(2) * make_gamma(3);

// \gamma^5 is Hermitian ...
std::cout << "gamma5 - conj(gamma5) = " << (gamma5 - conj(gamma5))
<< std::endl;
std::cout << "gamma5 - conj(gamma5) = " << (gamma5 - conj(gamma5)) << '\n';

// ... and anti-commutes with \gamma^\mu.
for(int mu = 0; mu < 4; ++mu) {
auto gamma_mu = make_gamma(mu);
std::cout << "{gamma5, " << gamma_mu
<< "} = " << (gamma5 * gamma_mu + gamma_mu * gamma5) << std::endl;
<< "} = " << (gamma5 * gamma_mu + gamma_mu * gamma5) << '\n';
}
}
2 changes: 1 addition & 1 deletion examples/gamma.loperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int main() {
for(int j = 0; j < 4; ++j) {
std::cout << "+" << phi[j] << "|" << j << ">";
}
std::cout << std::endl;
std::cout << '\n';
}

return 0;
Expand Down
18 changes: 9 additions & 9 deletions examples/heisenberg_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ int main() {
S_tot = S_tot + S[i];

// All three components of S commute with the Hamiltonian.
std::cout << "[H, S_x] = " << (H * S_tot[0] - S_tot[0] * H) << std::endl;
std::cout << "[H, S_y] = " << (H * S_tot[1] - S_tot[1] * H) << std::endl;
std::cout << "[H, S_z] = " << (H * S_tot[2] - S_tot[2] * H) << std::endl;
std::cout << "[H, S_x] = " << (H * S_tot[0] - S_tot[0] * H) << '\n';
std::cout << "[H, S_y] = " << (H * S_tot[1] - S_tot[1] * H) << '\n';
std::cout << "[H, S_z] = " << (H * S_tot[2] - S_tot[2] * H) << '\n';

// Higher charge Q_3 (1st line of Eq. (10)).
expr_t Q3;
for(int i = 0; i < N; ++i) {
Q3 += dot(cross(S[i], S[(i + 1) % N]), S[(i + 2) % N]);
}
std::cout << "[H, Q3] = " << (H * Q3 - Q3 * H) << std::endl;
std::cout << "[H, Q3] = " << (H * Q3 - Q3 * H) << '\n';

// Higher charge Q_4 (2nd line of Eq. (10)).
expr_t Q4;
Expand All @@ -103,7 +103,7 @@ int main() {
S[(i + 3) % N]);
Q4 += dot(S[i], S[(i + 2) % N]);
}
std::cout << "[H, Q4] = " << (H * Q4 - Q4 * H) << std::endl;
std::cout << "[H, Q4] = " << (H * Q4 - Q4 * H) << '\n';

// Higher charge Q_5 (3rd line of Eq. (10)).
expr_t Q5;
Expand All @@ -114,12 +114,12 @@ int main() {
Q5 += dot(cross(S[i], S[(i + 2) % N]), S[(i + 3) % N]);
Q5 += dot(cross(S[i], S[(i + 1) % N]), S[(i + 3) % N]);
}
std::cout << "[H, Q5] = " << (H * Q5 - Q5 * H) << std::endl;
std::cout << "[H, Q5] = " << (H * Q5 - Q5 * H) << '\n';

// Check that the higher charges pairwise commute.
std::cout << "[Q3, Q4] = " << (Q3 * Q4 - Q4 * Q3) << std::endl;
std::cout << "[Q3, Q5] = " << (Q3 * Q5 - Q5 * Q3) << std::endl;
std::cout << "[Q4, Q5] = " << (Q4 * Q5 - Q5 * Q4) << std::endl;
std::cout << "[Q3, Q4] = " << (Q3 * Q4 - Q4 * Q3) << '\n';
std::cout << "[Q3, Q5] = " << (Q3 * Q5 - Q5 * Q3) << '\n';
std::cout << "[Q4, Q5] = " << (Q4 * Q5 - Q5 * Q4) << '\n';

return 0;
}
6 changes: 3 additions & 3 deletions examples/holstein.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ int main() {
auto H_H = H_e + H_ph + H_e_ph;

// Print H_H. There will be quite a lot of terms for the 100-site lattice!
std::cout << "H_H = " << H_H << std::endl;
std::cout << "H_H = " << H_H << '\n';

// Check hermiticity of H_H
std::cout << "H_H - H_H^\\dagger = " << (H_H - conj(H_H)) << std::endl;
std::cout << "H_H - H_H^\\dagger = " << (H_H - conj(H_H)) << '\n';

// Check that H_H commutes with the total number of electrons
decltype(H_H) N_e;
Expand All @@ -135,7 +135,7 @@ int main() {
}
}

std::cout << "[H_H, N_e] = " << (H_H * N_e - N_e * H_H) << std::endl;
std::cout << "[H_H, N_e] = " << (H_H * N_e - N_e * H_H) << '\n';

return 0;
}
10 changes: 5 additions & 5 deletions examples/hubbard_holstein.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ int main() {
}

// Total number of terms (monomials) in 'H'.
std::cout << "Total number of terms in H: " << H.size() << std::endl;
std::cout << "Total number of terms in H: " << H.size() << '\n';
// Is H Hermitian?
std::cout << "H^\\dagger - H = " << (conj(H) - H) << std::endl;
std::cout << "H^\\dagger - H = " << (conj(H) - H) << '\n';

// Does H commute with N and S_z?
decltype(H) N, S_z;
Expand All @@ -127,8 +127,8 @@ int main() {
S_z += 0.5 * (n(ix, iy, "up") - n(ix, iy, "down"));
}
}
std::cout << "[H, N] = " << (H * N - N * H) << std::endl;
std::cout << "[H, S_z] = " << (H * S_z - S_z * H) << std::endl;
std::cout << "[H, N] = " << (H * N - N * H) << '\n';
std::cout << "[H, S_z] = " << (H * S_z - S_z * H) << '\n';

// Iterate over all terms in 'H' and print those of degree 3.
//
Expand All @@ -137,7 +137,7 @@ int main() {
for(auto const& term : H) {
if(term.monomial.size() == 3) {
// term.coeff is coefficient in front of the monomial
std::cout << term.monomial << " => " << term.coeff << std::endl;
std::cout << term.monomial << " => " << term.coeff << '\n';
}
}

Expand Down
9 changes: 4 additions & 5 deletions examples/jaynes_cummings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main() {

// Check that the number operator commutes with the Hamiltonian
auto N = a_dag() * a() + S_z();
std::cout << "[H, N] = " << (H * N - N * H) << std::endl;
std::cout << "[H, N] = " << (H * N - N * H) << '\n';

// Complete Hilbert space of the system is a product of the isospin-1/2 space
// and the bosonic space truncated to 2^10 - 1 excitations.
Expand Down Expand Up @@ -106,8 +106,7 @@ int main() {
psi = Hop(phi);

// Check |\psi> \approx E_{gs} |\phi>
std::cout << "|||0,g> - E_g|0,g>||_{L^2} = " << diff(psi, phi, E_gs)
<< std::endl;
std::cout << "|||0,g> - E_g|0,g>||_{L^2} = " << diff(psi, phi, E_gs) << '\n';

//
// Now, do a similar check for the Jaynes-Cummings ladder doublets.
Expand All @@ -131,7 +130,7 @@ int main() {
psi = Hop(phi);

std::cout << "|||" << n << ",+> - E_+(" << n << ")|" << n
<< ",+>||_{L^2} = " << diff(psi, phi, energy(1, n)) << std::endl;
<< ",+>||_{L^2} = " << diff(psi, phi, energy(1, n)) << '\n';

// Set \phi to be the "-" dressed state
std::fill(phi.begin(), phi.end(), 0);
Expand All @@ -141,7 +140,7 @@ int main() {
psi = Hop(phi);

std::cout << "|||" << n << ",-> - E_-(" << n << ")|" << n
<< ",->||_{L^2} = " << diff(psi, phi, energy(-1, n)) << std::endl;
<< ",->||_{L^2} = " << diff(psi, phi, energy(-1, n)) << '\n';
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions examples/kanamori.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main() {
}

// Print the Hamiltonian
std::cout << "H_K = " << H_K << std::endl;
std::cout << "H_K = " << H_K << '\n';

//
// Integrals of motion N, S^2 and L^2 (Eq. (4)).
Expand Down Expand Up @@ -142,7 +142,7 @@ int main() {
(5.0 / 2) * J * N;

// Must be zero
std::cout << "H_K - H_t2g = " << (H_K - H_t2g) << std::endl;
std::cout << "H_K - H_t2g = " << (H_K - H_t2g) << '\n';

return 0;
}
10 changes: 5 additions & 5 deletions examples/n_fermion_sectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main() {

// Automatically analyze structure of 'H' and construct a Hilbert space
auto hs = make_hilbert_space(H);
std::cout << "Full Hilbert space dimension: " << hs.dim() << std::endl;
std::cout << "Full Hilbert space dimension: " << hs.dim() << '\n';

// Construct a 'loperator' object that represents action of expression 'H' on
// state vectors in the Hilbert space 'hs'.
Expand All @@ -117,7 +117,7 @@ int main() {
int const N = 2;

auto const sector_size = n_fermion_sector_size(hs, N);
std::cout << "Size of the N = 2 sector: " << sector_size << std::endl;
std::cout << "Size of the N = 2 sector: " << sector_size << '\n';

// Preallocate a Hamiltonian matrix to be filled and diagonalized.
// Note that we have to store matrix elements only within the small sector.
Expand Down Expand Up @@ -148,7 +148,7 @@ int main() {
Eigen::EigenvaluesOnly);

std::cout << "10 lowest eigenvalues of the N = 2 sector: "
<< diag.eigenvalues().head(10).transpose() << std::endl;
<< diag.eigenvalues().head(10).transpose() << '\n';
}

//
Expand All @@ -175,7 +175,7 @@ int main() {

auto const multisector_size = n_fermion_multisector_size(hs, sectors);
std::cout << "Size of the N_up = 1, N_down = 1 multisector: "
<< multisector_size << std::endl;
<< multisector_size << '\n';

// Preallocate a Hamiltonian matrix to be filled and diagonalized.
// Note that we have to store matrix elements only within the multisector.
Expand Down Expand Up @@ -206,7 +206,7 @@ int main() {
Eigen::EigenvaluesOnly);

std::cout << "10 lowest eigenvalues of the multisector: "
<< diag.eigenvalues().head(10).transpose() << std::endl;
<< diag.eigenvalues().head(10).transpose() << '\n';
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/parametric_loperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int main() {
for(unsigned int i = 0; i < ket.size(); ++i) {
if(ket[i] != 0) std::cout << " +(" << ket[i] << ")|" << i << ">";
}
std::cout << std::endl;
std::cout << '\n';
}

return 0;
Expand Down
Loading

0 comments on commit 1e305dd

Please sign in to comment.