You are on page 1of 95

-

PROLOG
-


1 : ________________________________________________ 1
1.1 ________________ 5
1.2 ____________________ 5
1.3 _____________________________________ 6

2 : PROLOG _______________________________________________ 11
2.1 (unification) ____________________________________________ 14
2.2 PROLOG _____________________ 15
2.3 ________________________ 15
2.4 ___________________________________________ 15
2.5 PROLOG _______________________________ 16
2.6 (Unification) __________________ 18
2.7 SUBGOALS _____________________________________________ 19
2.8 PROLOG; ________________________________________ 19
2.9 PROLOG; _________________________ 21
2.10 PROLOG ____________________________________ 22
2.11 PROLOG____________________________________ 24
2.12 _____________ 29
2.13 ! _______________________________________________ 31

3 - ____________________________________ 37
3.1 _________________________________________________________ 37
3.2 ________________________________________ 38
3.3 ______________________________ 42
3.4 ________________________ 43
3.5 __________________________________________ 47
3.6 ______________________________ 48
3.7 _____________________________________________ 56
3.8 ___________________ 58
3.9 _____________________________________________ 63

4 : _____________________________ 75
4.1 _________________________________________________________ 75
4.2 ____________________________________________________________ 75
4.3 ____________________________ 76
4.4 _____________ 79
4.5 ___________________________ 80
4.6 ______________________________ 86
4.7 B ____________________________________________________ 87


(Planning)

1 :

.
, ,
, .
,
( : , ,
, )
.
() (Artificial Intelligence - AI)
/ .

,
: ,
, ,
.
(
):

, ,
(Herbert Simon).
.

.
(science)
(engineering) (Nils Nilsson).

. ()
, () .


.

, .
,
. ,


.
; ; ;
, , , ,

.
,
,
:
,

.
,
.

:

.
, .
.
:


(REASONING)

(BEHAVIOUR)

1.

(cognitive

science)


(I/O), . :
GPS (General Problem Solver):



.
3.

Turing Test. 3 ,

.
.
.
.
.
:
Eliza:
Turing Test. :
:

Eliza:

..

Eliza:

..

Eliza

(pattern matcher) .

,
if sentence = ..mother..
then respond with Tell me about your family
,
Eliza .

.
2 4.
.
2.

. :
()
:
.
.
: . -

.
4.

, .. robot arm.
:

1.1

Puzzle, , .

, .. MACSYMA
500 , , , .

(expert systems)
MYCIN ()
EL ( )
PROSPECTOR ()
XCON (hardware configuration)

INTELLECT
LIFER
LOQUI
(Learning)
-
->

.. (block world - )

ROBOT , , , .

.
,
, .

1.2
:
5

, ,
:




:
-
..

: Time flies like an arrow

:
: The spirit is willing but the flesh is weak
: vodka !

1.3
Newell & Simon:

.
.
.
.
( )
.

.
.
:
;
;
(knowledge) ( - belief).
;
;

..

: ;

pixels ;


;
(explicit) (implicit) ;

.
:
.
5 17
3 .
.

;


(. ) (
).

.
(17 5) 6000
.
, (6 3) , 20 .
17-5=12
4 ,
, 2 !
;
(Problem Solving) - (Search)
(Logic) - (Theorem Proving)
(Planning)
(Knowledge Representation)
(Machine Learning)
(Natural Language Understanding)
(Neural Networks)

LISP, PROLOG.
:

(
).
( )

;

.

(
). , ,
(
).
.
;
.


,
.

.
;
, ,
( )
. ,
.
;

( , , )

.
.

. '


.

:


, , .
"" ;
1. (
, , ...)
"" .
2. (search) .

.

. "crack"
(password) .
8 .
(~708)

.
(..
)
( "crack"
,
).


.

. , ,
9


.
3. (representation)
.



.
Fibonaci
( Pascal
C) ' GOTO
( Pascal
Fibonaci if ... goto ....).

.

1
'
.

4. (planning)


, .

.

.

10

2 : PROLOG
PROLOG

.
..
.
married (,).
(facts).
child (,).

child (,).

child (,).

child (, ).

child (,).

child (, ).

child (,).

child (,).

male ().

male ().

male ().

male ().

female ().

female ().

married (, ).

married (, ).

married (, ). married (, ).
:
?- child (, ).
YES
?- child (, ).
NO
?- child (X, ).
X=
?- child (,X).
X= ;
X=
?- child (X,Y).
X=
Y= ;
X=
Y= ;

11

?- child (X,), child (,Y).


X=
Y= ;

(rules)
/
.
grandchild (X,Y) :- child (X,Z), child (Z,Y).
1:
parent (X,Y) :- child (X,Y).
mother (X,Y) :- parent (X,Y), female (X).
father (X,Y) :- parent (X,Y), male (X).
sibling (X,Y) :- child (X,Z), child (Y,Z), notequal (X,Y).
sister (X,Y) :- sibling (X,Y), female (X).
2:
related (X,X).
related (X,Y) :- married (X,Y).
related (X,Y) :- child (X,Z), related (Z,Y).
related (X,Y) :- child (Y,Z), related (Z,X).
.
(goal). ,
.
(verifier goals) (finder goals). -
. :
:

?- child (,).

?- child (X,Y).

(recursive rules)
PROLOG.
D D P
, :
descendant (D,A) :- child (D,A).
descendant (D,A) :- child (D,P), descendant (P,A).

12

:
uncle (U,N) :- child (N,P), sibling (P,U), male (U).
uncle (U,N) :- child (N,P), sibling (P,Q), married (Q,U), male (U).
H PROLOG
: = + .
.
PROLOG

( - executor)
PROLOG.
PROLOG
: . :
grandchild (X,Y) :- child (X,Z), child (Z,Y).
()

,
.

()


Y.

:
literal :
P (t1, t2, ,tn)

(predicate) n

ti

(terms) . ,
m (function) f(x1, x2, ,xm).

(substitution) :
(x1=t1, x2=t2, , xN=tN)
xi=
ti=

13

PROLOG Horn Clauses

P Q1, Q2, Q3, ., Qn.


P Qi literals. P (consequent)
(antecedents).
clause (assertion).
clause (goal).
L literal L
L L xi
ti
:
= {X=son(), Y=U}

