def factor_state_vector(
    t: np.ndarray, axes: Sequence[int], *, validate=True, atol=1e-07
) -> tuple[np.ndarray, np.ndarray]:
    """Factors a state vector into two independent state vectors.

    This function should only be called on state vectors that are known to be
    separable, such as immediately after a measurement or reset operation. It
    does not verify that the provided state vector is indeed separable, and
    will return nonsense results for vectors representing entangled states.

    Args:
        t: The state vector to factor.
        axes: The axes to factor out.
        validate: Perform a validation that the density matrix factors cleanly.
        atol: The absolute tolerance for the validation.

    Returns:
        A tuple with the `(extracted, remainder)` state vectors, where
        `extracted` means the sub-state vector which corresponds to the axes
        requested, and with the axes in the requested order, and where
        `remainder` means the sub-state vector on the remaining axes, in the
        same order as the original state vector.

    Raises:
        EntangledStateError: If the tensor is already in entangled state, and
            the validate flag is set.
        ValueError: If the tensor factorization fails for any other reason.
    """
    n_axes = len(axes)
    t1 = np.moveaxis(t, axes, range(n_axes))
    pivot = np.unravel_index(np.abs(t1).argmax(), t1.shape)
    slices1 = (slice(None),) * n_axes + pivot[n_axes:]
    slices2 = pivot[:n_axes] + (slice(None),) * (t1.ndim - n_axes)
    extracted = t1[slices1]
    extracted = extracted / np.linalg.norm(extracted)
    remainder = t1[slices2]
    remainder = remainder / (np.linalg.norm(remainder) * t1[pivot] / abs(t1[pivot]))
    if validate:
        t2 = state_vector_kronecker_product(extracted, remainder)
        if not np.allclose(t2, t1, atol=atol):
            if not np.isclose(np.linalg.norm(t1), 1):
                raise ValueError('Input state must be normalized.')
            raise EntangledStateError('The tensor cannot be factored by the requested axes')
    return extracted, remainder
Factors a state vector into two independent state vectors.

    This function should only be called on state vectors that are known to be
    separable, such as immediately after a measurement or reset operation. It
    does not verify that the provided state vector is indeed separable, and
    will return nonsense results for vectors representing entangled states.

    Args:
        t: The state vector to factor.
        axes: The axes to factor out.
        validate: Perform a validation that the density matrix factors cleanly.
        atol: The absolute tolerance for the validation.

    Returns:
        A tuple with the `(extracted, remainder)` state vectors, where
        `extracted` means the sub-state vector which corresponds to the axes
        requested, and with the axes in the requested order, and where
        `remainder` means the sub-state vector on the remaining axes, in the
        same order as the original state vector.

    Raises:
        EntangledStateError: If the tensor is already in entangled state, and
            the validate flag is set.
        ValueError: If the tensor factorization fails for any other reason.
    
cirq-core/cirq/linalg/transformations.py