# Quantum Fourier Transformation and Phase Estimation

Let's use Yao first

`using Yao`

## Quantum Fourier Transformation

The Quantum Fourier Transformation (QFT) circuit is to repeat two kinds of blocks repeatly:

The basic building block control phase shift gate is defined as

\[R(k)=\begin{bmatrix} 1 & 0\\ 0 & \exp\left(\frac{2\pi i}{2^k}\right) \end{bmatrix}\]

Let's define block `A`

and block `B`

, block `A`

is actually a control block.

`A(i, j) = control(i, j=>shift(2π/(1<<(i-j+1))))`

`A (generic function with 1 method)`

Once you construct the blockl you can inspect its matrix using `mat`

function. Let's construct the circuit in dash box A, and see the matrix of $R_4$ gate.

`R4 = A(4, 1)`

`(n -> control(n, 4, 1 => shift(0.39269908169872414)))`

If you have read about preparing GHZ state, you probably know that in Yao, we could just leave the number of qubits, and it will be evaluated when possible.

`R4(5)`

```
nqubits: 5
control(4)
└─ (1,) shift(0.39269908169872414)
```

its matrix will be

`mat(R4(5))`

```
32×32 LinearAlgebra.Diagonal{ComplexF64, Vector{ComplexF64}}:
1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0+0.0im ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0.92388+0.382683im
```

Then we repeat this control block over and over on different qubits, and put a Hadamard gate to `i`

th qubit to construct `i`

-th `B`

block.

`B(n, k) = chain(n, j==k ? put(k=>H) : A(j, k) for j in k:n)`

`B (generic function with 1 method)`

We need to input the total number of qubits `n`

here because we have to iterate through from `k`

-th location to the last.

Now, let's construct the circuit by chaining all the `B`

blocks together

```
qft(n) = chain(B(n, k) for k in 1:n)
qft(4)
```

```
nqubits: 4
chain
├─ chain
│ ├─ put on (1)
│ │ └─ H
│ ├─ control(2)
│ │ └─ (1,) shift(1.5707963267948966)
│ ├─ control(3)
│ │ └─ (1,) shift(0.7853981633974483)
│ └─ control(4)
│ └─ (1,) shift(0.39269908169872414)
├─ chain
│ ├─ put on (2)
│ │ └─ H
│ ├─ control(3)
│ │ └─ (2,) shift(1.5707963267948966)
│ └─ control(4)
│ └─ (2,) shift(0.7853981633974483)
├─ chain
│ ├─ put on (3)
│ │ └─ H
│ └─ control(4)
│ └─ (3,) shift(1.5707963267948966)
└─ chain
└─ put on (4)
└─ H
```

## Wrap QFT to an external block

In most cases, `function`

s are enough to wrap quantum circuits, like `A`

and `B`

we defined above, but sometimes, we need to dispatch specialized methods on certain kinds of quantum circuit, or we want to define an external block to export, thus, it's useful to be able to wrap circuit to custom blocks.

First, we define a new type as subtype of `PrimitiveBlock`

since we are not going to use the subblocks of `QFT`

, if you need to use its subblocks, it'd be better to define it under `CompositeBlock`

.

```
struct QFT <: PrimitiveBlock{2}
n::Int
end
YaoBlocks.nqudits(q::QFT) = q.n
```

Now, let's define its circuit

`circuit(q::QFT) = qft(q.n)`

`circuit (generic function with 1 method)`

And forward `mat`

to its circuit's matrix

`YaoBlocks.mat(::Type{T}, x::QFT) where T = mat(T, circuit(x))`

You may notice, it is a little ugly to print `QFT`

at the moment, this is because we print the type summary by default, you can define your own printing by overloading `print_block`

`YaoBlocks.print_block(io::IO, x::QFT) = print(io, "QFT($(x.n))")`

Since it is possible to use FFT to simulate the results of QFT (like cheating), we could define our custom `apply!`

method:

```
using FFTW, LinearAlgebra
function YaoBlocks.apply!(r::ArrayReg, x::QFT)
α = sqrt(length(statevec(r)))
invorder!(r)
lmul!(α, ifft!(statevec(r)))
return r
end
```

Now let's check if our `apply!`

method is correct:

```
r = rand_state(5)
r1 = r |> copy |> QFT(5)
r2 = r |> copy |> circuit(QFT(5))
r1 ≈ r2
```

`true`

We can get iQFT (inverse QFT) directly by calling `adjoint`

`QFT(5)'`

` [†]QFT(5)`

QFT and iQFT are different from FFT and IFFT in three ways,

- they are different by a factor of $\sqrt{2^n}$ with $n$ the number of qubits.
- the bit numbering will exchange after applying QFT or iQFT.
- due to the convention, QFT is more related to IFFT rather than FFT.

## Phase Estimation

Since we have QFT and iQFT blocks we can then use them to realize phase estimation circuit, what we want to realize is the following circuit:

First we call Hadamard gates repeatly on first `n`

qubits.

`Hadamards(n) = repeat(H, 1:n)`

`Hadamards (generic function with 1 method)`

Then in dashed box `B`

, we have controlled unitaries:

