# Which the sequence of gates providing the following unitary?

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)])

• Would you know how to do it of the only element with $-1$ was the last entry (corresponding to input bits 111..1)? Oct 16 at 12:03
• 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 Oct 16 at 12:08
• So how could you convert from 000...00 into 111...11 (and then back again afterwards? Oct 16 at 12:12
• Application of x gate to each qubit? Oct 16 at 12:52
• Oh, I see your point. Oct 16 at 12:53