]> www.ginac.de Git - ginac.git/blob - check/exam_noncommut.cpp
bd395a3b8941872abddf4c1e62f0dad92cf03dad
[ginac.git] / check / exam_noncommut.cpp
1 /** @file exam_noncommut.cpp
2  *
3  *  Here we test manipulations on GiNaC's lortensors. */
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 lortensor_check1(void)
26 {
27         // checks simple identities of the metric tensor!
28         
29         unsigned result = 0;
30         lorentzidx mu("mu"), nu("nu");
31         ex e1, e2, e3, e4, e5, e6;
32         e1 = lortensor_g(mu,nu);
33         e2 = lortensor_g(nu,mu);
34         e3 = e1 - e2; // g(~mu,~nu) - g(~nu,~mu) = 0 !
35         e4 = lortensor_g(mu,mu.toggle_covariant());
36         e5 = lortensor_g(mu.toggle_covariant(),mu);
37         e6 = e4 - e5; // g(~mu,_mu) - g(_mu,~mu) = 0!
38         if (!e3.is_zero()) {
39                 clog << e1 << "-" << e2 << " erroneously returned "
40                      << e3 << " instead of 0" << endl;
41                 ++result;
42         }
43         if (!e6.is_zero()) {
44                 clog << e4 << "-" << e5 << " erroneously returned "
45                      << e6 << " instead of 0" << endl;
46                 ++result;
47         }
48
49         return result;
50 }
51
52 static unsigned lortensor_check2(void)
53 {
54         // checks simple contraction properties of an arbitrary (symmetric!) rankn lortensor!
55         
56         unsigned result = 0;
57         lorentzidx mu("mu"), nu("nu"), rho("rho");
58         ex e1, e2, e3, e4, e5, e6, e7, e8, e9, e10;
59         e1 = lortensor_g(mu,nu);
60         e2 = lortensor_g(nu,mu);
61         e3 = lortensor_rank1("p",mu.toggle_covariant());
62         e4 = lortensor_rank1("p",nu);
63         e5 = e3 * e1 - e3 * e2; // p_mu g(~mu,~nu) - p_mu g(~nu,~mu) = 0!
64         e6 = simplify_lortensor(e3 * e1) - e4; // p~nu - p~nu = 0!
65         e7 = lortensor_g(nu,rho);
66         e8 = lortensor_rank2("F",mu.toggle_covariant(),nu.toggle_covariant());
67         e9 = lortensor_rank2("F",mu.toggle_covariant(),rho);
68         e10 = simplify_lortensor(e8 * e7) - e9; // F(_mu,_nu) g(~nu,~rho) - F(_mu,~rho) = 0!
69         if (!e5.is_zero()) {
70                 clog << e3 << "*" << e1 << "-" << e3 << "*" << e2 << " erroneously returned "
71                      << e5 << " instead of 0" << endl;
72                 ++result;
73         }
74         if (!e6.is_zero()) {    
75                 clog << " simplify_lortensor(e3 * e1)" << "-" << e4 << " erroneously returned"
76                      << e6 << " instead of 0" << endl;
77                 ++result;
78         }
79         if (!e10.is_zero()) {           
80                 clog << " simplify_lortensor(e8 * e7)" << "-" << e9 << " erroneously returned"
81                      << e10 << " instead of 0" << endl;
82                 ++result;
83         }
84
85         return result;
86 }
87
88 unsigned exam_noncommut(void)
89 {
90         unsigned result = 0;
91         
92         cout << "examining behaviour of noncommutative objects" << flush;
93         clog << "----------behaviour of noncommutative objects:" << endl;
94         
95         result += lortensor_check1();  cout << '.' << flush;
96         result += lortensor_check2();  cout << '.' << flush;
97         
98         if (!result) {
99                 cout << " passed " << endl;
100                 clog << "(no output)" << endl;
101         } else {
102                 cout << " failed " << endl;
103         }
104         
105         return result;
106 }