Logic and Knowledge Representation P r o g r a m m i n g - - PowerPoint PPT Presentation

logic and knowledge representation
SMART_READER_LITE
LIVE PREVIEW

Logic and Knowledge Representation P r o g r a m m i n g - - PowerPoint PPT Presentation

Logic and Knowledge Representation P r o g r a m m i n g a s p r o b l e m - s o l v i n g , F i r s t s t e p s i n P r o l o g 2 0 A p r i l 2 0 1 8 g s i l e n o @e n s t . f


slide-1
SLIDE 1

Logic and Knowledge Representation

G i

  • v

a n n i S i l e n

  • g

s i l e n

  • @e

n s t . f r

T é l é c

  • m

P a r i s T e c h , P a r i s

  • D

a u p h i n e U n i v e r s i t y

P r

  • g

r a m m i n g a s p r

  • b

l e m

  • s
  • l

v i n g , F i r s t s t e p s i n P r

  • l
  • g

2 A p r i l 2 1 8

slide-2
SLIDE 2

Logic and Knowledge Representation

T h i s c

  • u

r s e i s a n i n t r

  • d

u c t i

  • n

t

  • s

y m b

  • l

i c t e c h n i q u e s i n A r t i fj c i a l I n t e l l i g e n c e ( A I ) , f

  • l

l

  • w

i n g a n h

  • m
  • n

y m c

  • u

r s e h e l d b y J e a n

  • L
  • u

i s D e s s a l l e s . T h e c

  • u

r s e w e b s i t e : h t t p : / / a i c

  • u

r s e . r 2 . e n s t . f r : 4 2 4 2 / S C I A F r

  • n

t a l t e a c h e r : G i

  • v

a n n i S i l e n

  • ,

g s i l e n

  • @e

n s t . f r D

  • n
  • t

h e s i t a t e t

  • w

r i t e m e

  • r

a s k q u e s t i

  • n

s i n c l a s s !

slide-3
SLIDE 3

Logic and Knowledge Representation

B e i n g a n e w c

  • u

r s e , w e w i l l p l a u s i b l y t w e a k

  • n

t h e fm y t h e c

  • n

t e n t , t h e e x e r c i s e s , a n d t h e w

  • r

k l

  • a

d . I n p r i n c i p l e , y

  • u

r g r a d e w i l l b e a w e i g h t e d a v e r a g e

  • f

:

  • w

e e k l y e x e r c i s e s p r

  • p
  • s

e d

  • n

t h e c

  • u

r s e w e b p a g e s

  • a

fj n a l e x a m

  • a

p r

  • g

r a m m i n g p r

  • j

e c t

slide-4
SLIDE 4

“Mechanical” computing

slide-5
SLIDE 5

Pascal: Pascaline ~ 1650

Blaise Pascal H e l p i n g h i s f a t h e r ( t a x a c c

  • u

n t a n t

  • f

N

  • r

m a n d y , a p p

  • i

n t e d b y R i c h e l i e u ) , P a s c a l i n v e n t e d a m a c h i n e f

  • r

m e c h a n i c c a l c u l a t i

  • n

, p e r f

  • r

m i n g a d d i t i

  • n

a n d s u b t r a c t i

  • n

.

slide-6
SLIDE 6

Schickard: Calculating Clock ~1625

Wilhelm Schickard B e f

  • r

e h i m , S c h i c k a r d h a d a l r e a d y i n v e n t e d a n “ a r t i t h m e t i c i n s t r u m e n t ” , b u t u n f

  • r

t u n a t e l y h e w a s n

  • t

a b l e t

  • p

u b l i c l y p r e s e n t a f u l l w

  • r

k i n g c

  • p

y .

slide-7
SLIDE 7

Leibniz: Stepped Reckoner ~1680

Gottfried Wilhelm von Leibniz I n fm u e n c e d b y t h e P a s c a l i n e , L e i b n i z p r

  • p
  • s

e d a m e c h a n i c c a l c u l a t

  • r

p e r f

  • r

m i n g a l l f

  • u

r

  • p

e r a t i

  • n

s : a d d i t i

  • n

, s u b t r a c t i

  • n

, m u l t i p l i c a t i

  • n

a n d d i v i s i

  • n

.

slide-8
SLIDE 8

Leibniz: Calculemus! ~1686

Gottfried Wilhelm von Leibniz F u r t h e r m

  • r

e , L e i b n i z b e l i e v e d t h a t c a l c u l a t i

  • n

w

  • u

l d b e t h e k e y t

  • s

e t t l e a l l h u m a n c

  • n

fm i c t s a n d d i s a g r e e m e n t s . . . → c h a r a c t e r i s t i c s n u m b e r s i n s t e a d

  • f

c

  • n

c e p t s .

slide-9
SLIDE 9

Leibniz: Calculemus! ~1686

Gottfried Wilhelm von Leibniz F u r t h e r m

  • r

e , L e i b n i z b e l i e v e d t h a t c a l c u l a t i

  • n

w

  • u

l d b e t h e k e y t

  • s

e t t l e a l l h u m a n c

  • n

fm i c t s a n d d i s a g r e e m e n t s . . . → c h a r a c t e r i s t i c s n u m b e r s i n s t e a d

  • f

c

  • n

c e p t s . a n i m a l = 2 r a t i

  • n

a l = 3 m a n = r a t i

  • n

a l a n i m a l = 2 * 3 = 6

slide-10
SLIDE 10

Leibniz: Calculemus! ~1686

Gottfried Wilhelm von Leibniz F u r t h e r m

  • r

e , L e i b n i z b e l i e v e d t h a t c a l c u l a t i

  • n

w

  • u

l d b e t h e k e y t

  • s

e t t l e a l l h u m a n c

  • n

fm i c t s a n d d i s a g r e e m e n t s . . . → c h a r a c t e r i s t i c s n u m b e r s i n s t e a d

  • f

c

  • n

c e p t s . a n i m a l = 2 r a t i

  • n

a l = 3 m a n = r a t i

  • n

a l a n i m a l = 2 * 3 = 6 I s e v e r y m a n r a t i

  • n

a l ? Y e s , b e c a u s e 6 i s d i v i s i b l e b y 3 .

slide-11
SLIDE 11

Machines as symbol handlers

S t a r t i n g f r

  • m

t h e P a s c a l i n e , c

  • m

p u t i n g m a c h i n e s r e s p

  • n

d t

  • t

h e n e e d t

  • d

i s p l a c e t e d i

  • u

s , r e p e t i t i v e ( s y m b

  • l

i c ) w

  • r

k .

slide-12
SLIDE 12

A p h y s i c a l s y m b

  • l

s y s t e m h a s t h e n e c e s s a r y a n d s u ffj c i e n t m e a n s f

  • r

g e n e r a l i n t e l l i g e n t a c t i

  • n

A l l e n N e w e l l a n d H e r b e r t A . S i m

  • n

C

  • m

p u t e r S c i e n c e a s E m p i r i c a l I n q u i r y : S y m b

  • l

s a n d S e a r c h ( 1 9 7 6 )

slide-13
SLIDE 13

A p h y s i c a l s y m b

  • l

s y s t e m h a s t h e n e c e s s a r y a n d s u ffj c i e n t m e a n s f

  • r

g e n e r a l i n t e l l i g e n t a c t i

  • n