L = child(X,Y)

L = child(son(), U)

L = child(son(X), son())
L = child(son(son()), son())

2.1 (unification)
(unifies) literals L1 L2 L1 = L2.
.. L1=child(X,Y) L2=child(son(),U) ={ = son(),Y=U}
L1 = L2 = child(son(),U).

() , . :
parent(X,Y)

unify

parent(son(X), X)

:
parent(X,Y)

unify

parent(son(Z), Z).

14

2.2 PROLOG
PROLOG (firstorder predicate logic formulas) quantifiers, Horn clause
, . .

2.3
f (g (Ab, 2), 100)

s (np (art (Ta), n ()), vp (v() n ()))

Ab

100

np

art

vp

2.4
.. Pascal
type person = record
name: string;
address: string;
birth: array[1..3] of integer;
sex: boolean
end
PROLOG
person(name(N), address(A), birth(D.M.Y), sex(S)).

15

2.5 PROLOG

(dot) .
.. (a.(b.(c.d))) a . b . c . d . nil

[a,b,c,d]

nil

[]

ab.nil

[ab]

nil.nil.nil

[ [], [] ]

(a.nil) . (b.nil) . nil

[ [a],[b] ]

((ab.nil) . nil) . nil)

[ [ [ab] ] ]



1. nil nil
2. , (head, tail) head,
tail .
..

total (nil, 0).


total (Head.Tail, T) :- total (Tail, Subtotal), T=Head+Subtotal.

total(L,N) .
: length (L,N)
length (nil,0).
length (Head.Tail,N) :- length (Tail,M), N=M+1.

length ([],0).
length ([H | Tail], N) :- length (Tail,M), N=M+1.

16

: member (X,L)
member (X, [X | Tail]).
member (X, [Head | Tail]) :- member (X,Tail).
: pick (X,L1,L2)
pick (X, [X | Tail], Tail).
pick (X, [Head | Tail], [Head | Rem]) :- pick (X, Tail, Rem).
: append (L1,L2,L3) ( L1 L2 L3)
append (nil, L, L).
append ([H | T], L, [H | P]) :- append (T,L,P).
:
?- append (L, L, [a,b,d,a,b,d]).
L = [a,b,d]
?- append ([a,b], [c], L3).
L3 = [a,b,c]
?- append (X, [b,c], [a,d,b,c]).
X = [a,d].
input output
.
: QUICKSORT
1.
qsort ([],[]).
2. , Head

.
qsort ([ H | T ], S) :-

partition(H,T,L1,L2),
qsort (L1,S1),
qsort (L2,S2),
append (S1, [H | S2], S).

17

partition (P, [H | T], [H | L1], L2) :- gt (H,P), partition (P,T,L1,L2).


partition (P, [H | T], T1, [H | L2]) :- le (H,P), partition (P,T,L1,L2).
partition ( _ , [], [], []).
partition P
(pivot) Head L.

L1 L2.

2.6 (Unification)
,
( unifiers);
1. literals (L1 clause C1 L2 clause C2)
.
2. unifier
literals
L1 = P(t1, t2, ., tk)
L2 = P(t1, t2, ., tk)
t1 t1, t1 t2, ., tk tk .
3. t1 t2 :
()

t1 ( t2) : =t2

()

t1 = f (q1, q2, , qm)

t2 = f (r1, r2, , rm)

q1 r1, q2 r2, .

.
:
L1 = parent (X,Y)
L2 = parent (Y,son(Z))
parent (W,son(Z))
= {X=W, Y=son(Z)}

18

2.7 SUBGOALS
goal
:- A1, A2, , Ai, , Am (m >=1)
clause
B :- B1, B2,., Bk
. goal unifier Ai
B
:- A1, A2, , B1, B2,., Bk, , Am (m >=1)
:
:- parent (X, ), parent (, Y)

parent(U,V) :- spouse(U,W), parent (W,V)

{U=, V=Y}

:- parent (X, ), spouse(,W), parent (W,V).

2.8 PROLOG;
.
: P, goal G,
R PROLOG :
1. G
2. goal
3. A1, A2, , Am, , An , R
Am. T A :- B1, B2, ., Bl Am A ,
(A1,,Am-1, B1, ,Bl, Am+1, , An) A1, A2, , An.
4. clause ( ) .

19

:
r1

descendant (D,A) :- child (D,A).

r2

descendant (D,A) :- child (D,P), descendant (P,A).

child (,).
child (,).
child (,).
child (,).
child (,).
:

?- descendant (, )

descendant (, )

r1

r2

child (, )

child (, )
descendant (X, )

X=

r1

[ ]
child (, )
child (, )

[ ]

20

2.9 PROLOG;
:
LEFT TO RIGHT
TOP TO BOTTOM
PROLOG !
:
(1)

p(a,b).

(2)

p(c,b).

(3)

p(X,Z) :- p(X,Y), p(Y,Z).

(4)

p(X,Y) :- p(Y,X).

:- p(a,c)
:-p(a,c)
4

p(c,a)

p(a,Y), p(Y,c)
1

p(b,c)

...

...

...

p(c,b)

p(b,Y), p(Y,c)
3

p(Y,a),p(Y,c)

p(a,Y1), p(Y1,Y), p(Y,c)

p(b,Y'),p(Y',Y),p(Y,c)

4
...

[]

...

21

4
...

...

2.10 PROLOG
Goal literals left-to-right
goal literal, top-to-bottom clause
(consequent) (unifies).
, , body clause goal
list.
, goal backtracking (.
goal literals goal list).
goals
.
:
;

:
walk

pushbox

climbbox

reach

22

4-tuple:

(, , , )

(states)


:
= = (pm, pb, bbox bgrasp?)
pm = position of monkey -
pb = position of box -
bbox = boolean, monkey on box? - ;
bgrasp? = boolean, monkey has banana? - ;
pi {X | X Room}
bi {yes,no}

= (atdoor, atwindow, no, no)

= { ( _ , _ , _ , yes) }

PROLOG
state (X, Y, Z, W)

