Labels

An Introduction To Prolog : Rules and Fact

Prolog
Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.
Prolog has its roots in formal logic, and unlike many other programming languages, Prolog is declarative: The program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations.
The language was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s and the first Prolog system was developed in 1972 by Colmerauer with Philippe Roussel.
Prolog was one of the first logic programming languages, and remains among the most popular such languages today, with many free and commercial implementations available. While initially aimed at natural language processing, the language has since then stretched far into other areas like theorem proving, expert systems, games, automated answering systems, ontologies and sophisticated control systems. Modern Prolog environments support creating graphical user interfaces, as well as administrative and networked applications. (taken fromhttp://en.wikipedia.org/wiki/Prolog)

How to Install Prolog
  1. Firstly you need to run Prolog Installer
  2. Agree the Public License
  3. Choose the components you wish to install (just click next of you don't understand the use the components)
  4. Select the directory for installation
  5. Select the workspace directory, click Install
  6. Please wait for completing installation.
  7. When the installation is complete, click finished (It's easy right? ^_^ )

Basic concept : Facts and Rules
In any programming (in this context Prolog), we will always face problems that needs rules and facts to resolve it. Facts is the basic things to solve, and rules is about 'what to do from the facts' . For example:

food(hamburger).
food(pizza).
food(bread).
food(fried_chicken).
food(cookie).
drink(syrup).
drink(milk).
drink(tea).
(above is the facts)

beverages(X,Y):-food(X),drink(Y).
(above is the rules, it will shows all possible compositions of food and drink)

Exercise: Fact and Rules
  1. First, we need to make a workspace about rules and facts from notepad.
  2. Then we need to save it with .pl extension
  3. Open the Prolog program
  4. Click File, click Consult. Select the facts & rules file from the directory, Click Open.
  5. Type beverages(X,Y). and press ; for multiple times to see the results (to show the possible compositions about food and drink)

Thanks :)