Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”

Similar presentations


Presentation on theme: "Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”"— Presentation transcript:

1 Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”

2 Introduction Logic programming language or declarative programming language Express programs in a form of symbolic logic Use a logical inferencing process to produce results Declarative rather that procedural: – Only specification of results are stated (not detailed procedures for producing them)

3 Copyright © 2006 Addison- Wesley. All rights reserved. 1-3 Applications of Logic Programming Relational database management systems Expert systems Natural language processing

4 Proposition A logical statement that may or may not be true – Consists of objects and relationships of objects to each other – Examples: John is a student : student(john). Hillary is Bill's wife: wife(hillary,bill).

5 Copyright © 2006 Addison- Wesley. All rights reserved. 1-5 Symbolic Logic Logic which can be used for the basic needs of formal logic: – Express propositions – Express relationships between propositions – Describe how new propositions can be inferred from other propositions Particular form of symbolic logic used for logic programming called predicate calculus

6 Copyright © 2006 Addison- Wesley. All rights reserved. 1-6 Object Representation Objects in propositions are represented by simple terms: either constants or variables – Constant: a symbol that represents an object – E.g student(mary)  “mary” is a constant – Variable: a symbol that can represent different objects at different times Different from variables in imperative languages E.g student(X)  “X” is a variable

7 Copyright © 2006 Addison- Wesley. All rights reserved. 1-7 Examples: student(john). like(seth, OSX). like(nick, windows). like(jim, linux). – Functor: function symbol that names the relationship ( e.g. student, like ….) – Ordered list of parameters (tuple) ( e.g. seth, OSX…)

8 Copyright © 2006 Addison- Wesley. All rights reserved. 1-8 Forms of a Proposition Propositions can be stated in two forms: – Fact: proposition is assumed to be true – Query: truth of proposition is to be determined Compound proposition: – Have two or more atomic propositions – Propositions are connected by operators

9 Facts A fact is a predicate expression that makes a declarative statement about the problem domain. Whenever a variable occurs in a Prolog expression, it is assumed to be universally quantified.

10 Rules A rule is a predicate expression that uses logical implication (:-) to describe a relationship among facts. left_hand_side :- right_hand_side. This sentence is interpreted as: left_hand_side if right_hand_side. The left_hand_side is restricted to a single, positive, literal, which means it must consist of a positive atomic expression. It cannot be negated and it cannot contain logical connectives. This notation is known as a Horn clause.

11 Rules Horn clause - can have only two forms – Headed: single atomic proposition on left side E.g likes(bob, trout):-likes(bob,fish),fish(trout). – Headless: empty left side (used to state facts) E.g father(bob, jake).

12 Copyright © 2006 Addison- Wesley. All rights reserved. 1-12 Example Rules ancestor(mary,shelley):- mother(mary,shelley). Can use variables (universal objects) to generalize meaning: parent(X,Y):- mother(X,Y). parent(X,Y):- father(X,Y). grandparent(X,Z):- parent(X,Y), parent(Y,Z). sibling(X,Y):- mother(M,X), mother(M,Y), father(F,X), father(F,Y).

13 Query The Prolog interpreter responds to queries about the facts and rules represented in its database. Whenever you run the Prolog interpreter, it will prompt you with ?-.

14 % ?- likes(sam,dahl). % ?- likes(sam,chop_suey). % ?- likes(sam,pizza). % ?- likes(sam,curry). likes(sam,Food) :- indian(Food), mild(Food). likes(sam,Food) :- chinese(Food). likes(sam,Food) :- italian(Food). indian(curry). indian(dahl). indian(tandoori). indian(kurma). mild(dahl). mild(tandoori). mild(kurma). chinese(chow_mein). chinese(chop_suey). chinese(sweet_and_sour). italian(pizza). italian(spaghetti ).

15 Copyright © 2006 Addison- Wesley. All rights reserved. 1-15 Resolution Unification: finding values for variables in propositions that allows matching process to succeed Instantiation: assigning temporary values to variables to allow unification to succeed After instantiating a variable with a value, if matching fails, may need to backtrack and instantiate with a different value


Download ppt "Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”"

Similar presentations


Ads by Google