  We calculate the dynamic structure factor S(q,omega) of a one-dimensional
(1D) interacting Bose gas confined in a harmonic trap. The effective
interaction depends on the strength of the confinement enforcing the 1D motion
of atoms; interaction may be further enhanced by superimposing an optical
lattice on the trap potential. In the compressible state, we find that the
smooth variation of the gas density around the trap center leads to softening
of the singular behavior of S(q,omega) at Lieb-1 mode compared to the behavior
predicted for homogeneous 1D systems. Nevertheless, the density-averaged
response remains a non-analytic function of q and omega at Lieb-1 mode in the
limit of weak trap confinement. The exponent of the power-law non-analyticity
is modified due to the inhomogeneity in a universal way, and thus, bears
unambiguously the information about the (homogeneous) Lieb-Liniger model. A
strong optical lattice causes formation of Mott phases. Deep in the Mott
regime, we predict a semi-circular peak in S(q,\omega) centered at the on-site
repulsion energy, omega=U. Similar peaks of smaller amplitudes exist at
multiples of U as well. We explain the suppression of the dynamic response with
entering into the Mott regime, observed recently by D. Clement et al., Phys.
Rev. Lett. v. 102, p. 155301 (2009), based on an f-sum rule for the
Bose-Hubbard model.
