The reason you find it difficult to complete this nat/1 definition is because the required order requires a search for a evidence tree that is neither depth nor width. Answer @CapelliC is the first width search. The answer from @lurker gives you the answers you are after.
If for one reason or another you do not want to use CLPFD, here is the solution in pure Prolog:
pairs(A, B) :- pairs_1(0, 0, A, B). pairs_1(A, B, A, B). pairs_1(A, B, RA, RB) :- ( succ(B1, B) -> succ(A, A1), pairs_1(A1, B1, RA, RB) ; succ(A, B1), pairs_1(0, B1, RA, RB) ).
It simply describes how to "navigate" through a matrix of rational numbers to list all pairs of integers.
user1812457
source share