You are on page 1of 56

ProLog

Introduction Prolog: An overview Syntax for Predicate Calculus Programming Abstract Data Types in Prolog Search Strategies in Prolog Prolog Tools Meta-Interpreters in Prolog Natural Language Understanding in Prolog Explanation- Based Learning in Prolog Prolog and programming with Logic OOP and Concurrency in Prolog

Prolog is a simple, yet prevailing programming language, based on the principles of first order predicate logic. The acronym of the Prolog is for the French PROgrammation en LOGique'. The name of prolog is known as a Logic programming. Until the end of the seventies, the use of prolog was limited to the academic world

Only after the development of an ancient Prolog interpreter and compiler. Prolog is still mainly used by researchers, even though it allows for the development of solemn and widespread programs in a fraction of the time needed to develop a C or Java program with similar functionality. The only explanation of this is the people wasting their time. There are a large number of _ends in which PROLOG has been applied successfully.

Prolog is a high-performance, high-quality, and awardwining implementation of the standard. Programming language based on first order Horn theories, SLD resolution. Search strategy is fixed: depth-first, left to right, top to bottom. Programmer uses this to order search, is responsible for efficiency and termination. Good for symbolic computing.

Syntax of terms Rules Facts Queries Unification

variables begin with upper-case letter or _ Constants and functors (function and predicate symbols) begin with lower-case Example: John, john_smith, X, Node, _person, CSE, fatherOf(paul), date(25,10,2005)

Rules extend the capabilities of a logic program. They are what give Prolog the ability to pursue its decision-making process. The following program contains two rules for temperature. The first rule is read as follows: ``It is hot if it is summer and it is sunny.'' The second rule is read as follows: ``It is cold if it is winter and it is snowing.''

Example: 'It is sunny'. 'It is summer'. 'It is hot' :- 'It is summer', 'It is sunny'. 'It is cold' :- 'It is winter', 'It is snowing'.

Facts are a special case of rules, definite clauses with no negative literal. A fact is just what it appears to be --- a fact. A fact in everyday language is often a proposition like ``It is sunny.'' or ``It is summer.''

A query in Prolog is the action of asking the program about information contained within its data base. Thus, queries usually occur in the interactive mode.

a query asks whether a (conjunction of) atomic formula is entailed by the program.

Variables in queries can be viewed as existentially quantified, can be used to retrieve information.

Unification is used to match queries with facts or the head or rules no fixed input or output parameters ?- parent (Mary,X). X = Elizabeth Yes

Predicate Calculus Predicate Calculus: Syntax

In propositional logic only the logical forms of compound propositions are analyzed. A simple proposition is an unanalyzed whole which is either true or false. There are certain arguments that seem to be perfectly logical, yet they cannot be expressed by using propositional calculus.

Example: 1. All cats have tails. 2. Tom is a cat. From these two sentences, one should be able to conclude that 3. Tom has a tail.

1. Maria is Renz's mother. 2. Maria is Mary's mother. 3. Any two persons having the same mother are siblings. Paul and Mary are siblings.

The truth of the statement \Maria is Paul's mother" can only be assessed within a certain context. There are many people named Jane and Paul, and without further information the statement in question can refer to many different people, which makes it ambiguous. To prevent such ambiguities we introduce the concept of a domain or universe of discourse.

Programming in almost any environment is enhanced by creating procedural abstractions and by hiding information. Because the set, stack, queue, and priority queue data structures are important support constructs for graph search algorithms, a major component of AI problem solving, we build them in prolog in the present section.

STACK Queue Priority Queue

Is a linear structure with access at one end only. Thus all elements must be added to pushed, and removed, popped, from the structure at that access end. A stack is sometimes referred to as a last-infirst-out (LIFO) data structure.

A queue is a first-in-first-out (FIFO) data structure. It is often characterized as a list where elements are taken of f or dequeued from one end and elements are added to or enqueued at the other end.

A priority queue orders the element of a regular queue so that each new element added to the priority queue is placed in its sorted order, with the best element first. The queue operator removes the best sorted element to the priority queue.

A set is a collection of elements with no elements repeated. Sets can be used for collecting all children of a state or for maintaining the set of all states visited while executing a search algorithm.

Search is a major issue. There are many ways to search for the solution to a problem and it is necessary to learn suitable algorithms that are efficient. Prolog provides a single method of search for free. This method is known as depth first search. You should find that Prolog enables the programmer to implement other search methods quite easily.

Prolog's basic search strategy is now going to be outlined. To do this we need to consider something about the Prolog system. Prolog is an interactive system. The interactions between the programmer and the Prolog system can be thought of as a conversation. When the Prolog system is entered we are at top level. The system is waiting for us to initiate a `conversation'.

Prolog Development Tools (ProDT) is a Prolog Integrated Development Environment (IDE) aiming to be as rich in functionality as the Eclipse's java IDE, giving the developer a single environment where it can control the development of a Prolog project from code edition, test execution and debugging.This project stands on top of Eclipse's projects to take advantage of its already existent features and its extensibility.

SWI- Prolog B-Prolog Interactive Environment Matching clauses Bi-directional Interface with C or Java Action rules and constraint solvers Constraint-based graphics package Tabling mechanism XSB

