def commutes(
    v1: Any, v2: Any, *, atol: float = 1e-8, default: Any = RaiseTypeErrorIfNotProvided
) -> Any:
    """Determines whether two values commute.

    This is determined by any one of the following techniques:

    - Either value has a `_commutes_` method that returns 'True', 'False', or
        'None' (meaning indeterminate). If both methods either don't exist or
        return `NotImplemented` then another strategy is tried. `v1._commutes_`
        is tried before `v2._commutes_`.
    - Both values are matrices. The return value is determined by checking if
        v1 @ v2 - v2 @ v1 is sufficiently close to zero.
    - Both values are `cirq.Operation` instances. If the operations apply to
        disjoint qubit sets then they commute. Otherwise, if they have unitary
        matrices, those matrices are checked for commutativity (while accounting
        for the fact that the operations may have different qubit orders or only
        partially overlap).

    If none of these techniques succeeds, the commutativity is assumed to be
    indeterminate.

    Args:
        v1: One of the values to check for commutativity. Can be a cirq object
            such as an operation, or a numpy matrix.
        v2: The other value to check for commutativity. Can be a cirq object
            such as an operation, or a numpy matrix.
        default: A fallback value to return, instead of raising a ValueError, if
            it is indeterminate whether or not the two values commute.
        atol: Absolute error tolerance. If all entries in v1@v2 - v2@v1 have a
            magnitude less than this tolerance, v1 and v2 can be reported as
            commuting. Defaults to 1e-8.

    Returns:
        True: `v1` and `v2` commute (or approximately commute).
        False: `v1` and `v2` don't commute.
        default: The commutativity of `v1` and `v2` is indeterminate, or could
        not be determined, and the `default` argument was specified.

    Raises:
        TypeError: The commutativity of `v1` and `v2` is indeterminate, or could
        not be determined, and the `default` argument was not specified.
    """
    atol = float(atol)

    strats = [_strat_commutes_from_commutes, _strat_commutes_from_matrix]
    for strat in strats:
        result = strat(v1, v2, atol=atol)
        if result is None:
            break
        if result is not NotImplemented:
            return result
    if default is not RaiseTypeErrorIfNotProvided:
        return default
    raise TypeError(
        f"Failed to determine whether or not "
        f"{v1!r} commutes with {v2!r}. "
        f"The result may be indeterminate, or there may be no strategy "
        f"implemented to handle this case.\n"
        f"If you want a default result in this case, specify a `default=` "
        f"argument or use `cirq.definitely_commutes`."
    )
Determines whether two values commute.

    This is determined by any one of the following techniques:

    - Either value has a `_commutes_` method that returns 'True', 'False', or
        'None' (meaning indeterminate). If both methods either don't exist or
        return `NotImplemented` then another strategy is tried. `v1._commutes_`
        is tried before `v2._commutes_`.
    - Both values are matrices. The return value is determined by checking if
        v1 @ v2 - v2 @ v1 is sufficiently close to zero.
    - Both values are `cirq.Operation` instances. If the operations apply to
        disjoint qubit sets then they commute. Otherwise, if they have unitary
        matrices, those matrices are checked for commutativity (while accounting
        for the fact that the operations may have different qubit orders or only
        partially overlap).

    If none of these techniques succeeds, the commutativity is assumed to be
    indeterminate.

    Args:
        v1: One of the values to check for commutativity. Can be a cirq object
            such as an operation, or a numpy matrix.
        v2: The other value to check for commutativity. Can be a cirq object
            such as an operation, or a numpy matrix.
        default: A fallback value to return, instead of raising a ValueError, if
            it is indeterminate whether or not the two values commute.
        atol: Absolute error tolerance. If all entries in v1@v2 - v2@v1 have a
            magnitude less than this tolerance, v1 and v2 can be reported as
            commuting. Defaults to 1e-8.

    Returns:
        True: `v1` and `v2` commute (or approximately commute).
        False: `v1` and `v2` don't commute.
        default: The commutativity of `v1` and `v2` is indeterminate, or could
        not be determined, and the `default` argument was specified.

    Raises:
        TypeError: The commutativity of `v1` and `v2` is indeterminate, or could
        not be determined, and the `default` argument was not specified.
    
cirq-core/cirq/protocols/commutes_protocol.py