Skip to content

Instantly share code, notes, and snippets.

@xenophobia
Created February 16, 2015 14:22
Show Gist options
  • Save xenophobia/e6f3e7a376cc3ea876a9 to your computer and use it in GitHub Desktop.
Save xenophobia/e6f3e7a376cc3ea876a9 to your computer and use it in GitHub Desktop.
nat(0).
nat(X1) :- nat(X), X1 is X + 1.
pair_of_nats(X, Y) :- nat(X), nat(Y).
(0 step)
pair_of_nats(X, Y).
(1 step)
nat(X), nat(Y).
(2 step)
[X=0, Y=0.] (resolved)
X=X1, nat(X2), X1 is X2 + 1, Y=0.
X=0, Y=Y1, nat(Y2), Y1 is Y2 + 1.
X=X1, nat(X2), X1 is X2 + 1, Y=Y1, nat(Y2), Y1 is Y2 + 1.
(3 step)
X=X1, X2=0, X1 is X2 + 1, Y=0. -> [X=1, Y=0.] (resolved)
X=X1, X2=X3, nat(X4), X3 is X4 + 1, X1 is X2 + 1, Y=0.
X=0, Y=Y1, Y2=0, Y1 is Y2 + 1. -> [X=0, Y=1.] (resolved)
X=0, Y=Y1, Y2=Y3, nat(Y4), Y3 is Y4 + 1, Y1 is Y2 + 1.
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment