1 / 18

Introduction to Prolog

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.

imogene
Download Presentation

Introduction to Prolog

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. Example Cont… • After compilation we can query the prolog system- Created By Zaman A N K

  8. 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

  9. 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

  10. Example Cont.. Created By Zaman A N K

  11. Example Cont.. Created By Zaman A N K

  12. 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

  13. Parts of a Prolog program • All programs written in Prolog usually contain 4 parts: • DOMAINS • PREDICATES • CLAUSES • GOALS Created By Zaman A N K

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

More Related