Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.

Slides:



Advertisements
Similar presentations
The Foundations: Logic and Proofs
Advertisements

1. An Overview of Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Predicates and Quantifiers
Bahar Pamuk. Outline Introduction Syntaxa Clauses, Programs and Queries List Manipulation Operators Backtracking, Cuts References.
Declarative Programming Autumn 2014 Basic syntax and sample programs.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
Declarative Languages. Declarative languages In an imperative programming language, a program specifies how to solve a problem In a declarative language,
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 2 Theory –Unification –Unification in Prolog –Proof search Exercises –Correction exercises.
CHA2555 Week2: Knowledge Representation, Logic and Prolog Lee McCluskey First term:
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
1 About Prolog Lu Han Written at Modified at
DEDUCTIVE DATABASE.
PROLOG KAIST Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.
Formal Models of Computation Part II The Logic Model
1 Prolog I. 2 Syllogisms “Prolog” is all about programming in logic. –Socrates is a man. –All men are mortal. –Therefore, Socrates is mortal.
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
F28PL1 Programming Languages Lecture 16: Prolog 1.
1.  Provides the ability to access individual assertions. e.g. in Predicate calculus we may say: P denotes “It rained on Tuesday” but in predicate calculus.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
CIS2326 Week2: Logic and Prolog Lee McCluskey First term:
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Programming Languages Tucker and Noonan – 2e Chapter 15 – Part 1 Logic Programming “Q: How many legs does a dog have if you call its tail a leg? A: Four.
CS 603: Programming Languages Lecture 25 Spring 2004 Department of Computer Science University of Alabama Joel Jones.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
Rules Statements about objects and their relationships Expess ◦ If-then conditions  I use an umbrella if there is a rain  use(i, umbrella) :- occur(rain).
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
1 Lecture 6 Logic Programming rule-based programming with Prolog Ras Bodik with Mangpo, Ali Hack Your Language! CS164: Introduction to Programming Languages.
Knowledge Based Information System
Artificial Intelligence CS370D
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Lecture 041 Predicate Calculus Learning outcomes Students are able to: 1. Evaluate predicate 2. Translate predicate into human language and vice versa.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
Section 16.5, 16.6 plus other references
A Conjunction is a logical operator that connects two logical terms.
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Tests, Backtracking, and Recursion
3.5 Programming paradigms
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Prolog programming Introduction to Prolog (part3)
Chapter 3: Prolog (Lists, Arithmetic, Operators)
Introduction to Prolog
Programming Languages 2nd edition Tucker and Noonan
Predicate Logic: Syntax.
Predicate Logic.
Chapter 2: Prolog (Introduction and Basic Concepts)
The Foundations: Logic and Proofs
Representations & Reasoning Systems (RRS) (2.2)
PROLOG.
Presentation transcript:

Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI

Presentation from Logic Programing By Dr. Mohamed Hamed

What is Prolog? Prolog (programming in logic) is a logical programming language: programs correspond to sets of logical formulas and the Prolog interpreter uses logical methods to resolve queries. Prolog is a declarative language: you specify what problem you want to solve rather than how to solve it. Prolog is very useful in some problem areas, like artificial intelligence, natural language processing, databases,..., but pretty useless in others, like graphics or numerical algorithms.

Facts A little Prolog program consisting of four facts: bigger( elephant, horse). bigger( horse, donkey). bigger ( donkey, dog). bigger ( donkey, monkey).

Queries After compilation we can query the Prolog system: ?- bigger ( donkey, dog). Yes ?- bigger( monkey, elephant). No

Problem The following query does not succeed! ?- bigger( elephant, monkey). – No The predicate bigger/2 apparently is not quite what we want. What we'd really like is the transitive closure of bigger/2. In other words: a predicate that succeeds whenever it is possible to go from the first animal to the second by iterating the previously defined facts.

Rules The following two rules define is_bigger/2 as the transitive closure of bigger/2 (via recursion): is-bigger( X, Y) :- bigger( X, Y). is-bigger( X, Y) :- bigger ( X, Z), is-bigger( Z, Y).

