A conservative finite-sample simultaneous confidence envelope for a de
nsity can be found by solving a finite set of finite-dimensional linea
r programming problems if the density is known to be monotonic or to h
ave at most it modes relative to a positive weight function. The dimen
sion of the problems is at most (n/log n)(1/3), where n is the number
of observations. The linear programs find densities attaining the larg
est and smallest values at a point among cumulative distribution funct
ions in a confidence set defined using the assumed shape restriction a
nd differences between the empirical cumulative distribution function
evaluated at a subset of the observed points. Bounds at any finite set
of points can be extrapolated conservatively using the shape restrict
ion. The optima are attained by densities piecewise proportional to th
e weight function with discontinuities at a subset of the observations
and at most five other points. If the weight function is constant and
the density satisfies a local Lipschitz condition with exponent rho,
the width of the bounds converges to zero at the optimal rate (log n/n
)(rho/(1+2 rho)) outside every neighborhood of the set of modes, if a
''bandwidth'' parameter is chosen correctly. The integrated width of t
he bounds converges at the same rate on intervals where the density sa
tisfies a Lipschitz condition if the intervals are strictly within the
support of the density. The approach also gives algorithms to compute
confidence intervals for the support of monotonic densities and for t
he mode of unimodal densities, lower confidence intervals on the numbe
r of modes of a distribution and conservative tests of the hypothesis
of K-modality. We use the method to compute confidence bounds for the
probability density of aftershocks of the 1984 Morgan Hill, CA, earthq
uake, assuming aftershock times are an inhomogeneous Poisson point pro
cess with decreasing intensity.