Week 1: Notes

In the lab we introduced the built-in predicate '=' which is true when two terms are equal (this predicate appears in section 2.2 "Matching" in the Bratko text).

We also introduced dif which is true when two terms are different. Bratko uses different operators for this purpose, but in this class we will use dif since it belongs to the pure core of Prolog (a concept we will discuss more later).

Here are the solutions to a couple of exercises that we solved in the lab:

5. Map of Europe

color(red). color(blue). color(green).

solve :-
  color(Czech), color(Slovakia), color(Germany), color(Poland),
  color(Austria), color(Hungary), color(Ukraine),
  dif(Czech, Germany), dif(Czech, Poland), dif(Czech, Slovakia), dif(Czech, Austria),
  dif(Slovakia, Poland), dif(Slovakia, Ukraine), dif(Slovakia, Hungary),
  dif(Germany, Poland), dif(Germany, Austria),
  dif(Poland, Ukraine),
  dif(Austria, Hungary),
  dif(Hungary, Ukraine).

6. Occupations and Instruments

person(katka).
person(maria).
person(roman).

different(P, Q, R) :-
  person(P), person(Q), person(R),
  dif(P, Q), dif(Q, R), dif(P, R).
  
solution(Doctor, Lawyer, Teacher, Piano, Flute, Violin) :-
  different(Doctor, Lawyer, Teacher),
  different(Piano, Flute, Violin),
  dif(maria, Doctor),
  Lawyer = Piano,
  dif(maria, Teacher),
  Violin = Doctor,
  dif(katka, Doctor).