# Can you make a Toffoli-like gate which flips if control bits are equal?

The toffioli gate flips the target bit when both of the control bits are $$\vert 1 \rangle$$.

Would it be possible to instead have a gate which flips a target bit when both control bits are 'equal'?

Possible meanings of equal:

1. Control bits are identical: $$\vert c1 \rangle = \alpha \vert 0 \rangle + \beta \vert 1 \rangle = \vert c2 \rangle$$.

2. Control bits have the same sign/phase: doesn't flip if $$\vert c1 \rangle = -\vert c2 \rangle$$. Flips otherwise.

I am thinking about this in the context of qubits which may or may not have been marked by the oracle in Grover's algorithm if that helps.

Many thanks

You can decompose that operation into CNOTs and NOTs. I propose a $$3$$-input "Agnew" gate acting on $$\{0,1\}^3$$ and producing $$3$$ outputs as follows:

1 2 T || 1 2 T
==============
0 0 0 || 0 0 1
0 0 1 || 0 0 0
0 1 0 || 0 1 0
0 1 1 || 0 1 1
1 0 0 || 1 0 0
1 0 1 || 1 0 1
1 1 0 || 1 1 1
1 1 1 || 1 1 0


Here, 1 and 2 are the two control (qu)bits, while T is the target (qu)bit.

This can be written in matrix form as:

$$\mathsf{AGNEW}= \left( \begin{array}{cccc} 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\ \end{array} \right)$$

This of course can be written in many other ways.

This is a permutation matrix, and is unitary. Thus, it is reversible and can be achieved with a quantum computer.

However, this is a purely classical gate, and the comments in the question about control qubits having the same phase do not immediately fit in to this gate.

• Would there be a way to make the global phase stuff fit in non-immediately or is that impossible? May 8 '20 at 13:01
1. Control bits have the same sign/phase: doesn't flip if $$\vert c1\rangle=−\vert c2\rangle$$. Flips otherwise.

is difficult.

If the state is $$-\vert 000\rangle$$, there's no way to decide

$$\vert c1\rangle, \vert c2\rangle, \vert t\rangle = \vert 0\rangle, \vert 0\rangle, -\vert 0\rangle$$ or

$$\vert c1\rangle, \vert c2\rangle, \vert t\rangle = \vert 0\rangle, -\vert 0\rangle, \vert 0\rangle$$.