• date post

16-Apr-2017
• Category

Education

• view

870

0

Embed Size (px)

Transcript of PROLOG ΜΑΘΗΜΑ 5

• 31PROLOG

5:

• A.

1.

1.

2 , 31, Prolog, 5:

1.

2. ! /0

2.

1. fail / 0

B.

• . 1. 1.

:

3 , 31, Prolog, 5:

:

max(X,Y,M):-

X>Y,

M=X.

max(X,Y,M):-

X=

• . 1. 1. :

4 , 31, Prolog, 5:

: max(4,5,).

max(X,Y,M):-

X>Y,

M=X.

max(X,Y,M):-

X=5,=4.

X=4,=5,=

X=4,=5,=

: 4=

• . 1. 2. To ! / 0

! / 0 ( cut) :

5 , 31, Prolog, 5:

: . . , !

! .

max : max :

max(X,Y,M):-

X>Y,!,

M=X.

max(X,Y,M):-

X=

• . 1. 2. To ! / 0

6 , 31, Prolog, 5:

: max(4,5,).

max(X,Y,M):-

X>Y,!,

M=X.

max(X,Y,M):-

X=5,!,=4.

X=4,=5,=

X=4,=5,=

: 4=

• . 1. 2. To ! / 0

! .

7 , 31, Prolog, 5:

. if-else

:

max(X,Y,M):-

X>Y,!,

M=X.

max(X,Y,M):-

max(X,Y,M):-

X>Y,!,

M=X.

max(X,Y,M):-

max(X,Y,):-

X>Y,!.

max(X,Y,).max(X,Y,M):-

X=

• . 2. 1. To fail / 0

fail / 0 :

8 , 31, Prolog, 5:

. ( )

. ! fail .

.

• . 1 Prolog:

9 , 31, Prolog, 5:

first:- room(X), write(X), nl, fail.

:(a1) first.(a2) second.fail.

second:- room(X), !, write(X), nl, fail.

third:- room(X), write(X), nl, !, fail.

fourth:- !, room(X), write(X),

(a2) second.(a3) third.(a4) fourth.(a5) fifth.

:

(1) (2) (3) (4) (5)a a

ba a

bab

write(X), nl, fail.

fifth:- room(X), write(X), nl, fail, !.

room(a). room(b). room(c).room(d).

, .. a3->2

No cd

No

No cd

No

cd

No

• . 1

10 , 31, Prolog, 5:

• 11 , 31, Prolog, 5:

. 2

() f(X,Y):- X

• . 2

12 , 31, Prolog, 5: