File: exam_color.cpp

package info (click to toggle)
ginac 1.0.8-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,544 kB
  • ctags: 3,232
  • sloc: cpp: 27,732; sh: 7,126; perl: 1,819; yacc: 763; lex: 345; makefile: 221; sed: 32
file content (150 lines) | stat: -rw-r--r-- 5,111 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/** @file exam_color.cpp
 *
 *  Here we test GiNaC's color objects (su(3) Lie algebra). */

/*
 *  GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "exams.h"

static unsigned check_equal(const ex &e1, const ex &e2)
{
	ex e = e1 - e2;
	if (!e.is_zero()) {
		clog << e1 << "-" << e2 << " erroneously returned "
		     << e << " instead of 0" << endl;
		return 1;
	}
	return 0;
}

static unsigned check_equal_simplify(const ex &e1, const ex &e2)
{
	ex e = simplify_indexed(e1) - e2;
	if (!e.is_zero()) {
		clog << "simplify_indexed(" << e1 << ")-" << e2 << " erroneously returned "
		     << e << " instead of 0" << endl;
		return 1;
	}
	return 0;
}

static unsigned color_check1(void)
{
	// checks general identities and contractions of the structure constants

	unsigned result = 0;

	idx a(symbol("a"), 8), b(symbol("b"), 8), c(symbol("c"), 8), d(symbol("d"), 8);

	result += check_equal(color_d(a, c, a), 0);
	result += check_equal_simplify(color_d(a, b, c) * color_d(b, d, c), numeric(5,3) * delta_tensor(a, d));
	result += check_equal_simplify(color_d(idx(5, 8), b, c) * color_d(b, idx(5, 8), c), numeric(5,3));
	result += check_equal_simplify(color_d(a, b, c) * color_d(b, c, a), numeric(40,3));
	result += check_equal_simplify(color_d(a, b, c) * color_f(b, d, c), 0);
	result += check_equal_simplify(color_d(a, b, c) * color_f(b, c, a), 0);
	result += check_equal_simplify(color_f(a, b, c) * color_f(b, c, a), 24);
	result += check_equal_simplify(color_f(a, b, c) * color_f(b, d, c), -3 * delta_tensor(a, d));
	result += check_equal_simplify(color_h(a, b, c) * color_h(a, b, c), numeric(-32,3));
	result += check_equal_simplify(color_h(a, b, c) * color_h(b, a, c), numeric(112,3));

    ex e = color_h(a, b, c) * color_h(a, b, c);
    ex sum = 0;
	for (int i=1; i<9; i++)
	    for (int j=1; j<9; j++)
	        for (int k=1; k<9; k++)
                sum += e.subs(lst(a == i, b == j, c == k));
	if (!sum.is_equal(numeric(-32,3))) {
		clog << "numeric contraction of " << e << " erroneously returned "
		     << sum << " instead of -32/3" << endl;
		result++;
	}

	return result;
}

static unsigned color_check2(void)
{
	// checks general identities and contractions of the generators

	unsigned result = 0;

	idx a(symbol("a"), 8), b(symbol("b"), 8), c(symbol("c"), 8), k(symbol("k"), 8);
	ex e;

	e = color_T(k) * color_T(k);
	result += check_equal_simplify(e, 4 * color_ONE() / 3);
	e = color_T(k) * color_T(a) * color_T(k);
	result += check_equal_simplify(e, -color_T(a) / 6);
	e = color_T(k) * color_T(a) * color_T(b) *  color_T(k);
	result += check_equal_simplify(e, delta_tensor(a, b) * color_ONE() / 4 - color_T(a) * color_T(b) / 6);
	e = color_T(k) * color_T(a) * color_T(b) *  color_T(c) * color_T(k);
	result += check_equal_simplify(e, (color_h(a, b, c) * color_ONE() / 8).expand() - color_T(a) * color_T(b) * color_T(c) / 6);
	e = color_T(a) * color_T(b) * color_T(a) *  color_T(b);
	result += check_equal_simplify(e, -2 * color_ONE() / 9);
	e = color_T(a) * color_T(b) * color_T(b) *  color_T(a);
	result += check_equal_simplify(e, 16 * color_ONE() / 9);
	e = color_T(a) * color_T(b) * color_T(c) * color_T(c) * color_T(b) *  color_T(a);
	result += check_equal_simplify(e, 64 * color_ONE() / 27);
	e = color_T(a) * color_T(b) * color_T(c) * color_T(k) * color_T(a) * color_T(k) *  color_T(c) * color_T(b);
	result += check_equal_simplify(e, -color_ONE() / 162);

	return result;
}

static unsigned color_check3(void)
{
	// checks traces

	unsigned result = 0;

	idx a(symbol("a"), 8), b(symbol("b"), 8), c(symbol("c"), 8), k(symbol("k"), 8);
	ex e;

	e = color_ONE();
	result += check_equal(color_trace(e), 3);
	e = color_T(a);
	result += check_equal(color_trace(e), 0);
	e = color_T(a) * color_T(b);
	result += check_equal(color_trace(e), delta_tensor(a, b) / 2);
	e = color_T(a) * color_T(b) * color_T(c);
	result += check_equal(color_trace(e), color_h(a, b, c) / 4);

	return result;
}

unsigned exam_color(void)
{
	unsigned result = 0;
	
	cout << "examining color objects" << flush;
	clog << "----------color objects:" << endl;

	result += color_check1();  cout << '.' << flush;
	result += color_check2();  cout << '.' << flush;
	result += color_check3();  cout << '.' << flush;
	
	if (!result) {
		cout << " passed " << endl;
		clog << "(no output)" << endl;
	} else {
		cout << " failed " << endl;
	}
	
	return result;
}