Unit 7 – Logic Paradigm10 hours |
In this unit we meet our second example of a paradigm shift from the procedural imperative and object oriented paradigms to in this case the logic (declarative) paradigm. In this paradigm, programmers focus on the goals of a computation rather than the development of an algorithm to achieve these goals. In the course text, Gabbrielli and Martini give R. Kowalski's definition of an algorithm as:
Algorithm = Logic + Control
In the Imperative paradigm, for example a programmer focuses on both what is to be achieved (the logic involved) and the how the goals are to be achieved (control).
In the logic paradigm, programmers focus only on the logic, the what, that has to be achieved. The control (or how) part of an algorithm is left to the abstract machine. The technique we wish to consider here is referred to as resolution and involves the interpreter searching through the set of all possible solutions.
We commence this unit with two examples of problems, the n queen problem and a list problem, both of which are suitable candidates for solving via the logic paradigm.
The N Queen Problem Introduction
Propositions Predicates and the Horn Clause
The development of the logic paradigm is said to have been driven by researchers in 'natural language processing', and 'automatic theorem proving'. The specifications for a logic problem are expressed using mathematical logic in terms of predicate and propositional logic and so in this session we review some of the concepts involved.
A Programming Practical (Prolog)
Logic Programming is sometimes referred to as rule based programming. It was developed in the 1970s. Prolog (short for Programming Logic) was quickly recognised as the most popular logic programming language and this, it is said still holds true today.
We note that Prolog
- does not store changeable data values (unlike the imperative or OO paradigms) and does not have executable statements
- does not entertain a sequence of commands to change stored data vales from one state to another
- works with the idea of a set of facts and rules for determining facts rather than on a sequence of executable commands
- is derived from a form of mathematical logic and an associated concept of automatic proof