# Implementing controlled rotation for FRQI by using controlled Ry and NOT Gate

I was reading about Flexible Representation of Quantum Images (FRQI) encoding in Qiskit textbook. It says that, given $$\{\theta_0, \theta_1, ..., \theta_{4^{n}-1}\} \quad (\theta_i \in [0,\pi/2])$$ we can transform $$\mid{0}\rangle^{\otimes2n+1}$$ into FRQI state $$\mid{I(\theta)}\rangle$$ by applying unitary operator $$\mathcal{R}\mathcal{H}$$, with $$\mathcal{H}= I \otimes H^{\otimes 2n}$$ and $$\mathcal{R}= \prod_{i=0}^{4^n-1}R_i$$. where $$\mid{I(\theta)}\rangle= \frac{1}{2^n}\sum_{i=0}^{4^n-1}(cos \theta_i|{0}\rangle+sin \theta_i|{1}\rangle)\otimes |{i}\rangle$$

And $$R_i$$ is a unitary matrix named controlled rotation, given by $$R_i= I \otimes \sum_{j=0, j \neq i}^{4^n-1} |{j}\rangle \langle {j}| + R_y(2\theta_i) \otimes |{i}\rangle \langle {i}\mid$$ I would like to implement the controlled rotation $$R_i$$ or $$\mathcal{R}$$ using $$C^{2n}R_y$$ (controlled $$R_y$$) and $$X$$ gate.

Edit: I think I have made some progress. We can write, $$R_i= I^{\otimes 2n+1}+(R_y(2\theta_i)-I) \otimes |{i}\rangle \langle {i}\mid$$ $$C^{2n}R_y(2\theta_i)= I^{\otimes 2n+1}+(R_y(2\theta_i)-I) \otimes |{4^n-1}\rangle \langle {4^n-1}\mid$$ Please review my results and suggest me how to approach further.

If you already have controlled$$^{2n}-R_Y$$, this is fairly straightforward. This means that what you already have is $$C^{2n} R_y(2\theta_i)=I^{\otimes(2n+1)}+(R_Y(2\theta_i)-I)\otimes |1\rangle\langle 1|^{\otimes 2n}$$ and you are aiming to make $$R_i=I^{\otimes(2n+1)}+(R_Y(2\theta_i)-I)\otimes |i\rangle\langle i|.$$ Now, let $$X_x$$ be a tensor product of Pauli $$X$$ matrices that have the action $$X_x|i\rangle=|1\rangle^{\otimes 2n}\rangle.$$ In other words, if $$y$$ is the binary representation of $$i$$, then $$x=y\oplus 11\ldots 1=\bar y.$$ Then \begin{align*} X_x C^{2n} R_y(2\theta_i)X_x&=X_x(I^{\otimes(2n+1)}+(R_Y(2\theta_i)-I)\otimes |1\rangle\langle 1|^{\otimes 2n})X_x\\ &=I^{\otimes(2n+1)}+(R_Y(2\theta_i)-I)\otimes |i\rangle\langle i|\\ &=R_i. \end{align*}