X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_indexed.cpp;h=90197c082014cafbbe70767d92aa5ff77b70b8bf;hp=e5a3772f5fc02a25dbccb21b99486209fffbdb3b;hb=f263f768cf609ae8c0899560449f235a6d408193;hpb=b8e4e8958d3884ea3c91ac9a8b99fb912ea44626 diff --git a/check/exam_indexed.cpp b/check/exam_indexed.cpp index e5a3772f..90197c08 100644 --- a/check/exam_indexed.cpp +++ b/check/exam_indexed.cpp @@ -3,7 +3,7 @@ * Here we test manipulations on GiNaC's indexed objects. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * 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 @@ -44,6 +44,17 @@ static unsigned check_equal_simplify(const ex &e1, const ex &e2) return 0; } +static unsigned check_equal_simplify(const ex &e1, const ex &e2, const scalar_products &sp) +{ + ex e = simplify_indexed(e1, sp) - 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 @@ -109,16 +120,28 @@ static unsigned epsilon_check(void) 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 s_mu("mu"), s_nu("nu"), s_rho("rho"), s_sigma("sigma"), s_tau("tau"); + symbol d("d"); + varidx mu(s_mu, 4), nu(s_nu, 4), rho(s_rho, 4), sigma(s_sigma, 4), tau(s_tau, 4); + varidx mu_co(s_mu, 4, true), nu_co(s_nu, 4, true), rho_co(s_rho, 4, true), sigma_co(s_sigma, 4, true), tau_co(s_tau, 4, true); // antisymmetry result += check_equal(lorentz_eps(mu, nu, rho, sigma) + lorentz_eps(sigma, rho, mu, nu), 0); // convolution is zero - result += check_equal(lorentz_eps(mu, nu, rho, nu.toggle_variance()), 0); - result += check_equal(lorentz_eps(mu, nu, mu.toggle_variance(), nu.toggle_variance()), 0); - result += check_equal_simplify(lorentz_g(mu.toggle_variance(), nu.toggle_variance()) * lorentz_eps(mu, nu, rho, sigma), 0); + result += check_equal(lorentz_eps(mu, nu, rho, nu_co), 0); + result += check_equal(lorentz_eps(mu, nu, mu_co, nu_co), 0); + result += check_equal_simplify(lorentz_g(mu_co, nu_co) * lorentz_eps(mu, nu, rho, sigma), 0); + + // contraction with symmetric tensor is zero + result += check_equal_simplify(lorentz_eps(mu, nu, rho, sigma) * indexed(d, sy_symm(), mu_co, nu_co), 0); + result += check_equal_simplify(lorentz_eps(mu, nu, rho, sigma) * indexed(d, sy_symm(), nu_co, sigma_co, rho_co), 0); + ex e = lorentz_eps(mu, nu, rho, sigma) * indexed(d, sy_symm(), mu_co, tau); + result += check_equal_simplify(e, e); + + // contractions of epsilon tensors + result += check_equal_simplify(lorentz_eps(mu, nu, rho, sigma) * lorentz_eps(mu_co, nu_co, rho_co, sigma_co), -24); + result += check_equal_simplify(lorentz_eps(tau, nu, rho, sigma) * lorentz_eps(mu_co, nu_co, rho_co, sigma_co), -6 * delta_tensor(tau, mu_co)); return result; } @@ -129,14 +152,61 @@ static unsigned symmetry_check(void) 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; + idx i(symbol("i"), 3), j(symbol("j"), 3), k(symbol("k"), 3), l(symbol("l"), 3); + symbol A("A"), B("B"); + ex e; + + result += check_equal(indexed(A, sy_symm(), i, j), indexed(A, sy_symm(), j, i)); + result += check_equal(indexed(A, sy_anti(), i, j) + indexed(A, sy_anti(), j, i), 0); + result += check_equal(indexed(A, sy_anti(), i, j, k) - indexed(A, sy_anti(), j, k, i), 0); + e = indexed(A, sy_symm(), i, j, k) * + indexed(B, sy_anti(), l, k, i); + result += check_equal_simplify(e, 0); + e = indexed(A, sy_symm(), i, i, j, j) * + indexed(B, sy_anti(), k, l); // GiNaC 0.8.0 had a bug here + result += check_equal_simplify(e, e); + + symmetry R = sy_symm(sy_anti(0, 1), sy_anti(2, 3)); + e = indexed(A, R, i, j, k, l) + indexed(A, R, j, i, k, l); + result += check_equal(e, 0); + e = indexed(A, R, i, j, k, l) + indexed(A, R, i, j, l, k); + result += check_equal(e, 0); + e = indexed(A, R, i, j, k, l) - indexed(A, R, j, i, l, k); + result += check_equal(e, 0); + e = indexed(A, R, i, j, k, l) + indexed(A, R, k, l, j, i); + result += check_equal(e, 0); + + e = indexed(A, i, j); + result += check_equal(symmetrize(e) + antisymmetrize(e), e); + e = indexed(A, sy_symm(), i, j, k, l); + result += check_equal(symmetrize(e), e); + result += check_equal(antisymmetrize(e), 0); + e = indexed(A, sy_anti(), i, j, k, l); + result += check_equal(symmetrize(e), 0); + result += check_equal(antisymmetrize(e), e); + + return result; +} + +static unsigned scalar_product_check(void) +{ + // check scalar product replacement + + unsigned result = 0; + + idx i(symbol("i"), 3), j(symbol("j"), 3); + symbol A("A"), B("B"), C("C"); + ex e; + + scalar_products sp; + sp.add(A, B, 0); // A and B are orthogonal + sp.add(A, C, 0); // A and C are orthogonal + sp.add(A, A, 4); // A^2 = 4 (A has length 2) - 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); + e = (indexed(A + B, i) * indexed(A + C, i)).expand(expand_options::expand_indexed); + result += check_equal_simplify(e, indexed(B, i) * indexed(C, i) + 4, sp); + e = indexed(A, i, i) * indexed(B, j, j); // GiNaC 0.8.0 had a bug here + result += check_equal_simplify(e, e, sp); return result; } @@ -157,27 +227,19 @@ static unsigned edyn_check(void) // 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); + L(0, 0) = gamma; + L(0, 1) = -beta*gamma; + L(1, 0) = -beta*gamma; + L(1, 1) = gamma; + L(2, 2) = 1; L(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); + matrix F(4, 4, lst( + 0, -Ex, -Ey, -Ez, + Ex, 0, -Bz, By, + Ey, Bz, 0, -Bx, + Ez, -By, Bx, 0 + )); // Indices symbol s_mu("mu"), s_nu("nu"), s_rho("rho"), s_sigma("sigma"); @@ -185,8 +247,8 @@ static unsigned edyn_check(void) // 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(); + * 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(); @@ -207,11 +269,7 @@ static unsigned edyn_check(void) // Test 2: check energy density and Poynting vector of electromagnetic field // Minkowski metric - matrix eta(4, 4); - eta.set(0, 0, 1); - eta.set(1, 1, -1); - eta.set(2, 2, -1); - eta.set(3, 3, -1); + ex eta = diag_matrix(lst(1, -1, -1, -1)); // Covariant field tensor ex F_mu_nu = (indexed(eta, mu.toggle_variance(), rho.toggle_variance()) @@ -240,6 +298,63 @@ static unsigned edyn_check(void) return result; } +static unsigned spinor_check(void) +{ + // check identities of the spinor metric + + unsigned result = 0; + + symbol psi("psi"); + spinidx A(symbol("A"), 2), B(symbol("B"), 2), C(symbol("C"), 2); + ex A_co = A.toggle_variance(), B_co = B.toggle_variance(); + ex e; + + e = spinor_metric(A_co, B_co) * spinor_metric(A, B); + result += check_equal_simplify(e, 2); + e = spinor_metric(A_co, B_co) * spinor_metric(B, A); + result += check_equal_simplify(e, -2); + e = spinor_metric(A_co, B_co) * spinor_metric(A, C); + result += check_equal_simplify(e, delta_tensor(B_co, C)); + e = spinor_metric(A_co, B_co) * spinor_metric(B, C); + result += check_equal_simplify(e, -delta_tensor(A_co, C)); + e = spinor_metric(A_co, B_co) * spinor_metric(C, A); + result += check_equal_simplify(e, -delta_tensor(B_co, C)); + e = spinor_metric(A, B) * indexed(psi, B_co); + result += check_equal_simplify(e, indexed(psi, A)); + e = spinor_metric(A, B) * indexed(psi, A_co); + result += check_equal_simplify(e, -indexed(psi, B)); + e = spinor_metric(A_co, B_co) * indexed(psi, B); + result += check_equal_simplify(e, -indexed(psi, A_co)); + e = spinor_metric(A_co, B_co) * indexed(psi, A); + result += check_equal_simplify(e, indexed(psi, B_co)); + + return result; +} + +static unsigned dummy_check(void) +{ + // check dummy index renaming + + unsigned result = 0; + + symbol p("p"), q("q"); + idx i(symbol("i"), 3), j(symbol("j"), 3), n(symbol("n"), 3); + varidx mu(symbol("mu"), 4), nu(symbol("nu"), 4); + ex e; + + e = indexed(p, i) * indexed(q, i) - indexed(p, j) * indexed(q, j); + result += check_equal_simplify(e, 0); + + e = indexed(p, i) * indexed(p, i) * indexed(q, j) * indexed(q, j) + - indexed(p, n) * indexed(p, n) * indexed(q, j) * indexed(q, j); + result += check_equal_simplify(e, 0); + + e = indexed(p, mu, mu.toggle_variance()) - indexed(p, nu, nu.toggle_variance()); + result += check_equal_simplify(e, 0); + + return result; +} + unsigned exam_indexed(void) { unsigned result = 0; @@ -251,7 +366,10 @@ unsigned exam_indexed(void) result += metric_check(); cout << '.' << flush; result += epsilon_check(); cout << '.' << flush; result += symmetry_check(); cout << '.' << flush; + result += scalar_product_check(); cout << '.' << flush; result += edyn_check(); cout << '.' << flush; + result += spinor_check(); cout << '.' << flush; + result += dummy_check(); cout << '.' << flush; if (!result) { cout << " passed " << endl;