Skip to content

Instantly share code, notes, and snippets.

@thezerobit
Created January 5, 2014 20:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thezerobit/8273752 to your computer and use it in GitHub Desktop.
Save thezerobit/8273752 to your computer and use it in GitHub Desktop.
Peano relation in Prolog using the CLP(FD) that ships with SWI-Prolog.
:- use_module(library(clpfd)).
peano(N,z) :- N #= 0.
peano(N,s(PDec)) :-
N #> 0,
N - 1 #= NDec,
peano(NDec, PDec).
% ?- peano(4, Q).
% Q = s(s(s(s(z)))) ;
% false.
% ?- peano(Q, s(s(s(s(z))))).
% Q = 4.
% ?- peano(0, Q).
% Q = z ;
% false.
% ?- peano(Q, z).
% Q = 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment