9

I am interesting in finding a circuit to implement the operation $f(x) > y$ for an arbitrary value of $y$. Below is the circuit I would like to build:

enter image description here

I use the first three qubits to encode $|x⟩$, use the other three qubits to encode $|f(x) = x⟩$, and finally I want to filter out all of the solutions for which $f(x) \leq y$.

So, if we set $y = 5$, the states would be:

$$\Psi_{0} = |0⟩\otimes|0⟩ $$

$$\Psi_{1} = \frac{1}{\sqrt{8}}\sum_{i=0}^{7} (|i⟩\otimes|0⟩) $$

$$\Psi_{2} = \frac{1}{\sqrt{8}}\sum_{i=0}^{7} (|i⟩\otimes|i⟩) $$

$$\Psi_{3} = \frac{1}{\sqrt{2}}(|6⟩\otimes|6⟩ + |7⟩\otimes|7⟩)$$

Is there a general method to come up with such filter, or is this non-trivial?

Sanchayan Dutta
  • 17,497
  • 7
  • 48
  • 110
Max
  • 193
  • 4
  • 2
    Just to check: suppose you were doing this not on three wires, but on $n$ wires, and you tried to realise a filter for $y = 3$, so that you're filtering for $f(x) < 4$. If $f(x)$ potentially ranges within $0 \leqslant f(x) < 2^n$, the probability of passing through this filter may be as low as $4/2^n = 2^{-(n-2)}$, which as $n$ grows will be vanishingly small. A circuit which relies on your filter might then fail the vast majority of the time (though you'll know that it has failed in principle). Is that the sort of thing you are looking for, or are you looking for something more reliable? – Niel de Beaudrap Oct 05 '18 at 11:42
  • @NieldeBeaudrap What I am envisioning is a double filter to select only the values of x for which a < f(x) < b. I would then measure x several times, pass the measured values of x to a classical computer, and use this information to build an isosurface plot of f(x) = c, where a < c < b. I'm trying to make a quantum-assisted marching cubes algorithm. Probably not very useful because marching cubes is already quite efficient, but it's a fun exercise. – Max Oct 05 '18 at 12:07
  • 1
    Can you write the action you expect this to do, i.e. how it is supposed to act on a set of basis states? – Norbert Schuch Oct 05 '18 at 12:29
  • @NieldeBeaudrap Sorry, I am not sure I understood your comment. Since the state is in a superposition, wouldn't such filter succeed in principle every time? I recently began studying and haven't gotten to errors and error correction - is the failure due to errors that occur in practice, or is it a fundamental type of failure that occurs even in a perfect quantum system? – Max Oct 05 '18 at 12:30
  • 1
    @NorbertSchuch Yes. It would be a diag(0,0,0,0,0,0,2,2). Which is not unitary. So the answers appears to be no... Is that the right way to think about it? Thanks! – Max Oct 05 '18 at 12:45
  • 3
    What you're looking to do isn't something we'd expect to be easy for just any function $f$, and doesn't work well if you think of it as a filter. (Consider the case where $f$ computes whether or not a boolean formula is satisfied by an assignment $x$, and take $y = 0$: then what you are asking for would allow you to produce a superposition over all satisfying assignments to the formula, provided that any exist! We don't expect quantum computers to be able to do this easily.) But if $f$ is a function which has an easily computed inverse (as is the case for $f(x) = x$), there's another approach. – Niel de Beaudrap Oct 05 '18 at 12:51
  • @NieldeBeaudrap Ah!! And that's when one applies Grover's algorithm! Ok, that makes sense, thanks! – Max Oct 05 '18 at 13:00
  • 2
    @Max Yes. But of course you could say you only fix certain matrix elements (eg the diagonal) and want to complete it to a unitary. This might have a different answer ... – Norbert Schuch Oct 05 '18 at 15:13
  • 1
    It looks like the pink box does not involve the definition of $f$. That is done beforehand. Instead it looks like it is the nonunitary sending $| i \rangle \otimes | j \rangle$ to itself if $j>y$ and $0$ otherwise. All followed by re-normalizing the state. So I don't see the role of $f$; that was done with the CNOTs before the pink/black box. – AHusain Oct 05 '18 at 17:12

2 Answers2

5

What you are looking for I think is to use a quantum circuit for doing comparison. Those are made from adder circuits with a slight modification to have comparators.

For adders, you have for example one from Cuccaro et al. (this one give the modification to adapt for comparison) and another from Himanshu et al.

cnada
  • 4,754
  • 1
  • 8
  • 21
  • 1
    Re: adders, see also: https://quantumcomputing.stackexchange.com/questions/2346/quantum-ripple-carry-adder-construction – user820789 Oct 06 '18 at 01:13
1

Let $U$ be the circuit you stated that takes $| 0 \rangle^{\otimes (2n)}$ to $\psi=\frac{1}{2^{n/2}}\sum_{i=0}^{2^n-1} | i \rangle \otimes | f(i) \rangle $.

$S_\psi = I - 2 | \psi \rangle \langle \psi | = U ( S_{| 0 \rangle^{\otimes (2n)}} ) U^\dagger$

$S_P$ needs to be the unitary that sends $| i \rangle \otimes | j \rangle$ to $(-1)^{j>y} (| i \rangle \otimes | j \rangle)$. For example if $y$ is $2^{n-1}-1$, then this would be done with a $Z$ gate on the most significant index. Generally for $y$ 1 less than a power of $2$ this should be easy by combining information from all more significant indices.

Those are the requisite ingredients for amplitude amplification for $f(x) \geq 2^k$ for some $k$. The number of times you need to apply $Q$ is dependent on the overlap which is dependent on how many solutions $x$ there are to $f(k) \geq 2^k$. If $f$ is reversible so just giving a permutation of $2^n$, then you have the overlap in terms of $n-k$ without bothering with any details of $f$.

You won't get exactly the result you asked for because that was projecting to a subspace/not unitary, but this will get you close to that desired state given your starting setup. There is also the trouble of setting $y$ arbitrarily, but at least you can amplify the condition $f(x) \geq 2^k$ as a step along the way to amplifying $f(x) \geq y$ for $y \geq 2^k$.

I may have misunderstood the question. You might have wanted something that works more generally, but given your small example this approach is okay. You don't have to worry about the fact that $\frac{\pi}{4\theta}$ will get really big as $n$ grows you, if you don't let $n$ grow. Did you want to input $y$ as a quantum state as well?

I wasn't careful about checking $\geq$ vs $\gt$ so you should check that.

AHusain
  • 3,633
  • 2
  • 9
  • 17