Prolog predicate for adjacency of integers with all signatures and no spurious choice points
The best way to reason about integers is to use your Prolog system's CLP(FD) constraints.

For example, in SICStus Prolog and SWI-Prolog:

:- use_module(library(clpfd)).

nearby(X, Y) :- abs(X - Y) #= 1.


This works in all directions out of the box.

For example, with both arguments integers:

?- nearby(1, 2).
true.


Second, with only one argument known:

?- nearby(X, 3).
X in 2\/4,
_G1047+3#=X,
_G1047 in -1\/1.


Third, with both arguments variables:

?- nearby(X, Y).
_G1085+Y#=X,
_G1085 in -1\/1.


etc.

All serious Prolog systems ship with CLP(FD) constraints, and I recommend you use them when describing relations over integers. Just state the constraints and let Prolog do the reasoning for&nbsp;you.

Note that the predicate is semideterministic: It either fails or succeeds precisely once. You can use labeling/2 to enumerate solutions if the domains are finite.