A l l e n N e w e l l a n d H e r b e r t A . S i m

  • n

C

  • m

p u t e r S c i e n c e a s E m p i r i c a l I n q u i r y : S y m b

  • l

s a n d S e a r c h ( 1 9 7 6 )

. . . b a s i s f

  • r

G

  • d

O l d F a s h i

  • n

e d A I ( G O F A I )

slide-14
SLIDE 14

Machines as symbol handlers

S t a r t i n g f r

  • m

t h e P a s c a l i n e , c

  • m

p u t i n g m a c h i n e s r e s p

  • n

d t

  • t

h e n e e d t

  • d

i s p l a c e t e d i

  • u

s , r e p e t i t i v e ( s y m b

  • l

i c ) w

  • r

k . b u t h

  • w

t

  • s

a y t

  • t

h e m a c h i n e w h a t t

  • d
  • ?
slide-15
SLIDE 15
slide-16
SLIDE 16

Machine code/instructions

R e l a t e d t

  • t

h e p h y s i c a l s t r u c t u r e

  • f

t h e c

  • m

p u t e r . + p

  • w

e f u l a n d f a s t

  • l
  • n

g p r

  • g

r a m s

  • d

i ffj c u l t t

  • b

e w r i t t e n

  • d

i ffj c u l t t

  • b

e r e v i s e d

slide-17
SLIDE 17

Natural (human) language

I t i s t h e l a n g u a g e w e u s e i n a l l

  • u

r c

  • m

m u n i c a t i

  • n

s , l e a r n e d s i n c e

  • u

r c h i l d h

  • d

. + E x p r e s s i v e l y r i c h .

  • A

m b i g u

  • u

s , r e d u n d a n t .

slide-18
SLIDE 18

Programming languages

A p r

  • g

r a m m i n g l a n g u a g e i s a l a n g u a g e w h i c h i s i n t e r m e d i a r y b e t w e e n m a c h i n e c

  • d

e a n d n a t u r a l l a n g u a g e .

slide-19
SLIDE 19

Programming languages

V a n R

  • y

2 9 , We i n b e r g 1 9 7 7

slide-20
SLIDE 20

Programming languages

A p r

  • g

r a m m i n g l a n g u a g e i s a l a n g u a g e w h i c h i s i n t e r m e d i a r y b e t w e e n m a c h i n e l a n g u a g e a n d n a t u r a l l a n g u a g e .

– B

u t w h a t w e h a v e t

  • t

e l l t

  • t

h e m a c h i n e ?

slide-21
SLIDE 21

Programming as problem-solving

slide-22
SLIDE 22

Problem solving terms

  • A

w e l l

  • d

e fj n e d p r

  • b

l e m i s u s u a l l y d e fj n e d i n t e r m s

  • f
  • a

n i n i t i a l s t a t e

  • r

s i t u a t i

  • n
  • a

g

  • a

l s t a t e , i . e . a d e s i r e d

  • u

t c

  • m

e ,

  • c

e r t a i n r e s

  • u

r c e s ( w h i c h p u t c

  • n

t r a i n t s

  • n

t h e p

  • s

s i b l e p a t h s t

  • w

a r d s t h e g

  • a

l ) .

slide-23
SLIDE 23

An ancient puzzle ~ 9th century

  • O

n c e u p

  • n

a t i m e a f a r m e r w e n t t

  • m

a r k e t a n d p u r c h a s e d a f

  • x

, a g

  • s

e , a n d a b a g

  • f

b e a n s . O n h i s w a y h

  • m

e , t h e f a r m e r c a m e t

  • t

h e b a n k

  • f

a r i v e r . I n c r

  • s

s i n g t h e r i v e r b y b

  • a

t , t h e f a r m e r c

  • u

l d c a r r y

  • n

l y h i m s e l f a n d a s i n g l e

  • n

e

  • f

h i s p u r c h a s e s

  • t

h e f

  • x

, t h e g

  • s

e ,

  • r

t h e b a g

  • f

t h e b e a n s .

slide-24
SLIDE 24

An ancient puzzle ~ 9th century

  • O

n c e u p

  • n

a t i m e a f a r m e r w e n t t

  • m

a r k e t a n d p u r c h a s e d a f

  • x

, a g

  • s

e , a n d a b a g

  • f

b e a n s . O n h i s w a y h

  • m

e , t h e f a r m e r c a m e t

  • t

h e b a n k

  • f

a r i v e r . I n c r

  • s

s i n g t h e r i v e r b y b

  • a

t , t h e f a r m e r c

  • u

l d c a r r y

  • n

l y h i m s e l f a n d a s i n g l e

  • n

e

  • f

h i s p u r c h a s e s

  • t

h e f

  • x

, t h e g

  • s

e ,

  • r

t h e b a g

  • f

t h e b e a n s .

slide-25
SLIDE 25

An ancient puzzle ~ 9th century

  • O

n c e u p

  • n

a t i m e a f a r m e r w e n t t

  • m

a r k e t a n d p u r c h a s e d a f

  • x

, a g

  • s

e , a n d a b a g

  • f

b e a n s . O n h i s w a y h

  • m

e , t h e f a r m e r c a m e t

  • t

h e b a n k

  • f

a r i v e r . I n c r

  • s

s i n g t h e r i v e r b y b

  • a

t , t h e f a r m e r c

  • u

l d c a r r y

  • n

l y h i m s e l f a n d a s i n g l e

  • n

e

  • f

h i s p u r c h a s e s

  • t

h e f

  • x

, t h e g

  • s

e ,

  • r

t h e b a g

  • f

t h e b e a n s .

slide-26
SLIDE 26

An ancient puzzle ~ 9th century

  • I

f l e f t t

  • g

e t h e r , t h e f

  • x

w

  • u

l d e a t t h e g

  • s

e ,

  • r

t h e g

  • s

e w

  • u

l d e a t t h e b e a n s .

  • T

h e f a r m e r ' s c h a l l e n g e w a s t

  • c

a r r y h i m s e l f a n d h i s p u r c h a s e s t

  • t

h e f a r b a n k

  • f

t h e r i v e r , l e a v i n g e a c h p u r c h a s e i n t a c t . H

  • w

d i d h e d

  • i

t ?

slide-27
SLIDE 27

An ancient puzzle ~ 9th century

  • Wh

a t i s t h e g

  • a

l ?

  • Wh

a t i s t h e i n i t i a l s i t u a t i

  • n

?

  • Wh

i c h a r e t h e r e s

  • u

r c e s / c

  • n

s t r a i n t s ?

slide-28
SLIDE 28

From problems to solvers

P r

  • b

l e m A n a l y s i s P r

  • b

l e m s

  • l

v i n g m e t h

  • d

P l a n n i n g P r

  • b

l e m s

  • l

v i n g t a s k E x e c u t i

  • n

S

  • l

u t i

  • n

P r

  • b

l e m A n a l y s i s A l g

  • r

i t h m P r

  • g

r a m m i n g P r

  • g

r a m E x e c u t i

  • n

O u t c

  • m

e

slide-29
SLIDE 29

P r

  • b

l e m A n a l y s i s P r

  • b

l e m s

  • l

v i n g m e t h

  • d

P l a n n i n g P r

  • b

l e m s

  • l

v i n g t a s k E x e c u t i

  • n

