I met a subroutine to change the phase for a subset of basis vectors, and I can't understand why uncomputing in this case removes the entanglement. I want to generalize it a little. Specifically, I want to know whether in general, uncomputing removes the entanglement.
The algorithm is like follows (a is a temporary qubit, and I generalized it.)
$$U_f\left|x,a\right\rangle$$ $$P\left|a\right\rangle$$ $$U_f^{-1}\left|x,a\right\rangle$$ Where $U_f\left|x,y\right\rangle\mapsto\left|x,y\oplus f(x)\right\rangle$, and P is an arbitrary operator. In the textbook, it is a phase shift operator for only $\left|1\right\rangle$.
Since when we operate on a, x also changes, the "uncompute" doesn't undo what the computation has done in line 1. Why does it remove the entanglement? I think in the two qubit case, it is possible to write the matrices and calculate, but what about the general case? And if in addition to operate on a, we also operate on x in between, does it also have the same effect?
Thanks in advance.