def hyperdeterminant(state):
    """Hyperdeterminant of any quantum state
        Args:
            state (cplx array): three-qubit random state
        Returns:
            Hyperdeterminant
    """
    indices = [(1, [(0, 0, 7, 7), (1, 1, 6, 6), (2, 2, 5, 5), (3, 3, 4, 4)]),
               (-2, [(0, 7, 3, 4), (0, 7, 5, 2), (0, 7, 6, 1), (3, 4, 5, 2), (3, 4, 6, 1), (5, 2, 6, 1)]),
               (4, [(0, 6, 5, 3), (7, 1, 2, 4)])]
    hyp = sum(coeff * sum(state[i] * state[j] * state[k] * state[l] for i, j, k, l in ids)
              for coeff, ids in indices)

    return hyp