0% found this document useful (0 votes)
23 views18 pages

PPL Unit5

The document discusses functional programming languages including lambda calculus, Scheme, and comparisons with object-oriented programming. Lambda calculus is a framework for studying computations with functions and includes syntax for function creation and application. Scheme is a minimalist dialect of Lisp that was created at MIT and influenced other languages. Functional programming focuses on mathematical functions and supports features like higher-order functions and lazy evaluation.

Uploaded by

Bhuvanesh
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)
23 views18 pages

PPL Unit5

The document discusses functional programming languages including lambda calculus, Scheme, and comparisons with object-oriented programming. Lambda calculus is a framework for studying computations with functions and includes syntax for function creation and application. Scheme is a minimalist dialect of Lisp that was created at MIT and influenced other languages. Functional programming focuses on mathematical functions and supports features like higher-order functions and lazy evaluation.

Uploaded by

Bhuvanesh
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/ 18

UNIT-V FUNCTIONAL AND LOGIC PROGRAMMING LANGUAGES

Introduction to lambda calculus:


Lambda calculus is a framework developed by Alonzo Church in 1930s to study computations with
functions.
 Function creation − Church introduced the notation λx.E to denote a function in which ‘x’ is a
formal argument and ‘E’ is the functional body. These functions can be of without names and
single arguments.
 Function application − Church used the notation E1.E2 to denote the application of function E1 to
actual argument E2. And all the functions are on single argument.

Syntax of Lambda Calculus

Lamdba calculus includes three different types of expressions, i.e.,


E :: = x(variables)
| E1 E2(function application)
| λx.E(function creation)
Where λx.E is called Lambda abstraction and E is known as λ-expressions.

Evaluating Lambda Calculus

Pure lambda calculus has no built-in functions. Let us evaluate the following expression −

(+ (* 5 6) (* 8 3))
Here, we can’t start with '+' because it only operates on numbers. There are two reducible expressions: (*
5 6) and (* 8 3).
We can reduce either one first. For example −

(+ (* 5 6) (* 8 3)) (+ 30 (* 8 3)) (+ 30 24) = 54

β-reduction Rule

We need a reduction rule to handle λs

(λx . * 2 x) 4 (* 2 4) = 8
This is called β-reduction.
The formal parameter may be used several times −

(λx . + x x) 4 (+ 4 4) = 8
When there are multiple terms, we can handle them as follows −

(λx . (λx . + (− x 1)) x 3) 9


The inner x belongs to the inner λ and the outer x belongs to the outer one.

(λx . + (− x 1)) 9 3 + (− 9 1) 3 + 8 3 = 11

Downloaded by Naveena M ([email protected])


Free and Bound Variables

In an expression, each appearance of a variable is either "free" (to λ) or "bound" (to a


λ). β-reduction of (λx . E) y replaces every x that occurs free in E with y. For Example

Alpha Reduction

Alpha reduction is very simple and it can be done without changing the meaning of a lambda expression.

λx . (λx . x) (+ 1 x) ↔ α λx . (λy . y) (+ 1 x)
For example −

(λx . (λx . + (− x 1)) x 3) 9 (λx . (λy . + (− y 1)) x 3) 9 (λy . + (− y 1)) 9 3 + (− 9 1) 3 + 8 3 11

Church-Rosser Theorem

The Church-Rosser Theorem states the following −


 If E1 ↔ E2, then there exists an E such that E1 → E and E2 → E. “Reduction in any way can
eventually produce the same result.”
 If E1 → E2, and E2 is normal form, then there is a normal-order reduction of E1 to E2. “Normal-
order reduction will always produce a normal form, if one exists.”

FUNDAMENTALS OF FUNCTIONAL PROGRAMMING LANGUAGES:

Functional programming languages are specially designed to handle symbolic computation and list
processing applications. Functional programming is based on mathematical functions. Some of the
popular functional programming languages include: Lisp, Python, Erlang, Haskell, Clojure, etc.
Functional programming languages are categorized into two groups, i.e. −
 Pure Functional Languages − These types of functional languages support only the functional
paradigms. For example − Haskell.
 Impure Functional Languages − These types of functional languages support the functional
paradigms and imperative style programming. For example − LISP.

