### Prolog - Aunts and Uncles.

 LA home Computing Logic  Prolog   Intro.   Syntax   Examples    Windsor    Append    Aunt    Solar    Diff    Tree    Witch

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 aunt 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).

{ The Aunt/Uncle Relation. }

```

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).

{ The Aunt/Uncle Relation. }

```