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

COMSATS University Islamabad, Vehari Campus

Department of Computer Science

CSC462-Artificial Intelligence
Lab Assignment # 2

Defining a simple knowledge base

Problem Statement:

We can think of a Prolog knowledge base as a collection of actual and virtual tables, just like a

database. Prolog queries can emulate SQL queries such as project, select, and join.

The file sjsu.pl contains the following tables:

student(S) asserts S is a student

instructor(Instructor)

taken(Student, Course, Result)

teaches(Instructor, Course)

prerequisite(Course, PreReqCourse)

Create rules for defining the following virtual tables:

1. academic(X) if X is a student or instructor

2. passed(X, Y) if X is a student who has passed

course Y

3. studentOf(X, Y) if student X has taken a course

from instructor Y

4. upperDivisionCSstudent(X) if X is a student who has

passed all lower division CS courses


Page 1 of 2
5. teachesPreReq(X) if X is an instructor who teaches

a prerequisite course

6. canTake(X, Y) if X is a student who has passed all

of the prerequisites for course Y

Careful, this last one is tricky. You might think this would work:

canTake(X, Y) :- prerequisite(Y, Z), taken(X, Z, pass).

But this is true if X has taken any prerequisite of course Y. Try using Prolog's meta-predicate:

foreach(predicate1, predicate2) if everything

satisfying predicate1 also satisfies predicate2

Page 2 of 2

You might also like