Functional Programming – Characteristics

The most prominent characteristics of functional programming are as follows −


 Functional programming languages are designed on the concept of mathematical functions that
use conditional expressions and recursion to perform computation.
 Functional programming supports higher-order functions and lazy evaluationfeatures.
 Functional programming languages don’t support flow Controls like loop statements and
conditional statements like If-Else and Switch Statements. They directly use the functions and
functional calls.
 Like OOP, functional programming languages support popular concepts such as Abstraction,
Encapsulation, Inheritance, and Polymorphism.

Downloaded by Naveena M ([email protected])


Functional Programming – Advantages

Functional programming offers the following advantages −


 Bugs-Free Code − Functional programming does not support state, so there are no side-effect
results and we can write error-free codes.
 Efficient Parallel Programming − Functional programming languages have NO Mutable state,
so there are no state-change issues. One can program "Functions" to work parallel as
"instructions". Such codes support easy reusability and testability.
 Efficiency − Functional programs consist of independent units that can run concurrently. As a
result, such programs are more efficient.
 Supports Nested Functions − Functional programming supports Nested Functions.
 Lazy Evaluation − Functional programming supports Lazy Functional Constructs like Lazy Lists,
Lazy Maps, etc.
As a downside, functional programming requires a large memory space. As it does not have state, you
need to create new objects every time to perform actions.
Functional Programming is used in situations where we have to perform lots of different operations on the
same set of data.
 Lisp is used for artificial intelligence applications like Machine learning, language processing,
Modeling of speech and vision, etc.
 Embedded Lisp interpreters add programmability to some systems like Emacs.

Functional Programming vs. Object-oriented Programming

The following table highlights the major differences between functional programming and object-oriented
programming −

Functional Programming OOP

Uses Immutable data. Uses Mutable data.

Follows Declarative Programming Model. Follows Imperative


Programming Model.

Focus is on: “What you are doing” Focus is on “How you are
doing”

Supports Parallel Programming Not suitable for Parallel


Programming

Its methods can produce


Its functions have no-side effects
serious side effects.

Flow Control is done using function calls & function calls with recursion Flow control is done using
loops and conditional
statements.

It uses "Recursion" concept to iterate Collection Data. It uses "Loop" concept to


iterate Collection Data. For

Downloaded by Naveena M ([email protected])


example: For-each loop in
Java

Execution order of statements is not so important. Execution order of statements


is very important.

Supports both "Abstraction over Data" and "Abstraction over Behavior". Supports only "Abstraction
over Data".

Efficiency of a Program Code

The efficiency of a programming code is directly proportional to the algorithmic efficiency and the
execution speed. Good efficiency ensures higher performance.
The factors that affect the efficiency of a program includes −

 The speed of the machine


 Compiler speed
 Operating system
 Choosing right Programming language
 The way of data in a program is organized
 Algorithm used to solve the problem
The efficiency of a programming language can be improved by performing the following tasks −
 By removing unnecessary code or the code that goes to redundant processing.
 By making use of optimal memory and nonvolatile storage
 By making the use of reusable components wherever applicable.
 By making the use of error & exception handling at all layers of program.
 By creating programming code that ensures data integrity and consistency.
 By developing the program code that's compliant with the design logic and flow.
An efficient programming code can reduce resource consumption and completion time as much as
possible with minimum risk to the operating environment.
PROGRAMMING WITH SCHEME:

Scheme is a minimalist dialect of the Lisp family of programming languages. Scheme consists of a small
standard core with several tools for language extension.[1]

Scheme was created during the 1970s at the MIT AI Lab and released by its developers, Guy L.
Steele and Gerald Jay Sussman, via a series of memos now known as the Lambda Papers. It was the first
dialect of Lisp to choose lexical scope and the first to require implementations to perform tail-call
optimization, giving stronger support for functional programming and associated techniques such as
recursive algorithms. It was also one of the first programming languages to support first-
class continuations. It had a significant influence on the effort that led to the development of Common
Lisp.[2]

Downloaded by Naveena M ([email protected])


Fundamental forms: define, lambda, quote, if, define-syntax, let-syntax, letrec-syntax, syntax-
rules, set!
Derived forms: do, let, let*, letrec, cond, case, and, or, begin, named let, delay, unquote,
unquote-splicing, quasiquote

