X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_indexed.cpp;h=10eb3d01e0b65b5dba44a18f4013cd264c918490;hp=2426430c8e4450e27a9614983046827f87e8489c;hb=ba4692d78f4412b3b072e86c2b48e8e716e82fff;hpb=8f12af23380271eebc2ac923dcbde662469c7fd7 diff --git a/check/exam_indexed.cpp b/check/exam_indexed.cpp index 2426430c..10eb3d01 100644 --- a/check/exam_indexed.cpp +++ b/check/exam_indexed.cpp @@ -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 @@ -136,14 +147,42 @@ 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, 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, indexed::symmetric, i, j, k) * + indexed(B, indexed::antisymmetric, l, k, i); + result += check_equal_simplify(e, 0); + e = indexed(A, indexed::symmetric, i, i, j, j) * + indexed(B, indexed::antisymmetric, k, l); // GiNaC 0.8.0 had a bug here + result += check_equal_simplify(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) + + 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; } @@ -235,6 +274,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; @@ -246,7 +342,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;