S

  • l

u t i

  • n

P r

  • b

l e m A n a l y s i s A l g

  • r

i t h m P r

  • g

r a m m i n g P r

  • g

r a m E x e c u t i

  • n

O u t c

  • m

e T h e “ r e a l ” p r

  • b

l e m i s n

  • t

p r

  • g

r a m m i n g b u t fj n d i n g t h e p a t h t

  • w

a r d t h e s

  • l

u t i

  • n

.

From problems to solvers

slide-30
SLIDE 30

Imperative vs Declarative

slide-31
SLIDE 31

Imperative vs Declarative

  • I

m p e r a t i v e :

– p

r

  • g

r a m m i n g f

  • c

u s i n g

  • n

t h e s e q u e n c e

  • f
  • p

e r a t i

  • n

s n e c e s s a r y t

  • s
  • l

v e t h e p r

  • b

l e m ( w h i c h i n t u r n u s u a l l y s t a y s i m p l i c i t )

  • D

e c l a r a t i v e

– p

r

  • g

r a m m i n g f

  • c

u s i n g

  • n

d e s c r i b i n g t h e p r

  • b

l e m ( w h i l e t h e s e q u e n c e

  • f
  • p

e r a t i

  • n

s t

  • b

e p e r f

  • r

m e d i s l e f t i m p l i c i t )

slide-32
SLIDE 32

Imperative programming

F

  • c

u s : h

  • w

t

  • c
  • m

p u t e B a s e d

  • n

i n s t r u c t i

  • n

s , c

  • r

r e s p

  • n

d e n t t

  • a

c t i

  • n

s c

  • m

m a n d e d t

  • t

h e m a c h i n e .

– I

t a s s u m e s t h a t t h e c

  • m

p u t e r c a n m a i n t a i n t h e c h a n g e s ( t h e s i d e

  • e

fg e c t s ) c a u s e d b y t h e c

  • m

p u t a t i

  • n

p r

  • c

e s s .

slide-33
SLIDE 33

Imperative programming

F

  • c

u s : h

  • w

t

  • c
  • m

p u t e

  • M
  • s

t p

  • p

u l a r p r

  • g

r a m m i n g l a n g u a g e s i m p l e m e n t t h e i m p e r a t i v e p a r a d i g m :

– i

t m

  • s

t c l

  • s

e l y r e s e m b l e s t h e a c t u a l m a c h i n e i t s e l f , s

  • t

h e p r

  • g

r a m m e r t h i n k s i n a m u c h c l

  • s

e r w a y t

  • t

h e m a c h i n e ;

– b

e c a u s e

  • f

s u c h c l

  • s

e n e s s , i t w a s u n t i l r e c e n t l y t h e

  • n

l y

  • n

e e ffj c i e n t e n

  • u

g h f

  • r

w i d e s p r e a d u s e .

slide-34
SLIDE 34

Imperative programming

  • A

d v a n t a g e s

– e

ffj c i e n t a s c l

  • s

e t

  • t

h e m a c h i n e

– p

  • p

u l a r

– f

a m i l i a r

  • D

i s a d v a n t a g e s

– a

p r

  • g

r a m c a n b e c

  • m

p l e x t

  • u

n d e r s t a n d , b e c a u s e t h e r e f e r e n t i a l t r a n s p a r e n c y d

  • e

s n

  • t

h

  • l

d ( d u e t

  • s

i d e e fge c t s )

– a

b s t r a c t i

  • n

i s m

  • r

e l i m i t e d

– o

r d e r i s c r u c i a l , w h i c h i s n

  • t

s u i t e d i n c e r t a i n p r

  • b

l e m s

slide-35
SLIDE 35

Declarative programming

F

  • c

u s : w h a t t

  • c
  • m

p u t e ( a s d e s i r e d

  • u

t c

  • m

e )

  • I

t i s n

  • t

c

  • n

c e r n e d a b

  • u

t h

  • w

t

  • d
  • t

h i n g s , b u t w h a t s h

  • u

l d b e

  • b

t a i n e d .

– L

a n g u a g e s : d

  • m

a i n s p e c i fj c ( e . g . H T M L ) , q u e r y ( S Q L ) , l

  • g

i c ( P r

  • l
  • g

) .

slide-36
SLIDE 36

Declarative/Logic programming

F

  • c

u s : w h a t t

  • c
  • m

p u t e ( a s d e s i r e d

  • u

t c

  • m

e )

  • V

a r i

  • u

s l

  • g

i c a l a s s e r t i

  • n

s a b

  • u

t a s i t u a t i

  • n

a r e m a d e , d e s c r i b i n g a l l k n

  • w

n f a c t s a n d r u l e s a b

  • u

t t h e m

  • d

e l e d w

  • r

l d . T h e n q u e r i e s a r e m a d e .

  • T

h e r

  • l

e

  • f

t h e c

  • m

p u t e r i s t

  • m

a i n t a i n d a t a a n d t

  • p

e r f

  • r

m i n f e r e n c e s .

slide-37
SLIDE 37

Algorithm = Logic + Control

“ A n a l g

  • r

i t h m c a n b e r e g a r d e d a s c

  • n

s i s t i n g

  • f

– a

l

  • g

i c c

  • m

p

  • n

e n t , w h i c h s p e c i fj e s t h e k n

  • w

l e d g e t

  • b

e u s e d i n s

  • l

v i n g p r

  • b

l e m s , a n d

– a

c

  • n

t r

  • l

c

  • m

p

  • n

e n t , w h i c h d e t e r m i n e s t h e p r

  • b

l e m

  • s
  • l

v i n g s t r a t e g i e s b y m e a n s

  • f

w h i c h t h a t k n

  • w

l e d g e i s u s e d . T h e l

  • g

i c c

  • m

p

  • n

e n t d e t e r m i n e s t h e m e a n i n g

  • f

t h e a l g

  • r

i t h m w h e r e a s t h e c

  • n

t r

  • l

c

  • m

p

  • n

e n t

  • n

l y a fg e c t s i t s e ffj c e n c y . ”

R

  • b

e r t K

  • w

a l s k y , A l g

  • r

i t h m = L

  • g

i c + C

  • n

t r

  • l

( 1 9 7 9 )

slide-38
SLIDE 38

Imperative vs Declarative

  • I

m p e r a t i v e :

– i

n s i d e

  • t
  • u

t s i d e a p p r

  • a

c h : a l l e x e c u t i

  • n

a l t e r n a t i v e s a r e e x p l i c i t l y s p e c i fj e d a n d n e w a l t e r n a t i v e s m u s t b e e x p l i c i t l y a d d e d

  • D

e c l a r a t i v e

– o

u t s i d e

  • t
  • i

n s i d e a p p r

  • a

c h : c

  • n

s t r a i n t s i m p l i c i t l y s p e c i f y e x e c u t i

  • n

a l t e r n a t i v e s a s a l l a l t e r n a t i v e s t h a t s a t i s f y t h e c

  • n

s t r a i n t s ; a d d i n g n e w c

  • n

s t r a i n t s u s u a l l y m e a n s d i s c a r d i n g s

  • m

e e x e c u t i

  • n

a l t e r n a t i v e s

slide-39
SLIDE 39

I m p e r a t i v e : y

  • u

c

  • m

m a n d t h e d i r e c t i

  • n

