What’s Prolog?

Print anything with Printful



Prolog is a logic-based programming language that focuses on logical relationships between entities rather than steps to solve a problem. It builds a knowledge base and can be used in various applications such as natural language systems, symbolic mathematics, and expert systems.

Prolog is a logic-based computer programming language. Most computer languages ​​are based on the steps needed to solve a problem. The Prolog language, on the other hand, is a “declarative” language that indicates the logical relationships between entities. The way to solve the problem is left to the computer. The name Prolog comes from the French PROgrammation en LOGique, i.e. PROgramming LOGic.

The following is a simple Prolog program:

ancestor(F, C) :- father(F, C)
ancestor(P, Q) :- father(P, R), ancestor(R, Q)
father (john, jim).
padre (jim, jerry).
padre (jerry, jason).
padre (jerry, jeff).
father (jason, joshua).

The above program points to obvious truths. If F is the father of C, then F is an ancestor of C. If P is the father of a person R who is an ancestor of Q, then P is an ancestor of Q. A number of true facts are then given, such as john is jim’s father. If then a problematic question is asked about whether john is an ancestor of jeff, we get the answer “Yes” as below:

?- ancestor (john, jeff).
Yes

If Joshua’s ancestors are interesting, the program displays all ancestors as follows:
?- ancestor (A, joshua)
A = jason
A = jerry
A = jim
A = John
Note that in both of the above cases, the program didn’t tell you how to do the assessment. For example, it did not indicate whether to start with the oldest person and work your way up to the youngest person or vice versa. Even swapping the parts as below:
ancestor(P, Q) :- ancestor(R, Q), father(P, R)
It would make no difference to the program, since both of these parts on the right side must be true for the left side to be true.
The Prolog language therefore focuses on relationships, and not on how to solve the problem. As the program runs, Prolog builds a series of true statements, creating a knowledge base. In the example above, the knowledge base, in no particular order, would have ancestor(john, jim), ancestor(jim, jerry), ancestor(john, jerry), ancestor(jim, jason), ancestor(john, jason), and so on. This knowledge base can continue to grow during the execution of the program and can be efficiently searched for solutions. Execution can use parallel processing, simultaneous execution from multiple computers.
The Prolog language is used in several areas. It started with natural language oriented systems like English; natural language is one of the areas of artificial intelligence. The Prolog language is also used in symbolic mathematics, including algebra. It is used in theorem proving, expert systems, and control systems, among many other applications.




Protect your devices with Threat Protection by NordVPN


Skip to content