`ControlU(n, m, U) = chain(n+m, control(k, n+1:n+m=>matblock(U^(2^(k-1)))) for k in 1:n)`

`ControlU (generic function with 1 method)`

each of them is a `U`

of power $2^{(k-1)}$.

Since we will only apply the qft and Hadamard on first `n`

qubits, we could use `Subroutine`

, which creates a context of a sub-scope of the qubits.

```
PE(n, m, U) =
chain(n+m, # total number of the qubits
subroutine(Hadamards(n), 1:n), # apply H in local scope
ControlU(n, m, U),
subroutine(QFT(n)', 1:n))
```

`PE (generic function with 1 method)`

we use the first `n`

qubits as the output space to store phase $ϕ$, and the other `m`

qubits as the input state which corresponds to an eigenvector of oracle matrix `U`

.

The subroutine here uses `focus!`

and `relax!`

to manage a local scope of quantum circuit, and only activate the first `n`

qubits while applying the block inside the subroutine context, and the scope will be `relax!`

ed back, after the context. This is equivalent to manually `focus!`

then `relax!`

fullly activated

`r = rand_state(5)`

```
ArrayReg{2, ComplexF64, Array...}
active qubits: 5/5
nlevel: 2
```

first 3 qubits activated

`focus!(r, 1:3)`

```
ArrayReg{2, ComplexF64, Array...}
active qubits: 3/5
nlevel: 2
```

relax back to the original

`relax!(r, 1:3)`

```
ArrayReg{2, ComplexF64, Array...}
active qubits: 5/5
nlevel: 2
```

In this way, we will be able to apply small operator directly on the subset of the qubits.

Details about the algorithm can be found here: Quantum Phase Estimation Algorithm

Now let's check the results of our phase estimation.

First we need to set up a unitary with known phase, we set the phase to be 0.75, which is `0.75 * 2^3 == 6 == 0b110`

.

```
N, M = 3, 5
P = eigen(rand_unitary(1<<M)).vectors
θ = Int(0b110) / 1<<N
phases = rand(1<<M)
phases[0b010+1] = θ
U = P * Diagonal(exp.(2π * im * phases)) * P'
```