s

slide-40
SLIDE 40

I m p e r a t i v e : y

  • u

c

  • m

m a n d t h e d i r e c t i

  • n

s

slide-41
SLIDE 41

I m p e r a t i v e : y

  • u

c

  • m

m a n d t h e d i r e c t i

  • n

s

  • Wh

a t i f t h e l a b y i n t h c h a n g e s ?

slide-42
SLIDE 42

D e c l a r a t i v e : y

  • u

g i v e j u s t t h e l a b y r i n t h . T h e c

  • m

p u t e r fj n d s t h e w a y .

slide-43
SLIDE 43

D e c l a r a t i v e : y

  • u

g i v e j u s t t h e l a b y r i n t h . T h e c

  • m

p u t e r fj n d s t h e w a y .

  • F
  • r

i n s t a n c e , v i a t r i a l , e r r

  • r

a n d b a c k t r a c k i n g

slide-44
SLIDE 44

D e c l a r a t i v e : y

  • u

g i v e j u s t t h e l a b y r i n t h . T h e c

  • m

p u t e r fj n d s t h e w a y .

  • F
  • r

i n s t a n c e , v i a t r i a l , e r r

  • r

a n d b a c k t r a c k i n g

slide-45
SLIDE 45

D e c l a r a t i v e : y

  • u

g i v e j u s t t h e l a b y r i n t h . T h e c

  • m

p u t e r fj n d s t h e w a y .

  • F
  • r

i n s t a n c e , v i a t r i a l , e r r

  • r

a n d b a c k t r a c k i n g

slide-46
SLIDE 46

D e c l a r a t i v e : y

  • u

g i v e j u s t t h e l a b y r i n t h . T h e c

  • m

p u t e r fj n d s t h e w a y .

  • F
  • r

i n s t a n c e , v i a t r i a l , e r r

  • r

a n d b a c k t r a c k i n g

slide-47
SLIDE 47

First steps in Prolog

slide-48
SLIDE 48

Histrory of Prolog

1 9 6 5 R e s

  • l

u t i

  • n

a l g

  • r

i t h m b y J . A . R

  • b

i n s

  • n

f

  • l

l

  • w

e d b y S L D r e s

  • l

u t i

  • n

b y R . K

  • w

a l s k i 1 9 7 2 P R O g r a m m a t i

  • n

e n L O G i q u e c r e a t e d b y A . C

  • l

m e r a u e r a n d P . R

  • u

s s e l i n L u m i n y , M a r s e i l l e 1 9 8 P r

  • l
  • g

a c k n

  • w

l e d g e d a s a m a j

  • r

A . I . l a n g u a g e … n

  • w

v a r i

  • u

s v e r s i

  • n

s , u s e d i n C

  • n

s t r a i n t P r

  • g

r a m m i n g ,

  • r

b a s i s / r e f e r e n c e f

  • r

a l t e r n a t i v et e c h n i q u e s , a s D a t a L

  • g

, A n w s e r S e t P r

  • g

r a m m i n g ( A S P ) , e t c .

slide-49
SLIDE 49

First program

parent(marge, lisa). parent(marge, bart). parent(marge, maggie). parent(homer, lisa). parent(homer, bart). parent(homer, maggie). parent(abraham, homer). parent(abraham, herb). parent(mona, homer). parent(jackie, marge). parent(clancy, marge). parent(jackie, patty). parent(clancy, patty). parent(jackie, selma). parent(clancy, selma). parent(selma, ling).

slide-50
SLIDE 50

First program

parent(marge, lisa). parent(marge, bart). parent(marge, maggie). parent(homer, lisa). parent(homer, bart). parent(homer, maggie). parent(abraham, homer). parent(abraham, herb). parent(mona, homer). parent(jackie, marge). parent(clancy, marge). parent(jackie, patty). parent(clancy, patty). parent(jackie, selma). parent(clancy, selma). parent(selma, ling). child(X,Y) :- parent(Y,X).

slide-51
SLIDE 51

Prolog clauses

  • F

a c t female(marge).

slide-52
SLIDE 52

Prolog clauses

  • F

a c t female(marge).

  • R

u l e child(X,Y) :- parent(Y,X).

slide-53
SLIDE 53

Prolog clauses

  • F

a c t female(marge).

  • R

u l e child(X,Y) :- parent(Y,X). E x e r c i s e : w r i t e mother(X,Y) grandparent(X,Y) ancestor(X,Y) cousin(X,Y)

slide-54
SLIDE 54

Prolog syntax and bonuses

slide-55
SLIDE 55

Prolog syntax: Terms

  • C
  • n

s t a n t s I d e n t i fj e r s

s t r i n g s

  • f

l e t t e r s , d i g i t s ,

  • r

u n d e r s c

  • r

e “ _ ” t h a t s t a r t w i t h l

  • w

e r c a s e l e t t e r s .

marge lisa x25 x_25 alpha_beta

slide-56
SLIDE 56

Prolog syntax: Terms

  • C
  • n

s t a n t s I d e n t i fj e r s

s t r i n g s

  • f

l e t t e r s , d i g i t s ,

  • r

u n d e r s c

  • r

e “ _ ” t h a t s t a r t w i t h l

  • w

e r c a s e l e t t e r s .

marge lisa x25 x_25 alpha_beta N u m b e r s 1.001 2 3.03

slide-57
SLIDE 57

Prolog syntax: Terms

  • C
  • n

s t a n t s I d e n t i fj e r s

s t r i n g s

  • f

l e t t e r s , d i g i t s ,

  • r

u n d e r s c

  • r

e “ _ ” t h a t s t a r t w i t h l

  • w

e r c a s e l e t t e r s .

marge lisa x25 x_25 alpha_beta N u m b e r s 1.001 2 3.03 S t r i n g s e n c l

  • s

e d i n s i n g l e q u

  • t

e s 'Mary' '.01' 'string'

N

  • t

e t h a t , b e c a u s e

  • f

t h e e n c l

  • s

i n g , s t r i n g s c a n s t a r t w i t h u p p e r c a s e l e t t e r ,

  • r

c a n b e a n u m b e r n

  • w

t r e a t e d a s a s t r i n g .

slide-58
SLIDE 58

Prolog syntax: Terms

  • C
  • n

s t a n t s I d e n t i fj e r s

s t r i n g s

  • f

l e t t e r s , d i g i t s ,

  • r

u n d e r s c

  • r

e “ _ ” t h a t s t a r t w i t h l

  • w

e r c a s e l e t t e r s .

marge lisa x25 x_25 alpha_beta N u m b e r s 1.001 2 3.03

  • V

a r i a b l e s

s t r i n g s

  • f

l e t t e r s , d i g i t s

  • r

u n d e r s c

  • r

e t h a t s t a r t w i t h a n u p p e r c a s e l e t t e r

  • r

t h e u n d e r s c

  • r

e

_x, Anna, Successor_State,

N

  • t

e : u n d e s c

  • r

e b y i t s e l f ( “ _” ) i s a s p e c i a l a n

  • n

y m

  • u

s v a r i a b l e .

slide-59
SLIDE 59

Prolog syntax: Terms

  • S

t r u c t u r e s <identifier>(Term1, ..., Termk)

r e c u r s i v e d e fj n i t i

  • n

