{"id":340221,"date":"2022-10-25T15:00:42","date_gmt":"2022-10-25T15:00:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=340221"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=340221","title":{"rendered":"<span>Prolog in Prolog: \u0437\u0430\u0447\u0435\u043c \u0438 \u043a\u0430\u043a<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f\u0437\u044b\u043a Prolog \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 &#171;\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c&#187;, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0443\u0442\u0435\u043c \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412\u0430\u0436\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 &#171;\u043c\u0438\u0440\u0430&#187;, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0418\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u0438\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.cs.ccu.edu.tw\/~dan\/advinpro\/a1start.htm\" rel=\"noopener noreferrer nofollow\">Nani Search<\/a>. \u0418 \u0440\u0435\u0448\u0430\u044e\u0442 \u0438\u0445 \u0447\u0430\u0441\u0442\u043e \u0432 <a href=\"https:\/\/www.amzi.com\/AdventureInProlog\/appendix.php\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a\u043e\u043c \u0441\u0442\u0438\u043b\u0435<\/a>: \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0438\u0440\u0430 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u043e\u0432 \u0432 \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u041d\u043e \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0430 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435! \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0445\u0443\u0434\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435! \u041c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u0440\u043e\u0439\u0442\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443!<\/p>\n<p>\u041d\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u043b\u043e\u0445\u043e\u0435 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0435 \u0441\u0442\u0438\u043b\u044c, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430, \u0438 \u0434\u0430\u0436\u0435 \u0447\u0430\u0441\u0442\u0435\u043d\u044c\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442, \u044f\u0432\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u043e, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0412\u0430\u0436\u043d\u043e \u0447\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0438\u0440\u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0435\u0442 \u0431\u044b\u0442\u044c first-order value \u0438 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043c\u0438\u0440\u0435, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u044f\u0437\u044b\u043a Prolog.<\/p>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 Prolog, \u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c. \u041d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 Prolog, \u0442\u0430\u043a\u043e\u0439, \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0447\u0435\u043c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f.<\/p>\n<p>Prolog &#8212; \u044f\u0437\u044b\u043a, \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Homoiconicity\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u043c\u043e\u0438\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0441\u0442\u044c<\/a>, \u0438 \u043c\u044b \u044d\u0442\u0438\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u043f\u0440\u043e\u043b\u043e\u0433\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0442\u0435\u0440\u043c\u0430\u043c\u0438, \u0430 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0442\u0435\u0440\u043c\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0449\u0443\u0442\u0441\u044f \u0442\u0435\u0440\u043c\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u043c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\u043c.<\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u041f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0443 <strong>p(x)<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c <strong>p(x)<\/strong>, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e <strong>p(X) :- X = Y, Y = x.<\/strong>. \u0422\u0430\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0442\u0435\u0440\u043c\u043e\u043c: <strong>&#8216;:-&#8216;(p(X), &#8216;,'(&#8216;='(X,Y), &#8216;='(Y,x)))<\/strong>, \u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0440\u043c &#8216;:-&#8216; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u044b\u043c &#8212; \u0432\u0441\u0435 \u0442\u0435\u0440\u043c\u044b \u0440\u0430\u0432\u043d\u043e\u043f\u0440\u0430\u0432\u043d\u044b, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0432\u043d\u043e\u043f\u0440\u0430\u0432\u043d\u0435\u0435. \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043ec\u0442\u044c, \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u0433\u043e\u043b\u043e\u0432\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0430 \u0445\u0432\u043e\u0441\u0442 &#8212; \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432, \u043e\u0431\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 AND. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f p \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043a\u0430\u043a <strong>[p(x)]<\/strong> \u0438 <strong>[p(X), &#8216;='(X, Y), &#8216;='(Y,x)]<\/strong>. \u0412 \u0440\u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u043e\u043c <strong>&#8216;:-&#8216;<\/strong> \u0442\u0435\u043b\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u0440\u043c\u0430-\u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0438\u043b\u0438 \u0442\u0443\u043f\u043b\u0430 (<strong>&#8216;,&#8217;<\/strong>) \u0442\u0435\u0440\u043c\u043e\u0432-\u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432. \u041d\u043e \u0432 Prolog \u043d\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0442\u0443\u043f\u043b\u0430 \u0438 \u0442\u0443\u043f\u043b\u043e\u0432 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0443\u043f\u043b\u043e\u0432 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0435\u0439 \u043f\u0440\u043e\u043b\u043e\u0433\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u043d\u0438\u044f \u0430\u0433\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0432 \u0435\u0433\u043e \u0442\u0435\u043b\u043e. \u0417\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430, \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <strong>f(X) :- g(X). g(a). g(b).<\/strong>, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432 <strong>f(a), f(b).<\/strong>. \u0412 Prolog \u044d\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u043e\u0439\u0434\u0435\u0442, \u043d\u043e \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u0438\u0432\u043d\u043e\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435? \u041f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 <strong>f(a)<\/strong> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <strong>X<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0430\u0442\u043e\u043c\u043e\u043c <strong>&#8216;a&#8217;<\/strong>, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <strong>g(a)<\/strong> \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u043d\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u044c \u043e\u0431 f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 <strong>f(a) :- g(a).<\/strong> \u0438 \u043f\u0440\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c <strong>f(b)<\/strong> \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f. \u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043d\u043e\u0432\u044b\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0418\u043c\u0435\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0442\u043e\u043c\u0430\u043c\u0438, \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c.<\/p>\n<pre><code>mkfree([], []). mkfree([V|T], [(V,_)|TF]) :- mkfree(T, TF).  subst(F, V, O) :- atom(V) ->         ( member((V, R), F) -> O=R ; O=V ) ; ( V =.. [P | A], maplist(subst(F), A, N), O =.. [P | N] ) .  setfree((N, V), O) :-   mkfree(N, F),   maplist(subst(F), V, O).<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <strong>mkfree<\/strong> \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a &#171;\u0438\u043c\u0435\u043d&#187; \u043d\u043e\u0432\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440 &#8212; \u0438\u043c\u044f, \u043d\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f.<\/p>\n<p><strong>subst<\/strong> \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0442\u0435\u0440\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0430\u0442\u043e\u043c\u043e\u0432-\u0438\u043c\u0435\u043d \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0412 \u043d\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <strong>&#8216;=..&#8217;<\/strong> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u0440\u043c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a (\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u043a\u0430\u043a \u0438 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043e &#171;\u0445\u043e\u0440\u043e\u0448\u0438\u043c&#187; \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u0438\u043c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\u043c). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <strong>a(x,y) =.. [a, x, y]<\/strong>. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 &#171;\u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430&#187; <strong>maplist<\/strong>, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0442\u0435\u0440\u043c, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0432 \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u041f\u043e\u043a\u0430 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u0432 \u044d\u0442\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u044b. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u0446\u0435\u043b\u044c\u044e \u0441\u0430\u043c\u043e\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438 \u044f \u0438\u0437\u0431\u0430\u0432\u043b\u044e\u0441\u044c \u043e\u0442 \u043d\u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445.<\/p>\n<p><strong>setfree<\/strong> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 <strong>mkfree<\/strong> \u0438 <strong>subst<\/strong>, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 <strong>maplist<\/strong> &#8212; \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430, \u0430 \u043d\u0435 \u0442\u0443\u043f\u043b\u0430).<\/p>\n<p>\u0421\u0430\u043c \u0438\u043d\u0442\u0435\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u043c \u043d\u0430 \u0434\u0432\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430: <strong>check<\/strong> &#8212; \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438\/\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u0449\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438, \u0438 <strong>doio<\/strong>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\/\u0432\u044b\u0432\u043e\u0434. \u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0434\u0432\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 &#8212; \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>doio(DB, writeln(X), DB) :- writeln(X).  check([], DB, DB). check([P|R], DB, DBO) :-   (doio(DB, P, DBN) ->      true ;      (member(D, DB),       setfree(D, [P | B]),       check(B, DB, DBN))),   check(R, DBN, DBO). <\/code><\/pre>\n<p><strong>check<\/strong> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0430 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0442\u043e \u0438\u0449\u0435\u0442 \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c &#171;\u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f&#187;, \u043d\u043e \u044f \u043d\u0435 \u043b\u044e\u0431\u043b\u044e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u0435\u043c (\u043a\u0430\u043a \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439) \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e (\u0430 \u044f \u0432\u0441\u0435 \u0435\u0449\u0435 \u0434\u0443\u043c\u0430\u044e \u043e \u0441\u0430\u043c\u043e\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438). \u0412\u043c\u0435\u0441\u0442\u043e \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <strong>P -> T ; E<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code>doio(DB, (P -> T ; F), NDB) :-    check(P, DB, TDB) -> check(T, TDB, NDB) ; check(F, DB, NDB). <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 Prolog \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0443\u043f\u043b\u043e\u043c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432. \u0422\u0430\u043a \u043a\u0430\u043a \u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0442\u0443\u043f\u043b\u043e\u0432 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0443 \u043c\u0435\u043d\u044f \u0434\u0430\u0436\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<pre><code>?- check([[a(x)] -> [writeln(a)] ; [writeln(b)]], [([], [a(x)])], _). a true. <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043c\u0438\u0440\u043e\u0432 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 <strong>asserta<\/strong> \u043f\u043e\u0447\u0442\u0438 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u0435\u043d.<\/p>\n<pre><code>doio(DB, asserta(P), [([],[P])|DB]).<\/code><\/pre>\n<p>\u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0430\u043a\u0442\u044b. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043c\u0438\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0415\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f.<\/p>\n<pre><code>atoms(T, A) :-   atom(T) -> A=[T] ;   var(T) -> A=[] ;   T =.. [_ | L], maplist(atoms, L, LL), append(LL, A).  nextatom(D, A, N) :-   name(A, M),   append(M, [97], NM),   name(NP, NM),   (member(NP, D) -> nextatom(D, NP, N) ;   N = NP).  fillfree(D, V, (A, L), (AN, LN)) :-    (var(V) -> (nextatom(D, A, AN), V = A, LN = [A | L]) ;     atom(V) -> AN=A, LN=L ;    V =.. [_ | F],    foldl(fillfree(D), F, (A, L), (AN, LN))).  fillfree(V, VO, L) :-   atoms(V, A),   nextatom(A, w, I),   findall((V, L1), fillfree(A, V, (I,[]), (_,L1)), [(VO, L)]).  compile(P, I) :-   (P = (H, T)) -> compile(H, I1), compile(T, I2), append(I1, I2, I) ;   (P = (C -> T ; E)) -> compile(C, IC), compile(T, IT), compile(E, IE), I = [IC -> IT ; IE];   I = [P].  compileDef(P, I) :-   (P = (D :- C)) -> compile(C, IC), I = [D | IC];   I = [P].  doio(DB, asserta(P), [(V,DO)|DB]) :- def2list(P, D), fillfree(D, DO, V).<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b <strong>fillfree\/4<\/strong> \u0438 <strong>fillfree\/3<\/strong>.<\/p>\n<p><strong>fillfree\/4<\/strong> \u0438\u0449\u0435\u0442 \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 (\u0434\u043b\u044f \u043d\u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <strong>var<\/strong>) \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0435\u0442 \u0438\u0445 \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u0442\u043e\u043c\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432 \u0438\u0445\u043e\u0434\u043d\u043e\u043c \u0442\u0435\u0440\u043c\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430, \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u0430 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u0445 var \u0441\u043e\u0447\u0442\u0435\u0442 \u0435\u0435 \u0441\u0432\u044f\u0437\u044f\u043d\u043d\u043e\u0439. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0442\u0435\u0440\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u044f\u043d\u044b \u0441 \u0430\u0442\u043e\u043c\u0430\u043c\u0438-\u0438\u043c\u0435\u043d\u0430\u043c\u0438, \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u0442\u0438\u0445 \u0438\u043c\u0435\u043d, \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 <strong>setfree<\/strong>. \u041d\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 &#8212; \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432 \u0442\u0435\u0440\u043c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0433\u0434\u0435-\u0442\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u043e\u043d\u0430 \u0442\u0430\u043c \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u044f\u0437\u044f\u043d\u0430 \u0441 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0430\u0442\u043e\u043c\u043e\u043c. \u0427\u0442\u043e \u0431\u044b \u0438\u0445 \u0440\u0430\u0437\u0432\u044f\u0437\u0430\u0442\u044c <strong>fillfree\/3<\/strong> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <strong>fillfree\/4<\/strong> \u0438\u0437 <strong>findall<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0433\u0440\u0435\u0433\u0433\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f <strong>fillfree\/4<\/strong> \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0438\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>findall<\/strong> &#8212; \u0435\u0449\u0435 \u043e\u0434\u0438\u043d\u043e \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435 \u043a \u0441\u0430\u043c\u043e\u043f\u0440\u0438\u043c\u0435\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430. \u0412\u044b\u0437\u043e\u0432 <strong>findall<\/strong> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 <strong>setfree<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u043d\u0438\u0442 \u0430\u0442\u043e\u043c\u044b \u043d\u0430 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 <strong>fillfree\/4<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0442\u0435\u0440\u043c \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0439 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 retract \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code>deleteall(_, [], []). deleteall(P, [E | L], O) :-   (P = E -> fail ;             deleteall(P, L, O1), O = [E | O1]) ->               true ;               deleteall(P, L, O).  doio(DB, retract(P), DBO) :- def2list(P, D), deleteall((_,D), DB, DBO).<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u0432\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <strong>P -> T ; E<\/strong>. \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0438 \u0444\u0435\u0439\u043b\u0438\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0431\u044b\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0443 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442.<\/p>\n<p>\u0423 \u044d\u0442\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 <strong>assert<\/strong> \u0438 <strong>retract<\/strong> \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 &#8212; &#171;\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u044c&#187;. \u0415\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043f\u043e\u0442\u043e\u043c \u0444\u0435\u0439\u043b\u0438\u0442\u0441\u044f, \u0442\u043e \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c Prolog \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f, \u0430 \u0432 \u044d\u0442\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 &#8212; \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u0425\u043e\u0442\u044f \u044d\u0442\u043e \u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0438\u0440\u043e\u0432, \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Prolog \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u043e\u043c \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440.<\/p>\n<p>Nani search &#8212; \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043c\u0438\u0440. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u0440 \u043f\u043e\u043f\u0440\u043e\u0449\u0435, \u0441 \u043a\u043e\u0437\u043b\u043e\u043c\/carba, \u0432\u043e\u043b\u043a\u043e\u043c\/lobo \u0438 \u043a\u0430\u043f\u0443\u0441\u0442\u043e\u0439\/repollo, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043b\u043e\u0434\u043a\u0435\/barco \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043a\u0443. (\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043e\u0441\u0442\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u0438\u0441\u043f\u0430\u043d\u0441\u043a\u043e\u0433\u043e).<\/p>\n<pre><code>:- dynamic(barco\/1). :- dynamic(esta\/2).  barco(izquierda). esta(carba, izquierda). esta(lobo, izquierda). esta(repollo, izquierda).  costados(izquierda, derecha). costados(derecha, izquierda). comer(lobo, repollo). comer(repollo, lobo).  movimiento(X) :-   barco(L),   esta(X, L),   costados(L, N),   retract(esta(X, L)),   asserta(esta(X, N)),   retract(barco(L)),   asserta(barco(N)).  paso(carba) :-   movimiento(carba).  paso(X) :-   comer(X, Y),   esta(carba, L),   costados(L, O),   esta(Y, O),   movimiento(X).  paso(none) :-   esta(carba, L),   costados(L, O),   esta(lobo, O),   esta(repollo, O),   barco(X),   costados(X, N),   retract(barco(X)),   asserta(barco(N)).<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 <strong>paso(X)<\/strong>, \u0433\u0434\u0435 <strong>X<\/strong> \u044d\u0442\u043e <strong>carba<\/strong>, <strong>lobo<\/strong>, <strong>repollo<\/strong> \u0438\u043b\u0438 <strong>none<\/strong>.<\/p>\n<p>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0438\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043e\u0434\u0438\u043d \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u043f\u0440\u0435\u0442\u0435\u0442\u043e\u0440\u0430 \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<pre><code>solve(X, R) :-    X = [paso(_), paso(_), paso(_), paso(_), paso(_), paso(_), paso(_), esta(repollo, derecha), esta(lobo, derecha), esta(carba, derecha)],    PROG = [([], [barco(izquierda)]),            ([], [esta(carba, izquierda)]), ([], [esta(lobo, izquierda)]), ([], [esta(repollo, izquierda)]),             ([], [costados(izquierda, derecha)]), ([], [costados(derecha, izquierda)]),            ([], [comer(lobo, repollo)]), ([], [comer(repollo, lobo)]),             ([x, l, n], [movimiento(x),                             barco(l),                             esta(x, l),                             costados(l, n),                             retract(esta(x, l)),                             retract(barco(l)),                             asserta(esta(x, n)),                             asserta(barco(n))]),            ([], [paso(carba), movimiento(carba)]),            ([a, b, l, o], [paso(a),                              comer(a, b),                              esta(carba, l),                              costados(l, o),                              esta(b, o),                              movimiento(a)]),            ([l, o, x, n], [paso(none),                              esta(carba, l),                              costados(l, o),                              esta(lobo, o),                              esta(repollo, o),                              barco(x),                              costados(x, n),                              retract(barco(x)),                              asserta(barco(n))])],    check(X, PROG, R).<\/code><\/pre>\n<p>Prolog \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 &#171;\u0432\u0433\u043b\u0443\u0431\u044c&#187;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443, \u0447\u0442\u043e \u0438\u0449\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0440\u043e\u0432\u043d\u043e \u0438\u0437 \u0441\u0435\u043c\u0438 \u0448\u0430\u0433\u043e\u0432. \u0412 \u043c\u043e\u0438\u0445 \u043f\u043b\u0430\u043d\u0430\u0445 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u043d\u0430 \u043f\u043e\u0438\u0441\u043a &#171;\u0432\u0448\u0438\u0440\u044c&#187;, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code>?- solve(P, D). P = [paso(carba), paso(none), paso(lobo), paso(carba), paso(repollo), paso(none), paso(carba), esta(repollo, derecha), esta(..., ...)|...], D = [([], [barco(derecha)]),  ([], [esta(carba, derecha)]),  ([], [esta(repollo, derecha)]),  ([], [esta(lobo, derecha)]),  ([], [costados(izquierda, derecha)]),  ([], [costados(derecha, izquierda)]),  ([], [comer(..., ...)]),  ([], [...]),  (..., ...)|...] ; P = [paso(carba), paso(none), paso(repollo), paso(carba), paso(lobo), paso(none), paso(carba), esta(repollo, derecha), esta(..., ...)|...], D = [([], [barco(derecha)]),  ([], [esta(carba, derecha)]),  ([], [esta(lobo, derecha)]),  ([], [esta(repollo, derecha)]),  ([], [costados(izquierda, derecha)]),  ([], [costados(derecha, izquierda)]),  ([], [comer(..., ...)]),  ([], [...]),  (..., ...)|...] ; false. <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u0434\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434 \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f &#171;\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u044e&#187; \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043a\u043e\u0434 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442\u0441\u044f &#8212; \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0445\u043e\u0434\u0430, \u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0445\u043e\u0434 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u043e\u0441\u0442\u0443\u0441\u043b\u043e\u0432\u0438\u0435.<\/p>\n<pre><code>solve(X, R) :-    X = [paso(_), paso(_), paso(_), paso(_), paso(_), paso(_), paso(_), esta(repollo, derecha), esta(lobo, derecha), esta(carba, derecha)],    PROG = [([], [barco(izquierda)]),            ([], [esta(carba, izquierda)]), ([], [esta(lobo, izquierda)]), ([], [esta(repollo, izquierda)]),             ([], [costados(izquierda, derecha)]), ([], [costados(derecha, izquierda)]),             ([x, l], [seguro(x), esta(carba, l), esta(x, l), barco(l)]),            ([x, l, o], [seguro(x), esta(carba, l), esta(x, o), costados(l, o)]),            ([], [seguro, seguro(lobo), seguro(repollo)]),             ([x, l, n], [paso(x),                             barco(l),                             esta(x, l),                             costados(l, n),                             retract(esta(x, l)),                             retract(barco(l)),                             asserta(esta(x, n)),                             asserta(barco(n)),                             seguro]),            ([l, n], [paso(none),                             barco(l),                             costados(l, n),                             retract(barco(l)),                             asserta(barco(n)),                             seguro])],    check(X, PROG, R).<\/code><\/pre>\n<p>\u0413\u0434\u0435 \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0438\u0442\u044c? \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 &#8212; \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0438 \u044d\u043a\u0437\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435, \u0442\u0438\u043f\u0430 <a href=\"https:\/\/www.mimuw.edu.pl\/~nguyen\/mpl.pdf\" rel=\"noopener noreferrer nofollow\">Modal Prolog<\/a>). \u0421\u0432\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u0438\u0431\u0438\u0442\u0441\u044f \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%98%D0%BD%D0%B4%D1%83%D0%BA%D1%82%D0%B8%D0%B2%D0%BD%D0%BE%D0%B5_%D0%BB%D0%BE%D0%B3%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%BE%D0%B5_%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a> (\u0441\u043f\u0430\u0441\u0438\u0431\u043e <a class=\"mention\" href=\"\/users\/robofreak\">@robofreak<\/a>\u0437\u0430 \u0441\u0442\u0430\u0442\u044c\u044e \u0432 \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438).<\/p>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0430\u044e \u0431\u043b\u0430\u0433\u043e\u0434\u043e\u0440\u043d\u043e\u0441\u0442\u044c <a class=\"mention\" href=\"\/users\/usr345\">@usr345<\/a>\u0437\u0430 \u043f\u043e\u0434\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u0435 Nani Search.<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"https:\/\/github.com\/potan\/pinp\" rel=\"noopener noreferrer nofollow\">\u043d\u0430 github<\/a> &#8212; \u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434 \u0432 \u0431\u043e\u0435\u0432\u043e\u0439 \u0440\u0430\u0441\u0441\u043a\u0440\u0430\u0441\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043b\u044f Prolog \u0437\u0434\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442.<\/p>\n<p>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 \u043c\u0438\u0440\u0430 Nani Search \u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u043e\u0434 \u043c\u0438\u0440 \u043a\u0430\u043f\u0443\u0441\u0442\u044b, \u043a\u043e\u0437\u043b\u0430 \u0438 \u0432\u043e\u043b\u043a\u0430.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/693880\/\"> https:\/\/habr.com\/ru\/post\/693880\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f\u0437\u044b\u043a Prolog \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 &#171;\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c&#187;, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0443\u0442\u0435\u043c \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412\u0430\u0436\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 &#171;\u043c\u0438\u0440\u0430&#187;, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0418\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u0438\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.cs.ccu.edu.tw\/~dan\/advinpro\/a1start.htm\" rel=\"noopener noreferrer nofollow\">Nani Search<\/a>. \u0418 \u0440\u0435\u0448\u0430\u044e\u0442 \u0438\u0445 \u0447\u0430\u0441\u0442\u043e \u0432 <a href=\"https:\/\/www.amzi.com\/AdventureInProlog\/appendix.php\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a\u043e\u043c \u0441\u0442\u0438\u043b\u0435<\/a>: \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0438\u0440\u0430 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u043e\u0432 \u0432 \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u041d\u043e \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0430 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435! \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0445\u0443\u0434\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435! \u041c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u0440\u043e\u0439\u0442\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443!<\/p>\n<p>\u041d\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u043b\u043e\u0445\u043e\u0435 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0435 \u0441\u0442\u0438\u043b\u044c, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430, \u0438 \u0434\u0430\u0436\u0435 \u0447\u0430\u0441\u0442\u0435\u043d\u044c\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442, \u044f\u0432\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u043e, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0412\u0430\u0436\u043d\u043e \u0447\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0438\u0440\u0430 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0435\u0442 \u0431\u044b\u0442\u044c first-order value \u0438 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043c\u0438\u0440\u0435, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u044f\u0437\u044b\u043a Prolog.<\/p>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 Prolog, \u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c. \u041d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 Prolog, \u0442\u0430\u043a\u043e\u0439, \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0447\u0435\u043c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f.<\/p>\n<p>Prolog &#8212; \u044f\u0437\u044b\u043a, \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Homoiconicity\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u043c\u043e\u0438\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0441\u0442\u044c<\/a>, \u0438 \u043c\u044b \u044d\u0442\u0438\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u043f\u0440\u043e\u043b\u043e\u0433\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0442\u0435\u0440\u043c\u0430\u043c\u0438, \u0430 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0442\u0435\u0440\u043c\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0449\u0443\u0442\u0441\u044f \u0442\u0435\u0440\u043c\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u043c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\u043c.<\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u041f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0443 <strong>p(x)<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c <strong>p(x)<\/strong>, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e <strong>p(X) :- X = Y, Y = x.<\/strong>. \u0422\u0430\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0442\u0435\u0440\u043c\u043e\u043c: <strong>&#8216;:-&#8216;(p(X), &#8216;,'(&#8216;='(X,Y), &#8216;='(Y,x)))<\/strong>, \u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0440\u043c &#8216;:-&#8216; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u044b\u043c &#8212; \u0432\u0441\u0435 \u0442\u0435\u0440\u043c\u044b \u0440\u0430\u0432\u043d\u043e\u043f\u0440\u0430\u0432\u043d\u044b, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0432\u043d\u043e\u043f\u0440\u0430\u0432\u043d\u0435\u0435. \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043ec\u0442\u044c, \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u0433\u043e\u043b\u043e\u0432\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0430 \u0445\u0432\u043e\u0441\u0442 &#8212; \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432, \u043e\u0431\u0435\u0434\u0438\u043d\u044f\u0435\u043c\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 AND. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f p \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043a\u0430\u043a <strong>[p(x)]<\/strong> \u0438 <strong>[p(X), &#8216;='(X, Y), &#8216;='(Y,x)]<\/strong>. \u0412 \u0440\u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u043e\u043c <strong>&#8216;:-&#8216;<\/strong> \u0442\u0435\u043b\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u0440\u043c\u0430-\u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0438\u043b\u0438 \u0442\u0443\u043f\u043b\u0430 (<strong>&#8216;,&#8217;<\/strong>) \u0442\u0435\u0440\u043c\u043e\u0432-\u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432. \u041d\u043e \u0432 Prolog \u043d\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0442\u0443\u043f\u043b\u0430 \u0438 \u0442\u0443\u043f\u043b\u043e\u0432 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0443\u043f\u043b\u043e\u0432 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0435\u0439 \u043f\u0440\u043e\u043b\u043e\u0433\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u043d\u0438\u044f \u0430\u0433\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0432 \u0435\u0433\u043e \u0442\u0435\u043b\u043e. \u0417\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430, \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <strong>f(X) :- g(X). g(a). g(b).<\/strong>, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432 <strong>f(a), f(b).<\/strong>. \u0412 Prolog \u044d\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u043e\u0439\u0434\u0435\u0442, \u043d\u043e \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u0438\u0432\u043d\u043e\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435? \u041f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 <strong>f(a)<\/strong> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <strong>X<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0430\u0442\u043e\u043c\u043e\u043c <strong>&#8216;a&#8217;<\/strong>, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <strong>g(a)<\/strong> \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u043d\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u044c \u043e\u0431 f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 <strong>f(a) :- g(a).<\/strong> \u0438 \u043f\u0440\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c <strong>f(b)<\/strong> \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f. \u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043d\u043e\u0432\u044b\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0418\u043c\u0435\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0442\u043e\u043c\u0430\u043c\u0438, \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c.<\/p>\n<pre><code>mkfree([], []). mkfree([V|T], [(V,_)|TF]) :- mkfree(T, TF).  subst(F, V, O) :- atom(V) ->         ( member((V, R), F) -> O=R ; O=V ) ; ( V =.. [P | A], maplist(subst(F), A, N), O =.. [P | N] ) .  setfree((N, V), O) :-   mkfree(N, F),   maplist(subst(F), V, O).<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <strong>mkfree<\/strong> \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a &#171;\u0438\u043c\u0435\u043d&#187; \u043d\u043e\u0432\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440 &#8212; \u0438\u043c\u044f, \u043d\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f.<\/p>\n<p><strong>subst<\/strong> \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0442\u0435\u0440\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0430\u0442\u043e\u043c\u043e\u0432-\u0438\u043c\u0435\u043d \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0412 \u043d\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <strong>&#8216;=..&#8217;<\/strong> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u0440\u043c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a (\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u043a\u0430\u043a \u0438 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043e &#171;\u0445\u043e\u0440\u043e\u0448\u0438\u043c&#187; \u043f\u0440\u043e\u043b\u043e\u0433\u043e\u0432\u0441\u043a\u0438\u043c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430\u043c). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <strong>a(x,y) =.. [a, x, y]<\/strong>. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 &#171;\u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430&#187; <strong>maplist<\/strong>, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0442\u0435\u0440\u043c, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0432 \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u041f\u043e\u043a\u0430 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u0432 \u044d\u0442\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u044b. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u0446\u0435\u043b\u044c\u044e \u0441\u0430\u043c\u043e\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438 \u044f \u0438\u0437\u0431\u0430\u0432\u043b\u044e\u0441\u044c \u043e\u0442 \u043d\u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445.<\/p>\n<p><strong>setfree<\/strong> \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 <strong>mkfree<\/strong> \u0438 <strong>subst<\/strong>, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 <strong>maplist<\/strong> &#8212; \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430, \u0430 \u043d\u0435 \u0442\u0443\u043f\u043b\u0430).<\/p>\n<p>\u0421\u0430\u043c \u0438\u043d\u0442\u0435\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u043c \u043d\u0430 \u0434\u0432\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430: <strong>check<\/strong> &#8212; \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438\/\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u0449\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438, \u0438 <strong>doio<\/strong>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\/\u0432\u044b\u0432\u043e\u0434. \u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0434\u0432\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 &#8212; \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>doio(DB, writeln(X), DB) :- writeln(X).  check([], DB, DB). check([P|R], DB, DBO) :-   (doio(DB, P, DBN) ->      true ;      (member(D, DB),       setfree(D, [P | B]),       check(B, DB, DBN))),   check(R, DBN, DBO). <\/code><\/pre>\n<p><strong>check<\/strong> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0430 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0442\u043e \u0438\u0449\u0435\u0442 \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c &#171;\u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f&#187;, \u043d\u043e \u044f \u043d\u0435 \u043b\u044e\u0431\u043b\u044e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u0435\u043c (\u043a\u0430\u043a \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439) \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e (\u0430 \u044f \u0432\u0441\u0435 \u0435\u0449\u0435 \u0434\u0443\u043c\u0430\u044e \u043e \u0441\u0430\u043c\u043e\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438). \u0412\u043c\u0435\u0441\u0442\u043e \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <strong>P -> T ; E<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code>doio(DB, (P -> T ; F), NDB) :-    check(P, DB, TDB) -> check(T, TDB, NDB) ; check(F, DB, NDB). <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 Prolog \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0443\u043f\u043b\u043e\u043c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432. \u0422\u0430\u043a \u043a\u0430\u043a \u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0442\u0443\u043f\u043b\u043e\u0432 \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0443 \u043c\u0435\u043d\u044f \u0434\u0430\u0436\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<pre><code>?- check([[a(x)] -> [writeln(a)] ; [writeln(b)]], [([], [a(x)])], _). a true. <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043c\u0438\u0440\u043e\u0432 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 <strong>asserta<\/strong> \u043f\u043e\u0447\u0442\u0438 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u0435\u043d.<\/p>\n<pre><code>doio(DB, asserta(P), [([],[P])|DB]).<\/code><\/pre>\n<p>\u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0430\u043a\u0442\u044b. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043c\u0438\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0415\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f.<\/p>\n<pre><code>atoms(T, A) :-   atom(T) -> A=[T] ;   var(T) -> A=[] ;   T =.. [_ | L], maplist(atoms, L, LL), append(LL, A).  nextatom(D, A, N) :-   name(A, M),   append(M, [97], NM),   name(NP, NM),   (member(NP, D) -> nextatom(D, NP, N) ;   N = NP).  fillfree(D, V, (A, L), (AN, LN)) :-    (var(V) -> (nextatom(D, A, AN), V = A, LN = [A | L]) ;     atom(V) -> AN=A, LN=L ;    V =.. [_ | F],    foldl(fillfree(D), F, (A, L), (AN, LN))).  fillfree(V, VO, L) :-   atoms(V, A),   nextatom(A, w, I),   findall((V, L1), fillfree(A, V, (I,[]), (_,L1)), [(VO, L)]).  compile(P, I) :-   (P = (H, T)) -> compile(H, I1), compile(T, I2), append(I1, I2, I) ;   (P = (C -> T ; E)) -> compile(C, IC), compile(T, IT), compile(E, IE), I = [IC -> IT ; IE];   I = [P].  compileDef(P, I) :-   (P = (D :- C)) -> compile(C, IC), I = [D | IC];   I = [P].  doio(DB, asserta(P), [(V,DO)|DB]) :- def2list(P, D), fillfree(D, DO, V).<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b <strong>fillfree\/4<\/strong> \u0438 <strong>fillfree\/3<\/strong>.<\/p>\n<p><strong>fillfree\/4<\/strong> \u0438\u0449\u0435\u0442 \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 (\u0434\u043b\u044f \u043d\u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <strong>var<\/strong>) \u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0435\u0442 \u0438\u0445 \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u0442\u043e\u043c\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432 \u0438\u0445\u043e\u0434\u043d\u043e\u043c \u0442\u0435\u0440\u043c\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430, \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u0430 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u0445 var \u0441\u043e\u0447\u0442\u0435\u0442 \u0435\u0435 \u0441\u0432\u044f\u0437\u044f\u043d\u043d\u043e\u0439. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0442\u0435\u0440\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u044f\u043d\u044b \u0441 \u0430\u0442\u043e\u043c\u0430\u043c\u0438-\u0438\u043c\u0435\u043d\u0430\u043c\u0438, \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u0442\u0438\u0445 \u0438\u043c\u0435\u043d, \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 <strong>setfree<\/strong>. \u041d\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 &#8212; \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432 \u0442\u0435\u0440\u043c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0433\u0434\u0435-\u0442\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u043e\u043d\u0430 \u0442\u0430\u043c \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u044f\u0437\u044f\u043d\u0430 \u0441 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0430\u0442\u043e\u043c\u043e\u043c. \u0427\u0442\u043e \u0431\u044b \u0438\u0445 \u0440\u0430\u0437\u0432\u044f\u0437\u0430\u0442\u044c <strong>fillfree\/3<\/strong> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <strong>fillfree\/4<\/strong> \u0438\u0437 <strong>findall<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0433\u0440\u0435\u0433\u0433\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f <strong>fillfree\/4<\/strong> \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0438\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>findall<\/strong> &#8212; \u0435\u0449\u0435 \u043e\u0434\u0438\u043d\u043e \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435 \u043a \u0441\u0430\u043c\u043e\u043f\u0440\u0438\u043c\u0435\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430. \u0412\u044b\u0437\u043e\u0432 <strong>findall<\/strong> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 <strong>setfree<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u043d\u0438\u0442 \u0430\u0442\u043e\u043c\u044b \u043d\u0430 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 <strong>fillfree\/4<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0442\u0435\u0440\u043c \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0439 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 retract \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code>deleteall(_, [], []). deleteall(P, [E | L], O) :-   (P = E -> fail ;             deleteall(P, L, O1), O = [E | O1]) ->               true ;               deleteall(P, L, O).  doio(DB, retract(P), DBO) :- def2list(P, D), deleteall((_,D), DB, DBO).<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u0432\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <strong>P -> T ; E<\/strong>. \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0438 \u0444\u0435\u0439\u043b\u0438\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0431\u044b\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0443 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442.<\/p>\n<p>\u0423 \u044d\u0442\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 <strong>assert<\/strong> \u0438 <strong>retract<\/strong> \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 &#8212; &#171;\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u044c&#187;. \u0415\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043f\u043e\u0442\u043e\u043c \u0444\u0435\u0439\u043b\u0438\u0442\u0441\u044f, \u0442\u043e \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c Prolog \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f, \u0430 \u0432 \u044d\u0442\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 &#8212; \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f. \u0425\u043e\u0442\u044f \u044d\u0442\u043e \u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0438\u0440\u043e\u0432, \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Prolog \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u043e\u043c \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440.<\/p>\n<p>Nani search &#8212; \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043c\u0438\u0440. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u0440 \u043f\u043e\u043f\u0440\u043e\u0449\u0435, \u0441 \u043a\u043e\u0437\u043b\u043e\u043c\/carba, \u0432\u043e\u043b\u043a\u043e\u043c\/lobo \u0438 \u043a\u0430\u043f\u0443\u0441\u0442\u043e\u0439\/repollo, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043b\u043e\u0434\u043a\u0435\/barco \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043a\u0443. (\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043e\u0441\u0442\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u0438\u0441\u043f\u0430\u043d\u0441\u043a\u043e\u0433\u043e).<\/p>\n<pre><code>:- dynamic(barco\/1). :- dynamic(esta\/2).  barco(izquierda). esta(carba, izquierda). esta(lobo, izquierda). esta(repollo, izquierda).  costados(izquierda, derecha). costados(derecha, izquierda). comer(lobo, repollo). comer(repollo, lobo).  movimiento(X) :-   barco(L),   esta(X, L),   costados(L, N),   retract(esta(X, L)),   asserta(esta(X, N)),   retract(barco(L)),   asserta(barco(N)).  paso(carba) :-   movimiento(carba).  paso(X) :-   comer(X, Y),   esta(carba, L),   costados(L, O),   esta(Y, O),   movimiento(X).  paso(none) :-   esta(carba, L),   costados(L,<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-340221","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340221"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340221\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}