0% found this document useful (0 votes)
2 views2 pages

Prolog Student Course KnowledgeBase

The document outlines a Prolog knowledge base for a student-course system, detailing the relationships between students, courses, and teachers. It includes facts about students, courses, and teaching assignments, along with rules to determine which teacher a student has and to identify classmates. Example queries demonstrate how to retrieve information such as who teaches a specific student and whether two students are classmates.

Uploaded by

cewinom874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Prolog Student Course KnowledgeBase

The document outlines a Prolog knowledge base for a student-course system, detailing the relationships between students, courses, and teachers. It includes facts about students, courses, and teaching assignments, along with rules to determine which teacher a student has and to identify classmates. Example queries demonstrate how to retrieve information such as who teaches a specific student and whether two students are classmates.

Uploaded by

cewinom874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Prolog Knowledge Base – Student-Course System

Question

Create a Prolog knowledge base for a student-course system with the following
requirements:

1. There are students, courses, and teachers.


2. Each teacher teaches one or more courses.
3. Students can be enrolled in one or more courses.
4. Define a rule teacher_of(Teacher, Student) that succeeds if a teacher teaches a course the
student is enrolled in.
5. Define a rule classmates(X, Y) that is true if X and Y are different students enrolled in the
same course.

Then answer the following queries:


a) Who teaches John?
b) Are John and Sara classmates?
c) List all classmates of Lee.
d) What course does Ms. Jones teach?

Prolog Code

% --- Facts ---


student(john).
student(sara).
student(lee).

course(math).
course(physics).

teaches(mr_smith, math).
teaches(ms_jones, physics).

enrolled(john, math).
enrolled(sara, math).
enrolled(lee, physics).

% --- Rules ---


% Rule 1: Teacher of a student
teacher_of(Teacher, Student) :-
teaches(Teacher, Course),
enrolled(Student, Course).

% Rule 2: Classmates
classmates(X, Y) :-
enrolled(X, Course),
enrolled(Y, Course),
X \= Y.

Example Queries & Answers

?- teacher_of(Who, john).
% Who = mr_smith.

?- classmates(john, sara).
% true.

?- classmates(lee, Who).
% false (no classmates in physics).

?- teaches(ms_jones, What).
% What = physics.

You might also like