24
Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson . 1

Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

Embed Size (px)

Citation preview

Page 1: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

1

Logic programming

( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson .

Page 2: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

2

Gnu prolog program

http://gnu-prolog.soft112.com/download.html

Page 3: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

3

Instruction

• You should print slides before classes.• You will be Assessment like this:• 40% on exams• 10% attendant and activity during class.• 10% activity file and assignment.• Your file will be assessment with second exam.• Zero mark for absent student on exams.

Page 4: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

4

Objective:

• The aim of this course is to present the key concepts behind logic programming

• let you know about one of logic programming languages(prolog).

• how to write programs with logic.• how to make efficient implementations

(Queries).

Page 5: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

5

Logic..

• Logic– is the study of the logic relationships between objects and – forms the basis of all mathematical reasoning and all

automated reasoning• Propositional Logic (PL) • In Propositional Logic, the objects are called propositions• Definition: A proposition is a statement that is either

true or false, but not both• We usually denote a proposition by a letter: p, q, r, s, …

Page 6: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

6

Propositions: Examples

• The following are propositions– Today is Monday M– The grass is wet W– It is raining R

• The following are not propositions– C++ is the best language– What is your name?– Do your homework

Page 7: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

7

Are these propositions?

• 2+2=5• Every integer is divisible by 12• Microsoft is an excellent company

Page 8: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

8

Logical connectives• Connectives are used to create a compound

proposition from two or more propositions– Negation (e.g., a or !a or ā) $\neg$, $\bar$– And or logical conjunction (denoted ) $\wedge$– OR or logical disjunction (denoted ) $\vee$– XOR or exclusive or (denoted ) $\oplus$– Impli ion (denoted or )

$\Rightarrow$, $\rightarrow$ – Biconditional (denoted or )

$\LeftRightarrow$, $\leftrightarrow$• We define the meaning (semantics) of the logical

connectives using truth tables

Page 9: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

9

Logical Arguments

• Consider the following statements.1. if you study then you succeed2. you study3. you succeed

• These three statements create a logical argument.• Lines 1 and 2 are premises and line 3 is the conclusion.• This logical argument is sound.– Premises can be true or false.– If the premises are true, the conclusion must be true.– If one (or more than one) of the premises is false, the

argument is still sound, but we don’t know whether the conclusion is true or false.

Page 10: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

10

Page 11: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

11

Rule of inference

Page 12: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

12

Modus Ponens

if you study then you succeedyou studyyou succeed

Aristotle called this modus ponens:

if P then QP

Q

PremisesConclusion

(a rule of inference – one of the most important rules)

Page 13: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

13

Important!

• We are dealing with the validity of an argument, NOT with the validity of the result!

• In logic, it doesn’t matter if a logical statement makes sense or not.

• What does matter is that if the premises are correct, then so is the result.

Page 14: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

14

Modus Ponens Examples

• P: I study hardQ: I get an A

• P: cows give milkQ: doors open

Makes sense

Doesn’t make sense

if P then QP

Q

Page 15: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

15

if thinks(‘Jill’) then exists(‘Jill’)thinks(‘Jill’)exists(‘Jill’)

if P(‘Jill’) then Q(‘Jill’)P(‘Jill’)Q(‘Jill’)

Predicates and Arguments

if ‘Jill’ thinks then ‘Jill’ exists‘Jill’ thinks‘Jill’ exists

if thinks(X) then exists(X)thinks(X)exists(X)

Page 16: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

16

Predicates in arguments (continued…)

thinks(X) exists(X)thinks(X)exists(X)

thinks(X) -: exists(X)thinks(X)exists(X)

if thinks(X) then exists(X)thinks(X)exists(X)

Page 17: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

17

Page 18: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

18

Page 19: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

19

Page 20: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

20

Page 21: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

21

Page 22: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

22

Page 23: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

23

Page 24: Logic programming ( Handbook of Logic in Artificial Intelligence, Vol) by D. M. Gabbay, C. Hogger, J.A. Robinson. 1

24