2
$\begingroup$

I am struggling with a problem which has been anticipated in a different question here for 3 qubits. I need a sequence of gates (Pauli, controlled also), such that the unitary matrix associated with the circuit is:

$$ U = \begin{bmatrix} -1 & 0 & 0 & 0 & ... \\ 0 & 1 & 0 & 0 & ... \\ 0 & 0 & 1 & 0 & ... \\ 0 & 0 & 0 & 1 & ... \\ &&... \\ \end{bmatrix}, $$

that is, the identity matrix having -1 as the first entry. I have not made any attempt as I do not know exactly how to approach this problem.


Edit:

This can be done by first computing the matrix having -1 at the end of the diagonal and using X-gates to put that '-1' on the first diagonal entry like this:

nq = 4
qc = QuantumCircuit(nq)

qc.x([j for j in range(0, nq)])

qc.h(0) 
qc.mcx([j for j in range(1, nq)], 0, mode='noancilla') 
qc.h(0)

qc.x([j for j in range(0, nq)])
$\endgroup$
5
  • 1
    $\begingroup$ Would you know how to do it of the only element with $-1$ was the last entry (corresponding to input bits 111..1)? $\endgroup$
    – DaftWullie
    Oct 16 at 12:03
  • $\begingroup$ Yes, it is ``` nq = 5 qc = QuantumCircuit(nq) qc.h(0) qc.mcx([j for j in range(1, nq)], 0, mode='noancilla') qc.h(0) ``` But I need the '-1' in the first entry $\endgroup$
    – francler
    Oct 16 at 12:08
  • 1
    $\begingroup$ So how could you convert from 000...00 into 111...11 (and then back again afterwards? $\endgroup$
    – DaftWullie
    Oct 16 at 12:12
  • 1
    $\begingroup$ Application of x gate to each qubit? $\endgroup$
    – francler
    Oct 16 at 12:52
  • $\begingroup$ Oh, I see your point. $\endgroup$
    – francler
    Oct 16 at 12:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.