summaryrefslogtreecommitdiff
path: root/lib/symmetric.h
blob: 41c8fb6fd5153d6fd0398625d203b0808a31ecf1 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

#pragma once

#include <stdlib.h>
#include "types.h"
#include "potts.h"

template <q_t q>
class symmetric_t {
  public:
    q_t *perm;
};

template <q_t q>
void init(symmetric_t<q> *p) {
  p->perm = (q_t *)malloc(q * sizeof(q_t));

  for (q_t i = 0; i < q; i++) {
    p->perm[i] = i;
  }
}

template <q_t q>
void free_spin(symmetric_t<q> p) {
  free(p.perm);
}

template <q_t q>
symmetric_t<q> copy(symmetric_t<q> x) {
  symmetric_t<q> x2;
  x2.perm = (q_t *)malloc(q * sizeof(q_t));

  for (q_t i = 0; i < q; i++) {
    x2.perm[i] = x.perm[i];
  }

  return x2;
}

template <q_t q>
potts_t<q> act(symmetric_t<q> r, potts_t<q> s) {
  potts_t<q> s2;
  s2.x = r.perm[s.x];
  return s2;
}

template <q_t q>
symmetric_t<q> act(symmetric_t<q> r1, symmetric_t<q> r2) {
  symmetric_t<q> r3;
  r3.perm = (q_t *)malloc(q * sizeof(q_t));
  for (q_t i = 0; i < q; i++) {
    r3.perm[i] = r1.perm[r2.perm[i]];
  }

  return r3;
}

template <q_t q>
potts_t<q> act_inverse(symmetric_t<q> r, potts_t<q> s) {
  potts_t<q> s2;

  q_t i;

  for (i = 0; i < q; i++) {
    if (r.perm[i] == s.x) {
      break;
    }
  }

  s2.x = i;

  return s2;
}

template <q_t q>
symmetric_t<q> act_inverse(symmetric_t<q> r1, symmetric_t<q> r2) {
  symmetric_t<q> r3;
  r3.perm = (q_t *)malloc(q * sizeof(q_t));
  for (q_t i = 0; i < q; i++) {
    r3.perm[r1.perm[i]] = r2.perm[i];
  }

  return r3;
}