In: Computer Science
2. Given the following sentences:
1. Jack owns Fiat
2. John owns Opel.
3. Fiat is a car and Opel is a car too.
4. Every car owner can drive
5. Jack exceeds the speed limit
6. John fasten seat belt.
7. Every driver who exceeds the speed limit or does not fasten seat belt breaks traffic rules.
8. Every one who can drive is a driver
9. Everyone who breaks any traffic rules will get a fine
10. Bad drivers get fines.
11. Good drivers do not get fines.
a. Translate these sentences into predicate logic
b. Convert the above sentence represented in predicate logic into Horn Clauses
c. Write the horn clauses into Prolog syntax on any Prolog system available online like SWI Prolog.
d. Prove that Jack is a bad driver and John is a good driver by submitting each of the two previous predicate as goals to your knowledgebase. If the KB failed to infer any of these goals, explain why it failed and what predicate should be there to prove your goals.
a) & b)
predicates:
owns(x, y) => x owns y
car(x) => x is a car
canDrive(x) => x can drive
A(x) => x exceeds the speed limit
B(x) => x fastens seat belt
C(x) => x breaks traffic rules
isDriver(x) => x is a driver
F(x) => x gets fine
bad(x) => x is a bad driver
good(x) => x is a good driver
1.
owns(Jack, Fiat)
2.
owns(John, Opel)
3.
car(Fiat)
car(Opel)
4.
can drive => For all car owners, there exists a car.
canDrive(x) =
5.
A(Jack)
6.
B(John)
7.
8.
9.
10.
11.
c)
% Jack owns Fiat
owns('Jack', 'Fiat').
% John owns Opel.
owns('John', 'Opel').
% Fiat is a car and Opel is a car too
car('Fiat').
car('Opel').
% Every car owner can drive
canDrive(X):-
owns(X, Y), car(Y).
% Jack exceeds the speed limit
exceedsSpeedLimit('Jack').
% John fasten seat belt
fastenSeatBelt('John').
% Every driver who exceeds the speed limit
% or does not fasten seat belt breaks traffic rules
breaksTraffic(X):-
isDriver(X), exceedsSpeedLimit(X), not(fastenSeatBelt(X)).
% Every one who can drive is a driver
isDriver(X):-
canDrive(X).
% Everyone who breaks any traffic rules will get a fine
getFine(X):-
breaksTraffic(X).
% Bad drivers get fines
badDriver(X):-
getFine(X).
% Good drivers do not get fines
goodDriver(X):-
not(getFine(X)).
Code Screenshots:
d)
Outputs: