# How to synthesize function $f(x)$ in amplitude encoding

In computational basis encoding, the way to encode $$f(x)$$ is known - a classical circuit is converted to a quantum circuit which takes $$|x\rangle|0\rangle \to |x\rangle|f(x)\rangle$$. I wonder how I may be able to encode $$f(x)$$ into amplitude encoding such that one gets state $$|\psi\rangle \propto \sum_{x=0}^{N-1}f(x)|x\rangle$$.

For convenience, suppose $$f(x)$$ is periodic function of period $$N$$, and suppose classical algorithm for computing $$f(x)$$ is known.

Should I consider something like LCU - linear combination of unitaries? (section 7.3 of the link)

Any quantum operation (put aside reset and measurement) is a unitary operation and can be represented by a unitary matrix. Any unitary matrix can be built of quantum gates. So if you can encode $$f(x)$$ into a unitary matrix $$U$$ then there must be some series of quantum gates that yields $$U$$.

For example, let $$n = 2$$ be the number of qubits in the system, and $$N = 4$$ be the dimension of the Hilbert space that the quantum statevector of the system $$|\psi\rangle$$ resides in. A simple example is $$U_1 = I \otimes Z$$:

$$U_1 = I \otimes Z = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}$$

Let $$f(x) = (-1)^x$$. From the matrix of $$U_1$$ we can deduce that $$U_1|x\rangle = (-1)^x|x\rangle = f(x)|x\rangle$$, i.e we have encoded $$f(x)$$ into $$U_1$$. We can create $$U_1$$ by applying the $$Z$$ gate to $$q_0$$ and do nothing to to $$q_1$$ so $$U_1 = I \otimes Z$$ (using little endian).

Another example would be $$U_2 = I \otimes S$$:

$$U_2 = I \otimes S = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & i \end{bmatrix}$$

Let $$g(x) = i^{x (mod\ 2)}$$. From the matrix of $$U_2$$ wen can deduce that $$U_2|x\rangle = i^{x (mod\ 2)}|x\rangle = g(x)|x\rangle$$, i.e we have encoded $$g(x)$$ into $$U_2$$. We can create $$U_2$$ by applying the $$S$$ gate to $$q_0$$ and do nothing to to $$q_1$$ so $$U_2 = I \otimes S$$ (again little endian).

These are just 2 examples and there are more, but I guess (not sure though) that without using extra qubits we are pretty limited (Someone reading this correct me if I am wrong). If we add more qubits then we can do much more.