Logical Programming Paradigm
Logical Programming Paradigm
Introduction:
The Logical Paradigm takes a declarative approach to problem-solving.
Various logical assertions about a situation are made, establishing all
known facts. Then queries are made. The role of the computer becomes
maintaining data and logical deduction.
Logical Paradigm Programming:
A logical program is divided into three sections:
1. a series of definitions/declarations that define the problem domain
2. statements of relevant facts
3. statement of goals in the form of a query
Advantages:
The advantages of logic-oriented programming are bifold:
1. The system solves the problem, so the programming steps
themselves are kept to a minimum;
2. Proving the validity of a given program is simple.
There are multiple different logic programming languages. The most common
language, Prolog (from the French programmation en logique, or programming in
logic), can also interface with other programming languages such as Java and C. On
top of being the most popular logic programming language, Prolog was also one of the
first such languages, with the first prolog program created in the 1970s for use with
interpretations. Prolog was developed using first-order logic, also called predicate
logic, which allows for the use of variables rather than propositions. Prolog utilizes
artificial intelligence (AI) to help form its conclusions and can quickly process large
amounts of data. Prolog can be run with or without manual inputs, meaning in it can
be programmed to run automatically as part of data processing.
Paradigm is a school of thought or model that has distinct features, frameworks, patterns, and
style which help you solve a particular problem. Paradigms are used in all fields such as
psychology, sociology, etymology, computer science and so on. In the field of computer
science, new programming languages emerge from existing languages and add, remove and
combine features in a new way. The languages may follow a particular paradigm or can be a
combination of many paradigms. Did you know that there are 256 programming languages? It is
evident that each of them has evolved from the other with an amalgamation of various
programming paradigms.
2. Logical Programming
Logical programming is a computer programming paradigm that has its foundations in
mathematical logic in which program statements express facts and rules about
problems within a system. Rules are written as logical clauses with a head and a body.
They also follow a declarative rather than an imperative approach. However, what does
that mean?
To understand how a problem can be solved in logical programming, you need to know
about the building blocks − Facts and Rules −
Let us understand the difference between Imperative and declarative programming.
Imagine you walk into your favorite coffee place and you would like to order some
coffee.
The imperative approach will be:
So rather than providing a step by step instruction (imperative), you tell the system what
you need and let it try to come up with a solution (declarative).
Prolog follows the Logical paradigm and is probably the most famous language in the
logical programming family.
Prolog has been enormously influential in the domains of theorem proving, expert
systems, natural language processing and in the field of artificial intelligence
(notably IBM’s Watson2) in general
Prolog, like SQL, has two main aspects, one to express the data and another to query it.
The basic constructs of logical programming, terms, and statements, are inherited from
logic. There are three basic statements:
Facts are fundamental assertions about the problem domain (e.g. "Socrates is a man")
Rules are inferences about facts in the domain (e.g. "All men are mortal.")
Queries are questions about that domain (e.g. "Is Socrates mortal?")
Logical programming can be used to express knowledge in a way that does not depend
on the
implementation, making programs more flexible, compressed and understandable.
It enables knowledge to be separated from use, i.e. the machine architecture can be
changed
without changing programs or their underlying code.
It can be altered and extended in natural ways to support special forms of knowledge,
such
as meta-level of higher-order knowledge.
It can be used in non-computational disciplines relying on reasoning and precise means
of
expression.
2 Brief Overview of the Logic Programming Paradigm The logic programming paradigm substantially
differs from other programming paradigms. When stripped to the bare essentials it can be summarized
by the following three features: • computing takes place over the domain of all terms defined over a
“universal” alphabet. • values are assigned to variables by means of automatically generated
substitutions, called most general unifiers. These values may contain variables, called logical variables, •
the control is provided by a single mechanism: automatic backtracking. In our exposition of this
programming paradigm we shall stress the above three points. Even such a brief summary shows both
the strength and weakness of the logic programming paradigm. Its strength lies in an enormous
simplicity and conciseness; its weakness has to do with the restrictions to one control mechanism and
the use of a single data type. So this framework has to be modified and enriched to accommodate it to
the customary needs of programming, for example by providing various control constructs and by
introducing the data type of integers with the customary arithmetic operations. This can be done and in
fact Prolog and constraint logic programming languages are examples of such a customization of this
framework. Declarative programming Two additional features of logic programming are important to
note. First, in its pure form it supports declarative programming. A declarative program admits two
interpretations. The first one, called a procedural interpretation, explains how the computation takes
place, whereas the second one, called a declarative interpretation, is concerned with the question what
is being computed. Informally, the procedural interpretation is concerned with the method, whereas the
declarative interpretation is concerned with the meaning. In the procedural interpretation a declarative
program is viewed as a description of an algorithm that can be executed. In the declarative
interpretation a declarative program is viewed as a formula, and one can reason about its correctness
without any reference to the underlying computational mechanism. This makes declarative programs
easier to understand and to develop. As we shall see, in some situations the specification of a problem in
the logic programming format already forms an algorithmic solution to the problem. So logic
programming supports declarative programming and allows us to write executable specifications. It
should be added however, that in practice the Prolog programs obtained in this way are often
inefficient, so this approach to programming has to be combined with various optimization techniques,
and an appropriate understanding of the underlying computation mechanism is indispensable. To clarify
this point we shall present here a number of Prolog programs that are declarative and eliminate from
them various sources of inefficiency. This dual interpretation of declarative programs also accounts for
the double use of logic programming —as a formalism for programming and for knowledge
representation, and explains the importance of logic programming in the field of artificial intelligence.
Interactive Programming Another important feature of logic programming is that it supports interactive
programming. That is, the user can write a single program and interact with it by means of various
queries of interest to which answers are produced. The Prolog systems greatly support such an
interaction and provide simple means to compute one or more solutions to the submitted query, to
submit another query, and to trace the execution by setting up, if desired, various check points, all
within the same “interaction loop”. This leads to a flexible style of programming. This is completely
analogous to the way functional programs are used where the interaction is achieved by means of
expressions that need to be evaluated using a given collection of function definitions. 3 In what follows
we shall introduce Prolog, the best known programming language based on the logic programming
paradigm. Prolog is then based on a subset of first-order logic. We explain here how Prolog uses this
syntax in a novel way (this characteristic is called ambivalent syntax ) and extends it by a number of
interesting features, notably by supporting infix notation and by providing so-called anonymous and
meta-variables. These extensions amount to more than syntactic sugar. In fact, they make it possible to
realize in Prolog higher-order programming and meta-programming in a simple way. When discussing
Prolog it is useful to abstract from the programming language and first consider the underlying
conceptual model provided by logic programming.