Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Prolog technically work? What's under the hood?

Tags:

prolog

I want to learn more about the internals of Prolog and understand how this works.

I know how to use it. But not how it works internally. What are the names of the algorithms and concepts used in Prolog?

Probably it builds some kind of tree structure or directed object graph, and then upon queries it traveres that graph with a sophisticated algorithm. A Depth First Search maybe. There might be some source code around but it would be great to read about it from a high level perspective first.

I'm really new to AI and understanding Prolog seems to be a great way to start, imho. My idea is to try to rebuild something similar and skipping the parser part completely. I need to know the directions in which I have to do my research efforts.

like image 419
SecretService - not really Avatar asked May 04 '11 09:05

SecretService - not really


People also ask

Is Prolog a high-level language?

Programmation en Logique (Programming in Logic) or Prolog is a high-level programming language that has its roots in first-order logic or first-order predicate calculus. The language was conceived in Marseilles, France in the early 1970s by a group led by Alain Colmerauer.

Is Prolog low level?

High-level language does not specifically refer to a specific language. Still, it includes many programming languages, such as the currently popular Java, c, c++, C#, pascal, python, Lisp, Prolog, FoxPro, VC, accessible language, Chinese version.

How does Prolog work?

Unlike many other programming languages, Prolog is intended primarily as a declarative programming language. In prolog, logic is expressed as relations (called as Facts and Rules). Core heart of prolog lies at the logic being applied. Formulation or Computation is carried out by running a query over these relations.


3 Answers

What are the names of the algorithms and concepts used in Prolog?

  • Logic programming
  • Depth-first, backtracking search
  • Unification

See Sterling & Shapiro, The Art of Prolog (MIT Press) for the theory behind Prolog.

Probably it builds some kind of tree structure or directed object graph, and then upon queries it traveres that graph with a sophisticated algorithm. A Depth First Search maybe.

It doesn't build the graph explicitly, that wouldn't even be possible with infinite search spaces. Check out the first chapters of Russell & Norvig for the concept of state-space search. Yes, it does depth-first search with backtracking, but no, that isn't very sophisticated. It's just very convenient and programming alternative search strategies isn't terribly hard in Prolog.

understanding Prolog seems to be a great way to start, imho.

Depends on what you want to do, but knowing Prolog certainly doesn't hurt. It's a very different way of looking at programming. Knowing Prolog helped me understand functional programming very quickly.

My idea is to try to rebuild something similar and skipping the parser part completely

You mean skipping the Prolog syntax? If you happen to be familiar with Scheme or Lisp, then check out section 4.4 of Abelson & Sussman where they explain how to implement a logic programming variant of Scheme, in Scheme.

like image 183
Fred Foo Avatar answered Oct 08 '22 20:10

Fred Foo


AI is a wide field, Prolog only touches symbolic AI. As for Prolog, the inner workings are too complex to explain here, but googling will give you plenty of resources. E.g. http://www.amzi.com/articles/prolog_under_the_hood.htm .

Check also Wikipedia articles to learn about the other areas of AI.

like image 31
compostus Avatar answered Oct 08 '22 19:10

compostus


You might also want to read about the Warren Abstract Machine
typically, prolog code is translated to WAM instructions and then executed more efficiently.

like image 42
Thanos Tintinidis Avatar answered Oct 08 '22 21:10

Thanos Tintinidis