Useless Solutions Call for Useless Problems

Published on
162 min read––– views

Useless Solutions Call for Useless Problems

Consider a toy problem wherein we’re given a black box function called ff which operates on four 1-bit inputs we’ll label b1,b2,b3b_1, b_2, b_3 and aa. ff is stateful, and perhaps better interpreted as a “circuit” with the following behavior:

f={a¬a if b1a¬a if b2a¬a if b3f = \begin{cases} a \leftarrow \lnot a \text{ if } b_1 \\ a \leftarrow \lnot a \text{ if } b_2 \\ a \leftarrow \lnot a \text{ if } b_3 \\ \end{cases}

The catch is that any subset of those cases might be ignored, deleted, faulty, flipped by a gamma ray1, etc. E.g., we might receive an ff with the second case “deleted” resembling:

f={a¬a if b1  a¬a if b3f = \begin{cases} a \leftarrow \lnot a \text{ if } b_1 \\ \; \\ a \leftarrow \lnot a \text{ if } b_3 \\ \end{cases}

For an instance of this problem with nn inputs, there are 2n12^{n-1} possible subsets of “missing” statements which can be interpreted as toggles acting on our accumulator. (2n12^{n-1} since we discount the aa which accumulates the effect of the other inputs).

We can consider the set of all possible configurations of this black box function ff with 4 arguments (3 input bits and one accumulator bit):

F3={  f,  fb1,fb2,fb3,fb1,b2,fb2,b3,fb1,b3,  fb1,b2,b3  }\begin{aligned} F_3 = \begin{Bmatrix} &\; &f_\emptyset, &\; \\ &f_{b_1}, &f_{b_2}, &f_{b_3}, \\ &f_{b_1,b_2}, &f_{b_2,b_3}, &f_{b_1,b_3}, \\ &\; &f_{b_1,b_2,b_3} &\; \end{Bmatrix} \end{aligned}

Where the subscripts correspond to which cases are present in the function. The problem statement is: given some unknown function fFnf \in F_n, we want to determine which ff we’re dealing with in as few invocations or “queries” to ff as possible.

An initial naive approach might be to select an arbitrary initial binary string, say 0ˉ\bar 0, flip the first bit, pass it to ff and observe what happens. For fF3f \in F_3 this might look like:

f(1000)1001f(1000) \rightarrow 1001

This tells us that the first case (toggling aa contingent on toggling b1b_1 is present in our given ff). Not that this logarithmically eliminates fully half of the 232^3 possible ffs (the ones where b1b_1 is absent, deleted, corrupted, etc.):

F3={  f,  fb1,fb2,fb3,fb1,b2,fb2,b3,fb1,b3,  fb1,b2,b3  }\begin{aligned} F_3 = \begin{Bmatrix} &\; &\color{red}f_\emptyset\color{black}, &\; \\ &f_{b_1}, &\color{red}f_{b_2}\color{black}, &\color{red}f_{b_3}\color{black}, \\ &f_{b_1,b_2}, &\color{red}f_{b_2,b_3}\color{black}, &f_{b_1,b_3}, \\ &\; &f_{b_1,b_2,b_3} &\; \end{Bmatrix} \end{aligned}

We can repeat with another input string to target the behavior of another of the cases, say:

f(0100)0100f(0100) \rightarrow 0100

which tells us that the case for b2b_2 is missing since aa was not toggled. So we can eliminate another half of the remaining possibilities:

F3={  f,  fb1,fb2,fb3,fb1,b2,fb2,b3,fb1,b3,  fb1,b2,b3  }\begin{aligned} F_3 = \begin{Bmatrix} &\; &\color{red}f_\emptyset\color{black}, &\; \\ &f_{b_1}, &\color{red}f_{b_2}\color{black}, &\color{red}f_{b_3}\color{black}, \\ &\color{red}f_{b_1,b_2}\color{black}, &\color{red}f_{b_2,b_3}\color{black}, &f_{b_1,b_3}, \\ &\; &\color{red}f_{b_1,b_2,b_3}\color{black} &\; \end{Bmatrix} \end{aligned}

And, finally, we isolate the behavior of the b3b_3 branch:

f(0010)0011    F3={  f,  fb1,fb2,fb3,fb1,b2,fb2,b3,fb1,b3,  fb1,b2,b3  }f(0010) \rightarrow 0011 \implies \begin{aligned} F_3 = \begin{Bmatrix} &\; &\color{red}f_\emptyset\color{black}, &\; \\ &\color{red}f_{b_1}\color{black}, &\color{red}f_{b_2}\color{black}, &\color{red}f_{b_3}\color{black}, \\ &\color{red}f_{b_1,b_2}\color{black}, &\color{red}f_{b_2,b_3}\color{black}, &f_{b_1,b_3}, \\ &\; &\color{red}f_{b_1,b_2,b_3}\color{black} &\; \end{Bmatrix} \end{aligned}

So we know that our given function must be fb1,b3f_{b_1,b_3}, but that took n=3n=3 total invocations for a mystery function with 3 inputs. Can we do better? We might experiment with more “sophisticated” input string combinations, but we’ll quickly find that regardless of our input to ff, we can never eliminate more than half the possible remaining answers at any iteration of this sluethy procedure.

To prove this, let’s consider what information we gain by sampling ff. Or, donning our Shannon deerstalker, perhaps a better question to ask is: how much information do we gain?

The answer is –perhaps obviously from the framing of the problem statement thus far– precisely 1 bit of information which gets encoded in the last bit of the output aa. So, the answer is, with classical computing techniques: … no, we cannot do better than nn queries to ff.

Suppose that there did exist a procedure which lets us identify the fF3f \in F_3 with only two invocations. We would have at our disposal 2 bits of information:

f()=a1f()=a2\begin{aligned} f(\bullet) = …a_1 \\ f(\bullet) = …a_2 \\ \end{aligned}

Leaving us with four possible combination of a1,a2a_1, a_2:

a1a2={00,01,10,11} a_1a_2 = \{ 00, 01, 10, 11\}

But there are still eight possible choices for fF3f \in F_3 and 2 bits of information still only inform on four of those possibilites, so we can conclude that any such procedure which claims perfect accuracy is WRONG since there’s simply not enough information. Not with classical computing techniques, that is. With quantum computing, we can get the number of invocations of ff down to one singular sample for any naturally numbered nn by leveraging some sick linear algebra on the properties of qubits.

Quantum

A qubit is the fundamental data type in quantum computing. Typically denoted ψ|\psi\rangle, with the bracket notation indicating that the value of xx can exist somewhere in between the two basic states: 0|0\rangle and 1|1\rangle. The measure of a qubit’s propinquity to each basic state is denoted as an amplitude:

1.0α0+1.01.0α1+1.0\begin{aligned} -1.0 \leq \alpha_{|0\rangle} \leq +1.0 \\ -1.0 \leq \alpha_{|1\rangle} \leq +1.0 \end{aligned}

And we can omit the amplitude’s subscript when the basic state being referenced is unambiguous.

Crucially, we don’t need a concrete implementation of a device which can replicate superposition (though this is more achievable than we might initially assume) in order to reason about quantum quantities.

Properties of Qubits

Measuring a qubit’s amplitude collapses it to one of its basic states depending on the amplitude. The exact rule governing which basic state is observed when a qubit collapses is given by the amplitude of that basic state squared:

p[x=0]=α2p\Big[|x\rangle = |0\rangle\Big] = \alpha^2

E.g. for a qubit x|x\rangle with amplitude α0=0.8\alpha_{|0\rangle} = 0.8, and since we know that the probability of observing one of the two possible basic states must sum to one, we have:

p[x=0]+p[x=1]=1p[x=0]=0.82=0.64    p[x=1]=10.64=0.36=0.62\begin{aligned} &p\Big[|x\rangle = |0\rangle\Big] + p\Big[|x\rangle = |1\rangle\Big] = 1 \\ &p\Big[|x\rangle = |0\rangle\Big] = 0.8^2 = 0.64 \\ \implies &p\Big[|x\rangle = |1\rangle\Big] = \sqrt{1- 0.64} = \sqrt{0.36} = 0.6^2 \end{aligned}

Note that this also allows for negative amplitudes, e.g. this is an equally valid quantum state for x|x\rangle to be in:

Since α02+α12=1\alpha_{|0\rangle}^2 + \alpha_{|1\rangle}^2 = 1.

Similarly to classical bits, for nn qubits, there are 2n2^n possible measurements which are the 2n2^n possible basic state configuration after measuring each of the qubits’ amplitudes. However, collections of qubits form quantum systems, the constituents of which cannot be meaningfully considered in isolation.

E.g. For n=2n=2 qubits, we have a system of 4 basic states:

With some amplitude on each of the basic states where the sum of the squares of said amplitudes is one:

p[x=00]=0.352p[x=01]=0.22p[x=10]=(0.47)2p[x=11]=0.7921 \begin{matrix} & p\Big[|x\rangle = |00\rangle\Big] = &0.35^2 \\ & p\Big[|x\rangle = |01\rangle\Big] = &0.2^2 \\ & p\Big[|x\rangle = |10\rangle\Big] = &(-0.47)^2 \\ & p\Big[|x\rangle = |11\rangle\Big] = &0.79^2 \\ \hline & & \sim 1 \end{matrix}

While it may seem natural to assume that each qubit on its own has distinct amplitudes on each of its basic states, this is not the case. Together, the nn qubits jointly have amplitudes on each of their 2n2^n basic states. This property is called quantum entanglement and is precisely what gives rise to the clever solutions found in quantum programming which are not possible with conventional approaches.

Quantum Programming

A quantum program takes as input nn qubits in some valid superposition of the 2n2^n basic states and takes them to some other (excluding the identity QP, I guess) valid super positions. In other words, a quantum program is any set of operations which satisfies the pre- and post-condition:

i2nαi=1\sum_i^{2^n} \alpha_i = 1

Where ii is expressed in base 10 [footnote, this is a base joke. Base two]. A quantum operation we might be interested in to solve the problem from earlier would be qubit negation on nn qubits. This can be achieved by “swapping” amplitudes of corresponding basic states. The operation can be visualized on a nn-dimensional cube. E.g., for n=3n=3:

The “toggle” or negation operation swaps a corner on the face of the cube where qi=0q_i = 0 with The corner where qi=1q_i = 1, and i{1,2,,n}i \in \{1, 2, …, n\}

This operation is one of three named for Mathematician Pauli, and is denoted XX or σx\sigma_x. We’ll cover the other two operations in a following section. Note that, without even knowing how to quantitatively represent this negation operation, we know that it is a valid one since it doesn’t violate the pre- and post-condition of squared amplitude summation to one.

To avoid have to bother validation summations for each quantum operation we might want to define, we can institute an abstraction constraint that these operations only define how each of the basic states are transformed in terms of one another rather than modifying amplitudes directly. This opens many direct analogs to linear algebra that might already be showing around the cracks of this ELI25AIDKALA2 explanation.

This abstraction constraint begs the question, though, what about non-basic states? E.g. what if we composed a 1-bit probabilistic operator with our negation “gate” which toggles the a qubit of a basic state with p=2/3p = 2/3 and does nothing the rest of the time:

RNG(q)={σx(q) if pU<2/3Id(q) if pU2/3RNG(q) = \begin{cases} \sigma_x(q) &\text{ if } p \sim U < 2/3 \\ \\ Id(q) &\text{ if } p \sim U \geq 2/3 \end{cases}

We can again visualize this behavior as a tree without having to worry our pretty little brains with any quantitative conception of what the hell we’re talking about (pictures r fun):

We can see that the probability of observing any of the basic states of this system is just the product of the probabilities of descending down any branch π\pi of this amplitude tree that results in that basic state 01|01\rangle:

p[AB=01]=iπ01pi=1×23×1=23p\big[|AB\rangle = |01\rangle\big] = \prod_{i \in \pi_{|01\rangle}} p_i = 1 \times \frac{2}{3} \times 1 = \frac{2}{3}

Quantum program analysis is almost identical, the only difference being that quantum instructions operate on amplitudes which can be negative whereas a classical stochastic decision tree operates on probabilities on the unit interval. Conveniently for us, this means that some of the amplitudes might cancel each other out, whereas in the classical context, probabilities are strictly additive (in the monotonically increasing sense of the word).

So far the two operations we’ve defined so far, σx\sigma_x and simple conditionals, don’t offer any further utility than those gates which are already available in classical circuitry as evidenced by their amplitude trees which don’t introduce any quantum branching:

p[C=1]=π{π1}iπpi=(1323111)+(1323111)=2/9+2/9=4/9\begin{aligned} p\big[C = 1\big] &= \sum_{\pi \in \{\pi_{|\bullet\bullet1\rangle}\}} \prod_{i \in \pi} p_i \\ &= \Big(\frac{1}{3}\cdot\frac{2}{3}\cdot1\cdot1\cdot1\Big) + \Big(\frac{1}{3}\cdot\frac{2}{3}\cdot1\cdot1\cdot1\Big) \\ &= 2/9 + 2/9 = 4/9 \end{aligned}

It’s now time to introduce non-trivial non-basic qubit states. Let’s define a unary function: Rotate(q):ψψRotate(q): |\psi\rangle \rightarrow |\psi\rangle with the following amplitude tree:

We can easily verify that it’s a valid quantum operation since it maps valid quantum states to other valid quantum states. Now suppose we have another operation ff which takes some qubit in the zero state and transforms it to a qubit with some amplitudes x,yx,y on each of its basic states s.t. x2+y2=1x^2 + y^2 = 1. We can (non-rigorously) check that RotateRotate is valid by passing f(q)f(q) as its input and examining the resultant amplitude tree:

Collapsing the amplitudes to measure the distribution over basic states, we get:

0=0.6x0.8y1=0.8x+0.6y    1=α02+α12=(0.6x0.8y)2+(0.8x+0.6y)2=0.36x2+0.64y22(0.48)xy+0.64x2+0.36y2+2(0.48)xy=x2+y2\begin{aligned} |0\rangle &= 0.6x -0.8y \\ |1\rangle &= 0.8x + 0.6y \\ \implies 1 &= \alpha_{|0\rangle}^2 + \alpha_{|1\rangle}^2 \\ &= (0.6x -0.8y)^2 + (0.8x + 0.6y)^2 \\ &= 0.36x^2 + 0.64y^2 \color{red}-2(0.48)xy\color{black} + 0.64x^2 + 0.36y^2 \color{red}+2(0.48)xy\color{black}\\ &= x^2 + y^2 \end{aligned}

So, RotateRotate is valid \blacksquare. An example of an invalid operation might be assignment. Yes, that most basic of instructions we might expect to see in a program:

q0q \leftarrow |0\rangle

Verboten! We can develop some intuition about this by subjecting assignment to the same procedural treatment as RotateRotate:

0=x+y1=0    1=α02+α12=(x+y)2+02=x2+y2+2xy    1+2xy1\begin{aligned} |0\rangle &= x + y \\ |1\rangle &= 0 \\ \implies 1 &= \alpha_{|0\rangle}^2 + \alpha_{|1\rangle}^2 \\ &= (x + y)^2 + 0^2 \\ &= x^2 +y^2 +2xy \\ &\implies 1 + 2xy \neq 1 \end{aligned}

Now, for a non-trivial quantum operation, and perhaps the most important (? depends who u ask, where my Hadamard truthers at), the Hadamard [Link to other mentions throughout the blog]:

Let’s observe how it behaves with some of our other operations:

And we can go a step further by enumerating the amplitudes on each of the basis states at each of the six steps of the program:

instr000\vert000\rangle001\vert001\rangle010\vert010\rangle011\vert011\rangle100\vert100\rangle101\vert101\rangle110\vert110\rangle111\vert111\rangle
init+1
Toggle(q1)0+1
Hadamard(q1)+0.71+0.71
Hadamard(q3)+0.5+0.5+0.5+0.5
if q1 and q2 Toggle(q3)+0.5+0.5+0.5+0.5
Hadamard(q3)+0.71+0.71

Note that – even though the +0.5+0.5 amplitude appears on the 011|011\rangle basic state, the final amplitude on this state is zero because both of the branches where it appears have inverse amplitudes which cancel each other out. And herein lies the crux of quantum programming: designing algorithms where the amplitude of undesirable quantum states cancel out:

p[q123=011]=11212112+11212112=0\begin{aligned} p\Big[q_{123} = |011\rangle\Big] = 1 &\cdot \frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}} \cdot 1 \cdot \frac{1}{\sqrt{2}} \\ & + 1 \cdot \frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}} \cdot 1 \cdot -\frac{1}{\sqrt{2}}\\ &=0 \end{aligned}

