]> www.ginac.de Git - ginac.git/blob - check/exam_noncommut.cpp
* some longish timings are now disabled by default.
[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 #if 0  // this will change
53 static unsigned lortensor_check2(void)
54 {
55         // checks simple contraction properties of an arbitrary (symmetric!) rankn lortensor!
56         
57         unsigned result = 0;
58         lorentzidx mu("mu"), nu("nu"), rho("rho");
59         ex e1, e2, e3, e4, e5, e6, e7, e8, e9, e10;
60         e1 = lortensor_g(mu,nu);
61         e2 = lortensor_g(nu,mu);
62         e3 = lortensor_rank1("p",mu.toggle_covariant());
63         e4 = lortensor_rank1("p",nu);
64         e5 = e3 * e1 - e3 * e2; // p_mu g(~mu,~nu) - p_mu g(~nu,~mu) = 0!
65         e6 = simplify_lortensor(e3 * e1) - e4; // p~nu - p~nu = 0!
66         e7 = lortensor_g(nu,rho);
67         e8 = lortensor_rank2("F",mu.toggle_covariant(),nu.toggle_covariant());
68         e9 = lortensor_rank2("F",mu.toggle_covariant(),rho);
69         e10 = simplify_lortensor(e8 * e7) - e9; // F(_mu,_nu) g(~nu,~rho) - F(_mu,~rho) = 0!
70         if (!e5.is_zero()) {
71                 clog << e3 << "*" << e1 << "-" << e3 << "*" << e2 << " erroneously returned "
72                      << e5 << " instead of 0" << endl;
73                 ++result;
74         }
75         if (!e6.is_zero()) {    
76                 clog << " simplify_lortensor(e3 * e1)" << "-" << e4 << " erroneously returned"
77                      << e6 << " instead of 0" << endl;
78                 ++result;
79         }
80         if (!e10.is_zero()) {           
81                 clog << " simplify_lortensor(e8 * e7)" << "-" << e9 << " erroneously returned"
82                      << e10 << " instead of 0" << endl;
83                 ++result;
84         }
85         
86         return result;
87 }
88 #endif
89
90 unsigned exam_noncommut(void)
91 {
92         unsigned result = 0;
93         
94         cout << "examining behaviour of noncommutative objects" << flush;
95         clog << "----------behaviour of noncommutative objects:" << endl;
96         
97         result += lortensor_check1();  cout << '.' << flush;
98 #if 0
99         result += lortensor_check2();  cout << '.' << flush;
100 #endif
101         if (!result) {
102                 cout << " passed " << endl;
103                 clog << "(no output)" << endl;
104         } else {
105                 cout << " failed " << endl;
106         }
107         
108         return result;
109 }