Solution (source code)

= Solution

Suppose the angle register stores a fixed-point expansion $\theta_i=\sum_{r=1}^q\theta_{ir}2^{-r}\theta_{\max}$. Append a target qubit in $|0\rangle$. For each angle bit $	heta_{ir}$, apply to the target a controlled $R_y(2^{1-r}\theta_{\max})$. Rotations about the same axis commute, so their product is $R_y(2\theta_i)$ and
$$
|0\rangle\longmapsto
\cos\theta_i|0\rangle+\sin\theta_i|1\rangle.
$$
With $q=O(\operatorname{poly}\log N)$ retained bits, each controlled rotation decomposes into one- and two-qubit gates and the complete <quantum variable rotation> has polylogarithmic size. Thus the required branchwise map is implemented coherently for every $i$.