Several mathematical frameworks of phase-locking are developed. The classical Huyghens approach is generalized to include all harmonic and subharmonic resonances and is found to be connected to 1/f noise and prime number theory. Two types of quantum phase-locking operators are defined, one acting on the rational numbers, the other on the elements of a Galois field. In both cases we analyse in detail the phase properties and find that they are related to the Riemann zeta function and to incomplete Gauss sums, respectively.