MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Logic Programming

Prolog and Logic programming is interesting.

The Logic package which implements logic programming in Mathematica is 
also very instructive. (The logic programming package can be downloaded 
from )

I tried to use it to solve the "Who drinks milk and who owns the horse" 
The main obstacle I have got is how to express the statements to the 
computer, especially when the relationships become complex.

Though I can understand I should post this problem to Prolog's 
newsgroup, I believe that Mathematica users are so universe and 
outstanding that someone may help or give some suggestions.

The puzzle was appeared in Trott's article on the Mathematica Journal. 
He solved it using Mathematica. Below is what I copied from his article:

I copied this text from achalfin at It was discussed in the 
newsgroup comp.soft.sys.mathematica in December 1997.

water.  Then, decide who owns the zebra.

1. There are five houses.

2. The Englishman lives in the red house.

3. The Spaniard owns a dog.

4. Coffee is drunk in the green house.

5. The Ukrainian drinks tea.

6. The green house is immediately to the right of the ivory house.

7. The Old Gold smoker owns snails.

8. Kools are smoked in the yellow house.

9. Milk is drunk in the middle house.

10. The Norwegian lives in the first house.

11. The Chesterfield smoker lives next door to the man with the fox.

12. Kools are smoked in the house next to the house with a horse.

13. The Lucky Strike smoker drinks orange juice.

14. The Japanese smokes Parliaments.

15. The Norwegian lives next door to the blue house.

16. In each house there is one nationality, one pet, one brand of 
cigarette smoked, and one kind of liquid drunk.


So my question is whether it is possible to solve the problem by logic 

First to express these statements like this:

Knowledge = Statements[
    Lives[Englishman, RedHouse, _],
    Lives[Norwegian, _, 1],
    Owns[Spaniard, Dog],
    Drinks[Ukranian, Tea],
    Smokes[Japanese, Parliaments],
    Lives[_, BlueHouse, 2]]
 .... ....

Then one can ask the question:
Question[Knowledge, Drinks[X_, Milk], X]
Question[Knowledge, Owns[X_, Horse], X]

Hu Zhe

  • Prev by Date: Re: Problems with TeX and EPS output (v3.0, mac)
  • Next by Date: Re: Question: How to display matrixes with a tube-defined figure
  • Previous by thread: Re: Problems with TeX and EPS output (v3.0, mac)
  • Next by thread: Re: Logic Programming