From Prolog Algebras towards WAM---A Mathematical Study of Implementation