What is Relational Programming?

Ordinary programming languages calculate functions. Sometimes a function is inappropriate. For example, 4 has two square roots, +2 and -2, but an ordinary programming language provides a sqrt function that returns only one of the roots. So if we want to find both roots of a quadratic equation, we have to deal with each root separately. In a relational language, we need only to specify one solution, and the program will find both. This is because it will treat sqrt as a binary relation. A binary relation is similar in concept to a function, but can map an argument to any number of values (including zero).

Relations have many uses in computer science. The Z Specification Language makes heavy use of relational algebra notation. One reason is that programs are usually required to establish an input-output relationship, but there are often many outputs that are allowable. For example, a program may be asked to find any solution to a problem, or it may be asked to list all solutions, but in no particular order. A functional specification is bound to specify some particular solution or some particular order. A functional specification is usually an over-specification.

You can find out more about Relational Methods in Computer Science from the RELMICS site.

Libra is a relational programming language that explores the different values yielded by relations by back-tracking rather than parallel execution. Click here to download Libra.

Since back-tracking is a feature of Prolog, the initial version of Libra is implemented in it. You can download a very good free Prolog system for a 68000 Macintosh, called Open-Prolog.

Computer Science Technical Report 95-10
LIBRA: A Lazy Interpreter of Binary Relational Algebra

Barry Dwyer
Department of Computer Science
University of Adelaide
G.P.O. Box 498, Adelaide
South Australia 5005
October 30, 1995.


LIBRA is a general-purpose programming language based on the algebra of binary relations. It is an attempt to unify functional and logic programming, retaining the advantages of both, and avoiding some of the problems. It has all the features needed of a programming language, including a straightforward semantic interpretation. Since program specifications are easily expressed as relations, it offers a simple path from a specification to a program and from the program to its proof of correctness. The algebra of binary relations has several operators whose effects are like those of familiar procedural language constructs, for example, relational composition is analogous to sequential execution.

The syntax and semantics of the Libra language are given in detail. The Prolog implementation of a lazy evaluator for Libra programs is described. Libra is illustrated by its application to some simple programming exercises.


PROGRAMMING Languages, Binary Relations, Specification Languages, Prolog.

This page has been accessed times since 12th June 1997.

Up to Barry Dwyer's Home Page