Simple Program in PROLOG

PROLOG, which is an acronym of PROgramming in LOGic, is commonly used for handling  this class of reasoning problems. Prolog is a declarative language that focilityuses on logic.

Prolog has been successfull as an AI (Artificial Intelligence) programming language for the following reasons.

  1. The syntax and semantics of prolog are very close to formal logic.
  2. Prolog language has a built in inference engine and automatic backtracking facility.
  3. This language has high productivity and ease of program maintenance.
  4. Prolog language is based on the universal formalism of Horn Clause.
  5. Beacuse of the inherent AND parallelism, prolog language can b implemented with the ease on parallel machines.
  6. The clause of prolog have a procedural and declarative meaning. Because of this, understanding of the languge is easier.
  7. In prolog, each clause can be executed separately as though it is a separate program.  Hence modular programming and testing is possible.

To run a simple program of PROLOG, just to have the knowledge about the structure of PROLOG program, you need to install swi-prolog on linux system with the command:

sudo apt-get install swi-prolog

Write a simple prolog program named
(note: pl is extension of PROLOG program)

/* Some facts about parent relationships */                           
/* A general rule */                                                  
grandparent(GRANDPARENT,CHILD) :-                                     

To run the program:

1. Start prolog


2. Load prolog program

?- [test].

3. Query the program

?-grandparent(WHO, jim).

It will give


Here is the screen shot for whatever we query.


Overview of PROLOG language:

  1. Facts starts with lowercase letter( or enclosed in single quotes) and ends with a period (.)
  2. Rules have syntax: rule:-condition1,condition2. :- is a break , is AND relationship ; is OR relationship.
  3. Variables starts with uppercase letters.

Thats all. 🙂


About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Simple Program in PROLOG

  1. Nice one i think this is the first blog on technology , that i am reading .. which company you are working for ? are u from India

  2. I am not working for any company. I am a student, pursuing B.Tech IT from Guru Nanak Dev Engineering College, Ludhiana (Punjab). Yes, I am from India 🙂
    If you read About page of this blog, you would not ask this question 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s