1- logic programming with prolog ai.....(a.abeer alshihri)1

14
1 - Logic Programming with Prolog AI.....(A.Abeer Alshihri) 1

Upload: roxanne-fitzgerald

Post on 04-Jan-2016

236 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri)

1 -Logic Programmingwith Prolog

1

Page 2: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri)

Introduction

Logic Programming is the name given to a distinctive style of programming, very different from that of conventional programming languages such as C++ and Java.

Fans of Logic Programming would say that 'different' means clearer, simpler and generally better!

Although there are other Logic Programming languages, by far the most widely used is Prolog…

The name stands for Programming in Logic.

2

Page 3: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

3

There are only two components to any program:

facts and rules.

The Prolog system reads in the program and simply stores it. The user then types in a series of questions (strictly known as queries), which the system answers using the facts and rules available to it.

AI.....(A.Abeer Alshihri)

Page 4: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 4

Used prolog in!..…

Prolog has been used for a wide variety of applications. Many of these are in

Mathematics and Logic . Some examples of the second type of application are ::

• programs for processing a 'natural language' text, to answer questions about its meaning, translate it to another language etc.

• applications for training .• maintaining databases for the Human

Genome project.

Page 5: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 5

Environment of prolog!.…

There are many versions of Prolog available for PC, Macintosh and Unix systems, including versions for Microsoft Windows, to link Prolog to an Oracle relational database and for use with 'object-oriented' program design.

These range from commercial systems with many features to public domain and 'freeware‘ versions. Some of these are listed (in alphabetical order) below, together with web addresses at which more information can be found.

Page 6: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 6

• Amzi! Prologhttp://www.amzi.com/products/prolog_products.htm• B-Prologhttp://www.probp.com/• GNU Prologhttp://gnu-prolog.inria.fr/• SWI Prolog

:// . - . /http www swi prolog org

•Turbo Prolog (an old version that only runs in MS-DOS)

:// . . / / / .http www fraber de university prolog tprolog html

•Visual Prolog:// . - . /http www visual prolog com

Page 7: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 7

SWI prolog SWI-Prolog is an open source implementation of the 

programming language Prolog, commonly used for teaching and semantic web applications. It has a rich set of features, libraries for constraint logic programming ,multithreading, unit testing, GUI, interfacing to Java, ODBC and others..

SWI-Prolog runs on Unix, Windows and Macintosh platforms.

SWI-Prolog has been under continuous development since 1987. Its main author is Jan Wielemaker. The name SWI is derived from Sociaal-Wetenschappelijke Informatica ("Social Science Informatics"), the former name of the group at the University of Amsterdam, where Wielemaker is employed.

Page 8: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 8

Page 9: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 9

SWI-Prolog's website has lots of information about SWI-

Prolog, a download area, and documentation. The upkeep for SWI-Prolog is excellent.

The link ...http://www.swi-prolog.org/

Page 10: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 10

Simple example..

This is a simple example, a series of queries and answers about animals. ..

dog(fido).dog(rover).dog(henry).cat(felix).cat(michael).cat(jane).animal(X):-dog(X).

Page 11: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 11

queries?- dog(fido).yes?-dog(jane).No [Is jane a dog? No - a cat]?- animal(fido).Yes [Is fido an animal?] [yes - because it is a dog and any dog is an

animal]?- dog(X).X = fido ;X = rover ;X = henry [Is it possible to find anything, let us call it X, that is

a dog?] [All 3 possible answers are

provided]?-animal(felix).No [felix is a cat and so does not qualify as an animal ,as

far as the program is concerned]

Page 12: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 12

You have now seen all three elements needed for logic

programming in Prolog:facts, rules and queries.

There are no others. Everything else is built from them .

Page 13: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 13

Starting SWI-PrologUnder Windows, SWI-Prolog installs a start

icon that can be double-clicked to initiate the interpreter. The interpreter then starts in its own command window.

Interactive goals in Prolog are entered by the user following the '?- ' prompt.

Many Prologs have command-line help information. SWI Prolog has extensive help information. This help is indexed and guides the user. To learn more about it, try

?- help(help)

Page 14: 1- Logic Programming with Prolog AI.....(A.Abeer Alshihri)1

AI.....(A.Abeer Alshihri) 14

abeeralshihri.weebly.com