This isn’t always feasible, however. Sometimes the best we can do is leaving a subset of ”undesirable” output states with a minimal amount of amplitude and then relying on probabilistic correctness over a series of trials.

Designing Quantum Programs

Since the state of nn qubits can be fully described by a collection of 2n2^n amplitudes, it’s natural to model nn qubits as 2n2^n-dimensional vectors containing amplitudes on each of the basic states:

ψ=[0.570.020.120.030.350.050.190.71]    iαi2=1|\psi \rangle = \begin{bmatrix} -0.57 \\ 0.02 \\ 0.12 \\ 0.03 \\ -0.35 \\ -0.05 \\ 0.19 \\ -0.71 \end{bmatrix} \implies \sum_i |\alpha_i|^2 = 1

With a vector spanning eight dimensions (1 for each basis) corresponding to each of the basic states, we can easily visualize up to three of those dimensions. And, per the sum-squared amplitudes theorem, we can geometrically represent the state of the qubits as a point on the 2n2^n-dimensional unit sphere. This is fun to say, but for any number of qubits greater than 1, we need at least 4-dimensional space which is more than you might be able to visualize.3 Before getting bogged down with nn-dimensional visualizations, let’s play with our linear algebraic interpretation of qubit state for n=1n=1 which is nicely represented on the plane:

We can describe quantum instructions operating on qubits as matrices of transition amplitudes multiplied by the state vector.

Now, back to the harsh realities of n>3n > 3-dimensional space, suppose we have two qubits q1,q2q_1, q_2 and we want to compute the Hadamard matrix for this system: H2H^{\otimes 2}.

For Hq1H_{q_1}, we can just fill in transition amplitude entries in the matrix for basis state pairs where q2q_2 doesn't change:

Hq1=12[1010010110100101]H_{q_1} = \frac{1}{\sqrt 2} \begin{bmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ \end{bmatrix}

And, similarly we can compute Hq2H_{q_2} for values where q1q_1 doesn't change:

Hq2=12[1100110000110011]H_{q_2} = \frac{1}{\sqrt 2} \begin{bmatrix} 1 & 1 & 0 & 0 \\ 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 1 & 1 \\ \end{bmatrix}

Furthermore, we can compose them via normal matrix multiplication to compute H2=Hq1Hq2H^{\otimes 2} = H_{q_1}\otimes H_{q_2} – and order actually doesn't matter for these operations since they modify different qubits by construction:

H2=Hq1Hq2=Hq2Hq1 =12[1111111111111111]=[++++++++++]\begin{aligned} H^{\otimes 2} &= H_{q_1}H_{q_2} = H_{q_2}H_{q_1} \\ \\\ &= \frac{1}{\sqrt 2} \begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \\ \end{bmatrix} \\ &= \begin{bmatrix} + & + & + & + \\ + & - & + & - \\ + & + & - & - \\ + & - & - & + \\ \end{bmatrix} \end{aligned}

and we can further simplify the notation since the magnitude of all the entries are equivalent, and all we really care about is the sign.

Note as well that the "convolution" of H2H^{\otimes 2} is itself composed of HH:

H=[+++]    H2=[HHHH]    H3=[H2H2H2H2]Hn=[Hn1Hn1Hn1Hn1]\begin{aligned} H &= \begin{bmatrix} + & + \\ + & - \\ \end{bmatrix} \\ \implies H^{\otimes 2} &= \begin{bmatrix} H & H \\ H & -H \\ \end{bmatrix} \\ \implies H^{\otimes 3} &= \begin{bmatrix} H^{\otimes 2} & H^{\otimes 2} \\ H^{\otimes 2} & -H^{\otimes 2} \\ \end{bmatrix} \\ \vdots\\ H^{\otimes n} &= \begin{bmatrix} H^{\otimes n-1} & H^{\otimes n-1} \\ H^{\otimes n-1} & -H^{\otimes n-1} \\ \end{bmatrix} \\ \end{aligned}

Mystery Toggles Revisited

Finally, we can return to our mystery problem on nn toggles and leverage the Hadamard to improve upon our O(n)O(n) classical solution.

Our solution is as follows:

  1. initialize n+1n+1 qubits, 1 for each possible toggle as well as an accumulator,
  2. Toggle the accumulator
  3. Apply Hn1H^{\otimes n - 1}
  4. Invoke the oracle ff on our input string
  5. Apply Hn1H^{\otimes n - 1} again
  6. Measure the amplitudes of the system to identify which cases are absent from ff

To understand how and why this works, let's trace it for n=3n = 3, with f=fb2f = f_{b_2} (only the second toggle is present).

First, we create our 2n=82^n = 8 dimensional state vector representing all combinations of b1b2ab_1b_2a with all of the amplitude on the zero state:

ψ=[+0000000]  000001010011100101110111|\psi \rangle = \begin{bmatrix} + \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix} \; \begin{matrix} |000\rangle \\ |001\rangle \\ |010\rangle \\ |011\rangle \\ |100\rangle \\ |101\rangle \\ |110\rangle \\ |111\rangle \\ \end{matrix}

Next, we toggle the accumulator bit, transferring all the amplitude from 000001|000\rangle \rightarrow |001\rangle.

ψ=[0+000000]| \psi \rangle = \begin{bmatrix} 0 \\ + \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix}

Then, we apply H3H^{\otimes 3} to the state vector:

ψH3=[0+000000][++++++++++++++++++++++++++++++++++++]|\psi\rangle H^{\otimes 3} = \begin{bmatrix} 0 \\ \colorbox{yellow}{$+$} \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix} \begin{bmatrix} + & + & + & + & + & + & + & + \\ \colorbox{yellow}{$+$} & \colorbox{yellow}{$-$} & \colorbox{yellow}{$+$} & \colorbox{yellow}{$-$} &\colorbox{yellow}{$+$} & \colorbox{yellow}{$-$} &\colorbox{yellow}{$+$} & \colorbox{yellow}{$-$} &\\ + & + & - & - & + & + & - & - \\ + & - & - & + & + & - & - & + \\ + & + & + & + & - & - & - & - \\ + & - & + & - & - & + & - & + \\ + & + & - & - & - & - & + & + \\ + & - & - & + & - & + & + & - \\ \end{bmatrix}

and recall that matrix multiplication with a vector with a single entry of 1 essentially acts as a select on that column s.t. our resultant product is the second row of our Hadamard matrix as a column vector:

ψH3=[++++]|\psi\rangle H^{\otimes 3} = \begin{bmatrix} + \\ - \\ + \\ - \\ + \\ - \\ + \\ - \\ \end{bmatrix}

Then, we invoke ff on the quantum state which –if we remember that far back– toggles the accumulator iff b2b_2 in the input string is set. This has the effect of applying ff to each entry in the vector, examining the middle bit of each basis state:

