# Prolog - Aunts and Uncles.

 home1 home2  Bib  Algorithms  Bioinfo  FP  Logic  MML  Prog.Lang and the  Book

Logic
Prolog
Introduction
Examples

A sister of a parent is an aunt of the child. A brother of a parent is an uncle. A wife of an uncle is an uncle and a husband of an aunt is an uncle:

 ``` parents(william, diana, charles). parents(henry, diana, charles). parents(charles, elizabeth, philip). parents(diana, frances, edward). parents(anne, elizabeth, philip). parents(andrew, elizabeth, philip). parents(edwardW, elizabeth, philip). married(diana, charles). married(elizabeth, philip). married(frances, edward). married(anne, mark). parent(C,M) <= parents(C,M,D). parent(C,D) <= parents(C,M,D). sibling(X,Y) <= parents(X,M,D) and parents(Y,M,D). {NB. sibling(X, X)} aORuDirect(C, A) <= parent(C,P) and sibling(P,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(X,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(A,X). aORu(C,A) <= aORuDirect(C,A). aORu(C,A) <= aORuMarr(C,A). ? aORu(william, A). {\fB The Aunt/Uncle Relation. \fP} ```

Unfortunately these rules, while finding correct aunts and uncles, return parents as aunts or uncles, and also give repeated solutions.

 parents(william, diana, charles). parents(henry, diana, charles). parents(charles, elizabeth, philip). parents(diana, frances, edward). parents(anne, elizabeth, philip). parents(andrew, elizabeth, philip). parents(edwardW, elizabeth, philip). married(diana, charles). married(elizabeth, philip). married(frances, edward). married(anne, mark). parent(C,M) <= parents(C,M,D). parent(C,D) <= parents(C,M,D). sibling(X,Y) <= parents(X,M,D) and parents(Y,M,D). {NB. sibling(X, X)} aORuDirect(C, A) <= parent(C,P) and sibling(P,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(X,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(A,X). aORu(C,A) <= aORuDirect(C,A). aORu(C,A) <= aORuMarr(C,A). ? aORu(william, A). {\fB The Aunt/Uncle Relation. \fP}

The cure is to insist that siblings while sharing the same parents must be different individuals:

 ``` parents(william, diana, charles). parents(henry, diana, charles). parents(charles, elizabeth, philip). parents(diana, frances, edward). parents(anne, elizabeth, philip). parents(andrew, elizabeth, philip). parents(edwardW, elizabeth, philip). married(diana, charles). married(elizabeth, philip). married(frances, edward). married(anne, mark). parent(C,M) <= parents(C,M,D). parent(C,D) <= parents(C,M,D). equal(X, X). sibling(X,Y) <= parents(X,M,D) and parents(Y,M,D) and not equal(X,Y). aORuDirect(C, A) <= parent(C,P) and sibling(P,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(X,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(A,X). aORu(C,A) <= aORuDirect(C,A). aORu(C,A) <= aORuMarr(C,A). ? aORu(william, A). {\fB The Aunt/Uncle Relation. \fP} ```
 parents(william, diana, charles). parents(henry, diana, charles). parents(charles, elizabeth, philip). parents(diana, frances, edward). parents(anne, elizabeth, philip). parents(andrew, elizabeth, philip). parents(edwardW, elizabeth, philip). married(diana, charles). married(elizabeth, philip). married(frances, edward). married(anne, mark). parent(C,M) <= parents(C,M,D). parent(C,D) <= parents(C,M,D). equal(X, X). sibling(X,Y) <= parents(X,M,D) and parents(Y,M,D) and not equal(X,Y). aORuDirect(C, A) <= parent(C,P) and sibling(P,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(X,A). aORuMarr(C, A) <= aORuDirect(C,X) and married(A,X). aORu(C,A) <= aORuDirect(C,A). aORu(C,A) <= aORuMarr(C,A). ? aORu(william, A). {\fB The Aunt/Uncle Relation. \fP}
 Coding Ockham's Razor, L. Allison, Springer A Practical Introduction to Denotational Semantics, L. Allison, CUP

 Linux  Ubuntu free op. sys. OpenOffice free office suite The GIMP ~ free photoshop Firefox web browser

 © L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated), Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University, was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.) Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Wednesday, 08-Feb-2023 11:03:36 AEDT.