Example: a macro to implement let as an expression using lambda to perform the variable
bindings.

(define-syntax let
(syntax-rules ()
((let ((var expr) ...) body ...)
((lambda (var ...) body ...) expr ...))))

Thus using let as defined above a Scheme implementation would rewrite "(let ((a 1)(b 2)) (+ b
a))" as "((lambda (a b) (+ b a)) 1 2)", which reduces implementation's task to that of coding
procedure instantiations.

Block structure[edit]

Scheme inherits its block structure from earlier block structured languages, particularly ALGOL.
In Scheme, blocks are implemented by three binding constructs: let, let*and letrec. For instance,
the following construct creates a block in which a symbol called var is bound to the number 10:

(define var "goose")


;; Any reference to var here will be bound to "goose"
(let ((var 10))
;; statements go here. Any reference to var here will be bound to 10.
)
;; Any reference to var here will be bound to "goose"

Blocks can be nested to create arbitrarily complex block structures according to the need of the
programmer. The use of block structuring to create local bindings alleviates the risk
of namespace collision that can otherwise occur.

One variant of let, let*, permits bindings to refer to variables defined earlier in the same
construct, thus:

(let* ((var1 10)


(var2 (+ var1 12)))
;; But the definition of var1 could not refer to var2
)

The other variant, letrec, is designed to enable mutually recursive procedures to be bound to one
Downloaded by Naveena M ([email protected])
another.

