Introduction to Prolog What is Prolog Application Areas


















- Slides: 18
Introduction to Prolog • What is Prolog? • Application Areas of Prolog • How does Prolog work? (Syntax of Prolog) • Program Structure Created By Zaman A N K
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, nonnumeric computation. • Prolog is the major example of a fourth generation programming language. 1/20/2022 Created By Zaman A N K 2
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. 1/20/2022 Created By Zaman A N K 3
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. 1/20/2022 Created By Zaman A N K 4
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. 1/20/2022 Created By Zaman A N K 5
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). 1/20/2022 Created By Zaman A N K 6
Example Cont… • After compilation we can query the prolog system- 1/20/2022 Created By Zaman A N K 7
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 exampleis_bigger(X, Y): bigger(X, Y). is_bigger(X, Y): bigger(X, Z), bigger(Z, Y). 1/20/2022 Created By Zaman A N K 8
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). 1/20/2022 Created By Zaman A N K 9
Example Cont. . 1/20/2022 Created By Zaman A N K 10
Example Cont. . 1/20/2022 Created By Zaman A N K 11
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 1/20/2022 Created By Zaman A N K 12
Parts of a Prolog program • • • All programs written in Prolog usually contain 4 parts: DOMAINS PREDICATES CLAUSES GOALS 1/20/2022 Created By Zaman A N K 13
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. 1/20/2022 Created By Zaman A N K 14
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). 1/20/2022 Created By Zaman A N K 15
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 1/20/2022 Created By Zaman A N K 16
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. 1/20/2022 Created By Zaman A N K 17
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 1/20/2022 Created By Zaman A N K 18