Skip to content

A Prolog family tree program demonstrating logical inference, recursive queries, and pattern matching. Implements parent-child, sibling, cousin, grandparent, and ancestor-descendant relationships across three generations using declarative logic programming.

License

Notifications You must be signed in to change notification settings

Akhil-uc/Family_Tree_in_Prolog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Family Tree Program in Prolog

A Prolog-based family tree implementation demonstrating logical inference, pattern matching, and recursive queries across three generations.


Features

  • 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

Family Structure

John + Mary (Generation 1)
├── Robert + Linda
│   ├── David
│   └── Jennifer
├── Patricia
│   ├── James
│   └── Susan
└── Michael
    ├── James
    └── Susan

Installation

Requirements

Setup

# Clone this repository
git clone [your-repo-url]
cd family-tree-prolog

# Start Prolog
swipl

Then load the program:

?- [family_tree].

Usage

Basic Queries

Find children of a person:

?- child(X, john).

Check if someone is a parent:

?- parent(john, robert).

Grandparent Queries

Find all grandchildren:

?- grandparent(X, david).

Find grandparents of a person:

?- grandparent(john, X).

Sibling Queries

Find siblings:

?- sibling(robert, X).
?- sibling(david, jennifer).

Cousin Queries

Find all cousins:

?- cousin(david, X).

Check cousin relationship:

?- cousin(james, david).

Recursive Queries

Find all descendants:

?- descendant(X, john).

Find all ancestors:

?- ancestor(X, david).

Rules Implemented

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

Examples

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

Project Structure

family-tree-prolog/
├── family_tree.pl      # Main Prolog program
├── README.md           # This file
└── queries.txt         # Sample queries and outputs

Assignment Details

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

License

This project is created for educational purposes.


About

A Prolog family tree program demonstrating logical inference, recursive queries, and pattern matching. Implements parent-child, sibling, cousin, grandparent, and ancestor-descendant relationships across three generations using declarative logic programming.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages