Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: INFINITE SETS IN PROLOG
Replies: 4   Last Post: Feb 25, 2013 7:18 PM

 Messages: [ Previous | Next ]
 Graham Cooper Posts: 4,495 Registered: 5/20/10
Re: INFINITE SETS IN PROLOG
Posted: Feb 25, 2013 4:23 PM

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

Date Subject Author
2/23/13 Graham Cooper
2/25/13 BruceS
2/25/13 Graham Cooper
2/25/13 BruceS
2/25/13 Graham Cooper