#pragma once #include "types.h" #include "potts.h" template struct dihedral2_t { bool is_reflection; T x; }; template void init(dihedral2_t *ptr) { ptr->is_reflection = false; ptr->x = (T)0; } template dihedral2_t copy(dihedral2_t r) { return r; } template void free_spin(dihedral2_t r) { // do nothing! } template potts_t act(dihedral2_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 dihedral2_t act(dihedral2_t r1, dihedral2_t r2) { dihedral2_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(dihedral2_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 dihedral2_t act_inverse(dihedral2_t r1, dihedral2_t r2) { dihedral2_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; }