]> www.ginac.de Git - ginac.git/blob - check/exam_color.cpp
more checks (more, MORE, BWAHAHHAAA!... uhm, ...) for noncommutative classes
[ginac.git] / check / exam_color.cpp
1 /** @file exam_color.cpp
2  *
3  *  Here we test GiNaC's color objects (su(3) Lie algebra). */
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 color_check1(void)
48 {
49         // checks general identities and contractions of the structure constants
50
51         unsigned result = 0;
52
53         idx a(symbol("a"), 8), b(symbol("b"), 8), c(symbol("c"), 8), d(symbol("d"), 8);
54
55         result += check_equal(color_d(a, c, a), 0);
56         result += check_equal_simplify(color_d(a, b, c) * color_d(b, d, c), numeric(5,3) * delta_tensor(a, d));
57         result += check_equal_simplify(color_d(idx(5, 8), b, c) * color_d(b, idx(5, 8), c), numeric(5,3));
58         result += check_equal_simplify(color_d(a, b, c) * color_d(b, c, a), numeric(40,3));
59         result += check_equal_simplify(color_d(a, b, c) * color_f(b, d, c), 0);
60         result += check_equal_simplify(color_d(a, b, c) * color_f(b, c, a), 0);
61         result += check_equal_simplify(color_f(a, b, c) * color_f(b, c, a), 24);
62         result += check_equal_simplify(color_f(a, b, c) * color_f(b, d, c), -3 * delta_tensor(a, d));
63         result += check_equal_simplify(color_h(a, b, c) * color_h(a, b, c), numeric(-32,3));
64         result += check_equal_simplify(color_h(a, b, c) * color_h(b, a, c), numeric(112,3));
65
66     ex e = color_h(a, b, c) * color_h(a, b, c);
67     ex sum = 0;
68         for (int i=1; i<9; i++)
69             for (int j=1; j<9; j++)
70                 for (int k=1; k<9; k++)
71                 sum += e.subs(lst(a == i, b == j, c == k));
72         if (!sum.is_equal(numeric(-32,3))) {
73                 clog << "numeric contraction of " << e << " erroneously returned "
74                      << sum << " instead of -32/3" << endl;
75                 result++;
76         }
77
78         return result;
79 }
80
81 static unsigned color_check2(void)
82 {
83         // checks general identities and contractions of the generators
84
85         unsigned result = 0;
86
87         idx a(symbol("a"), 8), b(symbol("b"), 8), c(symbol("c"), 8), k(symbol("k"), 8);
88         ex e;
89
90         e = color_T(k) * color_T(k);
91         result += check_equal_simplify(e, 4 * color_ONE() / 3);
92         e = color_T(k) * color_T(a) * color_T(k);
93         result += check_equal_simplify(e, -color_T(a) / 6);
94         e = color_T(k) * color_T(a) * color_T(b) *  color_T(k);
95         result += check_equal_simplify(e, delta_tensor(a, b) * color_ONE() / 4 - color_T(a) * color_T(b) / 6);
96         e = color_T(k) * color_T(a) * color_T(b) *  color_T(c) * color_T(k);
97         result += check_equal_simplify(e, (color_h(a, b, c) * color_ONE() / 8).expand() - color_T(a) * color_T(b) * color_T(c) / 6);
98         e = color_T(a) * color_T(b) * color_T(a) *  color_T(b);
99         result += check_equal_simplify(e, -2 * color_ONE() / 9);
100         e = color_T(a) * color_T(b) * color_T(b) *  color_T(a);
101         result += check_equal_simplify(e, 16 * color_ONE() / 9);
102         e = color_T(a) * color_T(b) * color_T(c) * color_T(c) * color_T(b) *  color_T(a);
103         result += check_equal_simplify(e, 64 * color_ONE() / 27);
104
105         return result;
106 }
107
108 static unsigned color_check3(void)
109 {
110         // checks traces
111
112         unsigned result = 0;
113
114         idx a(symbol("a"), 8), b(symbol("b"), 8), c(symbol("c"), 8), k(symbol("k"), 8);
115         ex e;
116
117         e = color_ONE();
118         result += check_equal(color_trace(e), 3);
119         e = color_T(a);
120         result += check_equal(color_trace(e), 0);
121         e = color_T(a) * color_T(b);
122         result += check_equal(color_trace(e), delta_tensor(a, b) / 2);
123         e = color_T(a) * color_T(b) * color_T(c);
124         result += check_equal(color_trace(e), color_h(a, b, c) / 4);
125
126         return result;
127 }
128
129 unsigned exam_color(void)
130 {
131         unsigned result = 0;
132         
133         cout << "examining color objects" << flush;
134         clog << "----------color objects:" << endl;
135
136         result += color_check1();  cout << '.' << flush;
137         result += color_check2();  cout << '.' << flush;
138         result += color_check3();  cout << '.' << flush;
139         
140         if (!result) {
141                 cout << " passed " << endl;
142                 clog << "(no output)" << endl;
143         } else {
144                 cout << " failed " << endl;
145         }
146         
147         return result;
148 }