Skip to content

dq.hadamard

hadamard(n: int = 1) -> QArray

Returns the Hadamard transform on \(n\) qubits.

For a single qubit, it is defined by $$ H = \frac{1}{\sqrt2} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} $$ For \(n\) qubits, it is defined by the tensor product of Hadamard matrices: $$ H_n = \bigotimes_{k=1}^n H $$

Parameters

  • n –

    Number of qubits to act on.

Returns

(qarray of shape (2^n, 2^n)) Hadamard transform operator.

Examples

>>> dq.hadamard()
QArray: shape=(2, 2), dims=(2,), dtype=complex64, layout=dense
[[ 0.707+0.j  0.707+0.j]
 [ 0.707+0.j -0.707+0.j]]
>>> dq.hadamard(2)
QArray: shape=(4, 4), dims=(2, 2), dtype=complex64, layout=dense
[[ 0.5+0.j  0.5+0.j  0.5+0.j  0.5+0.j]
 [ 0.5+0.j -0.5+0.j  0.5+0.j -0.5+0.j]
 [ 0.5+0.j  0.5+0.j -0.5+0.j -0.5+0.j]
 [ 0.5+0.j -0.5+0.j -0.5+0.j  0.5-0.j]]