PDA

View Full Version : Help with very basic prolog


mexicanwings
10-02-2005, 07:30 PM
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!

---

Rydinare
10-05-2005, 10:39 AM
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.

Rydinare
10-15-2005, 07:44 AM
Maybe you'd like to check back sometime and let us know if you had any luck with prolog and if my advice helped. :)

mexicanwings
10-15-2005, 09:42 PM
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.

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?"

Any reply is greatly appreciated!

p/s - I also have another question on Herbrand Theorem which i hope your can help me with please. Thanks :lol:
---