# pyerrors.dirac

View Source

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

def epsilon_tensor(i, j, k):
View Source

    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

Rank-3 epsilon tensor

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

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

    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

Rank-4 epsilon tensor

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

def Grid_gamma(gamma_tag):
View Source

    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

Returns gamma matrix in Grid labeling.