CSc 520 - Principles of Programming Languages
42 : Logic Programming -- Prolog Basic

Christian Collberg

Department of Computer Science

University of Arizona

1 Prolog Types

2 Prolog Types...

Types

3 Prolog Numbers

4 Prolog Arithmetic Expressions

5 Prolog Atoms

6 Prolog Variables

7 Prolog Variables...

8 Prolog Programs

9 Prolog Programs...

10 Standard predicates

11 Standard predicates...

12 Unification/Matching

13 Backtracking

14 Backtracking...

15 Maori Family Relationships

John Foster (in He Whakamaarama - A New Course in Maori) writes:

Relationship is very important to the Maori. Social seniority is claimed by those able to trace their whakapapa or genealogy in the most direct way to illustrious ancestors. Rights to shares in land and entitlement to speak on the marae may also depend on relationship. Because of this, there are special words to indicate elder or younger relations, or senior or younger branches of a family.

16 Maori Terms of Address

Maori English
au I
tipuna, tupuna grandfather, grandmother, grandparent, ancestor
tiipuna grandparents
matua taane father
maatua parents
paapaa father
whaea, maamaa mother
whaea kee aunt
kuia grandmother, old lady
tuakana older brother of a man, older sister of a woman
teina younger brother of a man, younger sister of a woman

17 Maori Terms of Address...

Maori English
tungaane woman's brother (older or younger)
tuahine man's sister (older or younger)
kaumaatua elder (male)
mokopuna grandchild (male or female)
iraamutu niece, nephew
taane husband, man
hunaonga daughter-in-law, son-in-law
tamaahine daughter
tama son
tamaiti child (male or female)
tamariki children
wahine wife, woman
maataamua oldest child

18 Maori Terms of Address...

Maori English
pootiki youngest child
koroheke, koro, koroua old man
whaiapo boyfriend, girlfriend1
kootiro girl
tamaiti taane boy
whanaunga relatives
1 Literally: "What you follow at night"

19 The Whanau


\begin{gprogram}
?- calls(aanaru, hata, Z). \\
\x Z = tuakana ; \\
\x Z = maat...
... \\
\\
?- calls(aanaru, rapeta, Z).\\
\x Z = teina ; \\
\x no
\end{gprogram}

20 The Whanau...

 Name Sex Father Mother Spouse Born
 Hoone male unknown unknown Rita 1910
 Rita female unknown unknown Hone 1915
 Ranginui male unknown unknown Reremoana 1915
 Reremoana female unknown unknown Ranginui 1916
 Rewi male Hoone Rita Rahia 1935
 Rahia female Ranginui Reremoana Rewi 1940
 Hata male Rewi Rahia none 1957
 Kiri female Rewi Rahia none 1959

21 The Whanau...

 Name Sex Father Mother Spouse Born
 Hiniera female Rewi Rahia Pita 1960
 Aanaru male Rewi Rahia none 1962
 Rapeta male Rewi Rahia none 1964
 Mere female Rewi Rahia none 1965
 Pita male unknown unknown Hiniera 1960
 Moeraa female Pita Hiniera none 1986
 Huia female Pita Hiniera none 1987
 Irihaapeti female Pita Hiniera none 1988

22 The Whanau Program -- Database Facts

% person(name,  sex,     father,mother,spouse,   birth-year).

person(hoone,   male,    unkn1, unkn5, rita,     1910).
person(rita,    female,  unkn2, unkn6, hoone,    1915).
person(ranginui,male,    unkn3, unkn7, reremoana,1915).
person(reremoana, female,unkn4, unkn8, ranginui, 1916).

person(rewi,  male,   hoone,    rita,      reremoana, 1935).
person(rahia, female, ranginui, reremoana, rita,      1916).

person(hata,    male,    rewi,  rahia,  none,   1957).
person(kiri,    female,  rewi,  rahia   none,   1959).

23 The Whanau Program -- Database Facts...

