You are on page 1of 8

1

(a) Many high-level languages use a procedural paradigm.


Explain the term procedural programming language.

[2]

(b) Some high-level languages use a declarative paradigm.


The clauses 1 to 12 show some of the facts to be implemented with a declarative
programming language. Clause 13 is a rule which uses variable X.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.

car(a1).
car(a2).
car(a3).
part(motorA).
part(motorB).
part(gearbox1).
part(gearbox2).
supplier_part(motorA, dealerD).
supplier_part(gearbox1, thirdpartyE).
combination(gearbox1, a1).
combination(motorA, a2).
combination(motorB, a2).
guaranteed_part(X) IF part(X) AND supplier_part(X, dealerD).

Note: car(a1) means a1 is a car.


supplier_part(motorA, dealerD) means motorA is supplied by dealerD.
(i) Write a new clause for each of the following facts:
There is a car zx6.
14.
gearbox2 is a part required for the a3 car.
15.
The supplier for part motorB is dealerD.
16.

[3]

(ii) Explain the rule given by clause 13.

[1]

(a) Procedural language


Uses sub-programs/subroutines/ blocks of code
Procedures are self-contained
Program statements will be executed sequentially

[2]

(b) (i) car(zx6)

[1]

combination(gearbox2, a3)

[1]

supplier_part(motorB, dealerD)

[1]

(ii) the part will be guaranteed if that parts supplier is dealerD

[1]
[Total: 6]

A declarative programming language is to be used to represent the knowledge base shown


below:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

continent(asia).
continent(north_america).
continent(australasia).
country(india, asia).
country(china, asia).
country(usa, north_america).
country(australia, australasia).
state(queensland, australia).
state(tasmania, australia).
state(texas, usa).
state(alaska, usa).

These clauses have the following meaning:


Clause
1
4
9

Explanation
There is a continent named asia
The country india is in asia
There is a state in australia named tasmania

(a) More facts are to be included.


There is a country in the continent of South America called Peru.
Write the extra facts to record this.

[2]
(b) Using variable ThisState, the clause:
state(ThisState, usa)
would return the result: ThisState = texas, alaska
Write the result returned by the clause:
country(ThisCountry, asia)
ThisCountry =

[1]

(c) Complete the rule below to determine if two countries are in the same continent.
in_same_continent(Country1, Country2)
IF

[3]

(a)

(i) continent(south_america)
[2]

country(peru, south_america)

(b) india, china

[1]

(c) In_same_continent(Country1, Country2)


IF country(Country1,X) AND country(Country2,X)

Mark as follows:
country clause used twice
AND operator between two country clauses
variables Country1 and Country2
Use of a common new variable e.g. X

(must be caps)
(must be caps)

[1]
[1]
[1]
[1]
[MAX 3]
[Total: 6]

Cambridge International Examinations 2012

In a particular country, to become a qualified driver you must:

have a licence; there is a minimum age at which a person can be issued with a licence
and it is different for cars and motorbikes
pass a theory test; it is the same test for cars and motorbikes
pass a driving test for that vehicle (car or motorbike)

A declarative programming language is to be used to represent the knowledge base shown


below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

minimum_age(car, 18).
minimum_age(motorbike, 16).
age(yu, 16).
age(kong, 16).
age(ho, 15).
age(zhen, 21).
age(tain, 21).
age(shen, 21).
has_licence(yu).
has_licence(kong).
has_licence(ho).
has_licence(zhen).
has_licence(tain).
has_licence(shen).
able_to_drive(X, V) IF has_licence(X) AND minimum_age(V, L)
AND age(X, A) AND A >= L.
passed_theory_test(kong).
passed_theory_test(yin).
passed_theory_test(zhen).
passed_theory_test(yu).
passed_driving_test(zhen, car).
passed_driving_test(yu, motorbike).
passed_driving_test(kong, car).
passed_driving_test(kong, motorbike).
passed_driving_test(shen, motorbike).
qualified_driver(X, V) IF able_to_drive(X, V) AND
passed_theory_test(X) AND passed_driving_test(X, V).

These clauses have the following meaning:


Clause
1
8
13
15

Explanation
The minimum age for a car licence is 18
Shen is aged 21
Tain has a licence
Person X is able to drive vehicle V if person X has a
licence, and the age A of person X is greater than
or equal to the minimum age L to drive vehicle V

(a) List the clause numbers for the rules in this knowledge base.
[1]

(b) Show the output produced from theses clauses:


(i) passed_driving_test(Who, car).

[1]
(ii) able_to_drive(ho, motorbike).

[1]
(iii) NOT(has_licence(shen)).

[1]

(c) Write a clause to output:


(i) all qualified motorbike drivers.

[2]
(ii) all drivers who have passed the theory test but not a driving test.

[3]

(d) To produce the output from a clause, the inference engine uses a process called
backtracking.
Consider the clause:
able_to_drive(ho, motorbike).
List the order in which clauses are used to produce the output.
For each clause, describe the result that it returns.

[3]

(a) Rules are: 15 and 25

[1]

(b) (i) Who = zhen


Who = kong

[1]

(ii) false

[1]

(iii) false

[1]

(c) (i) has_licence(X) AND passed_theory_Test(X) AND


passed_driving_test(X, motorbike)
each clause scores 1
use of two AND operators

[3]
[1]
MAX 3

(ii)

OR (using the anonymous variable) ...


[3]
(d) has_licence(ho) returns TRUE // clause 11
age(ho, A) returns 15 // A=15
minimum_age(motorbike, L) returns L=15 // clause 2
A >= L returns FALSE
able_to_drive(ho, motorbike) returns false

[1]
[1]
[1]
[1]
[1]
MAX 3
[Total: 12]

You might also like