Prolog - Aunts and Uncles.

home
 Bib
 Algorithms
 Bioinfo
 FP
 Logic
 MML
 Prog.Lang
and the
 mmlist

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.


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}

 

window on the wide world:

Computer Science Education Week

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite,
ver 3.4+

The GIMP
~ free photoshop
Firefox
web browser
FlashBlock
like it says!

© 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 Friday, 10-Jul-2020 09:11:04 AEST.