0% found this document useful (0 votes)
21 views4 pages

Prolog

Prolog is a logic programming language primarily used in artificial intelligence, focusing on declarative programming through facts and rules. It allows users to create a knowledge base and run queries to retrieve information, with features like unification, backtracking, and recursion. While it offers advantages such as easy database building and pattern matching, it 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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Prolog

Prolog is a logic programming language primarily used in artificial intelligence, focusing on declarative programming through facts and rules. It allows users to create a knowledge base and run queries to retrieve information, with features like unification, backtracking, and recursion. While it offers advantages such as easy database building and pattern matching, it 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 PDF, TXT or read online on Scribd

2/15/2020 Prolog | An Introduction - GeeksforGeeks

es

Prolog | An Introduction
Custom Search
Introduction :

in Prolog is a logic programming language. It has important role in arti cial intelligence. Unlike many other
Hire with us!
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 :

AppSumo™ Limited Time Offer

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 a rmative 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 de nite 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).

[Link] 1/4
2/15/2020 Prolog | An Introduction - GeeksforGeeks

Explanation :
These facts can be interpreted as :
raju and mahesh are friends.
sonu is a singer.
5 is an odd number.

Key Features :
1. Uni cation : 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 arti cial intelligence(AI). Prolog is also used for pattern matching over natural

language parse trees.

Reference 1: [Link]

Reference 2: [Link]

[Link] 2/4
2/15/2020 Prolog | An Introduction - GeeksforGeeks

PERIYAR INN
₹1,400
Ad MakeMyTrip
Learn more

Recommended Posts:
HQL | Introduction
SAP | An Introduction
Introduction to Smalltalk
Robotics | Introduction
Introduction to WebRTC
DHTML | Introduction
Introduction to AWS Batch
Introduction and Installation of Git
Introduction to SAS programming
Introduction To APIs
Introduction to Git Branch
Introduction of Vault
Apache POI | Introduction
Introduction to TensorFlow
Introduction of Libra

Prasad_Kshirsagar
Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using
[Link] or mail your article to contribute@[Link]. See your article
appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you nd anything incorrect by clicking on the "Improve Article" button
below.

Improved By : ManasChhabra2

Article Tags : GBlog Programming Language

[Link] 3/4
2/15/2020 Prolog | An Introduction - GeeksforGeeks


2

2.5
To-do Done
Based on 2 vote(s)

Feedback/ Suggest Improvement Add Notes Improve Article

Please write to us at contribute@[Link] to report any issue with the above content.

Writing code in comment? Please use [Link], generate link and share the link here.

Load Comments

5th Floor, A-118,


Sector-136, Noida, Uttar Pradesh - 201305
feedback@[Link]

COMPANY LEARN
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Video Tutorials

PRACTICE CONTRIBUTE
Courses Write an Article
Company-wise Write Interview Experience
Topic-wise Internships
How to begin? Videos

@geeksforgeeks, Some rights reserved

[Link] 4/4

Common questions

Powered by AI

Prolog offers an easier way to build databases without extensive programming, and it excels in pattern matching due to its recursion-based search processes. However, it has disadvantages compared to other logic programming languages like LISP, particularly regarding input and output capabilities. LISP is said to dominate Prolog in I/O features, which sometimes makes Prolog's I/O operations less intuitive and challenging .

Developers might face challenges with Prolog's input and output operations as they are not as straightforward as in other languages like LISP. This complexity arises due to Prolog's declarative nature which doesn't inherently follow procedural I/O mechanisms. These challenges may affect its application in scenarios where seamless I/O processing is critical, thereby requiring developers to implement intricate workarounds .

Prolog plays an important role in artificial intelligence (AI) as it is primarily a declarative programming language that allows the expression of logic as relations called Facts and Rules. This allows for the building of knowledge bases which can be queried to derive conclusions, which is a core requirement in AI applications. Its ability to perform pattern matching and recursive searches makes it suitable for AI tasks such as natural language processing .

Backtracking in Prolog allows the language to handle complex problem solving by retracing its steps to find alternate solutions when initial attempts fail. This means if a particular rule or fact cannot satisfy a query, Prolog will go back to previous points and try different paths until a solution is found or all possibilities are exhausted. This mechanism is key to implementing recursive searches and effectively builds on its logical framework to solve problems systematically .

Recursion in Prolog is critical because it enables the language to handle repetitive and complex structure queries by self-referential calls within a logic rule. This facilitates search operations, as recursive rules allow paths to be explored systematically by breaking down problems into simpler, solvable components. It is hence essential for naturally implementing pattern matching and exploring multiple solutions in search tasks .

Prolog's logic programming nature is fundamentally declarative, meaning it focuses on the 'what' rather than the 'how' of problem-solving, unlike procedural programming which is imperative. In Prolog, the logic is defined in terms of relations and rules, and the execution involves deriving consequences based on these predefined facts, whereas procedural programming executes step-by-step commands. This allows Prolog to excel at pattern matching and symbolic computation tasks that don't necessarily follow sequential logic .

Unification in Prolog refers to the ability to make two terms represent the same structure through logical consistency, which is essential for pattern matching and deducing relationships. Recursion allows for iterative problem solving, where functions call themselves to handle repetitive structures, enabling complex queries and searches. Together, these concepts enhance Prolog's logic processing capabilities by allowing diverse and dynamic query responses .

Prolog is particularly useful in developing AI applications requiring non-linear problem solving due to its inherent declarative approach, which facilitates the exploration of multiple solutions and alternative paths through its backtracking and recursion mechanisms. Traditional programming languages often follow strict sequential logic, limiting their ability to address problems that require dynamic logic evaluation and complex pattern matching. Thus, Prolog can handle AI tasks such as inference solving and knowledge representation more effectively .

Prolog's pattern matching capabilities are advantageous for parsing natural language constructs because they allow for the effective handling of symbolic representation and relationships. Prolog can easily match complex patterns found in natural language text, thanks to its flexible and declarative structure which excels in mapping syntax and semantics in a tree-based pattern matching model, making it suitable for AI-driven language processing tasks .

A knowledge base in Prolog is structured using facts and rules that define relationships between entities. These are expressed in a definite pattern and end with a dot, such as 'relation(entity1, entity2).' The knowledge base acts like a database where one can query the data. If a query matches or is implied by the knowledge base, it returns a positive result, which is crucial for executing logical operations and deriving conclusions in Prolog .

You might also like