Homework

20 views

sasa...@msn.com

Nov 23, 2017, 11:08:46 AM11/23/17
to SWI-Prolog
Hi guys :) I am totally new to prolog and therefor could use some help with a homework. I already asked the question on stackoverflow, but for what I really needed, the guy stopped responding and the homework is due to tomorrow :/

So we need to formulate these sentences into Prolog:

-Bill owns a dog.

-Every dogowner likes animals.

-Every person who likes animals cannot hit an animal.

-Bill or Bull hit a cat whose name is Tom.

-Every cat is an animal.

owns(bill,dog).

likes(X,animals):- owns(X,dog).

`cannothit(X,animal):- likes(X,animals).` or `hit(X,animal):- \+ likes(X,animal)`

With the 4th sentence I have a major problem because I do not know how to state that or.

It would be so awesome if someone could help me.

Barb Knox

Nov 23, 2017, 10:35:42 PM11/23/17
On 24/11/2017, at 05:08, sasa...@msn.com wrote:

Hi guys :) I am totally new to prolog and therefor could use some help with a homework. I already asked the question on stackoverflow, but for what I really needed, the guy stopped responding

and the homework is due to tomorrow :/

(Oops!)

So we need to formulate these sentences into Prolog:

1.  Bill owns a dog.

2.  Every dogowner likes animals.

3.  Every person who likes animals cannot hit an animal.

4.  Bill or Bull hit a cat whose name is Tom.

5.  Every cat is an animal.

owns(bill,dog).

Not quite.  Bill owns *a* dog, i.e. some (unknown to us) thing which is a dog.

I would code it as:
owns(bill, Pet), dog(Pet).

likes(X,animals):- owns(X,dog).

Again, I’d use Pet with dog(Pet) instead of dog.
Further, does X like *some* animals or *all* animals (including, e.g., large venomous spiders)?  It makes a difference.
As it stands, you are saying X likes some *particular* thing with the name “animals”.  Not good.  You can finesse the issue by using a predicate animal_lover(X).

`cannothit(X,animal):- likes(X,animals).` or `hit(X,animal):- \+ likes(X,animal)`

Definitely use hit as your predicate, rather than cannothit.  You will need hit for sentence 4.

Also, as with Pet, use hit(Hitter, Hittee) with animal(Hittee).

With the 4th sentence I have a major problem because I do not know how to state that or.

That is indeed a problem.  Look up “disjunction” in your text.

It would be so awesome if someone could help me.

I hope this is of some help.  You are unlikely to get correct homework in on time, but hopefully you’ve learned a couple of useful things.

IMO and FWIW, this is a *poor* problem for beginners.  Your instructor(s) may be less than adequately competent with Prolog.  They would not be the first….

--
---------------------------
|  BBB                b    \    Barbara at LivingHistory stop co stop uk
|  B  B   aa     rrr  b     |
|  BBB   a  a   r     bbb   |   ,008015L080180,022036,029037
|  B  B  a  a   r     b  b  |   ,047045,L014114L4.
|  BBB    aa a  r     bbb   |
-----------------------------