Implementation of Family Tree in Prolog: Full Code in Prolog

Implementation of Family Tree in Prolog: Full Code in Prolog
Implementation of Family Tree in Prolog: Full Code in Prolog


What is Prolog?
  1. It is a declarative and logical programming language.
  2. It is a short form of programming(PRO) and Logic(LOG).
  3. It is used in programs that consist of non-numeric or symbolic computation.
  4. It is used in artificial intelligence where manipulation of symbols is a common work.
  5. The Prolog specifies relationships among objects and properties of the objects.
  6. Prolog programs consist of a series of rules and facts.


Code:

female(carmel).

female(regina).
male(pascol).
male(peter).
male(prevail).
parent(pascol,peter).
parent(carmel,peter).
parent(peter,prevail).
parent(regina,prevail).
mother(X,Y):-parent(X,Y),female(X).
father(X,Y):-parent(X,Y),male(X).
haschild(X):-parent(X,_).





Output:

GNU Prolog 1.4.5 (64 bits)
Compiled Jul 14 2018, 13:19:42 with x86_64-w64-mingw32-gcc
By Daniel Diaz
Copyright (C) 1999-2018 Daniel Diaz
| ?- change_directory('C:/GNU-Prolog/bin/pp').

yes
| ?- [pp1].
compiling C:/GNU-Prolog/bin/pp/pp1.pl for byte code...
C:/GNU-Prolog/bin/pp/pp1.pl compiled, 11 lines read - 1660 bytes written, 5 msv
yes
| ?- male(X).

X = pascol ? ;

X = peter ? ;

X = prevail

(15 ms) yes
| ?- female(X).

X = carmel ? ;

X = regina

yes
| ?- father(X,Y).

X = pascol
Y = peter ? ;

X = peter
Y = prevail ? ;

(16 ms) no
| ?- mother(X,Y).

X = carmel
Y = peter ? ;

X = regina
Y = prevail

yes

| ?-




Post a Comment

0 Comments