f(ψH3)=[++++]000001010011100101110111f\big(|\psi\rangle H^{\otimes 3}\big) = \begin{bmatrix} + \\ - \\ \colorbox{yellow}{$-$} \\ \colorbox{yellow}{$+$} \\ + \\ - \\ \colorbox{yellow}{$-$} \\ \colorbox{yellow}{$+$} \\ \end{bmatrix} \begin{matrix} |000\rangle \\ |001\rangle \\ |010\rangle \\ |011\rangle \\ |100\rangle \\ |101\rangle \\ |110\rangle \\ |111\rangle \\ \end{matrix}

Note that, prior to this step, all states where the accumulator bit was 1 had negative amplitude, and all states where the accumulator bit was 0 had positive amplitude. When we invoke the oracle ff, the basis states where the accumulator doesn't change still have positive amplitude if the accumulator bit is unset and negative if it is set, just like before – but those basis states where the accumulator did get toggled now have the inverse amplitude pattern (- if a=0a = 0, and ++ if a=1a = 1) which encodes a sort of truth table for ff where positive amplitudes correspond to TODO: ???

In other words, taking the basis state 010|010\rangle which has negative amplitude implies that if b1=0,b2=1,a=0b_1 =0, b_2 = 1, a =0, then aa will be 11 after ff is called. Conversely, in 100|100\rangle the accumulator bit is unset since it has positive amplitude.

Now we run into another problem: if we were to try to measure the qubits now, the amplitudes would collapse to pure noise since all the magnitudes would cancel each other out and we'd effectively get a random 3-bit binary string as out output. To account for this, we just plop in another H3H^{\otimes 3} and, curiously, the purpose of this operation is completely different to the columnal selection from earlier since our state vector is no longer of the correct form to pick a single entry.

Again, it's useful to visualize what happens when we perform this multiplication:

f(ψH3)=[++++][++++++++++++++++++++++++++++++++++++]=+[11111111][11111111][11111111]+[11111111][11111111][11111111][11111111]+[11111111]    [11111111][02020202][11131113][00040004][11151113][02060202][11171111][00080000]000001010011100101110111\begin{aligned} f\big(|\psi\rangle H^{\otimes 3}\big) &= \begin{bmatrix} \color{blue} + \\ \color{blue} - \\ \color{blue} - \\ \color{blue} + \\ \color{blue} + \\ \color{blue} - \\ \color{blue} - \\ \color{blue} + \\ \end{bmatrix} \begin{bmatrix} + & + & + & + & + & + & + & + \\ + & - & + & - & + & - & + & - \\ + & + & - & - & + & + & - & - \\ + & - & - & + & + & - & - & + \\ + & + & + & + & - & - & - & - \\ + & - & + & - & - & + & - & + \\ + & + & - & - & - & - & + & + \\ + & - & - & + & - & + & + & - \\ \end{bmatrix} \\ \\ & =\color{blue}+\color{black} \begin{bmatrix} 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ \end{bmatrix} \color{blue}-\color{black} \begin{bmatrix} 1 \\ -1 \\ 1 \\ -1 \\ 1 \\ -1 \\ 1 \\ -1 \\ \end{bmatrix} \color{blue}-\color{black} \begin{bmatrix} 1 \\ 1 \\ -1 \\ -1 \\ 1 \\ 1 \\ -1 \\ -1 \\ \end{bmatrix} \color{blue}+\color{black} \begin{bmatrix} 1 \\ -1 \\ -1 \\ 1 \\ 1 \\ -1 \\ -1 \\ 1 \\ \end{bmatrix} \color{blue}-\color{black} \begin{bmatrix} 1 \\ 1 \\ 1 \\ 1 \\ -1 \\ -1 \\ -1 \\ -1 \\ \end{bmatrix} \color{blue}-\color{black}\begin{bmatrix} 1 \\ -1 \\ 1 \\ -1 \\ -1 \\ 1 \\ -1 \\ 1 \\ \end{bmatrix} \color{blue}-\color{black}\begin{bmatrix} 1 \\ 1 \\ -1 \\ -1 \\ -1 \\ -1 \\ 1 \\ 1 \\ \end{bmatrix} \color{blue}+\color{black}\begin{bmatrix} 1 \\ -1 \\ -1 \\ 1 \\ -1 \\ 1 \\ 1 \\ 1 \\ \end{bmatrix} \\ \\ &\implies \begin{bmatrix} 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1 \\ \end{bmatrix} \mapsto \begin{bmatrix} 0 \\ 2 \\ 0 \\ 2 \\ 0 \\ 2 \\ 0 \\ 2 \\ \end{bmatrix} \mapsto \begin{bmatrix} -1 \\ 1 \\ 1 \\ 3 \\ -1 \\ 1 \\ 1 \\ 3 \\ \end{bmatrix} \mapsto \begin{bmatrix} 0 \\ 0 \\ 0 \\ 4 \\ 0 \\ 0 \\ 0 \\ 4 \\ \end{bmatrix} \mapsto \begin{bmatrix} 1 \\ 1 \\ 1 \\ 5 \\ -1 \\ -1 \\ -1 \\ 3 \\ \end{bmatrix} \mapsto \begin{bmatrix} 0 \\ 2 \\ 0 \\ 6 \\ 0 \\ -2 \\ 0 \\ 2 \\ \end{bmatrix} \mapsto \begin{bmatrix} -1 \\ 1 \\ 1 \\ 7 \\ 1 \\ -1 \\ -1 \\ 1 \\ \end{bmatrix} \mapsto \begin{bmatrix} 0 \\ 0 \\ 0 \\ 8 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix} \begin{matrix} |000\rangle \\ |001\rangle \\ |010\rangle \\ |011\rangle \\ |100\rangle \\ |101\rangle \\ |110\rangle \\ |111\rangle \\ \end{matrix} \\ \end{aligned}

As we can see, as we compute the matrix multiplication all the amplitude values gradually accumulate on the 011|011\rangle basic state such that when we measure all the qubits, we learn the configuration of the mystery fF3f \in F_3 that we were given with p=1p = 1. The proof that this program is correct for fixed nn is trivial via programmatically enumerating all variations of ff.

If this seems like too convenient or mystically clever of a solution it's because this sequence of operations was discovered prior to the declaration of the problem statement. The problem of "mystery ff" was retconned as a problem to motivate this demonstration of a quantum system offering constant time solution to a problem with linear complexity by classic means. This problem is known as the Bernstein-Vazirani problem, and is one of many similarly contrived examples of "quantum supremacy."

Formally, the Bernstein-Vazirani4 problem is posed: given an oracle f:{0,1}n{0,1}f: \{0, 1\}^n \rightarrow \{0, 1\} where all that's known of ff is that it's output is the dot product between the input vector and a secret string s{0,1}ns \in \{0, 1\}^n modulo 2, we're tasked with finding ss s.t.

f(x)=xs=x1s1x2s2xnsnf(x) = x \cdot s = x_1s_1 \oplus x_2s_2 \oplus \cdots \oplus x_ns_n

More Math

Now that the gloves are off in terms of the linear algebra, let's revisit some of the earlier handwavey definitions of qubits and quantum gates.

Qubits as vectors

A qubit can be expressed as a linear combination of the amplitudes and the system's basis states:

ψ=a0+b1|\psi\rangle = a |0\rangle + b|1\rangle

where a,bCa, b \in \mathbb C, though we can largely ignore the complex components of pretty much all the systems and gates we'll cover (for explanations of the global phase described by complex components, ur gonna need an ELI35). As a linear combination, quantum states are easily expressed as vectors:

0=[10],1=[01]ψ=a0+b1=a[10]+b[01]=[a0]+[0b]=[ab]\begin{aligned} |0 \rangle = \begin{bmatrix}1 \\ 0\end{bmatrix}, &\quad |1 \rangle = \begin{bmatrix}0 \\ 1\end{bmatrix} \\ \\ |\psi\rangle &= a|0\rangle + b|1\rangle \\ &= a\begin{bmatrix}1 \\ 0\end{bmatrix} + b\begin{bmatrix}0 \\ 1\end{bmatrix} \\ &= \begin{bmatrix}a \\ 0\end{bmatrix} + \begin{bmatrix}0 \\ b\end{bmatrix}\\ &= \begin{bmatrix}a \\ b\end{bmatrix} \end{aligned}

The basis states of a quantum state vector span the 2D Hilbert Space which is just a well-defined complex vector space where the inner product exists.

Normalization Condition

The aforementioned "validity" rule for quantum states is known as the normalization condition:

a2+b2=1|a|^2 + |b|^2 = 1

For an nn-dimensional system, we sum over the squares of the amplitudes of all basic states:

iαi2=1\sum_i |\alpha_i|^2 = 1

Quantum Operations

Operations on single cubits can be expressed as 2x2 unitary and hermitian matrices. Unitary to ensure the conservation of amplitude, and Hermitian to ensure that the eigenvalues (measurable quantities which need to correspond to real world things) are real valued.5

A matrix UU is said to be unitary if its inverse equals its transpose conjugate (also known as the hermitian adjoint) UU^{\dagger}:

UU=UU=IU^{\dagger}U = UU^{\dagger} = I

The hermitian adjoint operation is a linear map which transposes an m×nm\times n complex matrix and conjugates each entry (negating the complex component).

A=[0a+bi00]    A=[00abi0]A = \begin{bmatrix} 0 & a + bi \\ 0 & 0 \\ \end{bmatrix} \implies A^{\dagger} = \begin{bmatrix} 0 & 0 \\ a - bi & 0 \\ \end{bmatrix}

For real matrices, the hermitian adjoint is just the transpose.

Bloch Sphere

Quantum operations on singular qubits can be visualized as maps between points on the unit sphere. As mentioned earlier, this also holds for systems of multiple qubits on hyper spheres but the utility of the Bloch sphere diminishes proportionately to one's ability to visualize higher dimensions and rotations therein.

Here, θ,ϕ\theta, \phi are the usual polar and azimuthal angles in spherical coordinate representation. The Pauli gates, then, are just rotations about these axes by π\pi radians. E.g.

Dˉ(nˉ,ϕ)=cos(ϕ2)Iisin(ϕ2)σnˉDˉ(xˉ,ϕ=π)=cos(π2)Iisin(π2)σnˉ=0iσx=σx\begin{aligned} \bar D(\bar n, \phi) &= \cos (\frac{\phi}{2})I - i\sin(\frac{\phi}{2})\vec\sigma \cdot \bar n \\ \bar D(\bar x, \phi = \pi) &= \cos (\frac{\pi}{2})I - i\sin(\frac{\pi}{2})\vec\sigma \cdot \bar n \\ &= 0 - i\vec\sigma_x \\ &= \sigma_x \\ \end{aligned}

again we drop the complex component since we're ignoring global phase of the quantum system, and just rotate dat boi about the x-axis (as observed in the planar example):

Similarly, this process yields a geometrically intuitive conception of the other two Pauli operations:

