Added the python implementation for the first math dm.