Generalized version of wolfram's rules