A Prolog-based family tree implementation demonstrating logical inference, pattern matching, and recursive queries across three generations.
- Basic Relationships: Parent, child, father, mother
- Grandparent Relationships: Implemented using logical composition
- Sibling Detection: Identifies siblings through shared parents
- Cousin Relationships: Finds cousins via parent-sibling relationships
- Recursive Queries: Ancestor and descendant tracking across multiple generations
John + Mary (Generation 1)
├── Robert + Linda
│ ├── David
│ └── Jennifer
├── Patricia
│ ├── James
│ └── Susan
└── Michael
├── James
└── Susan
- SWI-Prolog → Download here
or use online: SWISH Online Prolog
# Clone this repository
git clone [your-repo-url]
cd family-tree-prolog
# Start Prolog
swiplThen load the program:
?- [family_tree].Find children of a person:
?- child(X, john).Check if someone is a parent:
?- parent(john, robert).Find all grandchildren:
?- grandparent(X, david).Find grandparents of a person:
?- grandparent(john, X).Find siblings:
?- sibling(robert, X).
?- sibling(david, jennifer).Find all cousins:
?- cousin(david, X).Check cousin relationship:
?- cousin(james, david).Find all descendants:
?- descendant(X, john).Find all ancestors:
?- ancestor(X, david).parent(X, Y) - X is parent of Y
father(X, Y) - X is father of Y
mother(X, Y) - X is mother of Y
child(X, Y) - X is child of Y
grandparent(X, Y) - X is grandparent of Y
sibling(X, Y) - X and Y are siblings
cousin(X, Y) - X and Y are cousins
ancestor(X, Y) - X is ancestor of Y (recursive)
descendant(X, Y) - X is descendant of Y% Load the program
?- [family_tree].
% Who are John's children?
?- child(X, john).
X = robert ;
X = patricia ;
X = michael.
% Is Mary the grandmother of David?
?- grandparent(mary, david).
true.
% Who are David's cousins?
?- cousin(david, X).
X = james ;
X = susan.
% Find all descendants of John
?- descendant(X, john).
X = robert ;
X = patricia ;
X = michael ;
X = david ;
X = jennifer ;
X = james ;
X = susan.family-tree-prolog/
├── family_tree.pl # Main Prolog program
├── README.md # This file
└── queries.txt # Sample queries and outputs
This project was created as part of a Prolog assignment to demonstrate:
- Logical inference and pattern matching
- Recursive rule implementation
- Family relationship modeling
- Query-based knowledge retrieval
This project is created for educational purposes.