(See Hofstadter's male and female sequences for the definitions used in this example.)

All procedures bound in a single letrec may refer to one another by name, as well as to values of
variables defined earlier in the same letrec, but they may not refer tovalues defined later in the
same letrec.

A variant of let, the "named let" form, has an identifier after the let keyword. This binds the let
variables to the argument of a procedure whose name is the given identifier and whose body is
the body of the let form. The body may be repeated as desired by calling the procedure. The
named let is widely used to implement iteration.

Example: a simple counter

(let loop ((n 1))


(if (> n 10)

Downloaded by Naveena M ([email protected])


'()
(cons n
(loop (+ n 1)))))

===> (1 2 3 4 5 6 7 8 9 10)

Like any procedure in Scheme, the procedure created in the named let is a first-class object.
Proper tail recursion[edit]
Further information: Tail recursion

Scheme has an iteration construct, do, but it is more idiomatic in Scheme to use tail recursion to
express iteration. Standard-conforming Scheme implementations are required to optimize tail
calls so as to support an unbounded number of active tail calls (R5RS sec. 3.5)[4]—a property the
Scheme report describes as proper tail recursion—making it safe for Scheme programmers to
write iterative algorithms using recursive structures, which are sometimes more intuitive. Tail
recursive procedures and the named let form provide support for iteration using tail recursion.

;; Building a list of squares from 0 to 9:


;; Note: loop is simply an arbitrary symbol used as a label. Any symbol will do.

(define (list-of-squares n)
(let loop ((i n) (res '()))
(if (< i 0)
res
(loop (- i 1) (cons (* i i) res)))))

(list-of-squares 9)
===> (0 1 4 9 16 25 36 49 64 81)

First-class continuations[edit]
Main article: Continuation

Continuations in Scheme are first-class objects. Scheme provides the procedure call-with-
current-continuation (also known as call/cc) to capture the current continuation by packing it up
as an escape procedure bound to a formal argument in a procedure provided by the programmer.
(R5RS sec. 6.4)[4] First-class continuations enable the programmer to create non-local control
constructs such as iterators, coroutines, and backtracking.

Continuations can be used to emulate the behavior of return statements in imperative


programming languages. The following function find-first, given function func and list lst,
returns the first element x in lst such that (func x) returns true.

(define (find-first func lst)

Downloaded by Naveena M ([email protected])


(call-with-current-continuation
(lambda (return-immediately)
(for-each (lambda (x)
(if (func x)
(return-immediately x)))
lst)
#f)))

(find-first integer? '(1/2 3/4 5.6 7 8/9 10 11))


===> 7
(find-first zero? '(1 2 3 4))
===> #f

The following example, a traditional programmer's puzzle, shows that Scheme can handle
continuations as first-class objects, binding them to variables and passing them as arguments to
procedures.

(let* ((yin
((lambda (cc) (display "@") cc) (call-with-current-continuation (lambda (c) c))))
(yang
((lambda (cc) (display "*") cc) (call-with-current-continuation (lambda (c) c)))))
(yin yang))

When executed this code displays a counting


sequence: @*@**@***@****@*****@******@*******@********...
Shared namespace for procedures and variables[edit]

In contrast to Common Lisp, all data and procedures in Scheme share a common namespace,
whereas in Common Lisp functions and data have separate namespaces making it possible for a
function and a variable to have the same name, and requiring special notation for referring to a
function as a value. This is sometimes known as the "Lisp-1 vs. Lisp-2" distinction, referring to
the unified namespace of Scheme and the separate namespaces of Common Lisp. [24]

In Scheme, the same primitives that are used to manipulate and bind data can be used to bind
procedures. There is no equivalent of Common Lisp's defun and #' primitives.

;; Variable bound to a number:


(define f 10)
f
===> 10
;; Mutation (altering the bound value)
(set! f (+ f f 6))
f
===> 26

Downloaded by Naveena M ([email protected])


;; Assigning a procedure to the same variable:
(set! f (lambda (n) (+ n 12)))
(f 6)
===> 18
;; Assigning the result of an expression to the same variable:
(set! f (f 1))
f
===> 13
;; functional programming:
(apply + '(1 2 3 4 5 6))
===> 21
(set! f (lambda (n) (+ n 100)))
(map f '(1 2 3))
===> (101 102 103)

PROGRAMMING WITH MACHINE LEARNING:

Machine learning is a modern-day discipline that utilizes statistics, algorithms, probability to extract the

best out of data and offer insightful information that can be leveraged to create intelligent applications.

Being a strong part of AI, it has a pool of algorithms and methods that connect the data depending upon

the patterns and analytical methods.

Machine learning has a stringent focus on pattern recognition, predictive analytics, data mining and has a

close association with big data and data analytics. It has the power to enable machines to mimic human

decision-making through mathematical models and advanced prediction statistics.

Machine learning basically consists of three types – Supervised (based on labeled

data), Unsupervised(based on unlabelled data, hidden patterns), and Reinforcement learning (based on

learning from mistakes, trials, errors).

Good Read: What Is Machine Learning? An Overview In 200 Words

Machine Learning Uses:

 Self-driving autonomous cars

 Speech translation

 Face recognition

Downloaded by Naveena M ([email protected])


 Sentiment analysis

 Social media analysis

 Financial trading

 Fraud detection

 Product recommendation

 Medical diagnosis and predictions

Companies Using Machine Learning:

 Google

 Facebook

 Pinterest

 Yelp

 Twitter

 HubSpot

 Pindrop

 Apple

 Salesforce

 Intel

 Microsoft

 IBM

 Baidu

It is debatable as to how much knowledge of programming languages is needed to implement machine

learning models with effectiveness. It totally depends on the type of usage and what type of real-world

problems are being solved. To explore the best of machine learning, it is vital to have basic knowledge of

programming languages and their salient features like algorithms, data structures, logic, memory

management, etc. Of course, machine learning has its own set of libraries to act upon that makes it easy

for programmers to implement machine learning logic along with certain standard programming

languages.

Downloaded by Naveena M ([email protected])


Top 10 Programming Languages For Machine Learning

 Python

 R Programming

 JavaScript/Java

 Julia

 Lisp

 Scala

 C/C++

 TypeScript

 GO

 Shell

Python:

Python is a lightweight, versatile, simple programming language that can power complex scripting and

web app if used in an effective framework. It was created in 1991 as a general-purpose programming

language. Developers have always admired it as a simple, easy to learn and its popularity knows no

bounds. It supports multiple frameworks and libraries making it versatile.

Python developers are in trend since it is one of the most sought-after languages in the machine learning,

data analytics, and web development arena, and developers find it fast to code and easy to learn. Python

is liked by all since it allows a great deal of flexibility while coding. Thanks to its scalability and open-

source nature, it has multiple visualization packages and important core libraries like sklearn, seaborn,

etc. These powerful libraries make coding an easy task and empower machines to learn more.

Python supports object-oriented, functional, imperative, and procedural development paradigms. Two

highly popular machine learning libraries with Python developers are TensorFlow and Scikit. It is

considered ideal for prototyping, scientific computing, sentiment analysis, natural language processing,

and data science.

R Programming:

R is a popular open-source data visualization-driven language that focuses on statistical computing and
Downloaded by Naveena M ([email protected])
reigns high in the machine learning environment. It is being managed by the R Foundation and R

development core team. The USP of R is that it is preferred by professionals who are not very well

exposed to coding – analysts, statisticians, or data miners. It offers support to a command line and other

IDEs, with ease of coding and multiple tools for better library management and drawing better graphs.

R does have a good resource pool, thanks to its salient features that aid in developing machine learning

apps. Its usage for data and statistics has been profound. Effective machine learning solutions can be

delivered with its heavy computing capabilities. Being a graphics-based language, it is leveraged by data

scientists for analyzing data through graphs, by huge conglomerates, especially in the biomedical field.

R is known for implementing machine learning methodologies like classification, regression, decision

tree formation, etc. Because of its statistical and functional features, it has been a dynamic, imperative,

functional language. It supports different operating systems like Windows, Linux, OS X.

JavaScript/Java:

JavaScript and Java have been multipurpose programming languages that have proven their worth for

machine learning applications and algorithms. Known for their stability and reliability, these languages

have been object-oriented in nature and support heavy data processing competencies. Java has strong

frameworks like Weka, Rapid Miner, etc. that support machine learning algorithms, decision trees,

regression techniques, etc. It has been working very well with enterprise-based applications. JavaScript

has been an easy language to learn and hence has a good resource pool to look for.

Many high-profile projects of big organizations are based on Java and JavaScript. Considered to be

effective for machine learning projects, these technologies take support from the multiple machine

learning libraries associated with them. Experts are using them for detecting frauds, cyber-attacks, and for

better network security.

Julia:

Julia is a popular high-level, dynamic programming language that is especially meant for creating

effective model analytics needed for developing machine learning applications. As a good performance

language, it has an easy syntax and hence is a preferred option for developers. It offers different

takeaways like numerical precision, sleek compiler, distributed parallel execution, and a large

mathematical function library.


Downloaded by Naveena M ([email protected])
It executes seamlessly on various platforms and is considered interactive when it comes to scripting.

Being functional and object-oriented, it has a large fan following and is considered an ideal choice for

developing machine learning apps. It is accessible and easily understandable. Under the license of MIT, it

is free and open source by nature.

Julia can perform its best on the server-side and client-side, both. It is quite effective while doing

computational statistics and numerical calculations. Hence, it is considered ideal for statisticians in the

areas of bioinformatics and analytics.

Lisp:

Lisp has been an old programming language that has been popular now for AI and ML-related projects. It

is known for its architecture and practices and that is a good reason, developers are for it, especially for

artificial intelligence and machine learning applications. There are limitless possibilities that it offers to

its developers.

Salient characteristics like domain-specific language embedded with code, building owners, etc. have

made it popular. Utilizing its features while creating machine learning applications has been the

developer’s delights since there are many chances of doing so.

Lisp has been developed by the pioneer of AI – John McCarthy and hence has its own advantages. It has

been proven good for prototyping and facilitates the easy and dynamic creation of novel objects. There

is an automated garbage collection feature that assists in running operations smoothly.

Scala:

Scala is a well-known compiled language that makes the executable code work in a fast manner. It

possesses a static type of system that has good compatibility with Java frameworks and libraries. Scala is

known to deal with enterprise-level apps with huge databases and a scalable solution. Its USP lies in

creating big data-powered applications that carry an enormous amount of data within them.

It has a strong backend language and hence can manage a massive flow of data. Supported by the well-

known Apache Spark, Scala offers competitive functionalities through its MLLIB library. It offers

developers an effective method of developing, designing, and deploying machine learning algorithms by

leveraging Spark competencies along with other big data tools and technologies.

Downloaded by Naveena M ([email protected])


Scala has a lot of good libraries like Aerosol, Saddle, etc. that can help in developing applications

related to scientific computing, linear algebra, and random number generation. These libraries offer great

capabilities for data manipulation through different features like 2D data structures, automated data

alignment, etc.

C/C++:

C/C++ are powerful, versatile, and popular programming languages that have been preferred choices for

many, across the globe. And when it comes to developing machine learning algorithms, there is no

looking back. These have been traditional languages that have ruled the developer fraternity for years and

with regular updates, have been abreast of the latest technology moves.

These languages are considered low-level languages and hence are easily readable by the machine. It is

easy to offer hardware-level features and hence machine learning apps can easily be implemented on IoT

devices. The fast execution and delivery speed make it ideal for such applications.

There are many strong libraries like Torch, TensorFlow, etc. that are implemented using C/C++. They

have proven to be useful for performance-critical applications. C++ has the competence to manipulate

algorithms and undergo thorough memory management at a detailed level. It offers a great deal of control

over different performance parameters.

TypeScript:

TypeScript is an object-oriented programming language developed by Microsoft in 2012. It is JavaScript

for application scale development. It is considered a good choice for developing machine learning

applications through a browser-based library called Kalimdor, which is written in TypeScript. TypeScript

begins with JavaScript and ends with the same, supporting JavaScript libraries.

It is a compiled language that is strongly typed. It is considered as a language and a set of tools that

basically is JavaScript with some added features and tools. TypeScript has the following components at

its core – language, TypeScript Compiler, and TypeScript Language Service.

The major advantage of using TypeScript is that it is a simplified version of JavaScript and hence, reading

and debugging it is easier. It offers effective development tools for JavaScript IDEs and different

programming practices. The code becomes much simpler to perceive and read.

Downloaded by Naveena M ([email protected])


GO (Golang):

Go (Golang) has been a popular language with its salient features like open-source nature, owned by

Google, and light in execution. It has the capability to encompass big data sets in a simpler fashion with

multiple tasks being executed together. Its concurrency is its positive point. It is a system-level

programming language and has an in-built vocabulary.

It is considered as one of the fastest-growing languages on GitHub, with a good acceptance level amidst

the cloud computing services. Because of its resemblance to C and features like garbage collection,

dynamic typing, etc., it is popular in the serverless computing infrastructure.

Go is considered relatively simpler to learn and its easy syntax and security make it easy acceptable by

developers.

Shell:

Shell programming language has been conceived to be executed by the Unix shell, a command-line

interpreter. With its scripting languages and wrappers, Shell uses its simple syntax and makes it an ideal

choice to develop machine learning models, algorithms, and applications.

Shell, as a user interface to perform operations, uses a defined language and can be quite helpful in data

collection and preparation, through mathematical models. Shell is available for all operating systems,

including Windows, Linux, and macOS, offering them high-end portability

Shell commands and scripts are used to collect data and prepare it for further computing. It offers an easy

and friendly way to process data.

INTRODUCTION TO LOGIC AND LOGIC PROGRAMMING:

Logic programming is a computer programming paradigm.


Logic programming is a way of writing computer programs using languages that are based on formal
logic.

Logic programs are declarative rather than procedural, which means that only the specifications of the
desired results are stated rather than detailed procedures for producing them.
Programs in logic programming languages are collections of facts and rules.
Languages used for logic programming are called declarative languages, because programs written in
them consist of declarations rather than assignments and control flow statements.
Downloaded by Naveena M ([email protected])
Language used for logic programming: Prolog.

programming with prolog:

Prolog as the name itself suggests, is the short form of LOGical PROgramming. It is a logical and
declarative programming language. Before diving deep into the concepts of Prolog, let us first understand
what exactly logical programming is.
Logic Programming is one of the Computer Programming Paradigm, in which the program statements
express the facts and rules about different problems within a system of formal logic. Here, the rules are
written in the form of logical clauses, where head and body are present. For example, H is head and B1,
B2, B3 are the elements of the body. Now if we state that “H is true, when B1, B2, B3 all are true”, this is
a rule. On the other hand, facts are like the rules, but without any body. So, an example of fact is “H is
true”.
Some logic programming languages like Datalog or ASP (Answer Set Programming) are known as purely
declarative languages. These languages allow statements about what the program should accomplish.
There is no such step-by-step instruction on how to perform the task. However, other languages like
Prolog, have declarative and also imperative properties. This may also include procedural statements like
“To solve the problem H, perform B1, B2 and B3”.
Some logic programming languages are given below −
 ALF (algebraic logic functional programming language).
 ASP (Answer Set Programming)
 CycL
 Datalog
 FuzzyCLIPS
 Janus
 Parlog
 Prolog
 Prolog++

 ROOP

Logic and 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.
Now let us see some more differences below −

Functional Programming Logic Programming

Downloaded by Naveena M ([email protected])


Functional Programming follows the Von-Neumann Logic Programming uses abstract model, or deals
Architecture, or uses the sequential steps. with objects and their relationships.

The syntax is actually the sequence of statements like The syntax is basically the logic formulae (Horn
(a, s, I). Clauses).

The computation takes part by executing the It computes by deducting the clauses.
statements sequentially.

Logic and controls are mixed together. Logics and controls can be separated.

What is Prolog?

Prolog or PROgramming in LOGics is a logical and declarative programming language. It is one major
example of the fourth generation language that supports the declarative programming paradigm. This is
particularly suitable for programs that involve symbolicor non-numeric computation. This is the main
reason to use Prolog as the programming language in Artificial Intelligence, where symbol
manipulation and inference manipulation are the fundamental tasks.
In Prolog, we need not mention the way how one problem can be solved, we just need to mention what
the problem is, so that Prolog automatically solves it. However, in Prolog we are supposed to give clues
as the solution method.
Prolog language basically has three different elements −
Facts − The fact is predicate that is true, for example, if we say, “Tom is the son of Jack”, then this is a
fact.

Rules − Rules are extinctions of facts that contain conditional clauses. To satisfy a rule these conditions
should be met. For example, if we define a rule as −

grandfather(X, Y) :- father(X, Z), parent(Z, Y)


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.
Questions − And to run a prolog program, we need some questions, and those questions can be answered
by the given facts and rules.

History of Prolog

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.

Some Applications of Prolog


Prolog is used in various domains. It plays a vital role in automation system. Following are some other
Downloaded by Naveena M ([email protected])
important fields where Prolog is used −
 Intelligent Database Retrieval
 Natural Language Understanding
 Specification Language
 Machine Learning
 Robot Planning
 Automation System
 Problem Solving
Multi –paradigm languages:

Programming paradigms are a way to classify programming languages based on their features.
Languages can be classified into multiple paradigms.

Machine code[edit]

The lowest-level programming paradigms are machine code, which directly represents
the instructions (the contents of program memory) as a sequence of numbers, andassembly
language where the machine instructions are represented by mnemonics and memory addresses can be
given symbolic labels. These are sometimes called first- andsecond-generation languages.

In the 1960s, assembly languages were developed to support library COPY and quite sophisticated
conditional macro generation and preprocessing abilities, CALL to (subroutines), external variables and
common sections (globals), enabling significant code re-use and isolation from hardware specifics via the
use of logical operators such as READ/WRITE/GET/PUT. Assembly was, and still is, used for time-
critical systems and often in embedded systems as it gives the most direct control of what the machine
does.
Procedural languages[edit]

The next advance was the development of procedural languages. These third-generation languages (the
first described as high-level languages) use vocabulary related to the problem being solved. For example,

 COmmon Business Oriented Language (COBOL) – uses terms like file, move and copy.
 FORmula TRANslation (FORTRAN) – using mathematical language terminology, it was developed
mainly for scientific and engineering problems.
 ALGOrithmic Language (ALGOL) – focused on being an appropriate language to define algorithms,
while using mathematical language terminology, targeting scientific and engineering problems, just
like FORTRAN.
 Programming Language One (PL/I) – a hybrid commercial-scientific general purpose language
supporting pointers.
 Beginners All purpose Symbolic Instruction Code (BASIC) – it was developed to enable more people
to write programs.
 C – a general-purpose programming language, initially developed by Dennis Ritchie between 1969
and 1973 at AT&T Bell Labs.

Downloaded by Naveena M ([email protected])

You might also like