12.1. A brief introduction to clausal logic#

Solution 1.2 #

Construct the proof trees for the query


There are six answers to this query:

{ W→green_park }
{ W→piccadilly_circus }
{ W→leicester_square }
{ W→bond_street }
{ W→oxford_circus }
{ W→tottenham_court_road }

The proof trees for the first three answers are analogous to Figure 1.2. The proof tree for the fourth answer is given below (the two remaining proof trees are similar):


Solution 1.4 #

A list is either the empty list [], or a non-empty list [First|Rest] where Rest is a list. Define a predicate list(L), which checks whether L is a list. Adapt it such that it succeeds only for lists of (1) even length and (2) odd length.

The first specification can immediately be translated to Prolog:


A list of even length is either the empty list, or a non-empty list with two more elements than the next shorter list of even length:


In order to adapt this definition for lists of odd length, only the non-recursive clause needs to be changed:


Notice that oddlist can also be defined in terms of evenlist (or vice versa):


Solution 1.5 #

Construct a query asking for a route from Bond Street to Piccadilly Circus with at least two intermediate stations.