Date: Feb 23, 2013 5:25 PM
Author: Graham Cooper
Subject: INFINITE SETS IN PROLOG

nat(0).
nat(s(X)) :- nat(X).

even(0).
even(s(s(X))) :- even(X).

odd(s(0)).
odd(s(s(X))) :- odd(X).


*** e is SET MEMBERSHIP ***

e(A,nats) :- nat(A).
e(A,evens) :- even(A).
e(A,odds) :- odd(A).

insect(S1,S2) :- e(A,S1), e(A,S2).

?- insect(nats,evens).
?- insect(nats,odds).

This will return TRUE TRUE

******************************

You can see the results of the Set Intersection.

?- e(A,nats) , e(A,evens)

will return

A = 0
A = s(s(0))
A = s(s(s(s(0))))
A = s(s(s(s(s(s(0))))))

*******************************

?- e(A,nats) , e(A,odds)

will return

A = s(0)
A = s(s(s(0)))
A = s(s(s(s(s(0)))))
A = s(s(s(s(s(s(s(0)))))))

NOTE:

?-insect( odds, evens ) will CRASH!


HOMEWORK:

Define divby3(X)
and use it to output all numbers divisible by 6!


Herc
--
www.BLoCKPROLOG.com