pretty algorithm for SDM manuscript