0% found this document useful (0 votes)
54 views24 pages

Unit 5

The document discusses the fundamentals of functional programming languages including lambda calculus, characteristics of functional programming, advantages, and comparison with object-oriented programming. It also covers principles of Scheme programming.

Uploaded by

Prakash Jeeva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views24 pages

Unit 5

The document discusses the fundamentals of functional programming languages including lambda calculus, characteristics of functional programming, advantages, and comparison with object-oriented programming. It also covers principles of Scheme programming.

Uploaded by

Prakash Jeeva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

lOMoARcPSD|35484261

UNIT V - if you like ,comment thanks

Principles of Programming Language (Anna University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)
lOMoARcPSD|35484261

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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

The Scheme language is standardized in the official IEEE standard[3] and a de facto standard called
the Revisedn Report on the Algorithmic Language Scheme (RnRS). The most widely implemented
standard is R5RS (1998).[4] The most recent standard, R7RS,[5] provides "small" and "large" versions of
the Scheme language; the "small" language standard was ratified in 2013.[6]Scheme has a diverse user
base due to its compactness and elegance, but its minimalist philosophy has also caused wide divergence
between practical implementations, so much that the Scheme Steering Committee calls it "the world's
most unportable programming language" and "a family of dialects" rather than a single language.

Scheme is primarily a functional programming language. It shares many characteristics with other
members of the Lisp programming language family. Scheme's very simple syntax is based on s-
expressions, parenthesized lists in which a prefix operator is followed by its arguments. Scheme programs
thus consist of sequences of nested lists. Lists are also the main data structure in Scheme, leading to a
close equivalence between source code and data formats (homoiconicity). Scheme programs can easily
create and evaluate pieces of Scheme code dynamically.

The reliance on lists as data structures is shared by all Lisp dialects. Scheme inherits a rich set of list-
processing primitives such as cons, car and cdr from its Lisp progenitors. Scheme uses strictly
but dynamically typed variables and supports first class procedures. Thus, procedures can be assigned as
values to variables or passed as arguments to procedures.

This section concentrates mainly on innovative features of the language, including those features that
distinguish Scheme from other Lisps. Unless stated otherwise, descriptions of features relate to the R5RS
standard. In examples provided in this section, the notation "===> result" is used to indicate the result of
evaluating the expression on the immediately preceding line. This is the same convention used in R5RS.
Minimalism[edit]
Main article: Minimalism (computing)

Scheme is a very simple language, much easier to implement than many other languages of
comparable expressive power.[18] This ease is attributable to the use of lambda calculus to derive much of
the syntax of the language from more primitive forms. For instance of the 23 s-expression-based syntactic
constructs defined in the R5RS Scheme standard, 14 are classed as derived or library forms, which can be
written as macros involving more fundamental forms, principally lambda. As R5RS (§3.1) says: "The
most fundamental of the variable binding constructs is the lambda expression, because all other variable
binding constructs can be explained in terms of lambda expressions."[4]

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

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.

In 1998, Sussman and Steele remarked that the minimalism of Scheme was not a conscious
design goal, but rather the unintended outcome of the design process. "We were actually trying to
build something complicated and discovered, serendipitously, that we had accidentally designed
something that met all our goals but was much simpler than we had intended....we realized that
the lambda calculus—a small, simple formalism—could serve as the core of a powerful and
expressive programming language."[8]
Lexical scope[edit]
See also: Scope (programming)

Like most modern programming languages and unlike earlier Lisps such as Maclisp, Scheme is
lexically scoped: all possible variable bindings in a program unit can be analyzed by reading the
text of the program unit without consideration of the contexts in which it may be called. This
contrasts with dynamic scoping which was characteristic of early Lisp dialects, because of the
processing costs associated with the primitive textual substitution methods used to implement
lexical scoping algorithms in compilers and interpreters of the day. In those Lisps, it was
perfectly possible for a reference to a free variable inside a procedure to refer to quite distinct
bindings external to the procedure, depending on the context of the call.

The impetus to incorporate lexical scoping, which was an unusual scoping model in the early
1970s, into their new version of Lisp, came from Sussman's studies of ALGOL. He suggested
that ALGOL-like lexical scoping mechanisms would help to realize their initial goal of
implementing Hewitt's Actor model in Lisp.[8]

The key insights on how to introduce lexical scoping into a Lisp dialect were popularized in
Sussman and Steele's 1975 Lambda Paper, "Scheme: An Interpreter for Extended Lambda
Calculus",[19] where they adopted the concept of the lexical closure (on page 21), which had been
described in an AI Memo in 1970 by Joel Moses, who attributed the idea to Peter J. Landin.[20]
Lambda calculus[edit]
See also: Lambda calculus

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

Alonzo Church's mathematical notation, the lambda calculus, has inspired Lisp's use of "lambda"
as a keyword for introducing a procedure, as well as influencing the development of functional
programming techniques involving the use of higher-order functions in Lisp. But early Lisps
were not suitable expressions of the lambda calculus because of their treatment of free
variables.[8]

A formal lambda system has axioms and a complete calculation rule. It is helpful for the analysis
using mathematical logic and tools. In this system, calculation can be seen as a directional
deduction. The syntax of lambda calculus follows the recursive expressions from x, y, z,
...,parentheses, spaces, the period and the symbol λ.[21] The function of lambda calculation
includes: First, serve as a starting point of powerful mathematical logic. Second, it can reduce the
requirement of programmers to consider the implementation details, because it can be used to
imitate machine evaluation. Finally, the lambda calculation created a substantial meta-theory.[22]

