You are currently viewing Introduction to Prolog

Introduction to Prolog

In previous article we have discussed about Artificial Intelligence. In in this article we will talk about Programming Language used for making Artificial Intelligence Programmes i.e. Prolog.

Prolog was invented at the University of Marseille. Prolog stands for Programming in Logic. It is a logic language that is particularly used by programs that use non-numeric objects. For this reason it is a frequently used language in Artificial Intelligence where manipulation of symbols is a common task. Prolog differs from the most common programming languages because it is declarative language. In declarative languages the programmers only give the problem and the language find himself how to solve the problem.

 

Prolog Program

Prolog can be separated in two parts:

  1. The Program:The program, sometimes called Database is a texted file (*.pl) that contain the facts and rules that will be used by the user of the program. It contains all the relations that make this program.
  2. The Query:When we launch a program we are in query mode. This mode is represented by the sign? – At the beginning of the line. In query mode we can ask questions about relations described in the program.

Facts

In Prolog we can make some statements by using facts. Facts either consist of a particular item or a relation between items. Facts have some simple rules of syntax. Facts should always begin with a lowercase letter and end with a full stop. The facts themselves can consist of any letter or number combination, as well as the underscore _ character.

For example we can represent the fact that it is sunny by writing the program :

sunny. We can now ask a query of Prolog by asking  ?- sunny.

To this query, Prolog will answer yes.

Facts with arguments:

More complicated facts consist of a relation and the items that this refers to. These items are called arguments. Facts can have arbitrary number of arguments from zero upwards.

The general notation is:  relation (<argument1>, <argument2>, …, <argument N>).

The basic Prolog terms are an integer, an atom, a variable or a structure.

Example:  likes (john, mary).

This fact says that there is a relation between john and mary. ‘likes’ is the relation name also known as predicate value and ‘john’ and ‘mary’ are the two objects or the arguments.

In the above fact john and mary are two atoms. Atoms are usually made from letters and digits with lowercase characters. The underscore (_) can also be used to separate two words but is not allowed as the first characters.

 

Steps to run a program in PROLOG:

  1. Write a program in a notepad and save with .txt extension.
  2. Open PROLOG and click on file then select consult.
  3. Select the notepad file in which program is written. 
  4. In the last step write the queries to run the program.

 

Dinesh Kumar Bansal

Dinesh Kumar Bansal is an Indian Software Developer, who is working on ASP.Net, MS-SQL, SAP-ABAP technologies from last one year. His Basic Principle of developing software is, “You have to clear about, what do you want to do, how can it be done”. He always says that development can be done with a cool & fresh mind.

Leave a Reply