`less/2` relation in Peano arithmetic
问题 This less-than predicate in Peano arithmetic less(0, s(_)). less(s(X), s(Y)) :- less(X, Y). loops when ?- less(X, Y), X=s(0), Y=0. Is there a better way to write less/2 (using Horn clauses only)? 回答1: You can use when/2 . Making it not anymore an infinitely enumerating predicate and still keeping it 100% pure. The when/2 modifies the S (selection rule) in SLD-Resolution, an idea that can be traced back to Alain Colmerauer. less(X, Y) :- when((nonvar(X),nonvar(Y)), less2(X,Y)). less2(0, s(_)).