Now Reading
Sides of Prolog

Sides of Prolog

2023-09-11 16:25:21


Sides of Prolog





Video: A Tour of Prolog

Prolog is …

Prolog is a quite simple language

It’s straightforward to explain Prolog syntax in enough element
to start out working with Prolog instantly.

All data are represented by
Prolog terms.

There’s a single language factor, referred to as
a clause. A clause is of the
type:

Head :- Physique.

Which means if Physique
holds, then Head holds. The infix
operator (:-)/2 represents an arrow from proper to
left: ←.

If Head all the time
holds, then :- Physique might be omitted.

The above is sufficient to write helpful first Prolog packages.

Chances are you’ll not consider this, so witness the proof: All
packages introduced within the following consist solely of such
clauses.

In truth, all identified computations might be described in phrases
of such clauses, making Prolog
a Turing complete
programming language. One method to implement a
Turing machine in Prolog is to explain the relation
between completely different states of the machine with clauses of the
type “If the present state is S0 and
the image below the tape head is T, and
then the subsequent state is S“.
See turing.pl for one
implementation, and Thinking
in States
for extra data.

Prolog is a declarative language

Prolog is a declarative language. Which means we focus
on stating what we’re involved in. We express
what holds
about options we need to discover. We’re much less
involved about how the Prolog implementation finds these
options.

This declarative nature usually permits for very concise, clear and
common specs. It’s unlikely that shorter formalisms
which are equally clear and expressive exist.

For instance, allow us to describe the relation between
a list and its size,
utilizing integer arithmetic:

Notice: In some Prolog methods, you at the moment must
embody a devoted library to make use of declarative integer
arithmetic. More…
list_length([], 0).
list_length([_|Ls], N) :-
        N #> 0,
        N #= N0 + 1,
        list_length(Ls, N0).
    

We will read this declaratively as follows:

  1. The size of the empty checklist [] is  0.
  2. If the size of the checklist Ls
    is N0 and N
    is N0+1, then the size
    of [_|Ls] is N. Additional, this solely
    holds if N is better than 0.

When programming in Prolog, assume by way of relations
between entities. Your packages will turn out to be very common with this
strategy. Within the above instance, it’s tempting to assume and say
“We’re computing the size of a listing”. And sure, it’s true: We
can certainly use the above definition to compute the size of
a checklist:

?- list_length([a,b,c], L).
   L = 3.
    

Nevertheless, this crucial studying doesn’t do justice to
what we have now really carried out, as a result of the definition additionally
covers a number of further utilization patterns. For
instance, given a selected size, we will ask whether or not
there are lists of that size:

?- list_length(Ls, 3).
   Ls = [_A,_B,_C]
;  false.
    

Utilizing the most common question, we will even ask for all
solutions that Prolog finds in common:

?- list_length(Ls, L).
   Ls = [], L = 0
;  Ls = [_A], L = 1
;  Ls = [_A,_B], L = 2
;  Ls = [_A,_B,_C], L = 3
;  ... .
    

We are saying that the relation is usable in several modes.
Characteristically, Prolog experiences all solutions
through backtracking.

The predicate size/2 is a part of
the Prologue
for Prolog
draft, and already obtainable as
a built-in predicate in virtually all
Prolog implementations with the above semantics.

Within the class of declarative languages, we
discover practical programming languages and logic
programming languages. A perform is a particular case of a relation,
and practical programming might be considered a restricted type of
logic programming.

Prolog is firmly rooted in logic.

A pure Prolog program consists of a set
of Horn clauses.

Its execution might be considered a particular case
of resolution.

This connection to formal logic permits us to use highly effective
declarative debugging strategies that
are based mostly on logical properties of this system. For instance,
including a constraint can at most scale back the set of
options, and including a clause can at most lengthen
it. This property of pure Prolog packages is
referred to as monotonicity.

See
the GUPU
system
by Ulrich Neumerkel for a powerful software
of those concepts.

Prolog is a homoiconic language

homoiconic: from ὁμός = “identical” and εικών = “picture”

See Also

Prolog packages are additionally legitimate Prolog phrases! This
has many nice benefits: It’s straightforward to put in writing Prolog packages
that analyze, rework and interpret different Prolog
packages. You should utilize the built-in predicate learn/1 to
learn a Prolog time period, and thus additionally a Prolog clause.

There’s a highly effective mechanism to rewrite
Prolog packages at compilation time, so that you could simply
implement domain-specific languages that allow you to resolve your duties
extra naturally.

Chances are you’ll not consider this, as a result of some objectives—such
as list_length(Ls, N)—seem like
Prolog phrases as outlined above, whereas different objectives—such
as N #> 0—look fairly completely different.
The rationale for that is that Prolog supplies prefix, infix and
postfix operators that allow you to write Prolog phrases
in a extra readable method. For instance, the Prolog
time period +(a,b) will also be written utilizing
operator notation as a+b.
The summary syntax stays utterly uniform, and
you possibly can learn and course of all Prolog phrases unbiased of how they
are written down.

You may dynamically outline customized operators for particular use circumstances.

Prolog is a really dynamic language

Prolog packages might be simply created, referred to as and modified at
run time
. This additional will increase the expressiveness of Prolog
and allows you to implement higher-order
predicates
which produce other predicates as arguments. It additionally
permits the implementation of very dynamic strategies
like adaptive parsing.

The dynamic nature of Prolog additionally makes the language ideally
fitted to writing packages which are extensible by
customized guidelines that different programmers and even common customers
present. Proloxy
and Gerrit
Code Review
are examples of this strategy: You configure
these packages by supplying
Prolog rules that specific your
necessities in a really readable and versatile method.

See A Couple of
Meta-interpreters in Prolog
for extra data.

You may outline an interpreter for pure Prolog in two traces of
Prolog code.

Prolog is a really versatile language

Prolog is a particularly versatile language. Its relational nature
makes Prolog packages very versatile and common. This performs an
necessary position in language processing and
information illustration
in databases. Fashionable Prolog
methods present every little thing that’s wanted for fixing
easy logic puzzles to constructing enormous
functions, starting from
web hosting
to verification
and optimization duties.

Prolog’s versatility and energy are rooted in implicit
mechanisms that embody search, unification, argument indexing and
constraint propagation. You should utilize these mechanisms to your
benefit, and delegate many duties to the
Prolog engine.

Video: Sparrows on Eagles

This web page was despatched to you by
a Prolog HTTPS
server
.

More about Prolog

Main page

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top