Derivation of efficient logic programs by specialization and reduction of nondeterminism