]> www.ginac.de Git - ginac.git/commitdiff
added checks for new indexed objects
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 6 Mar 2001 20:06:38 +0000 (20:06 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 6 Mar 2001 20:06:38 +0000 (20:06 +0000)
check/Makefile.am
check/exam_indexed.cpp [new file with mode: 0644]
check/exams.cpp
check/exams.h
check/exams.ref

index a5e781b95ac3fdba4626d9117457d0fd67ef8e92..bb9ef632238efbe37ff3c16f9142c72f52aa6334 100644 (file)
@@ -1,14 +1,18 @@
 ## Process this file with automake to produce Makefile.in
+
 TESTS = run_exams run_checks run_times
 check_PROGRAMS = exams checks times
+
+checks_SOURCES =  check_numeric.cpp check_inifcns.cpp check_matrices.cpp \
+  check_lsolve.cpp genex.cpp checks.cpp checks.h
+checks_LDADD = ../ginac/libginac.la
+
 exams_SOURCES = exam_paranoia.cpp exam_numeric.cpp exam_powerlaws.cpp \
   exam_inifcns.cpp exam_differentiation.cpp exam_polygcd.cpp \
   exam_normalization.cpp exam_pseries.cpp exam_matrices.cpp exam_lsolve.cpp \
-  exam_noncommut.cpp exam_misc.cpp exams.cpp exams.h
+  exam_indexed.cpp exam_misc.cpp exams.cpp exams.h
 exams_LDADD = ../ginac/libginac.la
-checks_SOURCES =  check_numeric.cpp check_inifcns.cpp check_matrices.cpp \
-  check_lsolve.cpp genex.cpp checks.cpp checks.h
-checks_LDADD = ../ginac/libginac.la
+
 times_SOURCES = time_dennyfliegner.cpp time_gammaseries.cpp \
   time_vandermonde.cpp time_toeplitz.cpp time_lw_A.cpp time_lw_B.cpp \
   time_lw_C.cpp time_lw_D.cpp time_lw_E.cpp time_lw_F.cpp time_lw_G.cpp \
@@ -16,6 +20,8 @@ times_SOURCES = time_dennyfliegner.cpp time_gammaseries.cpp \
   time_lw_O.cpp time_lw_P.cpp time_lw_Pprime.cpp time_lw_Q.cpp \
   time_lw_Qprime.cpp time_antipode.cpp timer.cpp times.cpp times.h
 times_LDADD = ../ginac/libginac.la
+
 INCLUDES = -I$(srcdir)/../ginac -I../ginac
+
 CLEANFILES = exams.out checks.out times.out
 EXTRA_DIST = exams.ref checks.ref times.ref run_exams run_checks run_times
diff --git a/check/exam_indexed.cpp b/check/exam_indexed.cpp
new file mode 100644 (file)
index 0000000..11182cb
--- /dev/null
@@ -0,0 +1,208 @@
+/** @file exam_indexed.cpp
+ *
+ *  Here we test manipulations on GiNaC's indexed objects. */
+
+/*
+ *  GiNaC Copyright (C) 1999-2001 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 delta_check(void)
+{
+       // checks identities of the delta tensor
+
+       unsigned result = 0;
+
+       symbol s_i("i"), s_j("j"), s_k("k");
+       idx i(s_i, 3), j(s_j, 3), k(s_k, 3);
+       symbol A("A");
+
+       // symmetry
+       result += check_equal(delta_tensor(i, j), delta_tensor(j, i));
+
+       // trace = dimension of index space
+       result += check_equal(delta_tensor(i, i), 3);
+       result += check_equal_simplify(delta_tensor(i, j) * delta_tensor(i, j), 3);
+
+       // contraction with delta tensor
+       result += check_equal_simplify(delta_tensor(i, j) * indexed(A, k), delta_tensor(i, j) * indexed(A, k));
+       result += check_equal_simplify(delta_tensor(i, j) * indexed(A, j), indexed(A, i));
+       result += check_equal_simplify(delta_tensor(i, j) * indexed(A, i), indexed(A, j));
+       result += check_equal_simplify(delta_tensor(i, j) * delta_tensor(j, k) * indexed(A, i), indexed(A, k));
+
+       return result;
+}
+
+static unsigned metric_check(void)
+{
+       // checks identities of the metric tensor
+
+       unsigned result = 0;
+
+       symbol s_mu("mu"), s_nu("nu"), s_rho("rho"), s_sigma("sigma");
+       varidx mu(s_mu, 4), nu(s_nu, 4), rho(s_rho, 4), sigma(s_sigma, 4);
+       symbol A("A");
+
+       // becomes delta tensor if indices have opposite variance
+       result += check_equal(metric_tensor(mu, nu.toggle_variance()), delta_tensor(mu, nu.toggle_variance()));
+
+       // scalar contraction = dimension of index space
+       result += check_equal(metric_tensor(mu, mu.toggle_variance()), 4);
+       result += check_equal_simplify(metric_tensor(mu, nu) * metric_tensor(mu.toggle_variance(), nu.toggle_variance()), 4);
+
+       // contraction with metric tensor
+       result += check_equal_simplify(metric_tensor(mu, nu) * indexed(A, nu), metric_tensor(mu, nu) * indexed(A, nu));
+       result += check_equal_simplify(metric_tensor(mu, nu) * indexed(A, nu.toggle_variance()), indexed(A, mu));
+       result += check_equal_simplify(metric_tensor(mu, nu) * indexed(A, mu.toggle_variance()), indexed(A, nu));
+       result += check_equal_simplify(metric_tensor(mu, nu) * metric_tensor(mu.toggle_variance(), rho.toggle_variance()) * indexed(A, nu.toggle_variance()), indexed(A, rho.toggle_variance()));
+       result += check_equal_simplify(metric_tensor(mu, rho) * metric_tensor(nu, sigma) * indexed(A, rho.toggle_variance(), sigma.toggle_variance()), indexed(A, mu, nu));
+       result += check_equal_simplify(indexed(A, mu.toggle_variance()) * metric_tensor(mu, nu) - indexed(A, mu.toggle_variance()) * metric_tensor(nu, mu), 0);
+       result += check_equal_simplify(indexed(A, mu.toggle_variance(), nu.toggle_variance()) * metric_tensor(nu, rho), indexed(A, mu.toggle_variance(), rho));
+
+       // contraction with delta tensor yields a metric tensor
+       result += check_equal_simplify(delta_tensor(mu, nu.toggle_variance()) * metric_tensor(nu, rho), metric_tensor(mu, rho));
+       result += check_equal_simplify(metric_tensor(mu, nu) * indexed(A, nu.toggle_variance()) * delta_tensor(mu.toggle_variance(), rho), indexed(A, rho));
+
+       return result;
+}
+
+static unsigned symmetry_check(void)
+{
+       // check symmetric/antisymmetric objects
+
+       unsigned result = 0;
+
+       symbol s_i("i"), s_j("j"), s_k("k");
+       idx i(s_i, 3), j(s_j, 3), k(s_k, 3);
+       symbol A("A");
+       ex e, e1, e2;
+
+       result += check_equal(indexed(A, indexed::symmetric, i, j), indexed(A, indexed::symmetric, j, i));
+       result += check_equal(indexed(A, indexed::antisymmetric, i, j) + indexed(A, indexed::antisymmetric, j, i), 0);
+       result += check_equal(indexed(A, indexed::antisymmetric, i, j, k) - indexed(A, indexed::antisymmetric, j, k, i), 0);
+
+       return result;
+}
+
+static unsigned edyn_check(void)
+{
+       // relativistic electrodynamics: check transformation laws of electric
+       // and magnetic fields by applying a Lorentz boost to the field tensor
+
+       unsigned result = 0;
+
+       symbol beta("beta");
+       ex gamma = 1 / sqrt(1 - pow(beta, 2));
+       symbol Ex("Ex"), Ey("Ey"), Ez("Ez");
+       symbol Bx("Bx"), By("By"), Bz("Bz");
+
+       // Lorentz transformation matrix (boost along x axis)
+       matrix L(4, 4);
+       L.set(0, 0, gamma);
+       L.set(0, 1, -beta*gamma);
+       L.set(1, 0, -beta*gamma);
+       L.set(1, 1, gamma);
+       L.set(2, 2, 1);
+       L.set(3, 3, 1);
+
+       // Electromagnetic field tensor
+       matrix F(4, 4);
+       F.set(0, 1, -Ex);
+       F.set(1, 0, Ex);
+       F.set(0, 2, -Ey);
+       F.set(2, 0, Ey);
+       F.set(0, 3, -Ez);
+       F.set(3, 0, Ez);
+       F.set(1, 2, -Bz);
+       F.set(2, 1, Bz);
+       F.set(1, 3, By);
+       F.set(3, 1, -By);
+       F.set(2, 3, -Bx);
+       F.set(3, 2, Bx);
+
+       // Indices
+       symbol s_mu("mu"), s_nu("nu"), s_rho("rho"), s_sigma("sigma");
+       varidx mu(s_mu, 4), nu(s_nu, 4), rho(s_rho, 4), sigma(s_sigma, 4);
+
+       // Apply transformation law of second rank tensor
+       ex e = (indexed(L, mu, rho.toggle_variance())
+          * indexed(L, nu, sigma.toggle_variance())
+          * indexed(F, rho, sigma)).simplify_indexed();
+
+       // Extract transformed electric and magnetic fields
+       ex Ex_p = e.subs(lst(mu == 1, nu == 0)).normal();
+       ex Ey_p = e.subs(lst(mu == 2, nu == 0)).normal();
+       ex Ez_p = e.subs(lst(mu == 3, nu == 0)).normal();
+       ex Bx_p = e.subs(lst(mu == 3, nu == 2)).normal();
+       ex By_p = e.subs(lst(mu == 1, nu == 3)).normal();
+       ex Bz_p = e.subs(lst(mu == 2, nu == 1)).normal();
+
+       // Check results
+       result += check_equal(Ex_p, Ex);
+       result += check_equal(Ey_p, gamma * (Ey - beta * Bz));
+       result += check_equal(Ez_p, gamma * (Ez + beta * By));
+       result += check_equal(Bx_p, Bx);
+       result += check_equal(By_p, gamma * (By + beta * Ez));
+       result += check_equal(Bz_p, gamma * (Bz - beta * Ey));
+
+       return result;
+}
+
+unsigned exam_indexed(void)
+{
+       unsigned result = 0;
+       
+       cout << "examining indexed objects" << flush;
+       clog << "----------indexed objects:" << endl;
+
+       result += delta_check();  cout << '.' << flush;
+       result += metric_check();  cout << '.' << flush;
+       result += symmetry_check();  cout << '.' << flush;
+       result += edyn_check();  cout << '.' << flush;
+       
+       if (!result) {
+               cout << " passed " << endl;
+               clog << "(no output)" << endl;
+       } else {
+               cout << " failed " << endl;
+       }
+       
+       return result;
+}
index 068e936c8a36d79212dbb40711c9111f84f71e77..385ed9a3df8c9663688d73960a782f5620c7177a 100644 (file)
@@ -100,7 +100,7 @@ int main()
        }
        
        try {
-               result += exam_noncommut();
+               result += exam_indexed();
        } catch (const exception &e) {
                cout << "Error: caught exception " << e.what() << endl;
                ++result;
index 259b54d2f5a3032ef4ff628585720e5d34b1b161..6677659d0056b81221b23a5912ebd7780c5d59be 100644 (file)
@@ -38,7 +38,7 @@ unsigned exam_normalization();
 unsigned exam_pseries();
 unsigned exam_matrices();
 unsigned exam_lsolve();
-unsigned exam_noncommut();
+unsigned exam_indexed();
 unsigned exam_misc();
 
 #endif // ndef EXAMS_H
index 51e47b228a82895a5ca04c451dbe40af190e0f0a..f9c4afb40a8e1fdfc4e67f4cebb7cf8290a585b4 100644 (file)
@@ -18,7 +18,7 @@
 (no output)
 ----------linear solve:
 (no output)
-----------behaviour of noncommutative objects:
+----------indexed objects:
 (no output)
 ----------miscellaneous other things:
 (no output)