dq.overlap
overlap(x: ArrayLike, y: ArrayLike) -> Array
Returns the overlap between two quantum states.
The overlap is computed
- as \(\lvert\braket{\psi|\varphi}\rvert^2\) if both arguments are kets \(\ket\psi\) and \(\ket\varphi\),
- as \(\lvert\bra\psi \rho \ket\psi\rvert\) if one argument is a ket \(\ket\psi\) and the other is a density matrix \(\rho\),
- as \(\tr{\rho^\dag\sigma}\) if both arguments are density matrices \(\rho\) and \(\sigma\).
Parameters
-
x
(array_like of shape (..., n, 1) or (..., n, n))
–
Ket or density matrix.
-
y
(array_like of shape (..., n, 1) or (..., n, n))
–
Ket or density matrix.
Returns
(array of shape (...)) Real-valued overlap.
Examples
>>> fock0 = dq.fock(3, 0)
>>> dq.overlap(fock0, fock0)
Array(1., dtype=float32)
>>> fock01_dm = 0.5 * (dq.fock_dm(3, 0) + dq.fock_dm(3, 1))
>>> dq.overlap(fock0, fock01_dm)
Array(0.5, dtype=float32)