Download presentation
Presentation is loading. Please wait.
Published byGillian Maxwell Modified over 9 years ago
1
Prolog programming Introduction to Prolog CS370d - CS 461
2
What is Prolog programming? Prolog is a programming language for symbolic, non-numeric commutation. It solves problems that involve objects and relations between objects.
3
Defining relations by facts The fact that Tom is a parent of Bob can be written in prolog as: parent(tom, bob). tom and bob are objects, parent(tom, bob) is a relation between these objects.
4
Defining relations by facts The whole family tree can be described by the following facts: pam tom bob liz ann pat jim
5
Defining relations by facts The whole family tree can be described by the following facts: parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). pam tom bob liz ann pat jim
6
Defining relations by facts We can also add information about the sex of the people by the following facts: female(pam). male(tom). male(bob). female(liz). female(pat). female(ann). male(jim).
7
Defining relations by facts female(pam) is a Unary relation parent(bob,pat) is a Binary relation. Think about this relation: sex(pam, feminist).
8
SWI-Prolog SWI-Prolog editor is an open source implementation of the programming language. Prolog is a free software and you can download it from here: http://www.swi-prolog.org/Download.html
9
SWI-Prolog Getting started: ▫Any Prolog program in SWI-Prolog is written in a file with extension.pl. You can write your own one by following these steps:
10
SWI-Prolog After opening SWI Prolog environment, choose file -> new to create a new.pl file.
11
SWI-Prolog This will open a new window to create the new file, choose any name for your programs (here we name it tree) then choose to save it.
12
SWI-Prolog Now the.pl file we have just created will be opened, and we can write our own program. Let's write the following facts about parent, male and female relationships: parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). female(pam). female(liz). female(pat). female(ann). male(tom). male(bob). male(jim).
13
SWI-Prolog
14
Compile your program. Compile - > Make
15
SWI-Prolog Then click “ OK ” to save the changes on your file.
16
SWI-Prolog In SWI Prolog environment, load your program by file -> consult. Then choose your program.
17
Questions in prolog. Prolog can posed questions about any relation. So, we can ask a question about Parent relation, For example : Is bob a parent of Pat? ?- parent(bob,pat). The answer will be true.
18
Exercise 1: Write prolog program of your own family tree.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.