commutes(v1: Any, v2: Any, *, atol: Union[int, float] = 1e-08, default: TDefault = array(, dtype=float64)) → Union[bool, TDefault]¶
Determines whether two values commute.
This is determined by any one of the following techniques:
If none of these techniques succeeds, the commutativity is assumed to beindeterminate.
Either value has a
_commutes_method that returns ‘True’, ‘False’, or ‘None’ (meaning indeterminate). If both methods either don’t exist or return
NotImplementedthen another strategy is tried.
v1._commutes_is tried before
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.Operationinstances. 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).
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.
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.
- Return type
TypeError – The commutativity of v1 and v2 is indeterminate, or could
not be determined, and the default argument was not specified. –