{"id":87,"date":"2020-02-23T11:28:24","date_gmt":"2020-02-23T11:28:24","guid":{"rendered":"https:\/\/alandix.com\/aibook\/?page_id=87"},"modified":"2025-03-17T17:17:58","modified_gmt":"2025-03-17T17:17:58","slug":"code","status":"publish","type":"page","link":"https:\/\/alandix.com\/aibook\/code\/","title":{"rendered":"code"},"content":{"rendered":"\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div id=\"wp-block-themeisle-blocks-advanced-columns-72877abf\" class=\"wp-block-themeisle-blocks-advanced-columns alignwide has-1-columns has-desktop-equal-layout has-tablet-equal-layout has-mobile-equal-layout has-vertical-unset\"><div class=\"wp-block-themeisle-blocks-advanced-columns-overlay\"><\/div><div class=\"innerblocks-wrap\">\n<div id=\"wp-block-themeisle-blocks-advanced-column-8c113812\" class=\"wp-block-themeisle-blocks-advanced-column\">\n<p>All these code examples are provided for personal and educational use only. You may modify or distribute the code in source or compiled form for similar purposes so long as the original source is clearly identified.<\/p>\n\n\n\n<p>These code examples were written for the First Edition of the AI Book, and have been modified minimally since then to cope with changes to run with <a href=\"http:\/\/tau-prolog.org\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Tau-Prolog (opens in a new tab)\">Tau-Prolog<\/a>, so that you can try them out within the browser. <\/p>\n\n\n\n<p>If you wish to use any of the code examples, in part or whole, for commercial purposes please contact Alan Dix. <\/p>\n\n\n\n<p>Most are written principally with ease of comprehension in mind and are not necessarily the most efficient coding of the algorithm. In particular, Prolog code, especially the early examples, try to avoid &#8216;clever&#8217; Prolog tricks. However, the nature of the examples, means that sequential code achieved using cuts and mutable store achieved using assert\/retract is often necessary.<\/p>\n\n\n\n<p>Code examples are being added incrementally. If you have any problems with the existing code, or if critical examples are too slow appearing, please contact Alan Dix who will try to correct\/add to the code as appropriate in a reasonable time! <\/p>\n\n\n\n<p class=\"ticss-f80cccd1\">Some of the prolog examples use predicates defined in <a href=\"https:\/\/alandix.com\/aibook\/code\/prolog-utility-files\/\">utility files<\/a>. <\/p>\n\n\n\n<figure class=\"wp-block-table ticss-b6d34e8c\"><table><tbody><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch1\/tbirds.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">tbirds.p<\/a><\/td><td>chapter 1<\/td><td>page 16: representing logic<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch1\/prod.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">prod.p<\/a><\/td><td>chapter 1<\/td><td>pages 19\u201320: production rules<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch1\/network.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">network.p<\/a><\/td><td>chapter 1<\/td><td>page 22: semantic networks and inheritance<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch1\/frames.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">frames.p<\/a><\/td><td>chapter 1<\/td><td>pages 23\u201324: frames and slots<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch2\/forback.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">forback.p<\/a><\/td><td>chapter 2<\/td><td>pages 33\u201334: forwards and backwards reasoning<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch2\/tms.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">tms.p<\/a><\/td><td>chapter 2<\/td><td>page 35: non-monotonic reasoning<br>TMS &#8211; truth maintenace system<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch2\/bayes.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">bayes.p<\/a><\/td><td>chapter 2<\/td><td>page 36:  Baysian inference<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch2\/bayes2.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">bayes2.p<\/a><\/td><td>chapter 2<\/td><td>page 36: Baysian inference<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch2\/certf.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">certf.p<\/a><\/td><td>chapter 2<\/td><td>pages 37\u201338: certainty factors<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch2\/fuzzy.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">fuzzy.p<\/a><\/td><td>chapter 2<\/td><td>pages 39\u201340: fuzzy set theory<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch3\/gentest.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">gentest.p<\/a><\/td><td>chapter 3<\/td><td>pages 49\u201350: generate and test<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch3\/prune.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">prune.p<\/a><\/td><td>chapter 3<\/td><td>pages 50\u201351:search tree pruning<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch3\/hanext.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">hanext.p<\/a><\/td><td>chapter 3<\/td><td>pages 52\u201353: hanoi search graph 1<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch3\/hanint.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">hanint.p<\/a><\/td><td>chapter 3<\/td><td>pages 52\u201353: hanoi search graph 2<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch3\/proof.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">proof.p<\/a><\/td><td>chapter 3<\/td><td>pages 53\u201354: addition proof graph<br>pages 62\u201363: closed lists<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch8\/eximages.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">eximages.p<\/a><\/td><td>chapter 8<\/td><td>image processing utilities<br>images from examples in book<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch8\/filter.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">filter.p<\/a><\/td><td>chapter 8<\/td><td>pages 169\u2013172: digital filters<br>pages 174\u2013175: gradient filters<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch8\/gimage.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">gimage.p<\/a><\/td><td>chapter 8<\/td><td>image processing utilities<br>the &#8216;gimage&#8217; representation of a pixel image<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch8\/image.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">image.p<\/a><\/td><td>chapter 8<\/td><td>image processing utilities<br>simple representation of a pixel image<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch8\/threshold.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">threshold.p<\/a><\/td><td>chapter 8<\/td><td>pages 166\u2013167: thresholding<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch9\/meansend.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">meansend.p<\/a><\/td><td>chapter 9<\/td><td>pages 205\u2013207: means-end analysis<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch10\/blackboard.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">blackboard.p<\/a><\/td><td>chapter 10<\/td><td>pages 236\u2013238: blackboard architecture<\/td><\/tr><tr><td><a href=\"https:\/\/alandix.com\/code\/ai96\/prolog\/view\/ch10\/life.p\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">life.p<\/a><\/td><td>chapter 10<\/td><td>pages 240\u2013241: Conway&#8217;s game of Life<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"class_list":["post-87","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/pages\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":9,"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/pages\/87\/revisions"}],"predecessor-version":[{"id":336,"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/pages\/87\/revisions\/336"}],"wp:attachment":[{"href":"https:\/\/alandix.com\/aibook\/wp-json\/wp\/v2\/media?parent=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}