> one small comment: in some cases there is not much difference > between lily and your algorithm. Lily doesn't yet use accurate > bboxes for the naturals, so it won't squash them as close your > solution.
I've mentioned this already in the algorithm version with images. Note that the images show extreme cases which demonstrate the full usage of the rules. A lot of simpler situations are handled incorrectly by LilyPond but are fine with my proposal, as the attached image shows. The squashing is a minor detail. Werner