When is a block diagonal matrix a tensor product of Pauli matrices?

$$U = |0\rangle\langle 0|\otimes U_1 + |1\rangle\langle 1|\otimes U_2$$ is a block-diagonal unitary matrix. For this question we will assume $$U$$ acts on qubits. Then for some integer $$N\ge 1$$, $$U$$ is a $$2^N \times 2^N$$ unitary matrix and $$U_1,U_2$$ are $$2^{N-1} \times 2^{N-1}$$ unitary matrices.

My question is: For what $$U_1,U_2$$ does $$U$$ equal a tensor product of Pauli matrices?

More specifically, I'd like to prove (or disprove) that $$U$$ equals a tensor product of Pauli matrices iff $$U_1,U_2$$ are tensor products of Pauli matrices and $$U_1 = \pm U_2$$.

$$(\implies)$$ If $$U_1, U_2$$ are tensor products of Pauli matrices and $$U_1 = U_2 = P$$ or $$P = U_1 = -U_2$$ then $$U = I\otimes P$$ or $$U=Z\otimes P$$, respectively.

For the other direction we know that $$U^2 = I$$ (up to a global phase $$\pm 1$$) and therefore $$U_1^2 = U_2^2 = I$$, but I can't quite make the proof go through. Any help is much appreciated.

Assume $$U$$ equals a Pauli matrix and has the form $$|0\rangle \langle 0| \otimes U_1 + |1 \rangle \langle 1| \otimes U_2$$. The set of Pauli matrices $$\mathcal{P}_N := \{I, X, Y, Z\}^{\otimes N}$$ is an orthogonal basis for $$2^N \times 2^N$$ complex matrices, so there's exactly one $$P \in \mathcal{P}_N$$ for which $$\text{Tr}(PU) \neq 0$$.
Pick any $$P$$ of the form $$P = X \otimes P_{N-1}$$ (with $$P_{N-1} \in \mathcal{P}_{N-1}$$) and you'll compute \begin{align} \text{Tr}(PU) &= \text{Tr}\left( (X \otimes P_{N-1})(|0\rangle \langle 0| \otimes U_1 + |1 \rangle \langle 1| \otimes U_2) \right) \\&= \text{Tr}(X |0\rangle \langle 0|) \text{Tr}(P_{N-1} U_1) + \text{Tr}(X|1 \rangle \langle 1|)\text{Tr}( P_{N-1} U_2) \\&=0, \end{align} so $$U$$ cannot start with $$X$$ (or $$Y$$, for the same reason). There will be exactly one $$P_{N-1}$$ such that $$U \in \{I_2 \otimes P_{N-1}, Z \otimes P_{N-1}\}$$, i.e. $$U_1 = P_{N-1}$$ and $$U_2 = \pm P_{N-1}$$.
• Above when I refer to Pauli matrices I mean $\{I, X, Y, Z\}$ Commented Oct 8, 2023 at 1:05
• Thanks! Looks good. Should be "...one $P\in \mathcal{P}_N$ for which Tr$(PU)\ne 0$.", right? Commented Oct 8, 2023 at 20:51