PPL Unit5
PPL Unit5
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 −
β-reduction Rule
(λ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 1)) 9 3 + (− 9 1) 3 + 8 3 = 11
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 −
Church-Rosser Theorem
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.
The following table highlights the major differences between functional programming and object-oriented
programming −
Focus is on: “What you are doing” Focus is on “How you are
doing”
Flow Control is done using function calls & function calls with recursion Flow control is done using
loops and conditional
statements.
Supports both "Abstraction over Data" and "Abstraction over Behavior". Supports only "Abstraction
over Data".
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 −
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]
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:
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:
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.
===> (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.
(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.
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))
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.
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
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
data), Unsupervised(based on unlabelled data, hidden patterns), and Reinforcement learning (based on
Speech translation
Face recognition
Financial trading
Fraud detection
Product recommendation
Yelp
HubSpot
Pindrop
Apple
Salesforce
Intel
Microsoft
IBM
Baidu
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.
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
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,
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,
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
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
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
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
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
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
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.
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
TypeScript:
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
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.
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
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,
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
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,
Shell commands and scripts are used to collect data and prepare it for further computing. It offers an easy
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.
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
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 −
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 −
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.
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.