Question
Prolog queries can emulate SQL queries such as project, select, and join. The file xyz.pl contains the following tables: student(S) asserts S is a student
Prolog queries can emulate SQL queries such as project, select, and join. The file xyz.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:
academic(X) if X is a student or instructor
passed(X, Y) if X is a student who has passed course Y
studentOf(X, Y) if student X has taken a course from instructor Y
upperDivisionCSstudent(X) if X is a student who has passed all lower division CS courses
teachesPreReq(X) if X is an instructor who teaches a prerequisite course
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
xyz.pl:
student(smith). student(jones). student(nguyen). student(young). student(sherman). instructor(pearce). instructor(godel). instructor(escher). instructor(bach). taken(smith, cs46a, pass). taken(smith, cs46b, fail). taken(smith, cs146, pass). taken(jones, cs46a, pass). taken(jones, cs46b, pass). taken(jones, cs146, pass). taken(nguyen, cs46a, pass). taken(nguyen, cs46b, pass). taken(nguyen, cs151, pass). teaches(pearce, cs152). teaches(godel, cs151). teaches(escher, cs146). teaches(bach, cs46b). teaches(bach, cs46a). prerequisite(cs152, cs151). prerequisite(cs152, cs46b). prerequisite(cs151, cs46b). prerequisite(cs146, cs46b). prerequisite(cs46b, cs46a).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started