: e a c h t e r m c a n i t s e l f b e a s t r u c t u r e

date(1, may, 1983) point(X, Y, Z) date(+(0,1), may, +(1900,-(183,100)))

slide-60
SLIDE 60

Prolog syntax: Terms

S t r u c t u r e s c a n b e t h

  • u

g h t a s t r e e s ! date(+(0,1), may, +(1900,-(183,100)))

slide-61
SLIDE 61

Prolog syntax: Predicates

  • P

r e d i c a t e s a r e s y n t a x i c a l l y t h e s a m e a s s t r u c t u r e s . <identifier>(Term1, ..., Termk) parent(marge, bart) female(marge)

slide-62
SLIDE 62

Prolog syntax: Predicates

  • P

r e d i c a t e s a r e s y n t a x i c a l l y t h e s a m e a s s t r u c t u r e s . <identifier>(Term1, ..., Termk) parent(marge, bart) female(marge) . . b u t t h e y a r e n

  • t

t e r m s ! → p r e d i c a t e i d e n t i fj e r s s t r u c t u r e i d e n t i fj e r s ≠

slide-63
SLIDE 63

Prolog syntax: Predicates

→ p r e d i c a t e i d e n t i fj e r s s t r u c t u r e i d e n t i fj e r s ≠

  • b

j e c t s t h i n g s s a i d a b

  • u

t

  • b

j e c t s

slide-64
SLIDE 64

Prolog Syntax

  • A

p r

  • l
  • g

p r

  • g

r a m i s a s e q u e n c e

  • f

f a c t s a n d r u l e s .

  • F

a c t s a r e p r e d i c a t e s t e r m i n a t e d b y a p e r i

  • d

“ . ” <identifier>(Term1, ..., Termk).

slide-65
SLIDE 65

Prolog Syntax

  • A

p r

  • l
  • g

p r

  • g

r a m i s a s e q u e n c e

  • f

f a c t s a n d r u l e s .

  • F

a c t s a r e p r e d i c a t e s t e r m i n a t e d b y a p e r i

  • d

“ . ” <identifier>(Term1, ..., Termk). F a c t s e n c

  • d

e a s s e r t i

  • n

s , t h i n g s t h a t a r e d e c l a r e d c e r t a i n ! female(marge). parent(homer, bart).

slide-66
SLIDE 66

Prolog Syntax

  • A

p r

  • l
  • g

p r

  • g

r a m i s a s e q u e n c e

  • f

f a c t s a n d r u l e s .

  • R

u l e s a r e i n t h e f

  • r

m : predicateH :- predicate1, .., predicatek. t h e l e f t

  • f

“ :-” i s n a m e d h e a d , t h e r i g h t b

  • d

y .

slide-67
SLIDE 67

Prolog Syntax

  • A

p r

  • l
  • g

p r

  • g

r a m i s a s e q u e n c e

  • f

f a c t s a n d r u l e s .

  • R

u l e s a r e i n t h e f

  • r

m : predicateH :- predicate1, .., predicatek.

  • R

u l e s e n c

  • d

e w a y s

  • f

d e r i v i n g

  • r

c

  • m

p u t i n g a n e w f a c t . animal(X) :- elephant(X).

We c a n s h

  • w

t h a t X i s a n a n i m a l i f w e c a n s h

  • w

t h a t i t i s a n e l e p h a n t .

slide-68
SLIDE 68

Prolog Syntax

  • A

p r

  • l
  • g

p r

  • g

r a m i s a s e q u e n c e

  • f

f a c t s a n d r u l e s .

  • R

u l e s a r e i n t h e f

  • r

m : predicateH :- predicate1, .., predicatek.

  • R

u l e s e n c

  • d

e w a y s

  • f

d e r i v i n g

  • r

c

  • m

p u t i n g a n e w f a c t . animal(X) :- elephant(X).

We c a n s h

  • w

t h a t X i s a n a n i m a l i f w e c a n s h

  • w

t h a t i t i s a n e l e p h a n t .

father(X,Y) :- parent(X,Y), male(X).

We c a n s h

  • w

t h a t X i s a f a t h e r

  • f

Y i f w e c a n s h

  • w

t h a t X i s a p a r e n t

  • f

Y a n d t h a t X i s m a l e .

slide-69
SLIDE 69

Prolog's main operation

  • A

q u e r y i s a s e q u e n c e

  • f

p r e d i c a t e s predicate1, predicate2, ..., predicatek

– u

s i n g t h e f a c t s a n d r u l e s i n t h e P r

  • l
  • g

p r

  • g

r a m , t h e s

  • l

v e r t r i e s t

  • p

r

  • v

e t h a t t h i s s e q u e n c e

  • f

p r e d i c a t e s i s t r u e .

– i

n p r

  • v

i n g t h e s e q u e n c e i t ( s h

  • u

l d ) p e r f

  • r

m t h e c

  • m

p u t a t i

  • n

y

  • u

w a n t .

slide-70
SLIDE 70

Prolog's main operation

  • A

q u e r y i s a s e q u e n c e

  • f

p r e d i c a t e s predicate1, predicate2, ..., predicatek

– u

s i n g t h e f a c t s a n d r u l e s i n t h e P r

  • l
  • g

p r

  • g

r a m , t h e s

  • l

v e r t r i e s t

  • p

r

  • v

e t h a t t h i s s e q u e n c e

  • f

p r e d i c a t e s i s t r u e .

– i

n p r

  • v

i n g t h e s e q u e n c e i t ( s h

  • u

l d ) p e r f

  • r

m t h e c

  • m

p u t a t i

  • n

y

  • u

w a n t .

d e l i c a t e p

  • i

n t : p r

  • c

e d u r a l c

  • m

p u t a t i

  • n

m i g h t b e m i x e d w i t h d e c l a r a t i v e c

  • m

p u t a t i

  • n
slide-71
SLIDE 71

Prolog's resolution strategy

slide-72
SLIDE 72

Horn clauses

  • F

a c t s a n d r u l e s f a l l s u n d e r t h e d e fj n i t i

  • n
  • f

H

  • r

n c l a u s e s , t h e s t r u c t u r e s

  • n

w h i c h S L D r e s

  • l

u t i

  • n

w a s p r

  • v

e n : G e n e r a l f

  • r

m : F :- F1, F2,…, Fn.

  • T
  • p

r

  • v

e F,

  • n

e m u s t s u c c e s s i v e l y p r

  • v

e F1, … , Fn.

slide-73
SLIDE 73

Horn clauses

  • F

a c t s a n d r u l e s f a l l s u n d e r t h e d e fj n i t i

  • n
  • f

H

  • r

n c l a u s e s , t h e s t r u c t u r e s

  • n

w h i c h S L D r e s

  • l

u t i

  • n

w a s p r

  • v

e n : G e n e r a l f

  • r

m : F :- F1, F2,…, Fn.

  • T
  • p

r

  • v

e F,

  • n

e m u s t s u c c e s s i v e l y p r

  • v

e F1, … , Fn.

  • F

i s t h e c l a u s e ’ s h e a d .

  • F1,

F2, … , Fn c

  • n

s t i t u t e t h e c l a u s e ’ s t a i l

  • r

b

  • d

y .

  • A

f a c t i s a c l a u s e w i t h a n e m p t y t a i l .

slide-74
SLIDE 74