move (S1, M, S2)
S1 =
M =
S2 =
:
move (state (middle, middle, yes, no), reach, state (middle, middle, yes, yes)).
move (state (P, P, no, H), climbbox, state (P, P, yes, H)).
move (state (P1, P1, no, H), pushbox(P1,P2), state (P2, P2, no, H)).
move (state (P1, B, no, H), walk(P1,P2), state (P2, B, no, H)).
:

23

canget (state ( _ , _ , _ , yes)).


canget (S1) :- move (S1, M, S2), canget (S2).
:
?- canget (state (atdoor, atwindow, no, no)).

state (atdoor, atwindow, no, no)

reach

no

climb

push

no

walk(atdoor,P2)

no

state (atdoor, atwindow, no, no)


reach

no

climb

state (atdoor, atwindow, yes, no)

reach climb

no

no

state (atdoor, atwindow, no, no)

walk push

no

push (P2, P2')

backtrack

reach

no

no

climb

state (P2', P2; yes, no)

reach
P2' = middle

state (middle, midle, yes, yes)

2.11 PROLOG
Prolog .

.
Prolog
ISO.

Prolog
. %

24

. /*
*/ .
.
:
% this is a comment that ends at the end of the line
/* this is a multiple line comment
*-()-()-/-/-()-()-*
..that ends here */
()
(atoms)
Prolog. :
(a..z)
.
'_' (underscore) .
.
:
hello,

mother,

'this is an atom',

f15_x7_sky,

m88,

'don''t panic',

'Athens'.

Prolog
. .
:
123,

814,

-93,

12.4,

-0.01,

97.0

Prolog .
'_'.
,
(..) '_' ,
'_'. '_'
.

25

:
X,

John,

X13,

Fire_987,

_big_variable,

_98765

Prolog ,
literal. ( )
. ..
halt.
.
:
.

( .

,. , ,
.

).
:
child(oidipous, iokasti)
male(oidipous)
bought(Student, book(title(Programming in Prolog),author(W.F.C. C.S.M.)))
Unusual name(X, 98,0.09876)

.

..
, ,
[ , ] |. [] (
nil). .
.
:
[]

nil

[]

26

.(a, [])

(a.nil)

[a]

.(a, b)

(a.b)

[a | b]

.(a, .(b, [])) (a.(b.nil))

[a,b]

.(a, .(b, c)) (a.(b.c))

[a,b | c]

,
, , .
:
[1, 2, 74, hello, 93, male(oidipous)]
[this is the head of the list, this list is a list of atoms , last atom]
[

[a1,a2,[

b1

b2]

],c2,c3

[d1,d2]]

((a1.(a2.((b1,b2).[]))).(c2.(c3.(d1.(d2.[])))))

.
Prolog
.

. = =(,)
.

. 2*7+3
+(*(2,7),3)) *(2,+(7,3)).
:

x1 :- x2

1200

x2 x1 (Horn Cause).

x;y

1100

x OR y ( x y)

x,y

1000

x AND y ( x y)

x1 = x2

700

x1 x2

x1 \= x2

700

x1 x2

x1 == x2

700

x1 x2

x1 \== x2

700

x1 x2

x1 is x2

700

x1 x2

x1 =:= x2

700

x1 .

27

x2
x1 =\= x2

700

. x1 .
x2

x1 < x2

700

x1 x2 ( >, =<,
>=)

y+x

500

x1 x2 ( x - y)

y*x

400

y x ( y / x )

y // x

400

y x

y mod x

400

y x

:
10 + 20
X is 30 + 4 * 4 / 9.5
30*2+5=:=65
85//2=\=42.5
30*2+5\==65
a(X,L):- b(X,Z), c(Z,L)
a(X) = a(3)
b(3,4) \= b(3,5)
-
(, ,
, ) .
. 2(+)2
.

. AND
.


.
.
true/0 ,
. (: true/0
true 0 )

28

false/0
(backtracking).
repeat/0
.
repeat goal literal
repeat
repeat. Prolog
repeat ( ) goal literal
repeat. repeat
:
repeat.
repeat :- repeat.
! ( cut)

.
(side effects). !
goal literal
! .
cut .

2.12

X,Y

X Y

X;Y

(X.Y)

{ : [|] }

X=Y

X\=Y

X==Y

X\==Y


var(X)

nonvar(X)

var(X)

atom(X)

integer(X)

float(X)

[: real(X)]

29

atomic(X)

name(A,L)

L
.


!
repeat
true

false

not(X)

call(X)

halt

X is Y

X+Y

X-Y

X*Y

X/Y

//

X mod Y

X<Y

X>Y

X =< Y

X >= Y

X =:= Y

X =\= Y

( : cos, sin, abs, log, ...)


-
get0(X)

get(X)

ASCII
>=32.

read(X)

X .

put(X)

nl

30

tab(X)

write(X)

display(X)

see(X)

. (
user )

seeing(X)

seen

tell(X)

telling(X)

told


asserta(X)

assertz(X)

retract(X)

functor(T,F,N)

T F .

arg(N,T,A)

- .

X=..L

L
.


consult(X)

- .
.

reconsult(X)

- .

.

listing

listing(A)

2.13 !
! ( cut)
Prolog.
.

31

:
A :- B, C , D.
:- E, F.
B, C D
E F.
(goal) Prolog1 A
B, C, D E
F. B, C, D, E, F .
Prolog
.
, C D.
Prolog (backtracking point)

( E F).
. :
B :- B1.
B :- B2.
. Prolog
B1
.
1 , . Prolog, ,
C
D. C D .
D Prolog (backtrack)
. B2. 2

E F.
C !. :
A :- B, ! , D.
A :- E, F.

32

Prolog
.
, Prolog 1.
B1 . Prolog
!.
.
!.

. , D

B2, E F.
!
( !)
! .
!.
!
.
! .

.
! :
.
sum_to(, S) :
sum_to(1,1) :- !.
sum_to(,S) :- = - 1 , sum_to(, R) , S=R + M.


1 .
! 1
1 1
. ,

: Prolog Prolog

33


. !
sum_to(3,7) .
IF THEN ELSE !.
IF THEN ELSE
A :- B, ! , C.
A :- D.
C
D.
!
C D.
.

.


, ,
.

.
:
(FamilyMembers, Income, Grade, Athens, Money) :- B(FamilyMembers,
ncome, X), C(Grade,Y), Money = X * Y * 1.7.
(FamilyMembers, Income, Grade, Patra, Money) :- B(FamilyMembers,
ncome, X), C(Grade,Y), Money = X * Y * 1.2.
(FamilyMembers, Income, Grade, Larisa, Money) :- B(FamilyMembers,
Income, X), C(Grade,Y), Money = X * Y * 3.7.
.
,
(Grade) 7,

.
.
! fail

34


.

7,
.
(FamilyMembers, Income, Grade, City, Money) :- Grade < 7.0, !, fail.
(FamilyMembers, Income, Grade, Athens, Money) :- B(FamilyMembers,
Income, X), C(Grade,Y), Money = X * Y * 1.7.
(FamilyMembers, Income, Grades, Patra, Money) :- B(FamilyMembers,
Income, X), C(Grade,Y), Money = X * Y * 1.2.
(FamilyMembers, Income, Grades, Larisa, Money) :- B(FamilyMembers,
Income, X), C(Grade,Y), Money = X * Y * 3.7.
.
Grade < 7.0 !

.
!. fail
.
.


! .

!

.

35

3 -
3.1

.
( ) . ,
.


.

2
() 100 . 1
1 40 .
4
10000 2 45
.
8
, 3
.
, ,
. ,
,
.

8
. ,

.
.
.

-
.

37

. ,
,
.
,
.

3.2
(missionaries & cannibals)
3 3 .
2 .
:

.

,
.
.


.
A

canniba
l

canniba
l

canniba
l

missionar
y
missionar
y

missionar
y

8 (8 puzzle)
3 x 3 (9 ).
1 8.
.

38

:

.
:

(block world)
3 : , B, C.
C B .


( ).

.
C , B C .

39

(Traveling Salesman Problem - TSP)



. .
.

,
.

C1
C2

C3

C4

C5

B
C6

C8
C7
C9
C10

F
C12
C11

C13

D
C15

C14

12 (12 coins)
12 (
).
3 .

.
.

40

(Road-map)
,
,
.

50

150
141

197

144

210

120

80

100

60

60
40

26

80
92

120

212

140
100

80

45

90

80

75

8 (8 queens)
8 .

. , ,
.
:
2 .

41

3.3
.
.

(.. 8 ).
()
(..
).

. , ,
.
.


.
.

.

42

. ,
. (..
, ) .

.
,
.

.

.

3.4

:
1.
2.
3.
4.
5.
4
.
.
. ,

. ,

.

.

. d(s)
.
.

43

.

.

.

. 7 : 3
, 3 1

.

3
.

.
.
.
.
.
: (x, y, z)
:
(x=0 x y) (3-x = 0 3-x >= 3-y)


.
1: (x, y, ) (x-1,
y, B) x > 0.
2: (x, y, ) (x-2,
y, B) x > 1.
3: (x, y, ) (x, y1, B) y > 0.
4: (x, y, ) (x, y2, B) y > 1.

44

5: (x, y, ) (x-1,
y-1, B) x > 0 y > 0.
6: (x, y, B) (x+1,
y, A) x < 3.
7: (x, y, B) (x+2,
y, A) x < 2.
8: (x, y, B) (x,
y+1, A) y < 3.
9: (x, y, B) (x,
y+2, A) y < 2.
10: (x, y, B) (x+1,
y+1, A) x <3 y < 3.
(3,3,) : (0,0,).

.


. ,

.
.

.


.
4

45

3, 3, A

3, 2, B

3, 3, A

2, 2, B

3, 1, B

3, 2, A

2, 3, A

3, 3, A

......

......

3, 0, B

3, 1, B

2, 3, B

1, 3, B

3, 2, A

3, 3, A

......

......

2, 2, B

1, 2, B

2, 1, B


.


. ,

.
3, 3, A

3, 1, B

3, 2, B

2, 2, B

1, 3, B

2, 3, B

3, 2, A
2, 3, A

1, 2, B
2, 1, B

3, 0, B

2, 0, B
3, 1, A

1, 3, A

2, 1, A

1, 1, B

1, 2, A
2, 2, A

1, 1, A

0, 2, B

0, 3, A

0, 1, B

46

0, 2, A

0, 0, B

3.5

- .
(Divide and
conquer).
. ,
.

.
:
.
.

AND-OR:

OR

....................

-

........

........

OR

........

........

-

AND

........

47

........

AND

3.6

. :
,
,
.

( ).
d(s).

(
d(s) ). d(s)
. , d(s)

s. , d(s)
.

:

13

22

33

107

34

22

16

27

48

44

27

16

10

16

28


d(s). .

b ( b)
m. .

:
1. (queue) (root).
2. ,
.
2. .
2. , :
-
-
3. , , , .

: A, B, D, F, G, I
.
1

B
4

13

22

33

107

34

22

16

27

49

44

27

16

10

16

28

(bm) (bm).
m
.
b .

d(s).

:
1. (queue) (root).
2. ,
.
2. .
2. , :
-
-
3. , , , .

: A, B, F, M, G, M, N, T
.
1

B
3

13

22

27

10

22

107

16

16

33

34

27

50

44

16

28

(bm) (bm).

.

d(s).
(Hill Climbing)
. Hill
Climbing
.

Hill Climbing (
) .
d(s)
.
:
1. (queue) (root).
2. ,
.
2. .
2. , :
-
-

3. , , , .

: A, B, G, N, V
.

51

13

22

27

10

22

107

16

16

33

34

27

44

16

28


.


.
.
:
1. = 1
2.
.
2.1. 1
2.2. (queue) (root).
2.3. :
2.3.. .
2.3.. .
2.3.. , :
-
-
:
-
-
3. , , , .

52

: A, B, D, A, B, F, G, D, I
.
1,4

2,5

3,8

13

22

33

107

34

22

16

27

44

27

10

16

16

28

(bm) (bm).
m
.
b .

d(s).

:
1. (queue) (root).
2. ,
.
2. .
2. , :
-
-
- d(s) (
)
3. , , , .

53

d(s)
.
: A, B, D, G, K, F, R
.
1

B
6

13

22

27

10

22

33

107

34

16

27

44

16

16

28

(bm) (bm).
.

.

. , d(s)
d(s)
.


.
d(s) k
.
.
:

54

1. (queue) (root).
2. ,
.
2. .
2. , :
-
-
k .
3. , , , .

k=1
: A, B, G, N, V ( ).
k=2
: A, B, D, G, F, , I .
1

B
5

13

22

107

33

34

22

16

27

44

27

16

10

16

28


. (km)
O(km) O(km)
.


55

.

.
O(bm/2)
.

.
.
.
.
. ,
(
).
.

.

3.7

. , ,

.
. ,


. ,


. ,

.
,
.

56

. ,
. , ,
.
,
.

.

.
8 :
h1 = .
h2 =
.

,
.
, . ,
, .

.
.
, 12

8
.
,
.

.
. ,
.

57

h2



(
1).

3.8

. (
)
.
d(s)
s h(s)
s -.
.

- h 0.
h(s) (
) d(s) ( ).
.

58

21

20

13

22

0
8

3
107

56

33

76
22

27

0
16

0
34

38
27

43
44

10

16

1
16

28

(Greedy search)

:
1. (queue) (root).
2. ,
.
2. .
2. , :
-
-
- h(s) (
)
3. , , , .

59


h(s)
d(s). *

.
,
: A, B, G, M, N, T.

21

2
7

20

8
2

6
13

2
22

6
0

33

0
8

107

56

76
22

27

10

0
16

0
34

38
27

43
44

16

1
16

28

(bm) (bm).
.

.


, d(s).

60

*

. f(s) = d(s) + h(s).


. f(s)
s.
* h(s)
. ,
, h(s) (
) . f(s)
s.
f(s)
.
* , .

:
1. (queue) (root).
2. ,
.
2. .
2. , :
-
-
- f(s) ( )
3. , , , .

: A, B, G, D, K, R
.

61

21

2
7

20

8
2

6
13

5
0

76
22

27

10

6
2

22

3
107

56

33

0
16

0
34

38
27

43
44

16

1
16

28

(bm) (bm).
f(s)
. ,
f(s)
.

.

O(bm)
O(bm)
O(bm)
O(bm)

O(bm)
O(bm)
O(bm)
O(bm)

O(bm)

O(bm)

d(s)

d(s)

O(km)

O(km) O(km)

O(bm)

O(bm)

h(s)

OXI

O(bm)

O(bm)

62

3.9

.

. ,
, ,

- .
, , Claude Shannon Alan Turing,
. ,

.

.

,
. ,
.
,
.

.
,

.
. , ,
.


(
). MAX .
MAX
MIN .

63


.
.
( )
1 , 0 -1
.

7 (Grundys game).
7 .
. ,
.
.

MAX.

7, MAX

6, 1, MIN

5, 2, MIN

5, 1, 1, MAX

4, 3, MIN

4, 2, 1, MAX

4, 1, 1, 1, MIN

3, 2, 2, MAX

3, 2, 1, 1, MIN

3, 1, 1, 1, 1, MAX

3, 3, 1, MAX

2, 2, 2, 1, MIN

2, 2, 1, 1, 1, MAX

2, 1, 1, 1, 1, 1, MIN

( MAX)

. MIN
.

64

AND-OR.

OR

MAX
AND MIN .
MAX ( OR )
MIN ( OR ) MAX.
AND-OR
.

5, 2

6, 1

5, 1, 1

4, 1, 1, 1

3, 1, 1, 1, 1

4, 2, 1

3, 2, 1, 1

2, 2, 1, 1, 1

4, 3

3, 2, 1, 1

4, 2, 1

3, 2, 2

4, 2, 1

3, 2, 1, 1

2, 2, 1, 1, 1

2, 2, 2, 1

2, 2, 1, 1, 1

3, 2, 1, 1

2, 2, 1, 1, 1

3, 3, 1

3, 2, 1, 1

2, 2, 1, 1, 1

2, 1, 1, 1, 1, 1


OR , (
MAX) (, AND
MIN)
.
(, ).

65

-

.
-
- :
( AND-OR).
(
) MAX
.

:
MAX (AND )

.
MIN (OR )

.


.
7
(1 MAX -1 MIN).

AND-OR. ,

.
AND-OR
-
.

66

-1

-1

-1

5, 2

3, 1

-1

5, 1, 1

3, 2, 1, 1

-1

3, 2, 1, 1

2, 2, 1, 1, 1

-1

3, 2, 1, 1

-1

2, 2, 1, 1, 1

-1

2, 2, 1, 1, 1

-1

-1

3, 2, 1, 1

3, 2, 1, 1

-1

2, 2, 1, 1, 1

3, 3, 1

4, 2, 1

-1

3, 2, 1, 1

-1

3, 1, 1, 1, 1

3, 2, 2

4, 2, 1

-1

4, 1, 1, 1

-1

4, 2, 1

-1

4, 3

-1

2, 2, 1, 1, 1

2, 1, 1, 1, 1, 1


MAX ,
MAX .

MAX.

MIN-MAX

. ,

.
, ,
,
.

. ,
. , ,

67

. , ,
.

.


.


.
,
, MIN-MAX
.
Alfa-Beta .

MIN-MAX Prolog
.
Prolog state(Player, Board), Player
x Board 9 .
,
.
x, , e.
e .
x, state(x,[e,e,e,e,e,e,e,e,e])
.

. , minmax
MIN-MAX
. , minmax
MIN-MAX .
.
x.
triliza.
Board (
e). .
:

68

% The starting predicate


triliza:loop(state(x,[e,e,e,e,e,e,e,e,e])).
% Loop until someone wins the game
loop(State):staticval(State,2), !,
minmax(State,state(_,NewXTab),Val),
write('My move : '),write(NewXTab),write(' Value= '),write(Val),nl,
other_player(NewXTab).
loop(state(_,Tab)):write('Final

: '), write(Tab), nl,

write('Player o wins !'), nl.


% Simple interaction with the player
other_player(Tab):staticval(state(o,Tab),2), !,

% if the game is not already lost

write('Enter possition (1..9): '),read(N), nl,


play_at_N_pos(Tab,N,o,NewOTab),
write('Your move: '),write(NewOTab),nl,
loop(state(x,NewOTab)).
other_player(Tab):write('Final

: '), write(Tab), nl,

write('Player x wins !'), nl.


% Define which player is the min and which the max
min_to_move(state(o,_)).
max_to_move(state(x,_)).
minmax(Pos, BestSucc, Val):moves(Pos, PosList), !,
best(PosList, BestSucc, Val).
minmax(Pos, Pos, Val):staticval(Pos, Val).
best([Pos],Pos,Val):minmax(Pos,_,Val),!.
best([Pos1|PosTail],BestPos,BestVal):69

minmax(Pos1,_,Val1),
best(PosTail,BestTail, TailVal),
betterof(Pos1,Val1, BestTail, TailVal, BestPos, BestVal).
betterof(Pos0, Val0, _, Val1, Pos0, Val0):min_to_move(Pos0),
Val0>Val1, ! ;
max_to_move(Pos0),
Val0<Val1, !.
betterof(_, _, Pos1, Val1, Pos1, Val1).
% Generate all possible next states
moves(Pos,PosList):staticval(Pos,2),findall(X,make_a_move(Pos,X),PosList), PosList\=[].
% Generate a move
make_a_move(state(Player,Table),state(NextPlayer,NewTable)):member(N,[1,2,3,4,5,6,7,8,9]),
play_at_N_pos(Table,N,Player,NewTable),
switch_players(Player,NextPlayer).
% Define which is the next player
switch_players(x,o).
switch_players(o,x).
% Modify state
play_at_N_pos([e|Tail],1,Player,[Player|Tail]):- !.
play_at_N_pos([Head|Tail],N,Player,[Head|NewTail]):N>1, NewN is N - 1,
play_at_N_pos(Tail,NewN, Player, NewTail).
% All the winning states
staticval(state(_,[x,x,x,_,_,_,_,_,_]),V):- !, V=3.
staticval(state(_,[_,_,_,x,x,x,_,_,_]),V):- !, V=3.
staticval(state(_,[_,_,_,_,_,_,x,x,x]),V):- !, V=3.
staticval(state(_,[x,_,_,x,_,_,x,_,_]),V):- !, V=3.
staticval(state(_,[_,x,_,_,x,_,_,x,_]),V):- !, V=3.
staticval(state(_,[_,_,x,_,_,x,_,_,x]),V):- !, V=3.
staticval(state(_,[x,_,_,_,x,_,_,_,x]),V):- !, V=3.
staticval(state(_,[_,_,x,_,x,_,x,_,_]),V):- !, V=3.
staticval(state(_,[o,o,o,_,_,_,_,_,_]),V):- !, V=1.
staticval(state(_,[_,_,_,o,o,o,_,_,_]),V):- !, V=1.
staticval(state(_,[_,_,_,_,_,_,o,o,o]),V):- !, V=1.

70

staticval(state(_,[o,_,_,o,_,_,o,_,_]),V):- !, V=1.
staticval(state(_,[_,o,_,_,o,_,_,o,_]),V):- !, V=1.
staticval(state(_,[_,_,o,_,_,o,_,_,o]),V):- !, V=1.
staticval(state(_,[o,_,_,_,o,_,_,_,o]),V):- !, V=1.
staticval(state(_,[_,_,o,_,o,_,o,_,_]),V):- !, V=1.
% else we have a draw
staticval(_,2).

lfa-Beta
Alfa-Beta
. Alfa-Beta
MIN-MAX
.
,
:
(1, 2, ..., Xk-1, Xk) = MIN (1, 2, ..., Xk-1) i 0<i<k Xk > Xi.
AX (1, 2, ..., Xk-1, Xk) = MAX (1, 2, ..., Xk-1) i 0<i<k Xk < Xi.
MIN-MAX
MAX ( )
. , , MIN .

( )
.

. , .
Alfa-Beta .


.
_()
.

_()
.
71

, , Alfa Beta.
Alfa
MAX . Beta
MIN
. O

( )
.


.
Alfa-Beta
Alfa-Beta . MAX
Alfa
: MAX .

.

. Beta .
, Beta .
Alfa-Beta
:
MAX Alfa Beta.
M Beta Alfa.
:


, , . ,
- .

:
1. = .

72

2. = .
3. = MAX.
4. H minmax
TIMH_MAX(, , )

_(, , )
1. _() _().
2. .
2.1. = (, _(, , ))
2.2. .
3. .
_(, , )
1. _() _().
2. .
2.1. = (, _(, , ))
2.2. .
3. .
Alfa-Beta
: O, I, T, U, Y. ()
(
TIMH_MAX TIMH_MIN ). , F, C, K
MINMAX .
8

-2

73

4 :
.
4.1
,
(Natural Language Processing: NLP) .
' ,
.

4.2
,
- .


* * .

, ,
.

,
.
' ,

.
,
(Information Science)
(Artificial Intelligence).

.
,

(Computational Linguistics),
.

(Linguistic Engineering).

75

,
,

.

,
, (software
system).


: , , , , .

(artificial intelligence)
.

(formal languages)
.

, .

4.3


.
-

' .

.

:


,
.

76

. ,
(, , .).

(scanners)

(optical character recognition : O.C.R.)


(character set codes).
,
(word processor)
(text editor).

(keyboard driver)


. ,
,
,
.

, ,

, .
-
,
(understanding)
.
(identification)

:
, .. ,

: C. S. Moraitis, J. G. Maistros, "A Model Describing Connectivity and its


Application to Binary Picture Compression", International 84 AMSE Conference "Modeling and
Simulation", 1984,
C. S. Moraitis, J. G. Maistros, "A Model Describing Digitized Images",
International Symposium Applied Informatics", Switzerland, 1985,

, , .
. .
3
- ( 1000).
77

(finite state automaton, augmented transition

network: ATN),
, .. .
(pattern matching),
.
, ,
.
,
,

(knowledge representation)
.

.
.
.
,

.


.
.
.
, , , ,
,
.

(formatting)
.

'

John Lyons
78

.
,
(speech generation)
.

4.4

.

. ,
, ,
(formatter).

,
, , , , , , , ,
, .. ,


.
.
,
, '

. ,

, (bytes)
(patterns)
.

(speech recognition).
,

79

(strings).

, , - (response)
.

4.5


:
.
, '
6.
, ,
.

,
, .
(shift).

, .

, ,
.

. .
,
- -
,
, .
(sorting).
, .
5

*Semantics* NEW HORIZONS IN LINGUISTICS 2, Penguin Books,


1987.
6
EOT 927, 928 (ISO 8859/7), 10646: E X
(Coded Character Sets).
80

, ,
, ,
.

, (,)

( )

,
, ,
7 .
8. (transcription)
(transliteration)
. , ,

, .


(script)

.

(Hyphenation).

,
(format) , .. .


, (word
processors) (text editors) ,
(desk top publishing) (photo-composition).
.. ,

.
7

. : . - . ,
, "-84", ,
1984.
8
,
, , , . ,

81

,
, ,
.

)
9.
- . (corpus)

.
(compact disks).

.
(Text Data Bases), ,
, .

.
Thesaurus Linguae Graecae
Irvine California
.
-

(KeyWords In Context : KWIC

Concordances).

,
. ,
, , ,
.
Index. -
(stop words) , (index) .
,
.
.
.

,
, 1995.

82

(knowledge

representation techniques) .
.
(Data Base Interface)

10


,
11.

,
.
' (.. C,
Pascal, LISP), (.. Prolog)

12

. ,


( ,
).

, -
(Query Languages)
- .


(command language) .

(Spelling

Check,

Error

Correction).
, ,
, ,

. ,
,

9

743 ISO 843.


. , ,
,
, A 1991.
11
:
Androutsopoulos I., G.D. Richie, P. Thanisch, Natural Language Interfaces to Databases - An
Introduction, Research Paper no 709, Dept. of AI, Univ. of Edinburgh, 1994.
12
Shwartz P. Steven, Applied Natural Language Processing, Petrocelli Books, 1987.
10

83

.
.
,
,
(, )
, .
(Syntax Checker).
, .

,
. ,

13 .
.

.

,
.
(unification)
- (attribute - value pair).

(parsing).
.
.
(hangman)

14

.
.
.
,
13

: ., K E
E B , K..E. , 1988.
14
: () . ,
, ,
, A 1991, () ., K

84

(Computer Aided Learning)


.
.
(Machine Translation).
**
.
.

. ,

,
.
,

, .
: METEO EUROTRA
( )15.
.
(icons)
( ). ( Graphics
User Interface: GUI )

16

17

() -
( ).

A E , E,
T - E.M.. 1986.
15
()
, , 1984.
16
.
17
Windows 3.1.1, Windows '95 / NT, X-Windows (Unix)
85

4.6

, , , .

,

,
.
, , , :
, ,
, ,
,
(interface) ,
(hyphenation),
(concordance list keywords in context:
KWIC) ' ,
(error check,
correction),
2-, 3- ... n-
,
(text normalization),
(formatters)
(content
characters),
(transcription) (transliteration)
.
,
, ' :
,
- ,
.


(Artificial Intelligence)
86

(Knowledge Representation).


,
.

, ,
.

,
, , .

4.7 B
E (, )
Aho A. N. - J. D. Ullman, The theory of Parsing, Translation and Compiling,
Prentice Hall, 1972.
Aho A. N., Pattern Matching in Strings, Symposium on Formal Language Theory,
Santa Barbara, Univ. of Callifornia, 1979.
Bechtel W. Abrahamsen A., Connectionism and the Mind, Blackwell, 1991.
Chartres B. A., J. J. Florentin, A Universal Syntax Directed Top-Down Analyzer,
Journal of the Association for the Computing Machinery, Vol. 15, No 3, July
1968, pp 447-464.
Dix A., J. Finlay, G. Abowd, R. Beale, Human Computer Interaction, Prentice
Hall, 1993.
Kernighan Brian - Rob Pike, The UNIX Programming Environment, Prentice
Hall, 1984.
Moraitis C. S., J. G. Maistros, A Model Describing Connectivity and its
Application to Binary Picture Compression, International 84 AMSE Conference
Modeling and Simulation, 1984.
Moraitis C. S., J. G. Maistros, A Model Describing Digitized Images, International
Symposium Applied Informatics, Switzerland, 1985.
Papakonstantinou George, A Recursive Algorithm for the Optimal Conversion of
Decision Tables, Angewandte Informatik, vol. 9, 1980.
Russel S., P. Norvig, Artificial Intelligence - A Modern Approach, Prentice Hall,
1995
E -

87

A Compilation of Papers on Unification - Based Grammar Formalisms - Part I &


II, Report No : CSLI-86-48, Center for the Study of Language and Information,
Stanford.
Androutsopoulos I., Interfacing a Natural Language Front-End to a Relational
Database, MSc. Dissertation, Dept. of AI, Univ. of Edinburgh, 1992.
Androutsopoulos I., G.D. Richie, P. Thanisch, Natural Language Interfaces to
Databases - An Introduction, Research Paper no 709, Dept. of AI, Univ. of
Edinburgh, 1994.
Beale Andrew David, Grammatical Analysis by computer of the LOB Corpus of
British English Texts, Proceedings of the 23rd Annual Meeting of the ACL, 1985.
Bear John, A Morphological Recognizer with Syntactic and Phonological Rules,
Proc. of the 11th International Conference on Computational Linguistics
(COLING 86), Bonn August 1986
Calzolari Nicoletta, Lexical Definitions in a Computerized Dictionary, Computers
and Artificial Intelligence, Vol 2, No 3, June 1983.
Cercone Nick (Editor), Computational Linguistics, Pergamon Press.
Cherry L. L., PARTS - A System for Assigning Word Classes to English Text,
Computing Science Technical Report #81, Bell Laboratories, Murray Hill, NJ,
07974, 1978.
Dahl V. and P. Saint-Dizier (Editors),

Natural Language Understanding and

Logic Programming, Elsevier Science Publishers B. V. (North Holland), 1985.


Eeg-Olofsson Mats,

A Probability Model for

Computer-aided Word-Class

Determination, ALLC Journal, vol. 5, 1985.


Garvin L. Paul, The Current State of Language Data Processing, Advances in
Computers, Vol. 24, 1985.
Gazdar G., Klein E., Pullum G. and Sag I., Generalized Phrase Structure
Grammar, Blackwell, 1985.
Johnson Mark, Attribute-Value Logic and the Theory of Grammar, Center for the
Study of Language and Information, Stanford Univ., 1988
Karttunen

Lauri,

Features

and

Values, Proc. of the 10th International

Conference on Computational Linguistics (COLING 84), Stanford July 1984.


Karttunen Lauri, KIMMO: A General Morphological Processor, Texas Linguistic
Forum 22, 1983.
Karttunen Lauri, The Relevance of Computational Linguistics, SRI, Stanford
Univ., 1986.

88

Koktova Eva, Towards a new type of morphemic analysis, 2nd Conference of


the European Chapter of the ACL, Geneva March 1985.
Koskenniemi Kimmo, Two-Level Morphology - A General Computational Model
for Word-Form Recognition and Production, Univ. of Helsinki, Dept. of General
Linguistics, Publications No 11, 1983.
Krause W. and G. Willee, Lemmatizing German Newspaper Texts with the Aid
of an Algorithm, Computers and the Humanities 15, 1981.
Kummel Peter,

Formalization of Natural Languages, Springer-Verlag, Berlin

Heidelberg New York, 1979.


Lea A. W. (Editor), Trends in Speech Recognition, Prentice Hall, 1980.
Lyons John et al Editors, New Horizons in Linguistics 2, Penguin Books, 1987.
Markantonatou S. and L. Sadler (ed), Grammatical Formalisms - Issues in
Migration, Commission of the European Communities, 1994
Pereira Fernando, A Structure Sharing Representation for Unification - Based
Grammar Formalisms, Proc. of the 23rd Annual Meeting of the Association for
Computational Linguistics, Chicago, July 1985.
Proceedings

Association for Computational Linguistics (ACL)

COmputational LINGuistics (COLING), 1984 - 1986


Ritchie

Graeme,

Stephen

Pulman,

Alan

Black,

Graham

Russell,

Computational Framework for Lexical Description, Research Paper No. 293,


Department of Artificial Intelligence, University of Edinburgh, 1986.
Robinson B. J., DIAGRAM : A Grammar for Dialogues, Comm. of the ACM, Vol.
25, No 1, 1982.
Scott Dana, Domains for Denotational Semantics, ICALP 82, Aarhus Denmark,
July 1982.
Selkirk Elisabeth, The Syntax of Words, MIT Press, 1982.
Shieber Stuart, The Design of a Computer Language for Linguistic Information,
Proc. of the 10th International Conference on Computational Linguistics,
(COLING 84), Stanford, July 1984.
Shwartz P. Steven, Applied Natural Language Processing, Petrocelli Books,
1987.
Uszkoreit Hans Categorial Unification Grammars COLING 86.
Wehrli Eric, Design and Implementation of a Lexical Data Base, 2nd Conference
of the European Chapter of the ACL, Geneva, 1985.
Winograd, Terry,Language as a Cognitive Process, Vol. I: Syntax, AddisonWesley, 1983.

89


., , , 1967. A.
Mirambel, La Langue Grecque Modern - Description et Analyze, Klincksieck,
Paris, 1959.
Lembessi Z. - P., A Morphological Analysis of the Nominal Group of Greek
employing a computational model, M.A. Dissertation, Faculty of Arts, Exeter
Univ. 1988.
Mackridge Peter, The Modern Greek Language : A Descriptive Analysis

of

Standard Modern Greek, Oxford University Press, 1985.


., , 2 , , 1946/1953

1978 (1941).
E
.,
, , , A
1991.
. - . ,

, "-84", ,
1984.
., Metodi Quantitativi e Informatici per l' Analisi del Testo
Letterario - Il "caso" delle Canzoni Popolari Greche e la Loro Versione in Italiano,
, 1984.
Eurotra - Preparatory Phase, Final Report, Eurotra Greek Language Group,
A - P 1985.
K, . M, A N , 1
, TEE - EY, A 1984.
Kotsanis . - Y. Maistros, Alexios Zavras,"Quicklem:: A Software System for
Greek Word-Class Determination, Literary and Linguistic Computing, Literary
and Linguistics Computing, Vol. 2, No 4, Oxford Univ. Press, 1987.
Kotsanis Y. - Y. Maistros, Describing Morphological Phenomena of Modern
Greek using a Unification Grammar Formalism, Information Systems Vol. 16, No
6, 1991.
Kotsanis Y. - Y. Maistros, Lexifanis: a Lexical Analyzer of Modern Greek, 2nd
Conference of the European Chapter of the ACL, Geneva, March 1985.

90

M ., K E E , 1
, TEE - EY, A 1984.
M . - . :

E, 2

EY, , 1988.
., -
,

Institut

Fran*ais

dAth*nes,

, 1995.
M .,

, , T

, A, 1987.
M ., ,
, T , A,
1988.
Packard David, Computer-Assisted Morphological Analysis of Ancient Greek,
Computational and Mathematical Linguistics (Proceedings of the International
Conference on Computational Linguistics), Pisa, 1973.
Ralli A. - E. Galiotou,

A Morphological Processor of Modern Greek, 3rd

Conference of the European Chapter of the ACL, April 1987.


.,

K E

E B , K..E. , 1988.
T
EOT

927, 928 (ISO 8859/7), 10646:

E X (Coded Character Sets).


EOT 1000: E- ( ).
ISO 843 / 743:
.
ISO 8859/7 Information Processing, Coded Character Set.
Maistros Y., Written Greek Language Fundamentals, ISO TC97 / SC2 / WG4
Workshop, Heraclion, 1986.
M ., M - M E
, EOT TE48 / OE2 (1991) 74/1, 1994.
., -
,
, 1995.

91

., ,
, 1995.
, , , . ,
,
,
1995.
K -
Alvin Toffler, Power Shift, Bantam Books, 1991,
Alvin Toffler, , , 1982
M ., T KAI, E
- EY, A 1988
M ., O P E
H Y, "O H Y E
E E",

I.

E - B, A 1988. :
I Goethe
A, . Goethe, 1987
M ., . M, N T E T
K , EETAA, EOK, OOA : "H
T A K 1990: N T
", A . 1988.
M ., T E X ,
T A - E.M.., A 1990.

92

You might also like