# qftGate

Quantum Fourier transform gate

Since R2023a

Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.

## Syntax

``cg = qftGate(targetQubits)``

## Description

````cg = qftGate(targetQubits)` applies the quantum Fourier transform (QFT) to the target qubits and returns a `quantum.gate.CompositeGate` object with a `Name` property of `"qft"`.```

example

## Examples

collapse all

Create a quantum Fourier transform gate that acts on three qubits.

`cg = qftGate(1:3)`
```cg = CompositeGate with properties: Name: "qft" ControlQubits: [1×0 double] TargetQubits: [3×1 double] Gates: [7×1 quantum.gate.SimpleGate] ```

Get the matrix representation of the gate.

`M = getMatrix(cg)`
```M = Columns 1 through 5 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.2500 + 0.2500i 0.0000 + 0.3536i -0.2500 + 0.2500i -0.3536 + 0.0000i 0.3536 + 0.0000i 0.0000 + 0.3536i -0.3536 + 0.0000i -0.0000 - 0.3536i 0.3536 + 0.0000i 0.3536 + 0.0000i -0.2500 + 0.2500i -0.0000 - 0.3536i 0.2500 + 0.2500i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i -0.2500 - 0.2500i 0.0000 + 0.3536i 0.2500 - 0.2500i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.0000 - 0.3536i -0.3536 + 0.0000i 0.0000 + 0.3536i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.2500 - 0.2500i -0.0000 - 0.3536i -0.2500 - 0.2500i -0.3536 + 0.0000i Columns 6 through 8 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i -0.2500 - 0.2500i -0.0000 - 0.3536i 0.2500 - 0.2500i 0.0000 + 0.3536i -0.3536 + 0.0000i -0.0000 - 0.3536i 0.2500 - 0.2500i 0.0000 + 0.3536i -0.2500 - 0.2500i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.3536 + 0.0000i 0.2500 + 0.2500i -0.0000 - 0.3536i -0.2500 + 0.2500i -0.0000 - 0.3536i -0.3536 + 0.0000i 0.0000 + 0.3536i -0.2500 + 0.2500i 0.0000 + 0.3536i 0.2500 + 0.2500i```

Plot the returned QFT gate to show its internal gates.

`plot(cg)`

Create a quantum circuit that consists of two QFT gates. The first gate acts on qubits with indices 2 to 4. The second gate acts on qubits with indices 1, 3, and 5.

```gates = [qftGate(2:4); qftGate([1 3 5])]; c = quantumCircuit(gates)```
```c = quantumCircuit with properties: NumQubits: 5 Gates: [2×1 quantum.gate.CompositeGate] Name: ""```

Plot the quantum circuit.

`plot(c)`

The plotted circuit consists of five qubits with indices 1 to 5. The plot shows that qubits 2 to 4 of the outer circuit are mapped to qubits 1 to 3 of the inner circuit of internal gates that construct the first QFT gate. For the second QFT gate, qubit 1 of the outer circuit is mapped to qubit 1 of the inner circuit, qubit 3 of the outer circuit is mapped to qubit 2 of the inner circuit, and qubit 5 of the outer circuit is mapped to qubit 3 of the inner circuit.

Click either QFT gate in the plot. A new figure showing the internal gates of the composite gate appears.

## Input Arguments

collapse all

Target qubits to apply QFT, specified as a positive integer vector of qubit indices.

collapse all

### Quantum Fourier Transform

The quantum Fourier transform (QFT) acts on a quantum state $|x〉=\sum _{m=0}^{N-1}{x}_{m}|m〉$ and maps it to a quantum state $|y〉=\sum _{k=0}^{N-1}{y}_{k}|k〉$ according to the formula:

`${y}_{k}=\frac{1}{\sqrt{N}}\sum _{m=0}^{N-1}{x}_{m}{\omega }_{N}^{mk}\text{ }\text{ }k=0,1,\dots ,N-1,$`

where ${\omega }_{N}=\mathrm{exp}\left(\frac{2\pi i}{N}\right)$ and ${\omega }_{N}^{k}$ is an Nth root of unity.

Here, $N={2}^{n}$ is the number of basis states for the n qubits that are quantum Fourier transformed. The state $|m〉$ (or $|k〉$) represents the binary notation $|{m}_{1}{m}_{2}\dots {m}_{n}〉$ of the possible basis states, where the value of m is $m={2}^{n-1}{m}_{1}+{2}^{n-2}{m}_{2}+\dots +{2}^{1}{m}_{n-1}+{2}^{0}{m}_{n}$. By this definition, the effect of the QFT on the state vector matches the inverse discrete Fourier transform, but with a difference in the scaling factor because QFT uses $\text{1/}\sqrt{N}$ instead of $\text{1/}N$.

In matrix representation, the QFT can also be expressed as

`$QFT=\frac{1}{\sqrt{N}}\left[\begin{array}{cccccc}1& 1& 1& 1& \dots & 1\\ 1& \omega & {\omega }^{2}& {\omega }^{3}& \dots & {\omega }^{N-1}\\ 1& {\omega }^{2}& {\omega }^{4}& {\omega }^{6}& \dots & {\omega }^{2\left(N-1\right)}\\ 1& {\omega }^{3}& {\omega }^{6}& {\omega }^{9}& \dots & {\omega }^{3\left(N-1\right)}\\ ⋮& ⋮& ⋮& ⋮& \ddots & ⋮\\ 1& {\omega }^{N-1}& {\omega }^{2\left(N-1\right)}& {\omega }^{3\left(N-1\right)}& \dots & {\omega }^{\left(N-1\right)\left(N-1\right)}\end{array}\right].$`

## References

[1] Nielsen, Michael A., and Isaac L. Chuang. Quantum Computation and Quantum Information. 10th anniversary ed, Cambridge; New York: Cambridge University Press, 2010.

## Version History

Introduced in R2023a