The introduction of lexical scope resolved the problem by making an equivalence between some
forms of lambda notation and their practical expression in a working programming language.
Sussman and Steele showed that the new language could be used to elegantly derive all the
imperative and declarative semantics of other programming languages including ALGOL
and Fortran, and the dynamic scope of other Lisps, by using lambda expressions not as simple
procedure instantiations but as "control structures and environment modifiers".[23] They
introduced continuation-passing style along with their first description of Scheme in the first of
the Lambda Papers, and in subsequent papers, they proceeded to demonstrate the raw power of
this practical use of lambda calculus.
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:

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

(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
another.

;; Calculation of Hofstadter's male and female sequences as a list of pairs

(define (hofstadter-male-female n)
(letrec ((female (lambda (n)
(if (= n 0)
1
(- n (male (female (- n 1)))))))
(male (lambda (n)
(if (= n 0)
0
(- n (female (male (- n 1))))))))
(let loop ((i 0))
(if (> i n)
'()
(cons (cons (female i)
(male i))
(loop (+ i 1)))))))

(hofstadter-male-female 8)

===> ((1 . 0) (1 . 0) (2 . 1) (2 . 2) (3 . 2) (3 . 3) (4 . 4) (5 . 4) (5 . 5))

(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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

'()
(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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

(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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

;; 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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

 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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

There are many programming languages around the globe, that raise the question of what programming

language is best for machine learning. Here is a list of the best programming language for Machine

learning.

Top 10 Programming Languages For Machine Learning

 Python

 R Programming

 JavaScript/Java

 Julia

 Lisp

 Scala

 C/C++

 TypeScript

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

 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

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

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.

Due to its characteristics like package services, graphical representation increased user interaction, Java

and JavaScript have a huge fan base in the machine learning circuit. They ensure speed, precision, and

accuracy while developing algorithms and interpreting them on dashboards and reports.

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 Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.

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.

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.

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.

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.
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++

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

 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

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.

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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
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.

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

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.

All these languages follow the procedural paradigm. That is, they describe, step by step, exactly the
procedure that should, according to the particular programmer at least, be followed to solve a specific
problem. The efficacy and efficiency of any such solution are both therefore entirely subjective and
highly dependent on that programmer's experience, inventiveness, and ability.
Object-oriented programming[edit]
Main article: Object-oriented programming

Following the widespread use of procedural languages, object-oriented programming (OOP) languages
were created, such as Simula, Smalltalk, C++, Eiffel, Python, PHP, Java, and C#. In these
languages, data and methods to manipulate it are kept as one unit called an object. With
perfect encapsulation, one of the distinguishing features of OOP, the only way that another object or user
would be able to access the data is via the object's methods. Thus, an object's inner workings may be
changed without affecting any code that uses the object. There is still some controversy raised
by Alexander Stepanov, Richard Stallman[11] and other programmers, concerning the efficacy of the OOP
paradigm versus the procedural paradigm. The need for every object to have associative methods leads

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)


lOMoARcPSD|35484261

some skeptics to associate OOP with software bloat; an attempt to resolve this dilemma came
through polymorphism.

Because object-oriented programming is considered a paradigm, not a language, it is possible to create


even an object-oriented assembler language. High Level Assembly (HLA) is an example of this that fully
supports advanced data types and object-oriented assembly language programming – despite its early
origins. Thus, differing programming paradigms can be seen rather like motivational memes of their
advocates, rather than necessarily representing progress from one level to the next[citation needed]. Precise
comparisons of competing paradigms' efficacy are frequently made more difficult because of new and
differing terminology applied to similar entities and processes together with numerous implementation
distinctions across languages.
Further paradigms[edit]

Literate programming, as a form of imperative programming, structures programs as a human-centered


web, as in a hypertext essay: documentation is integral to the program, and the program is structured
following the logic of prose exposition, rather than compiler convenience.

Independent of the imperative branch, declarative programming paradigms were developed. In these
languages, the computer is told what the problem is, not how to solve the problem – the program is
structured as a set of properties to find in the expected result, not as a procedure to follow. Given a
database or a set of rules, the computer tries to find a solution matching all the desired properties. An
archetype of a declarative language is the fourth generation language SQL, and the family of functional
languages and logic programming.

Functional programming is a subset of declarative programming. Programs written using this paradigm
use functions, blocks of code intended to behave like mathematical functions. Functional languages
discourage changes in the value of variables through assignment, making a great deal of use
of recursion instead.

The logic programming paradigm views computation as automated reasoning over a body of knowledge.
Facts about the problem domain are expressed as logic formulas, and programs are executed by
applying inference rules over them until an answer to the problem is found, or the set of formulas is
proved inconsistent.

Symbolic programming is a paradigm that describes programs able to manipulate formulas and program
components as data.[3] Programs can thus effectively modify themselves, and appear to "learn", making
them suited for applications such as artificial intelligence, expert systems, natural-language
processing and computer games. Languages that support this paradigm include Lisp and Prolog.[12]

Downloaded by Prakash Jeeva (prakashjeeva433@gmail.com)

You might also like