Hadamard transform

From testwiki
Jump to navigation Jump to search

Template:Short description Template:Redirect-distinguish Template:Use American English

The product of a Boolean function and a Hadamard matrix is its Walsh spectrum:[1]
(1, 0, 1, 0, 0, 1, 1, 0) × H(8) = (4, 2, 0, −2, 0, 2, 0, 2)
Fast Walsh–Hadamard transform, a faster way to calculate the Walsh spectrum of (1, 0, 1, 0, 0, 1, 1, 0).
The original function can be expressed by means of its Walsh spectrum as an arithmetical polynomial.

The Hadamard transform (also known as the Walsh–Hadamard transform, Hadamard–Rademacher–Walsh transform, Walsh transform, or Walsh–Fourier transform) is an example of a generalized class of Fourier transforms. It performs an orthogonal, symmetric, involutive, linear operation on a tuple of Template:Math numbers.

The Hadamard transform can be regarded as being built out of size-2 discrete Fourier transforms (DFTs), and is in fact equivalent to a multidimensional DFT of size Template:Math.[2] It decomposes an arbitrary input vector into a superposition of Walsh functions.

The transform is named for the French mathematician Jacques Hadamard (Template:IPA), the German-American mathematician Hans Rademacher, and the American mathematician Joseph L. Walsh.

Definition

The Hadamard transform Hm is a 2m × 2m matrix, the Hadamard matrix (scaled by a normalization factor), that transforms 2m real numbers xn into 2m real numbers Xk. The Hadamard transform can be defined in two ways: recursively, or by using the binary (base-2) representation of the indices n and k.

Recursively, we define the 1 × 1 Hadamard transform H0 by the identity H0 = 1, and then define Hm for m > 0 by: Hm=12m/2(Hm−1Hm−1Hm−1−Hm−1) where the division by 2m/2 is a normalization that is sometimes omitted.

For m > 1, we can also define Hm by: Hm=H1⊗Hm−1 where ⊗ represents the Kronecker product. Thus, other than this normalization factor, the Hadamard matrices are made up entirely of 1 and −1.

Equivalently, we can define the Hadamard matrix by its (k, n)-th entry by writing k=∑i=0m−1ki2i=km−12m−1+km−22m−2+…+k12+k0n=∑i=0m−1ni2i=nm−12m−1+nm−22m−2+…+n12+n0

where the kj and nj are the bit elements (0 or 1) of k and n, respectively. Note that for the element in the top left corner, we define: k=n=0. In this case, we have: (Hm)k,n=12m/2(−1)∑jkjnj

This is exactly the multidimensional 2×2×⋯×2×2 DFT, normalized to be unitary, if the inputs and outputs are regarded as multidimensional arrays indexed by the nj and kj, respectively.

Some examples of the Hadamard matrices follow. H0=+(1)H1=12(111−1)H2=12(11111−11−111−1−11−1−11)H3=123/2(111111111−11−11−11−111−1−111−1−11−1−111−1−111111−1−1−1−11−11−1−11−1111−1−1−1−1111−1−11−111−1)(Hn)i,j=12n/2(−1)i⋅j where i⋅j is the bitwise dot product of the binary representations of the numbers i and j. For example, if n≥2, then (Hn)3,2=(−1)3⋅2=(−1)(1,1)⋅(1,0)=(−1)1+0=(−1)1=−1, agreeing with the above (ignoring the overall constant). Note that the first row, first column element of the matrix is denoted by (Hn)0,0.

H1 is precisely the size-2 DFT. It can also be regarded as the Fourier transform on the two-element additive group of Z/(2).

The rows of the Hadamard matrices are the Walsh functions.

Template:Missing information

Relation to Fourier transform

The Hadamard transform is equivalent to a multidimensional DFT of size Template:Math.[2]

Formally, the Hadamard transform is a Fourier transform on the Boolean group (ℤ/2ℤ)n.[3] [4] Using the Fourier transform on finite (abelian) groups, the Fourier transform of a function f:(ℤ/2ℤ)n→ℂ is the function f^ defined by f^(χ)=∑a∈(ℤ/2ℤ)nf(a)χ¯(a) where χ is a character of (ℤ/2ℤ)n. Each character has the form χr(a)=(−1)a⋅r for some r∈(ℤ/2ℤ)n, where the multiplication is the boolean dot product on bit strings, so we can identify the input to f^ with r∈(ℤ/2ℤ)n (Pontryagin duality) and define f^:(ℤ/2ℤ)n→ℂ by f^(r)=∑a∈(ℤ/2ℤ)nf(a)(−1)r⋅a

