.


:




:

































 

 

 

 


. 1. IV




 

1. IV . , 16-18, . - , , .

, , , , ,

pair(<>, < , >),

pair - . . 2

[pair (a, [b, c]), pair(b, [a, d]), pair(c, [a, d]), pair(d, [b, c, e]), pair(e, [d])].

.

- , ( .2 ).

 

2. min_path short_path , .. () .

( min_path) . (depth_first_search), -. , (.. ) [, .330-335; , .224-232].

, - .

( short_path) ( - min_path). - (breadth_first_search). , , . , , .. , .

, , , [, . 336-344].

() -

findall (Var, Goal, Vlist),

Var - , Goal - , Var, Vlist - - Goal. findall , Goal : Var Vlist - , Goal. findall , Var.

,

findall (X, append (X, _, [a, b, c]), Xlist)

Xlist ([ ], [a], [a, b], [a, b, c]).

3. - () (backtracking ). (, .), () [, .190-197].

, , , . , [1, 2, 3] :

dl ([1, 2, 3, 4, 5], [4, 5])

dl ([1, 2, 3| Y], Y)

dl ([1, 2, 3], [ ])

dl - , .. : - (), - .

, - , ( dl) , , . append , , . - append - :

 

append_dl (dl (Z1, Z2), dl (Z2, Z3), dl (Z1, Z3)).

- :

 

                 
   
Z1
 
 
 
dl(Z1, Z2)
 
 
   
Z2
   
 
   
dl(Z2, Z3)
 
 
   
Z3
   
 

 

 


, , , .

, - append append append, - .

, dl , - , . append

append_dl (Z1, Z2, Z2, Z3, Z1, Z3).

 

 

4. -. - fail cut ( !).

fail - ( ), - - , .. , () . , ,

, fail - ().

, fail , , fail .

! (cut), fail, : , fail. ! , .

!

P:- R1,..., Rk,!, Rk+1,..., Rn. (0 £ k £ n)

- P, G, , P (.. , G). , - , .

, -, , R1,..., Rk, (. . R1,..., Rk), -, , G, P, G, .

Rk+1,..., Rn, , , , . Rk+1,..., Rn , (), , , , P.

[, .127-132, 136-140]. () - , . , , , ( ).

, , - . member:

member (X, [X| Z]):-!

member (X, [Y| Z]):- member (X, Z).

(o, i) X Z, member, .

, ( ), - . , , .

 

5. - not, - . , not(Goal) , - Goal (.. ).

, Goal ( ) , , , .

not - fail ( G - ):

not(G):- G,!, fail.

not(G).

not, . , , , not , , .

 

 





:


: 2015-10-01; !; : 606 |


:

:

, .
==> ...

1725 - | 1549 -


© 2015-2024 lektsii.org - -

: 0.023 .