Knuth-Bendix completion algorithm implementation