This action might not be possible to undo. Are you sure you want to continue?

CONTENTS

INTRODUCTION INFERENCE SYSTEM P.L RESOLUTION PRINCIPLE & THEOREM PROVING PROLOG FUNDAMENTAL TIC-TAC-TOE CONCLUSION

Introduction

Realization of “in Knowledge lies the Power”.

Inference

Inference :- The process of deriving a new fact using some rule (from given or previously derived facts).

Valid Inference If Socrates is a Greek then Socrates is a mortal. Socrates is a Greek.

Infer

Socrates is mortal.

Invalid inference

If Rose is a Pig then Rose can fly. Rose is a Pig.

Infer

Rose can fly.

Garbage In Garbage Out

Some basic Concept

Proposition Logic

Predicate logic

Programming in Logic

Proposition

Proposition may be true or false. It is raining. My car is painted silver. John & Sue have five children. Snow is white.

Symbol use for Proposition logic

~ & V

not/negation and/conjunction or/disjunction If….then/implication If and only if / double implication

Symbol use for Proposition logic

If it is raining, then it is not sunny.

RAINING ~SUNNY

Symbol use for Proposition logic

Socrates is a man

SOCRATESMAN

Symbol use for Proposition logic

Plato is a man

PLATOMAN

Symbol use for Proposition logic

Socrates is a man

Plato is a man

SOCRATESMAN

PLATOMAN

We would not be able to draw any conclusions about similarity between SOCRATES and PLATO

Predicate Logic

Socrates is a man

Plato is a man

MAN (SOCRATES)

MAN (PLATO)

Now the structure of the representation reflects the structure of knowledge itself.

1. 2. 3. 4. 5. 6. 7.

Rabindranath was a Poet. Rabindranath wrote Gitanjali. Rabindranath was a man. Rabindranath was born in 1861. All man are mortal. No mortal lives more than 110 years. It is now 2005.

Is Rabindranath alive ?

10. Rabindranath is dead

3. Rabindranath was a man. 8. Rabindranath is mortal 5. All man are mortal.

4. Rabindranath was born in 1861. 9. Rabindranath’s age is 144 years 7. It is now 2005.

6. No mortal lives longer than 110 years.

**Representing the fact in predicate logic
**

Rabindranath was a Poet : poet(Rabindranath). Rabindranath wrote Gitanjali: wrote(Rabindranath,Gitanjali). Rabindranath was a man: man(Rabindranath). Rabindranath was born in 1861: born(Rabindranath,1861). All man are mortal: ∀x: man(x) mortal(x). No mortal lives more than 110 years: It is now 2005.

∀x:∀t1:∀t2: mortal(x) Λ born(x,t1) Λ gt(t2-t1,110) dead(x,t2). now=2005 ∀x:∀t: [ alive(x,t)~dead(x,t) ] Λ [ ~dead(x,t) alive(x,t) ]. ∀x:∀t1:∀t2: died(x,t1) Λ gt(t2,t1) dead(x,t2).

Alive means not dead:

If some one dies, then he is dead at all later times.

Convert to clause form

1. man(Rabindranath).

1. man(Rabindranath).

Convert to clause form

2. born(Rabindranath,1861).

2. born(Rabindranath,1861).

Convert to clause form

3. ∀x: man(x) mortal(x).

3. ~man(x1) v mortal(x1).

AB is equivalent to ~A v B.

Convert to clause form

4. ∀x:∀t1:∀t2: mortal(x) Λ born(x,t1) Λ gt(t2-t1,110) dead(x,t2).

4. ~mortal(x2) v ~born(x2,t1) v ~gt(t2-t1,110) v dead(x2,t2).

AB is equivalent to ~A v B. ~(A Λ B) is equivalent to ~A V ~B.

Convert to clause form

5. now=2005

5. now=2005

Convert to clause form

6. ∀x:∀t: [ alive(x,t)~dead(x,t) ] Λ [ ~dead(x,t) alive(x,t) ].

6. ~alive(x3,t3) v ~dead(x3,t3)

7. alive(x4,t4) v dead(x4,t4)

AB is equivalent to ~A v B. ~(~A ) is equivalent to A.

Convert to clause form

5. ∀x:∀t1:∀t2: died(x,t1) Λ gt(t2,t1) dead(x,t2).

