Write a Prolog predicate rational
such that
rational(X,Y)
will return values for X
and Y
such that
X/Y
is a rational number between 0 and 1, with
X
and Y
being relatively prime positive
integers. Each time you backtrack,
rational(X,Y)
should generate a new rational number.
Every rational
number should be generate eventually, and no rational number should be
generate more than once.
To see what is expected, you may want to look at some output from my solution to this assignment. Other correct solutions may produce different results, for example by generating rational numbers in a different order.
You should not use either negation or the cut operator.
In program comments or a separate document, describe what happens
if you call rational
with either or both variables instantiated.
Also state exactly the conditions under which a call to rational
or backtracking to rational
will initiate a nonterminating
computation.
In this and other programming assignments, at least half your grade will depend on the clarity, simplicity and organization of your code, including the documentation (usually in the form of comments).