Lecture 25 – November 28th 2006

 

Homework for Thursday, November 30th

 

More Prolog – see Slides and Tutorial1  Tutorial2 Tutorial6  Tutorial8

Note:  I have selected some of James Power’s  Prolog tutorials.  You can find all of them online  at http://www.cs.nuim.ie/~jpower/Courses/PROLOG/

There is additional material at  TutorialLong

 

 

Mystery

/* --------------------------------------------------------------

 *  "Mystery" Problem

 *  Who was the killer?

 * 

 *  Alice, her husband, son, daughter,

 *  and brother are involved in a murder.

 *  One of the five killed one of the other

 *  four.

 * 

 *  1. A man and a woman were together in the bar

 *     at the time of the murder.

 *  2. The victim and the killer were together

 *     on the beach ground at the time of the murder.

 *  3. One of the children was alone at the

 *     time of the murder.

 *  4. Alice and her husband were not together

 *     at the time of the murder.

 *  5. The victim's twin was innocent.

 *  6. The killer was younger than the victim.

 *----------------------------------------------------------------------*/

 

Note1 :  you can forget a file that you have consulted as forget(‘car.pro’).

 

Mystery Solution

 

In the 3:30 class we went through the notes in the slides and we loaded and ran: example, example2, car

I have a version of Prolog that traces the execution.  Here are the traces for them.  Note that the queries are in  typed in red and the SS stands for single step through the execution. 

 

Car Trace

Example Trace

Alice Trace

Example2 Trace

 

Note2 :  especially for the 3:30 class -  If I take out the line you didn’t like,  I don’t get the right answer (see boxed screen capture below where agatha3.pro is the modified file and agatha.pro is the original).   See if you can figure out why it’s needed…

 

 

?-consult('agatha3.pro').

Compiling agatha3.pro.

alice' killed 'alice.

husband' and 'daughter' were together in the bar.'

son' was alone.'

Yes.

?-forget('agatha3.pro').

Yes.

?-consult('agatha.pro').

Compiling agatha.pro.

husband' killed 'brother.

son' and 'alice' were together in the bar.'

daughter' was alone.'

 

Yes.

?-