Unit 3 PPL
Unit 3 PPL
Functional Programming
We will discuss about the differences between Logic programming and the traditional
functional programming languages. We can illustrate these two using the below diagram −
From this illustration, we can see that in Functional Programming, we have to define the
procedures, and the rule how the procedures work. These procedures work step by step to solve
one specific problem based on the algorithm. On the other hand, for the Logic Programming,
we will provide knowledge base. Using this knowledge base, the machine can find answers to
the given questions, which is totally different from functional programming.
In functional programming, we have to mention how one problem can be solved, but in logic
programming we have to specify for which problem we actually want the solution. Then the
logic programming automatically finds a suitable solution that will help us solve that specific
problem.
Ada
ALGOL
Assembly language
BASIC
C
C#
C++
COBOL
FORTRAN
JAVA
MATLAB
Python
The functional programming paradigm was explicitly created to support a pure functional
approach to problem solving. Functional programming is a form of declarative programming. In
contrast, most mainstream languages, including object-oriented programming (OOP) languages
such as C#, Visual Basic, C++, and Java, were designed to primarily
support imperative (procedural) programming.
With an imperative approach, a developer writes code that specifies the steps that the computer
must take to accomplish the goal. This is sometimes referred to as algorithmic programming. In
contrast, a functional approach involves composing the problem as a set of functions to be
executed. You define carefully the input to each function, and what each function returns. The
following table describes some of the general differences between these two approaches.
PROLOG
This implies that for X to be the grandfather of Y, Z should be a parent of Y and X should be
father of Z.
Other 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.
A typical prolog query can be asked as :
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'
The heritage of prolog includes the research on theorem provers and some other automated
deduction system that were developed in 1960s and 1970s. The Inference mechanism of the
Prolog is based on Robinson’s Resolution Principle, that was proposed in 1965, and Answer
extracting mechanism by Green (1968). These ideas came together forcefully with the advent of
linear resolution procedures.
The explicit goal-directed linear resolution procedures, gave impetus to the development of a
general purpose logic programming system. The first Prolog was the Marseille Prolog based
on the work by Colmerauer in the year 1970. The manual of this Marseille Prolog interpreter
(Roussel, 1975) was the first detailed description of the Prolog language.
Prolog is also considered as a fourth generation programming language supporting the
declarative programming paradigm. The well-known Japanese Fifth-Generation Computer
Project, that was announced in 1981, adopted Prolog as a development language, and thereby
grabbed considerable attention on the language and its capabilities.
Prolog is used in various domains. It plays a vital role in automation system. Following are
some other important fields where Prolog is used −
Intelligent Database Retrieval
Natural Language Understanding
Specification Language
Machine Learning
Robot Planning
Automation System
Problem Solving
Prolog is a logic programming language associated with AI and computational linguistics. It has
its roots in first-order logic, the formal logic, unlike many other programming languages. Prolog
is mainly a declarative programming language. It is possible to express the program logic as a set
of relations, facts and rules. Therefore, a computation can be initiated by running a query over
these relations.
Prolog was one of the first logic programming languages. It helps various tasks such as theorem
proving, expert systems, term rewriting, type systems, natural language processing and
automated planning. It also helps to create GUIs, administrative and networked applications.
Furthermore, Prolog is suitable for rule-based logical queries such as searching databases, filling
templates and voice control systems.
LISP
Lisp is a family of computer programming languages. And the most famous Lisp dialects used
for general purpose programming today are Common Lisp and Scheme. The name LISP comes
from “LISt Processing” and as it hints, Lisp’s major data structure is the linked list. In fact the
whole source is written using lists (using prefix notation), or more correctly parenthesized lists
(called s-expressions). For example, a function call is written as (f a1 a2 a3), which means
function f is called using a1, a2 and a3 as input arguments for the function. Therefore it is called
an expression oriented language, where all data and code are written as expressions (there is no
distinction between expressions and statements in Lisp). This nice feature is very special to Lisp,
where it could be used to extend the language to the problem at hand by writing helpful macros.
Although tail-recursion is used by programmers to express loops, all frequently seen Lisp
dialects do include control structures like loop. Furthermore, Common Lisp and scheme have
mapcar and map that are examples of functions, which provide looping functionality by applying
the function successively to all its elements and then collects the results in to a list.
Lisp is a computer programming language with a long history and a distinctive, fully
parenthesized prefix notation. The programmer writes all program code in s-expressions or
parenthesized lists. Furthermore, a function call or syntactic form can be written as a list with the
function or operator’s name first.
Lisp is an old, high-level programming language. The main objective of using Lisp is to
represent mathematical notations for computer programs. Some popular Lisp dialects are
Clojure, Common Lisp and Scheme. Moreover, it also helps to develop Artificial Intelligence
(AI) applications.
Prolog and Lisp are two of the most popular AI (Artificial Intelligence) computer programming
languages today. They are built with two different programming paradigms. Prolog is a
declarative language, while Lisp is a functional language. Both are used for various AI problems
but Prolog is used most for logic and reasoning problems, while Lisp is used for problems with
rapid prototyping needs.
Although, Prolog and Lisp are two of the most popular AI programming languages, they have
various differences. Lisp is a functional language, while Prolog is a logic programming and
declarative languages. Lisp is very flexible due to its fast prototyping and macro features, so it
actually allows extending the language to suit the problem at hand. In the areas of AI, graphics
and user interfaces, Lisp has been used extensively because of this rapid prototyping ability.
However, due to its inbuilt logic programming abilities, Prolog is ideal for AI problems with
symbolic reasoning, database and language parsing applications. Choice of one over the other
completely depends on the type of AI problem that need to be solved.
The main difference between Lisp and Prolog is that Lisp is a computer program language that
supports functional, procedural, reflective and meta paradigms while Prolog is a
computer programming language that supports logic programming paradigm.
Generally, Artificial Intelligence (AI) is a way of making a computer, robot, software or a
machine to work intelligently similar to a human. It is a discipline that covers various fields,
including Mathematics, Computer Sciences, Engineering, Philosophy etc. Overall, Lisp and
Prolog are two programming languages that help to write and develop AI-based applications.
Furthermore, Lisp is an older language than Prolog.
Introduction Prolog Operator
The prolog operator is a function to operate and works on the programming operand or
variable.
The prolog operator is a symbolic character to work arithmetic, logical, and comparison
operations.
It is a symbol to take action between two values and objects for a programming language.
The prolog operator is an expression to perform two or more than the two values in the
The prolog operator is a symbolic function to operate the “pl” files value in the console.
The prolog operator is a function for the prolog console and operates files variable,
The prolog operator is a function to work arithmetic, logic, comparison, and other
operations.
This operator is working for comparison between two operands and variables such as
equality.
Trigonometric operator:
• This operator works for operating operand and variable to find tangent and cotangent values.
1. SIN operator
2. COS operator
Output:
Output:
Example 1
Example 2
Example 2
Example 2
Example 3
Example 2
Example 3
Example 2
sin() operator
cos() operator