Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math.independent

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Graham Cooper

Posts: 4,256
Registered: 5/20/10
Re: INFINITE SETS IN PROLOG
Posted: Feb 25, 2013 4:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.