]> www.ginac.de Git - ginac.git/blob - check/exam_clifford.cpp
added more trace checks
[ginac.git] / check / exam_clifford.cpp
1 /** @file exam_clifford.cpp
2  *
3  *  Here we test GiNaC's Clifford algebra objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "exams.h"
24
25 static unsigned check_equal(const ex &e1, const ex &e2)
26 {
27         ex e = e1 - e2;
28         if (!e.is_zero()) {
29                 clog << e1 << "-" << e2 << " erroneously returned "
30                      << e << " instead of 0" << endl;
31                 return 1;
32         }
33         return 0;
34 }
35
36 static unsigned check_equal_simplify(const ex &e1, const ex &e2)
37 {
38         ex e = simplify_indexed(e1) - e2;
39         if (!e.is_zero()) {
40                 clog << "simplify_indexed(" << e1 << ")-" << e2 << " erroneously returned "
41                      << e << " instead of 0" << endl;
42                 return 1;
43         }
44         return 0;
45 }
46
47 static unsigned clifford_check1(void)
48 {
49         // checks general identities and contractions
50
51         unsigned result = 0;
52
53         symbol dim("D");
54         varidx mu(symbol("mu"), dim), nu(symbol("nu"), dim);
55         ex e;
56
57         e = dirac_ONE() * dirac_ONE();
58         result += check_equal(e, dirac_ONE());
59
60         e = dirac_ONE() * dirac_gamma(mu) * dirac_ONE();
61         result += check_equal(e, dirac_gamma(mu));
62
63         e = dirac_gamma(varidx(2, dim)) * dirac_gamma(varidx(1, dim)) *
64             dirac_gamma(varidx(1, dim)) * dirac_gamma(varidx(2, dim));
65         result += check_equal(e, dirac_ONE());
66
67         e = dirac_gamma(mu) * dirac_gamma(nu) *
68             dirac_gamma(nu.toggle_variance()) * dirac_gamma(mu.toggle_variance());
69         result += check_equal_simplify(e, pow(dim, 2) * dirac_ONE());
70
71         e = dirac_gamma(mu) * dirac_gamma(nu) *
72             dirac_gamma(mu.toggle_variance()) * dirac_gamma(nu.toggle_variance());
73         result += check_equal_simplify(e, 2*dim*dirac_ONE()-pow(dim, 2)*dirac_ONE());
74
75         return result;
76 }
77
78 static unsigned clifford_check2(void)
79 {
80         // checks identities relating to gamma5
81
82         unsigned result = 0;
83
84         symbol dim("D");
85         varidx mu(symbol("mu"), dim), nu(symbol("nu"), dim);
86         ex e;
87
88         e = dirac_gamma(mu) * dirac_gamma5() + dirac_gamma5() * dirac_gamma(mu);
89         result += check_equal(e, 0);
90
91         e = dirac_gamma5() * dirac_gamma(mu) * dirac_gamma5() + dirac_gamma(mu);
92         result += check_equal(e, 0);
93
94         return result;
95 }
96
97 static unsigned clifford_check3(void)
98 {
99         // checks traces
100
101         unsigned result = 0;
102
103         symbol dim("D"), m("m"), q("q"), l("l"), ldotq("ldotq");
104         varidx mu(symbol("mu"), dim), nu(symbol("nu"), dim), rho(symbol("rho"), dim),
105                sig(symbol("sig"), dim), kap(symbol("kap"), dim), lam(symbol("lam"), 4);
106         ex e;
107
108         e = dirac_gamma(mu);
109         result += check_equal(dirac_trace(e), 0);
110
111         e = dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho);
112         result += check_equal(dirac_trace(e), 0);
113
114         e = dirac_gamma5() * dirac_gamma(mu);
115         result += check_equal(dirac_trace(e), 0);
116
117         e = dirac_gamma5() * dirac_gamma(mu) * dirac_gamma(nu);
118         result += check_equal(dirac_trace(e), 0);
119
120         e = dirac_gamma5() * dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho);
121         result += check_equal(dirac_trace(e), 0);
122
123         scalar_products sp;
124         sp.add(q, q, pow(q, 2));
125         sp.add(l, l, pow(l, 2));
126         sp.add(l, q, ldotq);
127
128         e = pow(m, 2) * dirac_slash(q, dim) * dirac_slash(q, dim);
129         e = dirac_trace(e).simplify_indexed(sp);
130         result += check_equal(e, 4*pow(m, 2)*pow(q, 2));
131
132         // cyclicity without gamma5
133         e = dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig)
134           - dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig) * dirac_gamma(mu);
135         e = dirac_trace(e);
136         result += check_equal(e, 0);
137
138         e = dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig) * dirac_gamma(kap) * dirac_gamma(lam)
139           - dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig) * dirac_gamma(kap) * dirac_gamma(lam) * dirac_gamma(mu);
140         e = dirac_trace(e).expand();
141         result += check_equal(e, 0);
142
143         // cyclicity of gamma5 * S_4
144         e = dirac_gamma5() * dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig)
145           - dirac_gamma(sig) * dirac_gamma5() * dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho);
146         e = dirac_trace(e);
147         result += check_equal(e, 0);
148
149         // non-cyclicity of order D-4 of gamma5 * S_6
150         e = dirac_gamma5() * dirac_gamma(mu) * dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig) * dirac_gamma(kap) * dirac_gamma(mu.toggle_variance())
151           + dim * dirac_gamma5() * dirac_gamma(nu) * dirac_gamma(rho) * dirac_gamma(sig) * dirac_gamma(kap);
152         e = dirac_trace(e);
153         e = (e / (dim - 4)).normal();
154         result += check_equal(e, 8 * eps0123(nu, rho, sig, kap));
155
156         // one-loop vacuum polarization in QED
157         e = dirac_gamma(mu) *
158             (dirac_slash(l, dim) + dirac_slash(q, dim) + m * dirac_ONE()) *
159             dirac_gamma(mu.toggle_variance()) *
160             (dirac_slash(l, dim) + m * dirac_ONE());
161         e = dirac_trace(e).simplify_indexed(sp);
162         result += check_equal(e, 4*((2-dim)*l*l + (2-dim)*ldotq + dim*m*m).expand());
163
164         e = dirac_slash(q, dim) *
165             (dirac_slash(l, dim) + dirac_slash(q, dim) + m * dirac_ONE()) *
166             dirac_slash(q, dim) *
167             (dirac_slash(l, dim) + m * dirac_ONE());
168         e = dirac_trace(e).simplify_indexed(sp);
169         result += check_equal(e, 4*(2*ldotq*ldotq + q*q*ldotq - q*q*l*l + q*q*m*m).expand());
170
171         return result;
172 }
173
174 unsigned exam_clifford(void)
175 {
176         unsigned result = 0;
177         
178         cout << "examining clifford objects" << flush;
179         clog << "----------clifford objects:" << endl;
180
181         result += clifford_check1();  cout << '.' << flush;
182         result += clifford_check2();  cout << '.' << flush;
183         result += clifford_check3();  cout << '.' << flush;
184         
185         if (!result) {
186                 cout << " passed " << endl;
187                 clog << "(no output)" << endl;
188         } else {
189                 cout << " failed " << endl;
190         }
191         
192         return result;
193 }