Implementation of M4 in Python