Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Exercise 4 Language processing and Revision Questions 2009

1. Change the difference list grammar rules given on slide 14 of the Language
Processing lecture so that they will check that the singular/plural case of the noun
phrases matches that of the verb of the verb phrase. Model the change on the rules
on slide 10.

2. Add extra rules to those you have given in answer to Q1 to handle preceding
adjectives using the difference list representation. The rules using append/3 are on
slide 7.

3. a. Give a 2 rule recursive definition of the list processing relation remove/3


described below, modelled on the two rules for member/2 given in the lectures.

b. Give an alternative one rule non-recursive definition using two append/3


conditions. This is an elaboration of the one rule, one append/3 condition definition
you gave for member/2 in the second Problem class and in the second lab exercise
on lists.

remove(E, L, RL) – RL is the list L with some member E removed

Example uses:
?-remove(4,[1,3,4,6],RL).
RL=[1,3,6].
?-remove(4,[1,2,3]).
No.
4. Assume that a Prolog database has facts for the relations:

sellsFor(S,I,P) Supplier S sells item I for price P


inStock(S,I) Supplier S has item I in stock
locatedIn(S,T) Supplier S is located in town T
typeOfItem(I,T) Item I is of type T
equivalentItems(I1,I2) Items I1 and I2 have equivalent functionality

Example facts are:

sellsFor(‘Peter Jones’,swan123,25).
inStock(‘Peter Jones’,swan123).
locatedIn(‘Peter Jones’,london).
typeOfItem(swan123,electricKettle).
equivalentItems(swan123,electrolux214).

Using forall, findall, Prolog’s negation operator \+, if appropriate, and any
arithmetic primitives you may need, give Prolog clauses defining the following
relations:

i) sellsOneForLessThan(S,T,MP) S sells an item of type T at a


price less than MP. (MP is always given in
any query to this relation.)

ii) sellsEquivalentItemIn(S,I,T) S is a supplier located in town T and S either


has item I or an equivalent item in stock

iii) neverUnderSold(S) There is no other supplier that sells an item


that S sells for a price less than S. (Define it
so that it can be used to find such an S, if it
exists.)

iv) listOfSuppliersFor(I,T,L) L is a list of pairs (S,P) where S is a supplier


located in town T that supplies item I
for price P and has I in stock

You might also like