SWI-Prolog offers a comprehensive Free Software Prolog environment, licensed under the Lesser GNU Public License. Together with its graphics toolkit XPCE, its development started in 1987 and has been driven by the needs for real-world applications. These days SWI-Prolog is widely used in research and education as well as for commercial applications.

B-Prolog is a high-performance implementation of the standard Prolog language with several extended features including matching clauses, action rules for event handling, finite-domain constraint solving, arrays and hash tables, declarative loops, and tabling. First released in 1994, B-Prolog is now a widely used CLP system.

The constraint solver of B-Prolog was ranked top in two categories in the Second International Solvers Competition and it also took the second place in P class in the second ASP solver competition. BProlog underpins the PRISM system, a logic-based probabilistic reasoning and learning system. BProlog is a commercial product, but it can be used for learning and non-profit research purposes free of charge

B-Prolog provides an interactive environment through which users can consult, list, compile, load, debug and run programs. The command editor in the environment facilitates recalling and editing old commands.

B-Prolog accepts not only standard form Prolog programs but also matching clauses in which the determinacy and input/output unifications are denoted explicitly. Matching clauses are compiled into more compact and faster code than standardform clauses. The compiler and most of the libraries are written in matching clauses.

B-Prolog provides a bi-directional interface with C and Java. This interface makes it possible to integrate applications developed in B-Prolog with those developed in C, C++, and Java such as DBMS systems, Servlet, JSP, COM, and 3D graphics packages.

B-Prolog offers the user a unique construct, called action rules, which is useful for programming concurrency, implementing constraint propagators, and developing interactive graphical user interfaces. Action rules have been successfully used to implement efficient constraint solvers over trees, Boolean, finite-domains, and sets.

B-Prolog provides a high-level and constraint-based graphics library, called CGLIB. The library includes primitives for creating and manipulating graphical objects and a set of constraints that facilitates the specification of the layouts of objects. Action rules are employed to program interactions.

B-Prolog supports the tabling mechanism, which is effective for certain applications such as parsing, problem solving, theorem proving, model checking, and deductive databases.

XSB is a Logic Programming and Deductive Database system for Unix and Windows. It is being developed at a number of institutions, including the Computer Science Department of Stony Brook University, Universidade Nova de Lisboa, XSB, Inc., Katholieke Universities Leuven, and Uppsala Universities.

Interpreted languages like Prolog can easily treat program code as data can use clause to look at program code assert, retract, abolish to create/remove code =.., name, etc to look at terms themselves Meta-programming: a program which treats program code as data The program code executed can be a different language than the code the meta-program is written in or it can be the same language Meta-interpreter: a meta-program that executes a program (source program) , possibly writing in that language itself can be used to enhance your language execution can create prototype languages as well

Subtopic of natural language processing in artificial intelligence that deals with machine comprehension. He process of disassembling and parsing input is more complex than the reverse process of assembling output in natural language generation because of the occurrence of unknown and unexpected features in the input and the need to determine the appropriate syntactic and semantic schemes to apply to it, factors which are predetermined when outputting language.

Natural language processing (NLP) is a field of computer science, artificial intelligence (also called machine learning), and linguistics concerned with the interactions between computers and human (natural) languages. Specifically, the process of a computer extracting meaningful information from natural language input and/or producing natural language output. In theory, natural language processing is a very attractive method of humancomputer interaction. Natural language understanding is sometimes referred to as an AIcomplete problem because it seems to require extensive knowledge about the outside world and the ability to manipulate it.

The central idea of explanation-based learning (EBL) as conveniently formalized for Prolog [8, 16] is to compute a generalized explanation from a concrete proof of an example. Explanations use only so-called operational predicates, i.e. predicates that capture essential characteristics of the domain of interest and should be easy to prove. Operational predicates are to be declared by the user as such. Following the work by [8, 16], explanation based learning starts from a denite clause theory T, that is a pure Prolog program, and an example in the form of a ground atom p(t1, ..., tn). It then constructs a refutation proof of the example using SLD-resolution. SLD-resolution takes a goal of the form ? g, g1, ..., gn, a clause h b1, ..., bm such that g and h unify with most general unier , and then produces the resolvent ? b1, ..., bm, g1, ...., gn.

Intelligent Systems - programs which perform useful tasks by utilizing artificial intelligence techniques. Expert Systems - intelligent systems which reproduce decision-making at the level of a human expert. Natural Language Systems - which can analyst and respond to statements made in ordinary language as opposed to approved keywords or menu selections. Relational Database Systems

Concurrency Prolog is an open-source SWI-Prolog extension for distributed computing over the Message Passing Interface Also there are various concurrent Prolog programming languages. Message Passing Interface (MPI) is a standardized and portable message-passing system designed by a group of researchers from academia and industry to function on a wide variety of parallel computers.

The standard defines the syntax and semantics of a core of library routines useful to a wide range of users writing portable message-passing programs in Fortran 77 or the C programming language. Several well-tested and efficient implementations of MPI include some that are free and in the public domain. These fostered the development of a parallel software industry, and there encouraged development of portable and scalable large-scale parallel applications.

You might also like