```
32×32 Matrix{ComplexF64}:
0.225853-0.102828im 0.055023-0.0873042im 0.231798+0.0919657im -0.0433476+0.0117189im 0.0960013-0.121779im 0.188168+0.217723im -0.170756-0.145235im 0.0757637+0.0449361im -0.044384-0.0104396im -0.0242452+0.087086im 0.137731-0.0138354im -0.109127-0.0273222im 0.183487+0.112798im -0.0574463-0.0905073im -0.125309+0.111955im 0.111043+0.170864im 0.182012-0.268701im -0.139363-0.0606993im 0.0550828-0.131137im 0.0396535-0.0190459im -0.00915515-0.199483im 0.0920259-0.155272im -0.109221-0.199417im 0.011017+0.00363484im -0.105191+0.119461im -0.0469555+0.0236568im -0.0432902-0.188241im 0.180886-0.165847im 0.186621+0.0713136im -0.125261+0.126742im -0.181493+0.0672568im -0.0888815+0.106924im
0.0891105-0.00355291im -0.116855+0.0545604im 0.0617243-0.00751127im -0.0224067+0.0637275im 0.194425-0.168122im -0.0454915+0.118435im -0.0660855-0.0464291im 0.0835836-0.152921im 0.0354398-0.143637im 0.00583991-0.0237932im -0.318697-0.14342im -0.10343-0.06229im -0.0840164-0.117298im -0.128103+0.00375962im 0.182785-0.390877im -0.0072507-0.179854im 0.110615-0.183494im -0.104928-0.137531im -0.0484759-0.0555369im -0.0524084-0.0762546im 0.287057+0.0597613im 0.11023-0.0148674im -0.0870231+0.0572236im 0.233657-0.034592im 0.153251-0.156955im -0.00870731+0.0149868im 0.0777434+0.0122716im 0.081811-0.0547083im 0.122105-0.213369im -0.0423869-0.0155936im 0.0960121+0.0597703im 0.0367488-0.192767im
0.280706-0.0265179im 0.0417987-0.200211im -0.0295543-0.0131584im 0.00978714+0.00722738im 0.00157314+0.105886im -0.0459929-0.041618im 0.0516141+0.146616im 0.102128+0.0409532im -0.0183302+0.0103516im 0.0373318+0.106243im 0.0465607-0.0688864im -0.0400994-0.232622im 0.0584116+0.076845im 0.204128+0.214495im -0.255332-0.160697im 0.0514401-0.253394im 0.0741077+0.161305im -0.185546-0.0615394im -0.11885-0.0872229im 0.196236+0.122409im -0.0553462+0.163552im 0.150763-0.0667186im -0.0574547-0.0944702im -0.0526139+0.0356726im 0.019275-0.162629im 0.119892-0.107166im 0.0733045+0.121679im -0.154893-0.333723im -0.15005+0.0526697im 0.12726-0.00390731im -0.0892143+0.113428im 0.0630668+0.0527924im
-0.0447833-0.0462041im 0.150815-0.204864im 0.0384119-0.0375374im -0.201292-0.0189827im -0.0186769-0.0867105im 0.0981124-0.0858277im 0.0993885-0.0748327im -0.120488+0.0183649im -0.0113815+0.0602579im 0.14512+0.10374im -0.0141643+0.151841im -0.0166009-0.145118im -0.0243689-0.442979im -0.065582-0.238456im 0.0162508-0.121259im -0.0631919+0.131734im -0.0570298+0.291522im 0.0937031-0.0502626im 0.0281748-0.186212im 0.0831064+0.0678755im 0.039057-0.120592im -0.0214531-0.29168im 0.089399+0.0696474im 0.121421+0.0326352im -0.0680899-0.0311424im 0.235429+0.110615im 0.145334+0.01632im 0.0400735+0.0846813im 0.0441397+0.055435im 0.0792089+0.100024im -0.10747+0.196801im -0.00847952-0.0764512im
-0.093246-0.0653427im -0.248816+0.0971379im -0.228619-0.135197im -0.00998813-0.159767im -0.0911121-0.013903im 0.0737317+0.00201515im -0.0138053+0.020058im 0.0942888+0.0947613im -0.234936+0.0421027im 0.106072-0.014923im -0.00268362+0.22913im 0.0490905-0.146764im 0.131946+0.130872im -0.0494668-0.102937im 0.360681-0.128417im -0.110226+0.269167im 0.0481173+0.044681im -0.358812+0.00229825im -0.0113932+0.047234im 0.13301-0.029615im -0.0431612+0.22428im 0.0389104+0.0305657im -0.0665615-0.0464255im -0.0135071-0.090116im -0.166799-0.0187115im 0.0725168-0.0981806im 0.0338167+0.101635im 0.00852544-0.0824258im 0.119876+0.0192817im 0.0594737+0.174576im 0.0127312-0.122462im -0.120976-0.00250482im
-0.018143+0.27417im 0.0707437+0.0602974im 0.00884578-0.0862999im -0.00730797+0.208592im -0.196515+0.103196im -0.0759554+0.169656im 0.0839843+0.0367765im -0.0638381-0.0829669im 0.0717692-0.245996im 0.0942206-0.035459im -0.0683805-0.0318756im -0.304339-0.137029im -0.0891296+0.145213im 0.0573664-0.178031im 0.13945-0.00164524im -0.0628249-0.0310948im 0.0517229-0.0904062im 0.272839+0.205527im -0.12278-0.0620373im 0.135526-0.0452867im -0.121321-0.0227759im 0.0567757-0.188206im -0.0646515+0.0468317im 0.0432695-0.157615im -0.173447-0.00267883im 0.0158044+0.0680595im -0.200205+0.286556im 0.0331347-0.100402im 0.0711046-0.0182764im 0.0176654-0.00558696im -0.158331-0.0966809im 0.0146342+0.133276im
0.0614893-0.242979im 0.0821236-0.00396503im -0.0901532-0.0726472im 0.0360658+0.0906132im -0.0416747-0.197202im -0.0934591+0.0243894im -0.0472841+0.101943im -0.120317+0.14453im 0.0466052-0.237621im -0.0235423+0.103865im -0.0153637-0.068093im 0.0461705-0.0567509im 0.0804899-0.0377797im 0.066524+0.178621im 0.00399212+0.0111475im 0.244706+0.247825im -0.0420314+0.135202im -0.00599626+0.032434im -0.255282-0.0581454im -0.0036167+0.0514968im 0.208046+0.205627im -0.186602-0.12556im -0.11573-0.0534442im -0.185317-0.115061im -0.100347+0.0067745im -0.0903963-0.0202145im -0.0993596+0.0127953im 0.12429+0.19192im 0.0173699-0.0367724im -0.141046-0.261692im -0.193105-0.0823929im 0.0633247-0.228505im
-0.0160828-0.0737795im 0.0850324+0.0643579im 0.0144227-0.169985im 0.0672382-0.185373im 0.209439+0.0724862im -0.160751+0.0774487im -0.0299473-0.14044im -0.0904558+0.344562im 0.178598-0.00648339im -0.0312175-0.264532im -0.0493607-0.00780095im -0.0365982+0.0070986im 0.0992956-0.0104922im -0.0389916+4.32356e-6im -0.103245-0.0116658im -0.00986762-0.0742192im 0.0728106-0.120292im -0.0613255+0.207024im 0.0205768+0.151969im -0.0321945+0.253538im 0.0681833+0.032505im -0.310401-0.085188im 0.0542303+0.0977556im 0.102792+0.132707im 0.0208687-0.214047im 0.216422-0.079127im -0.0862357+0.026333im 0.0853338+0.00308316im 0.0451805-0.0505791im 0.0611703+0.258507im -0.148749-0.0908212im 0.109135+0.11978im
0.00159934-0.147002im -0.0026352-0.013883im -0.0981967-0.141818im 0.0170573-0.143645im -0.231424+0.0354412im -0.365438+0.183022im 0.247717+0.0521254im -0.0249071-0.149869im -0.145687+0.0717723im -0.296048-0.0671019im 0.0197411-0.147117im 0.0503045+0.0638509im -0.1374-0.131771im -0.113245-0.0447032im -0.0668683+0.00857086im -0.0935024-0.0943942im -0.0957805+0.0826414im -0.0215024-0.106936im 0.0267699+0.0838054im 0.0492817+0.0112095im -0.0635807-0.101899im 0.122736-0.127778im -0.0995963-0.171723im -0.0429969-0.00103747im 0.0377897+0.190053im 0.0144696-0.128735im 0.0124078-0.180715im 5.19047e-5-0.066942im 0.268932-0.185709im 0.0293673+0.0717726im -0.20664-0.132882im 0.0785321-0.0426637im
-0.138047+0.17238im -0.195103+0.0235463im -0.0605033+0.0565783im -0.0938487-0.130569im 0.0531557+0.138928im 0.155303-0.0587372im 0.0562487+0.136331im 0.112852-0.0386847im -0.030647+0.280348im 0.036388+0.170951im -0.178636-0.107643im -0.0491998+0.281555im 0.0193335+0.0353145im 0.132807+0.00688174im -0.223409+0.010998im -0.021264+0.153989im -0.0486662-0.0504664im 0.127918-0.1326im -0.20621-0.0141395im -0.0328958+0.0625917im 0.164931+0.00655032im 0.0291494+0.00260168im -0.0727843-0.101344im -0.0116193+0.0386827im -0.131756-0.159929im 0.323228+0.0347893im -0.185217+0.016389im 0.246225-0.0374948im 0.218969-0.0129237im 0.065218-0.138567im 0.0103004-0.0628755im 0.111594+0.015476im
-0.0213954+0.265625im -0.0196221-0.0733339im -0.0185501+0.097271im -0.0687276-0.0708298im -0.050364-0.0879401im -0.100987+0.16312im 0.0564253+0.18534im -0.14335+0.164098im 0.029004-0.0444752im -0.266483-0.0821498im 0.012131+0.128538im 0.163856+0.173253im 0.123041-0.0302201im 0.252241-0.269653im -0.0259792-0.150009im 0.114943+0.0842335im 0.00344146+0.00790143im -0.0867397-0.0562093im -0.17648-0.140757im 0.118558-0.120826im -0.0208622+0.0289354im -0.165926-0.0864496im -0.0307055+0.197321im 0.11091-0.0702969im 0.198944+0.00826385im -0.166995+0.0127066im -0.068972-0.177256im -0.0486472-0.212053im 0.0198084+0.15821im -0.0295928+0.0249292im 0.217297+0.0343672im 0.0961918+0.0452698im
0.265054-0.120724im -0.211384+0.0541926im -0.24085-0.00325993im -0.0234899+0.0737808im 0.0565171+0.00175215im -0.282329+0.0660473im -0.0840747+0.035689im -0.0270986+0.0294117im -0.0620556+0.225915im 0.113938+0.162284im 0.277494-0.0955595im 0.0573787+0.0590697im -0.217605+0.022148im 0.0212062-0.0863227im 0.183096-0.00549474im -0.0782523-0.0145409im -0.131123-0.157251im -0.0190775-0.00786199im 0.132388-0.170095im -0.0461532+0.184087im 0.157361-0.227697im -0.117027-0.0357434im -0.0155738+0.255034im -0.1275-0.0306718im -0.0863094-0.10936im -0.0960437+0.110588im 0.0227218+0.125127im 0.0755619-0.1007im -0.0369568+0.107221im -0.0179755-0.0867174im -0.012038+0.0991959im 0.102773+0.10269im
-0.131415+0.135526im -0.0814121+0.104307im 0.18926+0.0758497im -0.0373255-0.018043im 0.145447+0.0805106im -0.114083-0.0964675im 0.11911-0.0845069im 0.272681+0.0659984im -0.26013-0.0428466im 0.117012+0.0371538im -0.0870083+0.181747im 0.0431465-0.119938im 0.138995+0.255762im -0.14785+0.0974273im 0.0364839-0.006115im 0.0109003-0.267209im -0.185546+0.151639im 0.0203944+0.0607436im -0.00508895-0.151626im 0.0828121+0.0656442im 0.0533663-0.160983im -0.163824-0.219958im -0.0455445-0.0593355im -0.0783521-0.217573im 0.0543925+0.0268293im -0.0943903-0.0747571im -0.0385253-0.173165im 0.0393226+0.156803im 0.0682284+0.0442951im -0.0616729-0.00169862im 0.0143488+0.1042im 0.2591+0.00161555im
-0.18783+0.00711344im -0.170271+0.131818im 0.142582+0.0500465im 0.126629-0.0829839im 0.0396461-0.21585im -0.259928-0.0385261im 0.00816326-0.23407im -0.103327-0.0948512im 0.0572537-0.0475165im -0.148798+0.219477im 0.113554+0.0392748im -0.01105+0.106578im 0.121041+0.0533581im -0.151944+0.0961939im 0.0200587+0.121982im 0.115032+0.0503324im 0.0293971-0.0121601im 0.049696-0.0381048im -0.284567+0.143248im 0.239731-0.0174561im 0.000229187+0.00831474im 0.225851+0.01457im 0.119577+0.188961im -0.0796247-0.100353im 0.109675-0.163505im 0.108115+0.112391im 0.130838+0.0547062im -0.0170586-0.0209987im 0.00291097+0.0542406im 0.179941+0.0176253im -0.151617+0.206114im -0.139075+0.108921im
-0.0287875-0.0902572im -0.0441836-0.0281373im 0.291923-0.0194423im -0.225662-0.109798im 0.00375061+0.113396im -0.120064+0.02015im 0.173663+0.126458im -0.0485693+0.0350125im -0.0468615-0.0984439im 0.0638128-0.122492im 0.00915193+0.1144im 0.248816+0.175607im -0.0331515-0.0124924im -0.195247+0.184551im -0.0252208-0.0545172im -0.134691-0.0793585im 0.0820454-0.165595im -0.119086+0.110263im 0.0545543-0.0925781im 0.122103-0.184975im -0.000219531+0.0754636im -0.126325-0.000414846im -0.0289852-0.0741539im 0.077647+0.164571im -0.104532+0.135229im 0.0183697+0.322459im -0.00434248+0.185499im 0.119541-0.114774im -0.0747959+0.122332im 0.109095-0.289264im -0.102575-0.0092996im -0.117957-0.0745788im
0.268543+0.04554im -0.0384685+0.0849801im -0.018007+0.045286im 0.164404-0.0625197im -0.0268503-0.127579im 0.0525296+0.118911im 0.134384+0.279072im -0.0675126-0.0299197im -0.105898+0.0269067im 0.0991334-0.0345958im -0.0714418+0.220392im -0.0453412+0.0160983im -0.0022207-0.0347877im -0.107552+0.0102097im 0.0157946+0.13895im -0.0379156+0.0193267im 0.0743583-0.0116676im 0.0751154+0.221963im 0.107369-0.17839im 0.132103+0.172388im 0.0449252+0.148597im 0.0581354+0.0914438im 0.234581+0.0386623im -0.0217887+0.127846im 0.259134+0.0230939im 0.127686-0.189141im -0.185268-0.0746454im -0.0140701+0.0842372im 0.18915-0.151906im -0.11226-0.194051im 0.00306825+0.241266im -0.175534+0.0996299im
0.0764188+0.12411im -0.380702-0.118269im 0.0607066+0.0128105im 0.0130852-0.299497im -0.00348812+0.0605407im -0.0559408+0.0635818im -0.153376-0.189524im 0.0331103+0.100071im -0.0207961-0.0406917im -0.0361952-0.104111im 0.0431703+0.0435533im -0.232753-0.00858771im 0.04638-0.146324im -0.0486694+0.0722708im -0.0267749-0.0621533im 0.103224+0.0352995im -0.20272+0.217795im -0.000983441+0.0694303im -0.0900364-0.00806931im -0.153787+0.101073im -0.17676-0.0390467im 0.143466+0.00465708im 0.0386226+0.0635887im 0.227338+0.163047im -0.217444+0.0261365im -0.151973+0.0668994im -0.0922338+0.0079128im -0.125141-0.0611882im -0.0657788-0.115893im -0.267388-0.238205im -0.0470639-0.0158906im -0.0158292-0.00655105im
-0.0810337+0.0273886im 0.109529+0.295052im -0.28052+0.0311583im -0.0211881-0.0527468im 0.112036-0.159339im -0.0777843-0.166064im 0.0978807+0.0574377im 0.132851+0.141833im -0.168007-0.264573im 0.0422234-0.0287585im -0.0268309-0.113533im -0.089133+0.082585im 0.011093-0.121267im -0.163935+0.00316065im -0.0840258+0.0515539im -0.0578391+0.15141im 0.214075+0.0616738im -0.0528024-0.112329im 0.0571243-0.142745im -0.158104-0.191257im -0.184285-0.236461im 0.0438223-0.033484im -0.136471-0.054832im -0.0612567+0.14892im 0.140599-0.205886im 0.0720644+0.014578im -0.151368+0.0710333im -0.187478-0.100298im -0.0993746+0.104449im -0.107711-0.0554477im -0.0827503+0.0339783im 0.0584145+0.0572566im
-0.0338174-0.0218015im -0.0462048-0.207051im -0.132663+0.0333257im -0.208114+0.11126im -0.119339-0.233077im -0.041293+0.132883im -0.193202+0.0953034im 0.0911624+0.0911702im 0.0820279+0.209865im 0.101699-0.231024im -0.174575+0.0986249im 0.0719168+0.0425125im 0.0764578+0.151933im -0.232926-0.0626026im -0.030837+0.250878im -0.0778865-0.1039im 0.0360622+0.21637im 0.122948+0.0843241im -0.101623+0.0121117im -0.239952-0.139369im 0.128317+0.121084im 0.134558-0.102752im 0.0439987-0.0421044im -0.101521+0.0107267im 0.121355-0.127381im -0.109837+0.0920175im 0.192325+0.0370188im 0.0789321-0.174612im -0.0306881-0.044525im -0.0215584+0.0227896im -0.107131-0.0584261im 0.0601066+0.133327im
0.160358+0.0585491im -0.109096-0.0345548im -0.0126027+0.0735529im -0.360776-0.249121im -0.196872-0.0371234im -0.0668469+0.0901726im 0.0482844+0.0119628im -0.0173912-0.164162im 0.0773485-0.256921im 0.213948-0.166858im 0.02061+0.0163051im -0.102086-0.210939im -0.0228576+0.0815003im -0.0060345+0.013584im -0.146946+0.076116im 0.0116296+0.16073im -0.16302-0.140775im -0.0346549-0.207623im -0.0355673+0.0520629im 0.0270898+0.0280798im 0.0822303+0.0249152im -0.0445791+0.221653im -0.173702+0.101212im -0.129234+0.0320368im 0.139569+0.0654817im 0.141379+0.10502im 0.00522307-0.0896341im -0.0064463+0.225626im -0.137319-0.0350765im 0.0499053+0.159548im 0.0179906+0.0682941im 0.152024+0.113065im
-0.178499-0.0647007im 0.20865+0.168931im 0.188918-0.0118677im 0.0723822+0.106301im 0.0226719-0.11655im -0.00852346+0.125679im 0.000219002-0.0332038im 0.112587-0.178393im -0.0597475+0.0515494im -0.0380366+0.0761871im 0.0820926+0.0790751im -0.19117-0.0289824im -0.112419-0.0270192im -0.113857-0.26194im 0.0218784-0.00373405im -0.053878-0.0199996im -0.168795+0.11794im -0.145026-0.228806im -0.0554385+0.0670796im -0.0441251+0.178509im 0.148798+0.284047im -0.217565+0.077386im -0.0405288-0.115654im 0.0943486+0.149757im -0.0183356+0.0187808im -0.00752019-0.0141983im -0.092914-0.0486734im -0.0174118-0.155988im -0.199594+0.0888765im -0.0136918-0.214955im -0.0326886-0.0449164im 0.0241455+0.327559im
-0.0943765-0.109169im 0.0124348-0.0177572im -0.0583259+0.211053im 0.0457488-0.100978im -0.00887848+0.0417393im -0.0788878+0.0200756im -0.286318+0.1085im -0.231341-0.0851639im -0.122563+0.119788im -0.0846062-0.0480025im 0.127972+0.00803106im 0.064995-0.210987im 0.183289+0.0820169im -0.156994-0.0560996im -0.037084+0.0886789im 0.0841612-0.245941im 0.066389-0.0120286im 0.186184-0.202764im 0.106697-0.16734im 0.0770795-0.211537im 0.0850879+0.0234808im -0.0890623+0.0177658im -0.125536+0.144233im 0.175118-0.0994152im -0.152476-0.0420524im 0.322377-0.0954587im -0.17188+0.0190814im -0.133316+0.0345274im -0.0678733-0.0454885im -0.0909658-0.0461801im 0.00207299-0.147027im -0.0964211-0.0898576im
0.0232363+0.0319023im -0.0977469+0.105844im -0.0273798+0.0452114im 0.160594+0.0642387im -0.142243+0.043169im -0.0609301-0.0896637im -0.0210911+0.0374899im -0.0208379-0.105732im 0.137112-0.0964754im -0.113573-0.0954636im 0.101644-0.121892im 0.146051-0.0315667im 0.0879138+0.0930202im -0.0357284-0.160448im -0.244469-0.072122im -0.122618-0.00456439im -0.167772+0.142929im -0.129783+0.0408167im 0.10122-0.0113776im -0.193273-0.164323im 0.0149538+0.128103im -0.0517675+0.014551im -0.0345823-0.144782im 0.124904-0.0241215im -0.153945-0.129746im -0.0882811-0.0315919im -0.106842+0.177694im 0.231189+0.115974im 0.0978066+0.0279377im -0.0266106+0.153528im -0.0269282+0.525434im -0.0788787-0.00713072im
0.18465-0.0371849im 0.0445282+0.251415im 0.0110759+0.0379752im 0.0238721-0.166939im -0.351553+0.0181107im 0.14814-0.074041im -0.225928-0.1856im 0.0364232+0.108215im 0.137522+0.0412062im -0.130359+0.00946248im -0.109593+0.110048im -0.0361435-0.00874684im -0.0504987+0.0382102im 0.0995394-0.0210368im 0.050832+0.0195128im -0.0558764-0.171673im -0.0122029+0.0813968im -0.024945-0.0253327im -0.128824-0.125788im -0.00373675+0.0311857im 0.0245609-0.197868im -0.130756+0.0273301im -0.233793-0.0527496im 0.0753528+0.0859063im 0.236208+0.0287919im 0.00192359-0.0675602im 0.192615+0.191423im -0.0204536+0.119929im 0.235883+0.187466im 0.169928-0.212672im -0.0585747-0.0709082im -0.116379+0.0129015im
0.141921+0.0674054im 0.0256547+0.0147242im -0.0651372-0.0273189im -0.0487259+0.0473957im -0.0719297+0.0208306im -0.20624-0.213712im 0.00467427+0.132055im -0.0185092-0.0532809im -0.0525772+0.108334im -0.0681063+0.231984im -0.183937-0.0443195im -0.244768-0.137299im 0.0852729+0.167362im 0.0161617+0.162192im 0.0128365+0.1527im 0.0583989+0.197499im -0.102082+0.000832393im -0.0547057-0.0489222im 0.059418+0.0580486im 0.077373-0.209754im 0.101965-0.0840652im -0.304064-0.0363586im 0.325403-0.0811043im 0.35026+0.176167im 0.0717797+0.0241242im -0.10725+0.143873im 0.0783447-0.000808953im -0.0362692-0.0735327im 0.0366787-0.065356im -0.00596445+0.137385im -0.0476779-0.071772im -0.0418486-0.0222914im
0.0722807-0.0209528im -0.09653+0.0471429im -0.179219+0.040172im 0.14385+0.156877im -0.123604-0.0628307im -0.0632052-0.0359859im -0.0166063-0.0381898im -0.0375238+0.103973im 0.0227723+0.104556im -0.0644655+0.237279im -0.12848+0.132627im 0.0306228-0.114424im 0.139516-0.153054im -0.12814-0.0694672im -0.0842872-0.0600042im -0.115985-0.0810027im 0.074376-0.195685im -0.0296631+0.154174im -0.130417+0.0700251im 0.0913228-0.0636183im -0.201786+0.00659007im 0.10489+0.0674527im -0.0757496-0.0387424im 0.135778+0.111388im 0.0111667+0.234855im 0.126796-0.0219108im 0.0482353-0.0472804im 0.324261+0.126102im -0.317485+0.0411554im -0.109207-0.0464764im 0.046419-0.017029im 0.365421+0.0568524im
-0.166546-0.116047im -0.0945502+0.0299423im 0.184137+0.106864im 0.136866+0.085416im -0.103219-0.148164im 0.000840754-0.0056477im -0.0100623-0.00600538im 0.00220614+0.145204im -0.110566+0.0822863im 0.0792972-0.120685im 0.0534164+0.0701276im 0.000382731-0.139132im -0.00365593-0.0311444im 0.238234+0.0376853im -0.210987-0.000832046im -0.0183937+0.135348im 0.174623+0.0132846im -0.0584061-0.212749im 0.296037+0.0907927im 0.00751085+0.0381839im -0.068651+0.00437239im 0.0455691-0.00865171im 0.0866939+0.120775im 0.100868-0.181178im 0.133646+0.056299im -0.0916794+0.154562im -0.0240691+0.28313im 0.00633765+0.0171316im 0.190417-0.24479im 0.0918196-0.168636im -0.0408207-0.0333122im 0.330301+0.0798661im
0.00310576+0.109939im 0.145187+0.133im -0.251673-0.0203901im 0.168178+0.142359im 0.0967561+0.102228im 0.0500798+0.0497276im 0.017332-0.0488921im 0.0641814+0.188326im 0.135105-0.019672im 0.0425719-0.0843814im 0.0405182+0.205926im -0.0472073+0.037649im -0.122704-0.163601im 0.00322164+0.189622im -0.073083+0.221691im 0.00152819-0.183482im -0.14975-0.00137386im -0.180481-0.203227im -0.0720954-0.193932im 0.183667-0.147924im 0.111191+0.135244im 0.15788+0.0228327im -0.062813+0.127041im 0.0261512+0.0638387im -0.217145+0.0545958im -0.0718355+0.30475im -0.00937212-0.146502im -0.00600709+0.0867186im 0.198853-0.110835im 0.0239925+0.12365im 0.0139802-0.0147032im -0.013338+0.0856015im
-0.00678726+0.0214502im -0.025571-0.0443099im -0.0474986-0.286377im 0.205528-0.0170543im 0.0976394+0.0630363im 0.0400571+0.318192im 0.0656153+0.247331im 0.297491-0.14017im 0.0378256+0.00820392im 0.12456-0.0122069im 0.134142+0.00246191im 0.118564-0.0137927im 0.0874355+0.0437571im -0.0963098+0.00306214im -0.117789+0.032975im 0.215843+0.102804im 0.0110942+0.0555123im 0.00520491-0.0964215im -0.0469611+0.0321249im -0.0148859-0.0232361im -0.0439747-0.184401im 0.0429799-0.202626im -0.0719732+0.154049im 0.26569+0.0800639im 0.105297-0.0272293im -0.0663898-0.0861642im 0.0998359+0.130467im 0.111208+0.276805im -0.147208+0.052814im 0.17979-0.0493464im 0.0629649-0.12319im -0.139551+0.0310465im
-0.126418+0.0290508im -0.14344-0.130745im -0.0894705+0.202591im 0.0232046+0.170574im -0.0575658+0.205675im -0.0672029+0.104352im -0.206946-0.170742im 0.0637693-0.255285im -0.010413-0.268303im 0.079422+0.0595923im 0.00797289-0.0129294im 0.144836+0.159755im 0.154003-0.291963im 0.0265683+0.0811723im -0.103722+0.0303214im -0.0932681+0.0353998im -0.0576578-0.0128482im -0.142295+0.0521228im 0.0160864-0.191636im 0.124651+0.0547695im 0.0703916-0.00931292im -0.144718-0.0515111im 0.183896-0.125426im -0.100132+0.0196507im 0.176932-0.0290076im 0.0330158-0.123874im 0.0547012+0.207429im -0.00801406-0.00855787im 0.0474409-0.0467504im -0.153589+0.102924im 0.0272861-0.246979im -0.041515+0.17498im
-0.146138-0.047619im 0.111602+0.0500695im -0.232018-0.134121im -0.087543-0.0784173im 0.0739774+0.198991im -0.0426713-0.00536133im -0.169626-0.0272169im -0.138952-0.108804im -0.0848848-0.0103765im 0.0977019-0.0874691im 0.0354027+0.151704im 0.089807-0.145917im 0.0536567+0.0197452im 0.0107606-0.111075im -0.0498581+0.0348153im 0.0209975-0.0601488im 0.102488-0.22973im -0.0361791-0.116407im -0.342386-0.0120743im -0.169033+0.193417im 0.0860138-0.0921857im 0.141175-0.00933743im 0.322817-0.203422im 0.0764205-0.00387916im 0.0815713+0.170057im -0.166586+0.0417705im -0.182405+0.0618247im -0.113442-0.0270003im 0.0370018+0.070284im 0.128347-0.0788063im -0.0404734+0.188495im 0.0899888-0.16647im
-0.106711+0.142335im -0.0621224+0.0763952im -0.0523161+0.0318196im -0.0956498+0.0768794im -0.0939409-0.211418im 0.0855086-0.0122313im 0.136861-0.0152102im -0.172519+0.113817im -0.10965-0.179532im 0.227083+0.19152im 0.402039-0.0994299im -0.0313862+0.176779im 0.136486+0.169664im 0.0361548-0.0341351im -0.0642915+0.0243188im -0.128851-0.193413im 0.0226265-0.00831667im 0.0483501+0.0175852im -0.0498612-0.113547im -0.129071+0.186583im 0.000651233+0.113019im -0.0296941+0.0248881im -0.0586562-0.0149718im 0.241905+0.195281im 0.0103253+0.0327058im -0.0410979-0.071046im 0.217887-0.0793094im 0.020751-0.0248533im 0.051739-0.222867im 0.0952718+0.0762666im -0.032099-0.118284im -0.0077076-0.206361im
```