8. ~dead(x5,t5) v ~gt(t6,t5) v dead(x5,t6)

AB is equivalent to ~A v B. ~(A Λ B) is equivalent to ~A V ~B.

Resolution Principle

The resolution procedure is a simple iterative process: at each step, two clauses, called the parent clauses, are compared(resolved), yielding a new clause that has been inferred from them.

Winter V Summer

resolve

~Winter V cold

Summer V Cold

Resolution Principle

If the clause that is produced is the empty clause then a contradiction has been found. If a contradiction exists, then eventually it will be found. If no contradiction exists, it is possible that the procedure will never terminate.

Winter

resolve

~Winter

[]

Theorem proving using Resolution Principle

1. man(Rabindranath). 2. born(Rabindranath,1861). 3. ~man(x1) v mortal(x1). 4. ~mortal(x2) v ~born(x2,t1) v ~gt(t2-t1,110) v dead(x2,t2). 5. now=2005. 6. ~alive(x3,t3) v ~dead(x3,t3). 7. alive(x4,t4) v dead(x4,t4).

Suppose alive(Rabindranath,now).

Theorem proving using Resolution Principle

1. man(Rabindranath). 2. born(Rabindranath,1861). 3. ~man(x1) v mortal(x1). 4. ~mortal(x2) v ~born(x2,t1) v ~gt(t2-t1,110) v dead(x2,t2). 5. now=2005. 6. (x3=Rabindranath,t3=now) ~dead(Rabindranath,now). 7. alive(x4,t4) v dead(x4,t4).

)

Theorem proving using Resolution Principle

1. man(Rabindranath). 2. born(Rabindranath,1861). 3. ~man(x1) v mortal(x1). 4,6. ~mortal(Rabindranath) v ~born(Rabindranath,t1) v ~gt(now-t1,110) 5. now=2005. 7. alive(x4,t4) v dead(x4,t4).

(x2=Rabindranath,t2=now)

Theorem proving using Resolution Principle

**1. man(Rabindranath). 2. born(Rabindranath,1861). 3. ~man(x1) v mortal(x1).
**

5,4,6. ~mortal(Rabindranath) v ~born(Rabindranath,t1) v ~gt(2005-t1,110) (x2=Rabindranath,t2=2005)

7. alive(x4,t4) v dead(x4,t4).

,t6)

Theorem proving using Resolution Principle

1. man(Rabindranath). 2. born(Rabindranath,1861). 3,5,4,6. ~man(Rabindranath) v v ~born(Rabindranath,t1) v ~gt(2005-t1,110)

Theorem proving using Resolution Principle

**1. man(Rabindranath). t1=1861. t2-t1=2005-1861=144 2,3,5,4,6. ~man(x1) v ~gt(144,110) ,t6)
**

gt(144,110)

Theorem proving using Resolution Principle

**1. man(Rabindranath). 2,3,5,4,6. ~man(x1).
**

Theorem proving using Resolution Principle

1,2,3,5,6.

[ ].

t6)

Empty clause represent ~alive(Rabindranath,now)

Fundamental Of PROLOG

PROLG Consists of :

Declaring some facts Defining some rules Asking question

In Prolog the two goals would be written as a conjunction like this:

?- likes(mary,X),likes(john,X).

?-

likes(mary,X)

food

,

likes(john,X).

food likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary).

1. The first goal succeeds, instantiating X to food. 2. Next, attempt to satisfy the second goal. CDAC Kolkata

?-

likes(mary,X)

food

,

likes(john,X).

food likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary).

1. The second goal fails. 2. Next, backtrack: forget the previous X, and attempt to re-satisfy the first goal. CDAC Kolkata

?-

likes(mary,X)

wine

,

likes(john,X).

wine likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary).

1. The first goal succeeds again, instantiating X to wine. 2. Next, attempt to satisfy the second goal. CDAC Kolkata

?-

likes(mary,X)

wine

,

likes(john,X).

wine likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary).

1. The second goal succeeds. 2. Prolog notifies you of success, and waits for a reply. CDAC Kolkata

**A rule is a general statement about objects and their relationships sister_of(X,Y) :- female(X), parents(X,M,F), parents(Y,M,F).
**

Head Body if

