X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=check%2Fexam_indexed.cpp;h=96f6faa2e4157f4f64bb8a0b2b472e013e434a95;hb=4f71d7035d32e8f74d9b13e0d6a9c0ab4a58062d;hp=90197c082014cafbbe70767d92aa5ff77b70b8bf;hpb=e7cc6a764ff67b5885d6633385fac23ccc1dc9a7;p=ginac.git diff --git a/check/exam_indexed.cpp b/check/exam_indexed.cpp index 90197c08..96f6faa2 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-2002 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2020 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 @@ -17,10 +17,14 @@ * * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "exams.h" +#include "ginac.h" +using namespace GiNaC; + +#include +using namespace std; static unsigned check_equal(const ex &e1, const ex &e2) { @@ -55,7 +59,7 @@ static unsigned check_equal_simplify(const ex &e1, const ex &e2, const scalar_pr return 0; } -static unsigned delta_check(void) +static unsigned delta_check() { // checks identities of the delta tensor @@ -81,7 +85,7 @@ static unsigned delta_check(void) return result; } -static unsigned metric_check(void) +static unsigned metric_check() { // checks identities of the metric tensor @@ -114,7 +118,7 @@ static unsigned metric_check(void) return result; } -static unsigned epsilon_check(void) +static unsigned epsilon_check() { // checks identities of the epsilon tensor @@ -136,8 +140,10 @@ static unsigned epsilon_check(void) // 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); + result += check_equal_simplify(lorentz_eps(mu, nu, rho, sigma) * indexed(d, mu_co) * indexed(d, nu_co), 0); + result += check_equal_simplify(lorentz_eps(mu_co, nu, rho, sigma) * indexed(d, mu) * indexed(d, nu_co), 0); + ex e = lorentz_eps(mu, nu, rho, sigma) * indexed(d, mu_co) - lorentz_eps(mu_co, nu, rho, sigma) * indexed(d, mu); + result += check_equal_simplify(e, 0); // 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); @@ -146,14 +152,19 @@ static unsigned epsilon_check(void) return result; } -static unsigned symmetry_check(void) +DECLARE_FUNCTION_2P(symm_fcn) +REGISTER_FUNCTION(symm_fcn, set_symmetry(sy_symm(0, 1))); +DECLARE_FUNCTION_2P(anti_fcn) +REGISTER_FUNCTION(anti_fcn, set_symmetry(sy_anti(0, 1))); + +static unsigned symmetry_check() { // check symmetric/antisymmetric objects unsigned result = 0; idx i(symbol("i"), 3), j(symbol("j"), 3), k(symbol("k"), 3), l(symbol("l"), 3); - symbol A("A"), B("B"); + symbol A("A"), B("B"), C("C"); ex e; result += check_equal(indexed(A, sy_symm(), i, j), indexed(A, sy_symm(), j, i)); @@ -185,10 +196,17 @@ static unsigned symmetry_check(void) result += check_equal(symmetrize(e), 0); result += check_equal(antisymmetrize(e), e); + e = (indexed(A, sy_anti(), i, j, k, l) * (indexed(B, j) * indexed(C, k) + indexed(B, k) * indexed(C, j)) + indexed(B, i, l)).expand(); + result += check_equal_simplify(e, indexed(B, i, l)); + + result += check_equal(symm_fcn(0, 1) + symm_fcn(1, 0), 2*symm_fcn(0, 1)); + result += check_equal(anti_fcn(0, 1) + anti_fcn(1, 0), 0); + result += check_equal(anti_fcn(0, 0), 0); + return result; } -static unsigned scalar_product_check(void) +static unsigned scalar_product_check() { // check scalar product replacement @@ -211,7 +229,7 @@ static unsigned scalar_product_check(void) return result; } -static unsigned edyn_check(void) +static unsigned edyn_check() { // Relativistic electrodynamics @@ -226,20 +244,16 @@ static unsigned edyn_check(void) symbol Bx("Bx"), By("By"), Bz("Bz"); // Lorentz transformation matrix (boost along x axis) - matrix L(4, 4); - 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; + matrix L = {{ gamma, -beta*gamma, 0, 0}, + {-beta*gamma, gamma, 0, 0}, + { 0, 0, 1, 0}, + { 0, 0, 0, 1}}; // Electromagnetic field tensor - matrix F(4, 4, lst( - 0, -Ex, -Ey, -Ez, - Ex, 0, -Bz, By, - Ey, Bz, 0, -Bx, - Ez, -By, Bx, 0 - )); + matrix F = {{ 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"); @@ -251,12 +265,12 @@ static unsigned edyn_check(void) * 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(); + 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); @@ -269,7 +283,7 @@ static unsigned edyn_check(void) // Test 2: check energy density and Poynting vector of electromagnetic field // Minkowski metric - ex eta = diag_matrix(lst(1, -1, -1, -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()) @@ -278,16 +292,16 @@ static unsigned edyn_check(void) // Energy-momentum tensor ex T = (-indexed(eta, rho, sigma) * F_mu_nu.subs(s_nu == s_rho) - * F_mu_nu.subs(lst(s_mu == s_nu, s_nu == s_sigma)) + * F_mu_nu.subs(lst{s_mu == s_nu, s_nu == s_sigma}) + indexed(eta, mu.toggle_variance(), nu.toggle_variance()) - * F_mu_nu.subs(lst(s_mu == s_rho, s_nu == s_sigma)) + * F_mu_nu.subs(lst{s_mu == s_rho, s_nu == s_sigma}) * indexed(F, rho, sigma) / 4).simplify_indexed() / (4 * Pi); // Extract energy density and Poynting vector - ex E = T.subs(lst(s_mu == 0, s_nu == 0)).normal(); - ex Px = T.subs(lst(s_mu == 0, s_nu == 1)); - ex Py = T.subs(lst(s_mu == 0, s_nu == 2)); - ex Pz = T.subs(lst(s_mu == 0, s_nu == 3)); + ex E = T.subs(lst{s_mu == 0, s_nu == 0}).normal(); + ex Px = T.subs(lst{s_mu == 0, s_nu == 1}); + ex Py = T.subs(lst{s_mu == 0, s_nu == 2}); + ex Pz = T.subs(lst{s_mu == 0, s_nu == 3}); // Check results result += check_equal(E, (Ex*Ex+Ey*Ey+Ez*Ez+Bx*Bx+By*By+Bz*Bz) / (8 * Pi)); @@ -298,14 +312,14 @@ static unsigned edyn_check(void) return result; } -static unsigned spinor_check(void) +static unsigned spinor_check() { // 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); + spinidx A(symbol("A")), B(symbol("B")), C(symbol("C")), D(symbol("D")); ex A_co = A.toggle_variance(), B_co = B.toggle_variance(); ex e; @@ -327,13 +341,15 @@ static unsigned spinor_check(void) 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)); + e = spinor_metric(D, A) * spinor_metric(A_co, B_co) * spinor_metric(B, C) - spinor_metric(D, A_co) * spinor_metric(A, B_co) * spinor_metric(B, C); + result += check_equal_simplify(e, 0); return result; } -static unsigned dummy_check(void) +static unsigned dummy_check() { - // check dummy index renaming + // check dummy index renaming/repositioning unsigned result = 0; @@ -352,15 +368,32 @@ static unsigned dummy_check(void) e = indexed(p, mu, mu.toggle_variance()) - indexed(p, nu, nu.toggle_variance()); result += check_equal_simplify(e, 0); + e = indexed(p, mu.toggle_variance(), nu, mu) * indexed(q, i) + - indexed(p, mu, nu, mu.toggle_variance()) * indexed(q, i); + result += check_equal_simplify(e, 0); + + e = indexed(p, mu, mu.toggle_variance()) - indexed(p, nu.toggle_variance(), nu); + result += check_equal_simplify(e, 0); + e = indexed(p, mu.toggle_variance(), mu) - indexed(p, nu, nu.toggle_variance()); + result += check_equal_simplify(e, 0); + + // GiNaC 1.2.1 had a bug here because p.i*p.i -> (p.i)^2 + e = indexed(p, i) * indexed(p, i) * indexed(p, j) + indexed(p, j); + ex fi = exprseq(e.get_free_indices()); + if (!fi.is_equal(exprseq{j})) { + clog << "get_free_indices(" << e << ") erroneously returned " + << fi << " instead of (.j)" << endl; + ++result; + } + return result; } -unsigned exam_indexed(void) +unsigned exam_indexed() { unsigned result = 0; cout << "examining indexed objects" << flush; - clog << "----------indexed objects:" << endl; result += delta_check(); cout << '.' << flush; result += metric_check(); cout << '.' << flush; @@ -371,12 +404,10 @@ unsigned exam_indexed(void) result += spinor_check(); cout << '.' << flush; result += dummy_check(); cout << '.' << flush; - if (!result) { - cout << " passed " << endl; - clog << "(no output)" << endl; - } else { - cout << " failed " << endl; - } - return result; } + +int main(int argc, char** argv) +{ + return exam_indexed(); +}