Density Dependence and Cooperation: Theory and a Test with Bacteria