0% found this document useful (0 votes)
10 views2 pages

Prolog

Prolog is a declarative logic programming language primarily used in artificial intelligence, where logic is expressed through facts and rules. It allows users to build a knowledge base and query it, with features like unification, backtracking, and recursion. Prolog is advantageous for database creation and pattern matching but has limitations in I/O features compared to other languages like LISP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Prolog

Prolog is a declarative logic programming language primarily used in artificial intelligence, where logic is expressed through facts and rules. It allows users to build a knowledge base and query it, with features like unification, backtracking, and recursion. Prolog is advantageous for database creation and pattern matching but has limitations in I/O features compared to other languages like LISP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Prolog | An Introduction

Prolog is a logic programming language. It has important role in artificial


intelligence. Unlike many other programming languages, Prolog is intended
primarily as a declarative programming language. In prolog, logic is expressed
as relations (called as Facts and Rules). Core heart of prolog lies at
the logic being applied. Formulation or Computation is carried out by running a
query over these relations.

Installation in Linux :

Open a terminal (Ctrl+Alt+T) and type:

sudo apt-get install swi-prolog

Syntax and Basic Fields :

In prolog, We declare some facts. These facts constitute the Knowledge Base of
the system. We can query against the Knowledge Base. We get output as
affirmative if our query is already in the knowledge Base or it is implied by
Knowledge Base, otherwise we get output as negative. So, Knowledge Base can
be considered similar to database, against which we can query. Prolog facts are
expressed in definite pattern. Facts contain entities and their relation. Entities
are written within the parenthesis separated by comma (, ). Their relation is
expressed at the start and outside the parenthesis. Every fact/rule ends with a
dot (.). So, a typical prolog fact goes as follows :
Format : relation(entity1, entity2, ....k'th entity).

Example :
friends(raju, mahesh).
singer(sonu).
odd_number(5).

Explanation :
These facts can be interpreted as :
raju and mahesh are friends.
sonu is a singer.
5 is an odd number.
Key Features :
1. Unification : The basic idea is, can the given terms be made to represent
the same structure.
2. Backtracking : When a task fails, prolog traces backwards and tries to
satisfy previous task.
3. Recursion : Recursion is the basis for any search in program.

Running queries :

A typical prolog query can be asked as :


Query 1 : ?- singer(sonu).
Output : Yes.

Explanation : As our knowledge base contains


the above fact, so output was 'Yes', otherwise
it would have been 'No'.

Query 2 : ?- odd_number(7).
Output : No.

Explanation : As our knowledge base does not


contain the above fact, so output was 'No'.

Advantages :
1. Easy to build database. Doesn’t need a lot of programming effort.
2. Pattern matching is easy. Search is recursion based.
3. It has built in list handling. Makes it easier to play with any algorithm
involving lists.
Disadvantages :
1. LISP (another logic programming language) dominates over prolog with
respect to I/O features.
2. Sometimes input and output is not easy.
Applications :
Prolog is highly used in artificial intelligence(AI). Prolog is also used for pattern
matching over natural language parse trees.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy