LatticeYangMills
su3.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * MIT License
4 *
5 * Copyright (c) 2018 Giovanni Pederiva
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 ******************************************************************************/
25 
34 #include "Math/su3.h"
35 #include "Math/complex.h"
36 #include <ctime>
37 #include <cmath>
38 #include <cstdio>
39 #include <utility>
40 #include <random>
41 
42 SU3 I, Q2, Q3;
43 
44 
45 SU3::SU3() noexcept{
46 }
47 
48 SU3::SU3(double value) noexcept{
49  for(auto& i : mat)
50  i = value;
51 }
52 
53 SU3::SU3(SU3 const& source) noexcept : mat(source.mat){
54 }
55 
56 SU3::SU3(SU3&& source) noexcept : mat(source.mat){
57 }
58 
59 // Hermitean Conjugate
60 SU3 operator~(const SU3& a){
61  SU3 c;
62  for(int i = 0; i < 3; i++){
63  for(int j = 0; j < 3; j++){
64  c.mat[2 * (3*i + j)] = a.mat[2 * (3*j + i)];
65  c.mat[2 * (3*i + j) + 1] = -a.mat[2 * (3*j + i) + 1];
66  }
67  }
68  return std::move(c);
69 }
70 
71 SU3 operator~(SU3&& a){
72  SU3 c;
73  for(int i = 0; i < 3; i++){
74  for(int j = 0; j < 3; j++){
75  c.mat[2 * (3*i + j)] = a.mat[2 * (3*j + i)];
76  c.mat[2 * (3*i + j) + 1] = -a.mat[2 * (3*j + i) + 1];
77  }
78  }
79  return std::move(c);
80 }
81 
82 void SU3::printSU3(){
83  int idx = 0;
84  for(int i = 0; i < 3; i++){
85  for(int j = 0; j < 3; j++){
86  printf("( %2.5g, %2.5g )\t", mat[idx], mat[idx+1]);
87  idx += 2;
88  }
89  printf("\n");
90  }
91  printf("\n");
92 }
93 
94 void SU3::setSU3Identity(){
95  for(int i = 0; i < 18; i++)
96  mat[i] = 0;
97  mat[0] = 1;
98  mat[8] = 1;
99  mat[16] = 1;
100 }
101 
102 void SU3::setSU3Zero(){
103  for(int i = 0; i < 18; i++)
104  mat[i] = 0;
105 }
106 
107 double SU3::realTrace(){
108  return mat[0] + mat[8] + mat[16];
109 }
110 
111 double SU3::imagTrace(){
112  return mat[1] + mat[9] + mat[17];
113 }
114 
118 double getMultSumTrace(SU3 &a, SU3 &b){
119  return a.mat[0] * b.mat[0] - a.mat[1]*b.mat[1] + a.mat[2] * b.mat[6] - a.mat[3]*b.mat[7] + a.mat[4] * b.mat[12] - a.mat[5]*b.mat[13]
120  + a.mat[6] * b.mat[2] - a.mat[7]*b.mat[3] + a.mat[8] * b.mat[8] - a.mat[9]*b.mat[9] + a.mat[10] * b.mat[14] - a.mat[11]*b.mat[15]
121  + a.mat[12] * b.mat[4] - a.mat[13]*b.mat[5] + a.mat[14] * b.mat[10] - a.mat[15]*b.mat[11] + a.mat[16] * b.mat[16] - a.mat[17]*b.mat[17];
122 
123 }
124 
125 double getMultSumTrace(SU3&& a, SU3 &b){
126  return a.mat[0] * b.mat[0] - a.mat[1]*b.mat[1] + a.mat[2] * b.mat[6] - a.mat[3]*b.mat[7] + a.mat[4] * b.mat[12] - a.mat[5]*b.mat[13]
127  + a.mat[6] * b.mat[2] - a.mat[7]*b.mat[3] + a.mat[8] * b.mat[8] - a.mat[9]*b.mat[9] + a.mat[10] * b.mat[14] - a.mat[11]*b.mat[15]
128  + a.mat[12] * b.mat[4] - a.mat[13]*b.mat[5] + a.mat[14] * b.mat[10] - a.mat[15]*b.mat[11] + a.mat[16] * b.mat[16] - a.mat[17]*b.mat[17];
129 
130 }
131 
136 SU3 exp(const SU3& Q){
137  Q2 = Q*Q;
138  Q3 = Q2*Q;
139 
140  double c0 = Q3.realTrace() / 3.0;
141  double c1 = Q2.realTrace() / 2.0;
142 
143  bool c0negative = false;
144  if(c0 < 0){
145  c0negative = true;
146  c0 = -c0;
147  }
148 
149  double c1sqrt = sqrt(c1);
150  double oneoversqrt3 = 1.0/sqrt(3);
151  double c0max = c1*c1sqrt*oneoversqrt3*2.0 / 3.0;
152  double theta = acos(c0/c0max);
153  double w = c1sqrt*sin(theta/3.0);
154  double u = c1sqrt*oneoversqrt3*cos(theta/3.0);
155  double xi;
156  double u2 = u*u;
157  double w2 = w*w;
158 
159  if(fabs(w) < 0.05){
160  xi = 1.0 - w2/6.0 * (1 - w2/20.0 * (1 - w2/42.0));
161  }
162  else
163  xi = sin(w)/w;
164 
165 
166  double cmu = cos(-u);
167  double smu = sin(-u);
168  double c2u = cmu*cmu-smu*smu;
169  double s2u = -2.0*cmu*smu;
170  double cw = cos(w);
171  double cwcmu = cw*cmu;
172  double cwsmu = cw*smu;
173  double xicmu = xi*cmu;
174  double xismu = xi*smu;
175 
176  double h0r, h0i, h1r, h1i, h2r, h2i;
177  h0r = (u2-w2)*c2u + 8.0*u2*cwcmu - 2.0*u*(3.0*u2+w2)*xismu;
178  h0i = (u2-w2)*s2u + 8.0*u2*cwsmu + 2.0*u*(3.0*u2+w2)*xicmu;
179 
180  h1r = 2*u*c2u - 2*u*cwcmu - (3.0*u2-w2)*xismu;
181  h1i = 2*u*s2u - 2*u*cwsmu + (3.0*u2-w2)*xicmu;
182 
183  h2r = c2u - cwcmu + 3*u*xismu;
184  h2i = s2u - cwsmu - 3*u*xicmu;
185 
186  if (c0negative){
187  h0i *= -1;
188  h1r *= -1;
189  h2i *= -1;
190  }
191  double norm = 1.0/(9.0*u2-w2);
192  h0r*=norm;
193  h0i*=norm;
194  h1r*=norm;
195  h1i*=norm;
196  h2r*=norm;
197  h2i*=norm;
198 
199 
200 
201  SU3 result;
202  for(int i = 0; i < 18; i+=2){
203 
204  //F1
205  result.mat[i] = h1r*Q.mat[i]-h1i*Q.mat[i+1];
206  //F2
207  result.mat[i] += h2r*Q2.mat[i]-h2i*Q2.mat[i+1];
208 
209  if(i%8 == 0)
210  //F0
211  result.mat[i] += h0r;
212 
213  //F1
214  result.mat[i+1] = h1r*Q.mat[i+1]+h1i*Q.mat[i];
215  //F2
216  result.mat[i+1] += h2r*Q2.mat[i+1]+h2i*Q2.mat[i];
217  if(i%8 == 0)
218  //F0
219  result.mat[i+1] += h0i;
220 
221  }
222  return result;
223 }
224 
225 SU3 exp(SU3&& Q){
226  Q2 = Q*Q;
227  Q3 = Q2*Q;
228 
229  double c0 = Q3.realTrace() / 3.0;
230  double c1 = Q2.realTrace() / 2.0;
231 
232  bool c0negative = false;
233  if(c0 < 0){
234  c0negative = true;
235  c0 = -c0;
236  }
237 
238  double c1sqrt = sqrt(c1);
239  double oneoversqrt3 = 1.0/sqrt(3);
240  double c0max = c1*c1sqrt*oneoversqrt3*2.0 / 3.0;
241  double theta = acos(c0/c0max);
242  double w = c1sqrt*sin(theta/3.0);
243  double u = c1sqrt*oneoversqrt3*cos(theta/3.0);
244  double xi;
245  double u2 = u*u;
246  double w2 = w*w;
247 
248  if(fabs(w) < 0.05){
249  xi = 1.0 - w2/6.0 * (1 - w2/20.0 * (1 - w2/42.0));
250  }
251  else
252  xi = sin(w)/w;
253 
254 
255  double cmu = cos(-u);
256  double smu = sin(-u);
257  double c2u = cmu*cmu-smu*smu;
258  double s2u = -2.0*cmu*smu;
259  double cw = cos(w);
260  double cwcmu = cw*cmu;
261  double cwsmu = cw*smu;
262  double xicmu = xi*cmu;
263  double xismu = xi*smu;
264 
265  double h0r, h0i, h1r, h1i, h2r, h2i;
266  h0r = (u2-w2)*c2u + 8.0*u2*cwcmu - 2.0*u*(3.0*u2+w2)*xismu;
267  h0i = (u2-w2)*s2u + 8.0*u2*cwsmu + 2.0*u*(3.0*u2+w2)*xicmu;
268 
269  h1r = 2*u*c2u - 2*u*cwcmu - (3.0*u2-w2)*xismu;
270  h1i = 2*u*s2u - 2*u*cwsmu + (3.0*u2-w2)*xicmu;
271 
272  h2r = c2u - cwcmu + 3*u*xismu;
273  h2i = s2u - cwsmu - 3*u*xicmu;
274 
275  if (c0negative){
276  h0i *= -1;
277  h1r *= -1;
278  h2i *= -1;
279  }
280  double norm = 1.0/(9.0*u2-w2);
281  h0r*=norm;
282  h0i*=norm;
283  h1r*=norm;
284  h1i*=norm;
285  h2r*=norm;
286  h2i*=norm;
287 
288 
289 
290  SU3 result;
291  for(int i = 0; i < 18; i+=2){
292 
293  //F1
294  result.mat[i] = h1r*Q.mat[i]-h1i*Q.mat[i+1];
295  //F2
296  result.mat[i] += h2r*Q2.mat[i]-h2i*Q2.mat[i+1];
297 
298  if(i%8 == 0)
299  //F0
300  result.mat[i] += h0r;
301 
302  //F1
303  result.mat[i+1] = h1r*Q.mat[i+1]+h1i*Q.mat[i];
304  //F2
305  result.mat[i+1] += h2r*Q2.mat[i+1]+h2i*Q2.mat[i];
306  if(i%8 == 0)
307  //F0
308  result.mat[i+1] += h0i;
309 
310  }
311  return result;
312 }
Implementation of a class to perform arithmetics between links.
Definition: su3.h:53
double getMultSumTrace(SU3 &a, SU3 &b)
returns the real trace of the product of two SU3 matrices a and b
Definition: su3.cpp:118
Basic library to implement SU3 matrix arithmetics and functions.