X:0σxi1X0=[0110][10]=[01]=1X1=[0110][01]=[10]=0Y:0σyi1Y0=[0ii0][10]=[0i]=i1Y1=[0ii0][01]=[i0]=i0Z:0σzi0Z0=[1001][10]=[01]=0Z1=[1001][01]=[01]=1\begin{aligned} X &: |0\rangle \xrightarrow {\sigma_x} i|1\rangle \\ &X|0\rangle = \begin{bmatrix}0 & 1 \\ 1 &0 \end{bmatrix}\begin{bmatrix}1 \\ 0 \end{bmatrix} = \begin{bmatrix}0 \\ 1 \end{bmatrix} = |1\rangle \\ &X|1\rangle = \begin{bmatrix}0 & 1 \\ 1 &0 \end{bmatrix}\begin{bmatrix}0 \\ 1 \end{bmatrix} = \begin{bmatrix}1 \\ 0 \end{bmatrix} = |0\rangle \\ \\ Y &: |0\rangle \xrightarrow {\sigma_y} i|1\rangle \\ &Y|0\rangle = \begin{bmatrix}0 & -i \\ i &0 \end{bmatrix}\begin{bmatrix}1 \\ 0 \end{bmatrix} = \begin{bmatrix}0 \\ i \end{bmatrix} = i|1\rangle \\ &Y|1\rangle = \begin{bmatrix}0 & -i \\ i &0 \end{bmatrix}\begin{bmatrix}0 \\ 1 \end{bmatrix} = \begin{bmatrix}-i \\ 0 \end{bmatrix} = -i|0\rangle\\ \\ \\ Z &: |0\rangle \xrightarrow {\sigma_z} i|0\rangle \\ &Z|0\rangle = \begin{bmatrix}1 & 0 \\ 0 & -1 \end{bmatrix}\begin{bmatrix}1 \\ 0 \end{bmatrix} = \begin{bmatrix}0 \\ 1 \end{bmatrix} = |0\rangle \\ &Z|1\rangle = \begin{bmatrix}1 & 0 \\ 0 & -1 \end{bmatrix}\begin{bmatrix}0 \\ 1 \end{bmatrix} = \begin{bmatrix}0 \\ 1 \end{bmatrix} = -|1\rangle \\ \end{aligned}

Note that each of these are involutory, meaning that their squares are equal to the identity matrix. From these Pauli matrices, we can also generalize to arbitrary rotation operations:

Rx(θ)=[cosθ2isinθ2isinθ2cosθ2]Ry(θ)=[cosθ2sinθ2sinθ2cosθ2]Rz(θ)=[eiθ200eiθ2]\begin{aligned} R_x(\theta) &= \begin{bmatrix} \cos \frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin \frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix} \\ \\ R_y(\theta) &= \begin{bmatrix} \cos \frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin \frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix} \\ \\ R_z(\theta) &= \begin{bmatrix} e^{-i\frac{\theta}{2}} & 0 \\ 0 & e^{i\frac{\theta}{2}} \end{bmatrix} \\ \end{aligned}

It should be clear(er) now that all qubit operations acting on an nn-dimensional quantum system map a point on the hypersphere to another point, which can always be achieved via some rotation, e.g.

H=12(X+Z)=12[0110]+[1001]=12[1111]\begin{aligned} H = \frac{1}{\sqrt{2}}(X + Z) &= \frac{1}{\sqrt{2}}\begin{bmatrix}0 & 1 \\ 1 & 0\end{bmatrix} + \begin{bmatrix}1 & 0 \\ 0 & -1\end{bmatrix} \\ &=\frac{1}{\sqrt{2}}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix} \end{aligned}

so the Hadamard is just a rotation about the diagonal on the xz-plane of the Bloch sphere. Two applications of a rotation by π\pi will complete a full revolution about the sphere, returning to the original point.

Multi-qubit Systems

Recall that singular qubits occupy 2D Hilbert Spaces:

ψHA,ϕHB|\psi\rangle \in \mathcal H_A, \quad |\phi\rangle \in \mathcal H_B

The state vector of a composite system of two qubits is given by the tensor product of the two constituent state vectors being combined, where the tensor product Ψ|\Psi\rangle is defined as follows:

Ψ=ψϕHAHBHAB=[αβ][γδ]=[α[γδ]β[γδ]]=[αγαδβγβδ]\begin{aligned} |\Psi\rangle &= |\psi\rangle \otimes |\phi\rangle \in \mathcal H_A \otimes \mathcal H_B \equiv \mathcal H_{AB} \\ &= \begin{bmatrix} \alpha \\ \beta\end{bmatrix} \otimes \begin{bmatrix} \gamma \\ \delta \end{bmatrix} = \begin{bmatrix} \alpha\begin{bmatrix} \gamma \\ \delta \end{bmatrix} \\ \beta\begin{bmatrix} \gamma \\ \delta \end{bmatrix} \end{bmatrix} \\ &=\begin{bmatrix} \alpha\gamma \\ \alpha\delta \\ \beta\gamma \\ \beta\delta \end{bmatrix} \end{aligned}

In other words, the basis vectors of a 2 qubit system in HAB\mathcal H_{AB} are comprehensively enumerated:

00=00=[1000]01=01=[0100]10=10=[0010]11=11=[0001]\begin{aligned} |00\rangle = |0\rangle \otimes |0\rangle = \begin{bmatrix}1 \\ 0 \\ 0 \\0 \end{bmatrix} \\ \\ |01\rangle = |0\rangle \otimes |1\rangle = \begin{bmatrix}0 \\ 1 \\ 0 \\0 \end{bmatrix} \\ \\ |10\rangle = |1\rangle \otimes |0\rangle = \begin{bmatrix}0 \\ 0 \\ 1 \\0 \end{bmatrix} \\ \\ |11\rangle = |1\rangle \otimes |1\rangle = \begin{bmatrix}0 \\ 0 \\ 0 \\1 \end{bmatrix} \end{aligned}

In general, the tensor product of two matrices is given by:

AB=[a11a12a21a22][b11b12b21b22]=[a11Ba12Ba21Ba22B]=[a11b11a11b12a12b11a12b12a11b21a11b22a12b21a12b22a21b11a21b12a22b11a22b11a21b21a21b22a22b21a22b22]\begin{aligned} A \otimes B &= \begin{bmatrix} \colorbox{yellow}{$a_{11}$} & \colorbox{green}{$a_{12}$} \\ \colorbox{cyan}{$a_{21}$} & \colorbox{magenta}{$a_{22}$} \\ \end{bmatrix} \otimes \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{bmatrix} = \begin{bmatrix} \colorbox{yellow}{$a_{11}$}B & \colorbox{green}{$a_{12}$}B \\ \colorbox{cyan}{$a_{21}$}B & \colorbox{magenta}{$a_{22}$}B \\ \end{bmatrix} \\ \\ &=\begin{bmatrix} \colorbox{yellow}{$a_{11}b_{11}$} & \colorbox{yellow}{$a_{11}b_{12}$} & \colorbox{green}{$a_{12}b_{11}$} & \colorbox{green}{$a_{12}b_{12}$} \\ \colorbox{yellow}{$a_{11}b_{21}$} & \colorbox{yellow}{$a_{11}b_{22}$} & \colorbox{green}{$a_{12}b_{21}$} & \colorbox{green}{$a_{12}b_{22}$} \\ \colorbox{cyan}{$a_{21}b_{11}$} & \colorbox{cyan}{$a_{21}b_{12}$} & \colorbox{magenta}{$a_{22}b_{11}$} & \colorbox{magenta}{$a_{22}b_{11}$} \\ \colorbox{cyan}{$a_{21}b_{21}$} & \colorbox{cyan}{$a_{21}b_{22}$} & \colorbox{magenta}{$a_{22}b_{21}$} & \colorbox{magenta}{$a_{22}b_{22}$} \\ \end{bmatrix} \end{aligned}

And since the tensor product is distributive, we can also write a combination of operations in such a way is explicates the fact that each quantum operator is acting independently on the composite state space:

(AB)(ψϕ)=AψBϕ(A \otimes B)(|\psi\rangle \otimes |\phi\rangle) = A|\psi\rangle \otimes B|\phi\rangle

With this representation of multi-qubit systems, we can introduce some multi-qubit operations.

Multi-qubit Operations

Thus far, we've only defined single-qubit gates/operations, but we can also perform some actions on multiple qubits at a time, with a few crucial distinctions from classical logic gates. For starters, quantum gates must be reversible. Whereas it's entirely common for classical logic gates to map multiple inputs to a single binary output, since quantum systems model state changes in physical systems, the modifications made to each of the inputs must also be expressed in the output. The above description is phrased as a constraint, but it's really just a natural conclusion from the prior definitions about quantum operations being unitary & hermitian – which lets us simply apply the adjoint of an operation to "undo" it.

classiscal gatereversible?
ANDsometimes
ORno
NOTyes
NANDno
XORno

It should be straightforward to convince yourself that the input vector to these gates is not definitively knowable given the output bit/vector.

CNOT

The Controlled-NOT gate is analogous to the the classical XOR which can be thought of as addition mod2\mod 2 given by the following truth table:

\oplus01
001
110

Observe that, for a 2 qubit system, q1q_1 remains unchanged, and the state vectors of q2HABq_2 \in \mathcal H_{AB} are swapped:

0000010110111110\begin{aligned} |00\rangle \mapsto |00\rangle \\ |01\rangle \mapsto |01\rangle \\ |10\rangle \mapsto |11\rangle \\ |11\rangle \mapsto |10\rangle \\ \end{aligned}

Algebraically, we can express this as the matrix:

UCNOT=[1000010000010010]U_{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}

We can use CNOT to swap the states of two qubits the same way we might swap two classical variables' values without introducing a tmp value with three XORs:

b1b_1b2b_2b1b2b_1 \oplus b_2b1(b1b2)b_1 \oplus (b_1 \oplus b_2)
0000
0111
1010
1101

so b1(b1b2)b2b_1 \oplus (b_1 \oplus b_2) \equiv b_2.

and, in fact, we can represent any C-gate applied to an operation UU with this procedure:

CU=[1000010000u00u0100u10u11]CU = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{00} & u_{01} \\ 0 & 0 & u_{10} & u_{11} \\ \end{bmatrix}

Toffoli

The Toffoli gate is effectively a CNOT on a 3-qubit system:

Toff:HABCHABC=(q1,q2,q3)(q1,q2,q3q1q2)\begin{aligned} Toff &: \mathcal H_{ABC} \rightarrow H_{ABC} \\ &= (q_1, q_2, q_3) \rightarrow (q_1, q_2, q_3 \oplus q_1q_2) \end{aligned}

The Toffoli truth table indicates that q1,q2q_1, q_2 remain unchanged, and q3q_3 only changes if both q1=q2=1q_1 = q_2 = 1:

q1q_1q2q_2q3q_3q1q_1'q2q_2'q3q_3'
000000
001001
010010
011011
100100
101101
110111
111110

Entanglement

Recall from the section about multi-qubit states the expression:

(AB)(ψϕ)=AψBϕ(A \otimes B)(|\psi\rangle \otimes |\phi\rangle) = A|\psi\rangle \otimes B|\phi\rangle

When a 2-qubit composite state function can be expressed as a tensor product of the constituent qubit states like this, then the composite state is said to be separable. E.g.

ψϕ=(α0+β1)(γ0+δ1)=αγ00+αδ01+βγ10+βγ11    α00=αγα01=αδα10=βγα11=βδ    α00α01=α10α110=α00α11α10α01\begin{aligned} |\psi\rangle \otimes |\phi\rangle &= (\alpha |0\rangle + \beta |1\rangle) \otimes (\gamma |0\rangle + \delta |1\rangle) \\ &= \alpha\gamma|00\rangle + \alpha\delta|01\rangle + \beta\gamma|10\rangle + \beta\gamma|11\rangle \\ \\ \implies \alpha_{00} &= \alpha\gamma \\ \alpha_{01} &= \alpha\delta \\ \alpha_{10} &= \beta\gamma \\ \alpha_{11} &= \beta\delta \\ \\ \implies \frac{\alpha_{00}}{\alpha_{01}} &= \frac{\alpha_{10}}{\alpha_{11}} \\ 0 &= \alpha_{00}\alpha_{11} - \alpha_{10}\alpha_{01} \end{aligned}

For example, we can show that the following quantum state is separable:

