Prolog
Prolog
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 :
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 :
Example :
friends(raju, mahesh).
singer(sonu). ▲
odd_number(5).
https://www.geeksforgeeks.org/prolog-an-introduction/ 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.
Query 2 : ?- odd_number(7).
Output : 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
⇣
Reference 1: https://en.wikipedia.org/wiki/Prolog
Reference 2: http://www.swi-prolog.org/
https://www.geeksforgeeks.org/prolog-an-introduction/ 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
contribute.geeksforgeeks.org or mail your article to [email protected]. 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
https://www.geeksforgeeks.org/prolog-an-introduction/ 3/4
2/15/2020 Prolog | An Introduction - GeeksforGeeks
2
2.5
To-do Done
Based on 2 vote(s)
Please write to us at [email protected] to report any issue with the above content.
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Load Comments
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
https://www.geeksforgeeks.org/prolog-an-introduction/ 4/4