This is the Hadamard transform of f, considering the input to f and f^ as boolean strings.

In terms of the above formulation where the Hadamard transform multiplies a vector of 2n complex numbers v on the left by the Hadamard matrix Hn the equivalence is seen by taking f to take as input the bit string corresponding to the index of an element of v, and having f output the corresponding element of v.

The usual discrete Fourier transform, applied to a vector v of 2n complex numbers, instead uses characters of the cyclic group ℤ/2nℤ. Consequently the DFT requires substantially more complicated arithmetic than the Hadamard transform. Unlike the DFT, the Hadamard transform is purely real, and in fact requires no multiplication, only sign flips.

Computational complexity

In the classical domain, the Hadamard transform can be computed in nlog⁡n operations (n=2m), using the fast Hadamard transform algorithm.

In the quantum domain, the Hadamard transform can be computed in O(1) time, as it is a quantum logic gate that can be parallelized.

Quantum computing applications

The Hadamard transform is used extensively in quantum computing. The 2 × 2 Hadamard transform H1 is the quantum logic gate known as the Hadamard gate, and the application of a Hadamard gate to each qubit of an Template:Nowrap register in parallel is equivalent to the Hadamard transform Template:Nowrap

Hadamard gate

Template:Further In quantum computing, the Hadamard gate is a one-qubit rotation, mapping the qubit-basis states |0⟩ and |1⟩ to two superposition states with equal weight of the computational basis states |0⟩ and |1⟩. Usually the phases are chosen so that H=|0⟩+|1⟩2⟨0|+|0⟩−|1⟩2⟨1|

in Dirac notation. This corresponds to the transformation matrix H1=12(111−1) in the |0⟩,|1⟩ basis, also known as the computational basis. The states |0⟩+|1⟩2 and |0⟩−|1⟩2 are known as |+⟩ and |−⟩ respectively, and together constitute the polar basis in quantum computing.

Hadamard gate operations

H(|0⟩)=12|0⟩+12|1⟩=:|+⟩H(|1⟩)=12|0⟩−12|1⟩=:|−⟩H(|+⟩)=H(12|0⟩+12|1⟩)=12(|0⟩+|1⟩)+12(|0⟩−|1⟩)=|0⟩H(|−⟩)=H(12|0⟩−12|1⟩)=12(|0⟩+|1⟩)−12(|0⟩−|1⟩)=|1⟩

One application of the Hadamard gate to either a 0 or 1 qubit will produce a quantum state that, if observed, will be a 0 or 1 with equal probability (as seen in the first two operations). This is exactly like flipping a fair coin in the standard probabilistic model of computation. However, if the Hadamard gate is applied twice in succession (as is effectively being done in the last two operations), then the final state is always the same as the initial state.

Hadamard transform in quantum algorithms

Computing the quantum Hadamard transform is simply the application of a Hadamard gate to each qubit individually because of the tensor product structure of the Hadamard transform. This simple result means the quantum Hadamard transform requires log2N operations, compared to the classical case of Nlog2N operations.

For an n-qubit system, Hadamard gates acting on each of the n qubits (each initialized to the |0⟩) can be used to prepare uniform quantum superposition states when N is of the form N=2n. In this case with n qubits, the combined Hadamard gate Hn is expressed as the tensor product of n Hadamard gates: Hn=H⊗H⊗…⊗H⏟n times

The resulting uniform quantum superposition state is then: Hn|0⟩⊗n=12n∑j=02n−1|j⟩ This generalizes the preparation of uniform quantum states using Hadamard gates for any N=2n.[5]

Measurement of this uniform quantum state results in a random state between |0⟩ and Template:Nowrap

Many quantum algorithms use the Hadamard transform as an initial step, since as explained earlier, it maps n qubits initialized with |0⟩ to a superposition of all 2n orthogonal states in the |0⟩,|1⟩ basis with equal weight. For example, this is used in the Deutsch–Jozsa algorithm, Simon's algorithm, the Bernstein–Vazirani algorithm, and in Grover's algorithm. Note that Shor's algorithm uses both an initial Hadamard transform, as well as the quantum Fourier transform, which are both types of Fourier transforms on finite groups; the first on (ℤ/2ℤ)n and the second on ℤ/2nℤ.