ψ=120+121HAϕ=0HB\begin{aligned} |\psi\rangle &= \frac{1}{\sqrt 2} |0\rangle + \frac{1}{\sqrt 2} |1\rangle \in \mathcal H_A \\ |\phi\rangle &= |0\rangle \in \mathcal H_B \end{aligned}

The tensor product between ψ|\psi\rangle and ϕ|\phi\rangle yields the following composite state:

ψϕ=1200+1210HAB|\psi\rangle \otimes |\phi\rangle = \frac{1}{\sqrt 2} |00\rangle + \frac{1}{\sqrt 2} |10\rangle \in \mathcal H_{AB}

And we can verify this is separable by checking if the product of the differences of amplitudes along the major and minor diagonals cancel each other out:

α00=12α01=0α10=12α11=0    α00α11α10α01=0120120=0\begin{aligned} \alpha_{00} &= \frac{1}{\sqrt 2} \\ \alpha_{01} &= 0 \\ \alpha_{10} &= \frac{1}{\sqrt 2} \\ \alpha_{11} &= 0 \\ \\ \implies \alpha_{00}\alpha_{11} - \alpha_{10}\alpha_{01} &= 0 \\ \frac{1}{\sqrt 2}\cdot 0 - \frac{1}{\sqrt 2} \cdot 0 &= 0 \\ \end{aligned}

which should be a surprise since this composite state was constructed from separated states via the tensor product :p. By means of counter example, let's take a look at a special quantum state in HAB\mathcal H_{AB}:

Φ+=1200+1211α00=12α01=0α10=0α11=12    α00α11α10α01=01212000\begin{aligned} |\Phi^+\rangle = \frac{1}{\sqrt 2} |00\rangle &+ \frac{1}{\sqrt 2} |11\rangle\\ \\ \alpha_{00} &= \frac{1}{\sqrt 2} \\ \alpha_{01} &= 0 \\ \alpha_{10} &= 0 \\ \alpha_{11} &= \frac{1}{\sqrt 2} \\ \\ \implies \alpha_{00}\alpha_{11} - \alpha_{10}\alpha_{01} &= 0 \\ \frac{1}{\sqrt 2}\cdot \frac{1}{\sqrt 2} - 0 \cdot 0 &\neq 0 \\ \end{aligned}

Since the amplitudes don't cancel out, this state is inseparable or entangled. This quantum state Φ+|\Phi^+\rangle is one of four maximally entangled systems referred to as the Bell States.

Φ+=12(0A0B)+12(1A1B)=1200+1211Φ=12(0A0B)+12(1A1B)=12001211Ψ+=12(0A1B)+12(1A0B)=1201+1210Ψ=12(0A1B)+12(1A0B)=12011210\begin{aligned} |\Phi^+\rangle &= \frac{1}{\sqrt 2} (|0\rangle_A \otimes |0\rangle_B) + \frac{1}{\sqrt 2} (|1\rangle_A \otimes |1\rangle_B) \\ &= \frac{1}{\sqrt 2} |00\rangle + \frac{1}{\sqrt 2} |11\rangle\\ \\ |\Phi^-\rangle &= \frac{1}{\sqrt 2} (|0\rangle_A \otimes |0\rangle_B) + \frac{1}{\sqrt 2} (|1\rangle_A \otimes |1\rangle_B) \\ &= \frac{1}{\sqrt 2} |00\rangle - \frac{1}{\sqrt 2} |11\rangle\\ \\ |\Psi^+\rangle &= \frac{1}{\sqrt 2} (|0\rangle_A \otimes |1\rangle_B) + \frac{1}{\sqrt 2} (|1\rangle_A \otimes |0\rangle_B) \\ &= \frac{1}{\sqrt 2} |01\rangle + \frac{1}{\sqrt 2} |10\rangle\\ \\ |\Psi^-\rangle &= \frac{1}{\sqrt 2} (|0\rangle_A \otimes |1\rangle_B) + \frac{1}{\sqrt 2} (|1\rangle_A \otimes |0\rangle_B) \\ &= \frac{1}{\sqrt 2} |01\rangle - \frac{1}{\sqrt 2} |10\rangle\\ \end{aligned}

and they can be constructed with some Hadamard and CNOT gates as follows:

construction of Φ+|\Phi^+\rangle

Φ+=12(00+11)=UCNOT(HI)(00)=UCNOT(00)=UCNOT(00)=UCNOT(H0I0)=UCNOT(+0)=UCNOT(12[1010])=[1000010000010010]12[1010]=12[1000]=12([1000]+[0001])=12(00+11)\begin{aligned} |\Phi^+\rangle &= \frac{1}{\sqrt 2}(|00\rangle + |11\rangle) \\ \\ &= U_{CNOT}(H \otimes I)(|0\rangle \otimes |0\rangle) \\ &= U_{CNOT}(|0\rangle \otimes |0\rangle) = U_{CNOT}(|00\rangle) \\ &= U_{CNOT}(H|0\rangle \otimes I|0\rangle) \\ &= U_{CNOT}(|+\rangle \otimes |0\rangle) =U_{CNOT}(\frac{1}{\sqrt 2}\begin{bmatrix}1 \\ 0 \\ 1 \\ 0 \end{bmatrix}) \\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}\frac{1}{\sqrt 2}\begin{bmatrix}1 \\ 0 \\ 1 \\ 0 \end{bmatrix} = \frac{1}{\sqrt 2}\begin{bmatrix}1 \\ 0 \\ 0 \\ 0 \end{bmatrix} \\ \\ &= \frac{1}{\sqrt 2} \begin{pmatrix} \begin{bmatrix}1 \\ 0 \\ 0 \\ 0 \end{bmatrix} + \begin{bmatrix}0 \\ 0 \\ 0 \\ 1 \end{bmatrix} \end{pmatrix} = \frac{1}{\sqrt 2}(|00\rangle + |11\rangle) \end{aligned}

construction of Φ|\Phi^-\rangle

Φ+=12001211=(IZ)Φ+=(IZ)UCNOT(HI)(00)\begin{aligned} |\Phi^+\rangle &= \frac{1}{\sqrt 2} |00\rangle - \frac{1}{\sqrt 2} |11\rangle\\ \\ &= (I \otimes Z)|\Phi^+\rangle \\ &= (I \otimes Z)U_{CNOT}(H \otimes I)(|0\rangle \otimes |0\rangle) \\ \end{aligned}

construction of Ψ+|\Psi^+\rangle

Ψ+=1201+1210=(IX)Φ+=(IX)UCNOT(HI)(00)\begin{aligned} |\Psi^+\rangle &= \frac{1}{\sqrt 2} |01\rangle + \frac{1}{\sqrt 2} |10\rangle\\ \\ &= (I \otimes X)|\Phi^+\rangle \\ &= (I \otimes X)U_{CNOT}(H \otimes I)(|0\rangle \otimes |0\rangle) \\ \end{aligned}

construction of Ψ|\Psi^-\rangle

Ψ=12011210=(IZ)Ψ+=(IZ)(IX)UCNOT(HI)(00)\begin{aligned} |\Psi^-\rangle &= \frac{1}{\sqrt 2} |01\rangle - \frac{1}{\sqrt 2} |10\rangle\\ \\ &= (I \otimes Z)|\Psi^+\rangle \\ &= (I \otimes Z)(I \otimes X)U_{CNOT}(H \otimes I)(|0\rangle \otimes |0\rangle)\\ \end{aligned}

But what does it mean to be maximally entangled? Before tackling this question, or motivating even why we care, it's time to really get our hands dirty.

Dir-Ac notation

Commonly referred to as "bra-ket" notation, but it's more fun and kind of conventional to summon up some new fangled notation to become one-up on your academic peers.

Ket's we're familiar with, but what the hell was Dirac smoking with those bras.6 First let's consider a linear function x\ell_x which maps a 2-dimensional vector to a scalar by just shitting out the xx component of its input:

x:R2Rxv=vxx[vxvy]=vx\begin{aligned} \ell_x &: \mathbb R^2 \rightarrow \mathbb R \\ \ell_x\vec v &= v_x \\ \ell_x\begin{bmatrix} v_x \\ v_y\end{bmatrix} &= v_x \\ \end{aligned}

x\ell_x is indeed a linear map since it satisfies the following properties:

x(u+x)=xu+xvx(cv)=ccv\begin{aligned} \ell_x (\vec u + \vec x) &= \ell_x\vec u + \ell_x\vec v \\ \ell_x (c\vec v ) &= c\ell_c\vec v \end{aligned}

Linear maps of this form which take an element of our vector space and shit out a scalar are called linear functionals. The algebraic representation of x\ell_x will be a 2x1 matrix, AKA a row vector:

x=[10]\ell_x = \begin{bmatrix}1 & 0\end{bmatrix}

All linear functionals in R2\mathbb R^2 are two-dimensional row vectors. In other words, the set of all linear functions in R2\mathbb R^2 is the set of all row vectors of the form [ab]\begin{bmatrix}a & b\end{bmatrix}, and thus this set forms its own vector space known as the dual space.

Formally, given a vector space VV, the dual space VV^* is the vector space of all linear functionals in VV. Linear functionals find natural relevance in quantum mechanics wherever we want to measure a quantum state which is the process of "collapsing" the quantum state into a single number which resembles x:R2R\ell_x : \mathbb R^2 \rightarrow \mathbb R.

We denote linear functionals in quantum mechanics as those functions of the dual of the Hilbert space with "bras": ϕH\langle \phi | \in \mathcal H^*, operating on kets. Note how when we smush a bra together with a ket, we get something that looks an awful lot like an inner product:

ϕψ=c[10][ab]=1a+0b[10][ab]\begin{aligned} \langle \phi | |\psi\rangle &= c \\ \begin{bmatrix}1 & 0\end{bmatrix}\begin{bmatrix}a \\ b\end{bmatrix} &= 1 \cdot a + 0 \cdot b \equiv \begin{bmatrix}1 \\ 0\end{bmatrix}\begin{bmatrix}a \\ b\end{bmatrix} \end{aligned}

any R2\ell \in \mathbb R^2 acts on any vector and can be expressed as a dot product by translating \ell into a column vector courtesy of the Riesz Representation Theorem.7 I guess this is like significant if you're smart enough to have mentally bifurcated row vector/matrix multiplication as different than the dot product and thus this revelation may seem inobvious or maybe even haram. But, obviously, my brain was already rotating row vectors into column vectors (or maybe the other way around, idek), without realizing the profundity of being able to do so.

For any linear functional ϕ\ell_\phi, the action of ϕ\ell_\phi is equivalent to taking the inner product with some unique vector ϕ\vec \phi:

ϕv=ϕv\ell_\phi\vec v = \vec \phi \cdot \vec v

So, it's no mistake that:

ϕψϕψ\langle \phi||\psi\rangle \equiv \langle \phi|\psi\rangle

