Prolog | An Introduction

Last Updated : 28 Jun, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow


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.

Reference 1: https://en.wikipedia.org/wiki/Prolog

Reference 2: http://www.swi-prolog.org/



Similar Reads

Lists in Prolog
A list is a collection of items, not necessarily homogeneous. In Prolog, lists are inbuilt data structures. Lists can be used to represent sets, stacks, queues, linked lists, and several complex data structures such as trees, graphs, etc. Basic Notation and Properties of Lists:A list in Prolog is an ordered collection of items denoted as [i1, i2, .
4 min read
Java | MIDI Introduction
Introduction: Java MIDI is a set of Java APIs for handling musical data and MIDI (Musical Instrument Digital Interface) devices. These APIs allow Java programs to access and manipulate MIDI data, and can be used to create applications such as music players, synthesizers, and more. The Java Sound API, which includes the MIDI package, provides a low-
8 min read
Introduction to Programming Languages
Introduction: A programming language is a set of instructions and syntax used to create software programs. Some of the key features of programming languages include: Syntax: The specific rules and structure used to write code in a programming language.Data Types: The type of values that can be stored in a program, such as numbers, strings, and bool
13 min read
Introduction to Go Programming
Go (also referred as Golang) is a procedural and statically-typed programming language having syntax similar to C language. It provides a rich standard library, garbage collection, and dynamic-typing capability. This language also has key-value maps, length arrays features which are advance level built-in types. Go is the most powerful, performant,
5 min read
Introduction to the C99 Programming Language : Part I
Introduction: C99 is a standardized version of the C programming language that was published in 1999 by the International Organization for Standardization (ISO). It introduced a number of new features and improvements over the previous C89 standard, including support for variable-length arrays, flexible array members, complex numbers, and new keywo
8 min read
Introduction to the C99 Programming Language : Part II
In this article, we are going to discover some more interesting additions to C89 which gave us C99 standard: Variable Argument Lists: C99 brings out a small changes to the preprocessor. Macros can accept a variable number of arguments. These Macros are indicated by ellipsis (...) in their declaration. These Variable Arguments are represented by the
4 min read
Introduction to the C99 Programming Language : Part III
Kindly read Introduction to the C99 Programming Language (Part I) and Introduction to the C99 Programming Language (Part II) before reading this article. Addition of Library Functions: C99 provides some Additional Library functions listed below. Library Function Usage complex.h complex.h supports complex arithmetic fenv.h fenv.h gives access to flo
3 min read
Introduction to CherryPy
CherryPy is a popular framework of Python. Using CherryPy, web applications can be built in a faster and more reliable way. It is also called a web application library. It is known for its simplicity as it is based on object-oriented Python programming, resulting in smaller source code in less time. It is one of the oldest frameworks of Python, the
3 min read
Introduction of Object Oriented Programming
As the name suggests, Object-Oriented Programming or OOPs refers to languages that use objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of
6 min read
Introduction to Visual Programming Language
Any language that uses the graphics or blocks that are already defined with the code and you just need to use those blocks without worrying about the lines of code is known as a visual programming language. In today's era majority of the programming languages are text-based i.e. we have to write the lines of code to perform the specific task like i
6 min read
Introduction to Swift Programming
Swift is a general-purpose, multi-paradigm, object-oriented, functional, imperative and block structured language. It is the result of the latest research on programming languages and is built using a modern approach to safety, software design patterns by Apple Inc.. It is the brand new programming language for iOS application, macOS application, w
5 min read
Golang
Golang is a procedural and statically typed programming language having the syntax similar to C programming language. Sometimes it is termed as Go Programming Language. It provides a rich standard library, garbage collection, and dynamic-typing capability. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launch
2 min read
Python for Kids - Fun Tutorial to Learn Python Programming
Python for Kids - Python is an easy-to-understand and good-to-start programming language. In this Python tutorial for kids or beginners, you will learn Python and know why it is a perfect fit for kids to start. Whether the child is interested in building simple games, creating art, or solving puzzles, Python provides the foundation to the kids or a
15+ min read
7 Best IDEs For C/C++ Developers in 2024
Everything has been digitized in this digital era, and nothing seems possible without programming. The fact that C is the building block of all the programming languages can't be denied. Also, the extended version of C is C++, which you can call a subset of C. Every one of us must have gone through the basic concepts of this language before steppin
8 min read
Top 10 Fastest Programming Languages
There are approximately 700 programming languages in the world. In simple words, a programming language is used to give instructions to the computer to perform the task which we require. Have you ever wondered which is the fastest of all the programming languages in terms of execution speed? In most cases, speed is not the only metric to choose whi
8 min read
Passing a Function as a Parameter in C++
A function is a set of statements that take inputs, perform some specific computation, and produce output. The idea to use functions is to perform some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs. The general form of a function is in the below format: r
4 min read
Shallow Copy and Deep Copy in C++
In general, creating a copy of an object means to create an exact replica of the object having the same literal value, data type, and resources. There are two ways that are used by C++ compiler to create a copy of objects. Copy ConstructorAssignment Operator// Copy ConstructorGeeks Obj1(Obj);orGeeks Obj1 = Obj;// Default assignment operatorGeeks Ob
6 min read
Difference between Shallow and Deep copy of a class
Shallow Copy: Shallow repetition is quicker. However, it's "lazy" it handles pointers and references. Rather than creating a contemporary copy of the particular knowledge the pointer points to, it simply copies over the pointer price. So, each of the first and therefore the copy can have pointers that reference constant underlying knowledge. Deep C
5 min read
20 Best Programming Languages to Learn in 2025: A Complete List for Developers
Are you wondering which programming languages will dominate the tech world in 2025? Curious about which skills will be most in demand by employers? Or perhaps you're trying to figure out which programming language is the best fit for your career growth? Whether you’re an experienced developer aiming to sharpen your skills or a beginner wondering wh
15+ min read
R - Matrices
R-matrix is a two-dimensional arrangement of data in rows and columns. In a matrix, rows are the ones that run horizontally and columns are the ones that run vertically. In R programming, matrices are two-dimensional, homogeneous data structures. These are some examples of matrices: Creating a Matrix in RTo create a matrix in R you need to use the
12 min read
Extract text from PDF File using Python
All of you must be familiar with what PDFs are. In fact, they are one of the most important and widely used digital media. PDF stands for Portable Document Format. It uses .pdf extension. It is used to present and exchange documents reliably, independent of software, hardware, or operating system. We will extract text from pdf files using two Pytho
5 min read
getch() function in C with Examples
getch() is a nonstandard function and is present in conio.h header file which is mostly used by MS-DOS compilers like Turbo C. It is not part of the C standard library or ISO C, nor is it defined by POSIX.Like these functions, getch() also reads a single character from the keyboard. But it does not use any buffer, so the entered character is immedi
3 min read
Features of C Programming Language
C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and a clean style, these features make C language suitable for sys
3 min read
Increment and Decrement Operators in C
The increment ( ++ ) and decrement ( -- ) operators in C are unary operators for incrementing and decrementing the numeric values by 1 respectively. The incrementation and decrementation are one of the most frequently used operations in programming for looping, array traversal, pointer arithmetic, and many more. In this article, we will discuss the
4 min read
Structures in C++
We often come around situations where we need to store a group of data whether of similar data types or non-similar data types. We have seen Arrays in C++ which are used to store set of data of similar data types at contiguous memory locations.Unlike Arrays, Structures in C++ are user defined data types which are used to store group of items of non
5 min read
Differences between Procedural and Object Oriented Programming
This article focuses on discussing the differences between procedural and object-oriented programming. Procedural Programming Procedural Programming can be defined as a programming model which is derived from structured programming, based upon the concept of calling procedure. Procedures, also known as routines, subroutines or functions, simply con
2 min read
Java Swing | JComboBox with examples
JComboBox is a part of Java Swing package. JComboBox inherits JComponent class . JComboBox shows a popup menu that shows a list and the user can select a option from that specified list . JComboBox can be editable or read- only depending on the choice of the programmer .Constructor of the JComboBox are: JComboBox() : creates a new empty JComboBox .
7 min read
C# | Data Types
Data types specify the type of data that a valid C# variable can hold. C# is a strongly typed programming language because in C#, each type of data (such as integer, character, float, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data type
7 min read
type() function in Python
The type() function is mostly used for debugging purposes. Two different types of arguments can be passed to type() function, single and three arguments. If a single argument type(obj) is passed, it returns the type of the given object. If three argument types (object, bases, dict) are passed, it returns a new type object. Python type() function Sy
5 min read
Python String format() Method
The format() method is a powerful tool that allows developers to create formatted strings by embedding variables and values into placeholders within a template string. This method offers a flexible and versatile way to construct textual output for a wide range of applications. Python string format() function has been introduced for handling complex
13 min read
Article Tags :
three90RightbarBannerImg