From c8cb0e4cb81ce28d24973693a96a5db2281a6e28 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 23 Dec 2021 12:00:10 +0100 Subject: [PATCH] feat: epsilon tensors moved to dirac submodule, tests added --- pyerrors/dirac.py | 24 ++++++++++++++++++++++++ pyerrors/input/hadrons.py | 12 ------------ tests/dirac_test.py | 12 ++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/pyerrors/dirac.py b/pyerrors/dirac.py index f5350b94..7f68cb22 100644 --- a/pyerrors/dirac.py +++ b/pyerrors/dirac.py @@ -22,6 +22,30 @@ identity = np.array( dtype=complex) +def epsilon_tensor(i, j, k): + """Rank-3 epsilon tensor + + Based on https://codegolf.stackexchange.com/a/160375 + """ + test_set = set((i, j, k)) + if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))): + raise Exception("Unexpected input", i, j, k) + + return (i - j) * (j - k) * (k - i) / 2 + + +def epsilon_tensor_rank4(i, j, k, o): + """Rank-4 epsilon tensor + + Extension of https://codegolf.stackexchange.com/a/160375 + """ + test_set = set((i, j, k, o)) + if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))): + raise Exception("Unexpected input", i, j, k, o) + + return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12 + + def Grid_gamma(gamma_tag): """Returns gamma matrix in Grid labeling.""" if gamma_tag == 'Identity': diff --git a/pyerrors/input/hadrons.py b/pyerrors/input/hadrons.py index e139f2b2..efe4feb1 100644 --- a/pyerrors/input/hadrons.py +++ b/pyerrors/input/hadrons.py @@ -298,18 +298,6 @@ def read_Fourquark_hd5(path, filestem, ens_id, idl=None, vertices=["VA", "AV"]): return result_dict -def _epsilon_tensor(i, j, k, o): - """Rank-4 epsilon tensor - - Extension of https://codegolf.stackexchange.com/a/160375 - """ - test_set = set((i, j, k, o)) - if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))): - raise Exception("Unexpected input", i, j, k, o) - - return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12 - - def _get_lorentz_names(name): assert len(name) == 2 diff --git a/tests/dirac_test.py b/tests/dirac_test.py index 0a2c0379..f36017a6 100644 --- a/tests/dirac_test.py +++ b/tests/dirac_test.py @@ -32,3 +32,15 @@ def test_grid_dirac(): pe.dirac.Grid_gamma(gamma) with pytest.raises(Exception): pe.dirac.Grid_gamma('Not a gamma matrix') + + +def test_epsilon_tensor(): + check = {(1, 2, 3) : 1.0, + (3, 1, 2) : 1.0, + (2, 3, 1) : 1.0, + (1, 1, 1) : 0.0, + (3, 2, 1) : -1.0, + (1, 3, 2) : -1.0, + (1, 1, 3) : 0.0} + for key, value in check.items(): + assert pe.dirac.epsilon_tensor(*key) == value