This is useful for increasingly many reasons (as I'm realizing). Take, for example, the orthonormal basis of the vector space of a quantum system to be:

B1,B2,B3,...|\mathcal B_1\rangle, |\mathcal B_2\rangle, |\mathcal B_3\rangle, ...

and an arbitrary qubit of the system as:

ψ=iαiBi|\psi\rangle = \sum_i \alpha_i |\mathcal B_i\rangle

Since all of the states are orthonormal, we can compute their amplitude coefficients as:

αi=Biψ=iBiψBi=iBiBiψ=(iBiBi)ψ\begin{aligned} \alpha_i &= \langle \mathcal B_i |\psi\rangle \\ &= \sum_i \langle \mathcal B_i |\psi\rangle |\mathcal B_i \rangle \\ &= \sum_i |\mathcal B_i\rangle \langle \mathcal B_i |\psi\rangle \\ &= \Big(\sum_i |\mathcal B_i\rangle \langle \mathcal B_i \Big)|\psi\rangle \\ \end{aligned}

and for any orthonormal basis, this sum must be equal to the identity matrix e.g. for some arbitrary bases:

B1=[100],B2=[010],B3=[001]iBiBi=iBiBi=i[b1b1b1b2b1b3b2b1b2b2b2b3b3b1b3b2b3b3]=([100][100])+([010][010])+([001][001])=[100000000]+[000010000]+[000000001]=[100010001]=I\begin{aligned} \mathcal B_1 = \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix}, \mathcal B_2 &= \begin{bmatrix}0 \\ 1 \\ 0\end{bmatrix}, \mathcal B_3 = \begin{bmatrix}0 \\ 0 \\ 1\end{bmatrix} \\ \\ \sum_i |\mathcal B_i\rangle \langle\mathcal B_i| &= \sum_i \colorbox{yellow}{$\mathcal B_i$} \otimes \mathcal B_i \\ &= \sum_i \begin{bmatrix} \colorbox{yellow}{$b_{1}$}b_{1} & \colorbox{yellow}{$b_{1}$}b_{2} & \colorbox{yellow}{$b_{1}$}b_{3} \\ \colorbox{yellow}{$b_{2}$}b_{1} & \colorbox{yellow}{$b_{2}$}b_{2} & \colorbox{yellow}{$b_{2}$}b_{3} \\ \colorbox{yellow}{$b_{3}$}b_{1} & \colorbox{yellow}{$b_{3}$}b_{2} & \colorbox{yellow}{$b_{3}$}b_{3} \\ \end{bmatrix} \\ \\ &=\begin{pmatrix} \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix} \otimes \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix} \end{pmatrix} + \begin{pmatrix} \begin{bmatrix}0 \\ 1 \\ 0\end{bmatrix} \otimes \begin{bmatrix}0 \\ 1 \\ 0\end{bmatrix} \end{pmatrix} + \begin{pmatrix} \begin{bmatrix}0 \\ 0 \\ 1\end{bmatrix} \otimes \begin{bmatrix}0 \\ 0 \\ 1\end{bmatrix} \end{pmatrix}\\ \\ &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{bmatrix} + \begin{bmatrix} 0 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \\ \end{bmatrix} + \begin{bmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} \\ \\ &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} = I \end{aligned}

Measures of Entanglement

There are two measures of entanglement we'll consider. The first being the Positive Partial Transpose, and the second being a more comfy Von Neumann entropic measure.

Positive Partial Transpose

Let ΨHAB|\Psi \rangle \in \mathcal H_{AB}, and the density matrix ρ=ΨΨ\rho = |\Psi \rangle \langle \Psi|. The trace of ρ\rho (the sum of the eigenvalues, including duplicates), is given by:

Tr(ρ)=j,k=0,1(jk)ΨΨ(jk)Tr(\rho) = \sum_{j,k = 0, 1} \big(\langle j | \otimes \langle k|\big)|\Psi\rangle\langle \Psi|\big(| j\rangle \otimes |k\rangle\big)

which is the sum of the inner product with the basis vectors of the composite state. For an n=2n=2 qubit system, we have 4 basis states, the trace of which is a scalar. The partial trace of a density matrix is the trace only on a part (or slice) of the Hilbert space, and yields what is known as the reduced density matrix:

ρA=TrB(ρ)=k=0,1(Ik)ΨΨ(Ik)\rho_A = Tr_B(\rho) = \sum_{k = 0, 1}\big(I \otimes \langle k|\big) |\Psi\rangle\langle \Psi| \big(I \otimes |k\rangle\big)

So, for example:

ψ=α0000+α0101+α1010+α1111|\psi\rangle = \alpha_{00}|00\rangle + \alpha_{01}|01\rangle + \alpha_{10}|10\rangle + \alpha_{11}|11\rangle

the density matrix is:

ρ=i,j,k,lαijαklijkl    ρA=i,j,kαijαkjik\begin{aligned} \rho &= \sum_{i,j,k,l} \alpha_{ij}\alpha^*_{kl} |ij\rangle \langle kl| \\ \implies \rho_A &= \sum_{i,j,k} \alpha_{ij}\alpha^*_{kj} |i\rangle \langle k| \end{aligned}

we can see that the partial reduced density matrix collapses the outer product between the j,lj, l kets where the indices j=lj =l, thus the density matrix of ρA\rho_A is a 2x2, whereas ρ\rho is 4x4. We can recast ρA\rho_A in terms of the outer products of μ\mu via substitution:

ρA=j(iαiji)(kαkjk)=jμjμj=jpjμ~jμ~j\begin{aligned} \rho_A &= \sum_j\Big(\sum_i \alpha_{ij}|i\rangle \Big)\Big(\sum_k \alpha^*_{kj}\langle k| \Big) \\ &= \sum_j |\mu_j\rangle \langle \mu_j| \\ &= \sum_j p_j|\tilde\mu_j\rangle \langle \tilde\mu_j| \\ \end{aligned}

where μ~\tilde\mu is just the normalize version of μ\mu and

μ~j=pjμjpj=αij2,0pj1\begin{aligned} |\tilde\mu_j\rangle &= \sqrt p_j |\mu_j \rangle \\ p_j &= \sum |\alpha_{ij}|^2, \quad 0 \leq p_j \leq 1 \end{aligned}

so the trace of the square of the partial density matrix is then:

