summaryrefslogtreecommitdiff
path: root/lib/z2.h
blob: dae1eb7879f68027d775ceaf02153c4ef4c34abd (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

#pragma once

#include "types.h"
#include "ising.h"

/* The minimum definition for a group type R_t to act on a spin type X_t is
 * given by the following.
 *
 * void init(R_t *p);
 * void free_spin(R_t r);
 * R_t copy(R_t r);
 * X_t act(R_t r, X_t x);
 * R_t act(R_t r, R_t r);
 * X_t act_inverse(R_t r, X_t x);
 * R_t act_inverse(R_t r, R_t r);
 *
 */

struct z2_t { bool x; };

void init(z2_t *p) {
  p->x = false;
}

void free_spin(z2_t p) {
  // do nothing!
}

z2_t copy(z2_t x) {
  return x;
}

ising_t act(z2_t r, ising_t s) {
  ising_t rs;

  if (r.x) {
    rs.x = !s.x;
    return rs;
  } else {
    rs.x = s.x;
    return rs;
  }
}

z2_t act(z2_t r1, z2_t r2) {
  z2_t r3;

  if (r1.x) {
    r3.x = !r2.x;
    return r3;
  } else {
    r3.x = r2.x;
    return r3;
  }
}

ising_t act_inverse(z2_t r, ising_t s) {
  return act(r, s);
}

z2_t act_inverse(z2_t r1, z2_t r2) {
  return act(r1, r2);
}