Logic Programming

download Logic Programming

of 200

description

Σημειώσεις λογικού προγραμματισμού

Transcript of Logic Programming

  • ( 2.1)

    .

    2001

  • 1

    , 5 . , . , , . . Herbrand , , , Prolog, ... Prolog. , , , , ... , : , Prolog , . ( ) , , Prolog.

    ...

  • 2

    1

    1.1 (Artificial Intelligence, AI, ) , . , , , , , : - (Cognitive Sciences), , , , , - , , , - , , , ... - , (hardware, ).

    1.1. , (.1). , , .

    1950 , Rosenblatt,Wiener, McCulloch,PERCEPTRON 1960 , Newell,Simon,Shannon, Turing, GPS 1970 , Sortliffe,insky, McCarthy, MYCIN 1980 , Lenat,Samuel, Holland, EURISCO

  • 3

    , , . 1.2 . : , , , , , (.2,3). , . (.4,5), "", .

    1.2. (.. ) , , , . , . . , : , , , , , : , , . , , .

    - , - , - , - , - , - , - . - , -

  • 4

    : , , . : . . .

    1.3.

    1.4. : , ( ) . .. , , , , . , .

    ( ) : /, /, /, /.

    - ( - ) : - - , , , , - -

    : , , . ( ) . : ,

    - - - - ( ) ...

  • 5

    1.5. (--) . , , , ... , . , , , , . , ( , , , ). , , , , ... . , ( ) .

    : Modus Ponens : , --> :

    , . :

    . : (/ )

    . :

    . :

    . :

    . : :

    . :

    . , , ,

    , ...

    (spreading activation intersection search).

  • 6

    (2, 3 ..), , , , , ...

    1.6. , : , , ( ). . , , ... , , , , , ... . (declarative knowledge), , . . , (.6) , , , , ... , ' . (semantic networks, ) . T . -, - - , - - , - , , , (semantic cases), ... (primitive links) . ( )

    : , ' , , , , , - , , , ...

    : : , , , , .

    : . : . :

    .

  • 7

    (spreading activation intersection search). , , , ... (frames) (slots) , . , , (default value). , . , (scripts) . , , (procedural knowledge). , . "" , . . (production rules). " " . 1.3 , , . :

    (, ) - ) (.. , , , ...) robot , , ,

    VLSI, ...) :

    : ,

  • 8

    : , ,

    : : - - : , , ,

    ,,,, : : , : - , : : : /

    :

    . (.. LISP). (..

    Prolog). . .

    (expert systems) . . " , ". , :

    . ,

    .

    .

    .

    .

    . "" .

    (Knowledge Engineering) . , . (.6).

  • 9

    (.7) . , .

    1.7.

    &

    &

    , , , - (.8). :

    Dendral : "" , , , .

    Meta-Dendral : .

    Mycin : : .

    Prospector : . Hearsay-II : . Teiresias :

    "" .

  • 10

    1.8. 1.4 (logic programming) , . . . : ( )

    ( )

    Prolog. .. , , . , , , . - - . . , , . Prolog. O (mechanized reasoning). : .

  • 11

    , , Prolog.

    , , , . . : (model theory) (proof theory). , , . : (true), (false), (interpretation), (satisfaction), (model), (logical consequence) (semantic consequence). , , . : (axiom) , (inference rule), (theorem) , (proof), (consistency) (syntactic consequence). , . , , . 1.5 , Prolog . Prolog . . . , . . Logic for Problem Solving, Robert A. Kowalski [1], ISBN: 0-444-00365-7

    . , , . ,

  • 12

    (resolution theorem-proving), . . , .

    1.9. . Essentials of Logic Programming Christopher J. Hogger [2],ISBN: 0-19-853820-0

    . , . , .

    Foundations of Logic Programming John W. Lloyd [3], ISBN: 3-540-18199-7 .

    , , , . .

    The Art of Prolog : Advanced Programming Techniques Leon Sterling Ehud

    Y. Shapiro [4], ISBN: 0-262-19250-0

  • 13

    Prolog: Programming for Artificial Intelligence Ivan Bratko [5] ,ISBN: 0-201-41606-9 Prolog . . Prolog, . Prolog . Prolog.

    , . Journal of Logic Programming New Generation Computing Logic and Computation Artificial Intelligence Machine Intelligence Knowledge Engineering Review Journal of Automated Reasoning Journal of the ACM Communications of the ACM Journal of Theoritical Computer Science Journal of Symbolic Logic Journal of Logic and Computation International. Workshop on Logic Programming International. Conference on Logic Programming IEEE Symposium on Logic Programming, Atlantic City. North American Conference(s) on Logic Programming (NACLP) Italian Conference(s) on Logic Programming (GULP) Fifth Generation Computer Systems (FGCS) Int. Joint Conference(s) on Artificial Intalligence (IJCAI) Technical Reports of the Institute for New Generation Computer Technology, (ICOT),

    Tokyo. Technical Reports of the European Computer-Industry Research Centre, (ECRC),

    Munich. Logic Programming Newsletters of the Association of Logic Programming (ALP).

    [6]-[13] .

    [14]-[19], , .

  • 14

    1.6 , :

    ,

    . , , , . , . , - - , - (resolution principle) - . Prolog

    + (control strategy) . O Prolog (pure Prolog) . - (non-logical primitives), Prolog (impure Prolog). ( ) . , Prolog . Prolog . . , Prolog. , . , , -, , - . . ; - , clause , : likes(chris, Anyone) if reads(Anyone, these_notes)

  • 15

    reads(Anyone, these_notes) if sensible(Anyone) sensible(you) chris likes you. . , . . : Gottlob Frege, , Alfred Tarski, .

    clause

    1.10 . , , Jacques Herbrand. H (resolution) - J. Alan Robinson. , Carl Hewitt, Alain Colmerauer Robert Kowalski. - 25 , . 1965: J. Alan Robinson

    . 1971: Lighthill .

    . 1972: Robert A. Kowalski

    . 1973: Alain Colmerauer, o Philippe Roussel Aix-

    Marseille Prolog. 1974: Robert A. Kowalski

    IFIP-74. 1976: To

    Imperial College .

  • 16

    1977: O Keith L. Clark , Prolog.

    1981: William F. Clocksin Christopher S. Mellish Prolog (Programming in Prolog, Springer Verlag, Berlin, 1981, ISBN: 3-540-11046-1).

    1981: ! - , -.

    1983: . Alvey , .

    1984: Journal of Logic Programming J. Alan Robinson Jean-Louis Lassez.

    1984: O John W. Lloyd .

    1986: Association of Logic Programming, International North American Conferences on Logic Programming, (Newsletters).

    1987: , - ...

    1.7 . , , .

    , , . , : 1.

    (knowledge-based programming). . , . , , .

    2. -

  • 17

    1.11 . 3. -

    : , .

    4. - ,

    , .

    5.

    , - , - .

    6.

    - .

    7. ! - ,

    . 1.8 , . , ,

  • 18

    . , Prolog - . , Prolog. . , . , . , , , , . , , , , -, , . , , . Prolog - - - - . . . , Prolog . , (negation-by-failure) , . . , , , . , , . , Horn ( ), - . , . Horn , , (tail-recursion) (garbage-collection). .

  • 19

    . , , . , Dov Gabbay [2]. , . , . , . . . . . , . . - , . () . . . , , , . , , . . 1.9 , . , , . , . ,

  • 20

    . [1] R. A. Kowalski, "Logic for Problem Solving", Elsevier North Holland, 1979 [2] C. J. Hogger, "Essentials of Logic Programming", Oxford University Press, 1990 [3] J. W. Lloyd, " Foundations of Logic Programming ", Springer Verlag, 1987 [4] L.Sterling, E.Shapiro, "The Art of Prolog : Advanced Programming Techniques",

    MIT Press, 1986. [5] Ivan Bratko, Prolog : Programming for Artificial Intelligence, Addison Wesley,

    1990 [6] J. A. Robinson, A machine-oriented logic based on the resolution principle, Journal

    of the ACM 12, 1965, pp.23-41. [7] P. J. Hayes, Computation and deduction Proc. of the 2nd Symposium on the

    Mathematical Foundations of Computer Science, Czechoslovak Academy of Sciences, 1973, pp.105-118.

    [8] R. A. Kowalski, Predicate logic as a programming language Proc. of IFIP-74,

    North Holland Publishing Company, Amsterdam, 1974, pp.569-574. [9] R. A. Kowalski and M. H. van Emden, The semantics of predicate logic as a

    programming language, Journal of the ACM 23, 1976, pp.733-742. [10] M. H. van Emden, Programming in resolution logic Machine Intelligence 8, Ellis

    Horwood Ltd. Chichester, 1977, pp.266-299. [11] K. L. Clark and S.-A. Tarnlund, A first order theory of data and programs, Proc. of

    IFIP-77, North Holland Publishing Company, Amsterdam, 1977, pp.939-944. [12] K. L. Clark, Negation as failure, Logic and Data Bases (Eds. H. Gallaire and J.

    Minker), Plenum, New York, 1978, pp.293-322. [13] R. A. Kowalski, Algorithm = logic + control, Comm. of the ACM 22, 1979,

    pp.424-431. [14] R. A. Kowalski, Logic programming Invited Paper in Proc. of IFIP-83, North

    Holland Publishing Company, Amsterdam, 1983, pp.133-145. [15] R. A. Sammut and C. A. Sammut, Prolog: a tutorial introduction Australian

    Computer Journal 15, 1983, pp.42-51.

  • 21

    [16] M. R. Genesereth and M. L. Ginsberg, Logic programming Comm. of the ACM 28, 1985, pp.933-941.

    [17] L. Wos et al., An overview of automated reasoning and related fields, Journal of

    Automated Reasoning 1, 1985, pp.5-48. [18] C. J. Hogger and R. A. Kowalski, Logic programming, Encyclopedia of Artificial

    Intelligence (Ed. S. C. Shapiro), John Wiley & Sons, New York, 1987, pp.544-558. [19] R. A. Kowalski, The early years of logic programming, Comm. of the ACM 31,

    1988, pp.38-43. [20] N.J.Nilsson, "Principles of Artificial Intelligence", Springer-Verlag, 1982 [21] A.Barr & E.A.Feigenbaum, "The Handbook of Artificial Intelligence", Vol.2., Pitman

    Books LTd., 1983. [22] P.R.Cohen & E.A.Feigenbaum, "The Handbook of Artificial Intelligence", Vol.3.,

    Pitman Books LTd., 1984. [23] E.Rich, "Artificial Intelligence", McGraw-Hill, 1983. [24] R.Forsyth, "Expert Systems, Principles and Case Studies", Chapman and Hall

    Computing, 1984. [25] P.H.Winston, "Artificial Intelligence", Addison-Wesley publishing Company, 1984 [26] E.Charniak, D.McDermott, "Introduction to Artificial Intelligence", Addison-Wesley,

    1985. [27] R.Frost, "Introduction to knowledge Base Systems", Collins, 1986. [28] M.R.Genesereth, N.J.Nilsson, "Logical Foundations of Artificial Intelligence",

    Morgan Kaufmann Publishers Inc., 1988.

  • 22

    2

    2.1 , . (, propositional logic) . , ( ) ' (, first order logic). , . () , , , . , , , . . . . . . 2.2 : , . (atomic propositions, atoms). (logical connectives) (compound propositions). : (not, ), (and, , ), (or, , ), , (implies, ), (equivalent, ).

  • 23

    2.1 : p1, p2, ... : : ( ) : 2.2 , , , , , , , ()

    . 2.1 (p3 ((p1p2) p3)) p1 (p3p4) p4 p3 (p3p4) p4 , : . ' : (p (q (r))) pqr . 2.3 . , , , ... , , : , , , ... . , . / , , , , ... , . , , ... , /

  • 24

    , ... , , , . (procedural knowledge representation). , (declarative knowledge representation). . , , , . ( ) , . .. , . 2.3 , , . . , , , , , . , , DNA. , . , , , ... . , , . , . , , , ... , , , , , , ... , , . . . : " , ". p1=" ",

  • 25

    p2=" ", p3=" ", (p3) (p1p2) ... ..., ... ... , ... ..., , , ... , . . 2.2 , .

    1. , .

    2. , video . 3. . 4. . 5. video.

    ' : p=" ", q=" ", r=" ", s=" ", t=" video"

    , . ,

    , ,

    ( ) ( ) ( ).

    : q r p

    : ={ q r p, t r s , s p, q, t}.

    . 2.4 : H : ( ) , . (semantics), (interpretation) .

  • 26

    . ; ; . . (valuation), (truth value) . , , . (truth tables) . . .

    I(p) I(q) I(p) I(pq) I(pq) I(pq) I(pq) 0 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1 1 1 1

    . n 2n . : (true) (false). 1 t, 0 f . , . 2.4 , p1,p2,..,pn, . pi, i=1,...,n. p (p)=1 ( ), I(p)=0 ( ). 2.5 I I. I. ()=1 ( ), I()=0 ( ). . ,

  • 27

    {p,q,r,s,t} {0,0,1,1,0}. p=" ", q=" ", r=" ", s=" ", t=" video", , , , , video. , . 2.3 (pq)(rs). 4 , 16 . . , 1, .

    (p) (q) (r) (s) (s) (pq) (rs) ((pq)(rs)) 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 0

    2.6-, , (valid, tautology). (inconsistent, unsatisfiable, contradiction). (satisfiable) . 2.5 . : . (satisfaction) . 2.7 ( ) I . ()=1 , |= , |= . ()=0 , | , | . |=,

  • 28

    |= . | |= . , , . . . . , . 2.8 (satisfaction formulae) |= , , ()=1 |= | |= () |= |= |= () |= |= |= (), | |= |= (), |= () |= (), |= () |= () 2.4 :

    (p) (q) (r) (s) (s) (pq) (rs) ((pq)(rs)) 0 1 0 1 0 0 1 1

    ={0,1,0,1} {p,q,r,s}. (pq)(rs) : |= (pq)(rs) | (pq) |=(rs) (|= (pq)) ( |=(r s) |=(s r)) (|= (pq)) ( (| r |= s) ( | s |= r) ) (|= p |= q) ( (| r | s) ( |= s |= r) ) ((p)=1 (q)=1) ( ((r)=0 (s)=0) ( (s)=1 (r)=1) ) (p)=0 (q)=0 ( ((r)=0 (s)=0) ( (s)=1 (r)=1) ) ... |= (pq)(rs) , ((pq)(rs))=1 , . 2.9 () =1 - () () = () * () () = () + () - ()*() I() = I() = 1 - I() + ()*() () = (() ()) = 1 - () - () + 2*()*() 2.5 :

  • 29

    (p) (q) (r) (s) (s) (pq) (rs) ((pq)(rs)) 0 1 0 1 0 0 1 1

    ={0,1,0,1} {p,q,r,s} (pq)(rs) : ((pq)(rs)) = 1 - (pq) + (pq) * (rs). (pq) = (p)*I(q) = 0*1 = 0. ((pq)(rs)) = 1 - 0 + 0 * (rs) = 1. . . , , () = max((),()). 2.10 . : |= () |= . . , . . , . . . . (.. ), , . , . , . (.. ). , , , , , ... , . ( ). , . . . -

  • 30

    . , - - , . - - , . , , - - . . , , - - (. ). 2.5 : 2.11 (|=) (logical consequence) . , |=, . : |= (i) (|=i |=i ). , . , . . , , , , : . , . 6 . , . 2.1 ( - 1) ={1,2,...,} , |= 12... . 12... 12... ( ). . ( ). 2.6 : ={qr, pq, r} p. p .

  • 31

    (p) (q) (r) (qr) (pq) ((qr) (pq) r) 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0

    , . , ={1,0,1} p . |=p. 2.2 ( - 2) ={1,2,...,} , |= (12...) . (12...) 1 . 2.7 , ((qr) (pq) r )p. 1. 0 : 0 1.

    (p) (q) (r) (qr) (pq) ((qr) (pq) r) ( p) 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 1

    2.3 - 3 ={1,2,...,} , |= (12...) . (12...) 0 . 2.8 , ((qr) (pq) r ) p. 0.

  • 32

    (p) (q) (r) (qr) (pq) ((qr) (pq) r) ( p) 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 0

    2.12 (|=|). , , |=| , (|= |=). . . . , . : (2.1) () |=| ()() (2.2) () |=| (2.3) () |=| () () |=| () (2.4) () |=| () () |=| () (2.5) () |=| ()() () |=| ()() (2.6) () |=| (2.7) () |=| () |=| (2.8) 1 |=| 0 |=| 0 |=| |=| 0 (2.9) 1 |=| 1 0 |=| |=| |=| 1 - 4 , (12...) . 2.9 , p . (qr) (pq) r p |=| (q r) (p q) r p |=| (q r) (p q) r p |=| ((q r) r) ((p q) p) |=| ((q r) (r r)) ((p p) (q p)) |=| ((q r) 0) (0 (q p))

  • 33

    |=| (q r) (q p) |=| (q r q p) |=| (q q r p) |=| (0 r p) |=| 0 - 5 . ={1,2,...,}, , . 2.10 ={qr , pq , r}. : |= (qr) |= (pq) |= r. : |= (qr) |= (qr) (q) = 1 I(r) = 1. |= r I(r) = 1. I(r) = 0 (q) = 1 . (q) = 0. |= (pq) |= (pq) (p) = 1 I(q) = 1. (q) = 0, , (p) = 1, |= p. , p. - 6 . ={1,2,...,}, , . 2.11 ( ) ={qr , pq , r}. (qr)=1 (pq)=1 (r)=1. : (qr) = 1 (qr) = 1 (q) + I(r) - (q)*I(r)= 1 I(r) = 1. I(r) = 0, (q) + 0 - (q)*0= 1 (q) = 1 (q) = 0 (pq)=1, 1- (p)+(p)*(q)=1 1- (p)+(p)*0=1 (p)=0 (p)=1, , p. , .

  • 34

    . , . , . , , (conjunctive normal form). . , . (disjunctive normal form), . 2.12 : (p r s) (p r) ( ) p r s ( ) p r ( ) s ( ) : ((p r) s) (p r) 2.4 . . 2.1. . 1. (pq) |=| (pq)(qp)

    . 2. (pq) |=| p q . 3. (p) |=| p, (pq) |=| pq, (pq) |=| pq

    . 4. p(qr) |=| (pq)(pr) , p(qr) |=| (pq)(pr)

    . 5. (p1|=|p), (p0|=|0),

    (pp|=|p), (pp|=|0), (p1|=|1), (p0|=|p), (pp|=|p), (pp|=|1), .

    2.13 (pq)(rs). . 1 : (pq)(rs) |=| (pq) ( (r s) (s r) ) 2 : (pq) ( (r s) (s r) ) |=| (pq) ( (r s) (s r) ) 3 : (pq) ( (r s) (s r) )

  • 35

    |=| (pq) ( (r s) (s r) ) 4 : (pq) ( (r s) (s r) ) |=| ((pq) (r s)) ((pq) (s r)) |=| (p q r s) (p q s r) , (model theoretic semantics). . , (2 ). . . , , . , , . , (12...) , (12...), . , , . , . , , . (non logical axioms, proper axioms) . ( |= ) . (logical axioms) , . , , . . , , , , , , , , ... , . , , ... .

  • 36

    , ; . , , . . 2.6 (proof theoretic semantics). ( , inference rules) (logical axioms). . () , () , () (), () , . , . 2.6.1 Modus Ponens . . , . , . , , . () |=| ()() ,, , . . , . : (1) () (2) (())(()()) (3) ()(())) , Modus Ponens (M.P.) .

  • 37

    2.13. p, ( |-p ), 1, 2, ..., , = i , , M.P. . 2.14 |-p r , ={pq, qr} : 1. pq, , 2. qr, , 3. (qr)(p(qr)), (1) =(qr) =p, 4. p(qr), M.P. 2,3, 5. (p(qr))((pq)(pr)), (1) =p, =q, =r, 6. (pq)(pr), M.P. 4,5, 7. (pr), M.P. 1,6. 2.6.2. - , , . . . . (Soundness Theorem) : |-p |= . ( ) . (Completeness Theorem) : |= |-p . , . ( ) . 2.6.3 .. .. Modus Ponens : ) Hilbert

  • 38

    : (1) () (2) (())(()()) (3) () ) Hilbert - Ackermann : (1) (2) (3) (4) ()() ) Rosser : (1) (2)

    (3) ()(()()) 2.6.4. (Resolution Principle) 1965 Robinson (inference rule) (resolution principle) . : " C1 C2 , L1 C1 L2 C2, C C1, C2 L1 L2". C (resolvent) C1 C2. C1 C2 C. 2.15 pqr qs prs. 2.7. . , . (proof procedure) " ". , , . . . .

  • 39

    . : 1. ' . 2. ( ), ' ' : '' = '' 3. :

    '' . , , .

    2.14 , ( |-r ), 1,2, ...,, = i '{}' ( ), . 2.16 : 1. , . 2. , video . 3. . 4. . 5. video. ' : p=" ", q=" ", r=" ", s=" ", t=" video". : ={ p q r, s t r, p s, q, t}. : '={ p q r, s t r, p s, q, t}. p. p, ( p), ' ''={ p q r, s t r, p s, q, t, p}. : 1. p q r, '', 2. p, , 3. q r, 1,2, 4. s t r, '', 5. p s, '',

  • 40

    6. p t r, 5,6, 7. t r, 2,6, 8. t, '', 9. r, 7,8, 10. q, '', 11. r, 3,10, 12. , 9,11, . Prolog. Modus Ponens . .

  • 41

    3

    3.1 , . , " ", " ", " ". . ( ) ( ...) . , (First Order Predicate Logic, FOPL), , , . 3.2 () . . ) : A B C D E F G H I J K L M N O P Q R S T V U W X Y Z a b c d e f g h i j k l m n o p q r s t v u w x y z 1 2 3 4 5 6 7 8 9 0 . , ( ) { } [ ] + - * / ^ = < > ) . X,Y,Z, Human, , .

  • 42

    ) . a, b, c, , , , , , , . ) . . ) ( , predicate symbols) ( ). . : + - * / ^ {}[]. n- (1,2,...,n) (prefix) . (infix), . +(1,2) 1+2. :

    1+2, 1-2, 1*2, 1/2, 1^2, 1 2, 1 2 {1,2,...,n} , [1,2,...,n] . .

    =, , , , , , , , , :

    1=2+3*4, 1 (1 2), 1 (2 3)

    :

    =(1,+(2,*(3,4))), (1, (1,2), (1,(2,3) , , :

    equals(1,sum(2,product(3,4))), member(1,union(1,2), superset(1,intersection(2,3) H . , , (terms), (predicate symbols, predicates), (quantifiers). 3.1 (term) : 1. . 2. .

  • 43

    3. f n-, 1,2,...,n , f(1,2,...,n) .

    4. . , . , . 3.2 - p n- t1,t2,...,tn p(t1,t2,...,tn) . . 3.1 () project(leader(X),programmer(peter),secretary(helen)) i_am_a_list([1,2,3,5,7,8,16]) , , . . , {1,2,3} {2,3,4} {1,2,3} {2,3,4} {2,3} ( ). . , , . (.). 3.3 , "" ( Exists, ) "" (All, ) . . () ()... ... , () , , , () , ... , () ()... ... , () , , ... . . , . , .

  • 44

    3.4 (wffs) (well formed formulas, wffs), : 1. wff. 2. , wffs, , , , , , wffs. 3. wff X

    , () () wffs. 4.

    1-3, . 3.2 wffs () (() ()) () (() ()) () (() ()) () () () () () () () ( () () (() (,)) ) () () () ( ) () () . . . wffs () () (scope) . wff (QX)G, Q {, }, (scope) Q G X. X (bound) (QX). . () ( () () (() (,)) ) () , () (() (,)). , . ( ) . : () () () ()

  • 45

    3.3 (conceptualization) . , , . ( , , ) ( 2, , ). ( ) ( ). ( ). , . , '' . . , ... , , , . i

    (i, (, i, , i) )

    3.1 : , , , , . , 3.1. .. . : , , , () . - - , . D, .

    a ai

  • 46

    (formal language), 3.1, . , . . : , . , , . . 3.3 ,,,,, , , . , ( 3.2). D={,,,,} (Universe of Discourse). ,,,, . . . . , .

    C={a, b, c, d, e} F={hat} R={on, above, table, clear}

    3.2 : ' : . ''. : DD, D={,,,,} D={,,,,}. {,,} ( ()=, ()=, ()=).

    di ei ci

    bi

    ai

    D={ai, bi, ci, di, ei}

  • 47

    D, . () . D, , D={,,,,,} ()=, . (); D. (relations) . DnD, n . : '--'

    , . {,,}, ( --(,) , --(,) )

    '-' , . {,,,},

    '' , . {,},

    '' , . {,}.

    , , . ,,,, a,b,c,d,e. C={a,b,c,d,e} . C D. i. . : 1 a i = ai b i = bi c i = ci d i = di e i = ei : 2 a i = ai b i = bi c i = ci d i = di e i = ei .. . . . hat.

  • 48

    hat - - : hat i = hati . , , . 1 on i -- -- = on i above i - - = above i table i = table i clear i = clear i 2 on i - -- = on i above i -- - = above i table i = table i clear i = clear i .. hat(b) ; , (hat(b))i, hati(bi). :

    (hat(b))i = hati(bi) = () = , . :

    (hat(b))i = hati(bi) = () = , . . . above(b,c) . : (above(b,c))i = abovei(bi, ci) = -(,) = , - : (above(b,c))i = abovei(bi, ci) = --(,) = , -- , : , , , ... ; , . . : ={ ()()(on(X,Y) above(X,Y)),

    () () (Z)( above(X,Y) on(Y,Z) above(X,Z)), table(c), table(e), clear(a),clear(d), on(a,b), on(b,c), on(d,e)}

  • 49

    , . . . , ; . . , . 3.4 3.6 ( , Universe of Discource), , D, , , : 1. C i D, , D, 2. F i : Dn D, , , n ,

    Dn D. 3. R i : Dn {0, 1} ( i Dn),

    n- Dn {0,1}. n- Dn. n- ( 1). 3.4 C={a,b,c,d,e}, F={hat}, R={on, above, table, clear}. : a C ai D, ai = , b C bi D, bi = , c C ci D, ci = , d C di D, di = , e C ei D, ei = , : hat F hati : D1 D, hati = hati(bi)= ai, ()= ( ) hati(ci)= bi, ()= ( ) hati(ei)= di, ()= ( )

  • 50

    . on '--' : on R oni : D2 {0, 1} oni(ai,bi)=1, --(,)= oni(bi,ci)=1, --(,)= oni(di,ei)=1, --(,)= oni(ai,ai)=0, --(,)= oni(ai,ci)=0, --(,)=, ... ( D2 . : on R oni : D2 oni={,,}, , --={,,}. . . , . . , . . - . 3.6 . 0 1 . . D, . , ( ) D. D 3.6 : 3.7 D . 3.8 U V , (variable assignment) U V D, V u D 3.5 ()()(on(X,Y) above(X,Y)) . u = , u = . . .

  • 51

    , . . 3.9 TIU I U, (term assignment) TIU , :

    C TIU() = i V TIU() = u F, = (1, ..., n), i = g, TIU(j) = xj TIU() = g(x1, ..., xn)

    3.6 . hat(c) D. :

    hat F hati = , c C TIU(c) = ci = , TIU(hat(c)) = hati(ci) = () =

    hat(hat(Y)) D, : TIU(hat(hat(Y))) = hati(hati(Yu)) = (()) = () =

    . (satisfaction formulae) . ( 2.8). i[u] i u. 3.10 (1) |=i (=)[u] Tiu () = Tiu () (2) |=i (1, ..., n)[u] < Tiu (1), ..., Tiu (n)> i (3) |=i ()[u] |i [u] (4) |=i (

    jj)[u] (j) |=i i[u]

    (5) |=i ( jj)[u] (j) |=i i[u]

    (6) |=i ()[u] |i [u] or |=i [u] (7) |=i ()[u] |=i ()[u] (8) |=i ()[u] |=i ()[u] and |=i ()[u] (9) |=i (x) [u] d D: |=i [v], where V(x) = d and V(y) = u(y) for yx (10) |=i (x) [u] d D: |=i [v], where V(x) = d and V(y) = u(y) for yx . : (1) , .

  • 52

    (2) , - D. 3.7 above(hat(hat(Y),Y) , , U, u = . : i above(hat(hat(Y),Y) [u] < TIU(hat(hat(Y))), TIU(Y) > abovei < , > - (3),(4),...,(8) , . (9) (10) , , () . , U (1)-(10) . , , i, : 3.11 D, o {0,1}, : 1. ,

    , , , , , , .

    2. () 1, 1 d D ( X=d). 0.

    3. () 1, d D 1 ( X=d). 0.

    3.8 () p(X) () p(X), D={, }, pi = {}. a,b ai = bi = . :

    |=i () p(X) [u] |=i p(a) |=i p(b) pi pi ,

    |=i () p(X) [u] |=i p(a) |=i p(b) |i p(a) |i p(b) pi pi ,

  • 53

    3.9 () () p(X,), D={, }, pi = {,.} a,b ai = bi = . :

    |=i () () p(X,) [u] |=i () p(a,Y) |=i () p(b,Y) (|=i p(a,a) |=i p(a,b) ) (|=i p(b,a) |=i p(b,b) ) ( pi pi ) ( pi pi ) ( pi pi ) ( pi pi ) ( ) ( ),

    3.10 () (p(X)q(f(X),a)), D={,}. , a. , b, ai = bi = . fi = {,} pi = {} qi = {,,} . :

    |=i () (p(X)q(f(X),a)) |=i (p(a)q(f(a),a)) |=i (p(b)q(f(b),a)) |=i (p(a) q(f(a),a)) |=i (p(b) q(f(b),a)) (|=i p(a) |=i q(f(a),a) ) (|=i p(b) |=i q(f(b),a) ) (|i p(a) |=i q(f(a),a) ) (|i p(b) |=i q(f(b),a) ) (ai pi qi ) (bi pi qi ) ( pi qi ) ( pi qi ) ( ) ( ),

    3.11 ()()(on(X,Y) above(X,Y)) . , , U, : |=i ( ()()(on(X,Y) above(X,Y)) ) [u] |=i( ()()(on(X,Y) above(X,Y)) ) |=i( ()(on(a,Y) above(a,Y)) ) |=i( ()(on(b,Y) above(b,Y)) ) |=i( ()(on(c,Y) above(c,Y)) ) |=i( ()(on(d,Y) above(d,Y)) ) |=i( ()(on(e,Y) above(e,Y)) ) |=i( on(a,a) above(a,a) ) ... |=i ( on(a,e) above(a,e) ) |=i( on(b,a) above(b,a) ) ... |=i ( on(b,e) above(b,e) ) ... |=i ( on(e,a) above(e,a) ) ... |=i ( on(e,a) above(e,a) ) (|i on(a,a) |=i above(a,a) ) ... (|i on(a,e) |=i above(a,e) ) (|i on(b,a) |=i above(b,a) ) ... (|i on(b,e) |=i above(b,e) ) ... (|ion(e,a) |=i above(e,a) ) ... (|i on(e,a) |=i above(e,a) ) ( oni abovei) ... ( oni abovei) ( oni abovei) ... ( oni abovei) ...

  • 54

    ( oni abovei) ... ( oni abovei) , oni = {,,}, abovei = {,,,}, (1 0) ... (1 0) (1 0) ... (1 0) ... (1 0) ... (1 0) 1 (). . . (ground predicates).

    oni = {,,}, abovei = {,,,},

    . :

    {on(a,b),on(b,c),on(d,e)}, {above(a,b), above(b,c), above(a,c), above(d,e)},

    , . 3.12 - - (valid, tautology). (inconsistent, unsatisfiable, contradiction). (satisfiable) . ( ), , ( ). 3.5 : 3.13 i , .

    |====i () |====i

  • 55

    3.14 . , , :

    |==== iff (i) (u) (|====i [u] |====i [u]) . , . :

    |==== (i) (|====i |====i ) 3.15 , :

    ( | ) ( ) ( ) . . (X) X, . (X) (Y) (X,Y) |=| (Y) (X) (X,Y) (X) (Y) (X,Y) |=| (Y) (X) (X,Y) (X) ((X) (X)) |=| (X) (X) (X) (X) (X) ((X) ) |=| (X) (X) (X) ((X) (X)) |=| (X) (X) (X) (X) (X) ((X) ) |=| (X) (X) (X) (X) |=| (X) (X) (X) (X) |=| (X) (X) ( ). (X) ((X) (X)) |= (X) (X) (X) (X) (X) (Y) (X,Y) |= (Y) (X) (X,Y) (X) (X) |= (X) (X) (X) (X) |= (X) (X) (X) ((X) (X)) =| (X) (X) (X) (X) (X) (Y) (X,Y) =| (Y) (X) (X,Y)

  • 56

    1, ..., n, , = {1, ..., n}. , |i(1...n). : (i) (i(1... n) i) (i) ((j) ij i) (i) (i(1... n)) (i) (|i(1... n) . . 3.12 =(X)(d(X) u(X)) ={(X)(u(X)b(X)), (X)(d(X) b(X))}. , , . (i) (|=i |=i ). i, : |=i (X)(u(X)b(X)) |=i (X)(d(X) b(X)) |=i (X)(u(X)b(X)) |=i (X)(d(X) b(X)) |=i (u(c1)b(c1)) |=i (u(c2)b(c2)) ... |=i (u(cn)b(cn)) |=i (d(cj) b(cj)) i, |=i (d(cj) b(cj)) |=i (u(cj)b(cj)). d(cj) b(cj) , b(cj) 0, u(cj) 1. |=i ( d(cj) u(cj) ). |=i (X)(d(X) u(X)) . . . 3.13 , . , C={a,b,c, F={}, R={on, above,table,clear}. = { ()()(on(X,Y) above(X,Y)), () () (Z)( above(X,Y) on(Y,Z) above(X,Z)), table(c), clear(a), on(a,b), on(b,c) }

  • 57

    table(c), clear(a), on(a,b), on(b,c), , . , : |=i ( ()()(on(X,Y) above(X,Y)) ) [u] |=i( ()()(on(X,Y) above(X,Y)) ) |=i( ()(on(a,Y) above(a,Y)) ) |=i( ()(on(b,Y) above(b,Y)) ) |=i( ()(on(c,Y) above(c,Y)) ) i(on(a,a) above(a,a)) i(on(a,b) above(a,b)) i (on(a,c) above(a,c)) i(on(b,a) above(b,a)) i(on(b,b) above(b,b)) i (on(b,c) above(b,c)) i(on(c,a) above(c,a)) i(on(c,b) above(c,b)) i (on(c,c) above(c,c)) : on(a,a), on(a,b), on(a,c), on(b,a), on(b,b), on(b,c), on(c,a), on(c,b), on(c,c) , : above(a,b), above(b,c). : above(a,c). : on(a,a), on(a,b), on(a,c), on(b,a), on(b,b), on(b,c), on(c,a), on(c,b), on(c,c) above(a,a), above(a,b), above(a,c), above(b,a), above(b,b), above(b,c), above(c,a), above(c,b), above(c,c) table(a), table(b), table(c) clear(a), clear(b), clear(c) 3.6 , . . . (wffs) . 3.13 1. " " (X)( Y)( Z) ( (X,Y) (Y,Z) (X,Z) )

  • 58

    2. " " (X) ((X) (X)) 3. " " (X) [(X) (X)] 4. " " (X) [(X) (X)] 5. " " ((X) (X) ) ((X) (X) ) 6. " " (X) () (X,Y) 7. " " () () (,) 3.14 ; : 1. 2. 3. 4. 5. 6. 7. 8. . 9. . : 1. () 2. () 3. (X)[(X) (X)] 4. () 5. (X)((X) ((X,) (X,))) 6. (X)()((X,Y)) 7. (X)()[((X) () (X,Y) (X,) ] 8. (,) : 9. (,). 3.15 : 1. (X)(S)(T)[XSXTXST] (X,S) XS, (S,T)

    ST (S,T) ST. (X)(S)(T)((X,S) (X,T) (X,(S,T))). 2. (S)(T)(((X)(XSXT)) ST) (S)(T)(((X)((X,S) (X,T)) (S,T)) 3. (S)(T)(STS), (S)(T)((S,T),S).

  • 59

    3.7 . , . clause , . . 3.7.1 (Clauses) 3.16 - - - . not (). . .. a(X,S) . .. a(X,S) a(X,T) a(X, (S,T)) ( -clause set) , . (unit clause). (empty clause). , , . 3.16 a(X,S) a(X,T) a(X, (S,T)) = {a(X,S), a(X,T), a(X, (S,T))} 3.17 Horn (Horn clauses) Horn . 3.17 Horn a(X,S) a(X,T) a(X, (S,T)) a(f(S,T),T) u(S,T)} u((a,b),a)} a(f(S,T),S) u(S,T) Horn .

  • 60

    3.7.2 (wff to clausal form) , . , , . , :

    1: . , , , . 12 : 12 12 : 12 12 : (12)(12)

    2: , . : (12):12 (12):12 ()(()):()(()) ()(()):()(())

    3: (. ) ()(()()(())):()(()()(()))

    4: : , ( ) .

  • 61

    ()(()):() ( )

    , , . , . , . ()(p(X)(Z)(q(X,Y,Z)):(X)(p(X)q(X,Y,f(X,Y))) (Skolemization), .. Skolem, 1920.

    5: . , . (X)(p(X)q(X,Y,f(X,Y))): p(X)q(X,Y,f(X,Y))

    6: , , , : 1(23):(12)(23) (12) 3:(13)(23) (12) 3: 1(23) (12) 3: 1(23)

    7: , . 123:{1}, {2}, {3} 123:{123} (12)(34):{12}, {34}

  • 62

    8: . p(X):{p(X)} q(X):{q(Y)} 3.18- wff clause set

    (Y)(g(Y) (Z)(r(Z) f (Y,Z))) 1 (Y)(g(Y) (Z)(r(Z) f (Y, Z))) 2 (Y)(g(Y) (Z)(r(Z) f (Y, Z))) 3 (Y)(g(Y) (Z)(r(Z) f (Y, Z))) 4 g(a) (Z)(r(Z) f (a,Z))) 5 g(a) (r(z) f (a,Z))) 6 g(a) (r(z) f (a,Z))) 7 {g(a)},{r(Z) f (a, Z)} 8 {g(a)},{r(Z) f (a, Z)}

  • 63

    4

    4.1 , , , . . , , . , , . , , (resolution principle), Robinson (1965). , , . . , , {}, . . , , . {} , . , . , . , , . . , , .

  • 64

    4.2 Davis Putnam. : C1 : p C2 : p q , C1 C2 C3 : q ( , p) C1 ( , p) C2, C1 C2 C3 q. ( ), , : 4.1 C1 C2, L1 C1 L2 C2, L1 L2 C1 C2 , . C1 C2. 4.1 : C1 : p r C2 : p q C1 p, p C2. p p C1 C2 , , r q, r q. 4.2 : C1 : p q r C2 : q s C1 C2 p r s. 4.3 : C1 : p q C2 : p r

  • 65

    C1 C2, C1 C2. o C1 C2 C1 C2. . 4.1 C1 C2, C C1 C2 C1 C2. , , , . S , S. 4.6 . , . 4.2 - S, C S C1, C2, . . ., Ck Ci S Ci, Ck = C. S S. C S, C S. . 4.4 S={p q, q, p}. S . : (1) p q (2) q (3) p (1) (2) (4) p (4) (3) (5) S , 4.1 S. , . , S . 4.5 S={p q, p q, p q, p q }. S .

  • 66

    (1) p q (2) p q (3) p q (4) p q (5) q (1) (2) (6) q (3) (4) (7) (5) (6) : p q p q p q p q q q

    4.1 , S . 4.1, . . , . . , S, S , , S. 4.7 . 4.3 . , . ,

  • 67

    , . , : C1 : p(Y) q(Y) C2 : p(f()) r() C1 C2. , Y f() C1 X C2 C1 : p(f()) q(f()) C2 : p(f()) r() C1 C2 C1 C2, , p(f()) p(f()) . , C1 C2 C3 : q(f()) r() , Y f(X) C1, C1* : p(f(X)) q(f(X)) , C1* C1. p(f(X)) C1 p(f(X)) C2. , C1* C2 , C3 : q(f(X)) r(X) H C3 C3. C1 C2 , C1 C2. , C3 C3. H C3 (resolvent) C1 C2. , ( ). , . 4.3 - (substitution) {t1/v1, ..., tn/vn}, vi , ti vi, /. t1, ... , tn , (ground substitution). (empty substitution) . . 4.6 : {f(Z)/X, Y/Z} {/X, g(Y)/Y, f(g(b))/Z}

  • 68

    4.4 = {t1/v1, . . ., tn/vn} . vi, 1 i n, ti. . ( , 4.) 4.7 = {/X, f(b)/Y, c/Z} E = p(X,Y,Z). E = p(, f(b), c). 4.5 = {t1/x1, . . ., tn/xn} = {u1/y1, . . ., um/ym} . , ,

    {t1/x1, . . ., tn/xn, u1/y1, . . ., um/ym} tj/xj tj = xj ui/yi yi {x1, x2, . . ., xn}. 4.8

    = {t1/x1, t2/x2} = {f(Y)/X, Z/Y}

    = {u1/y1, u2/y2, u3/y3} = {/X, b/Y, Y/Z}

    {t1/x1, t2/x2, u1/y1, u2/y2, u3/y3} = {f(b)/X, Y/Y, /X, b/Y, Y/Z} , t2=x2, t2/x2, , Y/Y, . , y1 y2 {x1, x2, x3}, u1/y1 u2/y2, / b/, .

    = {f(b)/, /} , . ( ) = ( ) = , . , , () . . , . 4.6 (unifier) {1, . . ., } 1 = 2 = . . . = . {1, . . ., } (unifiable) . 4.7 {1, . . ., } (most general unifier) = .

  • 69

    4.9 {p(,Y), p(X,f(b))} = {/X, f(b)/Y} . 4.4 , . , . p() p(X). : p() X p(X). p() p(X), , . p() p(X), {,X}. X , , . . 4.8 (disagreement set) W, : 1. - W, (""). 2. o W -, . 3. "" . 4.10 W {p(X,f(Y,Z)), p(X,), p(X,g(h(k(X))))}, W , , p(X, . , - ( ) , {f(Y,Z), , g(h(k(X)))} (Unification Algorithm) : , . , . , , . () , . ( )

  • 70

    1 k = 0, Wk = W, k = . 2 Wk , . k W. , Dk Wk. 3 vk tk Dk vk tk, 4. , . W . 4 k+1 = k {tk/vk} Wk+1 = Wk{tk/vk}. ( Wk+1 = Wk+1) 5 k = k+1 2. 4.11 W={p(, X, f(g(Y))), p(Z, f(Z), f(U))} 1. = W0 = W. W0 , W. 2. D0 = {,Z}. D0 vo = Z to = . 3. 1 = {to / vo} = {/ Z}, W1 = W0 {to / vo} = {p(, X, f(g(Y))), p(Z, f(Z), f(U))} {/ Z} = {p(, X, f(g(Y))), p(, f(), f(U))}. 4. To W1 , D1 W1:

    D1 = {X, f()} 4. D1 v1 = X t1 = f(). 6. 2 = 1 {t1 / v1} = {/Z} {f()/X} = {/Z, f()/X}, W2 = W1 {t1 / v1} = {p(, X, f(g(Y))), p(, f(), f(u))} {f()/X} = {p(, f(), f(g(Y))), p(, f(), f(U))}. 7. To W2 , D2 W2: D2 = {g(Y), U)}. D2 v2 = U t2 = g(Y). 8. 3 = 2 {t2/ v2} = {/Z, {f()/X} {g(Y)/U} = {/Z, f()/X, g(Y)/U}, W3 = W2 {t2 / v2} = {p(, f(), f(g(Y))), p(, f(), f(U))}{g(Y)/U} = {p(, f(), f(g(Y))), p(, f(), f(g(Y)))} = {p(, f(), f(g(Y)))}. 9. W3 , 3 = {/Z, f()/X, g(Y)/U} W. 4.12 W={q(f(),g(X)), q(Y,Y)} . 1. = W0 = W. 2. To W0 , D0 W0: D0 = {f(), Y}. D0 vo = Y t0 = f(). 3. 1 = {to / vo} = {f()/Y} = {f()/Y}, W1 = W0 {to / vo} = q(f(),g(X)), q(Y,Y)}{f()/Y} = {q(f(),g(X)), q(f(), f())}.

  • 71

    4. To W1 , D1 W1: D1 = {g(X), f()}. 4. , D1 . W . , W0, W1, W2, . . . (, W vk W+1 ). W . W , W. . 4.2 ( ) W , 2, W. ( ) . O false. false, . , , , . function Unify(var L1,L2:lists of terms):list of pairs; begin if L1 or L2 is an atom then begin if L1,L2 identical then Unify:=NIL else if L1 is a variable then begin if L1 occurs in L2 then Unify:=false else Unify:=(L2/L1); end else if L2 is a variable then begin if L2 occurs in L1 then Unify:=false else Unify:=(L1/L2); end else Unify:=false; end if length(L1)Lenght(L2) then Unify:=false; SUBST:=NIL;

  • 72

    for i:=1 to number of elements of L1 do begin S:=Unify(i'th element of L1, i'th element of L2); if S=false then Unify:=false; if SNIL then begin apply S to the remainder of both L1 and L2; SUBST:=APPEND(S,SUBST); end; Unify:=SUBST; end; end; 4.5 , . 4.9 ( ) C , C (factor) C. C , (unit factor) C. 4.13 C = p(X) p(f(Y)) q(X). () = {f(Y)/X}. , C = p(f(Y)) q(f(Y)) C. 4.10 C1 C2 , (parent clauses), . L1 L2 C1 C2 . L1 L2 ,

    (C1 - L1) (C2 - L2)

    (binary resolvent) C1 C2. L1 L2 . 4.14 C1 = p(X) q(X) C2 = p() r(X). X C1 C2, C2 C2 = p() r(Y). L1 = p(X) L2 = p(). L2 = p(), L1 L2 = {/X}. ,

    (C1 - L1) (C2 - L2)=

    = ({p(),q()} - {p()}) ({p(),r(Y)} - {p()}) = {q()} {r(Y)} = {q(),r(Y)}= q() r(Y).

    q() r(Y) C1 C2. p(X) p(X) .

  • 73

    4.11 C1 C2 : 1. C1 C2 2. C1 C2 3. C1 C2 4. C1 C2 4.15 C1 = p(X) p(f(Y)) r(g(Y)) C2 = p(f(g())) q(b). C1 C1= p(f(Y)) r(g(Y)). T C1 C2 r(g(g())) q(b). , r(g(g())) q(b) C1 C2. , . , . 1965 Robinson. Herbrand Gilmore Davis Putnam. , . . , . 4.16 . , : a,b,c,d

    . t(X,Y,U,V) XYUV

    X, Y, U V.

    p(X,Y,U,V) XY UV.

    e(X,Y,Z,U,V,W) XYZ UVW. , , , ... , ... . : , ,

    t(X,Y,U,V), , p(X,Y,U,V). 1 (X) (Y) (U) (V) [t(X,Y,U,V) p(X,Y,U,V)] ,

    .

  • 74

    2 (X) (Y) (U) (V) [p(X,Y,U,V) e(X,Y,V,U,V,Y)] , a,b,c,d. 3 t(,b,c,d) 4.2 , e(,b,d,c,d,b) ,

    1 2 3 e(,b,d,c,d,b)

    . ,

    1 2 3 e(,b,d,c,d,b)

    . , :

    S = {t(X1,Y1,U1,V1) p(X1,Y1,U1,V1), p(X2,Y2,U2,V2) e(X2,Y2,V2,U2,V2,Y2),

    t(,b,c,d), e(,b,d,c,d,b)}. S . S : (1) t(X1,Y1,U1,V1) p(X1,Y1,U1,V1) S (2) p(X2,Y2,U2,V2) e(X2,Y2,V2,U2,V2,Y2) S (3) t(,b,c,d) S (4) e(,b,d,c,d,b) S (5) p(,b,c,d) (2) (4) (6) t(,b,c,d) (1) (5) (7) (3) (6). S, S . 4.3. (4) (2)

    (5) (1) (6) (3) (7)

  • 75

    4.3 4.3 . S ( ) , S, . , r r . , . 4.6 . 4.17 . . , . p,s,u : p = s = u = . (4) (1),(2),(3) : (1) p s (2) s u (3) p (4) u (4) (1), (2) (3), . (1) p s (2) s u (3) p (4) u u (1), (2) (3) . (4) :

  • 76

    (1) p s (2) s u (3) p (4) u (5) s (3) (1) (6) u (5) (2) (7) (6) (4) 4.18 , . , ; p,q,r,s : p = q = r = s = F1, F2 F3, . q F1 F2 F3. F1 : (p (q (s r) ) ) F2 : p F3 : s G : q q, q, F1 F2 F3 . : (1) p q r (2) p q s F1 (3) p F2 (4) s F3 (5) q , (6) q s (3) (2) (7) s (6) (5) (8) (7) (4) 4.19 : F1 : (X) (c(X) (w(X) r(X))) F2 : (X) (c(X) o(X)) G : (X) (o(X) r(X))

  • 77

    G F1 F2. F1, F2 G : (1) c(X1) w(X1) (2) c(X2) r(X2) F1 (3) c(a) (4) o(a) F2 (5) q(X5) r(X5) G. . : (6) r() (3) (2) (7) r() (5) (4) (8) (7) (6) , G F1 F2. 4.20 : . . : .: p(X) : d(X) : q(X) : l(X,Y): F1 : (X) (p(X) (Y) ( d(Y) l(X,Y) ) ) F2 : (X) (p(X) (Y) ( q(Y) l(X,Y) ) ) G : (X) (d(X) q(X)) F1, F2 G : (1) p(a) (2) d(X2) l(a, X2) (1),(2) F1 (3) p(X3) q(Y3) l(X3, Y3) F2 (4) d(b) (5) q(b) (4),(5) G , : (6) l(a,b) (4) (2) (7) q(Y7) l(, Y7) (3) (1) (8) l(,b) (5) (7) (9) (6) (8) . .

  • 78

    (a) F1, ( (1) (2)). (b) . b ( (4) (5)). (c) , b ( (6)). (d) , ( (7)). (e) , b . , b ( (8)). (f) (c). , . 4.21 : VIP. . VIP. : . : e(X) : v(X) : VIP (very important person!) s(X,Y): (searches) c(X) : (customs) p(X) : (pusher) : F1 : (X) ( (e(X) v(X)) (Y) ( s(X,Y) c(Y) ) ) F2 : (X) (p(X) e(X) (Y) ( s(X,Y) p(Y) ) ) F3 : (X) (p(X) v(X)) G : (X) ( p(X) c(X) ) (1) e(X1) v(X1) s(X1, f(X1)) (2) e(X2) v(X2) c(f(X2)) (3) p(a) (4) e(a) (5) s(a,Y5) p(Y5) (6) p(X6) v(X6) (6) p(X7) c(X7) : (8) v() (3) (6) (9) v() c(f()) (2) (4) (10) c(f()) (8) (9)

  • 79

    (11) v() s(,f()) (1) (4) (12) s(,f()) (8) (11) (13) p(f()) (12) (5) (14) c(f()) (13) (7) (15) (10) (14) , . 4.22 . , . s(X,Y), m(X), i(X) e(X,Y) X Y, X , X X Y, . : (X) ( (Y)(s(X,Y) m(Y)) (Y) ( i(Y) e(X,Y) ) ) (X) i(X) (X) (Y) ( s(X,Y) m(Y) )

    , (1) s(X1, Y1) m(Y1) i(f(X1)) (2) s(X2, Y2) m(Y2) e(X2,f(X2)) (3) i(X3) (4) s(,b) (5) m(b) : (6) s(X6, Y6) m(Y6) (3) (1) (7) m(b) (6) (4) (8) (7) (5) . 4.23 : . : . s(X), c(X) v(X,Y) X , X X Y . : (Y) (s(Y) c(Y) ) ( 7) (X) ((Y) (s(Y) v(X,Y) ) (Z) ( c(Z) v(X,Z) ) () :

  • 80

    (1) s(Y1) c(Y1) (X) ((Y) (s(Y) v(X,Y) ) (Z) ( c(Z) v(X,Z) ) |=| (X) ( (Y) (s(Y) v(X,Y) ) (Z) ( c(Z) v(X,Z) ) |=| (X) ((Y) s(Y) v(X,Y) ) (Z) ( c(Z) v(X,Z) ) |=| (X) (Y) (Z) ( s(Y) v(X,Y) ( c(Z) v(X,Z) ) |=| (X) (Y)(Z) ( s(Y) v(X,Y) ( c(Z) v(X,Z) ) |=| (X) (Y)(Z) ( s(b) v(a,b) ( c(Z) v(a,Z) ) , (2) s(b) (3) v(,b) (4) c(Z) v(,Z) : (5) C(b) (1) (2) (6) V(,b) (5) (4) (7) (6) (3) , . , : b , b . b , . , b b . . . 4.24 : 1. ,

    . 2. , video . 3. . 4. . 5. . 6. . 7. video. 8. video. 9. video. 10. video. : watch(X,Y) "O X " has(X,Y) "O X " busy(X) "O X " record(X,Y) "O X "

  • 81

    : 1. (X) (watch(X,film) has(X,color_TV) busy(X)) 2. (X) (record(X,film) has(X,video) busy(X)) 3. (X) (watch(X,film) record(X,film)) 4. has(paul,color_TV) 5. has(mary,color_TV) 6. has(peter,color_TV) 7. has(sofia,video) 8. has(mary,video) 9. has(john,video) 10.has(peter,video) watch(X,Y). . . . (1) watch(X1,film) has(X1,color_TV) busy(X1) (2) record(X2,film) has(X2,video) busy(X2) (3) watch(X3,film) record(X3,film) (4) has(paul,color_TV) (5) has(mary,color_TV) (6) has(peter,color_TV) (7) has(sofia,video) (8) has(mary,video) (9) has(john,video) (10) has(peter,video) (11) watch(X11,Y11) . . (11) (1) { film/Y11 , 12/1, 12/11} (12) : (12) has(12,color_TV) busy(X12), (2) (12) { 13/2, 13/12} (13) : (13) has(X13,color_TV) record(X13,film) has(X13,video) (3) (13) { 14/3, 14/13} (14) : (14) watch(X14,film) has(X14,color_TV) has(X14,video) (11) (14) { film/Y11 , 15/14, 15/11} (15) : (15) has(X15,color_TV) has(X15,video) has(X,color_TV) has(X,video) X. (5) (8) X=mary, (6) (10) X=peter. ,

  • 82

    , mary, peter . (11) (1), (3). {mary,peter} . 4.25 4.16 : : 1: {a(X1,S1) a(X1,T1) a(X1,(S1,T1)), 2: a(X2,(S2,T2)) a(X2,S2), 3: a(X3,(S3,T3)) a(X3,S3), 4: a(f(S4,T4),S4) u(S4,T4), 5: a(f(S5,T5),T5) u(S5,T5), 6: u((a,b),a)} 7. 5,6 = {(a,b)/S5, a/T5} a(f((a,b),a),a) 8. 4,6 = {(a,b)/S4, a/T4} a(f((a,b),a),(a,b)) 9. 2,8 = {f((a,b), a)/X2, a/S2, b/T2} a(f((a,b),a),a) 10. 7,9 = {} 4.26 : 1: {M(a, s(c), s(b)) 2: P(a) 3: M(X3, X3, s(X3)) 4: M(X4, Y4, Z4) M(Y4, X4, Z4) 5: M(X5, Y5, Z5) D(X5, Z5) 6: P(X6) M(Y6, Z6, U6) D(X6, U6) D(X6, Y6) D(X6, Z6) 7: D(a, b)} 8. 1,5 = {a/X5, s(c)/Y5, s(c)/Z5}

    D(a, s(b)) 1: 2,6, = {a/X6}

    M(Y9, Z9, U9) D(a, U9) D(a, Y9) D(a, Z9) 2: 9,8 = {s(b)/U9}

    M(Y10, Z10, s(b)) D(a, Y10) D(a, Z10) 3: 3,10 {X3/10, X3/10, b/X3} = {b/X3, b/10, b/10}

    D(a, b) D(a, b) 4: 11

    D(a, b) 5: 7,12 =

  • 83

    5

    5.1 , . () . , . , . 5.2 , N , D . step :

    step: D x N D ,

    step: (,1) =

    (next) . : . .

  • 84

    Markov (Markov inference procedures) .

    (a) Markov inference procedures next: D D

    step (,n) =

    , n=1

    next(step(,n-1)), n>1

    . (incremental inference procedures) :

    () incremental inference procedures new: D x N D

    step (,n) =

    , n=1

    append(step(,n-1), new(,n-1)), n>1 5.1 step new : step (,n) =

    , n=1

    append(step(,n-1), new(,n-1)), n>1 new (,n) =

    , n=1 [x] mp(first(fast(,n-1)), first(slow(,n-1)), x) [ ], otherwise

    fast (,n) =

    , n=1 append(step(,n-1), new(,n)), fast(,n-1)=slow(,n-1) append(rest(fast(,n-1)), new(,n)), otherwise

    slow (,n) =

    , n=1 append(rest(slow(,n-1)), new(,n)), fast(,n-1)=slow(,n-1) append(slow(,n-1)), new(,n)), otherwise

    mp Modus Ponens :

    Modus Ponens

    : stepn =

    , n=1

    stepn-1newn-1, n>1

  • 85

    newn =

    , n=1 {x}, if MP(first(fastn-1), first(slown-1), x) 0, otherwise

    fastn =

    , n=1 stepn-1newn if fastn-1=slown-1 rest(fastn-1)newn, otherwise

    slown =

    , n=1 rest(slown-1)newn if fastn-1=slown-1 slown-1newn, otherwise

    fastn, slown stepn. ,

    (fast) (slow). , .

    new . stepn

    . Modus Ponens

    . Modus Ponens(, , ) MP(, , )

    = {P, PQ, PR, QS} .

  • 86

    P

    PQ

    slow fast PR

    pointer pointer QS

    P

    PQ modus ponens

    PR

    QS

    Q

    P

    PQ

    PR

    MP QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R

    P

    PQ

    PR

    QS

    Q

    R MP

    S

    P

    PQ

    PR

    QS

    Q

    R

    S

    P

    PQ

    PR

    QS

    Q

    R

    S

    P

    PQ

    PR

    QS

    Q

    R

    S

    No more deductions are

    possible. Breadth-first incre-

    mental inference procedure

    with one inference rule :

    Modus Ponens

    3 1 2

    6 5 4

    10 8 7

    15 15 14

    28

    14 11

    16

    11

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

    . . . . . . . . .

    etc

    etc

    etc

    etc

  • 87

    . , . 5.3 , . (pure) . .

    F = {P Q R, P S, Q S, P, Q, R} S S, . (pure-literal elimination). . P(X) Q(Y) Q(Y) R(Z) . (tautology elimination). (subsumption elimination). (subsumes) (substitution) . . = P(X) Q(Y) = P(a) Q(V) R(W) = {a/X, Y/V} . 5.4 :

    R} Q R, P R, {P Q,

    Q R Q P P R

    P {R} Q R P R Q R R

  • 88

    . , . 24 ! . . . , . , . . . . , , . . . . . ,

    |= |- ,

    { } |= {} |- , . ,

    { } |= {} |- . , . .

  • 89

    5.5 (Unit Resolution) (unit clause) . (unit resolvent) , . (unit deduction) . (unit refutation) . :

    {P Q, P R, Q R, R}.

    P R R Q R

    P Q P Q P Q

    Q P

    R R

    .

    (efficient). , . , , . (complete). {P Q, P Q, P Q, P Q} , . , Horn, . 5.7. (Input Resolution) . , .

  • 90

    , Horn, . {P Q, P Q, P Q, P Q} , Q Q .

    P Q P Q P Q P Q

    Q Q

    5.8 (Linear Resolution) . (linear resolvent) , . . (linear deduction) , (top clause) .

    {P Q P Q P Q P Q}

    Q

    P

    Q

  • 91

    5.9 , . . (unsatisfiable). (satisfiable) , , . (set of support) - . , (clauses) . (set of support resolvent) , . {P Q, P R, Q R} R. (R) : = {P Q, P R, Q R, R} = {R}.

    -

    , , (Goal) goal-driven

    (backward). .

    Q R} P R, {P Q, {R}

    P

    Q

    P

    Q

  • 92

    5.10 (Ordered Resolution) , (linearly ordered set). . ( ) , , .

    . . . , Horn. 5.11 (Directed Resolution) (directed clauses). Horn . . (provable) . . : (forward) (backward).

    R}

    R

    Q R,

    Q R,

    P R, {P Q,

  • 93

    . ( ). , :

    1 ... n 1, ..., n 1 ... n 1, ..., n 1 ... n 1, ..., n 1, ..., n

    (forward resolution) . , (backward resolution), . ( ). (forward clause) .

    1 ... n 1, ..., n .

    .

    1. M(X) P(X) M(X) P(X) 2. M(a) M(a)

    3. P(Z) P(Z)

    1, 2: 4. P(a) P(a) 3, 4: 5.

    , 1, 3. , . .

    1. P(X) M(X) P(X) M(X) 2. M(a) M(a)

    3. P(Z) P(Z)

    1, 3: 4. (Z) M(Z) 2, 4: 5.

    , 1, 2.

  • 94

    . :

    1. P(X) Q(X) R(X) P(X), Q(X) R(X) 2. M(X) P(X) M(X) P(X)

    3. Q(X) N(X) Q(X) N(X)

    4. M(a) M(a)

    5. M(b) M(b)

    6. N(b) N(b)

    7. R(Z) R(Z)

    2, 4: 8. P(a) P(a)

    2, 5: 9. P(b) P(b)

    1, 8:10. Q(a) R(a) Q(a) R(a) 1, 9:11. Q(b) R(b) Q(b) R(b) 3,10:12. N(a) R(a) N(a) R(a) 3,11:13. N(b) R(b) N(b) R(b) 6,13:14. R(b) R(b) 7,14:15.

    . . :

    1. () () 2. () () 3. () () 4. () () 5. () () 6. () () 7. () () 8. () ()

    , ;

    9. ()

  • 95

    10. () 8, 9:11. () 2,11:12. () 10,12:13.

    . (search space) . :

    1. () () 2. () () 3. () () 4. () () 5. () () 6. () () 7. () () 8. () () 9. () 10. ()

    1,10:11. () 2,10:12. () 11,3:13. () 11,4:14. () 11,5:15. () 12,6:16. () 12,7:17. () 12,8:18. () 9,18:19.

    . (branching factor) . . () (). (data-driven). ()

  • 96

    . (). .. (), (), .. (goal driven) . . () () () ()

    () () () ()

    () () () ()

    () ()

    () .

    () ()

    () () () () () () ().

  • 97

    ( ) (data-driven) . 1 ... n 1, ..., n 1, ..., n . . (goal driven). 1 ... n 1, 2, ..., n 1, ..., n. 5.12 (Sequential Constraint Satisfaction) , . , . :

    (, ) (, ) (, ) (, ) (X,Y) (, ) / X (, ) / . (, ) (, ) (, ) (, ) (, ) (, ) (, ) (, ) (, ) ()

    . (,) (,) () (1) (,) (,) () (2) (,) () (,) (3) . . . () (,) (,) (4) ( ), .

  • 98

    . 100 100 (..., ...) ( ) 200 (..., ...). , 10, 10 (...). (1) 200 (,) . (2) - (,) , (,), . 100 x 2 - 200 . (3) 100 ( (,)), (4) 20 ! 10 !!! (heuristic rule) . (cheapest first rule) : . , , , .. . 5.13 ( ). (Ordered Input Resolution) Prolog. Prolog (Programming in Logic) . , n-, , n! .

    3! = 6 . .

    {Q Q P1 P2} P2, P1,

    Q P1 Q P2 P1 P2

    Q P1 Q P2 P1 P2

  • 99

    , .. , . , . Prolog. Prolog : (rules), (facts) . :

    Q: - P1, P2, ..., Pn. () P1. () ?Q ()

    Q P1 ... Pn () P1 () Q ()

    , Prolog : Q: - P1, P2, P3. P1. P2. ?Q (goal). P3. ?Q

    ?Q P1. P1 P1. P2, P2. P3. (, subgoals) , Q, . .

    !!!

    Q P1 P2} P2, P1, {Q,

    P1 P2

    P2

    {Q P1 P2 P3, Q} P3, P2, P1,

    P1 P2 P3

    P3

    P2 P3

  • 100

    . Prolog . . : Prolog

    Q: - P1, ..., Pn

    Q P1 ... Pn. , , . (Q) (P1 ..). Prolog , ( P1 P2 ..) ( ) . P1 P2 Q , , . . Prolog. Prolog . . , Prolog, !!! Prolog, , Prolog .

  • 101

    6

    6.1 , , Prolog .. , , (base set of beliefs) . . (Knowledge-base) (Database). , , . . - , (Wffs) . , . : . . , , .. . (exceptions). :

    () (() ())

  • 102

    :

    () (() () ()) : , , .. . . , . . , . . , , . , . , , . . . : () (F). , , . . . . (objects) , (clauses) . . , , .. . . , . . . (inference rules) . . (non monotonic) .

  • 103

    6.2 (The Closed-World Assumption, CWA) . = {(,) (,), (,), (,)} : = (,) O . | !!! . ( ) ( ). . ; . (proper axioms) , . : [] , , [] (Theory) . , . , (ground). (assumed beliefs) asm, :

    P asm P T[]. :

    CWA[] {asm}.

  • 104

    ....

    []. 6.1. = {P(a), P(a) Q(a), P(b)} Q(b) , Q(b) asm Q(b) T[] asm = {Q(b)}. 6.2 . :

    (, ) (, ) (, )

    , ! CWA. ?(, ), :

    (, ). , , , asm. asm . Prolog not. CWA CWA . = {P(a), P(a) Q(a), P(b)} asm = { }, asm Q(b) Q(b) . 6.1. asm (negated) . (consistency) asm. = {P(a) P(b)} asm = {P(a), P(b)} P(a) P(b) . asm , (. 6.1.)

    . 6.1. asm.

    P(b)} {P(a), asm = = {P(a) P(b)}

    P(b)

  • 105

    . 6.2. asm.

    asm (ground terms, ), . 6.4 = {P(X) Q(X), P(a), Q(b)} a b, asm = {P(b), Q(a)} asm . a, b, c asm = {P(b), Q(a), P(c), Q(c)} asm ( . 6.2.). , , Domain Closure Assumption DCA. . CWA P CWA, P . asm P . = {Q(X) P(X), Q(a), R(b) P(b)} asm = {P(b)} asm . CWA CWA ( ). CWA[] , . = {P Q}, asm = {P, Q} asm , P, Q = {P Q}, asm = {P} asm , P = {P Q}, asm = {Q} asm , Q.

    Q(c)} Q(a), P(c), {P(b), Q(b)} P(a), {P(X) Q(X), asm = =

    Q(c)

  • 106

    6.3 (Domain Closure Assumption DCA) : D (ground terms) . 6.5 = {p(X) q(f(X), p(a), q(f(b))}, C = {a, b}, F = {f} : P = {a, b, f(a), f(b), f(f(a)), f(f(b)), ...} 6.6 = {p(X) q(X), p(b), q(a), p(c)}, C = {a, b, c}, F = : P = {a, b, c} , t1, t2, ..., tn, ( ), DCA : C = {t1, ..., tn}, F = DOMAIN CLOSURE AXIOM

    DCA: (X) ((X = t1 ) (X = t2 ) ... (X = tn)) , . 6.4 (Unique-names assumption - UNA) UNA : , . UNA , . (Equality Reasoning) , , , ( ). , .

  • 107

    6.7 = {P(a), a = b}, : p(b) = {p(a), a = b, p(b)}

    p(a)

    UNA (by default), . a, b UNA a=b ab. C = {t1, ..., tn}, F = UNIQUE NAMES AXIOM

    UNA: (ti) (tj) (ti C tj C i j ti tj)

    CWA, asm. : Horn, , CWA[] . 6.5 (Predicate Completion) = {P(a)}, P(a) a P. :

    (X)( X=a P(X)) P, a P(a) :

    (X)( P(X) X=a) (completion formula) P. . (completion formula) P.

    P COMP[;P] : COMP[;P] {() ( P(X) X=a)}

  • 108

    6.8 = {p(a), p(b)} COMP[;p] {(x) (p(x) x=a x=b)} = {p(a), q(b), q(c)} COMP[;p] {(x) (q(x) x=b x=c)}

    Q1 Q2 ... Qm P(t1, t2, ..., tn) ti , , .. Qi P. :

    1=t1 2=t2 ... n=tn Q1 ... Qn P(X1, X2, ..., Xn)

    P(X). :

    ) : q1 q2 ... qm p(t1, ..., tn) t1, ..., tn .

    )

    (x1) ... (xn) (x1=t1 x2=t2 ... xn=tn q1 ... qm p(x1, ..., xn)) ( &x ) (e p( &x )) ) ( &x ) (e1 p( &x ))

    ( &x ) (e2 p( &x )) ( &x ) (ek p( &x ))

    ( &x ) (e1 e2 ... e p( &x ))

    ) :

    ( &x ) (p( &x ) e1 e2 ... e)

    ) COMP[;p] = {(( &x ) (p( &x ) e1 e2 ... e))} 6.9 = {() (), (tweety), (sam)} : () ()

    . . . .

  • 109

    =tweety () () =tweety () tweety. , , COMP[;] {() () =tweety}. sam ! , ( ): = {() () {1}, (tweety) {2}, (sam) {3}} : () =tweety () {4} (sam), (sam) , .

    , sam=tweety, samtweety, UNA (. VI.9.) 6.10 = {(x) (x), (x) (x), (a), (b), (c), (d), (d), (d), (d)} d . | (d)

    {4} () =tweety () (sam)

    (sam) sam=tweety

    {3} (sam)

    sam=tweety sam=tweety

  • 110

    {}Resolution {} = {(x1) (x1), (1) (x2) (x2), (2) (a), (3) (b), (4) (c), (5) (d), (6) (d) (7) (d) (8) (d) (9) (d)} (10) :

    (d). 1. CWA.

    C = {a, b, c, d}, = (d) asm = {(a), (a), (a), (b), (b), (b), (b), (c), (c), (d)} asm = ... CWA[] {}Resolution

    asm, C . 2. COMP. ... : (x) (x) (x)

    COMP[;] {} = 1: {(x1) (x1) (x1), 2: (x2) (x2), 3: (x3) (x3), 4: (a), 5: (b), 6: (c), 7: (d), 8: (d),

  • 111

    9: (d), 10: (d), 11: (d)} 12: 1, 11 = {d/x1} (d) (d) 13: 10, 12 (d) 14: 8, 13

    COMP[;] {}Resolution COMP = {P(X)} P(X) - - true P(X) P(X) true. P false P(X) P(X) false P(X) P. CWA COMP . . CWA + DCA COM COMP + UNA CWA. COMP . : = { () (), () (), (tweety), (sam)} : () () () =tweety. (sam), sam , !!! 6.6 , , .

    , . .

  • 112

    . . , - . , (circumscription), (default theories), ... . : ; , , ..., - , ;

    (Evidence Theory) (Certainty factors) (Credibility - Plausibility measures) - (Necessity - Possibility measures) (Possibility measures)

    ; (Modal logic) ; (Temporal logics) ; (Knowledge and Belief) ..

  • 113

    7

    Prolog

    7.1 Prolog. Prolog PROgramming in LOGic, . , , , . ( ), (software houses) . Prolog . Prolog, . Prolog , , ... , (interface) . Prolog Pascal C, , , , , . Prolog . Pascal C. Prolog . Prolog ! . , ( ).

  • 114

    H Prolog . , , Prolog , (metalogical) (extralogical) , . , Prolog Horn (Horn clauses). Prolog , , (inference engine). To Prolog (logic program) (knowledge base). , . . 7.2 7.2.1. (Logic programs) 7.1 o (T,N,P), T , N T, P Horn, N. L (facts), (rules) (queries). , ( - - ), .. human(socrates). cartoon(ran_tan_plan). . Prolog : Ro:-R1,R2,...,Rn.

  • 115

    Ro . Ri, i=1,...,n , , . (1) : Ro R1,R2,... (declarative) .. . Q . Prolog () Q' () Q. Q' . , . : grandparent(X,Y):-parents(X,V,U),parents(V,Y,W). Prolog , '', '' . Prolog (refutation procedure, refutation ). , , ( ) . Q1 Q2 ... Qn, (Q1 Q2 ... Qn) . 7.2.2 (unification) , . Prolog . Prolog x=x+1, x , . Prolog . , "" , , , . 7.3 : , , .

  • 116

    (complete). P Q, P Q, P Q, P Q, , . Horn. .

    R0 R1 ... Rj Rj+1 ... Rn (7.1) j+1 n-j . Horn (Horn clauses) . Horn . R0 R1 ... Rn R0 R1 ... Rn , Prolog. , , , . Prolog . . Prolog . , (current goal). , ( ). , , , . , Q1 ... Qn Q1 P1 ... Pm T Q1 Q1 , P1 ... Pm Q2 ... Qn , , . , . , .

  • 117

    , , , , ( ) . Prolog, , . Prolog, , (alternative solution). (backtracking mechanism), ' ' . , Prolog . E Prolog , . (left to right selection of the goals), . . , - Prolog. 7.1 Prolog. Prolog ?(,). a(X,Y) :- b(X,Y). /* 1 */ b(X,Y) :- d(X),e(Y). /* 2 */ d(c). /* 3 */ d(d). /* 4 */ d(X) :- c(X,Z),g(Z). /* 5 */ c(c,a). /* 6 */ g(a). /* 7 */ c(d,b). /* 8 */ g(b). /* 9 */ e(f). /* 10 */ e(g). /* 11 */ a(a,b). /* 12 */ b(g,h). /* 13 */ Prolog a(X,Y) 1, b(X,Y) 1 2. d(X) 2 d(c) 3. Prolog e(f) 10, a(c,f). Prolog e(X). 11, e(g), a(X,Y) a(c,g). , Prolog d(X) 2, d(d) 4, e(Y) . , , a(d,f) a(d,g). d(X) 2, : 5. , c(X,Z), g(Z).

  • 118

    , a(X,Y). , , . . . 7.4 Prolog (interpreter) Prolog. , Prolog A.Colmerauer Ph.Roussel - Prolog 1972. , Prolog. (structure sharing versus copying). Prolog, . Prolog , . Prolog Prolog (Concurrent Prolog). . A Prolog , Prolog, . , Prolog. , . . 7.5 Prolog , Prolog , . : - (arithmetic predicates). - (structure inspection). - (metalogical predicates). - (control predicates).

  • 119

    - (/, .). - . Prolog, cut ("!"). cut . Prolog cut . 7.2 " cut , Prolog cut". 7.2 Prolog. Prolog ?(,). 1. A(X,Y):-B(X,Y). 2. B(X,Y):-D(X),!,E(Y). 3. D(c). 4. D(d). 5. D(X):-C(X,Z),G(Z). 6. C(c,a). 7. G(a). 8. C(d,b). 9. G(b). 10. E(f). 11. E(g). 12. A(a,b). 13. B(g,h). Prolog A(X,Y) 1, B(X,Y) 1 2. D(X) 2 D(c) 3. cut (!) , D(c), 2. Prolog E(f) 10, A(c,f). Prolog A(c,g) A(a,b). A(c,g) Prolog : E(Y), E(g) ( 11). (backtracking) cut D(X) B(X,Y), A(X,Y). A(X,Y) , 12, A(a,b). cut (!), Prolog "" cut , . cut cut. cut : A(g,h), A(c,f), A(c,g), A(d,f), A(d,g), A(c,f), A(c,g), A(d,f), A(d,g), A(a,b). ( 7.1)

  • 120

    Prolog. H Prolog (negation by failure). (closed world assumption). 7.3. Prolog " Prolog". 7.4. , ( ) . . Prolog not cut , . , . 7.5. not(P) :- call(P), !, fail. not(P). P . P (function, , structure). call(P) P , P. fail . not. Prolog , 5.25 "" "not" Prolog. 7.3 1. watch(X,film) :- has(X,color_TV), not(busy(X)). 2. record(X,film):- has(X,video), busy(X). 3. watch(X,film) :- record(X,film). 4. has(paul,color_TV). 5. has(mary,color_TV). 6. has(peter,color_TV). 7. has(sofia,video). 8. has(mary,video). 9. has(john,video). 10. has(peter,video). ?watch(X,Y).

  • 121

    not(busy(X)) X busy(X). watch(X,Y) Prolog 1, has(X,color_TV). 4,5,6 busy(X), busy(paul), busy(mary), busy(peter),