Suppose that a quantum circuit with K elementary gates is known for a unitary matrix U, and assume that [Formula Presented] is a scalar matrix for some positive integer m. We show that a function of U can be realized on a quantum computer with at most [Formula Presented] elementary gates. The functions of U are realized by a generic quantum circuit, which has a particularly simple structure. Among other results, we obtain efficient circuits for the fractional Fourier transform. 2003 The American Physical Society.