Skip to content

dq.hadamard

hadamard(n: int = 1) -> Array

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

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

Examples

>>> dq.hadamard()
Array([[ 0.707+0.j,  0.707+0.j],
       [ 0.707+0.j, -0.707+0.j]], dtype=complex64)
>>> dq.hadamard(2)
Array([[ 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]], dtype=complex64)