Now it works ?- is-bigger ( elephant, monkey). Yes Even better, we can use the variable X: ?- is-bigger( X, donkey). X = horse ;

Fact 2 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody).

Query After compilation we can query the Prolog system: ?- woman(mia). –Prolog will answer –Yes ?- playsAirGuitar(mia). –We will get the answer –no

Fact and Query loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin). jealous(X,Y) :- loves(X,Z),loves(Y,Z). ?- jealous(marcellus,W).

TERMS/Syntax Prolog terms are either numbers, atoms, variables, or compound terms. Atoms start with a lowercase letter or are enclosed in single quotes: – elephant, xYZ, a-123, 'Another pint please‘ Variables start with a capital letter or the underscore: –X, Elephant, _G177, Myvariable, _

TERMS Compound/Complex terms have a functor (an atom) and a number of arguments (terms) : –is-bigger( horse, X), f( g( Alpha, _), 7), 'My Functor'(dog) Atoms and numbers are called atomic terms. Atoms and compound terms are called predicates. Terms without variables are called ground terms.

Facts and Rules Facts are predicates followed by a dot. Facts are used to define something as being unconditionally true. bigger( elephant, horse). parent ( john, mary). Rules consist of a head and a body separated by :-. The head of a rule is true if all predicates in the body can be proved to be true. grandfather( X, Y) :- father( X, Z), parent ( Z, Y).

Programs and Queries Programs. Facts and rules are called clauses. A Prolog program is a list of clauses. Queries are predicates (or sequences of predicates) followed by a dot. They are typed in at the Prolog prompt and cause the system to reply. ?- is-bigger ( horse, X), is-bigger( X, dog). X = donkey Yes

Built-in Predicates Compiling a program file: ?- consult( 'big-animals.pl'). Yes Writing terms on the screen: ?- write( 'Hello World! '), nl. Hello World! Yes

Matching Two terms match if they are either identical or if they can be made identical by substituting their variables with suitable ground terms. We can explicitly ask Prolog whether two given terms match by using the equality-predicate = (written as an infix operator). ?- born( mary, yorkshire) = born( mary, X). X = yorkshire Yes The variable instantiations are reported in Prolog's answer.

MATCHING ?- f ( a, g( X, Y)) = f ( X, Z), Z = g( W, h( X)). X = a Y = h(a) Z = g(a, h(a)) W = a – Yes p(X,2,2) = p(1,Y,X). – No kill(shoot(gun),Y) = kill(X,stab(knife)). –X = shoot(gun) –Y = stab(knife) –Yes father(X) = X.

Answering Queries Answering a query means proving that the goal represented by that query can be satisfied (according to the programs currently in memory). Recall: Programs are lists of facts and rules. A fact declares something as being true. A rule states conditions for a statement being true.

Answering Queries If a goal matches with a fact, it is satisfied. If a goal matches the head of a rule, then it is satisfied if the goal represented by the rule's body is satisfied. If a goal consists of several subgoals separated by commas,then it is satisfied if all its subgoals are satisfied. When trying to satisfy goals with built-in predicates like write/l Prolog also performs the associated action (e.g.writing on the screen).

Example: Mortal Philosophers Consider the following argument: All men are mortal. Socrates is a man. ______________________ Hence, Socrates is mortal. It has two premises and a conclusion

Translating it into Prolog The two premises can be expressed as a little Prolog program: mortal(X) :- man(X). man (socrates). The conclusion can then be formulated as a query: ?- mortal(socrates). Yes

Goal execution The query mortal ( socrates) is made the initial goal. Prolog looks for the first matching fact or head of rule and finds mortal ( X). Variable instantiation: X = socrates. This variable instantiation is extended to the rule's body, i.e. man( X) becomes man( socrates). New goal: man( socrates). Success, because man( socrates) is a fact itself. Therefore, also the initial goal succeeds.