def _compute_bitstrings_contribution_to_purity(bitstrings: npt.NDArray[np.int8]) -> float:
    """Computes the contribution to the purity of the bitstrings.
    Args:
        bitstrings: The bitstrings measured using the same unitary operators
    Returns: The purity of the bitstring
    """

    bitstrings, probs = _bitstrings_to_probs(bitstrings)
    product_iterator = cast(
        Iterator[
            tuple[
                tuple[npt.NDArray[np.int8], npt.NDArray[Any]],
                tuple[npt.NDArray[np.int8], npt.NDArray[Any]],
            ]
        ],
        product(zip(bitstrings, probs), repeat=2),
    )
    purity = 0
    for (s, p), (s_prime, p_prime) in product_iterator:
        purity += (-2.0) ** float(-_get_hamming_distance(s, s_prime)) * p * p_prime

    return purity * 2 ** (bitstrings.shape[-1])
Computes the contribution to the purity of the bitstrings.
    Args:
        bitstrings: The bitstrings measured using the same unitary operators
    Returns: The purity of the bitstring
    
cirq-core/cirq/qis/entropy.py