1

#include <stdio.h>

2

#include <string.h>

3


4

#define N(x) (sizeof(x)/sizeof(*(x)))

5

#define GX 0

6

#define GY 1

7

#define GZ 2

8

#define GT 3

9

#define G5 4

10

#define GYZ 5

11

#define GZX 6

12

#define GXY 7

13

#define GXT 8

14

#define GYT 9

15

#define GZT 10

16

#define G5X 11

17

#define G5Y 12

18

#define G5Z 13

19

#define G5T 14

20

#define G1 15

21

#define MAXGAMMA 16

22


23

typedef struct {

24

int column;

25

int phase;

26


27

} gamma_row;

28


29

typedef struct {

30

gamma_row row[4];

31

} gamma_matrix_t;

32


33

static char *gammalabel[MAXGAMMA+1] = {"X", "Y", "Z", "T", "5",

34

"YZ", "ZX", "XY", "XT", "YT", "ZT",

35

"5X", "5Y", "5Z", "5T", "1", "." };

36


37

static char *phaselabel[4] = {"", "i", "", "i" };

38


39

static gamma_matrix_t gamma[MAXGAMMA] = {

40

{{{3,1}, {2,1}, {1,3}, {0,3}}},

41

{{{3,2}, {2,0}, {1,0}, {0,2}}},

42

{{{2,1}, {3,3}, {0,3}, {1,1}}},

43

{{{2,0}, {3,0}, {0,0}, {1,0}}},

44

};

45


46

static void mult_gamma(int phase, gamma_matrix_t *g1, gamma_matrix_t *g2, gamma_matrix_t *g3)

47

{

48

int r,s;

49

for(r=0;r<4;r++)

50

{

51

s = g1>row[r].column;

52

g3>row[r].column = g2>row[s].column;

53

g3>row[r].phase = (g1>row[r].phase + g2>row[s].phase + phase) % 4;

54

}

55

}

56


57

static char* phase[4] = { " 1", " i", "1", "i" };

58


59

static void print_gamma(int index) {

60

char* cell[4][4];

61

int i, j;

62

printf("\n");

63

printf("h3. %s\n",gammalabel[index]);

64

printf("\n");

65

printf("<pre>\n");

66

for(i = 0; i < 4; ++i) for(j = 0; j < 4; ++j) cell[i][j] = " 0";

67

for(i = 0; i < 4; ++i) {

68

cell[i][gamma[index].row[i].column] =

69

phase[gamma[index].row[i].phase];

70

}

71

for(i = 0; i < 4; ++i) {

72

for(j = 0; j < 4; ++j) {

73

printf(" %s",cell[i][j]);

74

}

75

printf("\n");

76

}

77

printf("</pre>\n");

78

}

79


80

static void make_gammas(void)

81

{

82

int r;

83


84

mult_gamma(1,&gamma[GY ],&gamma[GZ ],&gamma[GYZ]);

85

mult_gamma(1,&gamma[GZ ],&gamma[GX ],&gamma[GZX]);

86

mult_gamma(1,&gamma[GX ],&gamma[GY ],&gamma[GXY]);

87


88

mult_gamma(1,&gamma[GX ],&gamma[GT ],&gamma[GXT]);

89

mult_gamma(1,&gamma[GY ],&gamma[GT ],&gamma[GYT]);

90

mult_gamma(1,&gamma[GZ ],&gamma[GT ],&gamma[GZT]);

91


92


93


94

mult_gamma(3,&gamma[GX ],&gamma[GYZ],&gamma[G5T]);

95


96

mult_gamma(0,&gamma[G5T],&gamma[GT ],&gamma[G5 ]);

97

mult_gamma(0,&gamma[G5 ],&gamma[GX ],&gamma[G5X]);

98

mult_gamma(0,&gamma[G5 ],&gamma[GY ],&gamma[G5Y]);

99

mult_gamma(0,&gamma[G5 ],&gamma[GZ ],&gamma[G5Z]);

100


101


102

for(r=0;r<4;r++) {

103

gamma[G1].row[r].column = r;

104

gamma[G1].row[r].phase = 0;

105

}

106

}

107


108

static int find_gamma_with_phase(gamma_matrix_t *matrix, int phase) {

109

int i, j, OK;

110

for(i = 0; i < N(gamma); ++i) {

111

for(j = 0; j < N(matrix>row); ++j) {

112

OK = 1;

113

if(!(gamma[i].row[j].column == matrix>row[j].column &&

114

gamma[i].row[j].phase == ((matrix>row[j].phase+phase) % 4))) {

115

OK = 0;

116

break;

117

}

118

}

119

if(OK) return i;

120

}

121

return N(gamma);

122

}

123


124

static int find_gamma(gamma_matrix_t *matrix, int *phase) {

125

int result;

126

for(*phase = 0; *phase < N(phaselabel); ++*phase) {

127

result = find_gamma_with_phase(matrix,*phase);

128

if(result != N(gamma)) return result;

129

}

130

*phase = 0;

131

return N(gamma);

132

}

133


134

int main(int argc, char** argv) {

135

int index, i, j, k, l, m, result, phase;

136

gamma_matrix_t product;

137

char buffer[8];

138

make_gammas();

139

for(index = 0; index < N(gamma); ++index) {

140

print_gamma(index);

141

}

142

printf("\n");

143

printf("++++++++++\n");

144

printf("%3s","");

145

for(l = 0; l < (N(gamma)1); ++l) printf("%5s",gammalabel[l]);

146

printf("\n");

147

for(k = 0; k < (N(gamma)1); ++k) {

148

printf("%3s",gammalabel[k]);

149

for(l = 0; l < (N(gamma)1); ++l) {

150

mult_gamma(0,gamma+k,gamma+l,&product);

151

result = find_gamma(&product,&phase);

152

strcpy(buffer,phaselabel[phase]);

153

strcat(buffer,gammalabel[result]);

154

printf("%5s",buffer);

155

}

156

printf("\n");

157

}

158

return 0;

159

}
