Friday, November 26, 2010

FUNDAMENTALS

Almost  all the  characters available in the keyboard can be  used. Prolog  programs  are built from TERMS. A term is either a  constant,  a variable or a structure.

DATA TYPES :
Constants :Constants  name  specific objects or  specific  relationships.
There are two types of constants.
        1. atoms (Also known as symbols)
        2. Integers
There  are two kind of atoms. One is made up of alphabets  and  digits. Another one is made up of signs only. An underscore symbol may  be used in between atoms to improve legibility.

Example of atoms : likes, kumar, books, valuable, -->, -?-

     Integers are whole numbers consisting of only digits and  may not contain a decimal point.

Example : 0   1   999    533     39848      12765      3332
Besides the above data types we have strings and characters. Strings are sequence of characters enclosed within double quotes and a character  is any valid character enclosed within single quotes.
Example of characters: 'a', '5', and 's'
Example of strings   : "GOOD MORNING", :DATE :01.02.2994".
In addition the user can define his own data types.

Variables:
A  variable is a term in Prolog look like an atom except that  they start with UPPER CASE letter.  Under score may be embedded and when used alone it is called an anonymous variable.

 Examples : Answer Input Gross-pay Sum  Otp
Please  note the difference between somebody and anybody.  Somebody can be referred only by a regular variable, but anybody can be  referred by the anonymous variable. If we ask the question, "Does anybody like ice-cream", PROLOG gives an error.  If we ask the question "does somebody like ice-cream", PROLOG gives  the answer of the variable as "mani". Hence a question  like  "Is
anyone likes ice-cream" we can write the fact as
                     ?- likes(_,icecream).
When a variable is assigned to a variable it is said to be BOUND TO THAT  VALUE OR INSTANTIATED and a variable without any value is said  to
be FREE or UNBOUND or UNINSTANTIATED.  ( i.e. ) when we write A=5  means that the variable A is bound to a value 5.
The following question will list all the thing liked by kumar.
                                    ?- likes(x,kumar).
STRUCTURE :

It is another kind of a term in prolog which is single object which consists of a collection of other objects called components.  The comp nents  are grouped together into a single structure for  convenience  in handling them. A structure is written in prolog by specifying its  functor and its components.  The functor names the general kind of structure and  corresponds to a data type.  The components are enclosed  in  rounded brackets  and separated by commas.  The functor is written  just  before the opening found bracket.
Example :
Consider the following fact, that kumar owns the byke called yamaha
by the company Escorts : 
        
                 owns(kumar,byke(yamaha,escorts)).    
  
Inside the owns fact we have a structure by the name of byke  which has two components, a byke name and the manufacturer.Structures can be nested.  Structures can also participate in the  process  of  question-answering using variable. For example, we may  ask  if  kumar owns any byke by the manufactureres Escorts:
                   ?- owns(kumar,byke(x,escorts)).
If  this is ture, x will be instantiated to the byke name that  was found.  This may resemble the tee structure like.

PROGRAMMING IN PROLOG

NTRODUCTION:PROLOG  is a computer programming language mainly used to communicate  with machine like English is used to communicate with humans. The language was developed by Alan Colmeraur & P.Russel in the year 1972  at
the  University  of Marsailles, France. For designing  Natural  language Translation  Systems.  The  word Prolog is acronym  for  Programming  in Logic.The  importance  of  this language is  quickly  gaining  popularity throughout the world and its application includes.
               --  relational database
               --  mathematic logic
               --  abstract problem solving
               --  natural language processing
               --  design automation
               --  symbolic equation solving
               --  biochemical structure analysis
               --  many areas of AI.