and then generate the state $ψ$

`psi = P[:, 3]`

```
32-element Vector{ComplexF64}:
-0.14356958412295875 - 0.2948839769899594im
-0.13977703244578626 - 0.06572421342808579im
0.10909825560316397 - 0.060291718198448134im
-0.018367389289801875 + 0.03568069705162181im
-0.15773279841748633 - 0.0494844469894115im
0.17784395496275635 + 0.20629663056702455im
-0.03460929050500871 - 0.22178467823488104im
0.07018417983479655 + 0.08264071874454355im
0.14636052813562891 - 0.2649639702190808im
0.06840978538504908 + 0.21265639934123856im
-0.0407927057038127 + 0.019791042862182747im
-0.06397198172328052 - 0.04910656442754963im
-0.0010703054306440594 + 0.03723994669030815im
0.03750546699061997 + 0.013553812193245798im
0.10537006316158208 + 0.11263317060527715im
-0.030750408336907613 + 0.18001399157499867im
-0.11260269297616968 + 0.09116457969936775im
0.05237577962063886 - 0.18008172232139022im
-0.13133677659693527 + 0.02479186181648083im
0.10856266095442754 - 0.0960578759408207im
0.038293074155218036 + 0.03886330242660748im
-0.1695161619054715 + 0.05899964218599172im
0.3581142448891385 + 0.0im
0.09173950738540951 + 0.07390682092824832im
0.03887189402222671 + 0.12758596347355006im
0.1079322064927011 - 0.12155982930249284im
-0.1797286075401408 - 0.08537395721767072im
-0.07136193350612526 - 0.09063008906527097im
-0.14173949246145917 - 0.002888993768690896im
0.001097602282169862 + 0.07285811813716499im
-0.11734831138045049 + 0.059528060346401276im
-0.23835647016944472 - 0.09249547798538231im
```

In the phase estimation process, we will feed the state to circuit and measure the first `n`

qubits processed by iQFT.

```
r = join(ArrayReg(psi), zero_state(N))
r |> PE(N, M, U)
```

```
ArrayReg{2, ComplexF64, Array...}
active qubits: 8/8
nlevel: 2
```

Since our phase can be represented by 3 qubits precisely, we only need to measure once

`results = measure(r, 1:N; nshots=1)`

```
1-element Vector{BitBasis.BitStr64{3}}:
011 ₍₂₎
```

Recall that our QFT's bit numbering is reversed, let's reverse it back

```
using BitBasis
estimated_phase = bfloat(results[]; nbits=N)
```

`0.75`

the phase is exactly `0.75`

!

*This page was generated using Literate.jl.*