Tr(ρA2)=k,k=pkμ~kμ~kμ~kμ~k=k,kpkδkk=kpk=kiαik2=1\begin{aligned} Tr(\rho_A^2) &= \sum_{k', k} =p_k \langle \tilde\mu_{k'} | \tilde\mu_{k}\rangle\langle \tilde\mu_{k} | \tilde\mu_{k'}\rangle \\ &= \sum_{k', k}p_k \delta_{kk'} = \sum_k p_k \\ &= \sum_k\sum_i |\alpha_{ik}|^2 = 1 \end{aligned}

In other words, ρA\rho_A is normalized, so:

Tr(ρA2)=k,k=pkμ~k(μ~kμ~μ~kμ~)μ~k=k,kpk2δkk=kpk2=k(iαik2)21\begin{aligned} Tr(\rho_A^2) &= \sum_{k', k} = p_k \langle \tilde\mu_{k'} | \Big(|\tilde\mu_k\rangle \langle\tilde\mu| \cdot |\tilde\mu_k\rangle \langle\tilde\mu|\Big) | \tilde\mu_{k'} \rangle \\ &= \sum_{k',k} p^2_k\delta_{kk'} = \sum_k p^2_k \\ &= \sum_k\Big( \sum_i |\alpha_{ik}|^2\Big)^2 \leq 1 \end{aligned}

And so we can use the trace of the square of a partial density matrix as a relevant and bounded measure of the degree of entanglement.

For example, the measure of entanglement of a separable state:

Ψ=ψϕHABρA=TrB(ρ)=k=0,1(Ik)(ψϕ)(ψϕ)(Ik)=ψψk=0,1kϕkϕ=ψψ    Tr(ρA2)=1\begin{aligned} |\Psi\rangle &= |\psi\rangle \otimes |\phi\rangle \in \mathcal H_{AB}\\ \\ \rho_A = Tr_B(\rho) &= \sum_{k = 0, 1} \big(I \otimes \langle k|\big) \big(|\psi\rangle \otimes | \phi\rangle\big) \big(\langle\psi| \otimes \langle \phi|\big) \big(I \otimes |k\rangle\big)\\ &= |\psi\rangle \langle\psi| \sum_{k=0,1} \langle k | \phi \rangle\langle k | \phi \rangle \\ &= |\psi\rangle \langle\psi| \\ \implies Tr(\rho_A^2) &= 1 \end{aligned}

Which means that we have exact information about the quantum system since the reduced density matrix is a pure state given by a single outer product instead of e.g. a mixture of outer products.

An impure, or mixed state for the partial density matrix of a non-separable state would have the form:

ρA=00+11+    Tr(ρA2)<1\begin{aligned} \rho_A &= |0\rangle\langle0| + |1\rangle\langle1| + \cdots \\ \\ \implies Tr(\rho_A^2) &< 1 \end{aligned}

Perfect mixed states are those where there is zero measurable information of the system, the partial density matrix of which are proportional to the identity matrix:

ρA=12I    Tr(ρA2)=12 \begin{aligned} \rho_A &= \frac{1}{2}I \\ \\ \implies Tr(\rho_A^2) &= \frac{1}{2} \end{aligned}

implying that we have equal likelihood of measuring a qubit's state in any of the basis states. The bounds for our measure of entanglement, then, is:

12Tr(ρA2)1\frac{1}{2} \leq Tr(\rho^2_A)\leq 1

An example of a maximally entangled state could be any of the Bell states:

Φ+=12001211ρ=Φ+Φ+=12(0000+0101+1010+1111)ρA=TrB(ρ)=12(00+11)=[1/2001/2]    ρA2=[1/4001/4]Tr(ρA2)=1/2\begin{aligned} |\Phi^+\rangle &= \frac{1}{\sqrt 2} |00\rangle - \frac{1}{\sqrt 2} |11\rangle\\ \\ \rho &= |\Phi^+\rangle \langle\Phi^+|\\ &= \frac{1}{2}\Big( |0\rangle \langle 0| \otimes |0\rangle \langle 0| + |0\rangle \langle 1| \otimes |0\rangle \langle 1| + |1\rangle \langle 0| \otimes |1\rangle \langle 0| + |1\rangle \langle 1| \otimes |1\rangle \langle 1| \Big)\\ \\ \rho_A = Tr_B(\rho) &= \frac{1}{2}\Big(|0\rangle \langle 0| + |1\rangle \langle 1| \Big)\\ \\ &= \begin{bmatrix} 1/2 & 0 \\ 0 & 1/2 \end{bmatrix} \implies \rho^2_A = \begin{bmatrix} 1/4 & 0 \\ 0 & 1/4 \end{bmatrix} \\ Tr(\rho_A^2) &= 1/2 \end{aligned}

This, if nothing else, is an illustrative example of how linear functionals behave, but is a rather painful measure of entanglement.

Von Neumann Entropy

An equally valid measure of disorder of a quantum system is Von Neumann Entropy, defined as:

E=xp(x)logp(x)E = - \sum_x p(x)\log p(x)

For quantum systems p(x)p(x) is equivalent to measuring the state vector ψi|\psi_i \rangle|. We can show that Von Neumann entropy is equivalent to:

E(ρ)=Tr(ρlogρ)E(\rho) = - Tr(\rho \log \rho)

Working backwards from the classical definition, and recalling that the eigenvalues of ρ\rho correspond to the measurable quantities of our quantum system we replace p(x)=pip(x) = p_i with the eigenvalues λi\lambda_i:

E=iλilogλiE = - \sum_i \lambda_i \log \lambda_i

We can derive this result from the definition of the density matrix:

ρ=ipiψiψi\rho = \sum_i p_i |\psi_i\rangle\langle\psi_i|

which is equivalent to the spectral decomposition of the matrix formed by the outer product within the sum above:

ρ=iλiii\rho = \sum_i \lambda_i |i\rangle\langle i|

This will be a diagonal matrix of the form

[λ10000λ200000000λn]\begin{bmatrix} \lambda_1 & 0 & 0 & 0 \\ 0 & \lambda_2 & 0 & 0 \\ 0 & 0 & \ddots & 0 \\ 0 & 0 & 0 & \lambda_n \\ \end{bmatrix}

where nn specifies the dimensionality of the Hilbert space of the system, and the diagonal matrix is in the basis of i|i\rangle. Plugging this expression of ρ\rho back into the Von Neumann definition, the sum can be written as the TraceTrace operation:

E(ρ)=Tr[iλiiilog(jλjjj)]=Tr[iλiii(jlog(λj)jj)]=Tr[ijλilog(λj)iijj]\begin{aligned} E(\rho) &= - Tr\Bigg[\sum_i \lambda_i |i\rangle\langle i| \log \Big(\sum_j \lambda_j |j\rangle\langle j|\Big)\Bigg] \\ \\ &= - Tr\Bigg[\sum_i \lambda_i |i\rangle\langle i| \Big(\sum_j \log(\lambda_j) |j\rangle\langle j|\Big)\Bigg] \\ \\ &= - Tr\Bigg[\sum_i \sum_j \lambda_i \log(\lambda_j) |i\rangle\langle i |j\rangle\langle j|\Bigg] \\ \end{aligned}

Note that ij\langle i | j\rangle is equivalent to the Kronecker delta:

δi,j={1 if i=j0 if ij\delta_{i,j} = \begin{cases} 1 &\text{ if } i =j\\ 0 &\text{ if } i \neq j\\ \end{cases}

so

E(ρ)=Tr[ijλilog(λj)ij]=iλilog(λi)Tr(ij)=iλilog(λi)I=iλilog(λi)\begin{aligned} E(\rho) &= - Tr\Bigg[\sum_i \sum_j \lambda_i \log(\lambda_j) |i\rangle\langle j|\Bigg] \\ \\ &= - \sum_i \lambda_i \log(\lambda_i) Tr\Big(|i\rangle\langle j|\Big) \\ \\ &= - \sum_i \lambda_i \log(\lambda_i) I \\ \\ &= - \sum_i \lambda_i \log(\lambda_i) \\ \end{aligned}

And, since we know that λ[0,1]\lambda \in [0, 1] since they correspond to the probabilities of measuring a given basic state, we can note that:

limλ0λlnλ=0limλ1λlnλ=0limλ1eλlnλ=1\begin{aligned} \lim_{\lambda \rightarrow 0} &-\lambda \ln \lambda = 0 \\ \lim_{\lambda \rightarrow 1} &-\lambda \ln \lambda = 0 \\ \lim_{\lambda \rightarrow \frac{1}{e}} &-\lambda \ln \lambda = 1 \\ \end{aligned}

And we can sanity check this measure of entanglement as we did with the fucked up one I presented above. For a pure, separable state, we have:

ρ=ψψλ1=1E(ρ)=0\begin{aligned} \rho &= |\psi\rangle\langle \psi | \\ \lambda_1 &= 1 \\ E(\rho) &= 0 \end{aligned}

And, for a finite8 Hilbert space of dimension dd, Von Neumann entropy is upper bounded by logd\log d.

For example, for the near-Bell state:

ψ=12[0010]=12[1010]|\psi \rangle = \frac{1}{\sqrt 2} \Big[ |00\rangle - |10\rangle\Big] = \frac{1}{\sqrt 2} \begin{bmatrix}1 \\ 0 \\ -1 \\0\end{bmatrix}

The density matrix, and partial density matrices thereof will be:

ρ=ψψ=12[000000101000+1001]ρA=TrB(ρ)=12[000000101000+1001]=12[1111]    λρA={0,1}ρB=TrA(ρ)=12[000000101000+1001]=12[1111]    λρB={0,1}    E(ρA)=E(ρB)=Tr(ρAlogρA)=iλilogλi=0\begin{aligned} \rho &= |\psi \rangle \langle\psi | \\ &= \frac{1}{2}\Big[|00\rangle\langle00| - |00\rangle\langle10| - |10\rangle\langle00| + |10\rangle\langle01|\Big] \\ \\ \rho_A &= Tr_B(\rho) \\ &= \frac{1}{2}\Big[|00\rangle\langle00| - |00\rangle\langle10| - |10\rangle\langle00| + |10\rangle\langle01|\Big] \\ &= \frac{1}{2}\begin{bmatrix}1 & -1 \\ -1 & 1\end{bmatrix} \\ &\implies \lambda_{\rho_A} = \{0, 1 \} \\ \\ \rho_B &= Tr_A(\rho) \\ &= \frac{1}{2}\Big[|00\rangle\langle00| - |00\rangle\langle10| - |10\rangle\langle00| + |10\rangle\langle01|\Big] \\ &= \frac{1}{2}\begin{bmatrix}1 & -1 \\ -1 & 1\end{bmatrix} \\ &\implies \lambda_{\rho_B} = \{0, 1 \} \\ \\ \implies E(\rho_A) = E(\rho_B) &= - Tr(\rho_A \log \rho_A) = - \sum_i \lambda_i \log \lambda_i \\ &= 0 \end{aligned}

9

Hidden Linear Function Problem

We'll consider now another problem10

Given a binary lattice G=(V,E)G = (V, E), where n=Vn = |V|, a binary vector b{0,1}nb \in \{0, 1\}^n, and a sparse n×nn\times n adjacency matrix for GG: AA – sparse in the sense that Aij=0A_{ij} = 0 unless i,ji,j correspond to neighboring vertices on the lattice: ij1|i - j| \leq 1:

Aij={0if ij>10 or 1o.w.A_{ij} = \begin{cases} 0 &\text{if } |i -j| > 1 \\ \\ 0 \text{ or }1 &\text{o.w.} \end{cases}

e.g. for n=42n = 4^2 we might have a grid that resembles:

![[HLF-1.png]]

q(x)=1i<jn2Aijxixj+i=1nbiximod4\begin{aligned} q(x) &= \sum_{1\leq i < j}^n 2A_{ij}x_ix_j + \sum_{i=1}^nb_ix_i \mod 4 \end{aligned}

where x=[x1,x2,...,xn]F2x = [x_1,x_2,...,x_n] \in \mathbb F_2 are binary values. A quadratic form is a polynomial where all terms are degree two, and note that since all our variables are binary-valued, xi2=xix_i^2 = x_i, so that second summation, though appearing to be degree one (and thus, not quadratic, is in fact equivalent to the sum of the squares of bixib_ix_i).

We further restrict q(x)q(x) onto the linear subspace Lq\mathcal L_q given by:

Lq={x{0,1}n:q(xy)=q(x)+q(y)  y{0,1}n}\mathcal L_q = \Big\{x \in \{0,1\}^n : q(x \oplus y) = q(x) + q(y) \; \forall y \in \{0,1\}^n \Big\}

where \oplus is arithmetic on the binary ring i.e. mod 2. It's also worth noting that, by design, Lq\mathcal L_q is the null space, or kernel of AA – that is:

Ax=0xLqAx = 0 \forall x \in \mathcal L_q

Together, the definitions of qq and Lq\mathcal L_q imply that there exists at least one vector z{0,1}nz \in \{0,1\}^n s.t.

q(x)=2i=1nzixi,xLq=2zx\begin{aligned} q(x) &= 2\sum_{i = 1}^n z_ix_i, \quad\forall x \in \mathcal L_q \\ \\ &= 2z^\top x \end{aligned}

We can find all the solutions classically by exhaustively checking all y{0,1}ny \in \{0,1\}^n like so:

import numpy as np

class HLF:
	"""
	A: a symmetric adjaceny matrix of "weights" for a lattice
	b: vertice "weights"
	"""

	def __init__(self, A, b):
		self.n = A.shape[0]
		assert A.shape == (self.n, self.n)
		assert b.shape == (self.n, )

		# symmetric
		assert np.array_equal(A, A.T)

	# only neighboring cells can be connected
	for i in range(self.n):
		for j in range(self.n):
			if A[i][j] == 1:
				# I am the smartest man alive. Google and MathStackExchange BTFO'd
				# I'd like to thank Daniel Shiffman and my whiteboard
				assert (abs(abs(i - self.n) - abs(j - self.n))) % 2 == 1

	self.A = A
	self.b = b

Note that this code is adapted/corrected from an example on Google's quantumai page, but they botch a few crucial aspects of the problem constraints.

A=[0110100010000000],b=[0010]A = \begin{bmatrix} 0 & 1 & 1 & 0 \\ 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix}, \quad b = \begin{bmatrix} 0 & 0 & 1 & 0 \end{bmatrix}

which specifies qq:

q(x)=1i<jn2Aijxixj+i=1nbixi=2(x1x2+x1x3)+x3\begin{aligned} q(x) &= \sum_{1\leq i < j}^n 2A_{ij}x_ix_j + \sum_{i=1}^nb_ix_i \\ \\ &=2(x_1x_2 + x_1x_3) + x_3 \end{aligned}

and the induced subset is:

Lq={[0000],[0110],[0001],[0111]} \mathcal L_q = \begin{Bmatrix} \begin{bmatrix} 0 \\ 0 \\ 0 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 1 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 1 \\ 1 \end{bmatrix} \end{Bmatrix}

which we can verify via the definition, enumerating over all of {0,1}n\{0,1\}^n and enough LaTeX to typeset God himself:

q(x+y)q(x)+q(y)q([0000])=q([0000])+q([0000])=2(00+00)0=0=0=2(00+00)0+2(00+00)0q([1000])=q([0000])+q([1000])=2(00+00)0=0=0=2(00+00)0+2(00+00)0q([0100])=q([0000])+q([0100])=2(10+10)0=0=0=2(00+00)0+2(10+10)0q([1100])=q([0000])+q([1100])=2(10+10)0=0=0=2(00+00)0+2(10+10)0q([0010])=q([0000])+q([0010])=2(01+00)0=0=0=2(00+00)0+2(01+00)0q([1010])=q([0000])+q([1010])=2(01+00)0=0=0=2(00+00)0+2(01+00)0q([0110])=q([0000])+q([0110])=2(11+10)0=2=2=2(00+00)0+2(11+10)0q([1110])=q([0000])+q([1110])=2(11+10)0=2=2=2(00+00)0+2(11+10)0q([0110])=q([0110])+q([0000])=2(11+10)0=2=2=2(11+10)0+2(00+00)0q([1110])=q([0110])+q([1000])=2(11+10)0=2=2=2(11+10)0+2(00+00)0q([0210])=q([0110])+q([0100])=2(21+20)0=0=2=2(11+10)0+2(10+10)0q([1210])=q([0110])+q([1100])=2(21+20)0=0=2=2(11+10)0+2(10+10)0q([0120])=q([0110])+q([0010])=2(12+10)0=0=2=2(11+10)0+2(01+00)0q([1120])=q([0110])+q([1010])=2(12+10)0=0=2=2(11+10)0+2(01+00)0q([0220])=q([0110])+q([0110])=2(22+20)0=0=4=2(11+10)0+2(11+10)0q([1220])=q([0110])+q([1110])=2(22+20)0=0=4=2(11+10)0+2(11+10)0q([0001])=q([0001])+q([0000])=2(00+01)1=2=2=2(00+01)1+2(00+00)0q([1001])=q([0001])+q([1000])=2(00+01)1=2=2=2(00+01)1+2(00+00)0q([0101])=q([0001])+q([0100])=2(10+11)1=0=2=2(00+01)1+2(10+10)0q([1101])=q([0001])+q([1100])=2(10+11)1=0=2=2(00+01)1+2(10+10)0q([0011])=q([0001])+q([0010])=2(01+01)1=2=2=2(00+01)1+2(01+00)0q([1011])=q([0001])+q([1010])=2(01+01)1=2=2=2(00+01)1+2(01+00)0q([0111])=q([0001])+q([0110])=2(11+11)1=2=4=2(00+01)1+2(11+10)0q([1111])=q([0001])+q([1110])=2(11+11)1=2=4=2(00+01)1+2(11+10)0q([0111])=q([0111])+q([0000])=2(11+11)1=2=2=2(11+11)1+2(00+00)0q([1111])=q([0111])+q([1000])=2(11+11)1=2=2=2(11+11)1+2(00+00)0q([0211])=q([0111])+q([0100])=2(21+21)1=2=2=2(11+11)1+2(10+10)0q([1211])=q([0111])+q([1100])=2(21+21)1=2=2=2(11+11)1+2(10+10)0q([0121])=q([0111])+q([0010])=2(12+11)1=0=2=2(11+11)1+2(01+00)0q([1121])=q([0111])+q([1010])=2(12+11)1=0=2=2(11+11)1+2(01+00)0q([0221])=q([0111])+q([0110])=2(22+21)1=2=4=2(11+11)1+2(11+10)0q([1221])=q([0111])+q([1110])=2(22+21)1=2=4=2(11+11)1+2(11+10)0\begin{aligned} q(x + y) &\equiv q(x) + q(y)\\ q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 2(0 \cdot 0 + 0 \cdot 0) \cdot 0 = 0 &= 0 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\0\\0\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}1\\0\\0\\0\end{bmatrix}) = 2(0 \cdot 0 + 0 \cdot 0) \cdot 0 = 0 &= 0 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}) = 2(1 \cdot 0 + 1 \cdot 0) \cdot 0 = 0 &= 0 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}) = 2(1 \cdot 0 + 1 \cdot 0) \cdot 0 = 0 &= 0 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}) = 2(0 \cdot 1 + 0 \cdot 0) \cdot 0 = 0 &= 0 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}) = 2(0 \cdot 1 + 0 \cdot 0) \cdot 0 = 0 &= 0 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 0) \cdot 0 = 2 &= 2 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) + q(\begin{bmatrix}1\\1\\1\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 0) \cdot 0 = 2 &= 2 =2(0 \cdot 0 + 0 \cdot 0) \cdot 0 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 0) \cdot 0 = 2 &= 2 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}1\\0\\0\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 0) \cdot 0 = 2 &= 2 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\2\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}) = 2(2 \cdot 1 + 2 \cdot 0) \cdot 0 = 0 &= 2 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\2\\1\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}) = 2(2 \cdot 1 + 2 \cdot 0) \cdot 0 = 0 &= 2 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\2\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}) = 2(1 \cdot 2 + 1 \cdot 0) \cdot 0 = 0 &= 2 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\2\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}) = 2(1 \cdot 2 + 1 \cdot 0) \cdot 0 = 0 &= 2 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\2\\2\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2(2 \cdot 2 + 2 \cdot 0) \cdot 0 = 0 &= 4 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\2\\2\\0\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) + q(\begin{bmatrix}1\\1\\1\\0\end{bmatrix}) = 2(2 \cdot 2 + 2 \cdot 0) \cdot 0 = 0 &= 4 =2(1 \cdot 1 + 1 \cdot 0) \cdot 0 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 2(0 \cdot 0 + 0 \cdot 1) \cdot 1 = 2 &= 2 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\0\\0\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}1\\0\\0\\0\end{bmatrix}) = 2(0 \cdot 0 + 0 \cdot 1) \cdot 1 = 2 &= 2 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\0\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}) = 2(1 \cdot 0 + 1 \cdot 1) \cdot 1 = 0 &= 2 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\0\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}) = 2(1 \cdot 0 + 1 \cdot 1) \cdot 1 = 0 &= 2 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\0\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}) = 2(0 \cdot 1 + 0 \cdot 1) \cdot 1 = 2 &= 2 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\0\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}) = 2(0 \cdot 1 + 0 \cdot 1) \cdot 1 = 2 &= 2 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 1) \cdot 1 = 2 &= 4 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}) + q(\begin{bmatrix}1\\1\\1\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 1) \cdot 1 = 2 &= 4 =2(0 \cdot 0 + 0 \cdot 1) \cdot 1 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 1) \cdot 1 = 2 &= 2 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}1\\0\\0\\0\end{bmatrix}) = 2(1 \cdot 1 + 1 \cdot 1) \cdot 1 = 2 &= 2 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(0 \cdot 0 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\2\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}) = 2(2 \cdot 1 + 2 \cdot 1) \cdot 1 = 2 &= 2 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\2\\1\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}) = 2(2 \cdot 1 + 2 \cdot 1) \cdot 1 = 2 &= 2 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(1 \cdot 0 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\1\\2\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}) = 2(1 \cdot 2 + 1 \cdot 1) \cdot 1 = 0 &= 2 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\1\\2\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}) = 2(1 \cdot 2 + 1 \cdot 1) \cdot 1 = 0 &= 2 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(0 \cdot 1 + 0 \cdot 0) \cdot 0\\ q(\begin{bmatrix}0\\2\\2\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2(2 \cdot 2 + 2 \cdot 1) \cdot 1 = 2 &= 4 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ q(\begin{bmatrix}1\\2\\2\\1\end{bmatrix}) =q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) + q(\begin{bmatrix}1\\1\\1\\0\end{bmatrix}) = 2(2 \cdot 2 + 2 \cdot 1) \cdot 1 = 2 &= 4 =2(1 \cdot 1 + 1 \cdot 1) \cdot 1 + 2(1 \cdot 1 + 1 \cdot 0) \cdot 0\\ \end{aligned}