Preparation of uniform quantum superposition states in the general case, when N ≠ 2n is non-trivial and requires more work. An efficient and deterministic approach for preparing the superposition state |Ψ⟩=1N∑j=0N−1|j⟩ with a gate complexity and circuit depth of only O(log2N) for all N was recently presented.[6] This approach requires only n=⌈log2N⌉ qubits. Importantly, neither ancilla qubits nor any quantum gates with multiple controls are needed in this approach for creating the uniform superposition state |Ψ⟩.

Convolutional neural networks

The Hadamard transform has found applications in quantum machine learning, particularly in hybrid quantum-classical neural networks. Dyadic convolution between two vectors is equivalent to element-wise multiplication of their Hadamard transform representations; thus convolutional layers can be performed efficiently by taking the Hadamard transform, multiplying, and then inverting the Hadamard transform. While classical computation of the Hadamard transform requires O(n log n) operations using the fast Hadamard transform algorithm, the quantum implementation can compute the transform in O(1) time by applying Hadamard gates to all qubits simultaneously.[7]

Application in evolutionary biology

The Hadamard transform can be used to estimate phylogenetic trees from molecular data.[8][9][10] In principle, the Hadamard transform can be applied to many different models of sequence evolution, but the case of greatest interest uses data from nucleic acids (NAs).[8][11]

Formally, consider the four possible strand nucleobases as elements of the Klein 4-group Template:Mvar acting on itself. One C2 axis corresponds to transitions and the other to transversions. NA sequences of length Template:Mvar are elements of Template:Math, and a given index into these length-Template:Mvar sequences is called a site. A phylogenetic tree Template:Mvar is a tree, rooted at some Template:Mvar, in which each point has been identified with a NA sequence.[12]

In biological applications, one would like to specify mutation rates for each edge of Template:Mvar and then compute the resulting probability of observing Template:Mvar. Ideally, this process should be easily invertible, such that an optimization algorithm can find a (tree, mutation rate) pair producing the observed DNA sequences with maximum likelihood. In fact, this can be done with the Hadamard transform, as follows.[12][13]

Let Template:Mvar be the power set of Template:Math, and consider the following Template:Math-indexed vector Template:Mvar. Each site Template:Mvar determines a Template:Math, the set of points with a transition relative to Template:Mvar at site Template:Mvar. Likewise transversions determine another Template:Math for each site. Then Template:Math is the proportion (out of Template:Math) of sites determining Template:Math.[12]

The linear operator Template:Math with Template:Mathth coefficient Template:Math is a Hadamard matrix; in fact, it defines a Hadamard transform when Template:Mvar is enumerated in a certain order.[9] Let

Template:Math

where the Template:Math indicates that the logarithm acts on each component of the vector. Then Template:Math is almost the mutation rates Template:Mvar necessary to produce the observed probability distribution Template:Mvar, as follows.[12][14]

For the full Kimura model, with all 4 nucleic acids distinguished, there are three free parameters for each edge. Converting these values to the corresponding entry in Template:Math requires conjugation of another logarithm with a Template:Math matrix.[12]

If the sequences are instead RY-coded, then the relationship is much simpler. In that case, Template:Mvar and Template:Math are indexed by Template:Mvar (rather than Template:Math), as can Template:Mvar be: for even-sized Template:Math, let Template:Math; for odd-sized Template:Math, let Template:Math; and let Template:Math be the mutation rate on the edge disconnecting Template:Math from the rest of Template:Mvar. (Template:Mvar is not quite a measured quantity, as it includes the probability of reverted mutations. It is related to the observed probability of character change via

Template:Math

where Template:Mvar is the observed probability.) Then Template:Math.[9]

This technique can also be generalized to the case in which different sites mutate at different rates.[15]

In all cases, the time complexity of determining the tree is dominated by the Hadamard transform, which takes Template:Math-many steps.[16] However, algorithms can reconstruct the tree by piecing together smaller trees constructed from a subset of Template:Mvar.[17]

Other applications

The Hadamard transform is also used in data encryption, as well as many signal processing and data compression algorithms, such as JPEG XR and MPEG-4 AVC. In video compression applications, it is usually used in the form of the sum of absolute transformed differences. It is also a crucial part of significant number of algorithms in quantum computing. The Hadamard transform is also applied in experimental techniques such as NMR, mass spectrometry and crystallography. It is additionally used in some versions of locality-sensitive hashing, to obtain pseudo-random matrix rotations.

See also

References

Template:Reflist