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

On Feb 26, 6:40 am, BruceS <bruce...@hotmail.com> wrote:
> <snip>
>
> Never mind infinite sets in Prolog, what about your finite series of
> incomplete excuses, tied to your failure to pay Brad the $1000 you owe
> him?  Why should anyone spend time on you if you can't even honor the
> agreements you make?



For someone in the Triple 9 Society you couldn't even get the homework
question right!


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


----PROGRAM DIV3-----

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

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(A,nats) :- nat(A).
e(A,evens) :- even(A).
e(A,odds) :- odd(A).
e(A,div3s) :- divby3(A).

?- e(A,div3s), e(A,evens).

-------RESULT-------

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

ie. {0,3,6,9.12...} /\ {0,2,4,6,8,10,12...}
= {0,6,12...}

Herc
--
www.BLoCKPROLOG.com