mother(mary, dorothy). mother(dorothy, geoff). mother(dorothy, graham). mother(dorothy, barbara). mother(barbara, chris). mother(barbara, lucy). father(norman, geoff). father(norman, graham). father(norman, barbara). father(leon, chris). father(leon, lucy). father(george, dorothy). ancestor(Ancestor, Person) :- ancestoriter(Ancestor, Person, 0). ancestoriter(Ancestor, Ancestor, N) :- N > 0. ancestoriter(Ancestor, Person, N) :- father(Father, Person), M is N + 1, ancestoriter(Ancestor, Father, M). ancestoriter(Ancestor, Person, N) :- mother(Mother, Person), M is N + 1, ancestoriter(Ancestor, Mother, M). [debug] 4 ?- ancestor(X,lucy). T Call: (8) ancestoriter(_G463, lucy, 0) T Redo: (8) ancestoriter(_G463, lucy, 0) T Call: (9) father(_L192, lucy) T Exit: (9) father(leon, lucy) T Call: (9) ancestoriter(_G463, leon, 1) T Exit: (9) ancestoriter(leon, leon, 1) T Exit: (8) ancestoriter(leon, lucy, 0) X = leon ; T Redo: (9) ancestoriter(_G463, leon, 1) T Call: (10) father(_L229, leon) T Fail: (10) father(_L229, leon) T Redo: (9) ancestoriter(_G463, leon, 1) T Call: (10) mother(_L229, leon) T Fail: (10) mother(_L229, leon) T Redo: (9) father(_L192, lucy) T Redo: (8) ancestoriter(_G463, lucy, 0) T Call: (9) mother(_L192, lucy) T Exit: (9) mother(barbara, lucy) T Call: (9) ancestoriter(_G463, barbara, 1) T Exit: (9) ancestoriter(barbara, barbara, 1) T Exit: (8) ancestoriter(barbara, lucy, 0) X = barbara ; T Redo: (9) ancestoriter(_G463, barbara, 1) T Call: (10) father(_L205, barbara) T Exit: (10) father(norman, barbara) T Call: (10) ancestoriter(_G463, norman, 2) T Exit: (10) ancestoriter(norman, norman, 2) T Exit: (9) ancestoriter(norman, barbara, 1) T Exit: (8) ancestoriter(norman, lucy, 0) X = norman ; T Redo: (10) ancestoriter(_G463, norman, 2) T Call: (11) father(_L242, norman) T Fail: (11) father(_L242, norman) T Redo: (10) ancestoriter(_G463, norman, 2) T Call: (11) mother(_L242, norman) T Fail: (11) mother(_L242, norman) T Redo: (10) father(_L205, barbara) T Fail: (10) father(_L205, barbara) T Redo: (9) ancestoriter(_G463, barbara, 1) T Call: (10) mother(_L205, barbara) T Exit: (10) mother(dorothy, barbara) T Call: (10) ancestoriter(_G463, dorothy, 2) T Exit: (10) ancestoriter(dorothy, dorothy, 2) T Exit: (9) ancestoriter(dorothy, barbara, 1) T Exit: (8) ancestoriter(dorothy, lucy, 0) X = dorothy ; T Redo: (10) ancestoriter(_G449, dorothy, 2) T Call: (11) father(_L235, dorothy) T Exit: (11) father(george, dorothy) T Call: (11) ancestoriter(_G449, george, 3) T Exit: (11) ancestoriter(george, george, 3) T Exit: (10) ancestoriter(george, dorothy, 2) T Exit: (9) ancestoriter(george, barbara, 1) T Exit: (8) ancestoriter(george, lucy, 0) X = george ; T Redo: (11) ancestoriter(_G449, george, 3) T Call: (12) father(_L255, george) T Fail: (12) father(_L255, george) T Redo: (11) ancestoriter(_G449, george, 3) T Call: (12) mother(_L255, george) T Fail: (12) mother(_L255, george) T Redo: (10) ancestoriter(_G449, dorothy, 2) T Call: (11) mother(_L235, dorothy) T Exit: (11) mother(mary, dorothy) T Call: (11) ancestoriter(_G449, mary, 3) T Exit: (11) ancestoriter(mary, mary, 3) T Exit: (10) ancestoriter(mary, dorothy, 2) T Exit: (9) ancestoriter(mary, barbara, 1) T Exit: (8) ancestoriter(mary, lucy, 0) X = mary ; T Redo: (11) ancestoriter(_G449, mary, 3) T Call: (12) father(_L265, mary) T Fail: (12) father(_L265, mary) T Redo: (11) ancestoriter(_G449, mary, 3) T Call: (12) mother(_L265, mary) T Fail: (12) mother(_L265, mary) T Redo: (11) mother(_L235, dorothy) T Fail: (11) mother(_L235, dorothy) T Redo: (10) mother(_L205, barbara) T Fail: (10) mother(_L205, barbara) false.