200 likes | 657 Views
Introduction to Prolog. What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure. What is Prolog?. Prolog is a logical and a declarative programming language. The name itself, Prolog, is short for PROgramming in LOGic.
E N D
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure
What is Prolog? • Prolog is a logical and a declarative programming language. • The name itself, Prolog, is short for PROgramming in LOGic. • Prolog is a Programming Language for symbolic, non-numeric computation. • Prolog is the major example of a fourth generation programming language. Created By Zaman A N K
Application Areas of Prolog The main applications of the language can be found in the area of Artificial Intelligence; but PROLOG is being used in other areas in which symbol manipulation is of prime importance as well. Some application areas are: • Natural-language processing; • Compiler construction; • The development of expert systems; • Work in the area of computer algebra; • The development of (parallel) computer architectures; • Game Development; • Database systems. Created By Zaman A N K
How does Prolog work? • Prolog is based on ‘Horn Clauses' or ‘clauses’ (Rules, Facts and Queries.) • Horn Clauses are a subset of ‘Predicate Logic’ • Predicate logic is a way of simply defining how reasoning gets done in logic terms. • Predicate Logic is a syntax for easily reading and writing Logical ideas. Created By Zaman A N K
Predicate Logic... • To transform an English sentence to Predicate Logic, we remove unnecessary terms. • This leaves only the relationship and the entities involved, known as arguments. • Ex: An elephant is bigger than a horse = bigger (elephant, horse). • The relation is ‘bigger’, the relation’s arguments are ‘elephant and horse’. • In Prolog, we call the relation’s name (e.g. “bigger”) the ‘Functor’. A relation may include many arguments after the functor. Created By Zaman A N K
Example • A Prolog Program consists of clauses and each clause terminates with a full stop. bigger(elephant, horse). bigger(horse, donkey). bigger(donkey, dog). bigger(donkey, monkey). Created By Zaman A N K
Example Cont… • After compilation we can query the prolog system- Created By Zaman A N K
Rules in Prolog • Rules enable us to define new relationships in terms of existing relationships. • Rules consists of a head and a body separated by ‘:-’. The head of a rule is true if all predicates in the body can be improved to be true. For example- is_bigger(X,Y):- bigger(X,Y). is_bigger(X,Y):- bigger(X,Z), bigger(Z,Y). Created By Zaman A N K
Example is_bigger(X,Y):- bigger(X,Y). is_bigger(X,Y):- bigger(X,Z), bigger(Z,Y). bigger(elephant, horse). bigger(horse, donkey). bigger(donkey, dog). bigger(donkey, monkey). Created By Zaman A N K
Example Cont.. Created By Zaman A N K
Example Cont.. Created By Zaman A N K
Prolog Queries • Based on the Rules and Facts, Prolog can answer questions we ask it • This is known as querying the system. • We may want to ask, “What is bigger than a donkey?” • In Prolog syntax, we ask: is_bigger(X,donkey). Note: capital X on what Created By Zaman A N K
Parts of a Prolog program • All programs written in Prolog usually contain 4 parts: • DOMAINS • PREDICATES • CLAUSES • GOALS Created By Zaman A N K
What is DOMAIN? • The section of code where we define the legal values for any type that is not defined as a standard type. This may include aliasing of types (renaming). • Domain declarations can also be used to define structures that are not defined by the standard domains. Created By Zaman A N K
What are PREDICATES? • The PREDICATES section is where we define predicates to be used in the CLAUSES section and define the domains for their arguments. • Symbolic name of a relation • We found it best to think of predicate declarations as function prototypes. • Ex: bigger(symbol,symbol).; age(string, integer). Created By Zaman A N K
What are CLAUSES • Clauses are the heart of the program. • A clause is an instance of a predicate, followed by a period. • Clauses are of two types: • Facts • Rules Created By Zaman A N K
What are GOALS? • Part of program where queries are made. • Can be singular or compound. • Each part of a compound goal is known as a subgoal. • To satisfy a compound goal (or query) each subgoal must itself be satisfied by the system. Created By Zaman A N K
Resources Book- • Prolog Programming for Artificial Intelligence By Ivan Bratko Pearson Education • Online • http://www.swi-prolog.org/ • http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/pt_framer.html • http://cs.wwc.edu/KU/PR/Prolog.html Created By Zaman A N K