# Help with very basic prolog

3 replies to this topic

### #1mexicanwings

New Member

• Members
• 5 posts

Posted 03 October 2005 - 01:30 AM

Hi everyone,

I've tried solving the following very basic question in prolog but to no avail:

"I love cats or I love dogs"
"If I love cats, then I love dogs"

By constructing a truth table, i know that "I love dogs" is a logical conquence of the premise. The same cannot be said about "I love cats". Howver, i just can't seem to get prolog to proof this. Can someone help me please? Thanks so much in advance!

---

### #2Rydinare

New Member

• Members
• 24 posts

Posted 05 October 2005 - 04:39 PM

I know some prolog, but I'm not sure what you're asking.

Okay, say you have cat and dog. First you say that they're animals

animal(cats)
animal(dogs)

Somewhere above, you may have defined one or both of these (or neither). For this example, let's say you have both:

love(cats)
love(dogs)

animalsthatilove(X):-love(X)

will show:
cats
dogs

loverelations(cats,dogs)

loveofrelated(X):-loverelations(cats,X)

will show:
dogs

I'm not sure if this answers your question. I think you have a misconception about how prolog works, but hopefully this gave you a head start.

### #3Rydinare

New Member

• Members
• 24 posts

Posted 15 October 2005 - 01:44 PM

Maybe you'd like to check back sometime and let us know if you had any luck with prolog and if my advice helped. :)

### #4mexicanwings

New Member

• Members
• 5 posts

Posted 16 October 2005 - 03:42 AM

Hi Rydinare,

Thank for your response. I'm pretty sure your program works fine in prolog. My apologies for perhaps not being explicit on my doubts. Do allow me to rephrase my question.

Rydinare said:

I know some prolog, but I'm not sure what you're asking.

Okay, say you have cat and dog. First you say that they're animals

animal(cats)
animal(dogs)

Somewhere above, you may have defined one or both of these (or neither). For this example, let's say you have both:

love(cats)
love(dogs)

By entering the above clauses into prolog, we're saying that love(cat) and love(dog) are both true statements and thus are both logical consequence of our logic program.

However, if we let (cat = p) and (dog = q), the original question:

"I love cats or I love dogs" translate into "p v q"
"If I love cats then I love dogs" translate into "q <- p"

By constructing a truth table for the above, we get the following:

-------------------------------------
p | q | p v q | q <- p |
-------------------------------------
T | T | T | T | (1)
T | F | T | F | (2)
F | T | T | T | (3)
F | F | F | T | (4)
-------------------------------------

It is shown that q is the only logical consequence of the program since it is true when both statements are also true (as shown in (1) and (3)). p on the other hand is not a logical consequence since it is false under (3). This would directly contredict our program clause earlier.

My question therefore is:
"Is there a way to use prolog to demonstrate what the truth table has just shown us?"