Prolog implementation