Re: Art of Prolog Exercise problem



David W. wrote:
busy(Lecturer, Time) :- course(Course, time(Day, Start, Finish), Lecturer, place(Building, Room)),
lecturer(Lecturer, Course), teaches(Lecturer, Day), location(Course, Building), occupied(Room, Day, Time).

Slightly reindented:

busy(Lecturer, Time) :-
    course(Course, time(Day, Start, Finish),
           Lecturer, place(Building, Room)),
    lecturer(Lecturer, Course),
    teaches(Lecturer, Day),
    location(Course, Building),
    occupied(Room, Day, Time).

The lecturer() line is superfluous. If there is a course(C, _, L, _), it is obvious that lecturer(C, L) is also true.

Same for teaches(L, D).

Same for location(C, B).

This leaves us with the following:

busy(Lecturer, Time) :-
    course(_, time(Day, _, _), Lecturer, place(_, Room)),
    occupied(Room, Day, Time).

This means: Lecturer is busy when there is any course in the same Room and on the same Day, no matter what the lecturer of that course is.

Roland
.



Relevant Pages

  • Re: Tips on studying math
    ... > I don't bother to mention small errors that don't matter. ... Once I was feeling picky and did, ... some people write down proofs verbatim during lectures and study ... lecturer isn't there to ask about it. ...
    (sci.math)
  • Re: Art of Prolog Exercise problem
    ... Lecturer, place), ... Roland ... busy/2 didn't work. ... For some reason, I thought that lecturer/2 rule constrained the lecturer to a specific course, but it just means that there is a lecturer for a course. ...
    (comp.lang.prolog)