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,255
Registered: 5/20/10
INFINITE SETS IN PROLOG
Posted: Feb 23, 2013 5:25 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




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.