1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Return an n-qubit QFT (or inverse QFT) gate that matches the
textbook/Qiskit definition (little-endian; bit-reversal built in).
Parameters
----------
num_qubits : int
inverse : bool, optional
If True, build the inverse transform (default: False).
do_swaps : bool, optional
Insert the final bit-reversal SWAP network (default: True).
"""
=
# *** 1. phase-ladder from MSB → LSB ***
# i = n-1 … 0
# j = 0 … i-1
= / # π / 2^{distance}
# control=i target=j
# *** 2. optional bit-reversal SWAPs ***
# *** 3. inverse = adjoint of the forward ***
= # exact adjoint
=
return #.to_gate(label=qc.name)