1 / 23

Logic Programming Language PROLOG

Logic Programming Language PROLOG. Presented by: Jeffrey Coleman & Desi Doncheva. Concepts of Logical Programming and Prolog. I. Overview of Logic Programming Concepts. A. Declarative programming paradigm.

cole-obrien
Télécharger la présentation

Logic Programming Language 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. Logic Programming Language PROLOG Presented by: Jeffrey Coleman & Desi Doncheva

  2. Concepts of Logical Programming and Prolog • I. Overview of Logic Programming Concepts. A. Declarative programming paradigm. B. The role of Predicate Calculus in Logic Programming. C. Characteristics of Logic Programming Languages - declarative semantic. • II. Prolog. A. Origins and OSI Standard for Prolog. B. Basic Elements in Prolog. C. Definition of Program Construction in Prolog. D. Prolog Resolution. E. Deficiencies of Prolog. • III. Applications. A. Use of Logic Programming in implementation of RDBMS. B. Expert Systems. C. Language Processing. • IV. Prolog Language Variances. A. ObjLog. B. TuProlog. C. VAP Prolog. D. Lambda Prolog. E. Visual Prolog. • V. Conclusion – the importance of Logic Programming Language Prolog.

  3. I. Overview of Logic Programming Concept. • Logic Programming uses a significantly different approach from functional and imperative programming in the process of developing the program and producing the result of the execution . • Programs are expressed in terms of symbolic logic and logical inferences. Logical Programming is built over first-order predicate calculus. • Logic programs are declarative - the program only describes what should be accomplished rather than the algorithm the program must follow in order to produce the desired result. • What is needed by the program to provide the capability of logic programming is the relevant information and the method of inference for computing the result.

  4. Predicate calculus defines terms such as atomic propositions, compound terms, antecedents and consequents of a causal form proposition, resolution of sequence of propositions that are used to define relations by Facts or by Rules in Logic Programming syntax. • Logic Programming Languages have declarative semantics. Every program consists of declarations (propositions) rather than assignments and control flow statements. • Declarative semantics is simpler than the semantics of the imperative languages. For example, the meaning of a proposition in declarative language can be determined from the proposition itself. In contrast, a simple assignment statement in imperative language requires variable type checks, examination of local declarations, and the scope rules of the language.

  5. II. Prolog. • Origins and OSI Standard for Prolog. • Developed by Alain Colmerauer, a French computer scientist, with the assistance of Robert Kowalski at University of Edinburgh in 1972. • Few dialects of Prolog are available because two independent European universities research on the development and the use of the language. • Prolog gained popularity when Japanese government launched a research project on developing Fifth Generation Computer Systems in 1981 and Prolog was chosen as a basis language for research. • The widely available syntax of Prolog is the so-called Edinburgh syntax, which in 1996 was officially accepted as OSI standard for Prolog.

  6. Basic Elements. There are only a few data types called data objects in Prolog but they can be constructed to be very complex. The type of an object is recognized by its syntactic form.

  7. Simple Data Objects. Constants are concrete objects in form of Atom or Integer. Atomsaresymbolic values represented by strings of letters, digits and the underscore character starting with a lower-case letter. Ex. anna, x25, x_, x_AB Integers in Prolog include real and integer numbers. But numbers are not heavily used because the language primarily uses symbolic non-numeric computation. Variables are strings of letters, digits and an underscore character, which must start with an upper-case letter. The lexical scope of the variable name is the clause the variable appears in. The process of binding a value to a variable is called instantiation. Ex. X, Result, _23, Object2 Structures. Structures are objects that have several components. Structures can be nested—a component of a structure can be another structure. The form of a structure is as follows: functor( parameters list) Ex. data( 1, may, 2001) – all components are constants. data (Day , may, 2001) – Day is a variable. A structure object can be pictured as a tree. The root of the tree is the functor and the children of the root are the parameters in the structure declaration. If one of the parameters is also a structure, then we define a subtree for that tree .

  8. Definition of Program Construction in Prolog. • A program written in Prolog starts with information assumed to be always true, then we define a theorem or a set of theorems, and finally, we ask if the theorem is satisfied for some set of objects. • Prolog programs consists of FACT statements, RULE statements and GOAL statements. • In proving theorems, we always use a set of information that we know is always true. Each statement in this set or database of assumed information is called a FACT in Prolog. • FACTS are defined with the use of structure data objects and a list of atoms or integers as parameters. Each statement ends with a period. The form of FACT statements corresponds to the headless Horn clause from predicate calculus. Ex.1 parent ( tom, bob). Tom is Bob’s parent female ( linda). Linda is a female. • Prolog is suited for solving problems that define relations between objects. The functor part of the statement actually defines the relation between the objects in the arguments list.

  9. RULE statements have an ‘if’ and a ‘then’ part. They correspond to headed Horn clauses. • The ‘then’ part, also called the consequent, is a single statement or term that needs to be satisfied. • The ‘if’ part, which is called the antecedent, can be constructed from a single statement or a set of statements. Ex 2. Consider the following logical statement: For all X and Y, Y is a child of X if X is parent of Y. Using Prolog RULE statements, we can construct the following Prolog clause: child (Y, X) :- parent ( X, Y)., where X and Y can be instantiated to any object. And if the parent (X, Y) term is satisfied or true then the child (Y, X) term is also true. • We can think of X and Y as being universal quantifiers or objects. • If there are some instances of X and Y that satisfy the antecedent part of the RULE statement, then the consequent term is also satisfied for those same instances of X and Y.

  10. If we define a rule with more then one statement in the antecedent part, the comma separator (,) acts as a conjunction or logical AND. Ex. 3 For all X and Y, X is mother of Y if X is a female and X is parent of Y. Prolog rule: mother (X , Y) :- female (X), parent (X, Y). In the second example BOTH female (X) AND parent (X, Y) must be true for some instances of X and Y in order for the rule mother (X, Y) to be satisfied for the same X and Y. Ex. 4 siblings (X, Y) : - mother(M, X), mother(M, Y), father(F, X), father(F, Y). • So far we have seen how known facts and rules that define relationships among facts are described in Prolog, but it’s still not clear what the output of a Prolog program would look like.

  11. After we define the facts and the rules of inference between objects, we can simply ask if certain rules are true for certain sets of objects. • This type of Prolog statement is the GOAL statement. • The syntactic form of a Prolog GOAL statement is identical to a headless Horn Clause. factor ( parameters list). where factor is the name of the relationship that will be proved to be either true or false for the parameters in the parameter list. Ex. 5 The following clause will be either true or false. female( linda ). The system will display YES if the predicate female is satisfied for the atom linda, either by fact reference or by rule reference, or NO if the predicate is not satisfied. • Prolog GOAL statements can include a combination of variables and atoms. In this case, the system not only displays the result of the satisfaction of the GOAL statement, but also the values of the variable or variables for which the GOAL statement is satisfied. Ex. 6 GOAL statement: father (X, bob). Result: X = tom yes

  12. Prolog Resolution. • How does the program decide if a GOAL statement is true or false? • When the programmer ask a question, the system uses the process of inference to satisfy each of the propositions when the GOAL is a compound proposition (more then one statement must be satisfied). • The inferencing process must find a chain of inference rules and/or facts in the database that connects the GOAL to one or more facts in the same database. If Q is the GOAL then either Q must be found in the facts database OR the inferencing process must find a fact P1 or a sequence of facts P1, P2, P3,…, PN, such that P2 : - P1, P3 : - P2, ….. Q : - PN. The process of finding the Ps is complicated when we have compound propositions in the antecedent part of the GOAL statement. This process is also called matching because the system basically compares and matches the rules with each other.

  13. Bottom-up resolution ( Forward chaining). The system begins with facts and the rules in the database and attempts to find a sequence of matches that lead to the GOAL. It’s suitable for large numbers of possible correct answers. Not used by Prolog system of inferencing. • Top-down resolution ( Backtrack chaining). The system begins with the goal and attempts to find a sequence of matching prepositions that lead to the same set of original facts in the database. The backtrack chaining works when a small set of candidate answers are possible. Prolog system uses the backtrack chaining because of the large class of problems that are suitable to be solved with top-down resolution. Ex. 7 Database of facts and rules: father (bob). man (X) : - father (X). GOAL: man (bob). Forward resolution? Backtracking resolution?

  14. What does the system do when a subgoal fails? Prolog system uses the backtracking mechanism to backtrack to a certain subgoal and reexamines all the possible answers. Multiple solutions result from different instantiations to the variables in the subgoal. The backtracking mechanism for finding solutions requires a lot of memory and time because it finds every possible solution for each subgoal.

  15. Deficiencies of Prolog. • Resolution Order Control The Prolog resolution technique is sequential—it starts with the first predicate in the database and continues until it has examined all of the facts and rules. This can be very inefficient and hinder optimization. By contrast, pure logic examines the prepositions in a non-deterministic manner, leaving out facts or rules which are less likely to be called upon. • Closed-World Assumption The Prolog system knows nothing about the world other than what is in its database, and anything that cannot be proven true from inference of that database is assumed to be false. Thus, Prolog is actually a true/fail rather than a true/false system. This means that a programmer must account for every possibility while writing a Prolog program. • Intrinsic Limitations Despite the versatility and power of logic programming, there are some sets of problems that it cannot solve without resorting to procedural programming concepts, such as sorting lists. The programmer must still define a procedure for the system to follow in these cases.

  16. III. Applications A. Use of Logic Programming in implementation of RDBMS In DBS, the query language SQL is used to execute queries. SQL is a nonprocedural language, which makes it similar to logic programming languages such as Prolog. The table which stores information in the database system can be described as a set of structures in a logic programming language, and the relationships between the tables can be described by rules of inference. Therefore, the use of logic programming to implement RDBMS systems is advantageous in terms of using a single language to input, output, and process data, and in the capability to deduce information not built into the database. (Conventional databases store facts or data without inference rules.) B. Expert Systems. Expert systems, also called knowledge-based systems, are programs that behave as an expert for some small set of problems. They are capable of solving problems that require some knowledge built into the system. They are designed to offer solutions to problems for which the set of initial information is inconsistent and/or incomplete. Defining an expert system involves the presentation of the knowledge and creation of a user-friendly interface in a manner by which proper reasoning can be applied to arrive at a solution.

  17. C. Natural Language Processing A form of logical programming can be used to describe the language syntax just as a context-free grammar would. The semantic of a natural language can be made clear by modeling the language with logic programming.

  18. IV. Prolog Language Variants • KL1—An experimental AND-parallel version of the sequential logic language KL0. • ObjLog—A frame-based language which combines objects with Prolog predicates. • TuProlog—A Java-based lightweight Prolog engine, used for research at the University of Bologna, Italy. The core is a tiny Java object which contains only the essential Prolog predicates such as input and output, and requires the Java Virtual machine to run. • Visual Prolog—Distributed by Borland, Visual Prolog is a strongly object-oriented extension of Prolog. It can be used to build Microsoft Windows GUI applications, console applications, DLLs, and CGI. It combines the best features of logic and object-oriented programming. • VAP Prolog—An open-source Prolog engine compatible with ISO Prolog standard.

  19. Lambda-Prolog—Developed at the University of Minnesota, it features high-ordered programming, using functions as arguments to other functions, as in lambda calculus. • Strawberry Prolog—A dialect of Prolog whose syntax is close to that of ISO Prolog with numerous extensions.

  20. Conclusion We have only covered a fraction of Prolog and concepts of logic programming, but we can see that it is very different from the functional and procedural programming that we are more familiar with. Logic programming is very powerful for defining relations between objects. We have seen how easy it is to define familial relations simply by using facts and rules, without having to know how the system interprets and derives solutions to questions such as “Who are Ivan’s siblings?” More advanced data structures, such as lists, are used to represent sets , trees, and graphs; such data structures are useful in creating games, solving scheduling problems, finding paths and other functions involving graphs, and so on, in a much clearer way than procedural programming. Because of its small number of primitive constructs, many more complex constructs can be designed in a way that is easy for the programmer to write and for an outside observer to read.

  21. Simple Program • FACTS Declaration: parent(tom, bob). parent(tom, liz). parent(bob, ann). parent(bob, pat). parent(pat, jim). female(pam). female(liz). female(ann). female(pat). male(tom). male(bob). male(jim). • RULES Declaration: offspring(Y, X):- parent(X, Y). mother(X, Y):- parent(X, Y), female(X). grandparent(X,Z):-parent(X, Y), parent(Y, Z). sister(X, Y):-parent(Z, X), parent(Z, Y), female(X), \==(X, Y). predecessor(X, Z):-parent(X, Z). predecessor(X, Z):-parent(X, Y), predecessor(Y, Z).

  22. Simple Queries that Prolog engine can answer based on FACTs and RULEs previously declared: parent( bob, pat). parent( tom, ann). child( ann, bob). child( liz, bob). predecessor( X, liz). predecessor( X, jin). predecessor( pam, Z). predecessor( X, Z). The free GNU Prolog interpreter and compiler can be downloaded from www.gprolog.org. It’s supported on Linux and Windows platforms as well as many other architectures. A comprehensive manual is also available. GNU Prolog compiler complies with ISO Prolog standard and extend the language specification by providing many other useful in practice predicates.

  23. References • Sebesta R., Concepts of Programming Languages, 7th Ed., 2006, Pearson Education, Inc • Bratko I., Prolog – Programming for Artificial Intelligent, 3rd Ed., 2000, Eddison Wesley • GNU Prolog Compiler Manual - www.gprolog.org

More Related