# 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    Returns
    31    -------
    32    elem : int
    33        Element (i,j,k) of the epsilon tensor of rank 3
    34    """
    35    test_set = set((i, j, k))
    36    if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))):
    37        raise Exception("Unexpected input", i, j, k)
    38
    39    return (i - j) * (j - k) * (k - i) / 2
    40
    41
    42def epsilon_tensor_rank4(i, j, k, o):
    43    """Rank-4 epsilon tensor
    44
    45    Extension of https://codegolf.stackexchange.com/a/160375
    46
    47
    48    Returns
    49    -------
    50    elem : int
    51        Element (i,j,k,o) of the epsilon tensor of rank 4
    52    """
    53    test_set = set((i, j, k, o))
    54    if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
    55        raise Exception("Unexpected input", i, j, k, o)
    56
    57    return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12
    58
    59
    60def Grid_gamma(gamma_tag):
    61    """Returns gamma matrix in Grid labeling."""
    62    if gamma_tag == 'Identity':
    63        g = identity
    64    elif gamma_tag == 'Gamma5':
    65        g = gamma5
    66    elif gamma_tag == 'GammaX':
    67        g = gamma[0]
    68    elif gamma_tag == 'GammaY':
    69        g = gamma[1]
    70    elif gamma_tag == 'GammaZ':
    71        g = gamma[2]
    72    elif gamma_tag == 'GammaT':
    73        g = gamma[3]
    74    elif gamma_tag == 'GammaXGamma5':
    75        g = gamma[0] @ gamma5
    76    elif gamma_tag == 'GammaYGamma5':
    77        g = gamma[1] @ gamma5
    78    elif gamma_tag == 'GammaZGamma5':
    79        g = gamma[2] @ gamma5
    80    elif gamma_tag == 'GammaTGamma5':
    81        g = gamma[3] @ gamma5
    82    elif gamma_tag == 'SigmaXT':
    83        g = 0.5 * (gamma[0] @ gamma[3] - gamma[3] @ gamma[0])
    84    elif gamma_tag == 'SigmaXY':
    85        g = 0.5 * (gamma[0] @ gamma[1] - gamma[1] @ gamma[0])
    86    elif gamma_tag == 'SigmaXZ':
    87        g = 0.5 * (gamma[0] @ gamma[2] - gamma[2] @ gamma[0])
    88    elif gamma_tag == 'SigmaYT':
    89        g = 0.5 * (gamma[1] @ gamma[3] - gamma[3] @ gamma[1])
    90    elif gamma_tag == 'SigmaYZ':
    91        g = 0.5 * (gamma[1] @ gamma[2] - gamma[2] @ gamma[1])
    92    elif gamma_tag == 'SigmaZT':
    93        g = 0.5 * (gamma[2] @ gamma[3] - gamma[3] @ gamma[2])
    94    else:
    95        raise Exception('Unkown gamma structure', gamma_tag)
    96    return g

gammaX = array([[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+1.j], [ 0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j], [ 0.+0.j, -0.-1.j, 0.+0.j, 0.+0.j], [-0.-1.j, 0.+0.j, 0.+0.j, 0.+0.j]])
gammaY = array([[ 0.+0.j,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j, 0.+0.j, 0.+0.j], [ 0.+0.j, 0.+0.j, -1.+0.j, 0.+0.j], [ 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j]])
identity = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
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    Returns
    32    -------
    33    elem : int
    34        Element (i,j,k) of the epsilon tensor of rank 3
    35    """
    36    test_set = set((i, j, k))
    37    if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))):
    38        raise Exception("Unexpected input", i, j, k)
    39
    40    return (i - j) * (j - k) * (k - i) / 2

Rank-3 epsilon tensor

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

###### Returns

- elem (int): Element (i,j,k) of the epsilon tensor of rank 3

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

    43def epsilon_tensor_rank4(i, j, k, o):
    44    """Rank-4 epsilon tensor
    45
    46    Extension of https://codegolf.stackexchange.com/a/160375
    47
    48
    49    Returns
    50    -------
    51    elem : int
    52        Element (i,j,k,o) of the epsilon tensor of rank 4
    53    """
    54    test_set = set((i, j, k, o))
    55    if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
    56        raise Exception("Unexpected input", i, j, k, o)
    57
    58    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

###### Returns

- elem (int): Element (i,j,k,o) of the epsilon tensor of rank 4

def Grid_gamma(gamma_tag): View Source

    61def Grid_gamma(gamma_tag):
    62    """Returns gamma matrix in Grid labeling."""
    63    if gamma_tag == 'Identity':
    64        g = identity
    65    elif gamma_tag == 'Gamma5':
    66        g = gamma5
    67    elif gamma_tag == 'GammaX':
    68        g = gamma[0]
    69    elif gamma_tag == 'GammaY':
    70        g = gamma[1]
    71    elif gamma_tag == 'GammaZ':
    72        g = gamma[2]
    73    elif gamma_tag == 'GammaT':
    74        g = gamma[3]
    75    elif gamma_tag == 'GammaXGamma5':
    76        g = gamma[0] @ gamma5
    77    elif gamma_tag == 'GammaYGamma5':
    78        g = gamma[1] @ gamma5
    79    elif gamma_tag == 'GammaZGamma5':
    80        g = gamma[2] @ gamma5
    81    elif gamma_tag == 'GammaTGamma5':
    82        g = gamma[3] @ gamma5
    83    elif gamma_tag == 'SigmaXT':
    84        g = 0.5 * (gamma[0] @ gamma[3] - gamma[3] @ gamma[0])
    85    elif gamma_tag == 'SigmaXY':
    86        g = 0.5 * (gamma[0] @ gamma[1] - gamma[1] @ gamma[0])
    87    elif gamma_tag == 'SigmaXZ':
    88        g = 0.5 * (gamma[0] @ gamma[2] - gamma[2] @ gamma[0])
    89    elif gamma_tag == 'SigmaYT':
    90        g = 0.5 * (gamma[1] @ gamma[3] - gamma[3] @ gamma[1])
    91    elif gamma_tag == 'SigmaYZ':
    92        g = 0.5 * (gamma[1] @ gamma[2] - gamma[2] @ gamma[1])
    93    elif gamma_tag == 'SigmaZT':
    94        g = 0.5 * (gamma[2] @ gamma[3] - gamma[3] @ gamma[2])
    95    else:
    96        raise Exception('Unkown gamma structure', gamma_tag)
    97    return g

Returns gamma matrix in Grid labeling.