Prolog's strategy

  • T
  • a

n s w e r t h e q u e s t i

  • n

, P r

  • l
  • g

b u i l d s a s e a r c h t r e e :

– s

e t

  • f

p

  • s

s i b i l i t i e s ( c l a u s e s m a t c h i n g t h e q u e s t i

  • n

) r e p r e s e n t e d a s a t r e e

– e

a c h c h

  • i

c e i s a n

  • d

e

  • f

t h e s e a r c h t r e e

– t

r i a l a n d e r r

  • r

s e q u e n t i a l s e a r c h , f

  • l

l

  • w

i n g t h e

  • r

d e r

  • f

d e c l a r a t i

  • n
slide-75
SLIDE 75

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-76
SLIDE 76

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-77
SLIDE 77

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-78
SLIDE 78

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-79
SLIDE 79

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-80
SLIDE 80

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-81
SLIDE 81

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-82
SLIDE 82

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-83
SLIDE 83

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). e(1). d(3).

  • Q

u e r y : ?- p(1).

slide-84
SLIDE 84

Prolog's strategy, example

p(1) :- a(1). p(1) :- b(1). a(1) :- c(1). c(1) :- d(1). c(1) :- d(2). b(1) :- e(1). b(1) :- d(3). e(1). d(3).

  • Q

u e r y : ?- p(1). w i t h b a c k t r a c k i n g w e c a n g e t m

  • r

e a n s w e r s b y u s i n g “ ;”

slide-85
SLIDE 85

Prolog's strategy

  • T

h e s

  • l

v e r f

  • l

l

  • w

s a d e p t h

  • fj

r s t s t r a t e g y

– s

u c c e s s n

  • d

e : s

  • l

u t i

  • n

f

  • u

n d ! t h e s

  • l

v e r d i s p l a y s i t a n d s t

  • p

s .

– f

a i l u r e n

  • d

e : t h e s

  • l

v e r b a c k t r a c k s u p i n t h e t r e e , u n t i l i t fj n d s a c h

  • i

c e p

  • i

n t w i t h u n e x p l

  • r

e d b r a n c h e s .

slide-86
SLIDE 86

Prolog's strategy

  • I

f b a c k t r a c k i n g e n c

  • u

n t e r s n

  • c

h

  • i

c e p

  • i

n t l e f t , P r

  • l
  • g

s t

  • p

s . N

  • f

u r t h e r s

  • l

u t i

  • n

.

  • N

O T E : S

  • m

e b r a n c h e s a r e i n fj n i t e ! S

  • s

e a r c h m a y n

  • t

s t

  • p

… T a k e c a r e

  • f

:

– T

h e

  • r

d e r

  • f

g

  • a

l s i n c l a u s e t a i l s

– T

h e

  • r

d e r

  • f

c l a u s e s

slide-87
SLIDE 87

Resolution with variables

slide-88
SLIDE 88

Using variables...

  • V

a r i a b l e s a l l

  • w

u s t

  • :

– c

  • m

p u t e m

  • r

e t h a n y e s / n

  • a

n s w e r s ?- parent(marge, X).

slide-89
SLIDE 89

Using variables...

  • V

a r i a b l e s a l l

  • w

u s t

  • :

– c

  • m

p u t e m

  • r

e t h a n y e s / n

  • a

n s w e r s ?- parent(marge, X).

– c

  • m

p r e s s t h e p r

  • g

r a m .

parent(marge, lisa) :- child(lisa, marge). parent(marge, bart) :- child(bart, marge). … parent(X, Y) :- child(Y, X).

slide-90
SLIDE 90

Using variables...

  • V

a r i a b l e s a l l

  • w

u s t

  • :

– c

  • m

p u t e m

  • r

e t h a n y e s / n

  • a

n s w e r s ?- parent(marge, X).

– c

  • m

p r e s s t h e p r

  • g

r a m .

parent(marge, lisa) :- child(lisa, marge). parent(marge, bart) :- child(bart, marge). … parent(X, Y) :- child(Y, X).

– r

e v e r s i b i l i t y ( w h e n d e c l a r a t i v i t y i s m a i n t a n e d ) ?- parent(Y, lisa).

slide-91
SLIDE 91

Variables matching via Unification

?- brother(bart, Who). brother(X,Y) :- male(X), parent(X,Z), parent(Y,Z), X \== Y. U n i fj c a t i

  • n

w i t h brother(X,Y) X=bart, Y=Who male(bart) parent(bart,Z) parent(bart,Z) bart \== Who

slide-92
SLIDE 92

Unification examples

  • U

n i fj c a t i

  • n

p r e d i c a t e : “ =” ?- a(B,C) = a(2,3). YES {B=2, C=3} ?- a(X,Y,L) = a(Y,2,carole). YES {X=2, Y=2, L=carole} ?- a(X,X,Y) = a(Y,u,v). NO

slide-93
SLIDE 93

Unification examples

  • U

n i fj c a t i

  • n

p r e d i c a t e : “ =” ?- a(B,C) = a(2,3). YES {B=2, C=3} ?- a(X,Y,L) = a(Y,2,carole). YES {X=Y, Y=2, L=carole} ?- a(X,X,Y) = a(Y,u,v). NO E x e r c i s e U n i f y p(X,b(Z,a),X) w i t h p(Y,Y,b(V,a))

slide-94
SLIDE 94

Unification algorithm

d e r e f e r e n c e i s a f u n c t i

  • n

t h a t d e r e f e r e n c e s b

  • u

n d v a r i a b l e s a n d r e t u r n s t h e i n p u t

  • t

h e r w i s e

A f r e e v a r i a b l e c a n b e s e e n a s a p

  • i

n t e r t

  • N

I L . Wh e n n

  • t

f r e e , i t i s s a i d b

  • u

n d v a r i a b l e . D e r e f e r e n c i n g a v a r i a b l e m e a n s r e a c h i n g t h e v a l u e t

  • w

h i c h i t i s b

  • u

n d .

p r

  • c

e d u r e u n i f y ( t 1 , t 2 ) t 3 : = d e r e f e r e n c e ( t 1 ) ; t 4 : = d e r e f e r e n c e ( t 2 ) i f t 3 i s a v a r i a b l e t h e n t 3 p

  • i

n t s t

  • t

4 ; r e t u r n s u c c e s s e l s e i f t 4 i s a v a r i a b l e t h e n t 4 p

  • i

n t s t

  • t

3 ; r e t u r n s u c c e s s e l s e i f t 3 i s a n a t

  • m

a n d t 4 i s a n a t

  • m

t h e n i f t 3 = t 4 t h e n r e t u r n s u c c e s s e l s e r e t u r n f a i l e l s e l e t t 3 = f ( t 3 1 , . . , t 3 n ) a n d t 4 = g ( t 4 1 , . . , t 4 m ) i f f = g a n d n = m t h e n f

  • r

i : = 1 t

  • n

d

  • i

f u n i f y ( t 3 i , t 4 i ) f a i l s t h e n r e t u r n f a i l r e t u r n s u c c e s s e l s e r e t u r n f a i l t 1 , t 2 a r e t w

  • t

e r m s

  • X

a n d m a r g e w h e r e X i s b

  • u

n d t

  • t

h e v a l u e m a r g e w i l l m a t c h .

  • X