% person(name,  sex,     father,mother,spouse,   birth-year).
person(hiniera, female,  rewi,  rahia,  pita,   1960).
person(anaru,   male,    rewi,  rahia,  none,   1962).
person(rapeta,  male,    rewi,  rahia,  none,   1964).
person(mere,    female,  rewi,  rahia,  none,   1965).
person(pita,    male,    unkn9, unkn10, hiniera,1960).

person(moeraa,  female,   hiniera,  pita, none, 1986).
person(huia,    female,   hiniera,  pita, none, 1987).
person(irihaapeti, female,hiniera,  pita, none, 1988).

24 Whanau -- Auxiliary predicates

% Auxiliary predicates
gender(X, G) :- person(X, G, _, _, _, _).
othergender(male, female).
othergender(female, male).
female(X) :- gender(X, female).
male(X)   :- gender(X, male).

25 Whanau -- Family Relationships

% Is Y the <operator> of X?
wife(X, Y)    :- person(X, male, _, _, Y, _).
husband(X, Y) :- person(X, female, _, _, Y, _).
spouse(X, Y)  :- wife(X, Y).
spouse(X, Y)  :- husband(X, Y).
parent(X, Y)  :- person(X, _,Y, _, _, _).
parent(X, Y)  :- person(X, _,  _, Y, _, _).
son(X, Y)     :- person(Y, male, X, _, _, _).
son(X, Y)     :- person(Y, male, _, X, _, _).
daughter(X, Y):- person(Y, female, X, _, _, _).
daughter(X, Y):- person(Y, female, _, X, _, _).
child(X, Y)   :- son(X, Y).
child(X, Y)   :- daughter(X, Y)

26 Whanau -- Family Relationships...

% Is X older than Y?
older(X,Y) :- 
      person(X, _, _, _, _,Xyear),
      person(Y, _, _, _, _,Yyear),
      Yyear > Xyear.

% Is Y a sibling of X of the gender G?
sibling(X, Y, G) :- <left as an exercise>.

% Is Y one of X's older siblings of gender G?
oldersibling(X,Y,G) :- <left as an exercise>.

% Is Y one of X's older/younger siblings of either gender?
oldersibling(X,Y) :- <left as an exercise>.
youngersibling(X,Y) :- <left as an exercise>.

27 Whanau -- Family Relationships...

% Is Y an ancestor of X of gender G?
ancestor(X,Y,G) :- <left as an exercise>.

% Is Y an older relative of X of gender G?
olderrelative(X,Y,G) :- 
   ancestor(X, Y, G).
olderrelative(X,Y,G) :- 
   ancestor(X, Z, _), 
   sibling(Y, Z, G).

% Is Y a sibling of X of his/her opposite gender?
siblingofothersex(X, Y) :- <left as an exercise>.

28 The Whanau Program -- Calls

% Me.
calls(X, X, au).

% Parents.
calls(X,Y,paapaa) :- person(X, _,Y, _, _, _).
calls(X,Y,maamaa) :- person(X, _, _,Y, _, _).

% Oldest/youngest sibling of same sex.
calls(X, Y, tuakana) :- 
   gender(X, G), 
   eldestsibling(X, Y, G).
calls(X, Y, teina) :- 
   gender(X, G), 
   youngestsibling(X, Y, G).

29 The Whanau Program -- Calls...

% Siblings of other sex.
calls(X, Y, tungaane) :- <left as an exercise>.
calls(X, Y, tuahine) :- <left as an exercise>.
calls(X, Y, tipuna) :-  <left as an exercise>.

% Sons and daughters.
calls(X, Y, tama)   :-  <left as an exercise>.
calls(X, Y, tamahine) :-  <left as an exercise>.

% Oldest/youngest child.
calls(X, Y, maataamua) :- <left as an exercise>.
calls(X, Y, pootiki) :- <left as an exercise>.

% Child-in-law.
calls(X, Y, hunaonga) :-  <left as an exercise>.

% Grandchild.
calls(X, Y, mokopuna) :-  <left as an exercise>.

30 Readings and References



Christian Collberg 2008-04-23