


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



The purpose of this assignment is for you to gain some experience designing and implementing Prolog programs. This assignment is broken into three parts. The first part is a fairly straightforward Prolog warm- up. Part 2 involves writing a set of simple programs for manipulating lists and variables. Part 3 requires you to use Prolog’s control mechanism to implement a predicate for scheduling.
You will be given sets of facts of the following form:
Here number is an atom denoting the course number (for instance, ecs140a), prereq a list of course numbers, and units a number indicating the number of units associated with a course.
Here name is an atom denoting a student’s name, and courses taken is a list of courses that the student has taken.
Here name specifies the name of the instructor who teaches the set of courses in the list course list. An example database of facts is shown below:
course(ecs40, [ecs30], 4). course(ecs122a, [ecs100, ecs110], 3). . . . student(john, [ecs30, ecs40]). . . . instructor(jim, [ecs30, ecs110]).
Write the following separate queries:
(a) Find all courses with 3 or 4 credits (fc course). (b) Find all courses whose immediate pre-requisite is ecs110 (prereq 110). (c) Find names of all students in ecs140a (ecs140a students). (d) Find the names of all instructors who teach john’s courses (instructor names).
(e) Find the names of all students who are in jim’s class (students). (f) Find all pre-requisites of a course (allprereq). (This will involve finding not only the immediate prerequisites of a course, but pre-requisite courses of pre-requisites and so on.)
When you are through testing your queries interactively, prepare them for use by the testing program by defining predicates with the names shown above.
The goal of this part of the homework is to familiarize you with the notions of lists and predicate definitions in Prolog. This part requires you to define a number of simple predicates:
?-all_length([a, b, c], X) X = 3; no ?-all_length([a, [b,c], [d,[e,f]]], Y) Y = 6; no
Part Percentage 1 30 2 45 3 25