From 96e878d2f69790dc72bb4b713c1d492fa2b4c587 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 24 Jul 2018 15:26:31 -0400 Subject: added preprocessor method for potts, and implemented dihedral for the c++ stuff --- lib/dihedral.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'lib/dihedral.h') diff --git a/lib/dihedral.h b/lib/dihedral.h index c95b23a..f67c930 100644 --- a/lib/dihedral.h +++ b/lib/dihedral.h @@ -19,3 +19,81 @@ q_t *dihedral_gen_transformations(q_t q); R_t *dihedral_gen_involutions(q_t q); R_t factorial(q_t); + +#ifdef __cplusplus + +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; +} + +#endif + -- cgit v1.2.3-70-g09d2