Introduction to Prolog

Module aims

This is a short, intensive 'taster' course intended to provide an introduction to:

  • the programming language Prolog and its basic features
  • logic programming concepts
  • a typical Prolog environment (Sicstus Prolog)
  • some common Prolog programming techniques

The emphasis is on explaining that Prolog has both a declarative and a procedural reading, and on the importance of clear and concise programs.

Learning outcomes

Students will:

  • be able to develop succinct and clear Prolog programs for unseen, but well specified, problems of small to medium scale;
  • have a sense of the computational efficiency of their programs and be able to employ some of Prolog's control primitives to improve efficiency;
  • have an awareness of the main differences and similarities between Prolog and functional programming languages (in particular Haskell).

Module syllabus

  • Declarative and procedural readings; variables and unification; computations, finite failure, and the search space; nondeterminism and multiple solutions. Logical and operational semantics.
  • Prolog terms. Lists and list processing. Tail recursion and last call optimisations.
  • Arithmetic and other built-in predicates.
  • Negation as  failure.
  • Control primitives: the 'cut'; Prolog conditionals.
  • Aggregation operators: findall and setof.

Pre-requisites

The basics of syntax and semantics of propositional and predicate logic, as covered in the first year Logic course. Some familiarity with functional programming languages (Haskell) and recursive programs is an advantage but is not essential.

Teaching methods

This is an intensive course spread over three days, consisting of lectures and timetabled laboratory sessions, with tutorial assistance available.

A series of unassessed programming exercises are designed to introduce features of the language and associated programming techniques. Model answers are made available and also discussed briefly in lectures.

Assessments

There is one assessed programming exercise.