Documentos de Académico
Documentos de Profesional
Documentos de Cultura
LOGO
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
Programming style
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
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
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
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
• 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
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
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
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
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
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:
bedroom(bd, bw) :−
Logic Programming
SURVEY OF PROGRAMMING LANGUAGES
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 Programming
SURVEY OF PROGRAMMING LANGUAGES
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
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