On the mathematical theory of the stability of earthwork and masonry