Skip to content

dq.norm

norm(x: QArrayLike, *, psd: bool = True) -> Array

Returns the norm of a ket, bra, density matrix, or Hermitian matrix.

For a ket or a bra, the returned norm is \(\sqrt{\braket{\psi|\psi}}\). For a Hermitian matrix, the returned norm is the trace norm defined by: $$ \|A\|_1 = \tr{\sqrt{A^\dag A}} = \sum_i |\lambda_i| $$ where \(\lambda_i\) are the eigenvalues of \(A\). If \(A\) is positive semi-definite (set psd=True), for example for a density matrix, the expression reduces to \(\|A\|_1 =\tr{A}\).

Parameters

  • x (qarray-like of shape (..., n, 1) or (..., 1, n) or (..., n, n)) –

    Ket, bra, density matrix, or Hermitian matrix.

  • psd –

    Whether x is a positive semi-definite matrix. If True, returns the trace of x, otherwise computes the eigenvalues of x to evaluate the norm.

Returns

(array of shape (...)) Real-valued norm of x.

See also
  • dq.unit(): normalize a ket, bra, density matrix, or Hermitian matrix to unit norm.

Examples

For a ket:

>>> psi = dq.fock(4, 0) + dq.fock(4, 1)
>>> dq.norm(psi)
Array(1.414, dtype=float32)

For a density matrix:

>>> rho = dq.fock_dm(4, 0) + dq.fock_dm(4, 1) + dq.fock_dm(4, 2)
>>> dq.norm(rho)
Array(3., dtype=float32)