Está en la página 1de 20

SURVEY OF PROGRAMMING LANGUAGES

LOGO

A Look at Programming Languages

Presented by: Taj Williams


SURVEY OF PROGRAMMING LANGUAGES

What are Programming


Paradigms
According to the 'The American Heritage Dictionary of the English Language, Third
Edition': a paradigm is a "An example that serves as pattern or model.“

Other definitions based


 Programming paradigm (in this course)
• A pattern that serves as a school of thoughts for programming of computers

 Programming technique
• Related to an algorithmic idea for solving a particular class of problems
• Examples: 'Divide and conquer' and 'program development by stepwise
refinement'

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

What are Programming Paradigms

 Programming style

• The way we express ourselves in a computer program


• Related to elegance or lack of elegance
 Programming culture

• The totality of programming behavior, which often is tightly related to a family of


programming languages
• The sum of a main paradigm, programming styles, and certain programming
techniques.

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Types of Programming Paradigms

• There are four main types of programming paradigms:

 The imperative paradigm

 The functional paradigm

 The object-oriented paradigm

 THE LOGICAL PARADIGM

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Logical Paradigm

This program specifies a computation by giving the properties of a correct answer. Prolog
and LDL are examples of logic paradigm; since they emphasize the logical properties of a
computation, they are often called logic/declarative programming languages

Characteristics:
 Discipline and idea

 Automatic proofs within artificial intelligence

 Based on axioms, inference rules, and queries.

 Program execution becomes a systematic search in a set of facts,


making use of a set of inference rules

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

How Logic Programming Works

 The basic property of this language is that a program is a theory in some suitable
logic. This property immediately gives a precise meaning to programs written in the
language. From a programmers point of the view basic property is that programming
is lifted to a higher level of abstraction. At this higher level of abstraction the
programmer can concentrate on stating what is to be computed, not
necessarily how it is to be computed.
 algorithm = logic + control, the programmer gives the logic but not necessarily the
control.

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

How Logic Programming Works

• From a programming point of view Prolog provides two features not present in
functional languages, built-in search and the ability to compute with partial
information. This is in contrast to functional languages where computations always
are directed, require all arguments to be known and give exactly one answer

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Difference between Imperative and logic


programming

The contrast between imperative and declarative programming can be illustrated by


looking at two solutions to a small programming problem, one using the conventional
approach of Pascal, and the other using the approach of logic programming. The problem
is to provide a program that will help an architect in designing motel suites. The client has
already decided that each suite will have two rooms, a lounge and a bedroom, and its
floor plan will be something like

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Difference between Imperative and logic


programming

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Objectives of the Program

The program must determine the directions in which the doors and windows may face,
following these guidelines:

1. The lounge window should be opposite the front door to create a feeling of space.

2. The bedroom door should be in one of the walls at right angles to the front door to
provide a little privacy.

3. The bedroom window should be in one of the walls adjacent to the bedroom door.

4. The bedroom window should face East to catch the morning light.

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Guidelines

 In Pascal, directions might be represented by elements of an enumerated type, like


this:

Type direction = (north, south, east, west);


• Guidelines (1) and (2) constrain the design of the lounge. They can be expressed in
Pascal by writing a Boolean-valued function lounge that takes as arguments
proposed directions for the two doors and the lounge window, and checks whether
the guidelines are satisfied. Names like fd and bw stand for ‘front door’ and ‘bedroom
window’, and the two Boolean functions opposite and adjacent have the obvious
meanings.

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Guidelines

 Guidelines (3) and (4) concern the design of the bedroom, and they are expressed by
the function bedroom that checks the directions for the bedroom door and window.
The functions lounge and bedroom are combined in the suite function that checks a
set of choices for the whole motel suite.
 Defining these functions seems to capture the essence of the problem, but the Pascal
program is not complete until we have shown how they are to be used ina search for
valid designs. For a simple problem like this one, and exhaustive

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Pascal Break Down-


Pascal functions for checking motel suite designs

 function lounge(fd, lw, bd: direction): boolean;


begin
lounge := opposite(fd, lw) ∧ adjacent(fd, bd)
end;
 function bedroom(bd, bw: direction): boolean;
begin
bedroom := adjacent(bd, bw) ∧ (bw = east)
end;
 function suite(fd, lw, bd, bw: direction): boolean;
begin
suite := lounge(fd, lw, bd) ∧ bedroom(bd, bw)
end;

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Pascal Break Down- Exhaustive search

for fd := north to west do

for lw := north to west do

for bd := north to west do

for bw := north to west do

if suite(fd, lw, bd, bw) then

print(fd, lw, bd, bw)

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Logic Break Down

Instead of the Boolean functions of the Pascal program, logic uses a notation more suited
to symbolic calculation. In this notation, the definition of lounge looks like this:

lounge(fd, bd, lw) :−

opposite(fd, lw), adjacent(fd, bd).

bedroom(bd, bw) :−

adjacent(bd, bw), bw = east .

suite(fd, lw, bd, bw) :−

lounge(fd, lw, bd), bedroom(bd, bw).

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Logic Break Down

In this definition, the symbol ‘:−’ is to be read as ‘if’; think of it as looking a little

like the leftward-pointing arrow ‘⇐’ that is sometimes used in ordinary logic. The

comma that separates the formulas opposite(fd, lw) and adjacent(fd, bd) is to

be read as ‘and’. Names like lounge stand for relations that hold between objects, and
names like fd are variables that stand for any object

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

Logic Break Down

suite(FD, LW, BD, BW) :-lounge(FD, LW, BD),bedroom(BD, BW).


lounge(FD, LW, BD) :- opposite(FD, LW),adjacent(FD, BD).
bedroom(BD, BW) :- adjacent(BD, BW), BW = east.

opposite(north, south) :- . adjacent(south, west) :- .


opposite(south, north) :- . adjacent(east, north) :- .
adjacent(east, south) :- .
opposite(east, west) :- .
adjacent(west, north) :- .
opposite(west, east) :- . adjacent(west, south) :- .
adjacent(north, east) :- .
adjacent(north, west) :- .
adjacent(south, east) :- .

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

The Merits of Declarative Languages


The use of declarative languages offers three important advantages.

 Logic programming languages are inherently ``high-level'' because they focus on the
computation's logic and not on its mechanics (which in fact are inaccessible to the
programmer). The result is that they are well-suited to expressing complex ideas
because the labour of memory management, stack pointers, etc., is left to the
computational engine. Since the engine incorporates logical inferencing, it is already
a powerful tool which can be exploited in developing inference engines specific to a
particular domain

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

The Merits of Declarative Languages

 Logic offers the opportunity to represent data both as an explicit fact (``Atom A is
connected to Atom B with a single bond'') and as a rule which implicitly describes the
fact (``Groups X and Y are connected in a cyclic structure''; processing the rule
produces the A-B bond).
 A consequence of the preceding is that logic programming languages are particularly
suited for rapidly prototyping data structures and code to express complex ideas.
Reduced labour and compact expression means the developer --- and even the
scientist! --- can concentrate on what should be represented and how. The use of the
built-in inference engine permits rapid and straightforward evaluation of the code. We
find repeatedly that difficulties in coding are due to vagueness and illogic in our thinking.

Logic Programming
SURVEY OF PROGRAMMING LANGUAGES

The End

Logic Programming

También podría gustarte