  Manipulating Hamiltonians governing physical systems has found a broad range
of applications, from quantum chemistry to semiconductor design. In this work,
we provide a new way of manipulating Hamiltonians, by transforming their
eigenvalues while keeping their eigenstates unchanged. We develop a universal
algorithm that deterministically implements any desired (suitably
differentiable) function on the eigenvalues of any unknown Hamiltonian, whose
positive-time and negative-time dynamics are given as a black box. Our
algorithm uses correlated randomness to efficiently combine two subroutines --
namely controlization and Fourier series simulation -- exemplifying a general
compilation procedure that we develop. The runtime of our algorithm is
significantly reduced using compilation compared to a na\"ive concatenation of
the subroutines and outperforms similar methods based on the quantum singular
value transformation. Finally, to circumvent the need for the negative-time
dynamics, we present a universal algorithm to transform positive-time to
negative-time dynamics without adding an auxiliary qubit, which could also be
of standalone interest.
