#pragma once #include "types.h" #include "potts.h" template struct dihedral_t { bool is_reflection; T x; }; template void init(dihedral_t *ptr) { ptr->is_reflection = false; ptr->x = (T)0; } template dihedral_t copy(dihedral_t r) { return r; } template void free_spin(dihedral_t r) { // do nothing! } template potts_t act(dihedral_t r, potts_t s) { potts_t s2; if (r.is_reflection) { s2.x = ((q + r.x) - s.x) % q; } else { s2.x = (r.x + s.x) % q; } return s2; } template dihedral_t act(dihedral_t r1, dihedral_t r2) { dihedral_t r3; if (r1.is_reflection) { r3.is_reflection = !(r2.is_reflection); r3.x = ((q + r1.x) - r2.x) % q; } else { r3.is_reflection = r2.is_reflection; r3.x = (r1.x + r2.x) % q; } return r3; } template potts_t act_inverse(dihedral_t r, potts_t s) { potts_t s2; if (r.is_reflection) { s2.x = ((r.x + q) - s.x) % q; } else { s2.x = ((s.x + q) - r.x) % q; } return s2; } template dihedral_t act_inverse(dihedral_t r1, dihedral_t r2) { dihedral_t r3; if (r1.is_reflection) { r3.is_reflection = !(r2.is_reflection); r3.x = ((r1.x + q) - r2.x) % q; } else { r3.is_reflection = r2.is_reflection; r3.x = ((r2.x + q) - r1.x) % q; } return r3; }