Lecture: Logic Programming and a Simple Query Language

Background Material

Reading

Theme

As programmers, we are used to describing "how to" do things and writing programs that explicitly show how to compute values. Most programming languages are biased towards uni-directional computation - given an input compute the corresponding output. In logic programming the emphasis is on specifying knowledge and the underlying control structure carries out computation. Moreover, it is possible to compute multiple results (relations rather than functions) that satisfy given constraints.

A good example of this is the append function that we saw in Lecture on scheme which stated how to recursively compute the concatenation of two lists. This function can be used to answer questions such as what is the concatenation of two given lists. The basis for this function can be interpreted as two rules: 1) what is the concatenation an empty list with a list and 2) how the concatenation of two lists is related to the concatenation of the list obtained by removing its first element and a second list. These rules specify when three lists are such that the third is the concatenation of the first two. A logic programming language can use these rules to obtain a list that concatenates with a given list to obtain a given third list in addition to concatenating two given lists. Moreover, the same rules, with an appropriate underlying control mechanism, can be used to find all pairs of lists that concatenate to obtain a third given list.

In this lecture we provide a simple logic programming language, called a query language since it can be used to retrieve information - by lookup or deduction - from a database. In addition to studying the language, we will study an implementation of the language. The key concepts in the implemenation of this language are pattern-matching, binding, and a generalization of pattern matching called unification that can be used for deduction.

Topics

  1. Introduction to Logic Programming
  2. A Simple Query Language

Exercises

Created: May 28, 2008 (revised May 26, 2010) by jjohnson AT cs DOT drexel DOT DOT edu