def pauli_product_phase(x1: bool, z1: bool, x2: bool, z2: bool) -> int:
    """Determines the power of i in the product of two Paulis.

    For example, X*Y = iZ and so this method would return +1 for X and Y.

    The input Paulis are encoded into the following form:

        x z | Pauli
        ----+-------
        0 0 | I
        1 0 | X
        1 1 | Y
        0 1 | Z
    """
    # Analyze by case over first gate.

    if x1 and z1:  # Y gate.
        # No phase for YI = Y
        # -1 phase for YX = -iZ
        # No phase for YY = I
        # +1 phase for YZ = +iX
        return int(z2) - int(x2)

    if x1:  # X gate.
        # No phase for XI = X
        # No phase for XX = I
        # +1 phase for XY = iZ
        # -1 phase for XZ = -iY
        return z2 and 2*int(x2) - 1

    if z1:  # Z gate.
        # No phase for ZI = Z
        # +1 phase for ZX = -iY
        # -1 phase for ZY = iX
        # No phase for ZZ = I
        return x2 and 1 - 2*int(z2)

    # Identity gate.
    return 0