Logic Programming
06-25433
Autumn 2012

 

 

 

Lecture 3: Writing and running recursive Prolog programs

  • rules allow us to write conjunctive queries more concisely and to reuse them;
  • recursive programs describe uncertain and unpredictable situations;
  • recursive structures need to be processed recursively.
How to prepare

 
  • Work your way through Tutorial Sheet 1.
  • Consider situations where there is an unknown number of "solutions", for instance, enumerating all of a person's friends.
  • Consider how you would visit every node of a binary tree - where you don't know in advance the depth of the tree and how many leaves it has.
Video

  Recording of the lecture (Autumn 2011) (Vimeo)

Slides

  If you really want the slides from the lecture ... but don't forget printing the slides is not the same as understanding them.

Summary

  Summary and programs with commentary from the lecture

Programs from the lecture

 
Example 1 - jealousy Example 2 - friendship (non-recursive) Example 3 - friendship (recursive)
Example 4 - friendship (recursive): demo version Example 5 - displaying a binary tree Example 6 - route finding: demo version

Individual study suggestions and further reading

 

Study how to represent information, search strategies and simple rules and how non-deterministic problems can be described and processed in Prolog.

Recursion is covered in:

Assessed work associated with this lecture

  Tutorial sheet 2