# pyerrors.dirac API documentation

# pyerrors.dirac

View Source

     1import numpy as np
     2
     3
     4gammaX = np.array(
     5    [[0, 0, 0, 1j], [0, 0, 1j, 0], [0, -1j, 0, 0], [-1j, 0, 0, 0]],
     6    dtype=complex)
     7gammaY = np.array(
     8    [[0, 0, 0, -1], [0, 0, 1, 0], [0, 1, 0, 0], [-1, 0, 0, 0]],
     9    dtype=complex)
    10gammaZ = np.array(
    11    [[0, 0, 1j, 0], [0, 0, 0, -1j], [-1j, 0, 0, 0], [0, 1j, 0, 0]],
    12    dtype=complex)
    13gammaT = np.array(
    14    [[0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0]],
    15    dtype=complex)
    16gamma = np.array([gammaX, gammaY, gammaZ, gammaT])
    17gamma5 = np.array(
    18    [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, -1]],
    19    dtype=complex)
    20identity = np.array(
    21    [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],
    22    dtype=complex)
    23
    24
    25def epsilon_tensor(i, j, k):
    26    """Rank-3 epsilon tensor
    27
    28    Based on https://codegolf.stackexchange.com/a/160375
    29    """
    30    test_set = set((i, j, k))
    31    if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))):
    32        raise Exception("Unexpected input", i, j, k)
    33
    34    return (i - j) * (j - k) * (k - i) / 2
    35
    36
    37def epsilon_tensor_rank4(i, j, k, o):
    38    """Rank-4 epsilon tensor
    39
    40    Extension of https://codegolf.stackexchange.com/a/160375
    41    """
    42    test_set = set((i, j, k, o))
    43    if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
    44        raise Exception("Unexpected input", i, j, k, o)
    45
    46    return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12
    47
    48
    49def Grid_gamma(gamma_tag):
    50    """Returns gamma matrix in Grid labeling."""
    51    if gamma_tag == 'Identity':
    52        g = identity
    53    elif gamma_tag == 'Gamma5':
    54        g = gamma5
    55    elif gamma_tag == 'GammaX':
    56        g = gamma[0]
    57    elif gamma_tag == 'GammaY':
    58        g = gamma[1]
    59    elif gamma_tag == 'GammaZ':
    60        g = gamma[2]
    61    elif gamma_tag == 'GammaT':
    62        g = gamma[3]
    63    elif gamma_tag == 'GammaXGamma5':
    64        g = gamma[0] @ gamma5
    65    elif gamma_tag == 'GammaYGamma5':
    66        g = gamma[1] @ gamma5
    67    elif gamma_tag == 'GammaZGamma5':
    68        g = gamma[2] @ gamma5
    69    elif gamma_tag == 'GammaTGamma5':
    70        g = gamma[3] @ gamma5
    71    elif gamma_tag == 'SigmaXT':
    72        g = 0.5 * (gamma[0] @ gamma[3] - gamma[3] @ gamma[0])
    73    elif gamma_tag == 'SigmaXY':
    74        g = 0.5 * (gamma[0] @ gamma[1] - gamma[1] @ gamma[0])
    75    elif gamma_tag == 'SigmaXZ':
    76        g = 0.5 * (gamma[0] @ gamma[2] - gamma[2] @ gamma[0])
    77    elif gamma_tag == 'SigmaYT':
    78        g = 0.5 * (gamma[1] @ gamma[3] - gamma[3] @ gamma[1])
    79    elif gamma_tag == 'SigmaYZ':
    80        g = 0.5 * (gamma[1] @ gamma[2] - gamma[2] @ gamma[1])
    81    elif gamma_tag == 'SigmaZT':
    82        g = 0.5 * (gamma[2] @ gamma[3] - gamma[3] @ gamma[2])
    83    else:
    84        raise Exception('Unkown gamma structure', gamma_tag)
    85    return g

def epsilon_tensor(i, j, k) View Source

    26def epsilon_tensor(i, j, k):
    27    """Rank-3 epsilon tensor
    28
    29    Based on https://codegolf.stackexchange.com/a/160375
    30    """
    31    test_set = set((i, j, k))
    32    if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))):
    33        raise Exception("Unexpected input", i, j, k)
    34
    35    return (i - j) * (j - k) * (k - i) / 2

Rank-3 epsilon tensor

Based on https://codegolf.stackexchange.com/a/160375

def epsilon_tensor_rank4(i, j, k, o) View Source

    38def epsilon_tensor_rank4(i, j, k, o):
    39    """Rank-4 epsilon tensor
    40
    41    Extension of https://codegolf.stackexchange.com/a/160375
    42    """
    43    test_set = set((i, j, k, o))
    44    if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
    45        raise Exception("Unexpected input", i, j, k, o)
    46
    47    return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12

Rank-4 epsilon tensor

Extension of https://codegolf.stackexchange.com/a/160375

def Grid_gamma(gamma_tag) View Source

    50def Grid_gamma(gamma_tag):
    51    """Returns gamma matrix in Grid labeling."""
    52    if gamma_tag == 'Identity':
    53        g = identity
    54    elif gamma_tag == 'Gamma5':
    55        g = gamma5
    56    elif gamma_tag == 'GammaX':
    57        g = gamma[0]
    58    elif gamma_tag == 'GammaY':
    59        g = gamma[1]
    60    elif gamma_tag == 'GammaZ':
    61        g = gamma[2]
    62    elif gamma_tag == 'GammaT':
    63        g = gamma[3]
    64    elif gamma_tag == 'GammaXGamma5':
    65        g = gamma[0] @ gamma5
    66    elif gamma_tag == 'GammaYGamma5':
    67        g = gamma[1] @ gamma5
    68    elif gamma_tag == 'GammaZGamma5':
    69        g = gamma[2] @ gamma5
    70    elif gamma_tag == 'GammaTGamma5':
    71        g = gamma[3] @ gamma5
    72    elif gamma_tag == 'SigmaXT':
    73        g = 0.5 * (gamma[0] @ gamma[3] - gamma[3] @ gamma[0])
    74    elif gamma_tag == 'SigmaXY':
    75        g = 0.5 * (gamma[0] @ gamma[1] - gamma[1] @ gamma[0])
    76    elif gamma_tag == 'SigmaXZ':
    77        g = 0.5 * (gamma[0] @ gamma[2] - gamma[2] @ gamma[0])
    78    elif gamma_tag == 'SigmaYT':
    79        g = 0.5 * (gamma[1] @ gamma[3] - gamma[3] @ gamma[1])
    80    elif gamma_tag == 'SigmaYZ':
    81        g = 0.5 * (gamma[1] @ gamma[2] - gamma[2] @ gamma[1])
    82    elif gamma_tag == 'SigmaZT':
    83        g = 0.5 * (gamma[2] @ gamma[3] - gamma[3] @ gamma[2])
    84    else:
    85        raise Exception('Unkown gamma structure', gamma_tag)
    86    return g

Returns gamma matrix in Grid labeling.