  Ultracold bosonic atoms are confined by an optical lattice inside an optical
resonator and interact with a cavity mode, whose wave length is incommensurate
with the spatial periodicity of the confining potential. We predict that the
intracavity photon number can be significantly different from zero when the
atoms are driven by a transverse laser whose intensity exceeds a threshold
value and whose frequency is suitably detuned from the cavity and the atomic
transition frequency. In this parameter regime the atoms form clusters in which
they emit in phase into the cavity. The clusters are phase locked, thereby
maximizing the intracavity photon number. These predictions are based on a
Bose-Hubbard model, whose derivation is here reported in detail. The
Bose-Hubbard Hamiltonian has coefficients which are due to the cavity field and
depend on the atomic density at all lattice sites. The corresponding phase
diagram is evaluated using Quantum Monte Carlo simulations in one-dimension and
mean-field calculations in two dimensions. Where the intracavity photon number
is large, the ground state of the atomic gas lacks superfluidity and possesses
finite compressibility, typical of a Bose-glass.
