0% found this document useful (0 votes)
20 views

Explorando Prolog

This document defines relationships between family members using Prolog predicates. It defines basic relationships like parent, father, mother, and sibling. It then expands on these to define more complex relationships such as uncle, grandparent, and various in-law relationships including sibling-in-law, parent-in-law, uncle-in-law, and grandparent-in-law. Examples of individuals and their relationships are provided to demonstrate how these predicates can be used.

Uploaded by

Helton Nogueira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Explorando Prolog

This document defines relationships between family members using Prolog predicates. It defines basic relationships like parent, father, mother, and sibling. It then expands on these to define more complex relationships such as uncle, grandparent, and various in-law relationships including sibling-in-law, parent-in-law, uncle-in-law, and grandparent-in-law. Examples of individuals and their relationships are provided to demonstrate how these predicates can be used.

Uploaded by

Helton Nogueira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exerccio - Explorando Prolog - Relacionamentos Familiares

Aluno: Helton Soares Nogueira


Matricula: 21206419

male(i).
male(f).
male(s1).
male(s2).
married(i,w).
parent(w,d).
parent(f,i).
married(f,d).
parent(w,s1).
parent(i,s1).
parent(f,s2).
parent(d,s2).

married(X,Y) :- tmarried(X,Y).
tmarried(X, Y) :- married(Y,X).

female(X) :- not(male(X)).

%% Normal relationships
father(Parent, Child) :parent(Parent, Child),
male(Parent).

mother(Parent, Child) :parent(Parent, Child),


female(Parent).

sibling(X,Y) :parent(F, X),


parent(F, Y), X = Y.

uncle(Uncle, Nephew) :parent(Parent, Nephew),


sibling(Parent, Uncle),
male(Uncle).

grandparent(Grandfather, Grandchild) :parent(X,Grandchild), parent(Grandfather,X).

%% In-law relationships
sibling_in_law(X,Y) :parent(P,X),
parent_in_law(P,Y),
X = Y.

sibling_in_law(X,Y) :parent(P,Y),
parent_in_law(P,X),
X = Y.

parent_in_law(Parent, Child) :parent(Partner, Child),


married(Parent, Partner).

uncle_in_law(Uncle, Nephew) :parent_in_law(Parent, Nephew),


sibling(Parent, Uncle),
male(Uncle).

grandparent_in_law(Grandparent, Grandchild) :( parent_in_law(X, Grandchild), parent_in_law(Grandparent, X) );


( parent(X, Grandchild), parent_in_law(Grandparent, X) );
( parent_in_law(X, Grandchild), parent(Grandparent, X) ).

grandfather_in_law(Grandfather, Grandchild) :grandparent_in_law(Grandfather, Grandchild),


male(Grandfather).

You might also like