a n d Y w h e r e X i s b

  • u

n d t

  • m

a r g e a n d Y i s b

  • u

n d t

  • m

a r g e w i l l m a t c h ,

  • X

a n d m a r g e w h e r e X i s b

  • u

n d t

  • l

i s a w i l l n

  • t

m a t c h .

slide-95
SLIDE 95

Lists

slide-96
SLIDE 96

Representing lists

  • L

i s t s a r e a c r u c i a l d a t a s t r u c t u r e i n P r

  • l
  • g

. T h e y a r e u s u a l l y w r i t t e n a s : [a, b, c, d] T h i s c

  • r

r e s p

  • n

d s t

  • t

h e s t r u c t u r e d t e r m : [a|[b|[c|[d|[]]]]] w h e r e [] i s a s p e c i a l c

  • n

s t a n t t h e e m p t y l i s t .

slide-97
SLIDE 97

Representing lists

  • E

a c h l i s t i s

  • f

t h e f

  • r

m [ < h e a d > | < r e s t _

  • f

_ l i s t > ] < h e a d > a n e l e m e n t

  • f

t h e l i s t ( n

  • t

n e c e s s a r i l y a l i s t ) . < r e s t _

  • f

_ l i s t > i s a l i s t ( a s u b

  • l

i s t ) . [a, b, c, d] = [a | [b, c, d] ] a : h e a d ; [ b , c , d ] : t a i l [a, b, c, d] = [a, b | [c, d]] [_|_] h a s a t l e a s t

  • n

e e l e m e n t .

slide-98
SLIDE 98

Cut

slide-99
SLIDE 99

Backtracking control using CUT

  • S
  • m

e t i m e s i t i s u s e f u l t

  • c
  • n

t r

  • l

t h e b a c k t r a c k i n g , a n d t h i s c a n b e d

  • n

e u s i n g t h e “ ! ” , t h e c u t

  • p

e r a t

  • r

. →

  • n

c e i t i s e x e c u t e d , i t d i s a l l

  • w

s b a c k t r a c k i n g

slide-100
SLIDE 100

Backtracking control using CUT

  • S
  • m

e t i m e s i t i s u s e f u l t

  • c
  • n

t r

  • l

t h e b a c k t r a c k i n g , a n d t h i s c a n b e d

  • n

e u s i n g t h e “ ! ” , t h e c u t

  • p

e r a t

  • r

. →

  • n

c e i t i s e x e c u t e d , i t d i s a l l

  • w

s b a c k t r a c k i n g p :- b1, b2, !, a1, a2, a3. p :- r1, r2 . p :- r3 .

B e f

  • r

e r e a c h i n g c u t , t h e r e m i g h t b e b a c k t r a c k i n g

  • n

b 1 a n d b 2

  • r

t r y i n g

  • t

h e r r u l e s f

  • r

p i f

  • n

e

  • f

b 1

  • r

b 2 c a n n

  • t

b e s a t i s fj e d . A f t e r r e a c h i n g ! , n

  • m
  • r

e b a c k t r a c k i n g . T h e s e c

  • n

d a n d t h i r d r u l e w i l l n

  • t

b e s e a r c h e d .

slide-101
SLIDE 101

Backtracking control using CUT

  • S
  • m

e t i m e s i t i s u s e f u l t

  • c
  • n

t r

  • l

t h e b a c k t r a c k i n g , a n d t h i s c a n b e d

  • n

e u s i n g t h e “ ! ” , t h e c u t

  • p

e r a t

  • r

. →

  • n

c e i t i s e x e c u t e d , i t d i s a l l

  • w

s b a c k t r a c k i n g p(X, Y) :- q(X), !, r(X,Y). p(X, Y) :- s(X). q(X) :- !, r(a,Y).

slide-102
SLIDE 102

...undermining declarativity

  • A

l l t i m e s i n w h i c h w e p l a y w i t h t h e c

  • n

t r

  • l

w e a r e u n d e r m i n i n g t h e d e c l a r a t i v e p r

  • p

e r t i e s

  • f

t h e l a n g u a g e .

  • T

h e r e f

  • r

e , u s e s

  • f

c u t ( a n d a s w e w i l l s e e n e g a t i

  • n

a s f a i l u r e )

  • r

a n y

  • t

h e r p r

  • p

e r t i e s h a v i n g s i d e e fg e c t s r e m

  • v

e p r

  • p

e r t i e s a s r e v e r s i b i l i t y .

slide-103
SLIDE 103

Prolog and logic

slide-104
SLIDE 104

Prolog and Logic

  • A

P r

  • l
  • g

c l a u s e i s a g e n e r a l i s e d d i s j u n c t i

  • n

a :- b, c. I n l

  • g

i c : b c a ∧ ⇒ A s m a t e r i a l i m p l i c a t i

  • n

p q e q u i v a l e n t t

  • ¬

p q ⇒ ∨ ¬ b ¬ c a ∨ ∨

  • P

r

  • l
  • g

i n h e r i t s t h e c

  • r

r e c t n e s s a n d c

  • m

p l e t e n e s s p r

  • f

m e t h

  • d

s f r

  • m

F i r s t O r d e r L

  • g

i c , a n d , f

  • r

t h e r e s t r i c t i

  • n

t

  • H
  • r

n C l a u s e s , e n j

  • y

e s d e c i d a b l e a l g

  • r

i t h m s … M

  • r

e a b

  • u

t t h i s t h e n e x t w e e k s .

slide-105
SLIDE 105

Prolog and Logic - 2

  • A

P r

  • l
  • g

c l a u s e a :- b. I n l

  • g

i c w

  • u

l d b e : b a ⇒ w h i c h i s e q u i v a l e n t t

  • ¬

a ¬ b ⇒

slide-106
SLIDE 106

Prolog and Logic - 2

  • A

P r

  • l
  • g

c l a u s e a :- b. I n l

  • g

i c w

  • u

l d b e : b a ⇒ w h i c h i s e q u i v a l e n t t

  • ¬

a ¬ b ⇒ b u t t h e c l a u s e d

  • e

s n

  • t

s p e c i f y t h a t ! ! . . . d i fg e r e n c e d u e t

  • t

h e d i fg e r e n t m e a n i n g

  • f

n e g a t i

  • n

!

slide-107
SLIDE 107

NAF – Negation as Failure

  • I

n p r

  • p
  • s

i t i

  • n

a l l

  • g

i c , p r

  • p
  • s

i t i

  • n

s c a n b e t r u e a n d f a l s e .

slide-108
SLIDE 108

NAF – Negation as Failure

  • I

n p r

  • p
  • s

i t i

  • n

a l l

  • g

i c , p r

  • p
  • s

i t i

  • n

s c a n b e t r u e a n d f a l s e . B u t p r

  • p
  • s

i t i

  • n

s c

  • u

l d b e a l s

  • u

n k n

  • w

n .

E x a m p l e :

  • b

v i

  • u

s l y , i t m a y r a i n ,

  • r

n

  • t

r a i n . B u t i f I ' m i n d

  • r

, a n d t h e r e i s n

  • w

i n d

  • w

, I d

  • n
  • t

k n

  • w

!

slide-109
SLIDE 109
  • I

n p r

  • p
  • s

i t i

  • n

a l l

  • g

i c , p r

  • p
  • s

i t i

  • n

