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.
- The syntax and semantics of prolog are very close to formal logic.
- Prolog language has a built in inference engine and automatic backtracking facility.
- This language has high productivity and ease of program maintenance.
- Prolog language is based on the universal formalism of Horn Clause.
- Beacuse of the inherent AND parallelism, prolog language can b implemented with the ease on parallel machines.
- The clause of prolog have a procedural and declarative meaning. Because of this, understanding of the languge is easier.
- 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 test.pl
(note: pl is extension of PROLOG program)
/* Some facts about parent relationships */ parent(sam,mark). parent(mark,jim). /* A general rule */ grandparent(GRANDPARENT,CHILD) :- parent(GRANDPARENT,PARENT), parent(PARENT,CHILD).
To run the program:
1. Start prolog
2. Load prolog program
3. Query the program
It will give
Here is the screen shot for whatever we query.
Overview of PROLOG language:
- Facts starts with lowercase letter( or enclosed in single quotes) and ends with a period (.)
- Rules have syntax: rule:-condition1,condition2. :- is a break , is AND relationship ; is OR relationship.
- Variables starts with uppercase letters.
Thats all. 🙂