male(raj). male(rabi). female(rani). female(ritu). parent(rabi,raj,rani). /* the parent of rabi are raj and rani */ parent(ritu,raj,rani). /* the parent of ritu are raj and rani */ /* father : raj mother : rani son : rabi daughter:ritu */ /* condition : ritu is sister of rabi if 1) ritu is female 2) ritu has the same mother and father as rabi does */ sister_of(X,Y):female(X), male(Y), parent(X,M,F), parent(Y,M,F).

change(you,i). change(are,[am,not]). change(french,german). change(do,no). change(X,X). alter([],[]). alter([H|T],[X|Y]) :change(H,X),alter(T,Y).

**?-alter([you,are,a,computer],Z).
**

H=[you] and T=[are,a,computer]. change(you,X) X=“i”. alter([are,a,computer],Y). change “are” to [am,not]. alter([a,computer],Y). Change “a” to “a” change(X,X). change(computer,X) again

change(you,i). change(are,[am,not]). change(french,german). change(do,no). change(X,X).

change(X,X) thus Z=[i,[am,not],a,computer].

alter([],[]). match alter([H|T],[X|Y]) :change(H,X),alter(T,Y).

•

• • • • •

grade(N,first) :- N>=70. grade(N,two_1) :- N<70, N>=63. grade(N,two_2) :- N<63, N>=55. grade(N,third) :- N<55, N>=50. grade(N,pass) :- N<50, N>=40. grade(N,fail) :- N<40.

• • • • • • • • • • • • • • • • •

If we were implementing this in C, we might try using a "switch" statement as follows: // This code is a little artificial for the purpose of comparison int int // int fir(int n) { return n>=70; } fir(int n) { return n<70 && n>=63; } ... fill in the rest ... fai(int n) { return n<40; }

switch(n) { case(fir(n)): printf(“1st”); break; case(tw1(n)): printf(“2.1”); break; case(tw2(n)): printf(“2.2”); break; case(thi(n)): printf(“third”); break; case(pas(n)): printf(“pass”); break; case(fai(n)): printf(“fail”); } Here we explicitly indicate that after one result has been accepted, we need not look at any of the others at all - this is the purpose of the "break" statement in each branch.

•

To eliminate useless backtracking from the above, (and taking advantage of Prolog's order of execution) we can rephrase the program as:

•

• • • • •

grade(N,first) :- N>=70, ! . grade(N,two_1) :- N>=63, ! . grade(N,two_2) :- N>=55, ! . grade(N,third) :- N>=50, ! . grade(N,pass) :- N>=40, ! . grade(N,fail) :- N<40.

**Tic-Tac-Toe
**

Input G.T.K+ File Output Main Main Processing Process Input

Prolog

User Input G.U.I.

Output

1 PROLOG

5 PROLOG

3x3 grid Two players: - X (Computer) - O (Human) Fact x(n) indicates a movement by X - E.g. x(5),x(9). Fact o(n) indicates a movement by O - E.g. o(1),o(6).

At a glance

We Know about Inference system. Proposition & predicate logic Resolution Principle. Logic programming : Prolog Backtracking, unification, recursion How prolog can be written with other language.

REFERENCE

Programming in Prolog, W.F.Clocksin C.S. Mellish, third, revised and Extended edition.

http://cs.www.edu/~cs_dept/KU/PR/Prolog.html http://www.mta.ca/~rrosebru/oldcourse/371199/prolog http://gnu-prolog.inria.fr/ http://www.compapp.dcu.ie/~alex/LOGIC/arith.html http://en.wikibooks.org/wiki/Programming:Prolog_Rules

Sign up to vote on this title

UsefulNot useful- Prolog
- Tutorial Prolog
- Prolog Program 3
- Intro to prolog programing
- Prolog
- Introduction Prolog
- Turbo Prolog Owners Handbook
- Prolog Programming
- Lab 1 Introduction to PROLOG
- 99 prolog problems
- Ppl Prolog
- prolog programs
- 5 Simple Prolog Programs
- AI-FINAL
- Artificial Intelligence by Rich and Knight
- AutoLisp
- Prolog - Probleme
- Prolog Env
- Prolog
- Prolog Notes
- 30277062 Lab 3 N Queens Problem in Prolog
- الكميوتر من البداية إلي الإحتراف
- Auto Lips
- Prolog
- Prolog
- Lisp Book
- PLVol2
- Chapter1
- AI_Lab_2
- Prolog

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.