Now we just repeat that enumeration process above to find some zz which satisfies:

q(x)=2zx,xLq2(x1x2+x1x3)+x3=2zxmod4(x1x2+x1x3)+12x3=zxmod4\begin{aligned} q(x) &= 2z^\top x, \quad \forall x \in \mathcal L_q \\ 2(x_1x_2 + x_1x_3) + x_3 &= 2z^\top x \mod 4 \\ (x_1x_2 + x_1x_3) + \frac{1}{2}x_3 &= z^\top x \mod 4 \end{aligned}

This trivially yields the solutions:

z{[0100],[1100],[0010],[0111]}z \in \begin{Bmatrix} \begin{bmatrix}0\\1\\0\\0\end{bmatrix}, \begin{bmatrix}1\\1\\0\\0\end{bmatrix}, \begin{bmatrix}0\\0\\1\\0\end{bmatrix}, \begin{bmatrix}0\\1\\1\\1\end{bmatrix} \end{Bmatrix}

which we can verify against all xLqx \in \mathcal L_q:

2([0100][0000])=0=q([0000]),2([0100][0110])=2=q([0110]),2([0100][0001])=0=q([0001]),2([0100][0111])=2=q([0111]),2([1100][0000])=0=q([0000]),2([1100][0110])=2=q([0110]),2([1100][0001])=0=q([0001]),2([1100][0111])=2=q([0111]),2([0010][0000])=0=q([0000]),2([0010][0110])=2=q([0110]),2([0010][0001])=0=q([0001]),2([0010][0111])=2=q([0111]),2([1010][0000])=0=q([0000]),2([1010][0110])=2=q([0110]),2([1010][0001])=0=q([0001]),2([1010][0111])=2=q([0111])\begin{aligned} 2(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}), &\quad2(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\1\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}), &\quad2(\begin{bmatrix}0\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\1\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}), &\quad2(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\1\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}), &\quad2(\begin{bmatrix}1\\1\\0\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\1\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}), &\quad2(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\1\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}), &\quad2(\begin{bmatrix}0\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\1\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\0\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\0\end{bmatrix}), &\quad2(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\0\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\0\end{bmatrix}), &\quad\\ 2(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\0\\0\\1\end{bmatrix}) = 0 = q(\begin{bmatrix}0\\0\\0\\1\end{bmatrix}), &\quad2(\begin{bmatrix}1\\0\\1\\0\end{bmatrix}^\top \begin{bmatrix}0\\1\\1\\1\end{bmatrix}) = 2 = q(\begin{bmatrix}0\\1\\1\\1\end{bmatrix}) \end{aligned}

But this solution requires O(n)O(n) queries to q(x)q(x) since we iterate over all permutations of of F2n\mathbb F^n_2 multiple times to exhaust the search space.

Quantum Circuits

Using a quantum approach, the output z{0,1}nz \in \{ 0,1\}^n can be sampled from the distribution:

p(z)=zHnUqHn0n2p(z) = \Big|\langle z| H^{\otimes n} U_q H^{\otimes n} |0^{n} \rangle\Big|^2

where p(z)>0p(z) > 0 if zz is a solution. UqU_q is constructed as:

Uq=CZ(A)S(b)CZ(A)=1i<jnCZijAij,S(b)=j=1nSjbj\begin{aligned} U_q &= CZ(A)S(b) \\ CZ(A) = \prod_{1 \leq i < j}^n CZ_{ij}^{A_{ij}}, &\quad S(b) = \bigotimes_{j=1}^nS_j^{b_j} \end{aligned}

Notably, this can be accomplished with a constant-depth circuit:

![[HLF-2.png]] To build these chonker matrices, we can first define some helpers:

A = np.array([
	[0, 1, 1, 0],
	[1, 0, 0, 0],
	[1, 0, 0, 0],
	[0, 0, 0, 0]
])
b = np.array([0, 0, 1, 0])
n = A.shape[0]

Z = [[1, 0],
	[0, -1]
]

S = [[1, 0],
	[0, -0j]]
H = 1/ np.sqrt(2) * np.array([
	[1 +0j, 1 + 0j],
	[1 + 0j, -1 + 0j]
	])
qubits = [np.zeros(4) for _ in range(4)]
for i in range(n):
	qubits[i] = qubits[i] @ H

	for j in range(n):

		if A[i][j] == 1:

			qubits[i] = qubits[i] @ Z
	if b[i] == 1:
		qubits[i] = qubits[i] @ S

qubits[i] = qubits[i] @ H

which leaves our qubits in a state of zz.

Again, this problem is psychopathic because it only exists as a variant of Bernstein-Vazirani to prove that quantum circuits can be used to solve classically exponential sized problems with a constant depth of quantum circuits.

Real Problems Have No Solutions

Microsoft just patted themselves on the back so hard they dislodged a rib,11 announcing a new "topological" chip which offers a path to million-qubit systems. This number is significant since that's the order of magnitude required for Shor's algorithm to be remotely viable.12,13
And even then, there are already provisions for "post-quantum" crypto.14

Footnotes

Footnotes

  1. Accounting for cosmic ray bit flips on board Voyager-2

  2. Explain Like I’m 25 And I Don’t Know Any Linear Algebra

  3. Not me tho, I'm a certified rotator

  4. Ethan Bernstein and Umesh Vazirani. "Quantum Complexity Theory." SIAM Journal on Computing Vol. 26, No. 5. 1997.

  5. that's not to say that complex values have no "real world" significance. I'd be loath to perpetuate the notion of "imaginary" numbers being just that – it's just that, for our intents and purposes lol, the complex components are imaginary, negligible, and we just need some guard rails to ensure this model doesn't fly off the rails to silly town aka imaginaryville.

  6. Bra-Ket notation

  7. Riesz, F. (1909). "Sur les opérations fonctionnelles linéaires". Comptes rendus de l'Académie des Sciences. Iss 149: 974–977.

  8. oh yeah, I should mention that there are infinitely dimensional quantum systems

  9. we take 0log0=00 \log 0 = 0 for convenience, which is consistent in the limit λi0+\lambda_i \rightarrow 0^+.

  10. Sergey Bravyi et al. "Quantum advantage with shallow circuits." ArXiv, April 2017.

  11. https://news.microsoft.com/source/features/ai/microsofts-majorana-1-chip-carves-new-path-for-quantum-computing/

  12. David Aasen et al. "Roadmap to fault tolerant quantum computation using topological qubit arrays." ArXiv, February 2025.

  13. Gidney, Craig and Ekereå Martin. "How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits." ArXiv, April 2021.

  14. FIPS 203. Module-Lattice-Based Key-Encapsulation Mechanism Standard.