GLAC  1.0
su3matrixgenerator.h
Go to the documentation of this file.
1 
13 #ifndef SU3MATRIXGENERATOR_H
14 #define SU3MATRIXGENERATOR_H
15 
16 #include <random>
17 #include "su3.h"
18 #include "su2.h"
19 
21 {
22 private:
23  // RNG
24  std::mt19937_64 m_generator;
25 
26  // Random matrix distribution
27  std::uniform_real_distribution<double> m_uniform_distribution;
28 
29  // RST related distribution
30  std::uniform_real_distribution<double> m_SU2_uniform_distribution;
31  double m_epsilon;
32  double m_epsilonSquared;
33  double m_sqrtOneMinusEpsSquared;
34  double m_projectionFactor[2];
35  double m_columnLength = 0;
36  inline SU3 RSTMatrixMultiplication(SU2 r, SU2 s, SU2 t);
37  inline SU3 RSTMatrixMultiplicationInverse(SU2 r, SU2 s, SU2 t);
38 
39  // Used for creating a random matrix
40  SU3 H;
41 
42  // Used for creating a random matrix close to unity
43  SU3 X;
44  SU2 r,s,t;
45  double rs[8];
46 
47  // Used for generating SU2 matrices
48  SU2 U;
49  double _r[4];
50  double _x[4];
51  double _rNorm = 0;
52 
53  // Pauli matrices
54  SU2 sigma[3];
55 
56 public:
60  SU3 generateRST();
61  SU2 generateSU2();
62 
73  SU3 testRSTMultiplication(SU2 r, SU2 s, SU2 t) { return RSTMatrixMultiplication(r,s,t); }
84  SU3 testRSTMultiplicationInverse(SU2 r, SU2 s, SU2 t) { return RSTMatrixMultiplicationInverse(r,s,t); }
85 };
86 
92 {
93  /*
94  * Generatores a random SU3 matrix.
95  * Index map:
96  * H =
97  * 0 1 2 0 1 2 3 4 5
98  * 3 4 5 = 6 7 8 9 10 11
99  * 6 7 8 12 13 14 15 16 17
100  */
101  H.zeros();
102  // Populating the matrix
103  for (int i = 0; i < 3; i++)
104  {
105  for (int j = 0; j < 3; j++)
106  {
107  H[6*i + 2*j] = m_uniform_distribution(m_generator);
108  H[6*i + 2*j + 1] = m_uniform_distribution(m_generator);
109  }
110  }
111  // Normalizing first column
112  m_columnLength = 0;
113  for (int i = 0; i < 3; i++)
114  {
115  m_columnLength += H[6*i]*H[6*i] + H[6*i+1]*H[6*i+1];
116  }
117  m_columnLength = sqrt(m_columnLength);
118  for (int i = 0; i < 3; i++)
119  {
120  H[6*i] /= m_columnLength;
121  H[6*i+1] /= m_columnLength;
122  }
123  // Using Gram-Schmitt to orthogonalize the second column
124  m_projectionFactor[0] = 0;
125  m_projectionFactor[1] = 0;
126  for (int i = 0; i < 3; i++)
127  {
128  m_projectionFactor[0] += H[6*i+2]*H[6*i] + H[6*i+3]*H[6*i+1];
129  m_projectionFactor[1] += H[6*i+3]*H[6*i] - H[6*i+2]*H[6*i+1];
130  }
131  for (int i = 0; i < 3; i++)
132  {
133  H[6*i+2] -= H[6*i]*m_projectionFactor[0] - H[6*i+1]*m_projectionFactor[1];
134  H[6*i+3] -= H[6*i]*m_projectionFactor[1] + H[6*i+1]*m_projectionFactor[0];
135  }
136  // Normalizing second column
137  m_columnLength = 0;
138  for (int i = 0; i < 3; i++)
139  {
140  m_columnLength += H[6*i+2]*H[6*i+2] + H[6*i+3]*H[6*i+3];
141  }
142  m_columnLength = sqrt(m_columnLength);
143  for (int i = 0; i < 3; i++)
144  {
145  H[6*i+2] /= m_columnLength;
146  H[6*i+3] /= m_columnLength;
147  }
148  // Taking cross product to produce the last column of our matrix
149  H[4] = H[8]*H[12] - H[9]*H[13] - H[14]*H[6] + H[15]*H[7];
150  H[5] = H[14]*H[7] + H[15]*H[6] - H[8]*H[13] - H[9]*H[12];
151  H[10] = H[14]*H[0] - H[15]*H[1] - H[2]*H[12] + H[3]*H[13];
152  H[11] = H[2]*H[13] + H[3]*H[12] - H[14]*H[1] - H[15]*H[0];
153  H[16] = H[2]*H[6] - H[3]*H[7] - H[8]*H[0] + H[9]*H[1];
154  H[17] = H[8]*H[1] + H[9]*H[0] - H[2]*H[7] - H[3]*H[6];
155 
156  return H;
157 }
158 
164 {
165  /*
166  * Generatores a random SU3 matrix close to unity.
167  * Index map:
168  * r,s,t =
169  * 0 1
170  * 2 3
171  * R,S,T =
172  * 0 1 2
173  * 3 4 5
174  * 6 7 8
175  * H =
176  * 0 1 2 0 1 2 3 4 5
177  * 3 4 5 = 6 7 8 9 10 11
178  * 6 7 8 12 13 14 15 16 17
179  */
180  // Generates SU2 matrices
181  r = generateSU2();
182  s = generateSU2();
183  t = generateSU2();
184  if (m_SU2_uniform_distribution(m_generator) < 0) {
185  return RSTMatrixMultiplicationInverse(r,s,t);
186  } else {
187  return RSTMatrixMultiplication(r,s,t);
188  }
189 }
190 
196 {
197  U.zeros();
198  _rNorm = 0;
199  // Generating 4 r random numbers
200  for (int i = 0; i < 4; i++) {
201  _r[i] = m_SU2_uniform_distribution(m_generator);
202  }
203  // Populating the x-vector
204  if (_r[0] < 0) {
205  _x[0] = - m_sqrtOneMinusEpsSquared;
206  }
207  else {
208  _x[0] = m_sqrtOneMinusEpsSquared;
209  }
210  for (int i = 1; i < 4; i++) {
211  _rNorm += _r[i]*_r[i];
212  }
213  _rNorm = sqrt(_rNorm)/m_epsilon;
214  for (int i = 1; i < 4; i++) {
215  _x[i] = _r[i]/_rNorm;
216  }
217  // Imposing unity
218  _rNorm = 0;
219  for (int i = 0; i < 4; i++) {
220  _rNorm += _x[i]*_x[i];
221  }
222  _rNorm = sqrt(_rNorm);
223  for (int i = 0; i < 4; i++) {
224  _x[i] /= _rNorm;
225  }
226  // Generating the SU2 matrix close to unity
227  U.mat[0] = _x[0]; // same as 1*x0
228  U.mat[6] = _x[0]; // same as 1*x0
229  for (int i = 0; i < 3; i++) {
230  for (int j = 0; j < 4; j++) {
231  U[2*j] = U[2*j] - _x[i+1]*sigma[i].mat[2*j+1];
232  U[2*j+1] = U[2*j+1] + _x[i+1]*sigma[i].mat[2*j];
233  }
234  }
235  return U;
236 }
237 
238 inline SU3 SU3MatrixGenerator::RSTMatrixMultiplication(SU2 r, SU2 s, SU2 t)
239 {
240  /*
241  * Generatores a random SU3 matrix.
242  * Index map:
243  * H =
244  * 0 1 2 0 1 2 3 4 5
245  * 3 4 5 = 6 7 8 9 10 11
246  * 6 7 8 12 13 14 15 16 17
247  */
248  // Block one shortenings
249  rs[0] = r[0]*s[2] - r[1]*s[3];
250  rs[1] = r[1]*s[2] + r[0]*s[3];
251  // Block two shortenings
252  rs[2] = r[4]*s[2] - r[5]*s[3];
253  rs[3] = r[5]*s[2] + r[4]*s[3];
254  // Compact RST multiplication
255  X[0] = r[0]*s[0] - r[1]*s[1];
256  X[1] = r[1]*s[0] + r[0]*s[1];
257  X[2] = rs[0]*t[4] - r[3]*t[1] + r[2]*t[0] - rs[1]*t[5];
258  X[3] = rs[1]*t[4] + r[3]*t[0] + r[2]*t[1] + rs[0]*t[5];
259  X[4] = rs[0]*t[6] - r[3]*t[3] + r[2]*t[2] - rs[1]*t[7];
260  X[5] = rs[1]*t[6] + r[3]*t[2] + r[2]*t[3] + rs[0]*t[7];
261  X[6] = r[4]*s[0] - r[5]*s[1];
262  X[7] = r[5]*s[0] + r[4]*s[1];
263  X[8] = rs[2]*t[4] - r[7]*t[1] + r[6]*t[0] - rs[3]*t[5];
264  X[9] = rs[3]*t[4] + r[7]*t[0] + r[6]*t[1] + rs[2]*t[5];
265  X[10] = rs[2]*t[6] - r[7]*t[3] + r[6]*t[2] - rs[3]*t[7];
266  X[11] = rs[3]*t[6] + r[7]*t[2] + r[6]*t[3] + rs[2]*t[7];
267  X[12] = s[4];
268  X[13] = s[5];
269  X[14] = s[6]*t[4] - s[7]*t[5];
270  X[15] = s[7]*t[4] + s[6]*t[5];
271  X[16] = s[6]*t[6] - s[7]*t[7];
272  X[17] = s[7]*t[6] + s[6]*t[7];
273 
274  return X;
275 }
276 
277 inline SU3 SU3MatrixGenerator::RSTMatrixMultiplicationInverse(SU2 r, SU2 s, SU2 t)
278 {
279  /*
280  * Generatores a random SU3 matrix.
281  * Index map:
282  * H =
283  * 0 1 2 0 1 2 3 4 5
284  * 3 4 5 = 6 7 8 9 10 11
285  * 6 7 8 12 13 14 15 16 17
286  */
287  // Block one shortenings
288  rs[0] = r[0]*s[2] - r[1]*s[3];
289  rs[1] = r[1]*s[2] + r[0]*s[3];
290  // Block two shortenings
291  rs[2] = r[4]*s[2] - r[5]*s[3];
292  rs[3] = r[5]*s[2] + r[4]*s[3];
293  // Compact RST multiplication
294  X[0] = r[0]*s[0] - r[1]*s[1];
295  X[1] = - r[1]*s[0] - r[0]*s[1];
296  X[2] = r[4]*s[0] - r[5]*s[1];
297  X[3] = - r[5]*s[0] - r[4]*s[1];
298  X[4] = s[4];
299  X[5] = - s[5];
300  X[6] = rs[0]*t[4] - r[3]*t[1] + r[2]*t[0] - rs[1]*t[5];
301  X[7] = - rs[1]*t[4] - r[3]*t[0] - r[2]*t[1] - rs[0]*t[5];
302  X[8] = rs[2]*t[4] - r[7]*t[1] + r[6]*t[0] - rs[3]*t[5];;
303  X[9] = - rs[3]*t[4] - r[7]*t[0] - r[6]*t[1] - rs[2]*t[5];
304  X[10] = s[6]*t[4] - s[7]*t[5];
305  X[11] = - s[7]*t[4] - s[6]*t[5];
306  X[12] = rs[0]*t[6] - r[3]*t[3] + r[2]*t[2] - rs[1]*t[7];
307  X[13] = - rs[1]*t[6] - r[3]*t[2] - r[2]*t[3] - rs[0]*t[7];
308  X[14] = rs[2]*t[6] - r[7]*t[3] + r[6]*t[2] - rs[3]*t[7];
309  X[15] = - rs[3]*t[6] - r[7]*t[2] - r[6]*t[3] - rs[2]*t[7];
310  X[16] = s[6]*t[6] - s[7]*t[7];
311  X[17] = - s[7]*t[6] - s[6]*t[7];
312 
313  return X;
314 }
315 
316 #endif // SU3MATRIXGENERATOR_H
SU3 testRSTMultiplicationInverse(SU2 r, SU2 s, SU2 t)
testRSTMultiplicationInverse wrapper for testing the RSTMatrixMultiplicationInverse method.
Definition: su3matrixgenerator.h:84
~SU3MatrixGenerator()
Definition: su3matrixgenerator.cpp:37
void zeros()
Definition: su3.cpp:8
class for holding matrices.
Definition: su3.h:18
Class for generating random SU3 matrices.
Definition: su3matrixgenerator.h:20
void zeros()
Definition: su2.h:176
SU3 generateRandom()
SU3MatrixGenerator::generateRandom generates a fully random SU3 matrix.
Definition: su3matrixgenerator.h:91
SU2 generateSU2()
SU3MatrixGenerator::generateSU2 generates a random SU2 matrix close to unity.
Definition: su3matrixgenerator.h:195
double mat[8]
Definition: su2.h:33
SU3MatrixGenerator()
Definition: su3matrixgenerator.cpp:16
Class for holding matrices.
Definition: su2.h:21
SU3 generateRST()
SU3MatrixGenerator::generateRST generates a SU3 matrix close to unity.
Definition: su3matrixgenerator.h:163
SU3 testRSTMultiplication(SU2 r, SU2 s, SU2 t)
testRSTMultiplication wrapper for testing the RSTMatrixMultiplication method.
Definition: su3matrixgenerator.h:73