Docsity

Prolog, Prolog Programming In Artificial Intelligence, Slides of Artificial Intelligence

Partial preview of the text

Download Prolog, Prolog Programming In Artificial Intelligence and more Slides Artificial Intelligence in PDF only on Docsity!

Prolog Programming

Introduction

Prolog

Prolog is a logic programming language. It has important role in artificial intelligence. Unlike many other programming languages, Prolog is intended primarily as a declarative programming language. In prolog, logic is expressed as relations (called as Facts and Rules). Core heart of prolog lies at the logic being applied. Formulation or Computation is carried out by running a query over these relations. 4 Prolog

What is Prolog? » Prolog or PRO gramming in LOG ics is a logical and declarative programming language. It is one major example of the fifth generation language that supports the declarative programming paradigm. This is particularly suitable for programs that involve symbolic or non- numeric computation. This is the main reason to use Prolog as the programming language in Artificial Intelligence , where symbol manipulation and inference manipulation are the fundamental tasks. » In Prolog, we need not mention the way how one problem can be solved, we just need to mention what the problem is, so that Prolog automatically solves it. However, in Prolog we are supposed to give clues as the solution method. 6

Programming languages are of two kinds: Procedural (BASIC, Fortran, C++, Pascal, Java); Declarative (LISP, Prolog, ML). In procedural programming, we tell the computer how to solve a problem. In declarative programming, we tell the computer what problem we want solved. SWI-Prolog offers a comprehensive free Prolog environment. Since its start in 1987 , SWI-Prolog development has been driven by the needs of real world applications. SWI-Prolog is widely used in research and education as well as commercial applications. Prolog was originally designed to be an AI language, and it is very well suited for expert systems, planning systems and similar AI applications. Logic Programming: Prolog SWI - Prolog The logic programming language PROLOG (Programmation en Logique) was conceived by Alain Colmerauer at the University of Aix-Marseille, France, where the language was first implemented in 1973. PROLOG was further developed by the logician Robert Kowalski, a member of the AI group at the University of Edinburgh.

Rules are extinctions of facts that contain conditional clauses. To satisfy a rule these conditions should be met. Rules And to run a prolog program, we need some questions, and those questions can be answered by the given facts and rules Questions Facts are statements that describe object properties or relations between objects. The fact is predicate that is true, for example, if we say, “Tom is the son of Jack”, then this is a fact. Facts Prolog language basically has three different elements − Facts Rules^ Queries

Prolog Syntax The syntax of Prolog is as follows: relationship(object1,object2)

English Predicate Calculus (^) Prolog If →^ :- Not ~ Not Or V ; and ^ , female, Male, X, Y, mother_of, _father, Pro 34 Variable is a string. The string can be a combination of lower case or upper case letters. The string can also contain underscore characters that begin with an underscore or an upper-case letter. Rules for forming names and predicate calculus are the same. Using the following truth-functional symbols, the Prolog expressions are comprised. These symbols have the same interpretation as in the predicate calculus. Symbols Variables

13 A fact is like a predicate expression. It is used to provide a declarative statement about the problem. In a Prolog expression, when a variable occurs, it is assumed to be universally quantified. Facts are specified in the form of the head. Head is known as the clause head. It will take in the same way as the goal entered at the prompt by the user. Facts cat(momo). / momo is a cat / dog(pulu). / pulu is a dog / likes(arslan, jolie). / Arslan likes Jolie/ not(likes(Jolie, pasta)). /* Jolie does not like pasta / For example:* Queries In Prolog, the query is the action of asking the program about the information which is available within its database. When a Prolog program is loaded, we will get the query prompt, ?- 'It is sunny'. yes ?- ?- 'It is cold'. no ?- no ?- ?- ’momo is cat'. yes ?- ?- ’momo is dog'.

likes(tarzan, jane). likes(jane, tarzan). likes(terk, jane).

facts

Arguments / objects / items .dot is necessary to end the statement relation friends(X,Y):- likes(X,Y), likes(Y,X). Predicate name

head body

variables Horn Clause

Example

elephant(george).

elephant(mary).

elephant(X) :- grey(X), mammal(X), hasTrunk(X).

Procedure for elephant Predicate Clauses

Rule

Facts

?- elephant(george).

yes

?- elephant(jane).

no

Queries

Replies

Queries

Rules

facts

Example 2 : Below student-professor relation table shows the facts, rules, goals and their English meanings. . Facts English meanings studies(charlie, csc135). // charlie studies csc studies(olivia, csc135). // olivia studies csc studies(jack, csc131). // jack studies csc studies(arthur, csc134). likes('John', car(bmw)) // arthur studies csc // Read as : john likes bmw car gives(john, chocolate, jane). // Read as : john gives chocolate to jane Rules professor(X, Y) :- teaches(X, C), studies(Y, C). // X is a professor of Y if X teaches C and Y studies C. Queries / Goals ?- studies(charlie, What). // charlie studies what? OR What does charlie study? ?- professor(kirke, Students). // Who are the students of professor kirke.

19 Lists and Sequence in Prolog In Prolog, the list builder uses brackets[...]. A list is referred by the notation [A | B] in which, A is the first element, and whose tail is B. The following example shows the three definitions, where the first element of the list is refereed by the 'car', the tail of the list is referred by 'cdr', list constructor is referred by the 'cons'. car([A | B], A). cdr([A | B], B). cons[A, B, [A | S]). Where,

  • A is the head(car) of [A | B].
  • B is the tail(car) of [A | B].
  • Put A at the head and B as the tail constructs the list [A | S]. The predicate 'member/ 2 ' definition is described as follows: member(A, [A | S]). member(A, [B | S]) :- member(A, S). The clauses can be read as follows:
  • A is a list member whose first element is A.
  • A is a list member whose tail is S if A is a member of S.

Here are some simple clauses.

The following queries yield the specified answers.

How do you add the following facts?

likes(mary,food).

likes(mary,juice).

likes(john,juice).

likes(john,mary).

| ?- likes(mary,food).

yes.

| ?- likes(john,juice).

yes.

| ?- likes(john,food).

no.

John likes anything that Mary likes

John likes anyone who likes juice

John likes anyone who likes themselves

Example 3 :

Some Applications of Prolog Prolog is used in various domains. It plays a vital role in automation system. Following are some other important fields where Prolog is used − Prolog is used in various domains. It plays a vital role in automation system. Following are some other important fields where Prolog is used −

  • Intelligent Database Retrieval
  • Natural Language Understanding
  • Specification Language
  • Machine Learning
  • Robot Planning
  • Automation System
  • Problem Solving
  • Expert Systems

What is

Prolog used

for

Good at ▪ Grammars and Language processing, ▪ Knowledge representation and reasoning, ▪ Unification, ▪ Pattern matching, ▪ Planning and Search. i.e. Prolog is good at Symbolic AI.