]> www.ginac.de Git - ginac.git/blob - check/exam_clifford.cpp
- subs() can be used to substitute functions, tensors and indexed objects
[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_gamma(mu) * dirac_gamma(nu) *
58             dirac_gamma(nu.toggle_variance()) * dirac_gamma(mu.toggle_variance());
59         result += check_equal_simplify(e, pow(dim, 2) * dirac_one());
60
61         e = dirac_gamma(mu) * dirac_gamma(nu) *
62             dirac_gamma(mu.toggle_variance()) * dirac_gamma(nu.toggle_variance());
63         result += check_equal_simplify(e, 2*dim*dirac_one()-pow(dim, 2)*dirac_one());
64
65         return result;
66 }
67
68 unsigned exam_clifford(void)
69 {
70         unsigned result = 0;
71         
72         cout << "examining clifford objects" << flush;
73         clog << "----------clifford objects:" << endl;
74
75         result += clifford_check1();  cout << '.' << flush;
76         
77         if (!result) {
78                 cout << " passed " << endl;
79                 clog << "(no output)" << endl;
80         } else {
81                 cout << " failed " << endl;
82         }
83         
84         return result;
85 }