s c a n b e t r u e a n d f a l s e . B u t p r

  • p
  • s

i t i

  • n

s c

  • u

l d b e a l s

  • u

n k n

  • w

n .

E x a m p l e :

  • b

v i

  • u

s l y , i t m a y r a i n ,

  • r

n

  • t

r a i n . B u t i f I ' m i n d

  • r

, a n d t h e r e i s n

  • w

i n d

  • w

, I d

  • n
  • t

k n

  • w

!

  • Wh

e n t h e i n f e r e n c e e n g i n e i s n

  • t

a b l e t

  • a

s s e s s i f t h e p r

  • p
  • s

i t i

  • n

i s t r u e , t h e r e s u l t w i l l b e f a l s e . T h i s i s c a l l e d N e g a t i

  • n

a s F a i l u r e ( N A F ) .

NAF – Negation as Failure

slide-110
SLIDE 110
  • I

n p r

  • p
  • s

i t i

  • n

a l l

  • g

i c , p r

  • p
  • s

i t i

  • n

s c a n b e t r u e a n d f a l s e . B u t p r

  • p
  • s

i t i

  • n

s c

  • u

l d b e a l s

  • u

n k n

  • w

n .

E x a m p l e :

  • b

v i

  • u

s l y , i t m a y r a i n ,

  • r

n

  • t

r a i n . B u t i f I ' m i n d

  • r

, a n d t h e r e i s n

  • w

i n d

  • w

, I d

  • n
  • t

k n

  • w

!

  • Wh

e n t h e i n f e r e n c e e n g i n e i s n

  • t

a b l e t

  • a

s s e s s i f t h e p r

  • p
  • s

i t i

  • n

i s t r u e , t h e r e s u l t w i l l b e f a l s e . T h i s i s c a l l e d N e g a t i

  • n

a s F a i l u r e ( N A F ) .

  • I

n g e n e r a l , t h e r e m a y b e t w

  • p
  • s

s i b l e n e g a t i

  • n

s :

  • s

t r

  • n

g n e g a t i

  • n

( “ c l a s s i c a l ” n e g a t i

  • n

) ↔

  • N

A F n e g a t i

  • n

( “ ↔ u n d e c i d a b l e ” )

NAF – Negation as Failure

slide-111
SLIDE 111
  • Wh

e n N A F i m p l i e s a s t r

  • n

g n e g a t i

  • n

w e a r e u n d e r t h e c l

  • s

e d

  • w
  • r

l d a s s u m p t i

  • n

.

I f I d

  • n
  • t

k n

  • w

s

  • m

e t h i n g ( i . e . I c a n n

  • t

i n f e r t h a t s

  • m

e t h i n g ) , t h a n t h a t s

  • m

e t h i n g w i l l b e f a l s e .

NAF – Negation as Failure

slide-112
SLIDE 112
  • Wh

e n N A F i m p l i e s a s t r

  • n

g n e g a t i

  • n

w e a r e u n d e r t h e c l

  • s

e d

  • w
  • r

l d a s s u m p t i

  • n

.

I f I d

  • n
  • t

k n

  • w

s

  • m

e t h i n g ( i . e . I c a n n

  • t

i n f e r t h a t s

  • m

e t h i n g ) , t h a n t h a t s

  • m

e t h i n g w i l l b e f a l s e .

  • E

x . U F O s d

  • n
  • t

e x i s t !

NAF – Negation as Failure

slide-113
SLIDE 113
  • Wh

e n N A F i m p l i e s a s t r

  • n

g n e g a t i

  • n

w e a r e u n d e r t h e c l

  • s

e d

  • w
  • r

l d a s s u m p t i

  • n

.

I f I d

  • n
  • t

k n

  • w

s

  • m

e t h i n g ( i . e . I c a n n

  • t

i n f e r t h a t s

  • m

e t h i n g ) , t h a n t h a t s

  • m

e t h i n g w i l l b e f a l s e .

  • E

x . U F O s d

  • n
  • t

e x i s t !

I f i t i s n

  • t

t h e c a s e t h a t u f

  • s

e x i s t , t h e n i t i s t h e c a s e t h a t u f

  • s

d

  • n
  • t

e x i s t .

NAF – Negation as Failure

slide-114
SLIDE 114
  • Wh

e n N A F i m p l i e s a s t r

  • n

g n e g a t i

  • n

w e a r e u n d e r t h e c l

  • s

e d

  • w
  • r

l d a s s u m p t i

  • n

.

I f I d

  • n
  • t

k n

  • w

s

  • m

e t h i n g ( i . e . I c a n n

  • t

i n f e r t h a t s

  • m

e t h i n g ) , t h a n t h a t s

  • m

e t h i n g w i l l b e f a l s e .

  • E

x . U F O s d

  • n
  • t

e x i s t !

I f i t i s n

  • t

t h e c a s e t h a t u f

  • s

e x i s t , t h e n i t i s t h e c a s e t h a t u f

  • s

d

  • n
  • t

e x i s t .

NAF – Negation as Failure

T h a t ' s t h e c a s e

  • f

P r

  • l
  • g

!

slide-115
SLIDE 115

Negation as failure

  • N

e g a t i

  • n

a s f a i l u r e c a n b e u s e d t

  • i

m p l e m e n t d e f a u l t s . fancy(belle_d_argent). fancy(maximus). expensive(belle_d_argent). affordable(Restaurant) :- not(expensive(Restaurant)). ?- fancy(X), affordable(X). X=maximus

slide-116
SLIDE 116

Negation as failure

  • N

e g a t i

  • n

a s f a i l u r e c a n b e u s e d t

  • i

m p l e m e n t d e f a u l t s . fancy(belle_d_argent). fancy(maximus). expensive(belle_d_argent). affordable(Restaurant) :- not(expensive(Restaurant)). ?- fancy(X), affordable(X). X=maximus ?- affordable(X), fancy(X). FALSE

slide-117
SLIDE 117

Negation as failure with CUT

  • T

h i s p r e d i c a t e b e h a v e s j u s t a s not p(X): q(X) :- p(X), !, fail. q(X).

slide-118
SLIDE 118

Conclusions

slide-119
SLIDE 119

Guidelines

  • G
  • n

h t t p : / / a i c

  • u

r s e . r 2 . e n s t . f r : 4 2 4 2 / S C I A

– R

e a d a n d w

  • r

k w i t h t h e m a t e r i a l .

– R

e s p

  • n

s e s t

  • q

u e s t i

  • n

s w i l l b e r e c

  • r

d e d u p t

  • a

l i m i t d a t e . ( g e n e r a l l y 2 w e e k s f r

  • m

t h e l e c t u r e ) a n d g r a d e d .

– A

f t e r s e n d i n g a r e s p

  • n

s e y

  • u

r e c e i v e a p

  • s

s i b l e c

  • r

r e c t i

  • n

.

  • T

r y t

  • b

e i n s c h e d u l i n g w i t h t h e c

  • u

r s e !

  • C
  • l

l a b

  • r

a t i v e l e a r n i n g i s w e l c

  • m

e , c

  • p

y i n g i s p r

  • h

i b i t e d !

  • Q

u e s t i

  • n

a n d c

  • m

m e n t s a r e w e l c

  • m

e , j u s t w r i t e m e : g s i l e n

  • @e

n s t . f r